mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
...
This commit is contained in:
parent
e38f7f2346
commit
4e66d2fff6
@ -234,6 +234,7 @@ class FormatterFunction:
|
||||
arg_count = 0
|
||||
aliases = []
|
||||
object_type = StoredObjectType.PythonFunction
|
||||
_cached_program_text = None
|
||||
|
||||
def __doc__getter__(self) -> str:
|
||||
return _('No documentation provided')
|
||||
@ -246,6 +247,18 @@ class FormatterFunction:
|
||||
def __doc__(self):
|
||||
return self.__doc__getter__()
|
||||
|
||||
@property
|
||||
def program_text(self) -> str:
|
||||
if self._cached_program_text is None:
|
||||
eval_func = inspect.getmembers(self.__class__,
|
||||
lambda x: inspect.isfunction(x) and x.__name__ == 'evaluate')
|
||||
try:
|
||||
lines = [l[4:] for l in inspect.getsourcelines(eval_func[0][1])[0]]
|
||||
except Exception:
|
||||
lines = []
|
||||
self._cached_program_text = ''.join(lines)
|
||||
return self._cached_program_text
|
||||
|
||||
def evaluate(self, formatter, kwargs, mi, locals, *args):
|
||||
raise NotImplementedError()
|
||||
|
||||
@ -281,21 +294,8 @@ class FormatterFunction:
|
||||
class BuiltinFormatterFunction(FormatterFunction):
|
||||
|
||||
def __init__(self):
|
||||
self._cached_program_text = None
|
||||
formatter_functions().register_builtin(self)
|
||||
|
||||
@property
|
||||
def program_text(self) -> str:
|
||||
if self._cached_program_text is None:
|
||||
eval_func = inspect.getmembers(self.__class__,
|
||||
lambda x: inspect.isfunction(x) and x.__name__ == 'evaluate')
|
||||
try:
|
||||
lines = [l[4:] for l in inspect.getsourcelines(eval_func[0][1])[0]]
|
||||
except Exception:
|
||||
lines = []
|
||||
self._cached_program_text = ''.join(lines)
|
||||
return self._cached_program_text
|
||||
|
||||
|
||||
class BuiltinStrcmp(BuiltinFormatterFunction):
|
||||
name = 'strcmp'
|
||||
@ -3691,7 +3691,7 @@ class FormatterUserFunction(FormatterFunction):
|
||||
self.name = name
|
||||
self.user_doc = doc
|
||||
self.arg_count = arg_count
|
||||
self._cached_program_text = program_text
|
||||
self._cached_program_text = program_text or ''
|
||||
self.cached_compiled_text = None
|
||||
# Keep this for external code compatibility. Set it to True if we have a
|
||||
# python template function, otherwise false. This might break something
|
||||
|
Loading…
x
Reference in New Issue
Block a user