[Python-checkins] r85887 - python/branches/issue10209/Lib/os.py

victor.stinner python-checkins at python.org
Thu Oct 28 14:26:35 CEST 2010


Author: victor.stinner
Date: Thu Oct 28 14:26:35 2010
New Revision: 85887

Log:
os.fsencode()/.fsdecode(): do nothing if the unicodedata module is missing


Modified:
   python/branches/issue10209/Lib/os.py

Modified: python/branches/issue10209/Lib/os.py
==============================================================================
--- python/branches/issue10209/Lib/os.py	(original)
+++ python/branches/issue10209/Lib/os.py	Thu Oct 28 14:26:35 2010
@@ -553,8 +553,12 @@
             return filename
         elif isinstance(filename, str):
             if sys.platform == 'darwin':
-                import unicodedata
-                filename = unicodedata.normalize('NFD', filename)
+                try:
+                    import unicodedata
+                except ImportError:
+                    pass
+                else:
+                    filename = unicodedata.normalize('NFD', filename)
                 return filename.encode('utf-8', 'surrogateescape')
             else:
                 return filename.encode(encoding, errors)
@@ -571,9 +575,13 @@
             return filename
         elif isinstance(filename, bytes):
             if sys.platform == 'darwin':
-                import unicodedata
                 filename = filename.decode('utf-8', 'surrogateescape')
-                return unicodedata.normalize('NFC', filename)
+                try:
+                    import unicodedata
+                except ImportError:
+                    return filename
+                else:
+                    return unicodedata.normalize('NFC', filename)
             else:
                 return filename.decode(encoding, errors)
         else:


More information about the Python-checkins mailing list