#NEWLINE# def __getitem__( self , key ) : #NEWLINE# #INDENT# "\n        Return an element for any key chosen key (in'bounded mode') or\n        for a previously generated key that is still in the cache\n        (for one of the 'open' modes)\n        " #NEWLINE# tuple_key = util . wrap_tuple ( key ) #NEWLINE# if ( self . mode == 'bounded' ) : #NEWLINE# #INDENT# if ( key == slice ( None , None , None ) ) : #NEWLINE# #INDENT# return self . clone ( self ) #NEWLINE# #UNINDENT# slices = [ el for el in tuple_key if isinstance ( el , slice ) ] #NEWLINE# if any ( ( el . step for el in slices ) ) : #NEWLINE# #INDENT# raise Exception ( 'Slices cannot have a step argument in DynamicMap bounded mode ' ) #NEWLINE# #UNINDENT# if ( len ( slices ) not in [ 0 , len ( tuple_key ) ] ) : #NEWLINE# #INDENT# raise Exception ( 'Slices must be used exclusively or not at all' ) #NEWLINE# #UNINDENT# if slices : #NEWLINE# #INDENT# return self . _slice_bounded ( tuple_key ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# cache = super ( DynamicMap , self ) . __getitem__ ( key ) #NEWLINE# if ( isinstance ( cache , DynamicMap ) and ( self . mode == 'open' ) ) : #NEWLINE# #INDENT# cache = self . clone ( cache ) #NEWLINE# #UNINDENT# #UNINDENT# except KeyError as e : #NEWLINE# #INDENT# cache = None #NEWLINE# if ( ( self . mode == 'open' ) and ( len ( self . data ) > 0 ) ) : #NEWLINE# #INDENT# raise KeyError ( ( str ( e ) + ' Note: Cannot index outside available cache in open interval mode.' ) ) #NEWLINE# #UNINDENT# #UNINDENT# product = self . _cross_product ( tuple_key , ( cache . data if cache else { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) #NEWLINE# if ( product is not None ) : #NEWLINE# #INDENT# return product #NEWLINE# #UNINDENT# if cache : #NEWLINE# #INDENT# return cache #NEWLINE# #UNINDENT# val = self . _execute_callback ( * tuple_key ) #NEWLINE# if ( self . call_mode == 'counter' ) : #NEWLINE# #INDENT# val = val [ 1 ] #NEWLINE# #UNINDENT# self . _cache ( tuple_key , val ) #NEWLINE# return val