"Fossies" - the Fresh Open Source Software Archive

Member "viewvc-1.1.27/lib/vcauth/forbidden/__init__.py" (6 Jun 2019, 1620 Bytes) of package /linux/misc/viewvc-1.1.27.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.26_vs_1.1.27.

    1 # -*-python-*-
    2 #
    3 # Copyright (C) 2006-2019 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 import string
   16 
   17 class ViewVCAuthorizer(vcauth.GenericViewVCAuthorizer):
   18   """A simple top-level module authorizer."""
   19   def __init__(self, root_lookup_func, username, params={}):
   20     forbidden = params.get('forbidden', '')
   21     self.forbidden = map(string.strip,
   22                          filter(None, string.split(forbidden, ',')))
   23 
   24   def check_root_access(self, rootname):
   25     return 1
   26 
   27   def check_universal_access(self, rootname):
   28     # If there aren't any forbidden paths, we can grant universal read
   29     # access.  Otherwise, we make no claim.
   30     if not self.forbidden:
   31       return 1
   32     return None
   33     
   34   def check_path_access(self, rootname, path_parts, pathtype, rev=None):
   35     # No path?  No problem.
   36     if not path_parts:
   37       return 1
   38 
   39     # Not a directory?  We aren't interested.
   40     if pathtype != vclib.DIR:
   41       return 1
   42 
   43     # At this point we're looking at a directory path.
   44     module = path_parts[0]
   45     default = 1
   46     for pat in self.forbidden:
   47       if pat[0] == '!':
   48         default = 0
   49         if fnmatch.fnmatchcase(module, pat[1:]):
   50           return 1
   51       elif fnmatch.fnmatchcase(module, pat):
   52         return 0
   53     return default