"Fossies" - the Fresh Open Source Software Archive

Member "viewvc-1.2.1/lib/vcauth/forbidden/__init__.py" (26 Mar 2020, 1605 Bytes) of package /linux/misc/viewvc-1.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "__init__.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.1.28_vs_1.2.1.

    1 # -*-python-*-
    2 #
    3 # Copyright (C) 2006-2020 The ViewCVS Group. All Rights Reserved.
    4 #
    5 # By using this file, you agree to the terms and conditions set forth in
    6 # the LICENSE.html file which can be found at the top level of the ViewVC
    7 # distribution or at http://viewvc.org/license-1.html.
    8 #
    9 # For more information, visit http://viewvc.org/
   10 #
   11 # -----------------------------------------------------------------------
   12 import vcauth
   13 import vclib
   14 import fnmatch
   15 
   16 class ViewVCAuthorizer(vcauth.GenericViewVCAuthorizer):
   17   """A simple top-level module authorizer."""
   18   def __init__(self, root_lookup_func, username, params={}):
   19     forbidden = params.get('forbidden', '')
   20     self.forbidden = map(lambda x: x.strip(),
   21                          filter(None, forbidden.split(',')))
   22 
   23   def check_root_access(self, rootname):
   24     return 1
   25 
   26   def check_universal_access(self, rootname):
   27     # If there aren't any forbidden paths, we can grant universal read
   28     # access.  Otherwise, we make no claim.
   29     if not self.forbidden:
   30       return 1
   31     return None
   32     
   33   def check_path_access(self, rootname, path_parts, pathtype, rev=None):
   34     # No path?  No problem.
   35     if not path_parts:
   36       return 1
   37 
   38     # Not a directory?  We aren't interested.
   39     if pathtype != vclib.DIR:
   40       return 1
   41 
   42     # At this point we're looking at a directory path.
   43     module = path_parts[0]
   44     default = 1
   45     for pat in self.forbidden:
   46       if pat[0] == '!':
   47         default = 0
   48         if fnmatch.fnmatchcase(module, pat[1:]):
   49           return 1
   50       elif fnmatch.fnmatchcase(module, pat):
   51         return 0
   52     return default