moved code for filename encoding to Utils.py to make it reusable elsewhere
authorStefan Behnel <scoder@users.berlios.de>
Fri, 9 May 2008 06:14:38 +0000 (08:14 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 9 May 2008 06:14:38 +0000 (08:14 +0200)
Cython/Compiler/Main.py
Cython/Utils.py

index a0e84cac2957ff175d844a4e2df2b2b18ad7727f..efdedc69f1baf9b26c02a5e5cc49200533700f3a 100644 (file)
@@ -138,16 +138,7 @@ class Context:
         return scope
 
     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
-
+        name = Utils.encode_filename(source_filename)
         # Parse the given source file and return a parse tree.
         try:
             f = Utils.open_source_file(source_filename, "rU")
index 8faa29eb669c8138c68f99cfeb1aab99d53017b4..12ba39ffdd0a31c23497b8929219b4548512ede5 100644 (file)
@@ -35,6 +35,18 @@ def castrate_file(path, st):
 
 # support for source file encoding detection and unicode decoding
 
+def encode_filename(filename):
+    if isinstance(filename, unicode):
+        return filename
+    try:
+        filename_encoding = sys.getfilesystemencoding()
+        if filename_encoding is None:
+            filename_encoding = sys.getdefaultencoding()
+        filename = filename.decode(filename_encoding)
+    except UnicodeDecodeError:
+        pass
+    return filename
+
 _match_file_encoding = re.compile(u"coding[:=]\s*([-\w.]+)").search
 
 def detect_file_encoding(source_filename):