# Path: pybindgen/typehandlers/codesink.py
# class CodeSink(object):
#     """Abstract base class for code sinks"""
#     def __init__(self):
#         r'''Constructor
# 
#         >>> sink = MemoryCodeSink()
#         >>> sink.writeln("foo();")
#         >>> sink.writeln("if (true) {")
#         >>> sink.indent()
#         >>> sink.writeln("bar();")
#         >>> sink.unindent()
#         >>> sink.writeln("zbr();")
#         >>> print sink.flush().rstrip()
#         foo();
#         if (true) {
#             bar();
#         zbr();
# 
#         >>> sink = MemoryCodeSink()
#         >>> sink.writeln("foo();")
#         >>> sink.writeln()
#         >>> sink.writeln("bar();")
#         >>> print len(sink.flush().split("\n"))
#         4
#         '''
#         self.indent_level = 0 # current indent level
#         self.indent_stack = [] # previous indent levels
#         if DEBUG:
#             self._last_unindent_stack = None # for debugging
# 
#     def _format_code(self, code):
#         """Utility method for subclasses to use for formatting code
#         (splits lines and indents them)"""
#         assert isinstance(code, string_types)
#         l = []
#         for line in code.split('\n'):
#             l.append(' '*self.indent_level + line)
#         return l
# 
#     def writeln(self, line=''):
#         """Write one or more lines of code"""
#         raise NotImplementedError
# 
#     def indent(self, level=4):
#         '''Add a certain ammount of indentation to all lines written
#         from now on and until unindent() is called'''
#         self.indent_stack.append(self.indent_level)
#         self.indent_level += level
# 
#     def unindent(self):
#         '''Revert indentation level to the value before last indent() call'''
#         if DEBUG:
#             try:
#                 self.indent_level = self.indent_stack.pop()
#             except IndexError:
#                 if self._last_unindent_stack is not None:
#                     for line in traceback.format_list(self._last_unindent_stack):
#                         sys.stderr.write(line)
#                 raise
#             self._last_unindent_stack = traceback.extract_stack()
#         else:
#             self.indent_level = self.indent_stack.pop()
# 
# Path: pybindgen/typehandlers/base.py
# class TypeLookupError(CodegenErrorBase):
#     """Exception that is raised when lookup of a type handler fails"""
# 
# class TypeConfigurationError(CodegenErrorBase):
#     """Exception that is raised when a type handler does not find some
#     information it needs, such as owernship transfer semantics."""
# 
# class CodeGenerationError(CodegenErrorBase):
#     """Exception that is raised when wrapper generation fails for some reason."""
# 
# class NotSupportedError(CodegenErrorBase):
#     """Exception that is raised when declaring an interface configuration
#     that is not supported or not implemented."""
# 
# class Parameter(_Parameter):
#     __metaclass__ = ParameterMeta
# 
# class ReturnValue(_ReturnValue):
#     __metaclass__ = ReturnValueMeta
# 
# Path: pybindgen/settings.py
# def _get_deprecated_virtuals():
#     def handle_error(self, wrapper, exception, traceback_):
# class ErrorHandler(object):


import sys
import warnings
from pybindgen.typehandlers.codesink import CodeSink
from pybindgen.typehandlers.base import TypeLookupError, TypeConfigurationError, CodeGenerationError, NotSupportedError, \
    Parameter, ReturnValue
    from pybindgen.version import __version__
from pybindgen import settings
        if isinstance(retval_spec[-1], dict):
            kwargs = retval_spec[-1]
            args = retval_spec[:-1]
        else:
            kwargs = dict()
            args = retval_spec
    elif isinstance(retval_spec, string_types):
        kwargs = dict()
        args = (retval_spec,)
    else:
        raise TypeError("Could not parse `%r' as a ReturnValue" % retval_spec)
    return args, kwargs


def eval_param(param_value, wrapper=None):
    if isinstance(param_value, Parameter):
        return param_value
    else:
        args, kwargs = parse_param_spec(param_value)
        return call_with_error_handling(Parameter.new, args, kwargs, wrapper,
                                        exceptions_to_handle=(TypeConfigurationError,
                                                              NotSupportedError,
                                                              TypeLookupError))


def eval_retval(retval_value, wrapper=None):
    if isinstance(retval_value, ReturnValue):
        return retval_value
    else:
        args, kwargs = parse_retval_spec(retval_value)

