FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-escpos/src/escpos/exceptions.py at master · python-escpos/python-escpos · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
python-escpos
/
python-escpos
Public
Notifications
You must be signed in to change notification settings
Fork
316
Star
1.3k
Code
Issues
60
Pull requests
12
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-escpos
/
src
/
escpos
/
exceptions.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
444 lines (302 loc) · 12.6 KB
Breadcrumbs
python-escpos
/
src
/
escpos
/
exceptions.py
Copy path
File metadata and controls
444 lines (302 loc) · 12.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# -*- coding: utf-8 -*-
"""ESC/POS Exceptions classes.
Result/Exit codes:
- `0` = success
- `10` = No Barcode type defined :py:exc:`~escpos.exceptions.BarcodeTypeError`
- `20` = Barcode size values are out of range :py:exc:`~escpos.exceptions.BarcodeSizeError`
- `30` = Barcode text not supplied :py:exc:`~escpos.exceptions.BarcodeCodeError`
- `40` = Image height is too large :py:exc:`~escpos.exceptions.ImageSizeError`
- `41` = Image width is too large :py:exc:`~escpos.exceptions.ImageWidthError`
- `50` = No string supplied to be printed :py:exc:`~escpos.exceptions.TextError`
- `60` = Invalid pin to send Cash Drawer pulse :py:exc:`~escpos.exceptions.CashDrawerError`
- `70` = Invalid number of tab positions :py:exc:`~escpos.exceptions.TabPosError`
- `80` = Invalid char code :py:exc:`~escpos.exceptions.CharCodeError`
- `90` = Device not found :py:exc:`~escpos.exceptions.DeviceNotFoundError`
- `91` = USB device not found :py:exc:`~escpos.exceptions.USBNotFoundError`
- `100` = Set variable out of range :py:exc:`~escpos.exceptions.SetVariableError`
- `110` = Invalid response format :py:exc:`~escpos.exceptions.ValidationError`
- `200` = Configuration not found :py:exc:`~escpos.exceptions.ConfigNotFoundError`
- `210` = Configuration syntax error :py:exc:`~escpos.exceptions.ConfigSyntaxError`
- `220` = Configuration section not found :py:exc:`~escpos.exceptions.ConfigSectionMissingError`
:author: python-escpos developers
:organization: Bashlinux and `python-escpos <https://github.com/python-escpos>`_
:copyright: Copyright (c) 2012-2017 Bashlinux and python-escpos
:license: MIT
"""
from
typing
import
Optional
class
Error
(
Exception
):
"""Base class for ESC/POS errors.
inheritance:
.. inheritance-diagram:: escpos.exceptions.Error
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
,
status
:
Optional
[
int
]
=
None
)
->
None
:
"""Initialize Error object."""
Exception
.
__init__
(
self
)
self
.
msg
=
msg
self
.
resultcode
=
1
if
status
is
not
None
:
self
.
resultcode
=
status
def
__str__
(
self
)
->
str
:
"""Return string representation of Error."""
return
self
.
msg
class
BarcodeTypeError
(
Error
):
"""No Barcode type defined.
This exception indicates that no known barcode-type has been entered. The barcode-type has to be
one of those specified in :py:meth:`escpos.escpos.Escpos.barcode`.
The returned error code is `10`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.BarcodeTypeError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize BarcodeTypeError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
10
def
__str__
(
self
)
->
str
:
"""Return string representation of BarcodeTypeError."""
return
f"No Barcode type is defined (
{
self
.
msg
}
)"
class
BarcodeSizeError
(
Error
):
"""Barcode size is out of range.
This exception indicates that the values for the barcode size are out of range.
The size of the barcode has to be in the range that is specified in :py:meth:`escpos.escpos.Escpos.barcode`.
The resulting return code is `20`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.BarcodeSizeError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize BarcodeSizeError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
20
def
__str__
(
self
)
->
str
:
"""Return string representation of BarcodeSizeError."""
return
f"Barcode size is out of range (
{
self
.
msg
}
)"
class
BarcodeCodeError
(
Error
):
"""No Barcode code was supplied, or it is incorrect.
No data for the barcode has been supplied in :py:meth:`escpos.escpos.Escpos.barcode` or the the `check` parameter
was True and the check failed.
The return code for this exception is `30`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.BarcodeCodeError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize BarcodeCodeError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
30
def
__str__
(
self
)
->
str
:
"""Return string representation of BarcodeCodeError."""
return
f"No Barcode code was supplied (
{
self
.
msg
}
)"
class
ImageSizeError
(
Error
):
"""Image height is longer than 255px and can't be printed.
The return code for this exception is `40`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.ImageSizeError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize ImageSizeError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
40
def
__str__
(
self
)
->
str
:
"""Return string representation of ImageSizeError."""
return
f"Image height is longer than 255px and can't be printed (
{
self
.
msg
}
)"
class
ImageWidthError
(
Error
):
"""Image width is too large.
The return code for this exception is `41`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.ImageWidthError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize ImageWidthError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
41
def
__str__
(
self
)
->
str
:
"""Return string representation of ImageWidthError."""
return
f"Image width is too large (
{
self
.
msg
}
)"
class
TextError
(
Error
):
"""Text string must be supplied to the `text()` method.
This exception is raised when an empty string is passed to :py:meth:`escpos.escpos.Escpos.text`.
The return code for this exception is `50`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.TextError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize TextError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
50
def
__str__
(
self
)
->
str
:
"""Return string representation of TextError."""
return
f"Text string must be supplied to the text() method (
{
self
.
msg
}
)"
class
CashDrawerError
(
Error
):
"""Valid pin must be set in order to send pulse.
A valid pin number has to be passed onto the method :py:meth:`escpos.escpos.Escpos.cashdraw`.
The return code for this exception is `60`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.CashDrawerError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize CashDrawerError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
60
def
__str__
(
self
)
->
str
:
"""Return string representation of CashDrawerError."""
return
f"Valid pin must be set to send pulse (
{
self
.
msg
}
)"
class
TabPosError
(
Error
):
"""Tab position is invalid.
Valid tab positions must be set by using from 1 to 32 tabs, and between 1 and 255 tab size values.
Both values multiplied must not exceed 255, since it is the maximum tab value.
This exception is raised by :py:meth:`escpos.escpos.Escpos.control`.
The return code for this exception is `70`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.TabPosError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize TabPosError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
70
def
__str__
(
self
)
->
str
:
"""Return string representation of TabPosError."""
return
f"Valid tab positions must be in the range 0 to 16 (
{
self
.
msg
}
)"
class
CharCodeError
(
Error
):
"""Valid char code must be set.
The supplied charcode-name in :py:meth:`escpos.escpos.Escpos.charcode` is unknown.
The return code for this exception is `80`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.CharCodeError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize CharCodeError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
80
def
__str__
(
self
)
->
str
:
"""Return string representation of CharCodeError."""
return
f"Valid char code must be set (
{
self
.
msg
}
)"
class
DeviceNotFoundError
(
Error
):
"""Device was not found.
The device seems to be not accessible.
The return code for this exception is `90`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.Error
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize DeviceNotFoundError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
90
def
__str__
(
self
)
->
str
:
"""Return string representation of DeviceNotFoundError."""
return
f"Device not found (
{
self
.
msg
}
)"
class
USBNotFoundError
(
DeviceNotFoundError
):
"""USB device was not found (probably not plugged in).
The USB device seems to be not plugged in.
The return code for this exception is `91`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.USBNotFoundError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize USBNotFoundError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
91
def
__str__
(
self
)
->
str
:
"""Return string representation of USBNotFoundError."""
return
f"USB device not found (
{
self
.
msg
}
)"
class
SetVariableError
(
Error
):
"""A set method variable was out of range.
Check set variables against minimum and maximum values
The return code for this exception is `100`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.SetVariableError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize SetVariableError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
100
def
__str__
(
self
)
->
str
:
"""Return string representation of SetVariableError."""
return
f"Set variable out of range (
{
self
.
msg
}
)"
class
ValidationError
(
Error
):
"""Invalid response format.
An error occurred while validating data.
The return code for this exception is `110`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.ValidationError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize ValidationError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
110
def
__str__
(
self
)
->
str
:
"""Return string representation of ValidationError."""
return
f"Invalid data (
{
self
.
msg
}
)"
# Configuration errors
class
ConfigNotFoundError
(
Error
):
"""The configuration file was not found.
The default or passed configuration file could not be read
The return code for this exception is `200`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.ConfigNotFoundError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize ConfigNotFoundError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
200
def
__str__
(
self
)
->
str
:
"""Return string representation of ConfigNotFoundError."""
return
f"Configuration not found (
{
self
.
msg
}
)"
class
ConfigSyntaxError
(
Error
):
"""The configuration file is invalid.
The syntax is incorrect
The return code for this exception is `210`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.ConfigSyntaxError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize ConfigSyntaxError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
210
def
__str__
(
self
)
->
str
:
"""Return string representation of ConfigSyntaxError."""
return
f"Configuration syntax is invalid (
{
self
.
msg
}
)"
class
ConfigSectionMissingError
(
Error
):
"""The configuration file is missing a section.
The part of the config asked for does not exist in the loaded configuration
The return code for this exception is `220`.
inheritance:
.. inheritance-diagram:: escpos.exceptions.ConfigSectionMissingError
:parts: 1
"""
def
__init__
(
self
,
msg
:
str
=
""
)
->
None
:
"""Initialize ConfigSectionMissingError object."""
Error
.
__init__
(
self
,
msg
)
self
.
msg
=
msg
self
.
resultcode
=
220
def
__str__
(
self
)
->
str
:
"""Return string representation of ConfigSectionMissingError."""
return
f"Configuration section is missing (
{
self
.
msg
}
)"
Back
|
FazBrowse Home
|
New Git URL