--- a/hgext/convert/common.py Sun Oct 06 09:45:02 2019 -0400
+++ b/hgext/convert/common.py Sun Oct 06 09:48:39 2019 -0400
@@ -46,7 +46,7 @@
@property
def infile(self):
- return self._l.infile or '<unknown>'
+ return self._l.infile or b'<unknown>'
@property
def lineno(self):
@@ -56,13 +56,13 @@
def shlexer(data=None, filepath=None, wordchars=None, whitespace=None):
if data is None:
if pycompat.ispy3:
- data = open(filepath, 'r', encoding=r'latin1')
+ data = open(filepath, b'r', encoding=r'latin1')
else:
- data = open(filepath, 'r')
+ data = open(filepath, b'r')
else:
if filepath is not None:
raise error.ProgrammingError(
- 'shlexer only accepts data or filepath, not both'
+ b'shlexer only accepts data or filepath, not both'
)
if pycompat.ispy3:
data = data.decode('latin1')
@@ -87,7 +87,7 @@
def encodearg(s):
lines = base64.encodestring(s)
lines = [l.splitlines()[0] for l in lines]
- return ''.join(lines)
+ return b''.join(lines)
s = pickle.dumps(args)
return encodearg(s)
@@ -109,14 +109,14 @@
exc = error.Abort
else:
exc = MissingTool
- raise exc(_('cannot find required "%s" tool') % name)
+ raise exc(_(b'cannot find required "%s" tool') % name)
class NoRepo(Exception):
pass
-SKIPREV = 'SKIP'
+SKIPREV = b'SKIP'
class commit(object):
@@ -135,8 +135,8 @@
optparents=None,
ctx=None,
):
- self.author = author or 'unknown'
- self.date = date or '0 0'
+ self.author = author or b'unknown'
+ self.date = date or b'0 0'
self.desc = desc
self.parents = parents # will be converted and used as parents
self.optparents = optparents or [] # will be used if already converted
@@ -160,15 +160,15 @@
self.revs = revs
self.repotype = repotype
- self.encoding = 'utf-8'
+ self.encoding = b'utf-8'
- def checkhexformat(self, revstr, mapname='splicemap'):
+ def checkhexformat(self, revstr, mapname=b'splicemap'):
""" fails if revstr is not a 40 byte hex. mercurial and git both uses
such format for their revision numbering
"""
if not re.match(br'[0-9a-fA-F]{40,40}$', revstr):
raise error.Abort(
- _('%s entry %s is not a valid revision' ' identifier')
+ _(b'%s entry %s is not a valid revision' b' identifier')
% (mapname, revstr)
)
@@ -236,7 +236,7 @@
def recode(self, s, encoding=None):
if not encoding:
- encoding = self.encoding or 'utf-8'
+ encoding = self.encoding or b'utf-8'
if isinstance(s, pycompat.unicode):
return s.encode("utf-8")
@@ -292,7 +292,7 @@
"""
return {}
- def checkrevformat(self, revstr, mapname='splicemap'):
+ def checkrevformat(self, revstr, mapname=b'splicemap'):
"""revstr is a string that describes a revision in the given
source control system. Return true if revstr has correct
format.
@@ -412,20 +412,20 @@
cmdline = [self.command, cmd] + list(args)
for k, v in kwargs.iteritems():
if len(k) == 1:
- cmdline.append('-' + k)
+ cmdline.append(b'-' + k)
else:
- cmdline.append('--' + k.replace('_', '-'))
+ cmdline.append(b'--' + k.replace(b'_', b'-'))
try:
if len(k) == 1:
- cmdline.append('' + v)
+ cmdline.append(b'' + v)
else:
- cmdline[-1] += '=' + v
+ cmdline[-1] += b'=' + v
except TypeError:
pass
cmdline = [procutil.shellquote(arg) for arg in cmdline]
if not self.ui.debugflag:
- cmdline += ['2>', pycompat.bytestr(os.devnull)]
- cmdline = ' '.join(cmdline)
+ cmdline += [b'2>', pycompat.bytestr(os.devnull)]
+ cmdline = b' '.join(cmdline)
return cmdline
def _run(self, cmd, *args, **kwargs):
@@ -449,7 +449,7 @@
def _dorun(self, openfunc, cmd, *args, **kwargs):
cmdline = self._cmdline(cmd, *args, **kwargs)
- self.ui.debug('running: %s\n' % (cmdline,))
+ self.ui.debug(b'running: %s\n' % (cmdline,))
self.prerun()
try:
return openfunc(cmdline)
@@ -466,16 +466,16 @@
p = self._run(cmd, *args, **kwargs)
output = p.stdout.readlines()
p.wait()
- self.ui.debug(''.join(output))
+ self.ui.debug(b''.join(output))
return output, p.returncode
- def checkexit(self, status, output=''):
+ def checkexit(self, status, output=b''):
if status:
if output:
- self.ui.warn(_('%s error:\n') % self.command)
+ self.ui.warn(_(b'%s error:\n') % self.command)
self.ui.warn(output)
msg = procutil.explainexit(status)
- raise error.Abort('%s %s' % (self.command, msg))
+ raise error.Abort(b'%s %s' % (self.command, msg))
def run0(self, cmd, *args, **kwargs):
output, status = self.run(cmd, *args, **kwargs)
@@ -484,7 +484,7 @@
def runlines0(self, cmd, *args, **kwargs):
output, status = self.runlines(cmd, *args, **kwargs)
- self.checkexit(status, ''.join(output))
+ self.checkexit(status, b''.join(output))
return output
@propertycache
@@ -540,7 +540,7 @@
if not self.path:
return
try:
- fp = open(self.path, 'rb')
+ fp = open(self.path, b'rb')
except IOError as err:
if err.errno != errno.ENOENT:
raise
@@ -551,10 +551,10 @@
# Ignore blank lines
continue
try:
- key, value = line.rsplit(' ', 1)
+ key, value = line.rsplit(b' ', 1)
except ValueError:
raise error.Abort(
- _('syntax error in %s(%d): key/value pair expected')
+ _(b'syntax error in %s(%d): key/value pair expected')
% (self.path, i + 1)
)
if key not in self:
@@ -565,13 +565,13 @@
def __setitem__(self, key, value):
if self.fp is None:
try:
- self.fp = open(self.path, 'ab')
+ self.fp = open(self.path, b'ab')
except IOError as err:
raise error.Abort(
- _('could not open map file %r: %s')
+ _(b'could not open map file %r: %s')
% (self.path, encoding.strtolocal(err.strerror))
)
- self.fp.write(util.tonativeeol('%s %s\n' % (key, value)))
+ self.fp.write(util.tonativeeol(b'%s %s\n' % (key, value)))
self.fp.flush()
super(mapfile, self).__setitem__(key, value)