Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.security.ACLStringIterator Class Reference

List of all members.

Public Member Functions

def __init__
def __iter__
def next

Public Attributes

 rights
 rest
 finished

Detailed Description

Iterator for acl string

Parse acl string and return the next entry on each call to
next. Implement the Iterator protocol.

Usage:
    iter = ACLStringIterator(cfg.acl_rights_valid, 'user name:right')
    for modifier, entries, rights in iter:
        # process data

Definition at line 375 of file __init__.py.


Constructor & Destructor Documentation

def MoinMoin.security.ACLStringIterator.__init__ (   self,
  rights,
  aclstring 
)
Initialize acl iterator

@param rights: the acl rights to consider when parsing
@param aclstring: string to parse

Definition at line 387 of file __init__.py.

00387 
00388     def __init__(self, rights, aclstring):
00389         """ Initialize acl iterator
00390 
00391         @param rights: the acl rights to consider when parsing
00392         @param aclstring: string to parse
00393         """
00394         self.rights = rights
00395         self.rest = aclstring.strip()
00396         self.finished = 0


Member Function Documentation

Required by the Iterator protocol 

Definition at line 397 of file __init__.py.

00397 
00398     def __iter__(self):
00399         """ Required by the Iterator protocol """
00400         return self

Return the next values from the acl string

When the iterator is finished and you try to call next, it
raises a StopIteration. The iterator finish as soon as the
string is fully parsed or can not be parsed any more.

@rtype: 3 tuple - (modifier, [entry, ...], [right, ...])
@return: values for one item in an acl string

Definition at line 401 of file __init__.py.

00401 
00402     def next(self):
00403         """ Return the next values from the acl string
00404 
00405         When the iterator is finished and you try to call next, it
00406         raises a StopIteration. The iterator finish as soon as the
00407         string is fully parsed or can not be parsed any more.
00408 
00409         @rtype: 3 tuple - (modifier, [entry, ...], [right, ...])
00410         @return: values for one item in an acl string
00411         """
00412         # Handle finished state, required by iterator protocol
00413         if self.rest == '':
00414             self.finished = 1
00415         if self.finished:
00416             raise StopIteration
00417 
00418         # Get optional modifier [+|-]entries:rights
00419         modifier = ''
00420         if self.rest[0] in ('+', '-'):
00421             modifier, self.rest = self.rest[0], self.rest[1:]
00422 
00423         # Handle the Default meta acl
00424         if self.rest.startswith('Default ') or self.rest == 'Default':
00425             self.rest = self.rest[8:]
00426             entries, rights = ['Default'], []
00427 
00428         # Handle entries:rights pairs
00429         else:
00430             # Get entries
00431             try:
00432                 entries, self.rest = self.rest.split(':', 1)
00433             except ValueError:
00434                 self.finished = 1
00435                 raise StopIteration("Can't parse rest of string")
00436             if entries == '':
00437                 entries = []
00438             else:
00439                 # TODO strip each entry from blanks?
00440                 entries = entries.split(',')
00441 
00442             # Get rights
00443             try:
00444                 rights, self.rest = self.rest.split(' ', 1)
00445                 # Remove extra white space after rights fragment,
00446                 # allowing using multiple spaces between items.
00447                 self.rest = self.rest.lstrip()
00448             except ValueError:
00449                 rights, self.rest = self.rest, ''
00450             rights = [r for r in rights.split(',') if r in self.rights]
00451 
00452         return modifier, entries, rights
00453 

Here is the caller graph for this function:


Member Data Documentation

Definition at line 395 of file __init__.py.

Definition at line 394 of file __init__.py.

Definition at line 393 of file __init__.py.


The documentation for this class was generated from the following file: