#NEWLINE# def _cb_bodyready( self , txresponse , request ) : #NEWLINE# #INDENT# if ( txresponse . length == 0 ) : #NEWLINE# #INDENT# return ( txresponse , b'' , None ) #NEWLINE# #UNINDENT# maxsize = request . meta . get ( 'download_maxsize' , self . _maxsize ) #NEWLINE# warnsize = request . meta . get ( 'download_warnsize' , self . _warnsize ) #NEWLINE# expected_size = ( txresponse . length if ( txresponse . length != UNKNOWN_LENGTH ) else ( - 1 ) ) #NEWLINE# if ( maxsize and ( expected_size > maxsize ) ) : #NEWLINE# #INDENT# error_message = 'Cancelling download of {url}: expected response size ({size}) larger than download max size ({maxsize}).' . format ( url = request . url , size = expected_size , maxsize = maxsize ) #NEWLINE# logger . error ( error_message ) #NEWLINE# txresponse . _transport . _producer . loseConnection ( ) #NEWLINE# raise defer . CancelledError ( error_message ) #NEWLINE# #UNINDENT# if ( warnsize and ( expected_size > warnsize ) ) : #NEWLINE# #INDENT# logger . warning ( 'Expected response size (%(size)s) larger than download warn size (%(warnsize)s).' , { #NEWLINE# #INDENT# 'size' : expected_size , #NEWLINE# 'warnsize' : warnsize , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# def _cancel( _ ) : #NEWLINE# #INDENT# txresponse . _transport . _producer . loseConnection ( ) #NEWLINE# #UNINDENT# d = defer . Deferred ( _cancel ) #NEWLINE# txresponse . deliverBody ( _ResponseReader ( d , txresponse , request , maxsize , expected_size ) ) #NEWLINE# self . _txresponse = txresponse #NEWLINE# return d