Show More
@@ -46,7 +46,6 b' asciiupper = charencode.asciiupper' | |||||
46 |
|
46 | |||
47 | _sysstr = pycompat.sysstr |
|
47 | _sysstr = pycompat.sysstr | |
48 |
|
48 | |||
49 | if pycompat.ispy3: |
|
|||
50 |
|
|
49 | unichr = chr | |
51 |
|
50 | |||
52 | # These unicode characters are ignored by HFS+ (Apple Technote 1150, |
|
51 | # These unicode characters are ignored by HFS+ (Apple Technote 1150, | |
@@ -78,10 +77,8 b' def hfsignoreclean(s):' | |||||
78 |
|
77 | |||
79 | # encoding.environ is provided read-only, which may not be used to modify |
|
78 | # encoding.environ is provided read-only, which may not be used to modify | |
80 | # the process environment |
|
79 | # the process environment | |
81 |
_nativeenviron = |
|
80 | _nativeenviron = os.supports_bytes_environ | |
82 | if not pycompat.ispy3: |
|
81 | if _nativeenviron: | |
83 | environ = os.environ # re-exports |
|
|||
84 | elif _nativeenviron: |
|
|||
85 | environ = os.environb # re-exports |
|
82 | environ = os.environb # re-exports | |
86 | else: |
|
83 | else: | |
87 | # preferred encoding isn't known yet; use utf-8 to avoid unicode error |
|
84 | # preferred encoding isn't known yet; use utf-8 to avoid unicode error | |
@@ -98,7 +95,7 b' else:' | |||||
98 | # cp65001 is a Windows variant of utf-8, which isn't supported on Python 2. |
|
95 | # cp65001 is a Windows variant of utf-8, which isn't supported on Python 2. | |
99 | # No idea if it should be rewritten to the canonical name 'utf-8' on Python 3. |
|
96 | # No idea if it should be rewritten to the canonical name 'utf-8' on Python 3. | |
100 | # https://bugs.python.org/issue13216 |
|
97 | # https://bugs.python.org/issue13216 | |
101 |
if pycompat.iswindows |
|
98 | if pycompat.iswindows: | |
102 | _encodingrewrites[b'cp65001'] = b'utf-8' |
|
99 | _encodingrewrites[b'cp65001'] = b'utf-8' | |
103 |
|
100 | |||
104 | try: |
|
101 | try: | |
@@ -270,21 +267,9 b' def unimethod(bytesfunc):' | |||||
270 | # converter functions between native str and byte string. use these if the |
|
267 | # converter functions between native str and byte string. use these if the | |
271 | # character encoding is not aware (e.g. exception message) or is known to |
|
268 | # character encoding is not aware (e.g. exception message) or is known to | |
272 | # be locale dependent (e.g. date formatting.) |
|
269 | # be locale dependent (e.g. date formatting.) | |
273 | if pycompat.ispy3: |
|
|||
274 |
|
|
270 | strtolocal = unitolocal | |
275 |
|
|
271 | strfromlocal = unifromlocal | |
276 |
|
|
272 | strmethod = unimethod | |
277 | else: |
|
|||
278 |
|
||||
279 | def strtolocal(s): |
|
|||
280 | # type: (str) -> bytes |
|
|||
281 | return s # pytype: disable=bad-return-type |
|
|||
282 |
|
||||
283 | def strfromlocal(s): |
|
|||
284 | # type: (bytes) -> str |
|
|||
285 | return s # pytype: disable=bad-return-type |
|
|||
286 |
|
||||
287 | strmethod = pycompat.identity |
|
|||
288 |
|
273 | |||
289 |
|
274 | |||
290 | def lower(s): |
|
275 | def lower(s): | |
@@ -344,7 +329,7 b' def upperfallback(s):' | |||||
344 | if not _nativeenviron: |
|
329 | if not _nativeenviron: | |
345 | # now encoding and helper functions are available, recreate the environ |
|
330 | # now encoding and helper functions are available, recreate the environ | |
346 | # dict to be exported to other modules |
|
331 | # dict to be exported to other modules | |
347 |
if pycompat.iswindows |
|
332 | if pycompat.iswindows: | |
348 |
|
333 | |||
349 | class WindowsEnviron(dict): |
|
334 | class WindowsEnviron(dict): | |
350 | """`os.environ` normalizes environment variables to uppercase on windows""" |
|
335 | """`os.environ` normalizes environment variables to uppercase on windows""" | |
@@ -360,7 +345,6 b' if not _nativeenviron:' | |||||
360 |
|
345 | |||
361 | DRIVE_RE = re.compile(b'^[a-z]:') |
|
346 | DRIVE_RE = re.compile(b'^[a-z]:') | |
362 |
|
347 | |||
363 | if pycompat.ispy3: |
|
|||
364 |
|
|
348 | # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which | |
365 |
|
|
349 | # returns bytes. | |
366 |
|
|
350 | if pycompat.iswindows: | |
@@ -386,10 +370,9 b' if pycompat.ispy3:' | |||||
386 |
|
|
370 | cwd = cwd[0:1].upper() + cwd[1:] | |
387 |
|
|
371 | return cwd | |
388 |
|
372 | |||
|
373 | ||||
389 |
|
|
374 | else: | |
390 |
|
|
375 | getcwd = os.getcwdb # re-exports | |
391 | else: |
|
|||
392 | getcwd = os.getcwd # re-exports |
|
|||
393 |
|
376 | |||
394 | # How to treat ambiguous-width characters. Set to 'wide' to treat as wide. |
|
377 | # How to treat ambiguous-width characters. Set to 'wide' to treat as wide. | |
395 | _wide = _sysstr( |
|
378 | _wide = _sysstr( | |
@@ -600,10 +583,7 b' def jsonescape(s, paranoid=False):' | |||||
600 |
|
583 | |||
601 | # We need to decode/encode U+DCxx codes transparently since invalid UTF-8 |
|
584 | # We need to decode/encode U+DCxx codes transparently since invalid UTF-8 | |
602 | # bytes are mapped to that range. |
|
585 | # bytes are mapped to that range. | |
603 | if pycompat.ispy3: |
|
|||
604 |
|
|
586 | _utf8strict = r'surrogatepass' | |
605 | else: |
|
|||
606 | _utf8strict = r'strict' |
|
|||
607 |
|
587 | |||
608 | _utf8len = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 4] |
|
588 | _utf8len = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 4] | |
609 |
|
589 |
General Comments 0
You need to be logged in to leave comments.
Login now