#NEWLINE# def __getitem__( self , k ) : #NEWLINE# #INDENT# '\n        Retrieves an item or slice from the set of results.\n        ' #NEWLINE# if ( not isinstance ( self , ( ( slice , ) + six . integer_types ) ) ) : #NEWLINE# #INDENT# raise TypeError #NEWLINE# #UNINDENT# assert ( ( ( not isinstance ( k , slice ) ) and ( k >= 0 ) ) or ( isinstance ( k , slice ) and ( ( k . start is None ) or ( k . start >= 0 ) ) and ( ( k . stop is None ) or ( k . stop >= 0 ) ) ) ) , 'Negative indexing is not supported.' #NEWLINE# if ( self . _result_cache is not None ) : #NEWLINE# #INDENT# return self . _result_cache [ k ] #NEWLINE# #UNINDENT# if isinstance ( k , slice ) : #NEWLINE# #INDENT# qs = self . _clone ( ) #NEWLINE# if ( k . start is not None ) : #NEWLINE# #INDENT# start = int ( k . start ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# start = None #NEWLINE# #UNINDENT# if ( k . stop is not None ) : #NEWLINE# #INDENT# stop = int ( k . stop ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# stop = None #NEWLINE# #UNINDENT# qs . query . set_limits ( start , stop ) #NEWLINE# return ( list ( qs ) [ : : k . step ] if k . step else qs ) #NEWLINE# #UNINDENT# qs = self . _clone ( ) #NEWLINE# qs . query . set_limits ( k , ( k + 1 ) ) #NEWLINE# return list ( qs ) [ 0 ]