<s> import time <EOL> import logging <EOL> from pyasn1 . compat . octets import octs2ints <EOL> from pyasn1 import error <EOL> from pyasn1 import __version__ <EOL> flagNone = <NUM_LIT> <EOL> flagEncoder = <NUM_LIT> <EOL> flagDecoder = <NUM_LIT> <EOL> flagAll = <NUM_LIT> <EOL> flagMap = { <EOL> '<STR_LIT>' : flagEncoder , <EOL> '<STR_LIT>' : flagDecoder , <EOL> '<STR_LIT:all>' : flagAll <EOL> } <EOL> class Printer : <EOL> def __init__ ( self , logger = None , handler = None , formatter = None ) : <EOL> if logger is None : <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . setLevel ( logging . DEBUG ) <EOL> if handler is None : <EOL> handler = logging . StreamHandler ( ) <EOL> if formatter is None : <EOL> formatter = logging . Formatter ( '<STR_LIT>' ) <EOL> handler . setFormatter ( formatter ) <EOL> handler . setLevel ( logging . DEBUG ) <EOL> logger . addHandler ( handler ) <EOL> self . __logger = logger <EOL> def __call__ ( self , msg ) : self . __logger . debug ( msg ) <EOL> def __str__ ( self ) : return '<STR_LIT>' <EOL> if hasattr ( logging , '<STR_LIT>' ) : <EOL> NullHandler = logging . NullHandler <EOL> else : <EOL> class NullHandler ( logging . Handler ) : <EOL> def emit ( self , record ) : <EOL> pass <EOL> class Debug : <EOL> defaultPrinter = None <EOL> def __init__ ( self , * flags , ** options ) : <EOL> self . _flags = flagNone <EOL> if options . get ( '<STR_LIT>' ) is not None : <EOL> self . _printer = options . get ( '<STR_LIT>' ) <EOL> elif self . defaultPrinter is not None : <EOL> self . _printer = self . defaultPrinter <EOL> if '<STR_LIT>' in options : <EOL> self . _printer = Printer ( <EOL> logger = logging . getLogger ( options [ '<STR_LIT>' ] ) , <EOL> handler = NullHandler ( ) <EOL> ) <EOL> else : <EOL> self . _printer = Printer ( ) <EOL> self ( '<STR_LIT>' % __version__ ) <EOL> for f in flags : <EOL> inverse = f and f [ <NUM_LIT:0> ] in ( '<STR_LIT:!>' , '<STR_LIT>' ) <EOL> if inverse : <EOL> f = f [ <NUM_LIT:1> : ] <EOL> try : <EOL> if inverse : <EOL> self . _flags &= ~ flagMap [ f ] <EOL> else : <EOL> self . _flags |= flagMap [ f ] <EOL> except KeyError : <EOL> raise error . PyAsn1Error ( '<STR_LIT>' % f ) <EOL> self ( '<STR_LIT>' % ( f , inverse and '<STR_LIT>' or '<STR_LIT>' ) ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( self . _printer , self . _flags ) <EOL> def __call__ ( self , msg ) : <EOL> self . _printer ( msg ) <EOL> def __and__ ( self , flag ) : <EOL> return self . _flags & flag <EOL> def __rand__ ( self , flag ) : <EOL> return flag & self . _flags <EOL> logger = <NUM_LIT:0> <EOL> def setLogger ( l ) : <EOL> global logger <EOL> logger = l <EOL> def hexdump ( octets ) : <EOL> return '<STR_LIT:U+0020>' . join ( <EOL> [ '<STR_LIT>' % ( n % <NUM_LIT:16> == <NUM_LIT:0> and ( '<STR_LIT>' % n ) or '<STR_LIT>' , x ) <EOL> for n , x in zip ( range ( len ( octets ) ) , octs2ints ( octets ) ) ] <EOL> ) <EOL> class Scope : <EOL> def __init__ ( self ) : <EOL> self . _list = [ ] <EOL> def __str__ ( self ) : return '<STR_LIT:.>' . join ( self . _list ) <EOL> def push ( self , token ) : <EOL> self . _list . append ( token ) <EOL> def pop ( self ) : <EOL> return self . _list . pop ( ) <EOL> scope = Scope ( ) </s>
