<s> """<STR_LIT>""" <EOL> import logging <EOL> from scrapy . exceptions import IgnoreRequest <EOL> logger = logging . getLogger ( __name__ ) <EOL> class HttpError ( IgnoreRequest ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , response , * args , ** kwargs ) : <EOL> self . response = response <EOL> super ( HttpError , self ) . __init__ ( * args , ** kwargs ) <EOL> class HttpErrorMiddleware ( object ) : <EOL> @ classmethod <EOL> def from_crawler ( cls , crawler ) : <EOL> return cls ( crawler . settings ) <EOL> def __init__ ( self , settings ) : <EOL> self . handle_httpstatus_all = settings . getbool ( '<STR_LIT>' ) <EOL> self . handle_httpstatus_list = settings . getlist ( '<STR_LIT>' ) <EOL> def process_spider_input ( self , response , spider ) : <EOL> if <NUM_LIT:200> <= response . status < <NUM_LIT> : <EOL> return <EOL> meta = response . meta <EOL> if '<STR_LIT>' in meta : <EOL> return <EOL> if '<STR_LIT>' in meta : <EOL> allowed_statuses = meta [ '<STR_LIT>' ] <EOL> elif self . handle_httpstatus_all : <EOL> return <EOL> else : <EOL> allowed_statuses = getattr ( spider , '<STR_LIT>' , self . handle_httpstatus_list ) <EOL> if response . status in allowed_statuses : <EOL> return <EOL> raise HttpError ( response , '<STR_LIT>' ) <EOL> def process_spider_exception ( self , response , exception , spider ) : <EOL> if isinstance ( exception , HttpError ) : <EOL> logger . debug ( <EOL> "<STR_LIT>" , <EOL> { '<STR_LIT>' : response } , extra = { '<STR_LIT>' : spider } , <EOL> ) <EOL> return [ ] </s>
