Show More
@@ -494,6 +494,8 b' def toutf8b(s):' | |||
|
494 | 494 | internal surrogate encoding as a UTF-8 string.) |
|
495 | 495 | ''' |
|
496 | 496 | |
|
497 | if not isinstance(s, localstr) and isasciistr(s): | |
|
498 | return s | |
|
497 | 499 | if "\xed" not in s: |
|
498 | 500 | if isinstance(s, localstr): |
|
499 | 501 | return s._utf8 |
@@ -544,6 +546,8 b' def fromutf8b(s):' | |||
|
544 | 546 | True |
|
545 | 547 | ''' |
|
546 | 548 | |
|
549 | if isasciistr(s): | |
|
550 | return s | |
|
547 | 551 | # fast path - look for uDxxx prefixes in s |
|
548 | 552 | if "\xed" not in s: |
|
549 | 553 | return s |
@@ -34,6 +34,12 b' class LocalEncodingTest(unittest.TestCas' | |||
|
34 | 34 | self.assertTrue(s is encoding.tolocal(s)) |
|
35 | 35 | self.assertTrue(s is encoding.fromlocal(s)) |
|
36 | 36 | |
|
37 | class Utf8bEncodingTest(unittest.TestCase): | |
|
38 | def testasciifastpath(self): | |
|
39 | s = b'\0' * 100 | |
|
40 | self.assertTrue(s is encoding.toutf8b(s)) | |
|
41 | self.assertTrue(s is encoding.fromutf8b(s)) | |
|
42 | ||
|
37 | 43 | if __name__ == '__main__': |
|
38 | 44 | import silenttestrunner |
|
39 | 45 | silenttestrunner.main(__name__) |
General Comments 0
You need to be logged in to leave comments.
Login now