Exemplo n.º 1
0
def compile_protocol_string(string):
    """Compile extprot protocol objects into python sourcecode.

    This function compiles the protocol definitions found in the given
    string, returning sourcecode for their corresponding python class
    definitions.
    """
    from extprot.compiler import ModuleCompiler
    mc = ModuleCompiler()
    mc.compile_string(string)
    return "\n".join(mc.code_lines)
Exemplo n.º 2
0
def compile_protocol(infile,outfile):
    """Compile extprot protocol objects into python sourcecode.

    This function compiles the protocol definitions found in 'infile'
    to sourcecode for their corresponding python class definitions.  The
    compiled code is written into 'outfile'.  Both 'infile' and 'outfile'
    can be specified as either a pathname or a file-like object.

    If the protocol defnitions change often, it may be more convenient to
    use the function extprot.import_protocol() to load them directly from
    protocol file, at the expense of some additional parsing overhead.
    """
    from extprot.compiler import ModuleCompiler
    mc = ModuleCompiler()
    mc.compile(infile)
    for ln in mc.code_lines:
        outfile.write(ln)
        outfile.write("\n")