comparison mercurial/encoding.py @ 34223:1c601df9894c

py3: wrap bytes in encoding.from/toutf8b() with bytestr
author Yuya Nishihara <yuya@tcha.org>
date Sun, 03 Sep 2017 15:54:29 +0900
parents 112f118ecb00
children aa877860d4d7
comparison
equal deleted inserted replaced
34222:b4abc438a8c9 34223:1c601df9894c
506 s.decode('utf-8') 506 s.decode('utf-8')
507 return s 507 return s
508 except UnicodeDecodeError: 508 except UnicodeDecodeError:
509 pass 509 pass
510 510
511 s = pycompat.bytestr(s)
511 r = "" 512 r = ""
512 pos = 0 513 pos = 0
513 l = len(s) 514 l = len(s)
514 while pos < l: 515 while pos < l:
515 try: 516 try:
558 # We could do this with the unicode type but some Python builds 559 # We could do this with the unicode type but some Python builds
559 # use UTF-16 internally (issue5031) which causes non-BMP code 560 # use UTF-16 internally (issue5031) which causes non-BMP code
560 # points to be escaped. Instead, we use our handy getutf8char 561 # points to be escaped. Instead, we use our handy getutf8char
561 # helper again to walk the string without "decoding" it. 562 # helper again to walk the string without "decoding" it.
562 563
564 s = pycompat.bytestr(s)
563 r = "" 565 r = ""
564 pos = 0 566 pos = 0
565 l = len(s) 567 l = len(s)
566 while pos < l: 568 while pos < l:
567 c = getutf8char(s, pos) 569 c = getutf8char(s, pos)