|
36 | 36 | unicode = str
|
37 | 37 | bytes = bytes
|
38 | 38 | basestring = (str,bytes)
|
| 39 | + isunicode = True |
| 40 | + def ustring(text): |
| 41 | + """Returns the byte string as a unicode string""" |
| 42 | + if text == '' or text == b'': |
| 43 | + return '' |
| 44 | + return unicode(text, "utf-8") |
39 | 45 | else:
|
40 | 46 | # 'unicode' exists, must be Python 2
|
41 | 47 | str = str
|
42 | 48 | unicode = unicode
|
43 | 49 | bytes = str
|
44 | 50 | basestring = basestring
|
| 51 | + isunicode = False |
| 52 | + def ustring(text): |
| 53 | + """Returns the byte string unchanged""" |
| 54 | + return text |
45 | 55 |
|
46 | 56 | try:
|
47 | 57 | from subprocess import CalledProcessError
|
@@ -196,6 +206,8 @@ def read_pipe_full(c):
|
196 | 206 | expand = isinstance(c,basestring)
|
197 | 207 | p = subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=expand)
|
198 | 208 | (out, err) = p.communicate()
|
| 209 | + out = ustring(out) |
| 210 | + err = ustring(err) |
199 | 211 | return (p.returncode, out, err)
|
200 | 212 |
|
201 | 213 | def read_pipe(c, ignore_error=False):
|
@@ -263,6 +275,7 @@ def p4_has_move_command():
|
263 | 275 | cmd = p4_build_cmd(["move", "-k", "@from", "@to"])
|
264 | 276 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
265 | 277 | (out, err) = p.communicate()
|
| 278 | + err = ustring(err) |
266 | 279 | # return code will be 1 in either case
|
267 | 280 | if err.find("Invalid option") >= 0:
|
268 | 281 | return False
|
@@ -646,10 +659,18 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
|
646 | 659 | if skip_info:
|
647 | 660 | if 'code' in entry and entry['code'] == 'info':
|
648 | 661 | continue
|
| 662 | + if b'code' in entry and entry[b'code'] == b'info': |
| 663 | + continue |
649 | 664 | if cb is not None:
|
650 | 665 | cb(entry)
|
651 | 666 | else:
|
652 |
| - result.append(entry) |
| 667 | + if isunicode: |
| 668 | + out = {} |
| 669 | + for key, value in entry.items(): |
| 670 | + out[ustring(key)] = ustring(value) |
| 671 | + result.append(out) |
| 672 | + else: |
| 673 | + result.append(entry) |
653 | 674 | except EOFError:
|
654 | 675 | pass
|
655 | 676 | exitCode = p4.wait()
|
@@ -792,7 +813,7 @@ def gitConfig(key, typeSpecifier=None):
|
792 | 813 | cmd += [ key ]
|
793 | 814 | s = read_pipe(cmd, ignore_error=True)
|
794 | 815 | _gitConfig[key] = s.strip()
|
795 |
| - return _gitConfig[key] |
| 816 | + return ustring(_gitConfig[key]) |
796 | 817 |
|
797 | 818 | def gitConfigBool(key):
|
798 | 819 | """Return a bool, using git config --bool. It is True only if the
|
@@ -860,6 +881,7 @@ def branch_exists(branch):
|
860 | 881 | cmd = [ "git", "rev-parse", "--symbolic", "--verify", branch ]
|
861 | 882 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
862 | 883 | out, _ = p.communicate()
|
| 884 | + out = ustring(out) |
863 | 885 | if p.returncode:
|
864 | 886 | return False
|
865 | 887 | # expect exactly one line of output: the branch name
|
|
0 commit comments