diff hgext/acl.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 aaad36b88298
children 687b865b95ad
line wrap: on
line diff
--- a/hgext/acl.py	Sat Oct 05 10:29:34 2019 -0400
+++ b/hgext/acl.py	Sun Oct 06 09:45:02 2019 -0400
@@ -224,9 +224,7 @@
     registrar,
     util,
 )
-from mercurial.utils import (
-    procutil,
-)
+from mercurial.utils import procutil
 
 urlreq = util.urlreq
 
@@ -240,33 +238,29 @@
 configitem = registrar.configitem(configtable)
 
 # deprecated config: acl.config
-configitem('acl', 'config',
-    default=None,
+configitem(
+    'acl', 'config', default=None,
 )
-configitem('acl.groups', '.*',
-    default=None,
-    generic=True,
+configitem(
+    'acl.groups', '.*', default=None, generic=True,
 )
-configitem('acl.deny.branches', '.*',
-    default=None,
-    generic=True,
+configitem(
+    'acl.deny.branches', '.*', default=None, generic=True,
 )
-configitem('acl.allow.branches', '.*',
-    default=None,
-    generic=True,
+configitem(
+    'acl.allow.branches', '.*', default=None, generic=True,
 )
-configitem('acl.deny', '.*',
-    default=None,
-    generic=True,
+configitem(
+    'acl.deny', '.*', default=None, generic=True,
 )
-configitem('acl.allow', '.*',
-    default=None,
-    generic=True,
+configitem(
+    'acl.allow', '.*', default=None, generic=True,
 )
-configitem('acl', 'sources',
-    default=lambda: ['serve'],
+configitem(
+    'acl', 'sources', default=lambda: ['serve'],
 )
 
+
 def _getusers(ui, group):
 
     # First, try to use group definition from section [acl.groups]
@@ -281,6 +275,7 @@
     except KeyError:
         raise error.Abort(_("group '%s' is undefined") % group)
 
+
 def _usermatch(ui, user, usersorgroups):
 
     if usersorgroups == '*':
@@ -293,29 +288,35 @@
             # if ug is a user  name: !username
             # if ug is a group name: !@groupname
             ug = ug[1:]
-            if (not ug.startswith('@') and user != ug
-                or ug.startswith('@') and user not in _getusers(ui, ug[1:])):
+            if (
+                not ug.startswith('@')
+                and user != ug
+                or ug.startswith('@')
+                and user not in _getusers(ui, ug[1:])
+            ):
                 return True
 
         # Test for user or group. Format:
         # if ug is a user  name: username
         # if ug is a group name: @groupname
-        elif (user == ug
-              or ug.startswith('@') and user in _getusers(ui, ug[1:])):
+        elif user == ug or ug.startswith('@') and user in _getusers(ui, ug[1:]):
             return True
 
     return False
 
+
 def buildmatch(ui, repo, user, key):
     '''return tuple of (match function, list enabled).'''
     if not ui.has_section(key):
         ui.debug('acl: %s not enabled\n' % key)
         return None
 
-    pats = [pat for pat, users in ui.configitems(key)
-            if _usermatch(ui, user, users)]
-    ui.debug('acl: %s enabled, %d entries for user %s\n' %
-             (key, len(pats), user))
+    pats = [
+        pat for pat, users in ui.configitems(key) if _usermatch(ui, user, users)
+    ]
+    ui.debug(
+        'acl: %s enabled, %d entries for user %s\n' % (key, len(pats), user)
+    )
 
     # Branch-based ACL
     if not repo:
@@ -332,6 +333,7 @@
         return match.match(repo.root, '', pats)
     return util.never
 
+
 def ensureenabled(ui):
     """make sure the extension is enabled when used as hook
 
@@ -345,16 +347,22 @@
     ui.setconfig('extensions', 'acl', '', source='internal')
     extensions.loadall(ui, ['acl'])
 
+
 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
 
     ensureenabled(ui)
 
     if hooktype not in ['pretxnchangegroup', 'pretxncommit', 'prepushkey']:
         raise error.Abort(
-            _('config error - hook type "%s" cannot stop '
-              'incoming changesets, commits, nor bookmarks') % hooktype)
-    if (hooktype == 'pretxnchangegroup' and
-        source not in ui.configlist('acl', 'sources')):
+            _(
+                'config error - hook type "%s" cannot stop '
+                'incoming changesets, commits, nor bookmarks'
+            )
+            % hooktype
+        )
+    if hooktype == 'pretxnchangegroup' and source not in ui.configlist(
+        'acl', 'sources'
+    ):
         ui.debug('acl: changes have source "%s" - skipping\n' % source)
         return
 
@@ -374,6 +382,7 @@
     else:
         _txnhook(ui, repo, hooktype, node, source, user, **kwargs)
 
+
 def _pkhook(ui, repo, hooktype, node, source, user, **kwargs):
     if kwargs[r'namespace'] == 'bookmarks':
         bookmark = kwargs[r'key']
@@ -382,22 +391,38 @@
         denybookmarks = buildmatch(ui, None, user, 'acl.deny.bookmarks')
 
         if denybookmarks and denybookmarks(bookmark):
-            raise error.Abort(_('acl: user "%s" denied on bookmark "%s"'
-                               ' (changeset "%s")')
-                               % (user, bookmark, ctx))
+            raise error.Abort(
+                _('acl: user "%s" denied on bookmark "%s"' ' (changeset "%s")')
+                % (user, bookmark, ctx)
+            )
         if allowbookmarks and not allowbookmarks(bookmark):
-            raise error.Abort(_('acl: user "%s" not allowed on bookmark "%s"'
-                               ' (changeset "%s")')
-                               % (user, bookmark, ctx))
-        ui.debug('acl: bookmark access granted: "%s" on bookmark "%s"\n'
-                 % (ctx, bookmark))
+            raise error.Abort(
+                _(
+                    'acl: user "%s" not allowed on bookmark "%s"'
+                    ' (changeset "%s")'
+                )
+                % (user, bookmark, ctx)
+            )
+        ui.debug(
+            'acl: bookmark access granted: "%s" on bookmark "%s"\n'
+            % (ctx, bookmark)
+        )
+
 
 def _txnhook(ui, repo, hooktype, node, source, user, **kwargs):
     # deprecated config: acl.config
     cfg = ui.config('acl', 'config')
     if cfg:
-        ui.readconfig(cfg, sections=['acl.groups', 'acl.allow.branches',
-            'acl.deny.branches', 'acl.allow', 'acl.deny'])
+        ui.readconfig(
+            cfg,
+            sections=[
+                'acl.groups',
+                'acl.allow.branches',
+                'acl.deny.branches',
+                'acl.allow',
+                'acl.deny',
+            ],
+        )
 
     allowbranches = buildmatch(ui, None, user, 'acl.allow.branches')
     denybranches = buildmatch(ui, None, user, 'acl.deny.branches')
@@ -408,21 +433,31 @@
         ctx = repo[rev]
         branch = ctx.branch()
         if denybranches and denybranches(branch):
-            raise error.Abort(_('acl: user "%s" denied on branch "%s"'
-                               ' (changeset "%s")')
-                               % (user, branch, ctx))
+            raise error.Abort(
+                _('acl: user "%s" denied on branch "%s"' ' (changeset "%s")')
+                % (user, branch, ctx)
+            )
         if allowbranches and not allowbranches(branch):
-            raise error.Abort(_('acl: user "%s" not allowed on branch "%s"'
-                               ' (changeset "%s")')
-                               % (user, branch, ctx))
-        ui.debug('acl: branch access granted: "%s" on branch "%s"\n'
-        % (ctx, branch))
+            raise error.Abort(
+                _(
+                    'acl: user "%s" not allowed on branch "%s"'
+                    ' (changeset "%s")'
+                )
+                % (user, branch, ctx)
+            )
+        ui.debug(
+            'acl: branch access granted: "%s" on branch "%s"\n' % (ctx, branch)
+        )
 
         for f in ctx.files():
             if deny and deny(f):
-                raise error.Abort(_('acl: user "%s" denied on "%s"'
-                ' (changeset "%s")') % (user, f, ctx))
+                raise error.Abort(
+                    _('acl: user "%s" denied on "%s"' ' (changeset "%s")')
+                    % (user, f, ctx)
+                )
             if allow and not allow(f):
-                raise error.Abort(_('acl: user "%s" not allowed on "%s"'
-                ' (changeset "%s")') % (user, f, ctx))
+                raise error.Abort(
+                    _('acl: user "%s" not allowed on "%s"' ' (changeset "%s")')
+                    % (user, f, ctx)
+                )
         ui.debug('acl: path access granted: "%s"\n' % ctx)