Reduce the doctest lease duration...
[python_utils.git] / acl.py
diff --git a/acl.py b/acl.py
index 0692a045308a4a3a30b3ff6af67047a1572dc4dc..726dafc72f0240a7371dd0da39b69c253c3c69bc 100644 (file)
--- a/acl.py
+++ b/acl.py
@@ -1,11 +1,15 @@
 #!/usr/bin/env python3
 
-from abc import ABC, abstractmethod
+# © Copyright 2021-2022, Scott Gasch
+
+"""This module defines various flavors of Access Control Lists."""
+
 import enum
 import fnmatch
 import logging
 import re
-from typing import Any, Callable, List, Optional, Set, Sequence
+from abc import ABC, abstractmethod
+from typing import Any, Callable, List, Optional, Sequence, Set
 
 from overrides import overrides
 
@@ -34,31 +38,30 @@ class SimpleACL(ABC):
             Order.DENY_ALLOW,
         ):
             raise Exception(
-                'order_to_check_allow_deny must be Order.ALLOW_DENY or '
-                + 'Order.DENY_ALLOW'
+                'order_to_check_allow_deny must be Order.ALLOW_DENY or ' + 'Order.DENY_ALLOW'
             )
         self.order_to_check_allow_deny = order_to_check_allow_deny
         self.default_answer = default_answer
 
     def __call__(self, x: Any) -> bool:
         """Returns True if x is allowed, False otherwise."""
-        logger.debug(f'SimpleACL checking {x}')
+        logger.debug('SimpleACL checking %s', x)
         if self.order_to_check_allow_deny == Order.ALLOW_DENY:
             logger.debug('Checking allowed first...')
             if self.check_allowed(x):
-                logger.debug(f'{x} was allowed explicitly.')
+                logger.debug('%s was allowed explicitly.', x)
                 return True
             logger.debug('Checking denied next...')
             if self.check_denied(x):
-                logger.debug(f'{x} was denied explicitly.')
+                logger.debug('%s was denied explicitly.', x)
                 return False
         elif self.order_to_check_allow_deny == Order.DENY_ALLOW:
             logger.debug('Checking denied first...')
             if self.check_denied(x):
-                logger.debug(f'{x} was denied explicitly.')
+                logger.debug('%s was denied explicitly.', x)
                 return False
             if self.check_allowed(x):
-                logger.debug(f'{x} was allowed explicitly.')
+                logger.debug('%s was allowed explicitly.', x)
                 return True
 
         logger.debug(
@@ -180,7 +183,9 @@ class PredicateListBasedACL(SimpleACL):
 
 
 class StringWildcardBasedACL(PredicateListBasedACL):
-    """An ACL that allows or denies based on string glob (*, ?) patterns."""
+    """An ACL that allows or denies based on string glob :code:`(*, ?)`
+    patterns.
+    """
 
     def __init__(
         self,
@@ -193,16 +198,12 @@ class StringWildcardBasedACL(PredicateListBasedACL):
         allow_predicates = []
         if allowed_patterns is not None:
             for pattern in allowed_patterns:
-                allow_predicates.append(
-                    lambda x, pattern=pattern: fnmatch.fnmatch(x, pattern)
-                )
+                allow_predicates.append(lambda x, pattern=pattern: fnmatch.fnmatch(x, pattern))
         deny_predicates = None
         if denied_patterns is not None:
             deny_predicates = []
             for pattern in denied_patterns:
-                deny_predicates.append(
-                    lambda x, pattern=pattern: fnmatch.fnmatch(x, pattern)
-                )
+                deny_predicates.append(lambda x, pattern=pattern: fnmatch.fnmatch(x, pattern))
 
         super().__init__(
             allow_predicate_list=allow_predicates,
@@ -227,16 +228,12 @@ class StringREBasedACL(PredicateListBasedACL):
         if allowed_regexs is not None:
             allow_predicates = []
             for pattern in allowed_regexs:
-                allow_predicates.append(
-                    lambda x, pattern=pattern: pattern.match(x) is not None
-                )
+                allow_predicates.append(lambda x, pattern=pattern: pattern.match(x) is not None)
         deny_predicates = None
         if denied_regexs is not None:
             deny_predicates = []
             for pattern in denied_regexs:
-                deny_predicates.append(
-                    lambda x, pattern=pattern: pattern.match(x) is not None
-                )
+                deny_predicates.append(lambda x, pattern=pattern: pattern.match(x) is not None)
         super().__init__(
             allow_predicate_list=allow_predicates,
             deny_predicate_list=deny_predicates,