<s> noDefault = object ( ) <EOL> class EntityContext ( object ) : <EOL> """<STR_LIT>""" <EOL> entityAttr = None <EOL> specialKeys = [ ] <EOL> def __init__ ( self , entity ) : <EOL> assert self . entityAttr is not None <EOL> for key in self . specialKeys : <EOL> assert hasattr ( self , '<STR_LIT>' + key ) <EOL> setattr ( self , self . entityAttr , entity ) <EOL> self . data = { } <EOL> def __getitem__ ( self , key ) : <EOL> if key in self . specialKeys : <EOL> accessor = getattr ( self , '<STR_LIT>' + key ) <EOL> return accessor ( ) <EOL> if key in self . data : <EOL> return self . data [ key ] <EOL> else : <EOL> entity = getattr ( self , self . entityAttr ) <EOL> raise KeyError ( "<STR_LIT>" % ( key , entity ) ) <EOL> def __setitem__ ( self , key , value ) : <EOL> if key in self . specialKeys : <EOL> raise KeyError ( "<STR_LIT>" % key ) <EOL> self . data [ key ] = value <EOL> def __delitem__ ( self , key ) : <EOL> if key in self . specialKeys : <EOL> raise KeyError ( "<STR_LIT>" % key ) <EOL> del self . data [ key ] <EOL> def __contains__ ( self , key ) : <EOL> return key in self . data or key in self . specialKeys <EOL> def __iter__ ( self ) : <EOL> for key in self . specialKeys : <EOL> yield key <EOL> for key in self . data : <EOL> yield key <EOL> def get ( self , key , default = noDefault ) : <EOL> try : <EOL> return self [ key ] <EOL> except KeyError : <EOL> if default == noDefault : <EOL> raise <EOL> else : <EOL> return default <EOL> def pop ( self , key , default = noDefault ) : <EOL> try : <EOL> return self . data . pop ( key ) <EOL> except KeyError : <EOL> if default == noDefault : <EOL> raise <EOL> else : <EOL> return default <EOL> def keys ( self ) : <EOL> return list ( self ) <EOL> def values ( self ) : <EOL> return [ self [ key ] for key in self ] <EOL> def items ( self ) : <EOL> return [ ( key , self [ key ] ) for key in self ] <EOL> def update ( self , otherDict ) : <EOL> return self . data . update ( otherDict ) <EOL> def clear ( self ) : <EOL> return self . data . clear ( ) <EOL> def copy ( self ) : <EOL> return dict ( self . items ( ) ) <EOL> def __repr__ ( self ) : <EOL> return repr ( self . copy ( ) ) </s>
