1# pylint: disable-msg=W0105
2
3from pybindgen.wrapper_registry import NullWrapperRegistry, StdMapWrapperRegistry
4
5"""
6
7Global settings to the code generator.
8
9"""
10
11name_prefix = ''
12"""
13Prefix applied to global declarations, such as instance and type
14structures.
15"""
16
17automatic_type_narrowing = False
18"""
19Default value for the automatic_type_narrowing parameter of C++ classes.
20"""
21
22allow_subclassing = False
23"""
24Allow generated classes to be subclassed by default.
25"""
26
27unblock_threads = False
28"""
29Generate code to support threads.
30When True, by default methods/functions/constructors will unblock
31threads around the funcion call, i.e. allows other Python threads to
32run during the call.
33"""
34
35
36error_handler = None
37"""
38Custom error handling.
39Error handler, or None.  When it is None, code generation exceptions
40propagate to the caller.  Else it can be a
41:class:`pybindgen.settings.ErrorHandler` subclass instance that handles the error.
42"""
43import sys
44if sys.version_info[0] >= 3:
45    min_python_version=(3, 1)
46else:
47    min_python_version=(2, 3)
48"""
49Minimum python version the generated code must support.
50"""
51
52wrapper_registry = NullWrapperRegistry
53"""
54A :class:`WrapperRegistry` subclass to use for creating
55wrapper registries.  A wrapper registry ensures that at most one
56python wrapper exists for each C/C++ object.
57"""
58
59deprecated_virtuals = False
60"""
61Prior to PyBindGen version 0.14, the code generated to handle C++
62virtual methods required Python user code to define a _foo method in
63order to implement the virtual method foo.  Since 0.14, PyBindGen
64changed so that virtual method foo is implemented in Python by
65defining a method foo, i.e. no underscore prefix is needed anymore.
66Setting deprecated_virtuals to True will force the old virtual method
67behaviour.  But this is really deprecated; newer code should set
68deprecated_virtuals to False.
69"""
70
71
72gcc_rtti_abi_complete = True
73"""
74If True, and GCC >= 3 is detected at compile time, pybindgen will try
75to use abi::__si_class_type_info to determine the closest registered
76type for pointers to objects of unknown type.  Notably, Mac OS X Lion
77has GCC > 3 but which breaks this internal API, in which case it
78should be disabled (set this option to False).
79"""
80
81def _get_deprecated_virtuals():
82    if deprecated_virtuals is None:
83        import warnings
84        warnings.warn("The option pybindgen.settings.deprecated_virtuals has not been set."
85                      "  I am going to assume the value of False, change it to True if it breaks your APIs."
86                      " The option will eventually disappear (the deprecated behaviour will eventually disappear).",
87                      DeprecationWarning)
88        return False
89    return deprecated_virtuals
90
91
92class ErrorHandler(object):
93    def handle_error(self, wrapper, exception, traceback_):
94        """
95        Handles a code generation error.  Should return True to tell
96        pybindgen to ignore the error and move on to the next wrapper.
97        Returning False will cause pybindgen to allow the exception to
98        propagate, thus aborting the code generation procedure.
99        """
100        raise NotImplementedError
101
102