Show More
@@ -66,33 +66,15 b' else:' | |||
|
66 | 66 | def sysstr(s): |
|
67 | 67 | return s |
|
68 | 68 | |
|
69 | # Partial backport from os.py in Python 3 | |
|
70 | def _fscodec(): | |
|
71 | encoding = sys.getfilesystemencoding() | |
|
72 | if encoding == 'mbcs': | |
|
73 | errors = 'strict' | |
|
69 | # Partial backport from os.py in Python 3, which only accepts bytes. | |
|
70 | # In Python 2, our paths should only ever be bytes, a unicode path | |
|
71 | # indicates a bug. | |
|
72 | def fsencode(filename): | |
|
73 | if isinstance(filename, str): | |
|
74 | return filename | |
|
74 | 75 | else: |
|
75 | errors = 'surrogateescape' | |
|
76 | ||
|
77 | def fsencode(filename): | |
|
78 | """ | |
|
79 | Encode filename to the filesystem encoding with 'surrogateescape' | |
|
80 | error handler, return bytes unchanged. On Windows, use 'strict' | |
|
81 | error handler if the file system encoding is 'mbcs' (which is the | |
|
82 | default encoding). | |
|
83 | """ | |
|
84 | if isinstance(filename, str): | |
|
85 | return filename | |
|
86 | elif isinstance(filename, unicode): | |
|
87 | return filename.encode(encoding, errors) | |
|
88 | else: | |
|
89 | raise TypeError( | |
|
90 | "expect str or unicode, not %s" % type(filename).__name__) | |
|
91 | ||
|
92 | return fsencode | |
|
93 | ||
|
94 | fsencode = _fscodec() | |
|
95 | del _fscodec | |
|
76 | raise TypeError( | |
|
77 | "expect str, not %s" % type(filename).__name__) | |
|
96 | 78 | |
|
97 | 79 | stringio = io.StringIO |
|
98 | 80 | empty = _queue.Empty |
General Comments 0
You need to be logged in to leave comments.
Login now