<s> from combi . _python_toolbox import comparison_tools <EOL> try : <EOL> from collections import OrderedDict as StdlibOrderedDict <EOL> except ImportError : <EOL> from combi . _python_toolbox . third_party . collections import OrderedDict as StdlibOrderedDict <EOL> class OrderedDict ( StdlibOrderedDict ) : <EOL> '''<STR_LIT>''' <EOL> def move_to_end ( self , key , last = True ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> self . __map <EOL> except AttributeError : <EOL> if last : <EOL> self [ key ] = self . pop ( key ) <EOL> else : <EOL> value = self . pop ( key ) <EOL> items = tuple ( self . items ( ) ) <EOL> self . clear ( ) <EOL> self [ key ] = value <EOL> self . update ( items ) <EOL> return <EOL> else : <EOL> link = self . __map [ key ] <EOL> link_prev = link [ <NUM_LIT:0> ] <EOL> link_next = link [ <NUM_LIT:1> ] <EOL> link_prev [ <NUM_LIT:1> ] = link_next <EOL> link_next [ <NUM_LIT:0> ] = link_prev <EOL> root = self . __root <EOL> if last : <EOL> last = self . __root [ <NUM_LIT:0> ] <EOL> link [ <NUM_LIT:0> ] = last <EOL> link [ <NUM_LIT:1> ] = self . __root <EOL> last [ <NUM_LIT:1> ] = self . __root [ <NUM_LIT:0> ] = link <EOL> else : <EOL> first = self . __root [ <NUM_LIT:1> ] <EOL> link [ <NUM_LIT:0> ] = self . __root <EOL> link [ <NUM_LIT:1> ] = first <EOL> root [ <NUM_LIT:1> ] = first [ <NUM_LIT:0> ] = link <EOL> def sort ( self , key = None , reverse = False ) : <EOL> '''<STR_LIT>''' <EOL> key_function = comparison_tools . process_key_function_or_attribute_name ( key ) <EOL> sorted_keys = sorted ( self . keys ( ) , key = key_function , reverse = reverse ) <EOL> for key_ in sorted_keys [ <NUM_LIT:1> : ] : <EOL> self . move_to_end ( key_ ) <EOL> def index ( self , key ) : <EOL> '''<STR_LIT>''' <EOL> if key not in self : <EOL> raise ValueError <EOL> for i , key_ in enumerate ( self ) : <EOL> if key_ == key : <EOL> return i <EOL> raise RuntimeError <EOL> @ property <EOL> def reversed ( self ) : <EOL> '''<STR_LIT>''' <EOL> return type ( self ) ( reversed ( tuple ( self . items ( ) ) ) ) </s>
