<s> try : <EOL> from sys import version_info <EOL> except ImportError : <EOL> version_info = ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> from operator import getslice <EOL> from types import SliceType <EOL> from string import join <EOL> from pyasn1 import error <EOL> tagClassUniversal = <NUM_LIT> <EOL> tagClassApplication = <NUM_LIT> <EOL> tagClassContext = <NUM_LIT> <EOL> tagClassPrivate = <NUM_LIT> <EOL> tagFormatSimple = <NUM_LIT> <EOL> tagFormatConstructed = <NUM_LIT> <EOL> tagCategoryImplicit = <NUM_LIT> <EOL> tagCategoryExplicit = <NUM_LIT> <EOL> tagCategoryUntagged = <NUM_LIT> <EOL> class Tag : <EOL> def __init__ ( self , tagClass , tagFormat , tagId ) : <EOL> if tagId < <NUM_LIT:0> : <EOL> raise error . PyAsn1Error ( <EOL> '<STR_LIT>' % tagId <EOL> ) <EOL> self . __tag = ( tagClass , tagFormat , tagId ) <EOL> self . __uniqTag = ( tagClass , tagId ) <EOL> self . __hashedUniqTag = hash ( self . __uniqTag ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> ( self . __class__ . __name__ , ) + self . __tag <EOL> ) <EOL> def __cmp__ ( self , other ) : return cmp ( self . __uniqTag , other ) <EOL> def __eq__ ( self , other ) : <EOL> return self is other or self . __hashedUniqTag == other <EOL> def __ne__ ( self , other ) : <EOL> return not ( self is other ) and self . __hashedUniqTag != other <EOL> def __hash__ ( self ) : return self . __hashedUniqTag <EOL> def __getitem__ ( self , idx ) : return self . __tag [ idx ] <EOL> def __and__ ( self , ( tagClass , tagFormat , tagId ) ) : <EOL> return self . __class__ ( <EOL> self . __tag & tagClass , self . __tag & tagFormat , self . __tag & tagId <EOL> ) <EOL> def __or__ ( self , ( tagClass , tagFormat , tagId ) ) : <EOL> return self . __class__ ( <EOL> self . __tag [ <NUM_LIT:0> ] | tagClass , self . __tag [ <NUM_LIT:1> ] | tagFormat , self . __tag [ <NUM_LIT:2> ] | tagId <EOL> ) <EOL> class TagSet : <EOL> def __init__ ( self , baseTag = ( ) , * superTags ) : <EOL> self . __baseTag = baseTag <EOL> self . __superTags = superTags <EOL> self . __hashedSuperTags = hash ( superTags ) <EOL> self . __lenOfSuperTags = len ( superTags ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> join ( map ( lambda x : repr ( x ) , self . __superTags ) , '<STR_LIT:U+002CU+0020>' ) <EOL> ) <EOL> def __add__ ( self , superTag ) : <EOL> return apply ( <EOL> self . __class__ , ( self . __baseTag , ) + self . __superTags + ( superTag , ) <EOL> ) <EOL> def __radd__ ( self , superTag ) : <EOL> return apply ( <EOL> self . __class__ , ( self . __baseTag , superTag ) + self . __superTags <EOL> ) <EOL> def tagExplicitly ( self , superTag ) : <EOL> tagClass , tagFormat , tagId = superTag <EOL> if tagClass == tagClassUniversal : <EOL> raise error . PyAsn1Error ( <EOL> '<STR_LIT>' <EOL> ) <EOL> if tagFormat != tagFormatConstructed : <EOL> superTag = Tag ( tagClass , tagFormatConstructed , tagId ) <EOL> return self + superTag <EOL> def tagImplicitly ( self , superTag ) : <EOL> tagClass , tagFormat , tagId = superTag <EOL> if self . __superTags : <EOL> superTag = Tag ( tagClass , self . __superTags [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] , tagId ) <EOL> return self [ : - <NUM_LIT:1> ] + superTag <EOL> def getBaseTag ( self ) : return self . __baseTag <EOL> def __getitem__ ( self , idx ) : <EOL> if type ( idx ) == SliceType : <EOL> return apply ( self . __class__ , <EOL> ( self . __baseTag , ) + getslice ( self . __superTags , <EOL> idx . start , idx . stop ) ) <EOL> return self . __superTags [ idx ] <EOL> if version_info < ( <NUM_LIT:2> , <NUM_LIT:0> ) : <EOL> def __getslice__ ( self , i , j ) : <EOL> return self [ max ( <NUM_LIT:0> , i ) : max ( <NUM_LIT:0> , j ) : ] <EOL> def __cmp__ ( self , other ) : return cmp ( self . __superTags , other ) <EOL> def __eq__ ( self , other ) : <EOL> return self is other or self . __hashedSuperTags == other <EOL> def __ne__ ( self , other ) : <EOL> return not ( self is other ) and self . __hashedSuperTags != other <EOL> def __hash__ ( self ) : return self . __hashedSuperTags <EOL> def __len__ ( self ) : return self . __lenOfSuperTags <EOL> def isSuperTagSetOf ( self , tagSet ) : <EOL> if len ( tagSet ) < self . __lenOfSuperTags : <EOL> return <EOL> idx = self . __lenOfSuperTags - <NUM_LIT:1> <EOL> while idx >= <NUM_LIT:0> : <EOL> if self . __superTags [ idx ] != tagSet [ idx ] : <EOL> return <EOL> idx = idx - <NUM_LIT:1> <EOL> return <NUM_LIT:1> <EOL> def initTagSet ( tag ) : return TagSet ( tag , tag ) </s>
