2016-03-28 13:54:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2023-08-14 23:03:36 +00:00
|
|
|
"""ESC/POS Exceptions classes.
|
2016-01-05 16:30:40 +00:00
|
|
|
|
|
|
|
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`
|
2017-05-23 13:13:28 +00:00
|
|
|
- `41` = Image width is too large :py:exc:`~escpos.exceptions.ImageWidthError`
|
2016-01-05 16:30:40 +00:00
|
|
|
- `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`
|
2013-02-27 14:10:34 +00:00
|
|
|
- `90` = USB device not found :py:exc:`~escpos.exceptions.USBNotFoundError`
|
2016-03-02 00:25:38 +00:00
|
|
|
- `100` = Set variable out of range :py:exc:`~escpos.exceptions.SetVariableError`
|
2016-03-15 19:01:15 +00:00
|
|
|
- `200` = Configuration not found :py:exc:`~escpos.exceptions.ConfigNotFoundError`
|
|
|
|
- `210` = Configuration syntax error :py:exc:`~escpos.exceptions.ConfigSyntaxError`
|
2016-03-31 00:10:21 +00:00
|
|
|
- `220` = Configuration section not found :py:exc:`~escpos.exceptions.ConfigSectionMissingError`
|
2016-01-05 16:30:40 +00:00
|
|
|
|
|
|
|
:author: `Manuel F Martinez <manpaz@bashlinux.com>`_ and others
|
|
|
|
:organization: Bashlinux and `python-escpos <https://github.com/python-escpos>`_
|
2017-01-29 23:39:43 +00:00
|
|
|
:copyright: Copyright (c) 2012-2017 Bashlinux and python-escpos
|
|
|
|
:license: MIT
|
2016-01-05 16:30:40 +00:00
|
|
|
"""
|
2010-02-26 08:54:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Error(Exception):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Base class for ESC/POS errors."""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg, status=None):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize Error object."""
|
2010-02-26 08:54:46 +00:00
|
|
|
Exception.__init__(self)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 1
|
|
|
|
if status is not None:
|
|
|
|
self.resultcode = status
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of Error."""
|
2010-02-26 08:54:46 +00:00
|
|
|
return self.msg
|
|
|
|
|
|
|
|
|
|
|
|
class BarcodeTypeError(Error):
|
2021-10-30 16:15:22 +00:00
|
|
|
"""No Barcode type defined.
|
2016-01-05 16:30:40 +00:00
|
|
|
|
|
|
|
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`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize BarcodeTypeError object."""
|
2010-02-26 08:54:46 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 10
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of BarcodeTypeError."""
|
2016-01-08 02:43:33 +00:00
|
|
|
return "No Barcode type is defined ({msg})".format(msg=self.msg)
|
2010-02-26 08:54:46 +00:00
|
|
|
|
2015-11-27 20:20:12 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
class BarcodeSizeError(Error):
|
2021-10-30 16:15:22 +00:00
|
|
|
"""Barcode size is out of range.
|
2016-01-05 16:30:40 +00:00
|
|
|
|
|
|
|
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 returncode is `20`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize BarcodeSizeError object."""
|
2010-02-26 08:54:46 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 20
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of BarcodeSizeError."""
|
2016-01-08 02:43:33 +00:00
|
|
|
return "Barcode size is out of range ({msg})".format(msg=self.msg)
|
2010-02-26 08:54:46 +00:00
|
|
|
|
2015-11-27 20:20:12 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
class BarcodeCodeError(Error):
|
2021-10-30 16:15:22 +00:00
|
|
|
"""No Barcode code was supplied, or it is incorrect.
|
2016-01-05 16:30:40 +00:00
|
|
|
|
2017-10-08 18:05:18 +00:00
|
|
|
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.
|
2016-01-05 16:30:40 +00:00
|
|
|
The returncode for this exception is `30`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize BarcodeCodeError object."""
|
2010-02-26 08:54:46 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 30
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of BarcodeCodeError."""
|
2016-07-23 20:09:35 +00:00
|
|
|
return "No Barcode code was supplied ({msg})".format(msg=self.msg)
|
2010-02-26 08:54:46 +00:00
|
|
|
|
2015-11-27 20:20:12 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
class ImageSizeError(Error):
|
2021-10-30 16:15:22 +00:00
|
|
|
"""Image height is longer than 255px and can't be printed.
|
2016-01-05 16:30:40 +00:00
|
|
|
|
|
|
|
The returncode for this exception is `40`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize ImageSizeError object."""
|
2010-02-26 08:54:46 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 40
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of ImageSizeError."""
|
2021-10-30 16:15:22 +00:00
|
|
|
return "Image height is longer than 255px and can't be printed ({msg})".format(
|
|
|
|
msg=self.msg
|
|
|
|
)
|
2010-02-26 08:54:46 +00:00
|
|
|
|
2015-11-27 20:20:12 +00:00
|
|
|
|
2017-05-23 13:13:28 +00:00
|
|
|
class ImageWidthError(Error):
|
2021-10-30 16:15:22 +00:00
|
|
|
"""Image width is too large.
|
2017-05-23 13:13:28 +00:00
|
|
|
|
|
|
|
The return code for this exception is `41`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2017-05-23 13:13:28 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize ImageWidthError object."""
|
2017-05-23 13:13:28 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 41
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of ImageWidthError."""
|
2017-05-23 13:13:28 +00:00
|
|
|
return "Image width is too large ({msg})".format(msg=self.msg)
|
|
|
|
|
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
class TextError(Error):
|
2021-10-30 16:15:22 +00:00
|
|
|
"""Text string must be supplied to the `text()` method.
|
2016-01-05 16:30:40 +00:00
|
|
|
|
|
|
|
This exception is raised when an empty string is passed to :py:meth:`escpos.escpos.Escpos.text`.
|
|
|
|
The returncode for this exception is `50`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize TextError object."""
|
2010-02-26 08:54:46 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 50
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of TextError."""
|
2021-10-30 16:15:22 +00:00
|
|
|
return "Text string must be supplied to the text() method ({msg})".format(
|
|
|
|
msg=self.msg
|
|
|
|
)
|
2010-02-26 08:54:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CashDrawerError(Error):
|
2021-10-30 16:15:22 +00:00
|
|
|
"""Valid pin must be set in order to send pulse.
|
2016-01-05 16:30:40 +00:00
|
|
|
|
|
|
|
A valid pin number has to be passed onto the method :py:meth:`escpos.escpos.Escpos.cashdraw`.
|
|
|
|
The returncode for this exception is `60`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize CashDrawerError object."""
|
2010-02-26 08:54:46 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 60
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of CashDrawerError."""
|
2016-07-23 20:09:35 +00:00
|
|
|
return "Valid pin must be set to send pulse ({msg})".format(msg=self.msg)
|
2014-05-21 05:15:54 +00:00
|
|
|
|
|
|
|
|
2015-11-27 20:38:59 +00:00
|
|
|
class TabPosError(Error):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""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.
|
2017-07-26 08:01:08 +00:00
|
|
|
Both values multiplied must not exceed 255, since it is the maximum tab value.
|
2016-01-05 16:30:40 +00:00
|
|
|
|
|
|
|
This exception is raised by :py:meth:`escpos.escpos.Escpos.control`.
|
|
|
|
The returncode for this exception is `70`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2014-05-21 05:15:54 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize TabPosError object."""
|
2014-05-21 05:15:54 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 70
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of TabPosError."""
|
2021-10-30 16:15:22 +00:00
|
|
|
return "Valid tab positions must be in the range 0 to 16 ({msg})".format(
|
|
|
|
msg=self.msg
|
|
|
|
)
|
2014-05-21 05:15:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CharCodeError(Error):
|
2021-10-30 16:15:22 +00:00
|
|
|
"""Valid char code must be set.
|
2016-01-05 16:30:40 +00:00
|
|
|
|
|
|
|
The supplied charcode-name in :py:meth:`escpos.escpos.Escpos.charcode` is unknown.
|
|
|
|
Ths returncode for this exception is `80`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2014-05-21 05:15:54 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize CharCodeError object."""
|
2014-05-21 05:15:54 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
2016-01-05 16:30:40 +00:00
|
|
|
self.resultcode = 80
|
2014-05-21 05:15:54 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of CharCodeError."""
|
2016-07-23 20:09:35 +00:00
|
|
|
return "Valid char code must be set ({msg})".format(msg=self.msg)
|
2013-02-27 14:10:34 +00:00
|
|
|
|
2016-01-08 02:34:14 +00:00
|
|
|
|
2013-02-27 14:10:34 +00:00
|
|
|
class USBNotFoundError(Error):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Device wasn't found (probably not plugged in).
|
2013-02-27 14:10:34 +00:00
|
|
|
|
|
|
|
The USB device seems to be not plugged in.
|
|
|
|
Ths returncode for this exception is `90`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2013-02-27 14:10:34 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize USBNotFoundError object."""
|
2013-02-27 14:10:34 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 90
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of USBNotFoundError."""
|
2016-07-23 20:09:35 +00:00
|
|
|
return "USB device not found ({msg})".format(msg=self.msg)
|
2016-03-02 00:25:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SetVariableError(Error):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""A set method variable was out of range.
|
2016-03-02 00:25:38 +00:00
|
|
|
|
|
|
|
Check set variables against minimum and maximum values
|
|
|
|
Ths returncode for this exception is `100`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2016-03-02 00:25:38 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize SetVariableError object."""
|
2016-03-02 00:25:38 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 100
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of SetVariableError."""
|
2016-07-23 20:09:35 +00:00
|
|
|
return "Set variable out of range ({msg})".format(msg=self.msg)
|
2016-03-15 19:01:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Configuration errors
|
|
|
|
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2016-03-15 19:01:15 +00:00
|
|
|
class ConfigNotFoundError(Error):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""The configuration file was not found.
|
2016-03-15 19:01:15 +00:00
|
|
|
|
|
|
|
The default or passed configuration file could not be read
|
|
|
|
Ths returncode for this exception is `200`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2016-03-15 19:01:15 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize ConfigNotFoundError object."""
|
2016-03-15 19:01:15 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 200
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of ConfigNotFoundError."""
|
2016-03-15 19:01:15 +00:00
|
|
|
return "Configuration not found ({msg})".format(msg=self.msg)
|
|
|
|
|
2016-06-19 10:25:40 +00:00
|
|
|
|
2016-03-15 19:01:15 +00:00
|
|
|
class ConfigSyntaxError(Error):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""The configuration file is invalid.
|
2016-03-15 19:01:15 +00:00
|
|
|
|
2016-03-31 00:10:21 +00:00
|
|
|
The syntax is incorrect
|
2016-03-15 19:01:15 +00:00
|
|
|
Ths returncode for this exception is `210`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2016-03-15 19:01:15 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize ConfigSyntaxError object."""
|
2016-03-15 19:01:15 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 210
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of ConfigSyntaxError."""
|
2016-03-15 19:01:15 +00:00
|
|
|
return "Configuration syntax is invalid ({msg})".format(msg=self.msg)
|
2016-03-31 00:10:21 +00:00
|
|
|
|
2016-06-19 10:25:40 +00:00
|
|
|
|
2016-03-31 00:10:21 +00:00
|
|
|
class ConfigSectionMissingError(Error):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""The configuration file is missing a section.
|
2016-03-31 00:10:21 +00:00
|
|
|
|
|
|
|
The part of the config asked for doesn't exist in the loaded configuration
|
|
|
|
Ths returncode for this exception is `220`.
|
|
|
|
"""
|
2021-10-30 16:15:22 +00:00
|
|
|
|
2016-03-31 00:10:21 +00:00
|
|
|
def __init__(self, msg=""):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Initialize ConfigSectionMissingError object."""
|
2016-03-31 00:10:21 +00:00
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 220
|
|
|
|
|
|
|
|
def __str__(self):
|
2023-08-14 23:03:36 +00:00
|
|
|
"""Return string representation of ConfigSectionMissingError."""
|
2016-03-31 00:10:21 +00:00
|
|
|
return "Configuration section is missing ({msg})".format(msg=self.msg)
|