PyFoam.Basics.TemplateFile module

class PyFoam.Basics.TemplateFile.EvalPseudoSandboxWithMath(allowExec=False)[source]

Bases: PyFoam.ThirdParty.pyratemp.EvalPseudoSandbox

Add mathematical functions to the valid functons

__init__(allowExec=False)[source]
__module__ = 'PyFoam.Basics.TemplateFile'
compile(expr, mode='eval')[source]

Compile a python-eval-expression. Overrides the default implementation to allow ‘_[1]’ as a valid name

eval(expr, locals)[source]

Eval a python-eval-expression.

Sets self.locals_ptr to locales and compiles the code before evaluating.

class PyFoam.Basics.TemplateFile.EvalPseudoSandboxWithMathWithImport[source]

Bases: PyFoam.Basics.TemplateFile.EvalPseudoSandboxWithMath

Class that allows the import of packages

__init__()[source]
__module__ = 'PyFoam.Basics.TemplateFile'
class PyFoam.Basics.TemplateFile.PyratempPreprocessor(dovarline=True, doexpr=True, expressionDelimiter='$', assignmentLineStart='$$', allowExec=False, assignmentDebug=None, specials=[])[source]

Bases: object

This 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

__call__(original)[source]

This does the actual work

__dict__ = mappingproxy({'__weakref__': <attribute '__weakref__' of 'PyratempPreprocessor' objects>, '__init__': <function PyratempPreprocessor.__init__>, '__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 ', '__dict__': <attribute '__dict__' of 'PyratempPreprocessor' objects>, '__module__': 'PyFoam.Basics.TemplateFile', '__call__': <function PyratempPreprocessor.__call__>})
__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.RendererWithFilename(evalfunc, escapefunc, filename=None)[source]

Bases: PyFoam.ThirdParty.pyratemp.Renderer

Usual renderer but report a filename

__init__(evalfunc, escapefunc, filename=None)[source]
__module__ = 'PyFoam.Basics.TemplateFile'
_eval(expr, data)[source]

evalfunc with error-messages

reportString(expr, err)[source]
class PyFoam.Basics.TemplateFile.TemplateFile(name=None, content=None, encoding='utf-8', expressionDelimiter='|', assignmentLineStart='$$', assignmentDebug=None, specials=[], renderer_class=None, tolerantRender=False, allowExec=False)[source]

Bases: PyFoam.Basics.TemplateFile.TemplateFileOldFormat

Works 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)[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'
buildTemplate(template)[source]
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

class PyFoam.Basics.TemplateFile.TemplateFileOldFormat(name=None, content=None)[source]

Bases: object

Works on template files. Does calculations between $$. Lines that start with $$ contain definitions

__dict__ = mappingproxy({'__weakref__': <attribute '__weakref__' of 'TemplateFileOldFormat' objects>, '__dict__': <attribute '__dict__' of 'TemplateFileOldFormat' objects>, '__init__': <function TemplateFileOldFormat.__init__>, '__doc__': 'Works on template files. Does calculations between $$.\n Lines that start with $$ contain definitions', 'writeToFile': <function TemplateFileOldFormat.writeToFile>, '__module__': 'PyFoam.Basics.TemplateFile', 'buildTemplate': <function TemplateFileOldFormat.buildTemplate>, 'getString': <function TemplateFileOldFormat.getString>})
__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)

buildTemplate(template)[source]
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)[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

class PyFoam.Basics.TemplateFile.TolerantRenderer(evalfunc, escapefunc, filename=None)[source]

Bases: PyFoam.Basics.TemplateFile.RendererWithFilename

Variant of the renderer that doesn’t choke on problems with evaluations

__init__(evalfunc, escapefunc, filename=None)[source]
__module__ = 'PyFoam.Basics.TemplateFile'
_eval(expr, data)[source]

evalfunc with error-messages