PyFoam.Basics.TemplateFile module
- class PyFoam.Basics.TemplateFile.EvalPseudoSandboxWithMath(allowExec=False)[source]
Bases:
EvalPseudoSandboxAdd mathematical functions to the valid functons
- __module__ = 'PyFoam.Basics.TemplateFile'
- class PyFoam.Basics.TemplateFile.EvalPseudoSandboxWithMathWithImport[source]
Bases:
EvalPseudoSandboxWithMathClass that allows the import of packages
- __annotations__ = {}
- __module__ = 'PyFoam.Basics.TemplateFile'
- class PyFoam.Basics.TemplateFile.Jinja2TemplateFileEngine(name=None, content=None, allowExec=False, encoding='utf-8', ignore_extra_kwargs=False, strict_undefined=True, **kwargs)[source]
Bases:
objectWorks on template files using the Jinja2 templateengine
- __dict__ = mappingproxy({'__module__': 'PyFoam.Basics.TemplateFile', '__doc__': 'Works on template files using the Jinja2 templateengine', '__init__': <function Jinja2TemplateFileEngine.__init__>, 'getString': <function Jinja2TemplateFileEngine.getString>, '__dict__': <attribute '__dict__' of 'Jinja2TemplateFileEngine' objects>, '__weakref__': <attribute '__weakref__' of 'Jinja2TemplateFileEngine' objects>, '__annotations__': {}})
- __init__(name=None, content=None, allowExec=False, encoding='utf-8', ignore_extra_kwargs=False, strict_undefined=True, **kwargs)[source]
Exactly one of the parameters must be specified :param name: name of the template file. :param content: Content of the template
- __module__ = 'PyFoam.Basics.TemplateFile'
- __weakref__
list of weak references to the object (if defined)
- class PyFoam.Basics.TemplateFile.PyratempPreprocessor(dovarline=True, doexpr=True, expressionDelimiter='$', assignmentLineStart='$$', allowExec=False, assignmentDebug=None, specials=[])[source]
Bases:
objectThis class preprocesses the input that is give to it in such a way that the old format (using $$ at the line beginnings and $ .. $ for expressions) is reworked into something that pyratemp understands
- __dict__ = mappingproxy({'__module__': 'PyFoam.Basics.TemplateFile', '__doc__': 'This class preprocesses the input that is give to it in such a\n way that the old format (using $$ at the line beginnings and $\n .. $ for expressions) is reworked into something that pyratemp understands\n ', '__init__': <function PyratempPreprocessor.__init__>, '__call__': <function PyratempPreprocessor.__call__>, '__dict__': <attribute '__dict__' of 'PyratempPreprocessor' objects>, '__weakref__': <attribute '__weakref__' of 'PyratempPreprocessor' objects>, '__annotations__': {}})
- __init__(dovarline=True, doexpr=True, expressionDelimiter='$', assignmentLineStart='$$', allowExec=False, assignmentDebug=None, specials=[])[source]
Create the regexp once for performance reasons :param dovarline: look for variable lines that start with $$ :param doexpr: substitute expressions that are between $ :param expressionDelimiter: character/string that is used before and after an expression. After the expression the reverse of the string is used :param assignmentLineStart: character sequence that signals an assignment line :param assignmentDebug: Add a commented line to debug assignments. Prefix used is this parameter :param allowExec: allows execution of code. This is potentially unsafe :param specials: a list. If any expression starts with one of these values then the full expression (including delimiters) is left verbatim in the template
- __module__ = 'PyFoam.Basics.TemplateFile'
- __weakref__
list of weak references to the object (if defined)
- class PyFoam.Basics.TemplateFile.PyratempTemplateFileEngine(name=None, content=None, encoding='utf-8', expressionDelimiter='|', assignmentLineStart='$$', assignmentDebug=None, specials=[], renderer_class=None, tolerantRender=False, allowExec=False, ignore_extra_kwargs=False, **kwargs)[source]
Bases:
TemplateFileOldFormatWorks on template files. Does calculations between $$. Lines that start with $$ contain definitions
- __init__(name=None, content=None, encoding='utf-8', expressionDelimiter='|', assignmentLineStart='$$', assignmentDebug=None, specials=[], renderer_class=None, tolerantRender=False, allowExec=False, ignore_extra_kwargs=False, **kwargs)[source]
Exactly one of the parameters must be specified :param name: name of the template file. :param content: Content of the template :param expressionDelimiter: character/string that delimits expression strings. :param assignmentLineStart: Start of a line that holds an assignment operation :param assignmentDebug: Add a commented line to debug assignments. Prefix used is this parameter :param allowExec: allow execution (and import). This is potentially unsafe :param special: list with strings that leave expression untreated
- __module__ = 'PyFoam.Basics.TemplateFile'
- class PyFoam.Basics.TemplateFile.RendererWithFilename(evalfunc, escapefunc, filename=None)[source]
Bases:
RendererUsual renderer but report a filename
- __init__(evalfunc, escapefunc, filename=None)[source]
Init the renderer.
- Parameters:
evalfunc: function for template-expression-evaluation (i.e.
EvalPseudoSandbox().eval)escapefunc: function for escaping special characters (i.e. escape)
- __module__ = 'PyFoam.Basics.TemplateFile'
- class PyFoam.Basics.TemplateFile.TemplateFile(name=None, content=None, encoding='utf-8', engine='auto', fallback_engine='pyratemp', ignore_extra_kwargs=False, peek_lines=5, **kwargs)[source]
Bases:
objectWorks on template files. Does calculations between $$. Lines that start with $$ contain definitions
- __dict__ = mappingproxy({'__module__': 'PyFoam.Basics.TemplateFile', '__doc__': 'Works on template files. Does calculations between $$.\n Lines that start with $$ contain definitions', '__init__': <function TemplateFile.__init__>, 'getString': <function TemplateFile.getString>, 'writeToFile': <function TemplateFile.writeToFile>, '__dict__': <attribute '__dict__' of 'TemplateFile' objects>, '__weakref__': <attribute '__weakref__' of 'TemplateFile' objects>, '__annotations__': {}})
- __init__(name=None, content=None, encoding='utf-8', engine='auto', fallback_engine='pyratemp', ignore_extra_kwargs=False, peek_lines=5, **kwargs)[source]
Exactly one of the parameters must be specified :param name: name of the template file. :param content: Content of the template :param engine: templating engine to use. If ‘auto’ then the program tries to determine the engine by looking at the first line of the file. Otherwise it falls back to :param fallback_engine: the engine to use if ‘auto’ could not determine the engine to use :param peek_lines: number of lines to use for automatic engine detection
all other parameter get passed to the appropriate engine
- __module__ = 'PyFoam.Basics.TemplateFile'
- __weakref__
list of weak references to the object (if defined)
- class PyFoam.Basics.TemplateFile.TemplateFileOldFormat(name=None, content=None)[source]
Bases:
objectWorks on template files. Does calculations between $$. Lines that start with $$ contain definitions
- __annotations__ = {}
- __dict__ = mappingproxy({'__module__': 'PyFoam.Basics.TemplateFile', '__doc__': 'Works on template files. Does calculations between $$.\n Lines that start with $$ contain definitions', '__init__': <function TemplateFileOldFormat.__init__>, 'buildTemplate': <function TemplateFileOldFormat.buildTemplate>, 'writeToFile': <function TemplateFileOldFormat.writeToFile>, 'getString': <function TemplateFileOldFormat.getString>, '__dict__': <attribute '__dict__' of 'TemplateFileOldFormat' objects>, '__weakref__': <attribute '__weakref__' of 'TemplateFileOldFormat' objects>, '__annotations__': {}})
- __init__(name=None, content=None)[source]
Exactly one of the parameters must be specified :param name: name of the template file. :param content: Content of the template
- __module__ = 'PyFoam.Basics.TemplateFile'
- __weakref__
list of weak references to the object (if defined)
- getString(vals)[source]
In the template, replaces all the strings between $$ with the evaluation of the expressions :param vals: dictionary with the values :returns: The string with the replaced expressions
- writeToFile(outfile, vals, gzip=False)[source]
In the template, replaces all the strings between $$ with the evaluation of the expressions and writes the results to a file :param outfile: the resulting output file :param vals: dictionary with the values :param gzip: Zip the file (and add a .gz to the name)
- class PyFoam.Basics.TemplateFile.TolerantRenderer(evalfunc, escapefunc, filename=None)[source]
Bases:
RendererWithFilenameVariant of the renderer that doesn’t choke on problems with evaluations
- __annotations__ = {}
- __init__(evalfunc, escapefunc, filename=None)[source]
Init the renderer.
- Parameters:
evalfunc: function for template-expression-evaluation (i.e.
EvalPseudoSandbox().eval)escapefunc: function for escaping special characters (i.e. escape)
- __module__ = 'PyFoam.Basics.TemplateFile'