<s> """<STR_LIT>""" <EOL> from UserDict import DictMixin <EOL> try : <EOL> all <EOL> except NameError : <EOL> def all ( seq ) : <EOL> for elem in seq : <EOL> if not elem : <EOL> return False <EOL> return True <EOL> class OrderedDict ( dict , DictMixin ) : <EOL> def __init__ ( self , * args , ** kwds ) : <EOL> if len ( args ) > <NUM_LIT:1> : <EOL> raise TypeError ( '<STR_LIT>' % len ( args ) ) <EOL> try : <EOL> self . __end <EOL> except AttributeError : <EOL> self . clear ( ) <EOL> self . update ( * args , ** kwds ) <EOL> def clear ( self ) : <EOL> self . __end = end = [ ] <EOL> end += [ None , end , end ] <EOL> self . __map = { } <EOL> dict . clear ( self ) <EOL> def __setitem__ ( self , key , value ) : <EOL> if key not in self : <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> dict . __setitem__ ( self , key , value ) <EOL> def __delitem__ ( self , key ) : <EOL> dict . __delitem__ ( self , key ) <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 popitem ( self , last = True ) : <EOL> if not self : <EOL> raise KeyError ( '<STR_LIT>' ) <EOL> if last : <EOL> key = reversed ( self ) . next ( ) <EOL> else : <EOL> key = iter ( self ) . next ( ) <EOL> value = self . pop ( key ) <EOL> return key , value <EOL> def __reduce__ ( self ) : <EOL> items = [ [ k , self [ k ] ] for k in self ] <EOL> tmp = self . __map , self . __end <EOL> del self . __map , self . __end <EOL> inst_dict = vars ( self ) . copy ( ) <EOL> self . __map , self . __end = tmp <EOL> if inst_dict : <EOL> return ( self . __class__ , ( items , ) , inst_dict ) <EOL> return self . __class__ , ( items , ) <EOL> def keys ( self ) : <EOL> return list ( self ) <EOL> setdefault = DictMixin . setdefault <EOL> update = DictMixin . update <EOL> pop = DictMixin . pop <EOL> values = DictMixin . values <EOL> items = DictMixin . items <EOL> iterkeys = DictMixin . iterkeys <EOL> itervalues = DictMixin . itervalues <EOL> iteritems = DictMixin . iteritems <EOL> def __repr__ ( self ) : <EOL> if not self : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , ) <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . items ( ) ) <EOL> def copy ( self ) : <EOL> return self . __class__ ( self ) <EOL> @ classmethod <EOL> def fromkeys ( cls , iterable , value = None ) : <EOL> d = cls ( ) <EOL> for key in iterable : <EOL> d [ key ] = value <EOL> return d <EOL> def __eq__ ( self , other ) : <EOL> if isinstance ( other , OrderedDict ) : <EOL> return len ( self ) == len ( other ) and all ( p == q for p , q in zip ( self . items ( ) , other . items ( ) ) ) <EOL> return dict . __eq__ ( self , other ) <EOL> def __ne__ ( self , other ) : <EOL> return not self == other </s>
