Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def flatten(name):
"make a name like::This look LikeThis"
return ''.join([make_upper(utils.mangle_name(s)) for s in name.split('::')])
:param value_type: a ReturnValue of the element type: note,
for mapping containers, value_type is a tuple with two
ReturnValue's: (key, element).
"""
self.cppclass = cppclass
self.begin_method = begin_method
self.end_method = end_method
self.iterator_type = iterator_type
self.iter_pytype = PyTypeObject()
self._iter_pystruct = None
if is_mapping:
(key_type, value_type) = value_type
self.key_type = utils.eval_retval(key_type, self)
self.value_type = utils.eval_retval(value_type, self)
else:
self.key_type = None
self.value_type = utils.eval_retval(value_type, self)
def get_c_to_python_type_converter_function_name(self, value_type):
"""
Internal API, do not use.
"""
assert isinstance(value_type, TypeHandler)
ctype = value_type.ctype
mangled_ctype = utils.mangle_name(str(ctype))
converter_function_name = "_wrap_convert_c2py__%s" % mangled_ctype
return converter_function_name
self.is_pure_virtual = is_pure_virtual
self.is_const = is_const
self.template_parameters = template_parameters
self.custom_name = (custom_name or custom_template_method_name)
#self.static_decl = True
self._class = None
self._helper_class = None
self.docstring = docstring
self.wrapper_base_name = None
self.wrapper_actual_name = None
self.return_value = None
self.parameters = None
return_value = utils.eval_retval(return_value, self)
parameters = [utils.eval_param(param, self) for param in parameters]
super(CppMethod, self).__init__(
return_value, parameters,
"return NULL;", "return NULL;",
unblock_threads=unblock_threads)
self.deprecated = deprecated
for t in throw:
assert isinstance(t, CppException)
self.throw = list(throw)
self.custodians_and_wards = [] # list of (custodian, ward, postcall)
from . import cppclass
cppclass.scan_custodians_and_wards(self)
self.is_const = is_const
self.template_parameters = template_parameters
self.custom_name = (custom_name or custom_template_method_name)
#self.static_decl = True
self._class = None
self._helper_class = None
self.docstring = docstring
self.wrapper_base_name = None
self.wrapper_actual_name = None
self.return_value = None
self.parameters = None
return_value = utils.eval_retval(return_value, self)
parameters = [utils.eval_param(param, self) for param in parameters]
super(CppMethod, self).__init__(
return_value, parameters,
"return NULL;", "return NULL;",
unblock_threads=unblock_threads)
self.deprecated = deprecated
for t in throw:
assert isinstance(t, CppException)
self.throw = list(throw)
self.custodians_and_wards = [] # list of (custodian, ward, postcall)
from . import cppclass
cppclass.scan_custodians_and_wards(self)
def __init__(self, arg):
"""
Accepts either a Parameter object or a tuple as sole
parameter. In case it's a tuple, it is assumed to be a retval
spec (\\*args, \\*\\*kwargs).
"""
if isinstance(arg, ReturnValue):
super(DummyParameter, self).__init__(arg.ctype)
else:
args, kwargs = utils.parse_param_spec(arg)
super(DummyParameter, self).__init__(args[0], args[1])
def add_typedef(self, wrapper, alias):
"""
Declares an equivalent to a typedef in C::
typedef Foo Bar;
:param wrapper: the wrapper object to alias (Foo in the example)
:param alias: name of the typedef alias
@note: only typedefs for CppClass objects have been
implemented so far; others will be implemented in the future.
"""
assert isinstance(wrapper, CppClass)
alias = utils.ascii(alias)
self.typedefs.append((wrapper, alias))
self.register_type(alias, alias, wrapper)
wrapper.register_alias(alias)
full_name = '::'.join(self.get_namespace_path() + [alias])
wrapper.register_alias(full_name)
def add_container(self, *args, **kwargs):
"""
Add a container to the module. See the documentation for
L{Container.__init__} for information on accepted parameters.
"""
try:
container = Container(*args, **kwargs)
except utils.SkipWrapper:
return None
container.stack_where_defined = traceback.extract_stack()
self._add_container_obj(container)
return container
self.is_const = is_const
self.template_parameters = template_parameters
self.custom_name = (custom_name or custom_template_method_name)
#self.static_decl = True
self._class = None
self._helper_class = None
self.docstring = docstring
self.wrapper_base_name = None
self.wrapper_actual_name = None
self.return_value = None
self.parameters = None
return_value = utils.eval_retval(return_value, self)
parameters = [utils.eval_param(param, self) for param in parameters]
super(CppMethod, self).__init__(
return_value, parameters,
"return NULL;", "return NULL;",
unblock_threads=unblock_threads)
self.deprecated = deprecated
for t in throw:
assert isinstance(t, CppException)
self.throw = list(throw)
self.injector = injector
self.custodians_and_wards = [] # list of (custodian, ward, postcall)
from . import cppclass
cppclass.scan_custodians_and_wards(self)
def generate(self, code_sink, wrapper_name=None, extra_wrapper_params=()):
"""
Generates the wrapper code
:param code_sink: a CodeSink instance that will receive the generated code
:returns: the wrapper function name.
"""
if self.visibility == 'private':
raise utils.SkipWrapper("Class %r has a private constructor ->"
" cannot generate a constructor for it" % self._class.full_name)
elif self.visibility == 'protected':
if self._class.helper_class is None:
raise utils.SkipWrapper("Class %r has a protected constructor and no helper class"
" -> cannot generate a constructor for it" % self._class.full_name)
#assert isinstance(class_, CppClass)
tmp_sink = codesink.MemoryCodeSink()
assert self._class is not None
self.generate_body(tmp_sink, gen_call_params=[self._class])
assert ((self.parse_params.get_parameters() == ['""'])
or self.parse_params.get_keywords() is not None), \
("something went wrong with the type handlers;"
" constructors need parameter names, "