1# This file was automatically generated by SWIG (http://www.swig.org).
2# Version 4.0.2
3#
4# Do not make changes to this file unless you know what you are doing--modify
5# the SWIG interface file instead.
6
7from sys import version_info as _swig_python_version_info
8if _swig_python_version_info < (2, 7, 0):
9    raise RuntimeError("Python 2.7 or later required")
10
11# Import the low-level C/C++ module
12if __package__ or "." in __name__:
13    from . import _result
14else:
15    import _result
16
17try:
18    import builtins as __builtin__
19except ImportError:
20    import __builtin__
21
22_swig_new_instance_method = _result.SWIG_PyInstanceMethod_New
23_swig_new_static_method = _result.SWIG_PyStaticMethod_New
24
25def _swig_repr(self):
26    try:
27        strthis = "proxy of " + self.this.__repr__()
28    except __builtin__.Exception:
29        strthis = ""
30    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
31
32
33def _swig_setattr_nondynamic_instance_variable(set):
34    def set_instance_attr(self, name, value):
35        if name == "thisown":
36            self.this.own(value)
37        elif name == "this":
38            set(self, name, value)
39        elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
40            set(self, name, value)
41        else:
42            raise AttributeError("You cannot add instance attributes to %s" % self)
43    return set_instance_attr
44
45
46def _swig_setattr_nondynamic_class_variable(set):
47    def set_class_attr(cls, name, value):
48        if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
49            set(cls, name, value)
50        else:
51            raise AttributeError("You cannot add class attributes to %s" % cls)
52    return set_class_attr
53
54
55def _swig_add_metaclass(metaclass):
56    """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
57    def wrapper(cls):
58        return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
59    return wrapper
60
61
62class _SwigNonDynamicMeta(type):
63    """Meta class to enforce nondynamic attributes (no new attributes) for a class"""
64    __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)
65
66
67import gphoto2.abilities_list
68import gphoto2.camera
69import gphoto2.context
70import gphoto2.file
71import gphoto2.filesys
72import gphoto2.list
73import gphoto2.port_info_list
74import gphoto2.port_log
75import gphoto2.version
76import gphoto2.widget
77GP_OK = _result.GP_OK
78
79GP_ERROR = _result.GP_ERROR
80
81GP_ERROR_BAD_PARAMETERS = _result.GP_ERROR_BAD_PARAMETERS
82
83GP_ERROR_NO_MEMORY = _result.GP_ERROR_NO_MEMORY
84
85GP_ERROR_LIBRARY = _result.GP_ERROR_LIBRARY
86
87GP_ERROR_UNKNOWN_PORT = _result.GP_ERROR_UNKNOWN_PORT
88
89GP_ERROR_NOT_SUPPORTED = _result.GP_ERROR_NOT_SUPPORTED
90
91GP_ERROR_IO = _result.GP_ERROR_IO
92
93GP_ERROR_FIXED_LIMIT_EXCEEDED = _result.GP_ERROR_FIXED_LIMIT_EXCEEDED
94
95GP_ERROR_TIMEOUT = _result.GP_ERROR_TIMEOUT
96
97GP_ERROR_IO_SUPPORTED_SERIAL = _result.GP_ERROR_IO_SUPPORTED_SERIAL
98
99GP_ERROR_IO_SUPPORTED_USB = _result.GP_ERROR_IO_SUPPORTED_USB
100
101GP_ERROR_IO_INIT = _result.GP_ERROR_IO_INIT
102
103GP_ERROR_IO_READ = _result.GP_ERROR_IO_READ
104
105GP_ERROR_IO_WRITE = _result.GP_ERROR_IO_WRITE
106
107GP_ERROR_IO_UPDATE = _result.GP_ERROR_IO_UPDATE
108
109GP_ERROR_IO_SERIAL_SPEED = _result.GP_ERROR_IO_SERIAL_SPEED
110
111GP_ERROR_IO_USB_CLEAR_HALT = _result.GP_ERROR_IO_USB_CLEAR_HALT
112
113GP_ERROR_IO_USB_FIND = _result.GP_ERROR_IO_USB_FIND
114
115GP_ERROR_IO_USB_CLAIM = _result.GP_ERROR_IO_USB_CLAIM
116
117GP_ERROR_IO_LOCK = _result.GP_ERROR_IO_LOCK
118
119GP_ERROR_HAL = _result.GP_ERROR_HAL
120
121gp_port_result_as_string = _result.gp_port_result_as_string
122GP_ERROR_CORRUPTED_DATA = _result.GP_ERROR_CORRUPTED_DATA
123
124GP_ERROR_FILE_EXISTS = _result.GP_ERROR_FILE_EXISTS
125
126GP_ERROR_MODEL_NOT_FOUND = _result.GP_ERROR_MODEL_NOT_FOUND
127
128GP_ERROR_DIRECTORY_NOT_FOUND = _result.GP_ERROR_DIRECTORY_NOT_FOUND
129
130GP_ERROR_FILE_NOT_FOUND = _result.GP_ERROR_FILE_NOT_FOUND
131
132GP_ERROR_DIRECTORY_EXISTS = _result.GP_ERROR_DIRECTORY_EXISTS
133
134GP_ERROR_CAMERA_BUSY = _result.GP_ERROR_CAMERA_BUSY
135
136GP_ERROR_PATH_NOT_ABSOLUTE = _result.GP_ERROR_PATH_NOT_ABSOLUTE
137
138GP_ERROR_CANCEL = _result.GP_ERROR_CANCEL
139
140GP_ERROR_CAMERA_ERROR = _result.GP_ERROR_CAMERA_ERROR
141
142GP_ERROR_OS_FAILURE = _result.GP_ERROR_OS_FAILURE
143
144GP_ERROR_NO_SPACE = _result.GP_ERROR_NO_SPACE
145
146gp_result_as_string = _result.gp_result_as_string
147
148import logging
149
150# user adjustable check_result lookup table
151error_severity = {
152    GP_ERROR_CANCEL           : logging.INFO,
153    GP_ERROR_DIRECTORY_EXISTS : logging.WARNING,
154    }
155error_exception = logging.ERROR
156
157_return_logger = logging.getLogger('gphoto2.returnvalue')
158
159def check_result(result):
160    """Pops gphoto2 'error' value from 'result' list and checks it.
161
162    If there is no error the remaining result is returned. For other
163    errors a severity level is taken from the error_severity dict, or
164    set to logging.CRITICAL if the error is not in error_severity.
165
166    If the severity >= error_exception an exception is raised.
167    Otherwise a message is logged at the appropriate severity level.
168    """
169
170    if not isinstance(result, (tuple, list)):
171        error = result
172    elif len(result) == 2:
173        error, result = result
174    else:
175        error = result[0]
176        result = result[1:]
177    if error >= GP_OK:
178        return result
179    severity = logging.CRITICAL
180    if error in error_severity:
181        severity = error_severity[error]
182    if severity >= error_exception:
183        raise gphoto2.GPhoto2Error(error)
184    _return_logger.log(severity, '[%d] %s', error, gp_result_as_string(error))
185    return result
186
187
188
189