Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bea4f29
fix unfinished Python2 -> 3 translation
a-detiste Dec 10, 2023
35565d5
remove some six usage
a-detiste Dec 10, 2023
6aec41f
annotate
a-detiste Dec 10, 2023
5bd936b
run isort & black
a-detiste Dec 10, 2023
324a236
pyflakes3
a-detiste Dec 10, 2023
8c8660b
fix regression in Six removal
a-detiste Dec 10, 2023
1f232fa
Merge remote-tracking branch 'origin/master' into pr/a-detiste/607
patkan Dec 10, 2023
369e709
use Type instead of type
patkan Dec 10, 2023
9a941e8
from __future__ import annotations
a-detiste Dec 10, 2023
e6380d1
Revert "use Type instead of type"
patkan Dec 10, 2023
56cabce
mypy: self.enf is always defined
a-detiste Dec 11, 2023
a8e38be
fix return type of cups.py
a-detiste Dec 13, 2023
a0ec58d
Usb idVendor/idProduct are integers
a-detiste Dec 13, 2023
44893f9
self.default_args is always defined
a-detiste Dec 13, 2023
fb6b9d9
tweak usb_args, PEP589 is better
a-detiste Dec 13, 2023
1147472
lp.py: reassure mypy
a-detiste Dec 13, 2023
e7db5a9
run black
a-detiste Dec 13, 2023
512a5ff
correctly cast call to CashDrawerError()
a-detiste Dec 13, 2023
45829b8
pyflakes3
a-detiste Dec 13, 2023
254eae0
update CUPS test
a-detiste Dec 13, 2023
aa2e5cd
add missing close() method in metaclass
a-detiste Dec 13, 2023
180721c
document a bug in typeshed
a-detiste Dec 13, 2023
0f2ee2b
query_status() returns bytes as seen in constants.py
a-detiste Dec 13, 2023
99b9484
remove more SIX usage
a-detiste Dec 13, 2023
7ad4396
isort
a-detiste Dec 13, 2023
3fb52f4
test examples too
patkan Dec 15, 2023
d68f187
Merge branch 'master' into master
patkan Dec 15, 2023
5c5acff
remove type comment where type is annotated
patkan Dec 15, 2023
b634354
adapt behavior of cups printer to match other implementations
patkan Dec 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/codepage_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import sys

import six

from escpos import printer
from escpos.constants import (
CODEPAGE_CHANGE,
Expand Down Expand Up @@ -38,7 +36,7 @@ def print_codepage(printer, codepage):
"""Print a codepage."""
if codepage.isdigit():
codepage = int(codepage)
printer._raw(CODEPAGE_CHANGE + six.int2byte(codepage))
printer._raw(CODEPAGE_CHANGE + bytes((codepage,)))
printer._raw("after")
else:
printer.charcode(codepage)
Expand All @@ -58,7 +56,9 @@ def print_codepage(printer, codepage):
printer.set()

for y in range(0, 16):
byte = six.int2byte(x * 16 + y)
byte = bytes(
(x * 16 + y),
)

if byte in (ESC, CTL_LF, CTL_FF, CTL_CR, CTL_HT, CTL_VT):
byte = " "
Expand Down
4 changes: 2 additions & 2 deletions examples/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import json
import os
import time
import urllib
from datetime import datetime
from urllib.request import urlopen

from escpos.printer import Usb

Expand Down Expand Up @@ -93,7 +93,7 @@ def icon():
+ LONG
+ "?exclude=[alerts,minutely,hourly,flags]&units=si"
) # change last bit to 'us' for Fahrenheit
response = urllib.urlopen(url)
response = urlopen(url)
data = json.loads(response.read())

printer.print_and_feed(n=1)
Expand Down
2 changes: 1 addition & 1 deletion src/escpos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""python-escpos enables you to manipulate escpos-printers."""

__all__ = ["constants", "escpos", "exceptions", "printer"]
__all__ = ["constants", "escpos", "exceptions", "printer", "__version__"]

try:
from .version import version as __version__ # noqa
Expand Down
21 changes: 11 additions & 10 deletions src/escpos/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing import Any, Dict, Optional, Type

import importlib_resources
import six
import yaml

logging.basicConfig()
Expand Down Expand Up @@ -92,7 +91,7 @@ class NotSupported(Exception):
BARCODE_B = "barcodeB"


class BaseProfile(object):
class BaseProfile:
"""This represents a printer profile.

