diff hgext/largefiles/proto.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 0a7f582f6f1f
children 687b865b95ad
line wrap: on
line diff
--- a/hgext/largefiles/proto.py	Sat Oct 05 10:29:34 2019 -0400
+++ b/hgext/largefiles/proto.py	Sun Oct 06 09:45:02 2019 -0400
@@ -19,16 +19,16 @@
     wireprotov1server,
 )
 
-from . import (
-    lfutil,
-)
+from . import lfutil
 
 urlerr = util.urlerr
 urlreq = util.urlreq
 
-LARGEFILES_REQUIRED_MSG = ('\nThis repository uses the largefiles extension.'
-                           '\n\nPlease enable it in your Mercurial config '
-                           'file.\n')
+LARGEFILES_REQUIRED_MSG = (
+    '\nThis repository uses the largefiles extension.'
+    '\n\nPlease enable it in your Mercurial config '
+    'file.\n'
+)
 
 eh = exthelper.exthelper()
 
@@ -36,6 +36,7 @@
 ssholdcallstream = None
 httpoldcallstream = None
 
+
 def putlfile(repo, proto, sha):
     '''Server command for putting a largefile into a repository's local store
     and into the user cache.'''
@@ -53,22 +54,27 @@
             tmpfp.close()
             lfutil.linktousercache(repo, sha)
         except IOError as e:
-            repo.ui.warn(_('largefiles: failed to put %s into store: %s\n') %
-                         (sha, e.strerror))
+            repo.ui.warn(
+                _('largefiles: failed to put %s into store: %s\n')
+                % (sha, e.strerror)
+            )
             return wireprototypes.pushres(
-                1, output.getvalue() if output else '')
+                1, output.getvalue() if output else ''
+            )
         finally:
             tmpfp.discard()
 
     return wireprototypes.pushres(0, output.getvalue() if output else '')
 
+
 def getlfile(repo, proto, sha):
     '''Server command for retrieving a largefile from the repository-local
     cache or user cache.'''
     filename = lfutil.findfile(repo, sha)
     if not filename:
-        raise error.Abort(_('requested largefile %s not present in cache')
-                          % sha)
+        raise error.Abort(
+            _('requested largefile %s not present in cache') % sha
+        )
     f = open(filename, 'rb')
     length = os.fstat(f.fileno())[6]
 
@@ -81,8 +87,10 @@
         yield '%d\n' % length
         for chunk in util.filechunkiter(f):
             yield chunk
+
     return wireprototypes.streamreslegacy(gen=generator())
 
+
 def statlfile(repo, proto, sha):
     '''Server command for checking if a largefile is present - returns '2\n' if
     the largefile is missing, '0\n' if it seems to be in good condition.
@@ -95,6 +103,7 @@
         return wireprototypes.bytesresponse('2\n')
     return wireprototypes.bytesresponse('0\n')
 
+
 def wirereposetup(ui, repo):
     class lfileswirerepository(repo.__class__):
         def putlfile(self, sha, fd):
@@ -102,12 +111,16 @@
             # input file-like into a bundle before sending it, so we can't use
             # it ...
             if issubclass(self.__class__, httppeer.httppeer):
-                res = self._call('putlfile', data=fd, sha=sha,
-                    headers={r'content-type': r'application/mercurial-0.1'})
+                res = self._call(
+                    'putlfile',
+                    data=fd,
+                    sha=sha,
+                    headers={r'content-type': r'application/mercurial-0.1'},
+                )
                 try:
                     d, output = res.split('\n', 1)
                     for l in output.splitlines(True):
-                        self.ui.warn(_('remote: '), l) # assume l ends with \n
+                        self.ui.warn(_('remote: '), l)  # assume l ends with \n
                     return int(d)
                 except ValueError:
                     self.ui.warn(_('unexpected putlfile response: %r\n') % res)
@@ -119,14 +132,14 @@
                 try:
                     ret, output = self._callpush("putlfile", fd, sha=sha)
                     if ret == "":
-                        raise error.ResponseError(_('putlfile failed:'),
-                                output)
+                        raise error.ResponseError(_('putlfile failed:'), output)
                     return int(ret)
                 except IOError:
                     return 1
                 except ValueError:
                     raise error.ResponseError(
-                        _('putlfile failed (unexpected response):'), ret)
+                        _('putlfile failed (unexpected response):'), ret
+                    )
 
         def getlfile(self, sha):
             """returns an iterable with the chunks of the file with sha sha"""
@@ -135,8 +148,9 @@
             try:
                 length = int(length)
             except ValueError:
-                self._abort(error.ResponseError(_("unexpected response:"),
-                                                length))
+                self._abort(
+                    error.ResponseError(_("unexpected response:"), length)
+                )
 
             # SSH streams will block if reading more than length
             for chunk in util.filechunkiter(stream, limit=length):
@@ -146,8 +160,9 @@
             if issubclass(self.__class__, httppeer.httppeer):
                 chunk = stream.read(1)
                 if chunk:
-                    self._abort(error.ResponseError(_("unexpected response:"),
-                                                    chunk))
+                    self._abort(
+                        error.ResponseError(_("unexpected response:"), chunk)
+                    )
 
         @wireprotov1peer.batchable
         def statlfile(self, sha):
@@ -165,6 +180,7 @@
 
     repo.__class__ = lfileswirerepository
 
+
 # advertise the largefiles=serve capability
 @eh.wrapfunction(wireprotov1server, '_capabilities')
 def _capabilities(orig, repo, proto):
@@ -173,6 +189,7 @@
     caps.append('largefiles=serve')
     return caps
 
+
 def heads(orig, repo, proto):
     '''Wrap server command - largefile capable clients will know to call
     lheads instead'''
@@ -181,6 +198,7 @@
 
     return orig(repo, proto)
 
+
 def sshrepocallstream(self, cmd, **args):
     if cmd == 'heads' and self.capable('largefiles'):
         cmd = 'lheads'
@@ -188,8 +206,10 @@
         args[r'cmds'] = args[r'cmds'].replace('heads ', 'lheads ')
     return ssholdcallstream(self, cmd, **args)
 
+
 headsre = re.compile(br'(^|;)heads\b')
 
+
 def httprepocallstream(self, cmd, **args):
     if cmd == 'heads' and self.capable('largefiles'):
         cmd = 'lheads'