diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-06-11 23:56:51 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-06-11 23:56:51 (GMT) |
commit | 313a120ab6515f1bcddb13a9403a857078a9e474 (patch) | |
tree | 7304789294142106cef3076af6249fa611f041e3 /Lib/os.py | |
parent | 0f35e2c0f44b2012e4e32aaccde6fa42756e61f1 (diff) | |
download | cpython-313a120ab6515f1bcddb13a9403a857078a9e474.zip cpython-313a120ab6515f1bcddb13a9403a857078a9e474.tar.gz cpython-313a120ab6515f1bcddb13a9403a857078a9e474.tar.bz2 |
Issue #8969: On Windows, use mbcs codec in strict mode to encode and decode
filenames and enable os.fsencode().
Diffstat (limited to 'Lib/os.py')
-rw-r--r-- | Lib/os.py | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -533,16 +533,19 @@ if supports_bytes_environ: return environb.get(key, default) __all__.append("getenvb") -if name != 'nt': - def fsencode(value): - """Encode value for use in the file system, environment variables - or the command line.""" - if isinstance(value, bytes): - return value - elif isinstance(value, str): - return value.encode(sys.getfilesystemencoding(), 'surrogateescape') +def fsencode(value): + """Encode value for use in the file system, environment variables + or the command line.""" + if isinstance(value, bytes): + return value + elif isinstance(value, str): + encoding = sys.getfilesystemencoding() + if encoding == 'mbcs': + return value.encode(encoding) else: - raise TypeError("expect bytes or str, not %s" % type(value).__name__) + return value.encode(encoding, 'surrogateescape') + else: + raise TypeError("expect bytes or str, not %s" % type(value).__name__) def _exists(name): return name in globals() |