Ignore:
Timestamp:
18/03/10 13:57:03 (9 years ago)
Author:
pjkersha
Message:

Parsing functionality near complete for rule1.xml

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/attributedesignatorreader.py

    r6747 r6750  
    1010__contact__ = "Philip.Kershaw@stfc.ac.uk" 
    1111__revision__ = "$Id: $" 
    12 from ndg.xacml.core.attributedesignator import AttributeDesignator 
     12from ndg.xacml.utils import str2Bool 
     13from ndg.xacml.core.attributedesignator import SubjectAttributeDesignator 
    1314from ndg.xacml.parsers import XMLParseError 
    1415from ndg.xacml.parsers.etree import QName 
    15 from ndg.xacml.parsers.etree.reader import ETreeAbstractReader 
     16from ndg.xacml.parsers.etree.expressionreader import ExpressionReader 
    1617 
    1718 
    18 class AttributeDesignatorReader(ETreeAbstractReader): 
    19     '''ElementTree based XACML Attribute Designator type parser 
     19class AttributeDesignatorReaderBase(ExpressionReader): 
     20    '''ElementTree based XACML Attribute Designator base class type parser 
    2021    ''' 
    21      
    22     def __call__(self, obj): 
     22    def _parseExtension(self, elem, attributeDesignator): 
    2323        """Parse AttributeDesignator object""" 
    24         elem = super(AttributeDesignatorReader, self)._parse(obj) 
     24        cls = self.__class__.TYPE 
    2525         
    26         cls = AttributeDesignator 
    27         attributeDesignator = cls() 
    28          
    29         localName = QName.getLocalPart(elem.tag) 
    30         if localName != cls.ELEMENT_LOCAL_NAME: 
    31             raise XMLParseError("No \"%s\" element found" %  
    32                                 cls.ELEMENT_LOCAL_NAME) 
    33          
    34         dataType = elem.attrib.get(cls.DATA_TYPE_ATTRIB_NAME) 
    35         if dataType is None: 
    36             raise XMLParseError('No "%s" attribute found in "%s" element' % 
    37                                 (cls.DATA_TYPE_ATTRIB_NAME,  
    38                                  cls.ELEMENT_LOCAL_NAME)) 
     26        # Unpack additional *required* attributes from top-level element 
     27        attributeValues = [] 
     28        for attributeName in (cls.ATTRIBUTE_ID_ATTRIB_NAME,): 
     29            attributeValue = elem.attrib.get(attributeName) 
     30            if attributeValue is None: 
     31                raise XMLParseError('No "%s" attribute found in "%s" element' % 
     32                                    (attributeName, cls.ELEMENT_LOCAL_NAME)) 
    3933                 
    40         attributeDesignator.dataType = dataType 
    41      
     34            attributeValues.append(attributeValue) 
     35              
     36        attributeDesignator.attributeId, = attributeValues 
     37               
     38        # Optional attributes 
     39        issuer = elem.attrib.get(cls.DATA_TYPE_ATTRIB_NAME) 
     40        if issuer is not None: 
     41            attributeDesignator.issuer = issuer 
     42              
     43        mustBePresent = elem.attrib.get(cls.DATA_TYPE_ATTRIB_NAME) 
     44        if mustBePresent is not None: 
     45            attributeDesignator.mustBePresent = str2Bool(mustBePresent) 
     46    
    4247        return attributeDesignator 
    4348 
    44          
     49 
     50class SubjectAttributeDesignatorReader(AttributeDesignatorReaderBase):  
     51    '''ElementTree based XACML Subject Attribute Designator type parser 
     52    ''' 
     53    TYPE = SubjectAttributeDesignator 
Note: See TracChangeset for help on using the changeset viewer.