Ignore:
Timestamp:
16/03/10 13:26:59 (10 years ago)
Author:
pjkersha
Message:

Added more !ETree readers for the different types.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/NDG_XACML/ndg/xacml/__init__.py

    r6740 r6746  
    1010__contact__ = "Philip.Kershaw@stfc.ac.uk" 
    1111__revision__ = "$Id: $" 
    12  
    1312class XACMLError(Exception): 
    1413    """Base class for XACML package exception types""" 
    15      
    16      
    17 class XMLParseError(XACMLError): 
    18     """XACML package XML Parsing error""" 
    19      
    20      
    21 class PolicyComponent(object): 
    22     """Base class for Policy and Policy subelements""" 
    23     XACML_2_0_XMLNS = "urn:oasis:names:tc:xacml:2.0:policy:schema:os" 
    24  
    25     __slots__ = ('__xmlns', '__reader', '__writer') 
    26  
    27     ELEMENT_LOCAL_NAME = None 
    28      
    29     def __init__(self): 
    30         self.__xmlns = PolicyComponent.XACML_2_0_XMLNS 
    31         self.__reader = None 
    32         self.__writer = None 
    33          
    34     def _getXmlns(self): 
    35         return self.__xmlns 
    36  
    37     def _setXmlns(self, value): 
    38         if not isinstance(value, basestring): 
    39             raise TypeError('Expecting string type for "xmlns" ' 
    40                             'attribute; got %r' % type(value)) 
    41         self.__xmlns = value 
    42  
    43     xmlns = property(_getXmlns, _setXmlns,  
    44                      doc="XML Namespace for policy the document") 
    45      
    46     @property 
    47     def isValidXmlns(self): 
    48         return self.xmlns in PolicyComponent.XMLNS 
    49  
    50     def read(self, obj): 
    51         """Read using callable assinged to reader property""" 
    52         if self.__reader is None: 
    53             raise AttributeError('No reader set for %r' % self.__class__) 
    54          
    55         self.__reader(self, obj) 
    56  
    57     @classmethod 
    58     def Read(cls, obj): 
    59         """Construct a new Policy"""  
    60         xacmlObj = cls() 
    61         xacmlObj.read(obj) 
    62         return xacmlObj 
    63      
    64     def write(self, obj): 
    65         """Read using callable assinged to reader property""" 
    66         if self.__writer is None: 
    67             raise AttributeError('No writer set for %r' % self.__class__) 
    68          
    69         self.__writer(self, obj) 
    70          
    71              
    72 class RequestPropertyBase(PolicyComponent): 
    73     """Base type for Subject, Resource, Action and Environment types""" 
    74     MATCH_TYPE = None 
    75      
    76     __slots__ = ('__matches', ) 
    77      
    78     def __init__(self): 
    79         # Derived types can specify the type for matches via the MATCH_TYPE 
    80         # class variable 
    81         self.__matches = TypedList(self.__class__.MATCH_TYPE) 
    82          
    83     @property 
    84     def matches(self): 
    85         return self.__matches 
Note: See TracChangeset for help on using the changeset viewer.