diff mercurial/wireprototypes.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents 9668744c9122
children 687b865b95ad
line wrap: on
line diff
--- a/mercurial/wireprototypes.py	Sat Oct 05 10:29:34 2019 -0400
+++ b/mercurial/wireprototypes.py	Sun Oct 06 09:45:02 2019 -0400
@@ -10,19 +10,13 @@
     hex,
 )
 from .i18n import _
-from .thirdparty import (
-    attr,
-)
+from .thirdparty import attr
 from . import (
     error,
     util,
 )
-from .interfaces import (
-    util as interfaceutil,
-)
-from .utils import (
-    compression,
-)
+from .interfaces import util as interfaceutil
+from .utils import compression
 
 # Names of the SSH protocol implementations.
 SSHV1 = 'ssh-v1'
@@ -38,57 +32,57 @@
 
 # All available wire protocol transports.
 TRANSPORTS = {
-    SSHV1: {
-        'transport': 'ssh',
-        'version': 1,
-    },
+    SSHV1: {'transport': 'ssh', 'version': 1,},
     SSHV2: {
         'transport': 'ssh',
         # TODO mark as version 2 once all commands are implemented.
         'version': 1,
     },
-    'http-v1': {
-        'transport': 'http',
-        'version': 1,
-    },
-    HTTP_WIREPROTO_V2: {
-        'transport': 'http',
-        'version': 2,
-    }
+    'http-v1': {'transport': 'http', 'version': 1,},
+    HTTP_WIREPROTO_V2: {'transport': 'http', 'version': 2,},
 }
 
+
 class bytesresponse(object):
     """A wire protocol response consisting of raw bytes."""
+
     def __init__(self, data):
         self.data = data
 
+
 class ooberror(object):
     """wireproto reply: failure of a batch of operation
 
     Something failed during a batch call. The error message is stored in
     `self.message`.
     """
+
     def __init__(self, message):
         self.message = message
 
+
 class pushres(object):
     """wireproto reply: success with simple integer return
 
     The call was successful and returned an integer contained in `self.res`.
     """
+
     def __init__(self, res, output):
         self.res = res
         self.output = output
 
+
 class pusherr(object):
     """wireproto reply: failure
 
     The call failed. The `self.res` attribute contains the error message.
     """
+
     def __init__(self, res, output):
         self.res = res
         self.output = output
 
+
 class streamres(object):
     """wireproto reply: binary stream
 
@@ -100,10 +94,12 @@
     uncompressable and that the stream should therefore use the ``none``
     engine.
     """
+
     def __init__(self, gen=None, prefer_uncompressed=False):
         self.gen = gen
         self.prefer_uncompressed = prefer_uncompressed
 
+
 class streamreslegacy(object):
     """wireproto reply: uncompressed binary stream
 
@@ -114,36 +110,45 @@
     Like ``streamres``, but sends an uncompressed data for "version 1" clients
     using the application/mercurial-0.1 media type.
     """
+
     def __init__(self, gen=None):
         self.gen = gen
 
+
 # list of nodes encoding / decoding
 def decodelist(l, sep=' '):
     if l:
-        return [bin(v) for v in  l.split(sep)]
+        return [bin(v) for v in l.split(sep)]
     return []
 
+
 def encodelist(l, sep=' '):
     try:
         return sep.join(map(hex, l))
     except TypeError:
         raise
 
+
 # batched call argument encoding
 
+
 def escapebatcharg(plain):
-    return (plain
-            .replace(':', ':c')
-            .replace(',', ':o')
-            .replace(';', ':s')
-            .replace('=', ':e'))
+    return (
+        plain.replace(':', ':c')
+        .replace(',', ':o')
+        .replace(';', ':s')
+        .replace('=', ':e')
+    )
+
 
 def unescapebatcharg(escaped):
-    return (escaped
-            .replace(':e', '=')
-            .replace(':s', ';')
-            .replace(':o', ',')
-            .replace(':c', ':'))
+    return (
+        escaped.replace(':e', '=')
+        .replace(':s', ';')
+        .replace(':o', ',')
+        .replace(':c', ':')
+    )
+
 
 # mapping of options accepted by getbundle and their types
 #
@@ -157,7 +162,7 @@
 # :scsv:  set of values, transmitted as comma-separated values
 # :plain: string with no transformation needed.
 GETBUNDLE_ARGUMENTS = {
-    'heads':  'nodes',
+    'heads': 'nodes',
     'bookmarks': 'boolean',
     'common': 'nodes',
     'obsmarkers': 'boolean',
@@ -171,6 +176,7 @@
     'excludepats': 'csv',
 }
 
+
 class baseprotocolhandler(interfaceutil.Interface):
     """Abstract base class for wire protocol handlers.
 
@@ -184,7 +190,8 @@
         """The name of the protocol implementation.
 
         Used for uniquely identifying the transport type.
-        """)
+        """
+    )
 
     def getargs(args):
         """return the value for arguments in <args>
@@ -239,10 +246,19 @@
         in a protocol specific manner.
         """
 
