File: foomodulegen3.py

package info (click to toggle)
pybindgen 0.20.0%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: python: 15,981; cpp: 1,889; ansic: 617; makefile: 86; sh: 4
file content (51 lines) | stat: -rw-r--r-- 1,570 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/env python
from __future__ import unicode_literals, print_function
import sys
import warnings

import pybindgen
import pybindgen.settings
from pybindgen import (FileCodeSink)

import foomodulegen_generated
import foomodulegen_common



class ErrorHandler(pybindgen.settings.ErrorHandler):
    def handle_error(self, wrapper, exception, dummy_traceback_):
        warnings.warn("exception >>> %r in wrapper %s" % (exception, wrapper))
        return True
pybindgen.settings.error_handler = ErrorHandler()



def my_module_gen():
    out = FileCodeSink(sys.stdout)
    root_module = foomodulegen_generated.module_init()
    root_module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()')
    foomodulegen_common.customize_module_pre(root_module)

    ## this is a very special case when we want to change the name of
    ## the python module to allow parallel testing of the same basic
    ## module 'foo' generated by 3 different code paths; normally
    ## users don't need this.
    root_module.name = 'foo3'

    foomodulegen_generated.register_types(root_module)
    foomodulegen_generated.register_methods(root_module)
    foomodulegen_generated.register_functions(root_module)
    foomodulegen_common.customize_module(root_module)

    root_module.generate(out)


if __name__ == '__main__':
    try:
        import cProfile as profile
    except ImportError:
        my_module_gen()
    else:
        print("** running under profiler", file=sys.stderr)
        profile.run('my_module_gen()', 'foomodulegen3.pstat')