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