Commit 7d769563 authored by Stefan Behnel's avatar Stefan Behnel

another Main.parse() cleanup to make sure a unicode error really comes from...

another Main.parse() cleanup to make sure a unicode error really comes from the parser, not from the filename decoding
parent cfdfe4fa
...@@ -138,26 +138,27 @@ class Context: ...@@ -138,26 +138,27 @@ class Context:
return scope return scope
def parse(self, source_filename, type_names, pxd, full_module_name): def parse(self, source_filename, type_names, pxd, full_module_name):
try:
name = source_filename
if not isinstance(source_filename, unicode):
filename_encoding = sys.getfilesystemencoding()
if filename_encoding is None:
filename_encoding = sys.getdefaultencoding()
name = source_filename.decode(filename_encoding)
except UnicodeDecodeError:
pass
# Parse the given source file and return a parse tree. # Parse the given source file and return a parse tree.
try: try:
f = Utils.open_source_file(source_filename, "rU") f = Utils.open_source_file(source_filename, "rU")
try: try:
if isinstance(source_filename, unicode):
name = source_filename
else:
filename_encoding = sys.getfilesystemencoding()
if filename_encoding is None:
filename_encoding = sys.getdefaultencoding()
name = source_filename.decode(filename_encoding)
s = PyrexScanner(f, name, source_encoding = f.encoding, s = PyrexScanner(f, name, source_encoding = f.encoding,
type_names = type_names, context = self) type_names = type_names, context = self)
tree = Parsing.p_module(s, pxd, full_module_name) tree = Parsing.p_module(s, pxd, full_module_name)
finally: finally:
f.close() f.close()
except UnicodeDecodeError, msg: except UnicodeDecodeError, msg:
error((source_filename, 0, 0), "Decoding error, missing or incorrect coding=<encoding-name> at top of source (%s)" % msg) error((name, 0, 0), "Decoding error, missing or incorrect coding=<encoding-name> at top of source (%s)" % msg)
if Errors.num_errors > 0: if Errors.num_errors > 0:
raise CompileError raise CompileError
return tree return tree
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment