示例#1
0
文件: __init__.py 项目: rfk/extprot
def import_protocol_string(string,namespace,module=None):
    """Dynamically load extprot protocol objects into the given namespace.

    This function dynamically compiles the protocol definitions found in
    the string 'string' and loads the resulting objects into 'namespace'.
    If the optional argument 'module' is provided, this string will be
    set as the __module__ attribute of the created type classes.  You'll
    need to use this if you want them to be picklable.
    """
    from extprot.compiler import NamespaceCompiler
    nsc = NamespaceCompiler(module=module)
    nsc.compile_string(string)
    for (n,v) in nsc.namespace.iteritems():
        namespace[n] = v 
示例#2
0
文件: __init__.py 项目: rfk/extprot
def import_protocol(filename,namespace,module=None):
    """Dynamically load extprot protocol objects into the given namespace.

    This function dynamically compiles the protocol definitions found in
    the file 'filename' and loads the resulting objects into 'namespace'.
    If the optional argument 'module' is provided, this string will be
    set as the __module__ attribute of the created type classes.  You'll
    need to use this if you want them to be pickleable.

    If the protocol file is fairly static then you may prefer to compile it
    into a python module, so it can be imported directly without any parsing
    overhead.  The function extprot.compile_protocol() can be used for this.
    """
    from extprot.compiler import NamespaceCompiler
    nsc = NamespaceCompiler(module=module)
    nsc.compile(filename)
    for (n,v) in nsc.namespace.iteritems():
        namespace[n] = v