<s> try : <EOL> from thread import get_ident as _get_ident <EOL> except ImportError : <EOL> from dummy_thread import get_ident as _get_ident <EOL> try : <EOL> from _abcoll import KeysView , ValuesView , ItemsView <EOL> except ImportError : <EOL> pass <EOL> class OrderedDict ( dict ) : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kwds ) : <EOL> '''<STR_LIT>''' <EOL> if len ( args ) > <NUM_LIT:1> : <EOL> raise TypeError ( '<STR_LIT>' % len ( args ) ) <EOL> try : <EOL> self . __root <EOL> except AttributeError : <EOL> self . __root = root = [ ] <EOL> root [ : ] = [ root , root , None ] <EOL> self . __map = { } <EOL> self . __update ( * args , ** kwds ) <EOL> def __setitem__ ( self , key , value , dict_setitem = dict . __setitem__ ) : <EOL> '<STR_LIT>' <EOL> if key not in self : <EOL> root = self . __root <EOL> last = root [ <NUM_LIT:0> ] <EOL> last [ <NUM_LIT:1> ] = root [ <NUM_LIT:0> ] = self . __map [ key ] = [ last , root , key ] <EOL> dict_setitem ( self , key , value ) <EOL> def __delitem__ ( self , key , dict_delitem = dict . __delitem__ ) : <EOL> '<STR_LIT>' <EOL> dict_delitem ( self , key ) <EOL> link_prev , link_next , key = self . __map . pop ( key ) <EOL> link_prev [ <NUM_LIT:1> ] = link_next <EOL> link_next [ <NUM_LIT:0> ] = link_prev <EOL> def __iter__ ( self ) : <EOL> '<STR_LIT>' <EOL> root = self . __root <EOL> curr = root [ <NUM_LIT:1> ] <EOL> while curr is not root : <EOL> yield curr [ <NUM_LIT:2> ] <EOL> curr = curr [ <NUM_LIT:1> ] <EOL> def __reversed__ ( self ) : <EOL> '<STR_LIT>' <EOL> root = self . __root <EOL> curr = root [ <NUM_LIT:0> ] <EOL> while curr is not root : <EOL> yield curr [ <NUM_LIT:2> ] <EOL> curr = curr [ <NUM_LIT:0> ] <EOL> def clear ( self ) : <EOL> '<STR_LIT>' <EOL> try : <EOL> for node in self . __map . itervalues ( ) : <EOL> del node [ : ] <EOL> root = self . __root <EOL> root [ : ] = [ root , root , None ] <EOL> self . __map . clear ( ) <EOL> except AttributeError : <EOL> pass <EOL> dict . clear ( self ) <EOL> def popitem ( self , last = True ) : <EOL> '''<STR_LIT>''' <EOL> if not self : <EOL> raise KeyError ( '<STR_LIT>' ) <EOL> root = self . __root <EOL> if last : <EOL> link = root [ <NUM_LIT:0> ] <EOL> link_prev = link [ <NUM_LIT:0> ] <EOL> link_prev [ <NUM_LIT:1> ] = root <EOL> root [ <NUM_LIT:0> ] = link_prev <EOL> else : <EOL> link = root [ <NUM_LIT:1> ] <EOL> link_next = link [ <NUM_LIT:1> ] <EOL> root [ <NUM_LIT:1> ] = link_next <EOL> link_next [ <NUM_LIT:0> ] = root <EOL> key = link [ <NUM_LIT:2> ] <EOL> del self . __map [ key ] <EOL> value = dict . pop ( self , key ) <EOL> return key , value <EOL> def keys ( self ) : <EOL> '<STR_LIT>' <EOL> return list ( self ) <EOL> def values ( self ) : <EOL> '<STR_LIT>' <EOL> return [ self [ key ] for key in self ] <EOL> def items ( self ) : <EOL> '<STR_LIT>' <EOL> return [ ( key , self [ key ] ) for key in self ] <EOL> def iterkeys ( self ) : <EOL> '<STR_LIT>' <EOL> return iter ( self ) <EOL> def itervalues ( self ) : <EOL> '<STR_LIT>' <EOL> for k in self : <EOL> yield self [ k ] <EOL> def iteritems ( self ) : <EOL> '<STR_LIT>' <EOL> for k in self : <EOL> yield ( k , self [ k ] ) <EOL> def update ( * args , ** kwds ) : <EOL> '''<STR_LIT>''' <EOL> if len ( args ) > <NUM_LIT:2> : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( len ( args ) , ) ) <EOL> elif not args : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> self = args [ <NUM_LIT:0> ] <EOL> other = ( ) <EOL> if len ( args ) == <NUM_LIT:2> : <EOL> other = args [ <NUM_LIT:1> ] <EOL> if isinstance ( other , dict ) : <EOL> for key in other : <EOL> self [ key ] = other [ key ] <EOL> elif hasattr ( other , '<STR_LIT>' ) : <EOL> for key in other . keys ( ) : <EOL> self [ key ] = other [ key ] <EOL> else : <EOL> for key , value in other : <EOL> self [ key ] = value <EOL> for key , value in kwds . items ( ) : <EOL> self [ key ] = value <EOL> __update = update <EOL> __marker = object ( ) <EOL> def pop ( self , key , default = __marker ) : <EOL> '''<STR_LIT>''' <EOL> if key in self : <EOL> result = self [ key ] <EOL> del self [ key ] <EOL> return result <EOL> if default is self . __marker : <EOL> raise KeyError ( key ) <EOL> return default <EOL> def setdefault ( self , key , default = None ) : <EOL> '<STR_LIT>' <EOL> if key in self : <EOL> return self [ key ] <EOL> self [ key ] = default <EOL> return default <EOL> def __repr__ ( self , _repr_running = { } ) : <EOL> '<STR_LIT>' <EOL> call_key = id ( self ) , _get_ident ( ) <EOL> if call_key in _repr_running : <EOL> return '<STR_LIT>' <EOL> _repr_running [ call_key ] = <NUM_LIT:1> <EOL> try : <EOL> if not self : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , ) <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . items ( ) ) <EOL> finally : <EOL> del _repr_running [ call_key ] <EOL> def __reduce__ ( self ) : <EOL> '<STR_LIT>' <EOL> items = [ [ k , self [ k ] ] for k in self ] <EOL> inst_dict = vars ( self ) . copy ( ) <EOL> for k in vars ( OrderedDict ( ) ) : <EOL> inst_dict . pop ( k , None ) <EOL> if inst_dict : <EOL> return ( self . __class__ , ( items , ) , inst_dict ) <EOL> return self . __class__ , ( items , ) <EOL> def copy ( self ) : <EOL> '<STR_LIT>' <EOL> return self . __class__ ( self ) <EOL> @ classmethod <EOL> def fromkeys ( cls , iterable , value = None ) : <EOL> '''<STR_LIT>''' <EOL> d = cls ( ) <EOL> for key in iterable : <EOL> d [ key ] = value <EOL> return d <EOL> def __eq__ ( self , other ) : <EOL> '''<STR_LIT>''' <EOL> if isinstance ( other , OrderedDict ) : <EOL> return len ( self ) == len ( other ) and self . items ( ) == other . items ( ) <EOL> return dict . __eq__ ( self , other ) <EOL> def __ne__ ( self , other ) : <EOL> return not self == other <EOL> def viewkeys ( self ) : <EOL> "<STR_LIT>" <EOL> return KeysView ( self ) <EOL> def viewvalues ( self ) : <EOL> "<STR_LIT>" <EOL> return ValuesView ( self ) <EOL> def viewitems ( self ) : <EOL> "<STR_LIT>" <EOL> return ItemsView ( self ) </s>