+
 class commandentry(object):
     """Represents a declared wire protocol command."""
-    def __init__(self, func, args='', transports=None,
-                 permission='push', cachekeyfn=None, extracapabilitiesfn=None):
+
+    def __init__(
+        self,
+        func,
+        args='',
+        transports=None,
+        permission='push',
+        cachekeyfn=None,
+        extracapabilitiesfn=None,
+    ):
         self.func = func
         self.args = args
         self.transports = transports or set()
@@ -258,8 +274,12 @@
         data not captured by the 2-tuple and a new instance containing
         the union of the two objects is returned.
         """
-        return commandentry(func, args=args, transports=set(self.transports),
-                            permission=self.permission)
+        return commandentry(
+            func,
+            args=args,
+            transports=set(self.transports),
+            permission=self.permission,
+        )
 
     # Old code treats instances as 2-tuples. So expose that interface.
     def __iter__(self):
@@ -274,12 +294,14 @@
         else:
             raise IndexError('can only access elements 0 and 1')
 
+
 class commanddict(dict):
     """Container for registered wire protocol commands.
 
     It behaves like a dict. But __setitem__ is overwritten to allow silent
     coercion of values from 2-tuples for API compatibility.
     """
+
     def __setitem__(self, k, v):
         if isinstance(v, commandentry):
             pass
@@ -296,12 +318,16 @@
                 v = self[k]._merge(v[0], v[1])
             else:
                 # Use default values from @wireprotocommand.
-                v = commandentry(v[0], args=v[1],
-                                 transports=set(TRANSPORTS),
-                                 permission='push')
+                v = commandentry(
+                    v[0],
+                    args=v[1],
+                    transports=set(TRANSPORTS),
+                    permission='push',
+                )
         else:
-            raise ValueError('command entries must be commandentry instances '
-                             'or 2-tuples')
+            raise ValueError(
+                'command entries must be commandentry instances ' 'or 2-tuples'
+            )
 
         return super(commanddict, self).__setitem__(k, v)
 
@@ -319,6 +345,7 @@
 
         return True
 
+
 def supportedcompengines(ui, role):
     """Obtain the list of supported compression engines for a request."""
     assert role in (compression.CLIENTROLE, compression.SERVERROLE)
@@ -335,16 +362,18 @@
         # because a server has the most to lose from a sub-optimal choice. (e.g.
         # CPU DoS due to an expensive engine or a network DoS due to poor
         # compression ratio).
-        configengines = ui.configlist('experimental',
-                                      'clientcompressionengines')
+        configengines = ui.configlist(
+            'experimental', 'clientcompressionengines'
+        )
         config = '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'
-        return [e for e in compengines
-                if getattr(e.wireprotosupport(), attr) > 0]
+        return [
+            e for e in compengines if getattr(e.wireprotosupport(), attr) > 0
+        ]
 
     # If compression engines are listed in the config, assume there is a good
     # reason for it (like server operators wanting to achieve specific
@@ -353,21 +382,29 @@
     validnames = set(e.name() for e in compengines)
     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))))
+        raise error.Abort(
+            _('invalid compression engine defined in %s: %s')
+            % (config, ', '.join(sorted(invalidnames)))
+        )
 
     compengines = [e for e in compengines if e.name() in configengines]
-    compengines = sorted(compengines,
-                         key=lambda e: configengines.index(e.name()))
+    compengines = sorted(
+        compengines, key=lambda e: configengines.index(e.name())
+    )
 
     if not compengines:
-        raise error.Abort(_('%s config option does not specify any known '
-                            'compression engines') % config,
-                          hint=_('usable compression engines: %s') %
-                          ', '.sorted(validnames))
+        raise error.Abort(
+            _(
+                '%s config option does not specify any known '
+                'compression engines'
+            )
+            % config,
+            hint=_('usable compression engines: %s') % ', '.sorted(validnames),
+        )
 
     return compengines
 
+
 @attr.s
 class encodedresponse(object):
     """Represents response data that is already content encoded.
@@ -378,8 +415,10 @@
     wire. If commands emit an object of this type, the encoding step is bypassed
     and the content from this object is used instead.
     """
+
     data = attr.ib()
 
+
 @attr.s
 class alternatelocationresponse(object):
     """Represents a response available at an alternate location.
@@ -389,6 +428,7 @@
 
     Only compatible with wire protocol version 2.
     """
+
     url = attr.ib()
     mediatype = attr.ib()
     size = attr.ib(default=None)
@@ -397,6 +437,7 @@
     serverdercerts = attr.ib(default=None)
     servercadercerts = attr.ib(default=None)
 
+
 @attr.s
 class indefinitebytestringresponse(object):
     """Represents an object to be encoded to an indefinite length bytestring.
@@ -404,4 +445,5 @@
     Instances are initialized from an iterable of chunks, with each chunk being
     a bytes instance.
     """
+
     chunks = attr.ib()