comparison hglib/util.py @ 142:fe74d5599539

hglib: wrap all application string literals in util.b() (issue4520) Conversion also included changing use of string interpolation to string concatenation as bytes interpolation does not exist in Python 3. Indexing related to bytes was also changed to length-1 bytes through slicing as Python 3 returns an int in this instance. Tests have not been switched to using util.b() so that the change to application code can be independently verified as not being broken.
author Brett Cannon <brett@python.org>
date Sun, 08 Mar 2015 13:08:37 -0400
parents ea80bd2775f6
children f3c430afa598
comparison
equal deleted inserted replaced
141:ea80bd2775f6 142:fe74d5599539
29 29
30 for line in cs: 30 for line in cs:
31 n -= 1 31 n -= 1
32 if n == 0: 32 if n == 0:
33 return cs.read() 33 return cs.read()
34 return '' 34 return b('')
35 35
36 def skiplines(s, prefix): 36 def skiplines(s, prefix):
37 """ 37 """
38 Skip lines starting with prefix in s 38 Skip lines starting with prefix in s
39 39
50 50
51 for line in cs: 51 for line in cs:
52 if not line.startswith(prefix): 52 if not line.startswith(prefix):
53 return line + cs.read() 53 return line + cs.read()
54 54
55 return '' 55 return b('')
56 56
57 def cmdbuilder(name, *args, **kwargs): 57 def cmdbuilder(name, *args, **kwargs):
58 """ 58 """
59 A helper for building the command arguments 59 A helper for building the command arguments
60 60
86 cmd = [name] 86 cmd = [name]
87 for arg, val in kwargs.items(): 87 for arg, val in kwargs.items():
88 if val is None: 88 if val is None:
89 continue 89 continue
90 90
91 arg = arg.replace('_', '-') 91 arg = arg.replace(b('_'), b('-'))
92 if arg != '-': 92 if arg != b('-'):
93 if len(arg) == 1: 93 if len(arg) == 1:
94 arg = '-' + arg 94 arg = b('-') + arg
95 else: 95 else:
96 arg = '--' + arg 96 arg = b('--') + arg
97 if isinstance(val, bool): 97 if isinstance(val, bool):
98 if val: 98 if val:
99 cmd.append(arg) 99 cmd.append(arg)
100 elif isinstance(val, list): 100 elif isinstance(val, list):
101 for v in val: 101 for v in val: