Make it work on Python 3, except gccxml, which has not been tested
This commit is contained in:
1 parent
4852c1bc65
commit
f8943e6719
44 files changed
+1878
-1804
No files matched your search
+10
-10
@@ -1,13 +1,13 @@
|
||||
|
||||
from typehandlers.base import ReturnValue, Parameter
|
||||
from module import Module
|
||||
from function import Function
|
||||
from typehandlers.codesink import CodeSink, FileCodeSink
|
||||
from cppclass import CppMethod, CppClass, CppConstructor
|
||||
from enum import Enum
|
||||
from utils import write_preamble, param, retval
|
||||
import version
|
||||
from pybindgen.typehandlers.base import ReturnValue, Parameter
|
||||
from pybindgen.module import Module
|
||||
from pybindgen.function import Function
|
||||
from pybindgen.typehandlers.codesink import CodeSink, FileCodeSink
|
||||
from pybindgen.cppclass import CppMethod, CppClass, CppConstructor
|
||||
from pybindgen.enum import Enum
|
||||
from pybindgen.utils import write_preamble, param, retval
|
||||
from pybindgen import version
|
||||
|
||||
import logging
|
||||
#import logging
|
||||
#logging.basicConfig(level=logging.DEBUG)
|
||||
del logging
|
||||
#del logging
|
||||
@@ -4,14 +4,14 @@ Wrap C++ STL containers
|
||||
|
||||
#import warnings
|
||||
|
||||
from typehandlers.base import ForwardWrapperBase, ReverseWrapperBase, \
|
||||
from .typehandlers.base import ForwardWrapperBase, ReverseWrapperBase, \
|
||||
Parameter, ReturnValue, param_type_matcher, return_type_matcher, \
|
||||
TypeConfigurationError, NotSupportedError
|
||||
|
||||
from typehandlers import codesink
|
||||
from pytypeobject import PyTypeObject
|
||||
import settings
|
||||
import utils
|
||||
from pybindgen.typehandlers import codesink
|
||||
from pybindgen.pytypeobject import PyTypeObject
|
||||
from . import settings
|
||||
from . import utils
|
||||
|
||||
|
||||
class IterNextWrapper(ForwardWrapperBase):
|
||||
|
||||
@@ -4,8 +4,8 @@ python to C or C to python. These can be useful in certain
|
||||
specialized contexts, such as converting list elements.
|
||||
"""
|
||||
|
||||
from typehandlers.base import ReverseWrapperBase, ForwardWrapperBase
|
||||
from typehandlers import ctypeparser
|
||||
from pybindgen.typehandlers.base import ReverseWrapperBase, ForwardWrapperBase
|
||||
from pybindgen.typehandlers import ctypeparser
|
||||
|
||||
class PythonToCConverter(ReverseWrapperBase):
|
||||
'''
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
Wraps C++ class instance/static attributes.
|
||||
"""
|
||||
|
||||
from typehandlers.base import ForwardWrapperBase, ReverseWrapperBase
|
||||
from typehandlers import codesink
|
||||
import settings
|
||||
import utils
|
||||
from pybindgen.typehandlers.base import ForwardWrapperBase, ReverseWrapperBase
|
||||
from pybindgen.typehandlers import codesink
|
||||
from pybindgen import settings
|
||||
from pybindgen import utils
|
||||
|
||||
|
||||
class PyGetter(ForwardWrapperBase):
|
||||
@@ -253,8 +253,8 @@ class PyMetaclass(object):
|
||||
:param getsets: name of a PyGetSetDef C array variable, or None
|
||||
"""
|
||||
assert getsets is None or isinstance(getsets, PyGetSetDef)
|
||||
assert isinstance(name, basestring)
|
||||
assert isinstance(parent_metaclass_expr, basestring)
|
||||
assert isinstance(name, str)
|
||||
assert isinstance(parent_metaclass_expr, str)
|
||||
|
||||
self.name = name
|
||||
prefix = settings.name_prefix.capitalize()
|
||||
@@ -391,7 +391,7 @@ class PyGetSetDef(object):
|
||||
|
||||
code_sink.writeln("static PyGetSetDef %s[] = {" % self.cname)
|
||||
code_sink.indent()
|
||||
for name, (getter_c_name, setter_c_name) in getsets.iteritems():
|
||||
for name, (getter_c_name, setter_c_name) in getsets.items():
|
||||
code_sink.writeln('{')
|
||||
code_sink.indent()
|
||||
code_sink.writeln('(char*) "%s", /* attribute name */' % name)
|
||||
|
||||
+1441
-32
File diff suppressed because it is too large.
Load diff
@@ -2,10 +2,10 @@
|
||||
Add container iteration powers to wrapped C++ classes
|
||||
"""
|
||||
|
||||
from typehandlers.base import ForwardWrapperBase
|
||||
from typehandlers import codesink
|
||||
from pytypeobject import PyTypeObject
|
||||
import utils
|
||||
from pybindgen.typehandlers.base import ForwardWrapperBase
|
||||
from pybindgen.typehandlers import codesink
|
||||
from pybindgen.pytypeobject import PyTypeObject
|
||||
from pybindgen import utils
|
||||
|
||||
|
||||
class IterNextWrapper(ForwardWrapperBase):
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
import settings
|
||||
import utils
|
||||
from pybindgen import settings
|
||||
from pybindgen import utils
|
||||
|
||||
|
||||
class CppException(object):
|
||||
|
||||
+22
-15
@@ -6,14 +6,14 @@ import warnings
|
||||
import traceback
|
||||
from copy import copy
|
||||
|
||||
from typehandlers.base import ForwardWrapperBase, ReverseWrapperBase, \
|
||||
from pybindgen.typehandlers.base import ForwardWrapperBase, ReverseWrapperBase, \
|
||||
join_ctype_and_name, CodeGenerationError
|
||||
from typehandlers.base import ReturnValue, Parameter
|
||||
from typehandlers import codesink
|
||||
import overloading
|
||||
import settings
|
||||
import utils
|
||||
from cppexception import CppException
|
||||
from pybindgen.typehandlers.base import ReturnValue, Parameter
|
||||
from pybindgen.typehandlers import codesink
|
||||
from pybindgen import overloading
|
||||
from pybindgen import settings
|
||||
from pybindgen import utils
|
||||
from pybindgen.cppexception import CppException
|
||||
|
||||
|
||||
class CppMethod(ForwardWrapperBase):
|
||||
@@ -125,7 +125,8 @@ class CppMethod(ForwardWrapperBase):
|
||||
self.throw = list(throw)
|
||||
|
||||
self.custodians_and_wards = [] # list of (custodian, ward, postcall)
|
||||
cppclass_typehandlers.scan_custodians_and_wards(self)
|
||||
from . import cppclass
|
||||
cppclass.scan_custodians_and_wards(self)
|
||||
|
||||
|
||||
def add_custodian_and_ward(self, custodian, ward, postcall=None):
|
||||
@@ -301,12 +302,14 @@ class CppMethod(ForwardWrapperBase):
|
||||
|
||||
def _before_call_hook(self):
|
||||
"hook that post-processes parameters and check for custodian=<n> CppClass parameters"
|
||||
cppclass_typehandlers.implement_parameter_custodians_precall(self)
|
||||
from . import cppclass
|
||||
cppclass.implement_parameter_custodians_precall(self)
|
||||
|
||||
def _before_return_hook(self):
|
||||
"""hook that post-processes parameters and check for custodian=<n>
|
||||
CppClass parameters"""
|
||||
cppclass_typehandlers.implement_parameter_custodians_postcall(self)
|
||||
from . import cppclass
|
||||
cppclass.implement_parameter_custodians_postcall(self)
|
||||
|
||||
def _get_pystruct(self):
|
||||
# When a method is used in the context of a helper class, we
|
||||
@@ -545,7 +548,8 @@ class CppConstructor(ForwardWrapperBase):
|
||||
self.throw = list(throw)
|
||||
|
||||
self.custodians_and_wards = [] # list of (custodian, ward, postcall)
|
||||
cppclass_typehandlers.scan_custodians_and_wards(self)
|
||||
from . import cppclass
|
||||
cppclass.scan_custodians_and_wards(self)
|
||||
|
||||
|
||||
def add_custodian_and_ward(self, custodian, ward, postcall=None):
|
||||
@@ -673,11 +677,13 @@ class CppConstructor(ForwardWrapperBase):
|
||||
|
||||
def _before_call_hook(self):
|
||||
"hook that post-processes parameters and check for custodian=<n> CppClass parameters"
|
||||
cppclass_typehandlers.implement_parameter_custodians_precall(self)
|
||||
from . import cppclass
|
||||
cppclass.implement_parameter_custodians_precall(self)
|
||||
|
||||
def _before_return_hook(self):
|
||||
"hook that post-processes parameters and check for custodian=<n> CppClass parameters"
|
||||
cppclass_typehandlers.implement_parameter_custodians_postcall(self)
|
||||
from . import cppclass
|
||||
cppclass.implement_parameter_custodians_postcall(self)
|
||||
|
||||
def generate(self, code_sink, wrapper_name=None, extra_wrapper_params=()):
|
||||
"""
|
||||
@@ -1052,6 +1058,7 @@ class CppVirtualMethodProxy(ReverseWrapperBase):
|
||||
self.before_call.unindent()
|
||||
else:
|
||||
if self.method.is_pure_virtual or self.method.visibility == 'private':
|
||||
from . import cppclass
|
||||
if isinstance(self.return_value, cppclass.CppClassReturnValue) \
|
||||
and self.return_value.cpp_class.has_trivial_constructor:
|
||||
pass
|
||||
@@ -1159,5 +1166,5 @@ class CustomCppConstructorWrapper(CppConstructor):
|
||||
def generate_call(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
import cppclass
|
||||
import cppclass_typehandlers
|
||||
#import cppclass
|
||||
#import cppclass_typehandlers
|
||||
+5
-5
@@ -2,9 +2,9 @@
|
||||
Wraps enumerations
|
||||
"""
|
||||
|
||||
from typehandlers import inttype
|
||||
from typehandlers.base import return_type_matcher, param_type_matcher
|
||||
from cppclass import CppClass
|
||||
from pybindgen.typehandlers import inttype
|
||||
from pybindgen.typehandlers.base import return_type_matcher, param_type_matcher
|
||||
from pybindgen.cppclass import CppClass
|
||||
|
||||
class Enum(object):
|
||||
"""
|
||||
@@ -27,12 +27,12 @@ class Enum(object):
|
||||
:param import_from_module: if not None, the enum is defined in
|
||||
another module, this parameter gives the name of the module
|
||||
"""
|
||||
assert isinstance(name, basestring)
|
||||
assert isinstance(name, str)
|
||||
assert '::' not in name
|
||||
assert outer_class is None or isinstance(outer_class, CppClass)
|
||||
self.outer_class = outer_class
|
||||
for val in values:
|
||||
if not isinstance(val, (basestring, tuple)):
|
||||
if not isinstance(val, (str, tuple)):
|
||||
raise TypeError
|
||||
|
||||
#if not name:
|
||||
|
||||
+16
-12
@@ -4,13 +4,14 @@ C function wrapper
|
||||
|
||||
from copy import copy
|
||||
|
||||
from typehandlers.base import ForwardWrapperBase, ReturnValue
|
||||
from typehandlers import codesink
|
||||
from cppexception import CppException
|
||||
from pybindgen.typehandlers.base import ForwardWrapperBase, ReturnValue
|
||||
from pybindgen.typehandlers import codesink
|
||||
from pybindgen.cppexception import CppException
|
||||
|
||||
from pybindgen import overloading
|
||||
from pybindgen import settings
|
||||
from pybindgen import utils
|
||||
|
||||
import overloading
|
||||
import settings
|
||||
import utils
|
||||
import warnings
|
||||
import traceback
|
||||
|
||||
@@ -84,7 +85,8 @@ class Function(ForwardWrapperBase):
|
||||
assert isinstance(t, CppException)
|
||||
self.throw = list(throw)
|
||||
self.custodians_and_wards = [] # list of (custodian, ward, postcall)
|
||||
cppclass_typehandlers.scan_custodians_and_wards(self)
|
||||
from pybindgen import cppclass
|
||||
cppclass.scan_custodians_and_wards(self)
|
||||
|
||||
|
||||
def clone(self):
|
||||
@@ -199,11 +201,13 @@ class Function(ForwardWrapperBase):
|
||||
|
||||
def _before_call_hook(self):
|
||||
"hook that post-processes parameters and check for custodian=<n> CppClass parameters"
|
||||
cppclass_typehandlers.implement_parameter_custodians_precall(self)
|
||||
from . import cppclass
|
||||
cppclass.implement_parameter_custodians_precall(self)
|
||||
|
||||
def _before_return_hook(self):
|
||||
"hook that post-processes parameters and check for custodian=<n> CppClass parameters"
|
||||
cppclass_typehandlers.implement_parameter_custodians_postcall(self)
|
||||
from . import cppclass
|
||||
cppclass.implement_parameter_custodians_postcall(self)
|
||||
|
||||
def generate(self, code_sink, wrapper_name=None, extra_wrapper_params=()):
|
||||
"""
|
||||
@@ -261,8 +265,8 @@ class Function(ForwardWrapperBase):
|
||||
:param name: python function/method name
|
||||
"""
|
||||
flags = self.get_py_method_def_flags()
|
||||
assert isinstance(self.wrapper_return, basestring)
|
||||
assert isinstance(self.wrapper_actual_name, basestring)
|
||||
assert isinstance(self.wrapper_return, str)
|
||||
assert isinstance(self.wrapper_actual_name, str)
|
||||
assert isinstance(self.wrapper_args, list)
|
||||
return "{(char *) \"%s\", (PyCFunction) %s, %s, %s }," % \
|
||||
(name, self.wrapper_actual_name, '|'.join(flags),
|
||||
@@ -313,4 +317,4 @@ class OverloadedFunction(overloading.OverloadedWrapper):
|
||||
RETURN_TYPE = 'PyObject *'
|
||||
ERROR_RETURN = 'return NULL;'
|
||||
|
||||
import cppclass_typehandlers
|
||||
#import cppclass_typehandlers
|
||||
+36
-35
@@ -10,14 +10,14 @@ import re
|
||||
import pygccxml
|
||||
from pygccxml import parser
|
||||
from pygccxml import declarations
|
||||
from module import Module
|
||||
from typehandlers.codesink import FileCodeSink, CodeSink, NullCodeSink
|
||||
import typehandlers.base
|
||||
from typehandlers.base import ctypeparser
|
||||
from typehandlers.base import ReturnValue, Parameter, TypeLookupError, TypeConfigurationError, NotSupportedError
|
||||
from .module import Module
|
||||
from .typehandlers.codesink import FileCodeSink, CodeSink, NullCodeSink
|
||||
from . import typehandlers.base
|
||||
from .typehandlers.base import ctypeparser
|
||||
from .typehandlers.base import ReturnValue, Parameter, TypeLookupError, TypeConfigurationError, NotSupportedError
|
||||
from pygccxml.declarations.enumeration import enumeration_t
|
||||
from cppclass import CppClass, ReferenceCountingMethodsPolicy, FreeFunctionPolicy, ReferenceCountingFunctionsPolicy
|
||||
from cppexception import CppException
|
||||
from .cppclass import CppClass, ReferenceCountingMethodsPolicy, FreeFunctionPolicy, ReferenceCountingFunctionsPolicy
|
||||
from .cppexception import CppException
|
||||
from pygccxml.declarations import type_traits
|
||||
from pygccxml.declarations import cpptypes
|
||||
from pygccxml.declarations import calldef
|
||||
@@ -25,12 +25,13 @@ from pygccxml.declarations import templates
|
||||
from pygccxml.declarations import container_traits
|
||||
from pygccxml.declarations.declaration import declaration_t
|
||||
from pygccxml.declarations.class_declaration import class_declaration_t, class_t
|
||||
import settings
|
||||
import utils
|
||||
from . import settings
|
||||
from . import utils
|
||||
|
||||
#from pygccxml.declarations.calldef import \
|
||||
# destructor_t, constructor_t, member_function_t
|
||||
from pygccxml.declarations.variable import variable_t
|
||||
import collections
|
||||
|
||||
|
||||
###
|
||||
@@ -133,7 +134,7 @@ class ErrorHandler(settings.ErrorHandler):
|
||||
definition = None
|
||||
|
||||
if definition is None:
|
||||
print >> sys.stderr, "exception %r in wrapper %s" % (exception, wrapper)
|
||||
print("exception %r in wrapper %s" % (exception, wrapper), file=sys.stderr)
|
||||
else:
|
||||
warnings.warn_explicit("exception %r in wrapper for %s"
|
||||
% (exception, definition),
|
||||
@@ -155,7 +156,7 @@ def normalize_class_name(class_name, module_namespace):
|
||||
|
||||
def _pygen_kwargs(kwargs):
|
||||
l = []
|
||||
for key, val in kwargs.iteritems():
|
||||
for key, val in kwargs.items():
|
||||
if isinstance(val, (CppClass, CppException)):
|
||||
l.append("%s=root_module[%r]" % (key, utils.ascii(val.full_name)))
|
||||
else:
|
||||
@@ -256,7 +257,7 @@ class GccXmlTypeRegistry(object):
|
||||
|
||||
def lookup_return(self, type_info, annotations={}):
|
||||
kwargs = {}
|
||||
for name, value in annotations.iteritems():
|
||||
for name, value in annotations.items():
|
||||
if name == 'caller_owns_return':
|
||||
kwargs['caller_owns_return'] = annotations_scanner.parse_boolean(value)
|
||||
elif name == 'reference_existing_object':
|
||||
@@ -274,7 +275,7 @@ class GccXmlTypeRegistry(object):
|
||||
|
||||
def lookup_parameter(self, type_info, param_name, annotations={}, default_value=None):
|
||||
kwargs = {}
|
||||
for name, value in annotations.iteritems():
|
||||
for name, value in annotations.items():
|
||||
if name == 'transfer_ownership':
|
||||
kwargs['transfer_ownership'] = annotations_scanner.parse_boolean(value)
|
||||
elif name == 'direction':
|
||||
@@ -381,7 +382,7 @@ class AnnotationsScanner(object):
|
||||
return global_annotations, parameter_annotations
|
||||
|
||||
def parse_boolean(self, value):
|
||||
if isinstance(value, (int, long)):
|
||||
if isinstance(value, int):
|
||||
return bool(value)
|
||||
if value.lower() in ['false', 'off']:
|
||||
return False
|
||||
@@ -391,7 +392,7 @@ class AnnotationsScanner(object):
|
||||
raise ValueError("bad boolean value %r" % value)
|
||||
|
||||
def warn_unused_annotations(self):
|
||||
for file_name, lines in self.files.iteritems():
|
||||
for file_name, lines in self.files.items():
|
||||
try:
|
||||
used_annotations = self.used_annotations[file_name]
|
||||
except KeyError:
|
||||
@@ -538,7 +539,7 @@ class ModuleParser(object):
|
||||
methods are denoted by a annotation for a
|
||||
parameter named 'return'.
|
||||
"""
|
||||
if not callable(hook):
|
||||
if not isinstance(hook, collections.Callable):
|
||||
raise TypeError("hook must be callable")
|
||||
self._pre_scan_hooks.append(hook)
|
||||
|
||||
@@ -557,7 +558,7 @@ class ModuleParser(object):
|
||||
- pybindgen_wrapper -- a pybindgen object that generates a wrapper,
|
||||
such as CppClass, Function, or CppMethod.
|
||||
"""
|
||||
if not callable(hook):
|
||||
if not isinstance(hook, collections.Callable):
|
||||
raise TypeError("hook must be callable")
|
||||
self._post_scan_hooks.append(hook)
|
||||
|
||||
@@ -866,7 +867,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
|
||||
def _apply_class_annotations(self, cls, annotations, kwargs):
|
||||
is_exception = False
|
||||
for name, value in annotations.iteritems():
|
||||
for name, value in annotations.items():
|
||||
if name == 'allow_subclassing':
|
||||
kwargs.setdefault('allow_subclassing', annotations_scanner.parse_boolean(value))
|
||||
elif name == 'is_singleton':
|
||||
@@ -1068,13 +1069,13 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
% (cls, count, cls._pybindgen_postpone_reason, reason))
|
||||
cls._pybindgen_postpone_reason = reason
|
||||
if DEBUG:
|
||||
print >> sys.stderr, ">>> class %s is being postponed (%s)" % (str(cls), reason)
|
||||
print(">>> class %s is being postponed (%s)" % (str(cls), reason), file=sys.stderr)
|
||||
unregistered_classes.append(cls)
|
||||
|
||||
while unregistered_classes:
|
||||
cls = unregistered_classes.pop(0)
|
||||
if DEBUG:
|
||||
print >> sys.stderr, ">>> looking at class ", str(cls)
|
||||
print(">>> looking at class ", str(cls), file=sys.stderr)
|
||||
typedef = None
|
||||
|
||||
kwargs = {}
|
||||
@@ -1523,7 +1524,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
## convert the return value
|
||||
try:
|
||||
return_type_elem = ReturnValue.new(*elem_type_spec[0], **elem_type_spec[1])
|
||||
except (TypeLookupError, TypeConfigurationError), ex:
|
||||
except (TypeLookupError, TypeConfigurationError) as ex:
|
||||
warnings.warn("Return value '%s' error (used in %s): %r"
|
||||
% (definition.partial_decl_string, definition, ex),
|
||||
WrapperWarning)
|
||||
@@ -1532,7 +1533,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
if key_type is not None:
|
||||
try:
|
||||
return_type_key = ReturnValue.new(*key_type_spec[0], **key_type_spec[1])
|
||||
except (TypeLookupError, TypeConfigurationError), ex:
|
||||
except (TypeLookupError, TypeConfigurationError) as ex:
|
||||
warnings.warn("Return value '%s' error (used in %s): %r"
|
||||
% (definition.partial_decl_string, definition, ex),
|
||||
WrapperWarning)
|
||||
@@ -1615,7 +1616,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
|
||||
try:
|
||||
param = Parameter.new(*arg_spec[0], **arg_spec[1])
|
||||
except (TypeLookupError, TypeConfigurationError), ex:
|
||||
except (TypeLookupError, TypeConfigurationError) as ex:
|
||||
warnings.warn_explicit("Parameter '%s' error (used in %s): %r"
|
||||
% (argument_types[1].partial_decl_string, op, ex),
|
||||
WrapperWarning, op.location.file_name, op.location.line)
|
||||
@@ -1721,7 +1722,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
|
||||
kwargs = {} # kwargs passed into the add_method call
|
||||
|
||||
for key, val in global_annotations.iteritems():
|
||||
for key, val in global_annotations.items():
|
||||
if key == 'template_instance_names' \
|
||||
and templates.is_instantiation(member.demangled_name):
|
||||
pass
|
||||
@@ -1820,7 +1821,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
## --- realize the return type and parameters
|
||||
try:
|
||||
return_type = ReturnValue.new(*return_type_spec[0], **return_type_spec[1])
|
||||
except (TypeLookupError, TypeConfigurationError), ex:
|
||||
except (TypeLookupError, TypeConfigurationError) as ex:
|
||||
warnings.warn_explicit("Return value '%s' error (used in %s): %r"
|
||||
% (member.return_type.partial_decl_string, member, ex),
|
||||
WrapperWarning, member.location.file_name, member.location.line)
|
||||
@@ -1835,7 +1836,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
for arg in argument_specs:
|
||||
try:
|
||||
arguments.append(Parameter.new(*arg[0], **arg[1]))
|
||||
except (TypeLookupError, TypeConfigurationError), ex:
|
||||
except (TypeLookupError, TypeConfigurationError) as ex:
|
||||
warnings.warn_explicit("Parameter '%s %s' error (used in %s): %r"
|
||||
% (arg[0][0], arg[0][1], member, ex),
|
||||
WrapperWarning, member.location.file_name, member.location.line)
|
||||
@@ -1852,7 +1853,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
try:
|
||||
method_wrapper = class_wrapper.add_method(member.name, return_type, arguments, **kwargs)
|
||||
method_wrapper.gccxml_definition = member
|
||||
except NotSupportedError, ex:
|
||||
except NotSupportedError as ex:
|
||||
if pure_virtual:
|
||||
class_wrapper.set_cannot_be_constructed("pure virtual method %r not wrapped" % member.name)
|
||||
class_wrapper.set_helper_class_disabled(True)
|
||||
@@ -1863,7 +1864,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
warnings.warn_explicit("Error adding method %s: %r"
|
||||
% (member, ex),
|
||||
WrapperWarning, member.location.file_name, member.location.line)
|
||||
except ValueError, ex:
|
||||
except ValueError as ex:
|
||||
warnings.warn_explicit("Error adding method %s: %r"
|
||||
% (member, ex),
|
||||
WrapperWarning, member.location.file_name, member.location.line)
|
||||
@@ -1913,7 +1914,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
for a, kw in argument_specs:
|
||||
try:
|
||||
arguments.append(Parameter.new(*a, **kw))
|
||||
except (TypeLookupError, TypeConfigurationError), ex:
|
||||
except (TypeLookupError, TypeConfigurationError) as ex:
|
||||
warnings.warn_explicit("Parameter '%s %s' error (used in %s): %r"
|
||||
% (arg.type.partial_decl_string, arg.name, member, ex),
|
||||
WrapperWarning, member.location.file_name, member.location.line)
|
||||
@@ -1971,7 +1972,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
## convert the return value
|
||||
try:
|
||||
return_type = ReturnValue.new(*return_type_spec[0], **return_type_spec[1])
|
||||
except (TypeLookupError, TypeConfigurationError), ex:
|
||||
except (TypeLookupError, TypeConfigurationError) as ex:
|
||||
warnings.warn_explicit("Return value '%s' error (used in %s): %r"
|
||||
% (member.type.partial_decl_string, member, ex),
|
||||
WrapperWarning, member.location.file_name, member.location.line)
|
||||
@@ -2094,7 +2095,7 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
ignore = False
|
||||
kwargs = {}
|
||||
|
||||
for name, value in global_annotations.iteritems():
|
||||
for name, value in global_annotations.items():
|
||||
if name == 'as_method':
|
||||
as_method = value
|
||||
elif name == 'of_class':
|
||||
@@ -2129,12 +2130,12 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
return_type_spec = self.type_registry.lookup_return(fun.return_type, return_annotations)
|
||||
try:
|
||||
return_type = ReturnValue.new(*return_type_spec[0], **return_type_spec[1])
|
||||
except (TypeLookupError, TypeConfigurationError), ex:
|
||||
except (TypeLookupError, TypeConfigurationError) as ex:
|
||||
warnings.warn_explicit("Return value '%s' error (used in %s): %r"
|
||||
% (fun.return_type.partial_decl_string, fun, ex),
|
||||
WrapperWarning, fun.location.file_name, fun.location.line)
|
||||
params_ok = False
|
||||
except TypeError, ex:
|
||||
except TypeError as ex:
|
||||
warnings.warn_explicit("Return value '%s' error (used in %s): %r"
|
||||
% (fun.return_type.partial_decl_string, fun, ex),
|
||||
WrapperWarning, fun.location.file_name, fun.location.line)
|
||||
@@ -2153,13 +2154,13 @@ pybindgen.settings.error_handler = ErrorHandler()
|
||||
argument_specs.append(spec)
|
||||
try:
|
||||
arguments.append(Parameter.new(*spec[0], **spec[1]))
|
||||
except (TypeLookupError, TypeConfigurationError), ex:
|
||||
except (TypeLookupError, TypeConfigurationError) as ex:
|
||||
warnings.warn_explicit("Parameter '%s %s' error (used in %s): %r"
|
||||
% (arg.type.partial_decl_string, arg.name, fun, ex),
|
||||
WrapperWarning, fun.location.file_name, fun.location.line)
|
||||
|
||||
params_ok = False
|
||||
except TypeError, ex:
|
||||
except TypeError as ex:
|
||||
warnings.warn_explicit("Parameter '%s %s' error (used in %s): %r"
|
||||
% (arg.type.partial_decl_string, arg.name, fun, ex),
|
||||
WrapperWarning, fun.location.file_name, fun.location.line)
|
||||
|
||||
+19
-15
@@ -45,15 +45,15 @@ to create sub-modules for wrapping nested namespaces. For instance::
|
||||
|
||||
"""
|
||||
|
||||
from function import Function, OverloadedFunction, CustomFunctionWrapper
|
||||
from typehandlers.base import CodeBlock, DeclarationsScope, ReturnValue, TypeHandler
|
||||
from typehandlers.codesink import MemoryCodeSink, CodeSink, FileCodeSink, NullCodeSink
|
||||
from cppclass import CppClass
|
||||
from cppexception import CppException
|
||||
from enum import Enum
|
||||
from container import Container
|
||||
from converter_functions import PythonToCConverter, CToPythonConverter
|
||||
import utils
|
||||
from pybindgen.function import Function, OverloadedFunction, CustomFunctionWrapper
|
||||
from pybindgen.typehandlers.base import CodeBlock, DeclarationsScope, ReturnValue, TypeHandler
|
||||
from pybindgen.typehandlers.codesink import MemoryCodeSink, CodeSink, FileCodeSink, NullCodeSink
|
||||
from pybindgen.cppclass import CppClass
|
||||
from pybindgen.cppexception import CppException
|
||||
from pybindgen.enum import Enum
|
||||
from pybindgen.container import Container
|
||||
from pybindgen.converter_functions import PythonToCConverter, CToPythonConverter
|
||||
from pybindgen import utils
|
||||
import warnings
|
||||
import traceback
|
||||
|
||||
@@ -726,7 +726,7 @@ class ModuleBase(dict):
|
||||
if self.functions:
|
||||
main_sink.writeln('/* --- module functions --- */')
|
||||
main_sink.writeln()
|
||||
for func_name, overload in self.functions.iteritems():
|
||||
for func_name, overload in self.functions.items():
|
||||
sink, header_sink = out.get_code_sink_for_wrapper(overload)
|
||||
sink.writeln()
|
||||
try:
|
||||
@@ -838,17 +838,21 @@ class ModuleBase(dict):
|
||||
main_sink.writeln('''
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
#define MOD_ERROR NULL
|
||||
#define MOD_INIT(name) PyInit_##name(void)
|
||||
#define MOD_INIT(name) PyObject* PyInit_##name(void)
|
||||
#define MOD_RETURN(val) val
|
||||
#else
|
||||
#define MOD_ERROR
|
||||
#define MOD_INIT(name) init##name(void)
|
||||
#define MOD_INIT(name) void init##name(void)
|
||||
#define MOD_RETURN(val)
|
||||
#endif
|
||||
PyMODINIT_FUNC
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
#endif
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||
__attribute__ ((visibility("default")))
|
||||
#endif''')
|
||||
#endif
|
||||
|
||||
''')
|
||||
else:
|
||||
main_sink.writeln("static PyObject *")
|
||||
if self.parent is None:
|
||||
@@ -913,7 +917,7 @@ class Module(ModuleBase):
|
||||
be imported into a foo module, to avoid making all types
|
||||
docstrings contain _foo.Xpto instead of foo.Xpto.
|
||||
"""
|
||||
if isinstance(out, file):
|
||||
if hasattr(out, 'write'):
|
||||
out = FileCodeSink(out)
|
||||
if isinstance(out, CodeSink):
|
||||
sink_manager = _MonolithicSinkManager(out)
|
||||
|
||||
+21
-21
@@ -1,11 +1,11 @@
|
||||
"""
|
||||
C wrapper wrapper
|
||||
"""
|
||||
from typehandlers.base import TypeConfigurationError, CodeGenerationError, NotSupportedError
|
||||
from typehandlers.base import ForwardWrapperBase
|
||||
from typehandlers.codesink import NullCodeSink
|
||||
import utils
|
||||
import settings
|
||||
from pybindgen.typehandlers.base import TypeConfigurationError, CodeGenerationError, NotSupportedError
|
||||
from pybindgen.typehandlers.base import ForwardWrapperBase
|
||||
from pybindgen.typehandlers.codesink import NullCodeSink
|
||||
from . import utils
|
||||
from . import settings
|
||||
import traceback
|
||||
import sys
|
||||
|
||||
@@ -17,7 +17,7 @@ except NameError:
|
||||
|
||||
def isiterable(obj):
|
||||
"""Returns True if an object appears to be iterable"""
|
||||
return hasattr(obj, '__iter__') or isinstance(obj, basestring)
|
||||
return hasattr(obj, '__iter__') or isinstance(obj, str)
|
||||
|
||||
def vector_counter(vec):
|
||||
"""
|
||||
@@ -25,14 +25,14 @@ def vector_counter(vec):
|
||||
[[1, 'a', 'x'], [1, 'a', 'y'], [1, 'b', 'x'], [1, 'b', 'y'], [2, 'a', 'x'], [2, 'a', 'y'], [2, 'b', 'x'], [2, 'b', 'y']]
|
||||
"""
|
||||
iters = [iter(l) for l in vec]
|
||||
values = [it.next() for it in iters[:-1]] + [vec[-1][0]]
|
||||
values = [next(it) for it in iters[:-1]] + [vec[-1][0]]
|
||||
while 1:
|
||||
for idx in xrange(len(iters)-1, -1, -1):
|
||||
for idx in range(len(iters)-1, -1, -1):
|
||||
try:
|
||||
values[idx] = iters[idx].next()
|
||||
values[idx] = next(iters[idx])
|
||||
except StopIteration:
|
||||
iters[idx] = iter(vec[idx])
|
||||
values[idx] = iters[idx].next()
|
||||
values[idx] = next(iters[idx])
|
||||
else:
|
||||
break
|
||||
else:
|
||||
@@ -96,10 +96,10 @@ class OverloadedWrapper(object):
|
||||
try:
|
||||
wrapper_flags = utils.call_with_error_handling(
|
||||
wrapper.get_py_method_def_flags, args=(), kwargs={}, wrapper=wrapper)
|
||||
except utils.SkipWrapper, ex:
|
||||
except utils.SkipWrapper:
|
||||
_, ex, tb = sys.exc_info()
|
||||
modified = True
|
||||
self.wrappers.remove(wrapper)
|
||||
dummy1, dummy2, tb = sys.exc_info()
|
||||
settings.error_handler.handle_error(wrapper, ex, tb)
|
||||
break
|
||||
|
||||
@@ -213,7 +213,7 @@ class OverloadedWrapper(object):
|
||||
## free previous exceptions and return the result
|
||||
code_sink.writeln("if (!exceptions[%i]) {" % number)
|
||||
code_sink.indent()
|
||||
for i in xrange(number):
|
||||
for i in range(number):
|
||||
code_sink.writeln("Py_DECREF(exceptions[%i]);" % i)
|
||||
code_sink.writeln("return retval;")
|
||||
code_sink.unindent()
|
||||
@@ -224,7 +224,7 @@ class OverloadedWrapper(object):
|
||||
## raise an appropriate exception, free the previous
|
||||
## exceptions, and return NULL
|
||||
code_sink.writeln('error_list = PyList_New(%i);' % len(delegate_wrappers))
|
||||
for i in xrange(len(delegate_wrappers)):
|
||||
for i in range(len(delegate_wrappers)):
|
||||
code_sink.writeln(
|
||||
'PyList_SET_ITEM(error_list, %i, PyObject_Str(exceptions[%i]));'
|
||||
% (i, i))
|
||||
@@ -263,8 +263,8 @@ class OverloadedWrapper(object):
|
||||
pass
|
||||
docstring = None # FIXME
|
||||
|
||||
assert isinstance(self.wrapper_return, basestring)
|
||||
assert isinstance(self.wrapper_actual_name, basestring)
|
||||
assert isinstance(self.wrapper_return, str)
|
||||
assert isinstance(self.wrapper_actual_name, str)
|
||||
assert isinstance(self.wrapper_args, list)
|
||||
|
||||
return "{(char *) \"%s\", (PyCFunction) %s, %s, %s }," % \
|
||||
@@ -275,8 +275,8 @@ class OverloadedWrapper(object):
|
||||
self.reset_code_generation_state()
|
||||
self._compute_all_wrappers()
|
||||
self.generate(NullCodeSink())
|
||||
assert isinstance(self.wrapper_return, basestring)
|
||||
assert isinstance(self.wrapper_actual_name, basestring)
|
||||
assert isinstance(self.wrapper_return, str)
|
||||
assert isinstance(self.wrapper_actual_name, str)
|
||||
assert isinstance(self.wrapper_args, list)
|
||||
code_sink.writeln("%s %s(%s);" % (self.wrapper_return, self.wrapper_actual_name, ', '.join(self.wrapper_args)))
|
||||
self.reset_code_generation_state()
|
||||
@@ -285,8 +285,8 @@ class OverloadedWrapper(object):
|
||||
self.reset_code_generation_state()
|
||||
self._compute_all_wrappers()
|
||||
self.generate(NullCodeSink())
|
||||
assert isinstance(self.wrapper_return, basestring)
|
||||
assert isinstance(self.wrapper_actual_name, basestring)
|
||||
assert isinstance(self.wrapper_return, str)
|
||||
assert isinstance(self.wrapper_actual_name, str)
|
||||
assert isinstance(self.wrapper_args, list)
|
||||
name = self.wrapper_actual_name.split('::')[-1]
|
||||
code_sink.writeln("static %s %s(%s);" % (self.wrapper_return, name, ', '.join(self.wrapper_args)))
|
||||
@@ -315,5 +315,5 @@ class OverloadedWrapper(object):
|
||||
section = property(get_section)
|
||||
|
||||
|
||||
from cppclass import CppClassParameter, CppClassRefParameter
|
||||
#from pybindgen.cppclass import CppClassParameter, CppClassRefParameter
|
||||
|
||||
+135
-91
@@ -105,54 +105,97 @@ class PyTypeObject(object):
|
||||
class PyNumberMethods(object):
|
||||
TEMPLATE = (
|
||||
'static PyNumberMethods %(variable)s = {\n'
|
||||
' (binaryfunc) %(nb_add)s,\n'
|
||||
' (binaryfunc) %(nb_subtract)s,\n'
|
||||
' (binaryfunc) %(nb_multiply)s,\n'
|
||||
' (binaryfunc) %(nb_divide)s,\n'
|
||||
' (binaryfunc) %(nb_remainder)s,\n'
|
||||
' (binaryfunc) %(nb_divmod)s,\n'
|
||||
' (ternaryfunc) %(nb_power)s,\n'
|
||||
' (unaryfunc) %(nb_negative)s,\n'
|
||||
' (unaryfunc) %(nb_positive)s,\n'
|
||||
' (unaryfunc) %(nb_absolute)s,\n'
|
||||
' (inquiry) %(nb_nonzero)s,\n'
|
||||
' (unaryfunc) %(nb_invert)s,\n'
|
||||
' (binaryfunc) %(nb_lshift)s,\n'
|
||||
' (binaryfunc) %(nb_rshift)s,\n'
|
||||
' (binaryfunc) %(nb_and)s,\n'
|
||||
' (binaryfunc) %(nb_xor)s,\n'
|
||||
' (binaryfunc) %(nb_or)s,\n'
|
||||
' (coercion) %(nb_coerce)s,\n'
|
||||
' (unaryfunc) %(nb_int)s,\n'
|
||||
' (unaryfunc) %(nb_long)s,\n'
|
||||
' (unaryfunc) %(nb_float)s,\n'
|
||||
' (unaryfunc) %(nb_oct)s,\n'
|
||||
' (unaryfunc) %(nb_hex)s,\n'
|
||||
' /* Added in release 2.0 */\n'
|
||||
' (binaryfunc) %(nb_inplace_add)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_subtract)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_multiply)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_divide)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_remainder)s,\n'
|
||||
' (ternaryfunc) %(nb_inplace_power)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_lshift)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_rshift)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_and)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_xor)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_or)s,\n'
|
||||
'#if PY_VERSION_HEX < 0x03000000\n'
|
||||
' (binaryfunc) %(nb_add)s,\n'
|
||||
' (binaryfunc) %(nb_subtract)s,\n'
|
||||
' (binaryfunc) %(nb_multiply)s,\n'
|
||||
' (binaryfunc) %(nb_divide)s,\n'
|
||||
' (binaryfunc) %(nb_remainder)s,\n'
|
||||
' (binaryfunc) %(nb_divmod)s,\n'
|
||||
' (ternaryfunc) %(nb_power)s,\n'
|
||||
' (unaryfunc) %(nb_negative)s,\n'
|
||||
' (unaryfunc) %(nb_positive)s,\n'
|
||||
' (unaryfunc) %(nb_absolute)s,\n'
|
||||
' (inquiry) %(nb_nonzero)s,\n'
|
||||
' (unaryfunc) %(nb_invert)s,\n'
|
||||
' (binaryfunc) %(nb_lshift)s,\n'
|
||||
' (binaryfunc) %(nb_rshift)s,\n'
|
||||
' (binaryfunc) %(nb_and)s,\n'
|
||||
' (binaryfunc) %(nb_xor)s,\n'
|
||||
' (binaryfunc) %(nb_or)s,\n'
|
||||
' (coercion) %(nb_coerce)s,\n'
|
||||
' (unaryfunc) %(nb_int)s,\n'
|
||||
' (unaryfunc) %(nb_long)s,\n'
|
||||
' (unaryfunc) %(nb_float)s,\n'
|
||||
' (unaryfunc) %(nb_oct)s,\n'
|
||||
' (unaryfunc) %(nb_hex)s,\n'
|
||||
' /* Added in release 2.0 */\n'
|
||||
' (binaryfunc) %(nb_inplace_add)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_subtract)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_multiply)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_divide)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_remainder)s,\n'
|
||||
' (ternaryfunc) %(nb_inplace_power)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_lshift)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_rshift)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_and)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_xor)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_or)s,\n'
|
||||
'\n'
|
||||
' /* Added in release 2.2 */\n'
|
||||
' /* The following require the Py_TPFLAGS_HAVE_CLASS flag */\n'
|
||||
' (binaryfunc) %(nb_floor_divide)s,\n'
|
||||
' (binaryfunc) %(nb_true_divide)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_floor_divide)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_true_divide)s,\n'
|
||||
' /* Added in release 2.2 */\n'
|
||||
' /* The following require the Py_TPFLAGS_HAVE_CLASS flag */\n'
|
||||
' (binaryfunc) %(nb_floor_divide)s,\n'
|
||||
' (binaryfunc) %(nb_true_divide)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_floor_divide)s,\n'
|
||||
' (binaryfunc) %(nb_inplace_true_divide)s,\n'
|
||||
'\n'
|
||||
'#if PY_VERSION_HEX >= 0x020500F0\n'
|
||||
' /* Added in release 2.5 */\n'
|
||||
' (unaryfunc) %(nb_index)s,\n'
|
||||
' /* Added in release 2.5 */\n'
|
||||
' (unaryfunc) %(nb_index)s,\n'
|
||||
'\n'
|
||||
'#endif\n'
|
||||
|
||||
'#else /* Python 3 changed this structure a lot */\n'
|
||||
|
||||
'(binaryfunc) %(nb_add)s,\n'
|
||||
'(binaryfunc) %(nb_subtract)s,\n'
|
||||
'(binaryfunc) %(nb_multiply)s,\n'
|
||||
'(binaryfunc) %(nb_remainder)s,\n'
|
||||
'(binaryfunc) %(nb_divmod)s,\n'
|
||||
'(ternaryfunc) %(nb_power)s,\n'
|
||||
'(unaryfunc) %(nb_negative)s,\n'
|
||||
'(unaryfunc) %(nb_positive)s,\n'
|
||||
'(unaryfunc) %(nb_absolute)s,\n'
|
||||
'(inquiry) %(nb_bool)s,\n'
|
||||
'(unaryfunc) %(nb_invert)s,\n'
|
||||
'(binaryfunc) %(nb_lshift)s,\n'
|
||||
'(binaryfunc) %(nb_rshift)s,\n'
|
||||
'(binaryfunc) %(nb_and)s,\n'
|
||||
'(binaryfunc) %(nb_xor)s,\n'
|
||||
'(binaryfunc) %(nb_or)s,\n'
|
||||
'(unaryfunc) %(nb_int)s,\n'
|
||||
'NULL,\n'
|
||||
'(unaryfunc) %(nb_float)s,\n'
|
||||
'\n'
|
||||
'(binaryfunc) %(nb_inplace_add)s,\n'
|
||||
'(binaryfunc) %(nb_inplace_subtract)s,\n'
|
||||
'(binaryfunc) %(nb_inplace_multiply)s,\n'
|
||||
'(binaryfunc) %(nb_inplace_remainder)s,\n'
|
||||
'(ternaryfunc) %(nb_inplace_power)s,\n'
|
||||
'(binaryfunc) %(nb_inplace_lshift)s,\n'
|
||||
'(binaryfunc) %(nb_inplace_rshift)s,\n'
|
||||
'(binaryfunc) %(nb_inplace_and)s,\n'
|
||||
'(binaryfunc) %(nb_inplace_xor)s,\n'
|
||||
'(binaryfunc) %(nb_inplace_or)s,\n'
|
||||
'\n'
|
||||
'(binaryfunc) %(nb_floor_divide)s,\n'
|
||||
'(binaryfunc) %(nb_divide)s,\n'
|
||||
'(binaryfunc) %(nb_inplace_floor_divide)s,\n'
|
||||
'(binaryfunc) %(nb_inplace_divide)s,\n'
|
||||
'\n'
|
||||
'(unaryfunc) %(nb_index)s,\n'
|
||||
'#endif\n'
|
||||
|
||||
'};\n'
|
||||
)
|
||||
|
||||
@@ -166,45 +209,46 @@ class PyNumberMethods(object):
|
||||
|
||||
slots = dict(self.slots)
|
||||
|
||||
slots.setdefault('nb_add', 'NULL')
|
||||
slots.setdefault('nb_subtract', 'NULL')
|
||||
slots.setdefault('nb_multiply', 'NULL')
|
||||
slots.setdefault('nb_divide', 'NULL')
|
||||
slots.setdefault('nb_remainder', 'NULL')
|
||||
slots.setdefault('nb_divmod', 'NULL')
|
||||
slots.setdefault('nb_power', 'NULL')
|
||||
slots.setdefault('nb_negative', 'NULL')
|
||||
slots.setdefault('nb_positive', 'NULL')
|
||||
slots.setdefault('nb_absolute', 'NULL')
|
||||
slots.setdefault('nb_nonzero', 'NULL')
|
||||
slots.setdefault('nb_invert', 'NULL')
|
||||
slots.setdefault('nb_lshift', 'NULL')
|
||||
slots.setdefault('nb_rshift', 'NULL')
|
||||
slots.setdefault('nb_and', 'NULL')
|
||||
slots.setdefault('nb_xor', 'NULL')
|
||||
slots.setdefault('nb_add', 'NULL')
|
||||
slots.setdefault('nb_bool', 'NULL')
|
||||
slots.setdefault('nb_subtract', 'NULL')
|
||||
slots.setdefault('nb_multiply', 'NULL')
|
||||
slots.setdefault('nb_divide', 'NULL')
|
||||
slots.setdefault('nb_remainder', 'NULL')
|
||||
slots.setdefault('nb_divmod', 'NULL')
|
||||
slots.setdefault('nb_power', 'NULL')
|
||||
slots.setdefault('nb_negative', 'NULL')
|
||||
slots.setdefault('nb_positive', 'NULL')
|
||||
slots.setdefault('nb_absolute', 'NULL')
|
||||
slots.setdefault('nb_nonzero', 'NULL')
|
||||
slots.setdefault('nb_invert', 'NULL')
|
||||
slots.setdefault('nb_lshift', 'NULL')
|
||||
slots.setdefault('nb_rshift', 'NULL')
|
||||
slots.setdefault('nb_and', 'NULL')
|
||||
slots.setdefault('nb_xor', 'NULL')
|
||||
slots.setdefault('nb_or', 'NULL')
|
||||
slots.setdefault('nb_coerce', 'NULL')
|
||||
slots.setdefault('nb_int', 'NULL')
|
||||
slots.setdefault('nb_long', 'NULL')
|
||||
slots.setdefault('nb_float', 'NULL')
|
||||
slots.setdefault('nb_oct', 'NULL')
|
||||
slots.setdefault('nb_hex', 'NULL')
|
||||
slots.setdefault('nb_inplace_add', 'NULL')
|
||||
slots.setdefault('nb_inplace_subtract', 'NULL')
|
||||
slots.setdefault('nb_inplace_multiply', 'NULL')
|
||||
slots.setdefault('nb_inplace_divide', 'NULL')
|
||||
slots.setdefault('nb_inplace_remainder', 'NULL')
|
||||
slots.setdefault('nb_inplace_power', 'NULL')
|
||||
slots.setdefault('nb_inplace_lshift', 'NULL')
|
||||
slots.setdefault('nb_inplace_rshift', 'NULL')
|
||||
slots.setdefault('nb_inplace_and', 'NULL')
|
||||
slots.setdefault('nb_inplace_xor', 'NULL')
|
||||
slots.setdefault('nb_inplace_or', 'NULL')
|
||||
slots.setdefault('nb_floor_divide', 'NULL')
|
||||
slots.setdefault('nb_true_divide', 'NULL')
|
||||
slots.setdefault('nb_inplace_floor_divide', 'NULL')
|
||||
slots.setdefault('nb_inplace_true_divide', 'NULL')
|
||||
slots.setdefault('nb_index', 'NULL')
|
||||
slots.setdefault('nb_coerce', 'NULL')
|
||||
slots.setdefault('nb_int', 'NULL')
|
||||
slots.setdefault('nb_long', 'NULL')
|
||||
slots.setdefault('nb_float', 'NULL')
|
||||
slots.setdefault('nb_oct', 'NULL')
|
||||
slots.setdefault('nb_hex', 'NULL')
|
||||
slots.setdefault('nb_inplace_add', 'NULL')
|
||||
slots.setdefault('nb_inplace_subtract', 'NULL')
|
||||
slots.setdefault('nb_inplace_multiply', 'NULL')
|
||||
slots.setdefault('nb_inplace_divide', 'NULL')
|
||||
slots.setdefault('nb_inplace_remainder', 'NULL')
|
||||
slots.setdefault('nb_inplace_power', 'NULL')
|
||||
slots.setdefault('nb_inplace_lshift', 'NULL')
|
||||
slots.setdefault('nb_inplace_rshift', 'NULL')
|
||||
slots.setdefault('nb_inplace_and', 'NULL')
|
||||
slots.setdefault('nb_inplace_xor', 'NULL')
|
||||
slots.setdefault('nb_inplace_or', 'NULL')
|
||||
slots.setdefault('nb_floor_divide', 'NULL')
|
||||
slots.setdefault('nb_true_divide', 'NULL')
|
||||
slots.setdefault('nb_inplace_floor_divide', 'NULL')
|
||||
slots.setdefault('nb_inplace_true_divide', 'NULL')
|
||||
slots.setdefault('nb_index', 'NULL')
|
||||
|
||||
code_sink.writeln(self.TEMPLATE % slots)
|
||||
|
||||
@@ -321,16 +365,16 @@ static int
|
||||
|
||||
slots = dict(self.slots)
|
||||
|
||||
slots.setdefault('sq_length', 'NULL')
|
||||
slots.setdefault('sq_concat', 'NULL')
|
||||
slots.setdefault('sq_repeat', 'NULL')
|
||||
slots.setdefault('sq_item', 'NULL')
|
||||
slots.setdefault('sq_slice', 'NULL')
|
||||
slots.setdefault('sq_ass_item', 'NULL')
|
||||
slots.setdefault('sq_ass_slice', 'NULL')
|
||||
slots.setdefault('sq_contains', 'NULL')
|
||||
slots.setdefault('sq_inplace_concat', 'NULL')
|
||||
slots.setdefault('sq_inplace_repeat', 'NULL')
|
||||
slots.setdefault('sq_length', 'NULL')
|
||||
slots.setdefault('sq_concat', 'NULL')
|
||||
slots.setdefault('sq_repeat', 'NULL')
|
||||
slots.setdefault('sq_item', 'NULL')
|
||||
slots.setdefault('sq_slice', 'NULL')
|
||||
slots.setdefault('sq_ass_item', 'NULL')
|
||||
slots.setdefault('sq_ass_slice', 'NULL')
|
||||
slots.setdefault('sq_contains', 'NULL')
|
||||
slots.setdefault('sq_inplace_concat', 'NULL')
|
||||
slots.setdefault('sq_inplace_repeat', 'NULL')
|
||||
|
||||
code_sink.writeln(self.TEMPLATE % slots)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# pylint: disable-msg=W0105
|
||||
|
||||
from wrapper_registry import NullWrapperRegistry, StdMapWrapperRegistry
|
||||
from pybindgen.wrapper_registry import NullWrapperRegistry, StdMapWrapperRegistry
|
||||
|
||||
"""
|
||||
|
||||
@@ -40,8 +40,11 @@ Error handler, or None. When it is None, code generation exceptions
|
||||
propagate to the caller. Else it can be a
|
||||
:class:`pybindgen.settings.ErrorHandler` subclass instance that handles the error.
|
||||
"""
|
||||
|
||||
min_python_version=(2, 3)
|
||||
import sys
|
||||
if sys.version_info[0] >= 3:
|
||||
min_python_version=(3, 1)
|
||||
else:
|
||||
min_python_version=(2, 3)
|
||||
"""
|
||||
Minimum python version the generated code must support.
|
||||
"""
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
|
||||
import base
|
||||
from pybindgen.typehandlers import base
|
||||
|
||||
import voidtype
|
||||
import inttype
|
||||
import stringtype
|
||||
import booltype
|
||||
import doubletype
|
||||
import floattype
|
||||
import pyobjecttype
|
||||
from pybindgen.typehandlers import voidtype
|
||||
from pybindgen.typehandlers import inttype
|
||||
from pybindgen.typehandlers import stringtype
|
||||
from pybindgen.typehandlers import booltype
|
||||
from pybindgen.typehandlers import doubletype
|
||||
from pybindgen.typehandlers import floattype
|
||||
from pybindgen.typehandlers import pyobjecttype
|
||||
|
||||
|
||||
from base import add_type_alias
|
||||
from pybindgen.typehandlers.base import add_type_alias
|
||||
|
||||
@@ -6,9 +6,12 @@ Base classes for all parameter/return type handlers,
|
||||
and base interfaces for wrapper generators.
|
||||
"""
|
||||
|
||||
import codesink
|
||||
from pybindgen.typehandlers import codesink
|
||||
import warnings
|
||||
import ctypeparser
|
||||
from pybindgen.typehandlers import ctypeparser
|
||||
import sys
|
||||
import six
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger("pybindgen.typehandlers")
|
||||
|
||||
@@ -192,7 +195,7 @@ class CodeBlock(object):
|
||||
ones from predecessor code blocks; Note: cleanup actions are
|
||||
executed in reverse order than when they were added.'''
|
||||
cleanup = []
|
||||
items = self._cleanup_actions.items()
|
||||
items = list(self._cleanup_actions.items())
|
||||
items.sort()
|
||||
for dummy, code in items:
|
||||
cleanup.append(code)
|
||||
@@ -862,7 +865,7 @@ class ForwardWrapperBase(object):
|
||||
% (param.ctype,))
|
||||
|
||||
if self.deprecated:
|
||||
if isinstance(self.deprecated, basestring):
|
||||
if isinstance(self.deprecated, str):
|
||||
msg = self.deprecated
|
||||
else:
|
||||
msg = "Deprecated"
|
||||
@@ -1061,7 +1064,7 @@ class TypeHandler(object):
|
||||
self.type_traits.make_target_const()
|
||||
else:
|
||||
self.type_traits.make_const()
|
||||
elif isinstance(ctype, basestring):
|
||||
elif isinstance(ctype, str):
|
||||
if is_const:
|
||||
warnings.warn("is_const is deprecated, put a 'const' in the C type instead.", DeprecationWarning)
|
||||
self.type_traits = ctypeparser.TypeTraits('const %s' % ctype)
|
||||
@@ -1093,7 +1096,23 @@ class TypeHandler(object):
|
||||
self.untransformed_ctype = untransformed_ctype
|
||||
|
||||
|
||||
class ReturnValue(TypeHandler):
|
||||
|
||||
class ReturnValueMeta(type):
|
||||
"Metaclass for automatically registering parameter type handlers"
|
||||
def __init__(mcs, name, bases, dict_):
|
||||
"metaclass __init__"
|
||||
type.__init__(mcs, name, bases, dict_)
|
||||
if __debug__:
|
||||
try:
|
||||
iter(mcs.CTYPES)
|
||||
except (TypeError, AttributeError):
|
||||
sys.stderr.write("ERROR: missing CTYPES on class %s.%s\n" % (mcs.__module__, mcs.__name__))
|
||||
|
||||
for ctype in mcs.CTYPES:
|
||||
return_type_matcher.register(ctype, mcs)
|
||||
|
||||
|
||||
class ReturnValue(TypeHandler, metaclass=ReturnValueMeta):
|
||||
'''Abstract base class for all classes dedicated to handle
|
||||
specific return value types'''
|
||||
|
||||
@@ -1105,19 +1124,6 @@ class ReturnValue(TypeHandler):
|
||||
|
||||
REQUIRES_ASSIGNMENT_CONSTRUCTOR = False
|
||||
|
||||
class __metaclass__(type):
|
||||
"Metaclass for automatically registering parameter type handlers"
|
||||
def __init__(mcs, name, bases, dict_):
|
||||
"metaclass __init__"
|
||||
type.__init__(mcs, name, bases, dict_)
|
||||
if __debug__:
|
||||
try:
|
||||
iter(mcs.CTYPES)
|
||||
except TypeError:
|
||||
print "ERROR: missing CTYPES on class ", mcs
|
||||
for ctype in mcs.CTYPES:
|
||||
return_type_matcher.register(ctype, mcs)
|
||||
|
||||
#@classmethod
|
||||
def new(cls, *args, **kwargs):
|
||||
"""
|
||||
@@ -1136,7 +1142,8 @@ class ReturnValue(TypeHandler):
|
||||
args = tuple(args)
|
||||
try:
|
||||
return type_handler_class(*args, **kwargs)
|
||||
except TypeError, ex:
|
||||
except TypeError:
|
||||
ex = sys.exc_info()[1]
|
||||
warnings.warn("Exception %r in type handler %s constructor" % (str(ex), type_handler_class))
|
||||
raise
|
||||
else:
|
||||
@@ -1189,7 +1196,21 @@ class PointerReturnValue(ReturnValue):
|
||||
PointerReturnValue.CTYPES = NotImplemented
|
||||
|
||||
|
||||
class Parameter(TypeHandler):
|
||||
class ParameterMeta(type):
|
||||
"Metaclass for automatically registering parameter type handlers"
|
||||
def __init__(mcs, name, bases, dict_):
|
||||
"metaclass __init__"
|
||||
type.__init__(mcs, name, bases, dict_)
|
||||
if __debug__:
|
||||
try:
|
||||
iter(mcs.CTYPES)
|
||||
except TypeError:
|
||||
sys.stderr.write("ERROR: missing CTYPES on class %s\n" % mcs)
|
||||
for ctype in mcs.CTYPES:
|
||||
param_type_matcher.register(ctype, mcs)
|
||||
|
||||
|
||||
class Parameter(TypeHandler, metaclass=ParameterMeta):
|
||||
'''Abstract base class for all classes dedicated to handle specific parameter types'''
|
||||
|
||||
## bit mask values
|
||||
@@ -1215,18 +1236,6 @@ class Parameter(TypeHandler):
|
||||
return "(invalid %r)" % value
|
||||
_direction_value_to_name = classmethod(_direction_value_to_name)
|
||||
|
||||
class __metaclass__(type):
|
||||
"Metaclass for automatically registering parameter type handlers"
|
||||
def __init__(mcs, name, bases, dict_):
|
||||
"metaclass __init__"
|
||||
type.__init__(mcs, name, bases, dict_)
|
||||
if __debug__:
|
||||
try:
|
||||
iter(mcs.CTYPES)
|
||||
except TypeError:
|
||||
print "ERROR: missing CTYPES on class ", mcs
|
||||
for ctype in mcs.CTYPES:
|
||||
param_type_matcher.register(ctype, mcs)
|
||||
|
||||
#@classmethod
|
||||
def new(cls, *args, **kwargs):
|
||||
@@ -1247,7 +1256,8 @@ class Parameter(TypeHandler):
|
||||
args = tuple(args)
|
||||
try:
|
||||
return type_handler_class(*args, **kwargs)
|
||||
except TypeError, ex:
|
||||
except TypeError:
|
||||
_, ex, _ = sys.exc_info()
|
||||
warnings.warn("Exception %r in type handler %s constructor" % (str(ex), type_handler_class))
|
||||
raise
|
||||
else:
|
||||
@@ -1409,7 +1419,7 @@ class TypeMatcher(object):
|
||||
|
||||
def items(self):
|
||||
"Returns an iterator over all registered items"
|
||||
return self._types.iteritems()
|
||||
return iter(self._types.items())
|
||||
|
||||
def add_type_alias(self, from_type_name, to_type_name):
|
||||
from_type_name_normalized = str(ctypeparser.TypeTraits(from_type_name).ctype)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# docstrings not neede here (the type handler interfaces are fully
|
||||
# documented in base.py) pylint: disable-msg=C0111
|
||||
|
||||
from base import ReturnValue, Parameter, \
|
||||
from pybindgen.typehandlers.base import ReturnValue, Parameter, \
|
||||
ReverseWrapperBase, ForwardWrapperBase
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class CodeSink(object):
|
||||
def _format_code(self, code):
|
||||
"""Utility method for subclasses to use for formatting code
|
||||
(splits lines and indents them)"""
|
||||
assert isinstance(code, basestring)
|
||||
assert isinstance(code, str)
|
||||
l = []
|
||||
for line in code.split('\n'):
|
||||
l.append(' '*self.indent_level + line)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import tokenizer
|
||||
from pybindgen.typehandlers.ctypeparser import tokenizer
|
||||
|
||||
|
||||
MODIFIERS = ['const', 'volatile'] # XXX: are there others?
|
||||
|
||||
@@ -55,7 +55,7 @@ PREPROCESSOR = 'PREPROCESSOR'
|
||||
|
||||
# Where the token originated from. This can be used for backtracking.
|
||||
# It is always set to WHENCE_STREAM in this code.
|
||||
WHENCE_STREAM, WHENCE_QUEUE = range(2)
|
||||
WHENCE_STREAM, WHENCE_QUEUE = list(range(2))
|
||||
|
||||
|
||||
class Token(object):
|
||||
@@ -270,13 +270,12 @@ def GetTokens(source):
|
||||
# exception and return the bogus char.
|
||||
i += 1
|
||||
else:
|
||||
print >>sys.stderr, \
|
||||
('Got invalid token in %s @ %d token:%s: %r' %
|
||||
('?', i, c, source[i-10:i+10]))
|
||||
sys.stderr.write('Got invalid token in %s @ %d token:%s: %r\n' %
|
||||
('?', i, c, source[i-10:i+10]))
|
||||
raise RuntimeError('unexpected token')
|
||||
|
||||
if i <= 0:
|
||||
print 'Invalid index, exiting now.'
|
||||
print('Invalid index, exiting now.')
|
||||
return
|
||||
yield Token(token_type, source[start:i], start, i)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# docstrings not neede here (the type handler doubleerfaces are fully
|
||||
# documented in base.py) pylint: disable-msg=C0111
|
||||
|
||||
from base import ReturnValue, Parameter, \
|
||||
from pybindgen.typehandlers.base import ReturnValue, Parameter, \
|
||||
ReverseWrapperBase, ForwardWrapperBase
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# docstrings not neede here (the type handler floaterfaces are fully
|
||||
# documented in base.py) pylint: disable-msg=C0111
|
||||
|
||||
from base import ReturnValue, Parameter, \
|
||||
from pybindgen.typehandlers.base import ReturnValue, Parameter, \
|
||||
ReverseWrapperBase, ForwardWrapperBase
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import struct
|
||||
assert struct.calcsize('i') == 4 # assumption is made that sizeof(int) == 4 for all platforms pybindgen runs on
|
||||
|
||||
|
||||
from base import ReturnValue, Parameter, PointerParameter, PointerReturnValue, \
|
||||
from pybindgen.typehandlers.base import ReturnValue, Parameter, PointerParameter, PointerReturnValue, \
|
||||
ReverseWrapperBase, ForwardWrapperBase, TypeConfigurationError, NotSupportedError
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# docstrings not neede here (the type handler doubleerfaces are fully
|
||||
# documented in base.py) pylint: disable-msg=C0111
|
||||
|
||||
from base import ReturnValue, Parameter, \
|
||||
from pybindgen.typehandlers.base import ReturnValue, Parameter, \
|
||||
ReverseWrapperBase, ForwardWrapperBase
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# docstrings not neede here (the type handler interfaces are fully
|
||||
# documented in base.py) pylint: disable-msg=C0111
|
||||
|
||||
from base import ReturnValue, PointerReturnValue, Parameter, PointerParameter, ReverseWrapperBase, ForwardWrapperBase
|
||||
from pybindgen.typehandlers.base import ReturnValue, PointerReturnValue, Parameter, PointerParameter, ReverseWrapperBase, ForwardWrapperBase
|
||||
|
||||
|
||||
class CStringParam(PointerParameter):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# docstrings not neede here (the type handler interfaces are fully
|
||||
# documented in base.py) pylint: disable-msg=C0111
|
||||
|
||||
from base import ReturnValue
|
||||
from pybindgen.typehandlers.base import ReturnValue
|
||||
|
||||
|
||||
class VoidReturn(ReturnValue):
|
||||
|
||||
+13
-7
@@ -9,11 +9,11 @@ except NameError:
|
||||
|
||||
|
||||
import sys
|
||||
from typehandlers.codesink import CodeSink
|
||||
from typehandlers.base import TypeLookupError, TypeConfigurationError, CodeGenerationError, NotSupportedError, \
|
||||
from pybindgen.typehandlers.codesink import CodeSink
|
||||
from pybindgen.typehandlers.base import TypeLookupError, TypeConfigurationError, CodeGenerationError, NotSupportedError, \
|
||||
Parameter, ReturnValue
|
||||
import version
|
||||
import settings
|
||||
from pybindgen import version
|
||||
from pybindgen import settings
|
||||
import warnings
|
||||
|
||||
|
||||
@@ -100,6 +100,10 @@ typedef intobjargproc ssizeobjargproc;
|
||||
code_sink.writeln(r'''
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
typedef void* cmpfunc;
|
||||
#define PyCObject_FromVoidPtr(a, b) PyCapsule_New(a, NULL, b)
|
||||
#define PyCObject_AsVoidPtr(a) PyCapsule_GetPointer(a, NULL)
|
||||
#define PyString_FromString(a) PyBytes_FromString(a)
|
||||
#define Py_TPFLAGS_CHECKTYPES 0 /* this flag doesn't exist in python 3 */
|
||||
#endif
|
||||
''')
|
||||
|
||||
@@ -119,6 +123,7 @@ typedef enum _PyBindGenWrapperFlags {
|
||||
} PyBindGenWrapperFlags;
|
||||
|
||||
''')
|
||||
|
||||
|
||||
|
||||
def mangle_name(name):
|
||||
@@ -132,7 +137,7 @@ def mangle_name(name):
|
||||
|
||||
def get_mangled_name(base_name, template_args):
|
||||
"""for internal pybindgen use"""
|
||||
assert isinstance(base_name, basestring)
|
||||
assert isinstance(base_name, str)
|
||||
assert isinstance(template_args, (tuple, list))
|
||||
|
||||
if template_args:
|
||||
@@ -157,7 +162,8 @@ def call_with_error_handling(callback, args, kwargs, wrapper,
|
||||
else:
|
||||
try:
|
||||
return callback(*args, **kwargs)
|
||||
except Exception, ex:
|
||||
except Exception:
|
||||
_, ex, _ = sys.exc_info()
|
||||
if isinstance(ex, exceptions_to_handle):
|
||||
dummy1, dummy2, traceback = sys.exc_info()
|
||||
if settings.error_handler.handle_error(wrapper, ex, traceback):
|
||||
@@ -180,7 +186,7 @@ def ascii(value):
|
||||
return value
|
||||
elif isinstance(value, str):
|
||||
return value
|
||||
elif isinstance(value, unicode):
|
||||
elif isinstance(value, str):
|
||||
return value.encode('ascii')
|
||||
else:
|
||||
raise TypeError("value must be str or ascii string contained in a unicode object")
|
||||
|
||||
@@ -3,7 +3,7 @@ The class that generates code to keep track of existing python
|
||||
wrappers for a given root class.
|
||||
"""
|
||||
|
||||
from typehandlers.base import NotSupportedError
|
||||
from pybindgen.typehandlers.base import NotSupportedError
|
||||
|
||||
|
||||
class WrapperRegistry(object):
|
||||
|
||||
Reference in new issue
Block a user