Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(5)  |  Call(5)  |  Derive(0)  |  Import(0)
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(more...)

        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 
        


src/e/x/extprot-0.2.4/extprot/tests/test_compiler.py   extprot(Download)
    def test_import_protocol(self):
        # Try it with the filename
        namespace = {}
        extprot.import_protocol(pfile,namespace)
        assert issubclass(namespace["person"],Message)
        assert issubclass(namespace["address_book"],Message)
        # Try it with filelike object
        namespace = {}
        extprot.import_protocol(open(pfile,"r"),namespace)

src/e/x/extprot-0.2.4/extprot/tests/test_types.py   extprot(Download)
 
file = path.join(path.dirname(__file__),"../../examples/address_book.proto")
extprot.import_protocol(file,globals(),__name__)
 
 

src/e/x/extprot-0.2.4/extprot/tests/test_tst.py   extprot(Download)
file = path.join(path.dirname(__file__),"../../examples/tst.proto")
dynamic = {}
extprot.import_protocol(file,dynamic)
Test_dynamic = make_cases(**dynamic)
 

src/e/x/extprot-0.2.4/extprot/tests/test_addressbook.py   extprot(Download)
file = path.join(path.dirname(__file__),"../../examples/address_book.proto")
dynamic = {}
extprot.import_protocol(file,dynamic)
Test_dynamic = make_cases(**dynamic)