1
0
mirror of https://github.com/python-escpos/python-escpos synced 2025-09-13 09:09:58 +00:00

Drop Py37, improve typing and docstrings (#544)

Drops Py3.7, improves typing and adds a mypy config, improves the docstrings and isorts the imports.

* configure isort
* sort with isort
* add github action
* enable flake8-docstrings
* fix docstrings
* add mypy env
* no implicit optional
* add type for raw
* add some type hints
This commit is contained in:
Patrick Kanzler
2023-08-15 01:03:36 +02:00
committed by GitHub
parent 2b62c8e28d
commit fbabd8ed88
45 changed files with 465 additions and 345 deletions

View File

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
""" ESC/POS Exceptions classes
"""ESC/POS Exceptions classes.
Result/Exit codes:
@@ -27,9 +27,10 @@ Result/Exit codes:
class Error(Exception):
"""Base class for ESC/POS errors"""
"""Base class for ESC/POS errors."""
def __init__(self, msg, status=None):
"""Initialize Error object."""
Exception.__init__(self)
self.msg = msg
self.resultcode = 1
@@ -37,6 +38,7 @@ class Error(Exception):
self.resultcode = status
def __str__(self):
"""Return string representation of Error."""
return self.msg
@@ -49,11 +51,13 @@ class BarcodeTypeError(Error):
"""
def __init__(self, msg=""):
"""Initialize BarcodeTypeError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 10
def __str__(self):
"""Return string representation of BarcodeTypeError."""
return "No Barcode type is defined ({msg})".format(msg=self.msg)
@@ -66,11 +70,13 @@ class BarcodeSizeError(Error):
"""
def __init__(self, msg=""):
"""Initialize BarcodeSizeError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 20
def __str__(self):
"""Return string representation of BarcodeSizeError."""
return "Barcode size is out of range ({msg})".format(msg=self.msg)
@@ -83,11 +89,13 @@ class BarcodeCodeError(Error):
"""
def __init__(self, msg=""):
"""Initialize BarcodeCodeError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 30
def __str__(self):
"""Return string representation of BarcodeCodeError."""
return "No Barcode code was supplied ({msg})".format(msg=self.msg)
@@ -98,11 +106,13 @@ class ImageSizeError(Error):
"""
def __init__(self, msg=""):
"""Initialize ImageSizeError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 40
def __str__(self):
"""Return string representation of ImageSizeError."""
return "Image height is longer than 255px and can't be printed ({msg})".format(
msg=self.msg
)
@@ -115,11 +125,13 @@ class ImageWidthError(Error):
"""
def __init__(self, msg=""):
"""Initialize ImageWidthError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 41
def __str__(self):
"""Return string representation of ImageWidthError."""
return "Image width is too large ({msg})".format(msg=self.msg)
@@ -131,11 +143,13 @@ class TextError(Error):
"""
def __init__(self, msg=""):
"""Initialize TextError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 50
def __str__(self):
"""Return string representation of TextError."""
return "Text string must be supplied to the text() method ({msg})".format(
msg=self.msg
)
@@ -149,16 +163,20 @@ class CashDrawerError(Error):
"""
def __init__(self, msg=""):
"""Initialize CashDrawerError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 60
def __str__(self):
"""Return string representation of CashDrawerError."""
return "Valid pin must be set to send pulse ({msg})".format(msg=self.msg)
class TabPosError(Error):
"""Valid tab positions must be set by using from 1 to 32 tabs, and between 1 and 255 tab size values.
"""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`.
@@ -166,11 +184,13 @@ class TabPosError(Error):
"""
def __init__(self, msg=""):
"""Initialize TabPosError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 70
def __str__(self):
"""Return string representation of TabPosError."""
return "Valid tab positions must be in the range 0 to 16 ({msg})".format(
msg=self.msg
)
@@ -184,43 +204,49 @@ class CharCodeError(Error):
"""
def __init__(self, msg=""):
"""Initialize CharCodeError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 80
def __str__(self):
"""Return string representation of CharCodeError."""
return "Valid char code must be set ({msg})".format(msg=self.msg)
class USBNotFoundError(Error):
"""Device wasn't found (probably not plugged in)
"""Device wasn't found (probably not plugged in).
The USB device seems to be not plugged in.
Ths returncode for this exception is `90`.
"""
def __init__(self, msg=""):
"""Initialize USBNotFoundError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 90
def __str__(self):
"""Return string representation of USBNotFoundError."""
return "USB device not found ({msg})".format(msg=self.msg)
class SetVariableError(Error):
"""A set method variable was out of range
"""A set method variable was out of range.
Check set variables against minimum and maximum values
Ths returncode for this exception is `100`.
"""
def __init__(self, msg=""):
"""Initialize SetVariableError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 100
def __str__(self):
"""Return string representation of SetVariableError."""
return "Set variable out of range ({msg})".format(msg=self.msg)
@@ -228,48 +254,54 @@ class SetVariableError(Error):
class ConfigNotFoundError(Error):
"""The configuration file was not found
"""The configuration file was not found.
The default or passed configuration file could not be read
Ths returncode for this exception is `200`.
"""
def __init__(self, msg=""):
"""Initialize ConfigNotFoundError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 200
def __str__(self):
"""Return string representation of ConfigNotFoundError."""
return "Configuration not found ({msg})".format(msg=self.msg)
class ConfigSyntaxError(Error):
"""The configuration file is invalid
"""The configuration file is invalid.
The syntax is incorrect
Ths returncode for this exception is `210`.
"""
def __init__(self, msg=""):
"""Initialize ConfigSyntaxError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 210
def __str__(self):
"""Return string representation of ConfigSyntaxError."""
return "Configuration syntax is invalid ({msg})".format(msg=self.msg)
class ConfigSectionMissingError(Error):
"""The configuration file is missing a section
"""The configuration file is missing a section.
The part of the config asked for doesn't exist in the loaded configuration
Ths returncode for this exception is `220`.
"""
def __init__(self, msg=""):
"""Initialize ConfigSectionMissingError object."""
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 220
def __str__(self):
"""Return string representation of ConfigSectionMissingError."""
return "Configuration section is missing ({msg})".format(msg=self.msg)