<s> import sys <EOL> from pyasn1 . type import constraint , tagmap , tag <EOL> from pyasn1 import error <EOL> class Asn1Item : pass <EOL> class Asn1ItemBase ( Asn1Item ) : <EOL> tagSet = tag . TagSet ( ) <EOL> subtypeSpec = constraint . ConstraintsIntersection ( ) <EOL> typeId = None <EOL> def __init__ ( self , tagSet = None , subtypeSpec = None ) : <EOL> if tagSet is None : <EOL> self . _tagSet = self . tagSet <EOL> else : <EOL> self . _tagSet = tagSet <EOL> if subtypeSpec is None : <EOL> self . _subtypeSpec = self . subtypeSpec <EOL> else : <EOL> self . _subtypeSpec = subtypeSpec <EOL> def _verifySubtypeSpec ( self , value , idx = None ) : <EOL> try : <EOL> self . _subtypeSpec ( value , idx ) <EOL> except error . PyAsn1Error : <EOL> c , i , t = sys . exc_info ( ) <EOL> raise c ( '<STR_LIT>' % ( i , self . __class__ . __name__ ) ) <EOL> def getSubtypeSpec ( self ) : return self . _subtypeSpec <EOL> def getTagSet ( self ) : return self . _tagSet <EOL> def getEffectiveTagSet ( self ) : return self . _tagSet <EOL> def getTagMap ( self ) : return tagmap . TagMap ( { self . _tagSet : self } ) <EOL> def isSameTypeWith ( self , other , matchTags = True , matchConstraints = True ) : <EOL> return self is other or ( not matchTags or self . _tagSet == other . getTagSet ( ) ) and ( not matchConstraints or self . _subtypeSpec == other . getSubtypeSpec ( ) ) <EOL> def isSuperTypeOf ( self , other , matchTags = True , matchConstraints = True ) : <EOL> """<STR_LIT>""" <EOL> return ( not matchTags or self . _tagSet . isSuperTagSetOf ( other . getTagSet ( ) ) ) and ( not matchConstraints or ( self . _subtypeSpec . isSuperTypeOf ( other . getSubtypeSpec ( ) ) ) ) <EOL> class NoValue : <EOL> def __getattr__ ( self , attr ) : <EOL> raise error . PyAsn1Error ( '<STR_LIT>' % attr ) <EOL> def __getitem__ ( self , i ) : <EOL> raise error . PyAsn1Error ( '<STR_LIT>' ) <EOL> def __repr__ ( self ) : return '<STR_LIT>' % self . __class__ . __name__ <EOL> noValue = NoValue ( ) <EOL> class AbstractSimpleAsn1Item ( Asn1ItemBase ) : <EOL> defaultValue = noValue <EOL> def __init__ ( self , value = None , tagSet = None , subtypeSpec = None ) : <EOL> Asn1ItemBase . __init__ ( self , tagSet , subtypeSpec ) <EOL> if value is None or value is noValue : <EOL> value = self . defaultValue <EOL> if value is None or value is noValue : <EOL> self . __hashedValue = value = noValue <EOL> else : <EOL> value = self . prettyIn ( value ) <EOL> self . _verifySubtypeSpec ( value ) <EOL> self . __hashedValue = hash ( value ) <EOL> self . _value = value <EOL> self . _len = None <EOL> def __repr__ ( self ) : <EOL> r = [ ] <EOL> if self . _value is not self . defaultValue : <EOL> r . append ( self . prettyOut ( self . _value ) ) <EOL> if self . _tagSet is not self . tagSet : <EOL> r . append ( '<STR_LIT>' % ( self . _tagSet , ) ) <EOL> if self . _subtypeSpec is not self . subtypeSpec : <EOL> r . append ( '<STR_LIT>' % ( self . _subtypeSpec , ) ) <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , '<STR_LIT:U+002CU+0020>' . join ( r ) ) <EOL> def __str__ ( self ) : return str ( self . _value ) <EOL> def __eq__ ( self , other ) : <EOL> return self is other and True or self . _value == other <EOL> def __ne__ ( self , other ) : return self . _value != other <EOL> def __lt__ ( self , other ) : return self . _value < other <EOL> def __le__ ( self , other ) : return self . _value <= other <EOL> def __gt__ ( self , other ) : return self . _value > other <EOL> def __ge__ ( self , other ) : return self . _value >= other <EOL> if sys . version_info [ <NUM_LIT:0> ] <= <NUM_LIT:2> : <EOL> def __nonzero__ ( self ) : return bool ( self . _value ) <EOL> else : <EOL> def __bool__ ( self ) : return bool ( self . _value ) <EOL> def __hash__ ( self ) : return self . __hashedValue <EOL> def hasValue ( self ) : <EOL> return not isinstance ( self . _value , NoValue ) <EOL> def clone ( self , value = None , tagSet = None , subtypeSpec = None ) : <EOL> if value is None and tagSet is None and subtypeSpec is None : <EOL> return self <EOL> if value is None : <EOL> value = self . _value <EOL> if tagSet is None : <EOL> tagSet = self . _tagSet <EOL> if subtypeSpec is None : <EOL> subtypeSpec = self . _subtypeSpec <EOL> return self . __class__ ( value , tagSet , subtypeSpec ) <EOL> def subtype ( self , value = None , implicitTag = None , explicitTag = None , <EOL> subtypeSpec = None ) : <EOL> if value is None : <EOL> value = self . _value <EOL> if implicitTag is not None : <EOL> tagSet = self . _tagSet . tagImplicitly ( implicitTag ) <EOL> elif explicitTag is not None : <EOL> tagSet = self . _tagSet . tagExplicitly ( explicitTag ) <EOL> else : <EOL> tagSet = self . _tagSet <EOL> if subtypeSpec is None : <EOL> subtypeSpec = self . _subtypeSpec <EOL> else : <EOL> subtypeSpec = subtypeSpec + self . _subtypeSpec <EOL> return self . __class__ ( value , tagSet , subtypeSpec ) <EOL> def prettyIn ( self , value ) : return value <EOL> def prettyOut ( self , value ) : return str ( value ) <EOL> def prettyPrint ( self , scope = <NUM_LIT:0> ) : <EOL> if self . hasValue ( ) : <EOL> return self . prettyOut ( self . _value ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> def prettyPrinter ( self , scope = <NUM_LIT:0> ) : return self . prettyPrint ( scope ) <EOL> def prettyPrintType ( self , scope = <NUM_LIT:0> ) : <EOL> return '<STR_LIT>' % ( self . getTagSet ( ) , self . __class__ . __name__ ) <EOL> class AbstractConstructedAsn1Item ( Asn1ItemBase ) : <EOL> componentType = None <EOL> sizeSpec = constraint . ConstraintsIntersection ( ) <EOL> def __init__ ( self , componentType = None , tagSet = None , <EOL> subtypeSpec = None , sizeSpec = None ) : <EOL> Asn1ItemBase . __init__ ( self , tagSet , subtypeSpec ) <EOL> if componentType is None : <EOL> self . _componentType = self . componentType <EOL> else : <EOL> self . _componentType = componentType <EOL> if sizeSpec is None : <EOL> self . _sizeSpec = self . sizeSpec <EOL> else : <EOL> self . _sizeSpec = sizeSpec <EOL> self . _componentValues = [ ] <EOL> self . _componentValuesSet = <NUM_LIT:0> <EOL> def __repr__ ( self ) : <EOL> r = [ ] <EOL> if self . _componentType is not self . componentType : <EOL> r . append ( '<STR_LIT>' % ( self . _componentType , ) ) <EOL> if self . _tagSet is not self . tagSet : <EOL> r . append ( '<STR_LIT>' % ( self . _tagSet , ) ) <EOL> if self . _subtypeSpec is not self . subtypeSpec : <EOL> r . append ( '<STR_LIT>' % ( self . _subtypeSpec , ) ) <EOL> r = '<STR_LIT>' % ( self . __class__ . __name__ , '<STR_LIT:U+002CU+0020>' . join ( r ) ) <EOL> if self . _componentValues : <EOL> r += '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( [ repr ( x ) for x in self . _componentValues ] ) <EOL> return r <EOL> def __eq__ ( self , other ) : <EOL> return self is other and True or self . _componentValues == other <EOL> def __ne__ ( self , other ) : return self . _componentValues != other <EOL> def __lt__ ( self , other ) : return self . _componentValues < other <EOL> def __le__ ( self , other ) : return self . _componentValues <= other <EOL> def __gt__ ( self , other ) : return self . _componentValues > other <EOL> def __ge__ ( self , other ) : return self . _componentValues >= other <EOL> if sys . version_info [ <NUM_LIT:0> ] <= <NUM_LIT:2> : <EOL> def __nonzero__ ( self ) : return bool ( self . _componentValues ) <EOL> else : <EOL> def __bool__ ( self ) : return bool ( self . _componentValues ) <EOL> def getComponentTagMap ( self ) : <EOL> raise error . PyAsn1Error ( '<STR_LIT>' ) <EOL> def _cloneComponentValues ( self , myClone , cloneValueFlag ) : pass <EOL> def clone ( self , tagSet = None , subtypeSpec = None , sizeSpec = None , <EOL> cloneValueFlag = None ) : <EOL> if tagSet is None : <EOL> tagSet = self . _tagSet <EOL> if subtypeSpec is None : <EOL> subtypeSpec = self . _subtypeSpec <EOL> if sizeSpec is None : <EOL> sizeSpec = self . _sizeSpec <EOL> r = self . __class__ ( self . _componentType , tagSet , subtypeSpec , sizeSpec ) <EOL> if cloneValueFlag : <EOL> self . _cloneComponentValues ( r , cloneValueFlag ) <EOL> return r <EOL> def subtype ( self , implicitTag = None , explicitTag = None , subtypeSpec = None , <EOL> sizeSpec = None , cloneValueFlag = None ) : <EOL> if implicitTag is not None : <EOL> tagSet = self . _tagSet . tagImplicitly ( implicitTag ) <EOL> elif explicitTag is not None : <EOL> tagSet = self . _tagSet . tagExplicitly ( explicitTag ) <EOL> else : <EOL> tagSet = self . _tagSet <EOL> if subtypeSpec is None : <EOL> subtypeSpec = self . _subtypeSpec <EOL> else : <EOL> subtypeSpec = subtypeSpec + self . _subtypeSpec <EOL> if sizeSpec is None : <EOL> sizeSpec = self . _sizeSpec <EOL> else : <EOL> sizeSpec = sizeSpec + self . _sizeSpec <EOL> r = self . __class__ ( self . _componentType , tagSet , subtypeSpec , sizeSpec ) <EOL> if cloneValueFlag : <EOL> self . _cloneComponentValues ( r , cloneValueFlag ) <EOL> return r <EOL> def _verifyComponent ( self , idx , value ) : pass <EOL> def verifySizeSpec ( self ) : self . _sizeSpec ( self ) <EOL> def getComponentByPosition ( self , idx ) : <EOL> raise error . PyAsn1Error ( '<STR_LIT>' ) <EOL> def setComponentByPosition ( self , idx , value , verifyConstraints = True ) : <EOL> raise error . PyAsn1Error ( '<STR_LIT>' ) <EOL> def setComponents ( self , * args , ** kwargs ) : <EOL> for idx in range ( len ( args ) ) : <EOL> self [ idx ] = args [ idx ] <EOL> for k in kwargs : <EOL> self [ k ] = kwargs [ k ] <EOL> return self <EOL> def getComponentType ( self ) : return self . _componentType <EOL> def setDefaultComponents ( self ) : pass <EOL> def __getitem__ ( self , idx ) : return self . getComponentByPosition ( idx ) <EOL> def __setitem__ ( self , idx , value ) : self . setComponentByPosition ( idx , value ) <EOL> def __len__ ( self ) : return len ( self . _componentValues ) <EOL> def clear ( self ) : <EOL> self . _componentValues = [ ] <EOL> self . _componentValuesSet = <NUM_LIT:0> </s>
