<s> '''<STR_LIT>''' <EOL> import sys <EOL> from decimal import Decimal <EOL> from fractions import Fraction <EOL> from collections import OrderedDict , MutableSet <EOL> if sys . version [ <NUM_LIT:0> ] >= '<STR_LIT:3>' : <EOL> import builtins <EOL> builtins . __dict__ [ '<STR_LIT>' ] = str <EOL> builtins . __dict__ [ '<STR_LIT>' ] = str <EOL> builtins . __dict__ [ '<STR_LIT>' ] = str <EOL> builtins . __dict__ [ '<STR_LIT>' ] = int <EOL> builtins . __dict__ [ '<STR_LIT>' ] = int <EOL> builtins . __dict__ [ '<STR_LIT>' ] = ( int , float , Decimal , Fraction ) <EOL> builtins . __dict__ [ '<STR_LIT>' ] = ( str , int , float , Decimal , Fraction ) <EOL> builtins . __dict__ [ '<STR_LIT>' ] = range <EOL> def noop ( x ) : return x <EOL> builtins . __dict__ [ '<STR_LIT>' ] = noop <EOL> else : <EOL> __builtins__ [ '<STR_LIT>' ] = str <EOL> __builtins__ [ '<STR_LIT>' ] = basestring <EOL> __builtins__ [ '<STR_LIT>' ] = unicode <EOL> __builtins__ [ '<STR_LIT>' ] = long <EOL> __builtins__ [ '<STR_LIT>' ] = ( int , long ) <EOL> __builtins__ [ '<STR_LIT>' ] = ( int , long , float , Decimal , Fraction ) <EOL> __builtins__ [ '<STR_LIT>' ] = ( basestring , int , long , float , Decimal , Fraction ) <EOL> __builtins__ [ '<STR_LIT>' ] = xrange <EOL> __builtins__ [ '<STR_LIT>' ] = set <EOL> import math <EOL> if sys . version >= "<STR_LIT>" : <EOL> __builtins__ [ '<STR_LIT>' ] = math . isfinite <EOL> else : <EOL> def simulatedIsFinite ( num ) : <EOL> return not math . isinf ( num ) and not math . isnan ( num ) <EOL> __builtins__ [ '<STR_LIT>' ] = simulatedIsFinite <EOL> def py3unquote ( string , encoding = '<STR_LIT:utf-8>' , errors = '<STR_LIT:replace>' ) : <EOL> """<STR_LIT>""" <EOL> if string == '<STR_LIT>' : <EOL> return string <EOL> res = string . split ( '<STR_LIT:%>' ) <EOL> if len ( res ) == <NUM_LIT:1> : <EOL> return string <EOL> if encoding is None : <EOL> encoding = '<STR_LIT:utf-8>' <EOL> if errors is None : <EOL> errors = '<STR_LIT:replace>' <EOL> pct_sequence = b'<STR_LIT>' <EOL> string = res [ <NUM_LIT:0> ] <EOL> for item in res [ <NUM_LIT:1> : ] : <EOL> try : <EOL> if not item : <EOL> raise ValueError <EOL> pct_sequence += _STR_8BIT ( bytearray . fromhex ( item [ : <NUM_LIT:2> ] ) ) <EOL> rest = item [ <NUM_LIT:2> : ] <EOL> if not rest : <EOL> continue <EOL> except ValueError : <EOL> rest = '<STR_LIT:%>' + item <EOL> string += pct_sequence . decode ( encoding , errors ) + rest <EOL> pct_sequence = b'<STR_LIT>' <EOL> if pct_sequence : <EOL> string += pct_sequence . decode ( encoding , errors ) <EOL> return string <EOL> def pyTypeName ( object ) : <EOL> try : <EOL> objectClass = object . __class__ <EOL> classModule = objectClass . __module__ <EOL> className = objectClass . __name__ <EOL> if sys . version [ <NUM_LIT:0> ] >= '<STR_LIT:3>' : <EOL> if classModule == '<STR_LIT>' : <EOL> return className <EOL> else : <EOL> if classModule == '<STR_LIT>' : <EOL> return className <EOL> fullname = classModule + '<STR_LIT:.>' + className <EOL> if fullname == '<STR_LIT>' : <EOL> if object . dateOnly : <EOL> fullname += '<STR_LIT>' <EOL> else : <EOL> fullname += '<STR_LIT>' <EOL> return fullname <EOL> except : <EOL> return str ( type ( object ) ) <EOL> def pyNamedObject ( name ) : <EOL> try : <EOL> if sys . version [ <NUM_LIT:0> ] >= '<STR_LIT:3>' : <EOL> import builtins <EOL> return builtins . __dict__ [ name ] <EOL> else : <EOL> import __builtin__ <EOL> return __builtin__ . __dict__ [ name ] <EOL> except : <EOL> return None <EOL> def strTruncate ( value , length ) : <EOL> _s = str ( value ) . strip ( ) <EOL> if len ( _s ) <= length : <EOL> return _s <EOL> return _s [ <NUM_LIT:0> : length ] + "<STR_LIT>" <EOL> SEQUENCE_TYPES = ( tuple , list , set ) <EOL> def flattenSequence ( x , sequence = None ) : <EOL> if sequence is None : <EOL> if not isinstance ( x , SEQUENCE_TYPES ) : <EOL> if x is None : <EOL> return [ ] <EOL> return [ x ] <EOL> sequence = [ ] <EOL> for el in x : <EOL> if isinstance ( el , SEQUENCE_TYPES ) : <EOL> flattenSequence ( el , sequence ) <EOL> else : <EOL> sequence . append ( el ) <EOL> return sequence <EOL> class attrdict ( dict ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> dict . __init__ ( self , * args , ** kwargs ) <EOL> self . __dict__ = self <EOL> class OrderedDefaultDict ( OrderedDict ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args ) : <EOL> self . default_factory = None <EOL> if len ( args ) > <NUM_LIT:0> : <EOL> self . default_factory = args [ <NUM_LIT:0> ] <EOL> if len ( args ) > <NUM_LIT:1> : <EOL> super ( OrderedDefaultDict , self ) . __init__ ( args [ <NUM_LIT:1> ] ) <EOL> else : <EOL> super ( OrderedDefaultDict , self ) . __init__ ( ) <EOL> def __missing__ ( self , key ) : <EOL> if self . default_factory is None : <EOL> raise KeyError ( key ) <EOL> _missingValue = self . default_factory ( ) <EOL> self [ key ] = _missingValue <EOL> return _missingValue <EOL> class OrderedSet ( MutableSet ) : <EOL> def __init__ ( self , iterable = None ) : <EOL> self . end = end = [ ] <EOL> end += [ None , end , end ] <EOL> self . map = { } <EOL> if iterable is not None : <EOL> self |= iterable <EOL> def __len__ ( self ) : <EOL> return len ( self . map ) <EOL> def __contains__ ( self , key ) : <EOL> return key in self . map <EOL> def add ( self , key ) : <EOL> if key not in self . map : <EOL> end = self . end <EOL> curr = end [ <NUM_LIT:1> ] <EOL> curr [ <NUM_LIT:2> ] = end [ <NUM_LIT:1> ] = self . map [ key ] = [ key , curr , end ] <EOL> def update ( self , other ) : <EOL> s |= other <EOL> def discard ( self , key ) : <EOL> if key in self . map : <EOL> key , prev , next = self . map . pop ( key ) <EOL> prev [ <NUM_LIT:2> ] = next <EOL> next [ <NUM_LIT:1> ] = prev <EOL> def __iter__ ( self ) : <EOL> end = self . end <EOL> curr = end [ <NUM_LIT:2> ] <EOL> while curr is not end : <EOL> yield curr [ <NUM_LIT:0> ] <EOL> curr = curr [ <NUM_LIT:2> ] <EOL> def __reversed__ ( self ) : <EOL> end = self . end <EOL> curr = end [ <NUM_LIT:1> ] <EOL> while curr is not end : <EOL> yield curr [ <NUM_LIT:0> ] <EOL> curr = curr [ <NUM_LIT:1> ] <EOL> def pop ( self , last = True ) : <EOL> if not self : <EOL> raise KeyError ( '<STR_LIT>' ) <EOL> key = self . end [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] if last else self . end [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] <EOL> self . discard ( key ) <EOL> return key <EOL> def __repr__ ( self ) : <EOL> if not self : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , ) <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , list ( self ) ) <EOL> def __eq__ ( self , other ) : <EOL> if isinstance ( other , OrderedSet ) : <EOL> return len ( self ) == len ( other ) and list ( self ) == list ( other ) <EOL> return set ( self ) == set ( other ) <EOL> def Fraction ( numerator , denominator = None ) : <EOL> if denominator is None : <EOL> if isinstance ( numerator , ( Fraction , _STR_UNICODE , Decimal ) ) : <EOL> return Fraction ( numerator ) <EOL> elif isinstance ( numerator , Decimal ) and isinstance ( denominator , Decimal ) : <EOL> return Fraction ( int ( numerator ) , int ( denominator ) ) <EOL> return Fraction ( numerator , denominator ) </s>
