From af8f0bfc9a5f38c88766fdfeb53c59f4d432709a Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sun, 28 Feb 2021 20:38:45 +0100 Subject: [PATCH] support heritage --- src/rougail/template/engine/creole.py | 39 +++++++++++--------- src/rougail/template/engine/creole_legacy.py | 26 ++++++++----- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/rougail/template/engine/creole.py b/src/rougail/template/engine/creole.py index 2e84cb3b..631283d1 100644 --- a/src/rougail/template/engine/creole.py +++ b/src/rougail/template/engine/creole.py @@ -34,16 +34,25 @@ from ...utils import normalize_family from ...error import TemplateError +@classmethod +def cl_compile(kls, *args, **kwargs): + """Rewrite compile methode to force some settings + """ + kwargs['compilerSettings'] = {'directiveStartToken' : '%', + 'cheetahVarStartToken' : '%%', + 'EOLSlurpToken' : '%', + 'commentStartToken' : '#', + 'multiLineCommentStartToken' : '#*', + 'multiLineCommentEndToken' : '*#', + } + return kls.old_compile(*args, **kwargs) # pylint: disable=E1101 +Template.old_compile = Template.compile +Template.compile = cl_compile + + class CheetahTemplate(Template): # pylint: disable=W0223 """Construct a cheetah templating object """ - compilerSettings = {'directiveStartToken' : '%', - 'cheetahVarStartToken' : '%%', - 'EOLSlurpToken' : '%', - 'commentStartToken' : '#', - 'multiLineCommentStartToken' : '#*', - 'multiLineCommentEndToken' : '*#', - } def __init__(self, filename: str, source: str, @@ -54,17 +63,13 @@ class CheetahTemplate(Template): # pylint: disable=W0223 """Initialize Creole CheetahTemplate """ if filename is not None: - Template.__init__(self, - file=filename, - searchList=[context, eosfunc, extra_context], - compilerSettings=self.compilerSettings, - ) + super().__init__(file=filename, + searchList=[context, eosfunc, extra_context], + ) else: - Template.__init__(self, - source=source, - searchList=[context, eosfunc, extra_context], - compilerSettings=self.compilerSettings, - ) + super().__init__(source=source, + searchList=[context, eosfunc, extra_context], + ) # FORK of Cheetah function, do not replace '\\' by '/' def serverSidePath(self, diff --git a/src/rougail/template/engine/creole_legacy.py b/src/rougail/template/engine/creole_legacy.py index a775207e..b002d90c 100644 --- a/src/rougail/template/engine/creole_legacy.py +++ b/src/rougail/template/engine/creole_legacy.py @@ -35,6 +35,23 @@ from ...utils import normalize_family from ...error import TemplateError +@classmethod +def cl_compile(kls, *args, **kwargs): + """Rewrite compile methode to force some settings + """ + kwargs['compilerSettings'] = {'directiveStartToken' : u'%', + 'cheetahVarStartToken' : u'%%', + 'EOLSlurpToken' : u'%', + 'PSPStartToken' : u'µ' * 10, + 'PSPEndToken' : u'µ' * 10, + 'commentStartToken' : u'µ' * 10, + 'commentEndToken' : u'µ' * 10, + 'multiLineCommentStartToken' : u'µ' * 10, + 'multiLineCommentEndToken' : u'µ' * 10} + return kls.old_compile(*args, **kwargs) # pylint: disable=E1101 +oriCheetahTemplate.compile = cl_compile + + class IsDefined: """ filtre permettant de ne pas lever d'exception au cas où @@ -58,15 +75,6 @@ class IsDefined: class CheetahTemplate(oriCheetahTemplate): - compilerSettings = {'directiveStartToken' : '%', - 'cheetahVarStartToken' : '%%', - 'EOLSlurpToken' : '%', - 'PSPStartToken' : 'µ' * 10, - 'PSPEndToken' : 'µ' * 10, - 'commentStartToken' : 'µ' * 10, - 'commentEndToken' : 'µ' * 10, - 'multiLineCommentStartToken' : 'µ' * 10, - 'multiLineCommentEndToken' : 'µ' * 10} def __init__(self, filename: str, source: str,