Mercurial > public > mercurial-scm > hg-stable
diff mercurial/wireprototypes.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | c59eb1560c44 |
line wrap: on
line diff
--- a/mercurial/wireprototypes.py Sun Oct 06 09:45:02 2019 -0400 +++ b/mercurial/wireprototypes.py Sun Oct 06 09:48:39 2019 -0400 @@ -19,27 +19,27 @@ from .utils import compression # Names of the SSH protocol implementations. -SSHV1 = 'ssh-v1' +SSHV1 = b'ssh-v1' # These are advertised over the wire. Increment the counters at the end # to reflect BC breakages. -SSHV2 = 'exp-ssh-v2-0003' -HTTP_WIREPROTO_V2 = 'exp-http-v2-0003' +SSHV2 = b'exp-ssh-v2-0003' +HTTP_WIREPROTO_V2 = b'exp-http-v2-0003' -NARROWCAP = 'exp-narrow-1' -ELLIPSESCAP1 = 'exp-ellipses-1' -ELLIPSESCAP = 'exp-ellipses-2' +NARROWCAP = b'exp-narrow-1' +ELLIPSESCAP1 = b'exp-ellipses-1' +ELLIPSESCAP = b'exp-ellipses-2' SUPPORTED_ELLIPSESCAP = (ELLIPSESCAP1, ELLIPSESCAP) # All available wire protocol transports. TRANSPORTS = { - SSHV1: {'transport': 'ssh', 'version': 1,}, + SSHV1: {b'transport': b'ssh', b'version': 1,}, SSHV2: { - 'transport': 'ssh', + b'transport': b'ssh', # TODO mark as version 2 once all commands are implemented. - 'version': 1, + b'version': 1, }, - 'http-v1': {'transport': 'http', 'version': 1,}, - HTTP_WIREPROTO_V2: {'transport': 'http', 'version': 2,}, + b'http-v1': {b'transport': b'http', b'version': 1,}, + HTTP_WIREPROTO_V2: {b'transport': b'http', b'version': 2,}, } @@ -116,13 +116,13 @@ # list of nodes encoding / decoding -def decodelist(l, sep=' '): +def decodelist(l, sep=b' '): if l: return [bin(v) for v in l.split(sep)] return [] -def encodelist(l, sep=' '): +def encodelist(l, sep=b' '): try: return sep.join(map(hex, l)) except TypeError: @@ -134,19 +134,19 @@ def escapebatcharg(plain): return ( - plain.replace(':', ':c') - .replace(',', ':o') - .replace(';', ':s') - .replace('=', ':e') + plain.replace(b':', b':c') + .replace(b',', b':o') + .replace(b';', b':s') + .replace(b'=', b':e') ) def unescapebatcharg(escaped): return ( - escaped.replace(':e', '=') - .replace(':s', ';') - .replace(':o', ',') - .replace(':c', ':') + escaped.replace(b':e', b'=') + .replace(b':s', b';') + .replace(b':o', b',') + .replace(b':c', b':') ) @@ -162,18 +162,18 @@ # :scsv: set of values, transmitted as comma-separated values # :plain: string with no transformation needed. GETBUNDLE_ARGUMENTS = { - 'heads': 'nodes', - 'bookmarks': 'boolean', - 'common': 'nodes', - 'obsmarkers': 'boolean', - 'phases': 'boolean', - 'bundlecaps': 'scsv', - 'listkeys': 'csv', - 'cg': 'boolean', - 'cbattempted': 'boolean', - 'stream': 'boolean', - 'includepats': 'csv', - 'excludepats': 'csv', + b'heads': b'nodes', + b'bookmarks': b'boolean', + b'common': b'nodes', + b'obsmarkers': b'boolean', + b'phases': b'boolean', + b'bundlecaps': b'scsv', + b'listkeys': b'csv', + b'cg': b'boolean', + b'cbattempted': b'boolean', + b'stream': b'boolean', + b'includepats': b'csv', + b'excludepats': b'csv', } @@ -253,9 +253,9 @@ def __init__( self, func, - args='', + args=b'', transports=None, - permission='push', + permission=b'push', cachekeyfn=None, extracapabilitiesfn=None, ): @@ -292,7 +292,7 @@ elif i == 1: return self.args else: - raise IndexError('can only access elements 0 and 1') + raise IndexError(b'can only access elements 0 and 1') class commanddict(dict): @@ -308,7 +308,7 @@ # Cast 2-tuples to commandentry instances. elif isinstance(v, tuple): if len(v) != 2: - raise ValueError('command tuples must have exactly 2 elements') + raise ValueError(b'command tuples must have exactly 2 elements') # It is common for extensions to wrap wire protocol commands via # e.g. ``wireproto.commands[x] = (newfn, args)``. Because callers @@ -322,11 +322,12 @@ v[0], args=v[1], transports=set(TRANSPORTS), - permission='push', + permission=b'push', ) else: raise ValueError( - 'command entries must be commandentry instances ' 'or 2-tuples' + b'command entries must be commandentry instances ' + b'or 2-tuples' ) return super(commanddict, self).__setitem__(k, v) @@ -354,8 +355,8 @@ # Allow config to override default list and ordering. if role == compression.SERVERROLE: - configengines = ui.configlist('server', 'compressionengines') - config = 'server.compressionengines' + configengines = ui.configlist(b'server', b'compressionengines') + config = b'server.compressionengines' else: # This is currently implemented mainly to facilitate testing. In most # cases, the server should be in charge of choosing a compression engine @@ -363,14 +364,16 @@ # CPU DoS due to an expensive engine or a network DoS due to poor # compression ratio). configengines = ui.configlist( - 'experimental', 'clientcompressionengines' + b'experimental', b'clientcompressionengines' ) - config = 'experimental.clientcompressionengines' + config = b'experimental.clientcompressionengines' # No explicit config. Filter out the ones that aren't supposed to be # advertised and return default ordering. if not configengines: - attr = 'serverpriority' if role == util.SERVERROLE else 'clientpriority' + attr = ( + b'serverpriority' if role == util.SERVERROLE else b'clientpriority' + ) return [ e for e in compengines if getattr(e.wireprotosupport(), attr) > 0 ] @@ -383,8 +386,8 @@ invalidnames = set(e for e in configengines if e not in validnames) if invalidnames: raise error.Abort( - _('invalid compression engine defined in %s: %s') - % (config, ', '.join(sorted(invalidnames))) + _(b'invalid compression engine defined in %s: %s') + % (config, b', '.join(sorted(invalidnames))) ) compengines = [e for e in compengines if e.name() in configengines] @@ -395,11 +398,12 @@ if not compengines: raise error.Abort( _( - '%s config option does not specify any known ' - 'compression engines' + b'%s config option does not specify any known ' + b'compression engines' ) % config, - hint=_('usable compression engines: %s') % ', '.sorted(validnames), + hint=_(b'usable compression engines: %s') + % b', '.sorted(validnames), ) return compengines