Tayra

Template. Script. Distribute

codegen – Instruction generator

Instruction generator for tayra.runtime.StackMachine. Generates intermediate python file.

Module contents

class tayra.codegen.InstrGen(compiler)[source]

Bases: builtins.object

Instruction generator to compile template script to an intermediate python file. This file can be loaded as template module and executed in the context of a HTTP request to generate the final HTML response. Since creating an instance of this class every time can be a costly operation, create it once and use _init() to initialize for subsequent uses.

codeindent(up=None, down=None, indent=True)[source]

Increase or decrease python code-indentation for subsequently generated code.

codetext()[source]

Return the final text of python code.

comment(comment, force=False)[source]

Optionally create a comment line inside the python code. Happens only when TTLCompiler[‘debug’] option is set true.

cr(count=1)[source]

Generate a new-line (along with current indentation level) in python generated text.

evalexprs(s)[source]

Evaluate a string as python expression and append the result into the stack buffer.

finish()[source]

Call this when there is no more instruction to generate. Before calling this footer() method must have been called.

flushtext()[source]

puttext() method’s text string are not immediately appended to the stack buffer. They are accumulated and appended only when this method is called.

footer(ttlhash, ttlfile)[source]

Add the footer python code.

handletag(**kwargs)[source]

Pop the last two buffers from the stack and supply them to ITayraTags plugins. The returned HTML text from the plugin is only again pushed into the stack buffer.

implement_interface(implements, interfaces)[source]

Special method to handle @implement directive and @interface functions implementations.

importttl(modname, ttlfile)[source]

Special method to handle @import directive.

initialize()[source]

Initialize and begin generating the intermediate python file. Generates import statements and in debug mode generate trace-back generator.

popappend(astext=True)[source]

Pop the last buffer in the stack and append the text into the previous buffer in the stack.

popobject(returnwith=None)[source]

Some times a function might want to return something else other than stacked buffers.

popreturn(astext=True)[source]

Pop the last buffer in the stack and return the text.

pushbuf()[source]

Create a new buffer in the stack. The newly created buffer will start accumulated text string.

putblock(codeblock, indent=True)[source]

Add a block of python statements in the intermediate code.

putinherit(ttlloc)[source]

Special method to handle @inherit directive.

putstatement(stmt)[source]

Add a python statement in the intermediate code.

puttext(text, force=False)[source]

Append text into the stack machine.

Table Of Contents

Related Topics

This Page