#NEWLINE# def fetch( self , request , callback = None , **kwargs ) : #NEWLINE# #INDENT# start_time = time . time ( ) #NEWLINE# if isinstance ( request , basestring ) : #NEWLINE# #INDENT# request = tornado . httpclient . HTTPRequest ( url = request , ** kwargs ) #NEWLINE# #UNINDENT# ctx = blueox . Context ( self . blueox_name ) #NEWLINE# ctx . start ( ) #NEWLINE# ctx . set ( 'request.uri' , request . url ) #NEWLINE# ctx . set ( 'request.method' , request . method ) #NEWLINE# ctx . set ( 'request.size' , ( len ( request . body ) if request . body else 0 ) ) #NEWLINE# ctx . stop ( ) #NEWLINE# def complete_context( response ) : #NEWLINE# #INDENT# ctx . start ( ) #NEWLINE# ctx . set ( 'response.code' , response . code ) #NEWLINE# ctx . set ( 'response.size' , ( len ( response . body ) if response . body else 0 ) ) #NEWLINE# ctx . done ( ) #NEWLINE# #UNINDENT# if ( callback is None ) : #NEWLINE# #INDENT# def fetch_complete( future ) : #NEWLINE# #INDENT# exc = future . exception ( ) #NEWLINE# if ( isinstance ( exc , tornado . httpclient . HTTPError ) and ( exc . response is not None ) ) : #NEWLINE# #INDENT# response = exc . response #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( exc is not None ) : #NEWLINE# #INDENT# response = tornado . httpclient . HTTPResponse ( request , 599 , error = exc , request_time = ( time . time ( ) - start_time ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# response = future . result ( ) #NEWLINE# #UNINDENT# #UNINDENT# complete_context ( response ) #NEWLINE# #UNINDENT# future = super ( AsyncHTTPClient , self ) . fetch ( request ) #NEWLINE# future . add_done_callback ( fetch_complete ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# def callback_wrapper( response ) : #NEWLINE# #INDENT# complete_context ( response ) #NEWLINE# callback ( response ) #NEWLINE# #UNINDENT# future = super ( AsyncHTTPClient , self ) . fetch ( request , callback = callback_wrapper ) #NEWLINE# #UNINDENT# return future