Changeset 7109
- Timestamp:
- 28/06/10 13:54:57 (11 years ago)
- Location:
- TI12-security/trunk/ndg_xacml/ndg/xacml
- Files:
-
- 2 added
- 1 deleted
- 35 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/ndg_xacml/ndg/xacml/core/apply.py
r7100 r7109 155 155 '''functionMap object for PDP to retrieve functions from given XACML 156 156 function URNs 157 @ ivarvalue: function mapping object to map URNs to function157 @param value: function mapping object to map URNs to function 158 158 class implementations 159 159 @type value: ndg.xacml.core.functions.FunctionMap -
TI12-security/trunk/ndg_xacml/ndg/xacml/core/attribute.py
r7101 r7109 66 66 """Set attribute values 67 67 68 @ ivarvalue: list of attribute values68 @param value: list of attribute values 69 69 @type value: ndg.xacml.utils.TypedList 70 70 @raise TypeError: incorrect input type -
TI12-security/trunk/ndg_xacml/ndg/xacml/core/attributedesignator.py
r7101 r7109 356 356 self.issuer)) 357 357 358 return attributeValueBag 358 return attributeValueBag -
TI12-security/trunk/ndg_xacml/ndg/xacml/core/attributevalue.py
r7101 r7109 127 127 def _get_value(self): 128 128 """Get value 129 @ param: setting for this attribute value129 @return: setting for this attribute value 130 130 @rtype: any - constrained in derived classes 131 131 """ … … 226 226 AttributeValueClassMap 227 227 228 @ param__classMap: mapping object to map attribute value URIs to their228 @ivar __classMap: mapping object to map attribute value URIs to their 229 229 implementations as classes 230 230 @type __classMap: ndg.xacml.core.attributevalue.AttributeValueClassMap -
TI12-security/trunk/ndg_xacml/ndg/xacml/core/context/pdp.py
r7087 r7109 64 64 @param value: policy object for PDP to use to apply access control 65 65 decisions 66 @type policy: ndg.xacml.core.policy.Policy66 @type value: ndg.xacml.core.policy.Policy 67 67 ''' 68 68 if not isinstance(value, Policy): -
TI12-security/trunk/ndg_xacml/ndg/xacml/core/context/request.py
r7087 r7109 142 142 '%r' % (CtxHandlerInterface, type(value))) 143 143 144 self.__ctxHandler = value 144 self.__ctxHandler = value -
TI12-security/trunk/ndg_xacml/ndg/xacml/core/functions/__init__.py
r7088 r7109 646 646 @param key: XACML function URN 647 647 @type key: basestring 648 @param *arg: set a single additional argument if required which is648 @param arg: set a single additional argument if required which is 649 649 used as the default value should the key not be found in the map 650 @type *arg: tuple650 @type arg: tuple 651 651 @return: function class 652 652 @rtype: ndg.xacml.core.functions.AbstractFunction / NotImplemented -
TI12-security/trunk/ndg_xacml/ndg/xacml/core/functions/v1/bag.py
r7087 r7109 36 36 """return inputs into a bag 37 37 38 @param *args: inputs to add to bag38 @param args: inputs to add to bag 39 39 @type args: tuple 40 @param string2: second string41 @type string2: basestring42 40 @return: True if strings match, False otherwise 43 41 @rtype: bool -
TI12-security/trunk/ndg_xacml/ndg/xacml/core/policy.py
r7108 r7109 41 41 42 42 class Policy(XacmlCoreBase): 43 """ NDG MSI Policy.43 """XACML Policy 44 44 45 45 @cvar DEFAULT_XACML_VERSION: default is 2.0 … … 85 85 @ivar __ruleCombiningAlg: rule combining algorithm 86 86 @type __ruleCombiningAlg: NoneType / ndg.xacml.core.rule_combining_alg.RuleCombiningAlgInterface 87 88 87 """ 89 88 DEFAULT_XACML_VERSION = "2.0" … … 209 208 ''' 210 209 @return: policy id 211 @ type basestring: NoneType / basestring210 @rtype: NoneType / basestring 212 211 ''' 213 212 return self.__policyId … … 328 327 @property 329 328 def obligations(self): 330 """@ ivar __obligations: obligations331 @ type __obligations: ndg.xacml.utils.TypedList329 """@return: obligations 330 @rtype: ndg.xacml.utils.TypedList 332 331 """ 333 332 return self.__obligations -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/__init__.py
r7087 r7109 54 54 55 55 def _getPrefix(self): 56 """Get prefix 57 @return: prefix 58 @rtype: string 59 """ 56 60 return self.__prefix 57 61 58 62 def _setPrefix(self, value): 63 """Set prefix 64 @param value: prefix 65 @type value: string 66 @raise TypeError: invalid input value type 67 """ 59 68 self.__prefix = value 60 69 … … 62 71 63 72 def _getLocalPart(self): 73 """Get local part 74 @return: local part 75 @rtype: string 76 """ 64 77 return self.__localPart 65 78 66 79 def _setLocalPart(self, value): 80 """Set local part 81 @param value: local part 82 @type value: string 83 @raise TypeError: invalid input value type 84 """ 67 85 self.__localPart = value 68 86 … … 70 88 71 89 def _getNamespaceURI(self): 90 """Get namespace URI 91 @return: namespace URI 92 @rtype: string 93 """ 72 94 return self.__namespaceURI 73 95 74 96 def _setNamespaceURI(self, value): 97 """Set namespace URI 98 @param value: namespace URI 99 @type value: string 100 @raise TypeError: invalid input value type 101 """ 75 102 self.__namespaceURI = value 76 103 … … 84 111 @type qname: ndg.xacml.utils.etree.QName 85 112 @param qname: Qualified Name to compare with self 113 @return: True if input and this object match 114 @rtype: bool 86 115 """ 87 116 if not isinstance(qname, QName): -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/actionattributedesignatorreader.py
r7087 r7109 17 17 class ActionAttributeDesignatorReader(AttributeDesignatorReaderBase): 18 18 '''ElementTree based XACML Action Attribute Designator type parser 19 20 @cvar TYPE: XACML class type that this reader will read values into 21 @type TYPE: abc.ABCMeta 19 22 ''' 20 23 TYPE = ActionAttributeDesignator -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/actionmatchreader.py
r7087 r7109 16 16 17 17 class ActionMatchReader(MatchReaderBase): 18 """ElementTree based parser for XACML ActionMatch""" 18 """ElementTree based parser for XACML ActionMatch 19 20 @cvar TYPE: XACML class type that this reader will read values into 21 @type TYPE: type 22 23 @cvar ATTRIBUTE_DESIGNATOR_TYPE: type of attribute designator that this 24 match type holds 25 @type ATTRIBUTE_DESIGNATOR_TYPE: abc.ABCMeta 26 """ 19 27 TYPE = ActionMatch 20 28 ATTRIBUTE_DESIGNATOR_TYPE = ActionAttributeDesignator -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/actionreader.py
r7087 r7109 17 17 '''ElementTree based parser for Action type 18 18 @cvar TYPE: XACML type to instantiate from parsed object 19 @type string: type19 @type TYPE: type 20 20 ''' 21 TYPE = Action 21 TYPE = Action -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/applyreader.py
r7087 r7109 31 31 '''ElementTree based XACML Apply type parser 32 32 33 @cvar TYPE: XACML type to instantiate from parsed object 34 @type string: type 33 @cvar FUNCTION_ELEMENT_LOCAL_NAME: XML local name for function element 34 @type FUNCTION_ELEMENT_LOCAL_NAME: string 35 36 @cvar VARIABLE_REFERENCE_ELEMENT_LOCAL_NAME: XML local name for variable 37 reference element 38 @type VARIABLE_REFERENCE_ELEMENT_LOCAL_NAME: string 39 40 @cvar TYPE: XACML class type that this reader will read values into 41 @type TYPE: abc.ABCMeta 35 42 ''' 36 43 TYPE = Apply … … 43 50 44 51 def __call__(self, obj): 45 """Parse Apply type object""" 52 """Parse Apply type object 53 54 @param obj: input object to parse 55 @type obj: ElementTree Element, or stream object 56 @return: ElementTree element 57 @rtype: xml.etree.Element 58 """ 46 59 elem = super(ApplyReader, self)._parse(obj) 47 60 -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/attributedesignatorreader.py
r7087 r7109 20 20 ''' 21 21 def _parseExtension(self, elem, attributeDesignator): 22 """Parse AttributeDesignator object""" 22 """Parse Attribute Designator element 23 24 @param elem: ElementTree XML element 25 @type elem: xml.etree.Element 26 27 @param attributeDesignator: attribute designator 28 @type attributeDesignator: ndg.xacml.core.attributedesignator.AttributeDesignator 29 30 @raise XMLParseError: error parsing attribute ID XML attribute 31 32 @return: updated attribute designator 33 @rtype: ndg.xacml.core.attributedesignator.AttributeDesignator 34 """ 23 35 xacmlType = self.__class__.TYPE 24 36 -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/attributeselectorreader.py
r7087 r7109 10 10 __contact__ = "Philip.Kershaw@stfc.ac.uk" 11 11 __revision__ = "$Id$" 12 from ndg.xacml.utils import str2Bool 12 13 from ndg.xacml.core.attributeselector import AttributeSelector 13 14 from ndg.xacml.parsers import XMLParseError … … 17 18 18 19 class AttributeSelectorReader(ExpressionReader): 19 '''ElementTree based parser for XACML Attribute Selector type''' 20 '''ElementTree based parser for XACML Attribute Selector type 21 22 @cvar TYPE: XACML class type that this reader will read values into 23 @type TYPE: abc.ABCMeta 24 ''' 20 25 TYPE = AttributeSelector 21 26 22 27 def _parseExtension(self, elem, attributeSelector): 28 """Parse XML Attribute Selector element 29 30 @param elem: ElementTree XML element 31 @type elem: xml.etree.Element 32 33 @param attributeSelector: attribute selector to be updated with parsed 34 values 35 @type attributeSelector: ndg.xacml.core.attributeSelector.AttributeSelector 36 37 @raise XMLParseError: error parsing attribute ID XML attribute 38 39 @return: updated attribute selector 40 @rtype: ndg.xacml.core.attributeSelector.AttributeSelector 41 """ 23 42 24 43 xacmlType = self.__class__.TYPE -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/attributevaluereader.py
r7087 r7109 19 19 class AttributeValueReader(ExpressionReader): 20 20 '''ElementTree based XACML Expression type parser 21 22 @cvar TYPE: XACML class type that this reader will read values into 23 @type TYPE: abc.ABCMeta 24 25 @cvar FACTORY: factory function for returning an Attribute value type for a 26 given XACML Attribute value URI 27 @type FACTORY: ndg.xacml.core.attributevalue.AttributeValueClassFactory 21 28 ''' 22 29 TYPE = AttributeValue … … 27 34 _parseExtension since AttributeValue class is virtual. A sub-type can 28 35 be instantiated only once the data type attribute is parsed 36 37 @param obj: input object to parse 38 @type obj: ElementTree Element, or stream object 39 @return: new XACML attribute value instance 40 @rtype: ndg.xacml.core.attributevalue.AttributeValue derived type 41 @raise XMLParseError: error reading element 29 42 """ 30 43 elem = super(AttributeValueReader, self)._parse(obj) … … 55 68 56 69 def _parseExtension(self, elem, attributeValue): 70 """Parse XML Attribute value element 71 72 @param elem: ElementTree XML element 73 @type elem: xml.etree.Element 74 75 @param attributeValue: attribute selector to be updated with parsed 76 values 77 @type attributeValue: ndg.xacml.core.attributevalue.AttributeValue 78 79 @raise XMLParseError: error parsing attribute ID XML attribute 80 """ 57 81 if elem.text is None: 58 82 raise XMLParseError('No attribute value element found parsing %r' % -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/conditionreader.py
r7087 r7109 23 23 24 24 @cvar TYPE: XACML type to instantiate from parsed object 25 @type string: type25 @type TYPE: type 26 26 ''' 27 27 TYPE = Condition 28 28 29 29 def __call__(self, obj): 30 """Parse policy object""" 30 """Parse condition object 31 32 @param obj: input object to parse 33 @type obj: ElementTree Element, or stream object 34 @return: new XACML condition instance 35 @rtype: ndg.xacml.core.condition.Condition 36 @raise XMLParseError: error reading sub-elements 37 """ 31 38 elem = super(ConditionReader, self)._parse(obj) 32 39 -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/environmentreader.py
r7087 r7109 17 17 '''ElementTree based XACML Rule parser 18 18 @cvar TYPE: XACML type to instantiate from parsed object 19 @type string: type19 @type TYPE: type 20 20 ''' 21 TYPE = Environment 21 TYPE = Environment 22 -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/expressionreader.py
r7087 r7109 20 20 class ExpressionReader(ETreeAbstractReader): 21 21 '''ElementTree based XACML Expression type parser 22 23 @cvar TYPE: XACML type to instantiate from parsed object 24 @type TYPE: abc.ABCMeta 22 25 ''' 23 26 TYPE = Expression 24 27 25 28 def __call__(self, obj): 26 """Parse AttributeValue object""" 29 """Parse Expression object 30 31 @param obj: input object to parse 32 @type obj: ElementTree Element, or stream object 33 @return: new XACML expression instance 34 @rtype: ndg.xacml.core.expression.Expression derived type 35 @raise XMLParseError: error reading element 36 """ 27 37 elem = super(ExpressionReader, self)._parse(obj) 28 38 … … 55 65 def _parseExtension(self, elem, expression): 56 66 """Derived classes should implement this method to read any remaining 57 attributes and elements specific to their type""" 67 attributes and elements specific to their type 68 69 @param elem: ElementTree XML element 70 @type elem: xml.etree.Element 71 72 @param expression: attribute selector to be updated with parsed 73 values 74 @type expression: ndg.xacml.core.attributevalue.AttributeValue 75 76 77 @raise NotImplementedError: Derived classes should implement 78 """ 58 79 raise NotImplementedError() 59 80 -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/matchreader.py
r7087 r7109 22 22 '''ElementTree based XACML generic Match parser for subject, resource, 23 23 action and environment match types 24 25 @cvar ATTRIBUTE_DESIGNATOR_TYPE: type for attribute designator sub-elements: 26 derived class should set to relevant type e.g. for SubjectMatch, 27 SubjectAttributeDesignator 28 @type ATTRIBUTE_DESIGNATOR_TYPE: NoneType 24 29 ''' 25 30 ATTRIBUTE_DESIGNATOR_TYPE = None 26 31 27 32 def __init__(self): 33 """Virtual method 34 35 @raise NotImplementedError: ATTRIBUTE_DESIGNATOR_TYPE must be set in a 36 derived class 37 """ 28 38 if self.__class__.ATTRIBUTE_DESIGNATOR_TYPE is None: 29 39 raise NotImplementedError('Extend this class setting the ' 30 '"ATTRIBUTE_DESIGNATOR_TYPE" '31 ' classvariable')40 '"ATTRIBUTE_DESIGNATOR_TYPE" class ' 41 'variable') 32 42 33 43 super(MatchReaderBase, self).__init__() 34 44 35 45 def __call__(self, obj): 36 """Parse subject object""" 46 """Parse *Match object (where * = Subject, Resource, Environment or 47 Action 48 49 @param obj: input object to parse 50 @type obj: ElementTree Element, or stream object 51 @return: new XACML match instance 52 @rtype: ndg.xacml.core.matchreader.MatchReaderBase derived type 53 @raise XMLParseError: error reading element 54 """ 37 55 elem = super(MatchReaderBase, self)._parse(obj) 38 56 -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/policydefaultsreader.py
r7087 r7109 18 18 class PolicyDefaultsReader(ETreeAbstractReader): 19 19 '''ElementTree based XACML PolicyDefaults type parser 20 21 @cvar TYPE: XACML class type that this reader will read values into 22 @type TYPE: type 20 23 ''' 21 24 TYPE = PolicyDefaults 22 25 23 26 def __call__(self, obj): 24 """Parse AttributeValue object""" 27 """Parse Policy defaults object 28 29 @param obj: input object to parse 30 @type obj: ElementTree Element, or stream object 31 @return: new XACML expression instance 32 @rtype: ndg.xacml.core.policydefaults.PolicyDefaults derived type 33 @raise XMLParseError: error reading element 34 """ 25 35 elem = super(PolicyDefaultsReader, self)._parse(obj) 26 36 -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/policyreader.py
r7087 r7109 24 24 """Parse a Policy Document using ElementTree 25 25 @cvar TYPE: XACML type to instantiate from parsed object 26 @type string: type"""26 @type TYPE: type""" 27 27 TYPE = Policy 28 28 29 29 def __call__(self, obj): 30 """Parse policy object""" 30 """Parse policy object 31 32 @param obj: input object to parse 33 @type obj: ElementTree Element, or stream object 34 @return: new XACML expression instance 35 @rtype: ndg.xacml.core.policy.Policy derived type 36 @raise XMLParseError: error reading element 37 @raise NotImplementedError: parsing is not implemented for rule 38 combiner, combiner parameters and obligations elements. 39 """ 31 40 elem = super(PolicyReader, self)._parse(obj) 32 41 -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/reader.py
r7087 r7109 23 23 24 24 @cvar TYPE: XACML type to instantiate from parsed object 25 @type string: type"""25 @type TYPE: NoneType""" 26 26 TYPE = None 27 27 28 28 def __init__(self): 29 """Initialise ElementTree namespace map for XACML 2.0 namespaces 30 31 @raise NotImplementedError: TYPE class variable must be set in a 32 derived class 33 """ 29 34 if self.__class__.TYPE is None: 30 35 raise NotImplementedError('No "TYPE" class variable set to specify ' -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/resourceattributedesignatorreader.py
r7087 r7109 17 17 class ResourceAttributeDesignatorReader(AttributeDesignatorReaderBase): 18 18 '''ElementTree based XACML Resource Attribute Designator type parser 19 20 @cvar TYPE: XACML class type that this reader will read values into 21 @type TYPE: abc.ABCMeta 19 22 ''' 20 23 TYPE = ResourceAttributeDesignator -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/resourcematchreader.py
r7087 r7109 16 16 17 17 class ResourceMatchReader(MatchReaderBase): 18 """ElementTree based parser for XACML ResourceMatch""" 18 """ElementTree based parser for XACML ResourceMatch 19 20 @cvar TYPE: XACML class type that this reader will read values into 21 @type TYPE: abc.ABCMeta 22 23 @cvar ATTRIBUTE_DESIGNATOR_TYPE: type for attribute designator sub-elements 24 @type ATTRIBUTE_DESIGNATOR_TYPE: abc.ABCMeta 25 """ 19 26 TYPE = ResourceMatch 20 27 ATTRIBUTE_DESIGNATOR_TYPE = ResourceAttributeDesignator -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/resourcereader.py
r7087 r7109 17 17 '''ElementTree based XACML Rule parser 18 18 @cvar TYPE: XACML type to instantiate from parsed object 19 @type string: type19 @type TYPE: type 20 20 ''' 21 21 TYPE = Resource -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/rulereader.py
r7087 r7109 23 23 24 24 @cvar TYPE: XACML type to instantiate from parsed object 25 @type string: type25 @type TYPE: type 26 26 ''' 27 27 TYPE = Rule 28 28 29 29 def __call__(self, obj): 30 """Parse rule object""" 30 """Parse rule object 31 32 @param obj: input object to parse 33 @type obj: ElementTree Element, or stream object 34 @return: new XACML expression instance 35 @rtype: ndg.xacml.core.rule.Rule derived type 36 @raise XMLParseError: error reading element 37 """ 31 38 elem = super(RuleReader, self)._parse(obj) 32 39 -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/subjectattributedesignatorreader.py
r7087 r7109 17 17 class SubjectAttributeDesignatorReader(AttributeDesignatorReaderBase): 18 18 '''ElementTree based XACML Subject Attribute Designator type parser 19 20 @cvar TYPE: XACML class type that this reader will read values into 21 @type TYPE: abc.ABCMeta 19 22 ''' 20 23 TYPE = SubjectAttributeDesignator -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/subjectmatchreader.py
r7087 r7109 16 16 17 17 class SubjectMatchReader(MatchReaderBase): 18 """ElementTree based parser for XACML SubjectMatch""" 18 """ElementTree based parser for XACML SubjectMatch 19 20 @cvar TYPE: XACML class type that this reader will read values into 21 @type TYPE: abc.ABCMeta 22 23 @cvar ATTRIBUTE_DESIGNATOR_TYPE: type for attribute designator sub-elements 24 @type ATTRIBUTE_DESIGNATOR_TYPE: abc.ABCMeta 25 """ 19 26 TYPE = SubjectMatch 20 27 ATTRIBUTE_DESIGNATOR_TYPE = SubjectAttributeDesignator -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/subjectreader.py
r7087 r7109 17 17 '''ElementTree based XACML Rule parser 18 18 @cvar TYPE: XACML type to instantiate from parsed object 19 @type string: type19 @type TYPE: type 20 20 ''' 21 21 TYPE = Subject -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/targetchildreader.py
r7087 r7109 11 11 __contact__ = "Philip.Kershaw@stfc.ac.uk" 12 12 __revision__ = "$Id$" 13 from ndg.xacml.core.subject import Subject14 13 from ndg.xacml.parsers import XMLParseError 15 14 from ndg.xacml.parsers.etree import QName … … 21 20 '''ElementTree based XACML generic target child element parser 22 21 @cvar TYPE: XACML type to instantiate from parsed object 23 @type string: type22 @type TYPE: type 24 23 ''' 25 24 26 25 def __call__(self, obj): 27 """Parse subject object""" 26 """Parse target child element object 27 28 @param obj: input object to parse 29 @type obj: ElementTree Element, or stream object 30 @return: new XACML expression instance 31 @rtype: ndg.xacml.core.TargetChildBase derived type 32 @raise XMLParseError: error reading element 33 """ 28 34 elem = super(TargetChildReader, self)._parse(obj) 29 35 -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/targetreader.py
r7087 r7109 25 25 26 26 @cvar TYPE: XACML type to instantiate from parsed object 27 @type string: type""" 27 @type TYPE: type 28 """ 28 29 TYPE = Target 29 30 30 31 def __call__(self, obj): 32 """Parse Target object 33 34 @param obj: input object to parse 35 @type obj: ElementTree Element, or stream object 36 @return: new XACML expression instance 37 @rtype: ndg.xacml.core.target.Target derived type 38 @raise XMLParseError: error reading element 39 """ 31 40 elem = super(TargetReader, self)._parse(obj) 32 41 … … 67 76 "recognised" % localName) 68 77 69 return target 78 return target -
TI12-security/trunk/ndg_xacml/ndg/xacml/test/test_context.py
r7087 r7109 45 45 @param pepRequest: request from PEP, derived class determines its type 46 46 e.g. SAML AuthzDecisionQuery 47 @type pepRequest: type47 @type myRequest: type 48 48 @return: PEP response - derived class determines type 49 49 @rtype: None -
TI12-security/trunk/ndg_xacml/ndg/xacml/utils/__init__.py
r7087 r7109 19 19 from the list 20 20 """ 21 21 22 def extend(self, iter): 23 """Extend a list with input iterable 24 @param iter: iterable object 25 @type iter: iterable type 26 """ 22 27 return super(UniqList, self).extend([i for i in iter if i not in self]) 23 28 24 29 def __iadd__(self, iter): 30 """Extend a list with input iterable 31 @param iter: iterable object 32 @type iter: iterable type 33 """ 25 34 return super(UniqList, self).__iadd__([i for i in iter 26 35 if i not in self]) 27 36 28 37 def append(self, item): 38 """Add an item to the list 39 @param item: item to append to list 40 @type item: any 41 """ 29 42 for i in self: 30 43 if i == item: … … 50 63 51 64 def __repr__(self): 65 """@return: represent instance giving type information about the 66 elements 67 @rtype: string 68 """ 52 69 return "%r type: %s" % (self.__elementType, 53 70 super(TypedList, self).__repr__()) 54 71 55 72 def _getElementType(self): 73 """@return: the element type for this list 74 @rtype: type 75 """ 56 76 return self.__elementType 57 77 … … 60 80 61 81 def extend(self, iter): 82 """Extend a list with input iterable 83 @param iter: iterable object 84 @type iter: iterable type 85 @raise TypeError: input item doesn't match list type 86 """ 62 87 for i in iter: 63 88 if not isinstance(i, self.__elementType): … … 68 93 69 94 def __iadd__(self, iter): 95 """Extend a list with input iterable 96 @param iter: iterable object 97 @type iter: iterable type 98 @raise TypeError: input item doesn't match list type 99 """ 70 100 for i in iter: 71 101 if not isinstance(i, self.__elementType): … … 76 106 77 107 def append(self, item): 108 """Add an item to the list 109 @param iter: iterable object 110 @type iter: iterable type 111 @raise TypeError: input item doesn't match list type 112 """ 78 113 if not isinstance(item, self.__elementType): 79 114 raise TypeError("List items must be of type %s" % … … 95 130 96 131 def __setitem__(self, key, val): 132 """@param key: key for item to set 133 @type key: any 134 @param val: value to set for this key 135 @type val: any 136 """ 97 137 if key not in self.__keyNames: 98 138 raise KeyError('Key name %r not recognised. Valid key names ' … … 102 142 103 143 def update(self, d, **kw): 144 """@param d: dictionary to update from 145 @type d: dict 146 @param kw: keywords to update dictionary with 147 @type kw: dict 148 """ 104 149 for dictArg in (d, kw): 105 150 for k in dictArg: … … 117 162 class VettedDict(UserDict.DictMixin): 118 163 """Enforce custom checking on keys and items before addition to a 119 dictionary""" 164 dictionary 165 """ 120 166 121 167 def __init__(self, *args): … … 145 191 filtered out. Filter functions may also raise an exception if they 146 192 wish to abort completely 193 194 @param key: dict key to check 195 @type key: basestring 196 @param val: value to check 197 @type val: any 147 198 """ 148 199 if not self.__KeyFilter(key): … … 156 207 157 208 def __setitem__(self, key, val): 158 """Enforce type checking when setting new items""" 209 """Enforce type checking when setting new items 210 211 @param key: key for item to set 212 @type key: any 213 @param val: value to set for this key 214 @type val: any 215 """ 159 216 if self._verifyKeyValPair(key, val): 160 217 self.__map[key] = val 161 218 162 219 def __getitem__(self, key): 163 """Provde implementation for getting items""" 220 """Provide implementation for getting items 221 @param key: key for item to retrieve 222 @type key: any 223 @return: value for input key 224 @rtype: any 225 """ 164 226 if key not in self.__map: 165 227 raise KeyError('%r key not found in dict' % key) … … 168 230 169 231 def get(self, key, *arg): 170 """Provide implementation of get item with default""" 232 """Provide implementation of get item with default 233 234 @param key: key for item to retrieve 235 @type key: any 236 @param arg: use to set a default argument 237 @type arg: tuple 238 """ 171 239 if key in self.__map: 172 240 return self.__map[key]
Note: See TracChangeset
for help on using the changeset viewer.