<s> """<STR_LIT>""" <EOL> from collections . abc import MutableMapping <EOL> _sentinel = object ( ) <EOL> class TransformDict ( MutableMapping ) : <EOL> '''<STR_LIT>''' <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , transform , init_dict = None , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> if not callable ( transform ) : <EOL> msg = '<STR_LIT>' <EOL> raise TypeError ( msg % transform . __class__ ) <EOL> self . _transform = transform <EOL> self . _original = { } <EOL> self . _data = { } <EOL> if init_dict : <EOL> self . update ( init_dict ) <EOL> if kwargs : <EOL> self . update ( kwargs ) <EOL> def getitem ( self , key ) : <EOL> '<STR_LIT>' <EOL> transformed = self . _transform ( key ) <EOL> original = self . _original [ transformed ] <EOL> value = self . _data [ transformed ] <EOL> return original , value <EOL> @ property <EOL> def transform_func ( self ) : <EOL> "<STR_LIT>" <EOL> return self . _transform <EOL> def __len__ ( self ) : <EOL> return len ( self . _data ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . _original . values ( ) ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . _data [ self . _transform ( key ) ] <EOL> def __setitem__ ( self , key , value ) : <EOL> transformed = self . _transform ( key ) <EOL> self . _data [ transformed ] = value <EOL> self . _original . setdefault ( transformed , key ) <EOL> def __delitem__ ( self , key ) : <EOL> transformed = self . _transform ( key ) <EOL> del self . _data [ transformed ] <EOL> del self . _original [ transformed ] <EOL> def clear ( self ) : <EOL> '<STR_LIT>' <EOL> self . _data . clear ( ) <EOL> self . _original . clear ( ) <EOL> def __contains__ ( self , key ) : <EOL> return self . _transform ( key ) in self . _data <EOL> def get ( self , key , default = None ) : <EOL> '<STR_LIT>' <EOL> return self . _data . get ( self . _transform ( key ) , default ) <EOL> def pop ( self , key , default = _sentinel ) : <EOL> '''<STR_LIT>''' <EOL> transformed = self . _transform ( key ) <EOL> if default is _sentinel : <EOL> del self . _original [ transformed ] <EOL> return self . _data . pop ( transformed ) <EOL> else : <EOL> self . _original . pop ( transformed , None ) <EOL> return self . _data . pop ( transformed , default ) <EOL> def popitem ( self ) : <EOL> '''<STR_LIT>''' <EOL> transformed , value = self . _data . popitem ( ) <EOL> return self . _original . pop ( transformed ) , value <EOL> def copy ( self ) : <EOL> '<STR_LIT>' <EOL> other = self . __class__ ( self . _transform ) <EOL> other . _original = self . _original . copy ( ) <EOL> other . _data = self . _data . copy ( ) <EOL> return other <EOL> __copy__ = copy <EOL> def __getstate__ ( self ) : <EOL> return ( self . _transform , self . _data , self . _original ) <EOL> def __setstate__ ( self , state ) : <EOL> self . _transform , self . _data , self . _original = state <EOL> def __repr__ ( self ) : <EOL> try : <EOL> equiv = dict ( self ) <EOL> except TypeError : <EOL> equiv = list ( self . items ( ) ) <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , <EOL> self . _transform , repr ( equiv ) ) </s>