# Path: pybindgen/typehandlers/codesink.py
# class CodeSink(object):
#     """Abstract base class for code sinks"""
#     def __init__(self):
#         r'''Constructor
# 
#         >>> sink = MemoryCodeSink()
#         >>> sink.writeln("foo();")
#         >>> sink.writeln("if (true) {")
#         >>> sink.indent()
#         >>> sink.writeln("bar();")
#         >>> sink.unindent()
#         >>> sink.writeln("zbr();")
#         >>> print sink.flush().rstrip()
#         foo();
#         if (true) {
#             bar();
#         zbr();
# 
#         >>> sink = MemoryCodeSink()
#         >>> sink.writeln("foo();")
#         >>> sink.writeln()
#         >>> sink.writeln("bar();")
#         >>> print len(sink.flush().split("\n"))
#         4
#         '''
#         self.indent_level = 0 # current indent level
#         self.indent_stack = [] # previous indent levels
#         if DEBUG:
#             self._last_unindent_stack = None # for debugging
# 
#     def _format_code(self, code):
#         """Utility method for subclasses to use for formatting code
#         (splits lines and indents them)"""
#         assert isinstance(code, string_types)
#         l = []
#         for line in code.split('\n'):
#             l.append(' '*self.indent_level + line)
#         return l
# 
#     def writeln(self, line=''):
#         """Write one or more lines of code"""
#         raise NotImplementedError
# 
#     def indent(self, level=4):
#         '''Add a certain ammount of indentation to all lines written
#         from now on and until unindent() is called'''
#         self.indent_stack.append(self.indent_level)
#         self.indent_level += level
# 
#     def unindent(self):
#         '''Revert indentation level to the value before last indent() call'''
#         if DEBUG:
#             try:
#                 self.indent_level = self.indent_stack.pop()
#             except IndexError:
#                 if self._last_unindent_stack is not None:
#                     for line in traceback.format_list(self._last_unindent_stack):
#                         sys.stderr.write(line)
#                 raise
#             self._last_unindent_stack = traceback.extract_stack()
#         else:
#             self.indent_level = self.indent_stack.pop()
# 
# Path: pybindgen/typehandlers/base.py
# class TypeLookupError(CodegenErrorBase):
#     """Exception that is raised when lookup of a type handler fails"""
# 
# class TypeConfigurationError(CodegenErrorBase):
#     """Exception that is raised when a type handler does not find some
#     information it needs, such as owernship transfer semantics."""
# 
# class CodeGenerationError(CodegenErrorBase):
#     """Exception that is raised when wrapper generation fails for some reason."""
# 
# class NotSupportedError(CodegenErrorBase):
#     """Exception that is raised when declaring an interface configuration
#     that is not supported or not implemented."""
# 
# class Parameter(_Parameter):
#     __metaclass__ = ParameterMeta
# 
# class ReturnValue(_ReturnValue):
#     __metaclass__ = ReturnValueMeta
# 
# Path: pybindgen/settings.py
# def _get_deprecated_virtuals():
#     def handle_error(self, wrapper, exception, traceback_):
# class ErrorHandler(object):


# Path: pybindgen/utils.py
import sys
import warnings
from pybindgen.typehandlers.codesink import CodeSink
from pybindgen.typehandlers.base import TypeLookupError, TypeConfigurationError, CodeGenerationError, NotSupportedError, \
    Parameter, ReturnValue
    from pybindgen.version import __version__
from pybindgen import settings

        if isinstance(retval_spec[-1], dict):
            kwargs = retval_spec[-1]
            args = retval_spec[:-1]
        else:
            kwargs = dict()
            args = retval_spec
    elif isinstance(retval_spec, string_types):
        kwargs = dict()
        args = (retval_spec,)
    else:
        raise TypeError("Could not parse `%r' as a ReturnValue" % retval_spec)
    return args, kwargs


def eval_param(param_value, wrapper=None):
    if isinstance(param_value, Parameter):
        return param_value
    else:
        args, kwargs = parse_param_spec(param_value)
        return call_with_error_handling(Parameter.new, args, kwargs, wrapper,
                                        exceptions_to_handle=(TypeConfigurationError,
                                                              NotSupportedError,
                                                              TypeLookupError))


def eval_retval(retval_value, wrapper=None):
    if isinstance(retval_value, ReturnValue):
        return retval_value
    else:
        args, kwargs = parse_retval_spec(retval_value)

        return call_with_error_handling(ReturnValue.new, args, kwargs, wrapper,