2019-09-17 02:04:27 +00:00
|
|
|
import six
|
2018-10-31 16:08:29 +00:00
|
|
|
# coding=utf-8
|
|
|
|
|
|
|
|
|
|
|
|
class Processor(object):
|
|
|
|
"""
|
|
|
|
Processor base class
|
|
|
|
"""
|
|
|
|
name = None
|
|
|
|
parent = None
|
|
|
|
supported = None
|
|
|
|
enabled = True
|
|
|
|
|
|
|
|
def __init__(self, name=None, parent=None, supported=None):
|
|
|
|
self.name = name
|
|
|
|
self.parent = parent
|
|
|
|
self.supported = supported if supported else lambda parent: True
|
|
|
|
|
|
|
|
@property
|
|
|
|
def info(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def process(self, content, debug=False, **kwargs):
|
|
|
|
return content
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "Processor <%s %s>" % (self.__class__.__name__, self.info)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return repr(self)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2019-09-17 02:04:27 +00:00
|
|
|
return six.text_type(repr(self))
|
2018-10-31 16:08:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FuncProcessor(Processor):
|
|
|
|
func = None
|
|
|
|
|
|
|
|
def __init__(self, func, name=None, parent=None, supported=None):
|
|
|
|
super(FuncProcessor, self).__init__(name=name, supported=supported)
|
|
|
|
self.func = func
|
|
|
|
|
|
|
|
def process(self, content, debug=False, **kwargs):
|
|
|
|
return self.func(content)
|