<s> """<STR_LIT>""" <EOL> from ants . utils import log <EOL> from ants . http import Request <EOL> from ants . utils . exceptions import NotConfigured <EOL> class UrlLengthMiddleware ( object ) : <EOL> def __init__ ( self , maxlength ) : <EOL> self . maxlength = maxlength <EOL> @ classmethod <EOL> def from_settings ( cls , settings ) : <EOL> maxlength = settings . getint ( '<STR_LIT>' ) <EOL> if not maxlength : <EOL> raise NotConfigured <EOL> return cls ( maxlength ) <EOL> def process_spider_output ( self , response , result , spider ) : <EOL> def _filter ( request ) : <EOL> if isinstance ( request , Request ) and len ( request . url ) > self . maxlength : <EOL> log . spider_log ( "<STR_LIT>" + self . maxlength + "<STR_LIT>" + request . url , <EOL> level = log . DEBUG , spider = spider ) <EOL> return False <EOL> else : <EOL> return True <EOL> return ( r for r in result or ( ) if _filter ( r ) ) </s>
