From 33b20be7b5a0ff47dd9830ef29ecbc8532753a83 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Tue, 25 Nov 2008 17:06:36 +0000 Subject: [PATCH] cleanup handling of adaptor pipe debugging code --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40421 --- scrapy/trunk/scrapy/item/adaptors.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scrapy/trunk/scrapy/item/adaptors.py b/scrapy/trunk/scrapy/item/adaptors.py index ae848b502..dd06a2422 100644 --- a/scrapy/trunk/scrapy/item/adaptors.py +++ b/scrapy/trunk/scrapy/item/adaptors.py @@ -11,13 +11,16 @@ class AdaptorPipe(list): in order to filter the input. """ def __init__(self, adaptors): - super(AdaptorPipe, self).__init__([adaptor for adaptor in adaptors if callable(adaptor)]) + for adaptor in adaptors: + if not callable(adaptor): + raise TypeError("%s is not a callable" % adaptor) + super(AdaptorPipe, self).__init__(adaptors) + self.debug = settings.getbool('ADAPTORS_DEBUG') def __call__(self, value, **kwargs): """ Execute the adaptor pipeline for this attribute. """ - debug = kwargs.pop('debug', all([settings.getbool('LOG_ENABLED'), settings.get('LOGLEVEL') == 'TRACE'])) for adaptor in self: if inspect.isfunction(adaptor): @@ -30,7 +33,7 @@ class AdaptorPipe(list): name = adaptor.__class__.__name__ if hasattr(adaptor, '__class__') else adaptor.__name__ try: - if debug: + if self.debug: print " %07s | input >" % name, repr(value) if 'adaptor_args' in func_args: @@ -38,7 +41,7 @@ class AdaptorPipe(list): else: value = adaptor(value) - if debug: + if self.debug: print " %07s | output >" % name, repr(value) except Exception: print "Error in '%s' adaptor. Traceback text:" % name