Add debug pre-processor
This commit is contained in:
parent
dd5213b761
commit
b337d2f655
1 changed files with 25 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ from weboob.capabilities.base import empty
|
|||
from weboob.tools.compat import basestring
|
||||
from weboob.tools.exceptions import ParseError
|
||||
from weboob.tools.browser2 import URL
|
||||
from weboob.tools.log import getLogger
|
||||
|
||||
class NoDefault(object):
|
||||
def __repr__(self):
|
||||
|
|
@ -90,6 +91,30 @@ class _Filter(object):
|
|||
return self.__class__.__name__
|
||||
|
||||
|
||||
def debug(*args):
|
||||
"""
|
||||
A decorator function to provide some debugs informations
|
||||
in Filters.
|
||||
It prints by default the name of the Filter and the input value.
|
||||
You can add environnement variable used by filters, by example
|
||||
using @debug("symbols", "toreplace", "childs")
|
||||
"""
|
||||
def wraper(function):
|
||||
def print_debug(self, value):
|
||||
logger = getLogger('b2filters')
|
||||
logger.debug("Use the filter %s on %s" % (str(self), value))
|
||||
env = ''
|
||||
for arg in args:
|
||||
env += "%s: %s;;; " % (arg, getattr(self, arg))
|
||||
if env != '':
|
||||
logger.debug(env)
|
||||
res = function(self, value)
|
||||
logger.debug("Result is: %s" % res)
|
||||
return res
|
||||
return print_debug
|
||||
return wraper
|
||||
|
||||
|
||||
class Filter(_Filter):
|
||||
"""
|
||||
Class used to filter on a HTML element given as call parameter to return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue