source = position[0]
assert not (isinstance(source, unicode) or isinstance(source, str)), (
"Please replace filename strings with Scanning.FileSourceDescriptor instances %r" % source)
- F = list(source.get_lines())
- s = ''.join(F[max(0, position[1]-6):position[1]])
- s += ' '*(position[2]-1) + '^'
- s = '-'*60 + '\n...\n' + s + '\n' + '-'*60 + '\n'
+ try:
+ F = list(source.get_lines())
+ except UnicodeDecodeError:
+ # file has an encoding problem
+ s = "[unprintable code]\n"
+ else:
+ s =''.join(F[max(0, position[1]-6):position[1]])
+ s = '...\n' + s + ' '*(position[2]-1) + '^\n'
+ s = '-'*60 + '\n' + s + '-'*60 + '\n'
return s
class CompileError(PyrexError):