Ignore:
Timestamp:
Nov 23, 2010 6:42:19 PM (13 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master
Children:
25f66c3
Parents:
353db8c
Message:

Checkpoint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/access.py

    r353db8c r6e63513  
    194194        finally:
    195195            if f: f.close()
     196
     197    def read_abac_access(self, fn, access_obj=None):
     198        """
     199        Read an access DB of the form
     200            abac.attribute -> local_auth_data
     201        The access dict is filled with mappings from the abac attributes (as
     202        strings) to the access objects.  The objects are strings by default,
     203        but the class constructor is called with the string following the ->
     204        and whitespace in the file.
     205        """
     206
     207        map_re = re.compile("(\S+)\s+->\s+(.*)");
     208        if access_obj is None:
     209            access_obj = lambda(x): "%s" % x
     210
     211        f = open(fn, 'r')
     212        try:
     213            lineno = 0
     214            for line in f:
     215                lineno += 1
     216                line = line.strip();
     217                if len(line) == 0 or line.startswith('#'):
     218                    continue
     219                m = map_re.match(line)
     220                if m != None:
     221                    self.access[m.group(1)] = access_obj(m.group(2))
     222                    continue
     223
     224                # Nothing matched to here: unknown line - raise exception
     225                # (finally will close f)
     226                raise self.parse_error(
     227                        "Unknown statement at line %d of %s" % \
     228                        (lineno, fn))
     229        finally:
     230            if f: f.close()
     231
    196232
    197233    def get_users(self, obj):
Note: See TracChangeset for help on using the changeset viewer.