A printer profile knows about the number of columns, supported
Expand All @@ -111,20 +110,22 @@ def get_font(self, font) -> int:
Makes sure that the requested `font` is valid.
"""
font = {"a": 0, "b": 1}.get(font, font)
if not six.text_type(font) in self.fonts:
if not str(font) in self.fonts:
raise NotSupported(f'"{font}" is not a valid font in the current profile')
return font

def get_columns(self, font):
def get_columns(self, font) -> int:
"""Return the number of columns for the given font."""
font = self.get_font(font)
return self.fonts[six.text_type(font)]["columns"]
columns = self.fonts[str(font)]["columns"]
assert type(columns) is int
return columns

def supports(self, feature):
def supports(self, feature) -> bool:
"""Return true/false for the given feature."""
return self.features.get(feature)

def get_code_pages(self):
def get_code_pages(self) -> Dict[str, int]:
"""Return the support code pages as a ``{name: index}`` dict."""
return {v: k for k, v in self.codePages.items()}

Expand Down Expand Up @@ -161,7 +162,7 @@ def get_profile_class(name: str) -> Type[BaseProfile]:
return CLASS_CACHE[name]


def clean(s):
def clean(s: str) -> str:
"""Clean profile name."""
# Remove invalid characters
s = re.sub("[^0-9a-zA-Z_]", "", s)
Expand All @@ -180,14 +181,14 @@ class Profile(ProfileBaseClass):
For users, who want to provide their own profile.
"""

def __init__(self, columns=None, features=None):
def __init__(self, columns: Optional[int] = None, features=None) -> None:
"""Initialize profile."""
super(Profile, self).__init__()

self.columns = columns
self.features = features or {}

def get_columns(self, font):
def get_columns(self, font) -> int:
"""Get column count of printer."""
if self.columns is not None:
return self.columns
Expand Down
12 changes: 4 additions & 8 deletions src/escpos/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
pass # noqa
import sys

import six

from . import config
from . import printer as escpos_printer_module
from . import version


# Must be defined before it's used in DEMO_FUNCTIONS
def str_to_bool(string):
def str_to_bool(string: str) -> bool:
"""Convert string to bool.

Used as a type in argparse so that we get back a proper
Expand Down Expand Up @@ -563,7 +561,7 @@ def generate_parser() -> argparse.ArgumentParser:
return parser


def main():
def main() -> None:
"""Handle main entry point of CLI script.

Handles loading of configuration and creating and processing of command
Expand All @@ -580,9 +578,7 @@ def main():
if not args_dict:
parser.print_help()
sys.exit()
command_arguments = dict(
[k, v] for k, v in six.iteritems(args_dict) if v is not None
)
command_arguments = dict([k, v] for k, v in args_dict.items() if v is not None)

# If version should be printed, do this, then exit
print_version = command_arguments.pop("version", None)
Expand Down Expand Up @@ -621,7 +617,7 @@ def main():
globals()[target_command](**command_arguments)


def demo(printer, **kwargs):
def demo(printer, **kwargs) -> None:
"""Print demos.

Called when CLI is passed `demo`. This function
Expand Down
6 changes: 3 additions & 3 deletions src/escpos/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from . import exceptions, printer


class Config(object):
class Config:
"""Configuration handler class.

This class loads configuration from a default or specified directory. It
Expand All @@ -21,7 +21,7 @@ class Config(object):
_app_name = "python-escpos"
_config_file = "config.yaml"

def __init__(self):
def __init__(self) -> None:
"""Initialize configuration.

Remember to add anything that needs to be reset between configurations
Expand All @@ -33,7 +33,7 @@ def __init__(self):
self._printer_name = None
self._printer_config = None

def _reset_config(self):
def _reset_config(self) -> None:
"""Clear the loaded configuration.

If we are loading a changed config, we don't want to have leftover
Expand Down
4 changes: 1 addition & 3 deletions src/escpos/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
# (TODO: Where is this specified?)

# Cash Drawer (ESC p <pin> <on time: 2*ms> <off time: 2*ms>)
_CASH_DRAWER = (
lambda m, t1="", t2="": ESC + b"p" + m + six.int2byte(t1) + six.int2byte(t2)
)
_CASH_DRAWER = lambda m, t1="", t2="": ESC + b"p" + m + bytes((t1, t2))

#: decimal cash drawer kick sequence
CD_KICK_DEC_SEQUENCE = (
Expand Down
Loading