python-gammu 3.2.5__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gammu/exception.py ADDED
@@ -0,0 +1,41 @@
1
+ # vim: expandtab sw=4 ts=4 sts=4:
2
+ #
3
+ # Copyright © 2003 - 2018 Michal Čihař <michal@cihar.com>
4
+ #
5
+ # This file is part of python-gammu <https://wammu.eu/python-gammu/>
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License along
18
+ # with this program; if not, write to the Free Software Foundation, Inc.,
19
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
+ #
21
+ """Gammu exceptions."""
22
+
23
+ import gammu._gammu
24
+ from gammu import GSMError
25
+
26
+ __all__ = [
27
+ "GSMError",
28
+ ]
29
+
30
+ # Import all exceptions
31
+ for _name in dir(gammu._gammu):
32
+ if not _name.startswith("ERR_"):
33
+ continue
34
+ _temp = __import__("gammu._gammu", globals(), locals(), [_name], 0)
35
+ locals()[_name] = getattr(_temp, _name)
36
+ __all__.append(_name) # noqa: PYI056
37
+
38
+ # Cleanup
39
+ del _name
40
+ del _temp
41
+ del gammu
gammu/smsd.py ADDED
@@ -0,0 +1,25 @@
1
+ # vim: expandtab sw=4 ts=4 sts=4:
2
+ #
3
+ # Copyright © 2003 - 2018 Michal Čihař <michal@cihar.com>
4
+ #
5
+ # This file is part of python-gammu <https://wammu.eu/python-gammu/>
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License along
18
+ # with this program; if not, write to the Free Software Foundation, Inc.,
19
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
+ #
21
+ """SMSD wrapper layer."""
22
+
23
+ from gammu import SMSD
24
+
25
+ __all__ = ["SMSD"]
gammu/worker.py ADDED
@@ -0,0 +1,323 @@
1
+ # vim: expandtab sw=4 ts=4 sts=4:
2
+ #
3
+ # Copyright © 2003 - 2018 Michal Čihař <michal@cihar.com>
4
+ #
5
+ # This file is part of python-gammu <https://wammu.eu/python-gammu/>
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License along
18
+ # with this program; if not, write to the Free Software Foundation, Inc.,
19
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
+ #
21
+ """
22
+ Asynchronous communication to phone.
23
+
24
+ Mostly you should use only L{GammuWorker} class, others are only helpers
25
+ which are used by this class.
26
+ """
27
+
28
+ import queue
29
+ import threading
30
+
31
+ import gammu
32
+
33
+
34
+ class InvalidCommand(Exception):
35
+ """Exception indicating invalid command."""
36
+
37
+ def __init__(self, value) -> None:
38
+ """
39
+ Initializes exception.
40
+
41
+ @param value: Name of wrong command.
42
+ @type value: string
43
+ """
44
+ super().__init__()
45
+ self.value = value
46
+
47
+ def __str__(self) -> str:
48
+ """Returns textual representation of exception."""
49
+ return f'Invalid command: "{self.value}"'
50
+
51
+
52
+ def check_worker_command(command) -> None:
53
+ """
54
+ Checks whether command is valid.
55
+
56
+ @param command: Name of command.
57
+ @type command: string
58
+ """
59
+ if hasattr(gammu.StateMachine, command):
60
+ return
61
+
62
+ raise InvalidCommand(command)
63
+
64
+
65
+ class GammuCommand:
66
+ """Storage of single command for gammu."""
67
+
68
+ def __init__(self, command, params=None, percentage=100) -> None:
69
+ """Creates single command instance."""
70
+ check_worker_command(command)
71
+ self._command = command
72
+ self._params = params
73
+ self._percentage = percentage
74
+
75
+ def get_command(self):
76
+ """Returns command name."""
77
+ return self._command
78
+
79
+ def get_params(self):
80
+ """Returns command params."""
81
+ return self._params
82
+
83
+ def get_percentage(self):
84
+ """Returns percentage of current task."""
85
+ return self._percentage
86
+
87
+ def __str__(self) -> str:
88
+ """Returns textual representation."""
89
+ if self._params is not None:
90
+ return f"{self._command} {self._params}"
91
+ return f"{self._command} ()"
92
+
93
+
94
+ class GammuTask:
95
+ """Storage of tasks for gammu."""
96
+
97
+ def __init__(self, name, commands) -> None:
98
+ """
99
+ Creates single command instance.
100
+
101
+ @param name: Name of task.
102
+ @type name: string
103
+ @param commands: List of commands to execute.
104
+ @type commands: list of tuples or strings
105
+ """
106
+ self._name = name
107
+ self._list = []
108
+ self._pointer = 0
109
+ for i in range(len(commands)):
110
+ if isinstance(commands[i], tuple):
111
+ cmd = commands[i][0]
112
+ try:
113
+ params = commands[i][1]
114
+ except IndexError:
115
+ params = None
116
+ else:
117
+ cmd = commands[i]
118
+ params = None
119
+ percents = round(100 * (i + 1) / len(commands))
120
+ self._list.append(GammuCommand(cmd, params, percents))
121
+
122
+ def get_next(self):
123
+ """Returns next command to be executed as L{GammuCommand}."""
124
+ result = self._list[self._pointer]
125
+ self._pointer += 1
126
+ return result
127
+
128
+ def get_name(self):
129
+ """Returns task name."""
130
+ return self._name
131
+
132
+
133
+ def gammu_pull_device(state_machine) -> None:
134
+ state_machine.ReadDevice()
135
+
136
+
137
+ class GammuThread(threading.Thread):
138
+ """Thread for phone communication."""
139
+
140
+ def __init__(self, queue, config, callback, pull_func=gammu_pull_device) -> None:
141
+ """
142
+ Initialises thread data.
143
+
144
+ @param queue: Queue with events.
145
+ @type queue: queue.Queue object.
146
+
147
+ @param config: Gammu configuration, same as
148
+ L{StateMachine.SetConfig} accepts.
149
+ @type config: hash
150
+
151
+ @param callback: Function which will be called upon operation
152
+ completing.
153
+ @type callback: Function, needs to accept four params: name of
154
+ completed operation, result of it, error code and percentage of
155
+ overall operation. This callback is called from different
156
+ thread, so please take care of various threading issues in other
157
+ modules you use.
158
+ """
159
+ super().__init__()
160
+ self._kill = False
161
+ self._terminate = False
162
+ self._sm = gammu.StateMachine()
163
+ self._callback = callback
164
+ self._queue = queue
165
+ self._sm.SetConfig(0, config)
166
+ self._pull_func = pull_func
167
+
168
+ def _do_command(self, name, cmd, params, percentage=100) -> None:
169
+ """Executes single command on phone."""
170
+ func = getattr(self._sm, cmd)
171
+ error = "ERR_NONE"
172
+ result = None
173
+ try:
174
+ if params is None:
175
+ result = func()
176
+ elif isinstance(params, dict):
177
+ result = func(**params)
178
+ else:
179
+ result = func(*params)
180
+ except gammu.GSMError as info:
181
+ errcode = info.args[0]["Code"]
182
+ error = gammu.ErrorNumbers[errcode]
183
+
184
+ self._callback(name, result, error, percentage)
185
+
186
+ def run(self) -> None:
187
+ """
188
+ Thread body, which handles phone communication.
189
+
190
+ This should not be used from outside.
191
+ """
192
+ start = True
193
+ while not self._kill:
194
+ try:
195
+ if start:
196
+ task = GammuTask("Init", ["Init"])
197
+ start = False
198
+ else:
199
+ # Wait at most ten seconds for next command
200
+ task = self._queue.get(True, 10)
201
+ try:
202
+ while True:
203
+ cmd = task.get_next()
204
+ self._do_command(
205
+ task.get_name(),
206
+ cmd.get_command(),
207
+ cmd.get_params(),
208
+ cmd.get_percentage(),
209
+ )
210
+ except IndexError:
211
+ try:
212
+ if task.get_name() != "Init":
213
+ self._queue.task_done()
214
+ except (AttributeError, ValueError):
215
+ pass
216
+ except queue.Empty:
217
+ if self._terminate:
218
+ break
219
+ # Read the device to catch possible incoming events
220
+ try:
221
+ self._pull_func(self._sm)
222
+ except Exception as ex: # noqa: BLE001
223
+ self._callback("ReadDevice", None, ex, 0)
224
+
225
+ def kill(self) -> None:
226
+ """Forces thread end without emptying queue."""
227
+ self._kill = True
228
+
229
+ def join(self, timeout=None) -> None:
230
+ """Terminates thread and waits for it."""
231
+ self._terminate = True
232
+ super().join(timeout)
233
+
234
+
235
+ class GammuWorker:
236
+ """
237
+ Wrapper class for asynchronous communication with Gammu.
238
+
239
+ It spawns own thread and then passes all commands to this thread. When task
240
+ is done, caller is notified via callback.
241
+ """
242
+
243
+ def __init__(self, callback, pull_func=gammu_pull_device) -> None:
244
+ """
245
+ Initializes worker class.
246
+
247
+ @param callback: See L{GammuThread.__init__} for description.
248
+ """
249
+ self._thread = None
250
+ self._callback = callback
251
+ self._config = {}
252
+ self._lock = threading.Lock()
253
+ self._queue = queue.Queue()
254
+ self._pull_func = pull_func
255
+
256
+ def enqueue_command(self, command, params) -> None:
257
+ """
258
+ Enqueues command.
259
+
260
+ @param command: Command(s) to execute. Each command is tuple
261
+ containing function name and it's parameters.
262
+ @type command: tuple of list of tuples
263
+ @param params: Parameters to command.
264
+ @type params: tuple or string
265
+ """
266
+ self._queue.put(GammuTask(command, [(command, params)]))
267
+
268
+ def enqueue_task(self, command, commands) -> None:
269
+ """
270
+ Enqueues task.
271
+
272
+ @param command: Command(s) to execute. Each command is tuple
273
+ containing function name and it's parameters.
274
+ @type command: tuple of list of tuples
275
+ @param commands: List of commands to execute.
276
+ @type commands: list of tuples or strings
277
+ """
278
+ self._queue.put(GammuTask(command, commands))
279
+
280
+ def enqueue(self, command, params=None, commands=None) -> None:
281
+ """
282
+ Enqueues command or task.
283
+
284
+ @param command: Command(s) to execute. Each command is tuple
285
+ containing function name and it's parameters.
286
+ @type command: tuple of list of tuples
287
+ @param params: Parameters to command.
288
+ @type params: tuple or string
289
+ @param commands: List of commands to execute. When this is not
290
+ none, params are ignored and command is taken as task name.
291
+ @type commands: list of tuples or strings
292
+ """
293
+ if commands is not None:
294
+ self.enqueue_task(command, commands)
295
+ else:
296
+ self.enqueue_command(command, params)
297
+
298
+ def configure(self, config) -> None:
299
+ """
300
+ Configures gammu instance according to config.
301
+
302
+ @param config: Gammu configuration, same as
303
+ L{StateMachine.SetConfig} accepts.
304
+ @type config: hash
305
+ """
306
+ self._config = config
307
+
308
+ def abort(self):
309
+ """Aborts any remaining operations."""
310
+ raise NotImplementedError
311
+
312
+ def initiate(self) -> None:
313
+ """Connects to phone."""
314
+ self._thread = GammuThread(
315
+ self._queue, self._config, self._callback, self._pull_func
316
+ )
317
+ self._thread.start()
318
+
319
+ def terminate(self, timeout=None) -> None:
320
+ """Terminates phone connection."""
321
+ self.enqueue("Terminate")
322
+ self._thread.join(timeout)
323
+ self._thread = None
@@ -0,0 +1,120 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-gammu
3
+ Version: 3.2.5
4
+ Summary: Gammu bindings
5
+ Author-email: Michal Čihař <michal@cihar.com>
6
+ License-Expression: GPL-2.0-or-later
7
+ Project-URL: Download, https://wammu.eu/download/python-gammu/
8
+ Project-URL: Homepage, https://wammu.eu/python-gammu/
9
+ Keywords: calendar,contact,gammu,mobile,phone,SMS,todo
10
+ Platform: Linux
11
+ Platform: Mac OSX
12
+ Platform: Windows 95/98/ME
13
+ Platform: Windows XP/2000/NT
14
+ Classifier: Development Status :: 6 - Mature
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Telecommunications Industry
17
+ Classifier: Operating System :: MacOS
18
+ Classifier: Operating System :: Microsoft :: Windows
19
+ Classifier: Operating System :: POSIX
20
+ Classifier: Operating System :: Unix
21
+ Classifier: Programming Language :: C
22
+ Classifier: Programming Language :: Python :: 3
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Programming Language :: Python :: 3.14
28
+ Classifier: Programming Language :: Python
29
+ Classifier: Topic :: Communications :: Telephony
30
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
31
+ Classifier: Topic :: System :: Hardware
32
+ Requires-Python: >=3.10
33
+ Description-Content-Type: text/x-rst
34
+ License-File: COPYING
35
+ License-File: AUTHORS
36
+ Dynamic: license-file
37
+
38
+ python-gammu
39
+ ============
40
+
41
+ Python bindings for the `Gammu library <https://wammu.eu/gammu/>`_.
42
+
43
+ .. image:: https://github.com/gammu/python-gammu/actions/workflows/test.yml/badge.svg
44
+ :target: https://github.com/gammu/python-gammu/actions/workflows/test.yml
45
+
46
+ .. image:: https://img.shields.io/liberapay/receives/Gammu.svg
47
+ :alt: Liberapay
48
+ :target: https://liberapay.com/Gammu/donate
49
+
50
+ .. image:: https://img.shields.io/pypi/v/python-gammu.svg
51
+ :alt: PyPI
52
+ :target: https://pypi.python.org/pypi/python-gammu/
53
+
54
+ Homepage
55
+ ========
56
+
57
+ <https://wammu.eu/python-gammu/>
58
+
59
+ License
60
+ =======
61
+
62
+ Copyright (C) Michal Čihař <michal@cihar.com>
63
+
64
+ This program is free software; you can redistribute it and/or modify
65
+ it under the terms of the GNU General Public License as published by
66
+ the Free Software Foundation; either version 2 of the License, or
67
+ (at your option) any later version.
68
+
69
+ This program is distributed in the hope that it will be useful,
70
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
71
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72
+ GNU General Public License for more details.
73
+
74
+ You should have received a copy of the GNU General Public License along
75
+ with this program; if not, write to the Free Software Foundation, Inc.,
76
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
77
+
78
+ Installing
79
+ ==========
80
+
81
+ Install it using pip installer::
82
+
83
+ pip install python-gammu
84
+
85
+ Requirements
86
+ ============
87
+
88
+ To compile python-gammu, you need Gammu development files (usually shipped as
89
+ ``libgammu-dev`` or ``gammu-devel`` in Linux distributions).
90
+
91
+ The location of the libraries is discovered using ``pkg-config``,
92
+ ``GAMMU_PATH`` environment variable and falls back to generic locations. In
93
+ case it does not work, either install ``pkg-config`` or set ``GAMMU_PATH``.
94
+
95
+ On Linux something like this should work::
96
+
97
+ GAMMU_PATH=/opt/gammu python setup.py build
98
+
99
+ On Windows::
100
+
101
+ SET GAMMU_PATH="C:\Gammu"
102
+ python setup.py build
103
+
104
+
105
+ Documentation
106
+ =============
107
+
108
+ Please see included python documentation::
109
+
110
+ >>> import gammu
111
+ >>> help(gammu)
112
+
113
+ Alternatively you can use Sphinx to generate browsable version, which is
114
+ also available on-line at <https://wammu.eu/docs/manual/>.
115
+
116
+ Feedback and bug reports
117
+ ========================
118
+
119
+ Any feedback is welcome, see <https://wammu.eu/support/> for information
120
+ how to contact developers.
@@ -0,0 +1,13 @@
1
+ gammu/__init__.py,sha256=Ps8k_ubKaLNnr5KyTTtDF4U9IOtDUX4vPndxKJMBRX0,1089
2
+ gammu/_gammu.cp313-win_amd64.pyd,sha256=jpoG_7SdPquD_nPa1XddGPaQgYIVJC_al_7kUZ3sC0I,1457152
3
+ gammu/asyncworker.py,sha256=xFf8DUb7Iee_zRmoIKyxeTRh_QA8afcxtgwdDt3_gLY,6455
4
+ gammu/data.py,sha256=Rh64yN5hCghWJZWjzve3a4iVw-GOdP6lxCoUNfeb9Tc,8099
5
+ gammu/exception.py,sha256=ZTr1CLwDmrr2ygd-qBHfOMoBfmzltwOzyoSuUFPCtik,1330
6
+ gammu/smsd.py,sha256=Jf0KHvOzxJ1cfX-ch7my-GgeioDwZYkUSad0V23rbo8,971
7
+ gammu/worker.py,sha256=Pz2iovO8RhLa_1xXXxlpsl0G4KblcDR0_7IsWz_-sSg,10527
8
+ python_gammu-3.2.5.dist-info/licenses/AUTHORS,sha256=FW5xxPfFuJoST6r5YwP91QO-KyTcTDrHXPwOBmGu450,105
9
+ python_gammu-3.2.5.dist-info/licenses/COPYING,sha256=GJsa-V1mEVHgVM6hDJGz11Tk3k0_7PsHTB-ylHb3Fns,18431
10
+ python_gammu-3.2.5.dist-info/METADATA,sha256=sQ7MloyzGye_-4IY77-QyFcCPKG9khnSYmqoOFaXTOw,3897
11
+ python_gammu-3.2.5.dist-info/WHEEL,sha256=-WvvtQtdhM1F5HMi-4hSXLQ_1Tg6qJRWO1HnLNr4mCU,102
12
+ python_gammu-3.2.5.dist-info/top_level.txt,sha256=DCkjQyKLL2Scv_sr-bcKLuYLvOBgT2TuYlP4CD2jvNw,6
13
+ python_gammu-3.2.5.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-win_amd64
5
+
@@ -0,0 +1,3 @@
1
+ Michal Čihař <michal@cihar.com>
2
+ Marcin Wiącek <marcin@mwiacek.com>
3
+ ...and many other contributors.