# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.2
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.





from sys import version_info
if version_info >= (3,0,0):
    new_instancemethod = lambda func, inst, cls: _gphoto2_port_log.SWIG_PyInstanceMethod_New(func)
else:
    from new import instancemethod as new_instancemethod
if version_info >= (2,6,0):
    def swig_import_helper():
        from os.path import dirname
        import imp
        fp = None
        try:
            fp, pathname, description = imp.find_module('_gphoto2_port_log', [dirname(__file__)])
        except ImportError:
            import _gphoto2_port_log
            return _gphoto2_port_log
        if fp is not None:
            try:
                _mod = imp.load_module('_gphoto2_port_log', fp, pathname, description)
            finally:
                fp.close()
            return _mod
    _gphoto2_port_log = swig_import_helper()
    del swig_import_helper
else:
    import _gphoto2_port_log
del version_info
try:
    _swig_property = property
except NameError:
    pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
    if (name == "thisown"): return self.this.own(value)
    if (name == "this"):
        if type(value).__name__ == 'SwigPyObject':
            self.__dict__[name] = value
            return
    method = class_type.__swig_setmethods__.get(name,None)
    if method: return method(self,value)
    if (not static):
        self.__dict__[name] = value
    else:
        raise AttributeError("You cannot add attributes to %s" % self)

def _swig_setattr(self,class_type,name,value):
    return _swig_setattr_nondynamic(self,class_type,name,value,0)

def _swig_getattr(self,class_type,name):
    if (name == "thisown"): return self.this.own()
    method = class_type.__swig_getmethods__.get(name,None)
    if method: return method(self)
    raise AttributeError(name)

def _swig_repr(self):
    try: strthis = "proxy of " + self.this.__repr__()
    except: strthis = ""
    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)

try:
    _object = object
    _newclass = 1
except AttributeError:
    class _object : pass
    _newclass = 0


def _swig_setattr_nondynamic_method(set):
    def set_attr(self,name,value):
        if (name == "thisown"): return self.this.own(value)
        if hasattr(self,name) or (name == "this"):
            set(self,name,value)
        else:
            raise AttributeError("You cannot add attributes to %s" % self)
    return set_attr



def gp_log_add_func_py(*args) -> "int" :
  """
    gp_log_add_func_py(level, func) -> int

    Parameters:
        level: enum GPLogLevel
        func: PyObject *

    """
  return _gphoto2_port_log.gp_log_add_func_py(*args)

def gp_log_remove_func_py(*args) -> "int" :
  """
    gp_log_remove_func_py(id) -> int

    Parameters:
        id: int

    """
  return _gphoto2_port_log.gp_log_remove_func_py(*args)
GP_LOG_ERROR = _gphoto2_port_log.GP_LOG_ERROR
GP_LOG_VERBOSE = _gphoto2_port_log.GP_LOG_VERBOSE
GP_LOG_DEBUG = _gphoto2_port_log.GP_LOG_DEBUG
GP_LOG_DATA = _gphoto2_port_log.GP_LOG_DATA

def gp_log_remove_func(*args) -> "int" :
  """
    gp_log_remove_func(id) -> int

    Parameters:
        id: int

    """
  return _gphoto2_port_log.gp_log_remove_func(*args)

def gp_log(*args) -> "void" :
  """
    gp_log(level, domain, format)

    Parameters:
        level: enum GPLogLevel
        domain: char const *
        format: char const *

    """
  return _gphoto2_port_log.gp_log(*args)
import logging

from gphoto2.gphoto2_result import check_result, GP_OK

class _GPhoto2Logger(object):
    def __init__(self):
        self.log = None
        self.log_id = -1
        self.mapping = {}

    def callback(self, level, domain, msg):
        self.log(self.mapping[level], '(%s) %s', domain, msg)

    def install(self, mapping):
        self.mapping.update(mapping)
        if not self.log:
            self.log = logging.getLogger('gphoto2').log
        if self.log_id >= GP_OK:
            check_result(gp_log_remove_func(self.log_id))
        self.log_id = gp_log_add_func_py(GP_LOG_DATA, self.callback)
        return self.log_id

_gphoto2_logger = _GPhoto2Logger()

def use_python_logging(
    mapping = {
        GP_LOG_ERROR   : logging.WARNING,
        GP_LOG_VERBOSE : logging.INFO,
        GP_LOG_DEBUG   : logging.DEBUG,
        GP_LOG_DATA    : logging.DEBUG - 5,
        }):
    """Install a callback to receive gphoto2 errors and forward them
    to Python's logging system.

    The mapping parameter is a dictionary mapping each of the four
    gphoto2 logging severity levels to a Python logging level.

    """
    return _gphoto2_logger.install(mapping)



