Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ deps = [
"jaconv",
"coverage",
"scripttest",
"mock",
"pytest>=7.4",
"pytest-cov",
"pytest-mock",
Expand Down Expand Up @@ -114,8 +113,6 @@ commands = [["flake8", "--version"], ["flake8"]]
base_python = ["python"]
deps = [
"mypy",
"types-six",
"types-mock",
"types-PyYAML",
"types-Pillow",
"types-pyserial",
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ install_requires =
qrcode>=8.0
python-barcode>=0.16.0,<1
setuptools
six
platformdirs
PyYAML
argcomplete
Expand All @@ -54,7 +53,6 @@ tests_require =
pytest-cov
pytest-mock
scripttest
mock
hypothesis>=6.83
flake8>7
sphinxcontrib-spelling>=8.0.2
Expand Down
16 changes: 7 additions & 9 deletions src/escpos/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

from typing import Dict

import six

from .types import ConstTxtStyleClass

# Control characters
Expand Down Expand Up @@ -49,11 +47,11 @@

#: decimal cash drawer kick sequence
CD_KICK_DEC_SEQUENCE = (
lambda esc, p, m, t1=50, t2=50: six.int2byte(esc)
+ six.int2byte(p)
+ six.int2byte(m)
+ six.int2byte(t1)
+ six.int2byte(t2)
lambda esc, p, m, t1=50, t2=50: esc.to_bytes()
+ p.to_bytes()
+ m.to_bytes()
+ t1.to_bytes()
+ t2.to_bytes()
)
#: Sends a pulse to pin 2 []
CD_KICK_2: bytes = _CASH_DRAWER(b"\x00", 50, 50)
Expand All @@ -72,7 +70,7 @@
BUZZER: bytes = ESC + b"\x42"

# Panel buttons (e.g. the FEED button)
_PANEL_BUTTON = lambda n: ESC + b"c5" + six.int2byte(n)
_PANEL_BUTTON = lambda n: ESC + b"c5" + n.to_bytes()
PANEL_BUTTON_ON: bytes = _PANEL_BUTTON(0) # enable all panel buttons
PANEL_BUTTON_OFF: bytes = _PANEL_BUTTON(1) # disable all panel buttons

Expand Down Expand Up @@ -210,7 +208,7 @@
# - Type A: "GS k <type as integer> <data> NUL"
# - TYPE B: "GS k <type as letter> <data length> <data>"
# The latter command supports more barcode types
_SET_BARCODE_TYPE = lambda m: GS + b"k" + six.int2byte(m)
_SET_BARCODE_TYPE = lambda m: GS + b"k" + m.to_bytes()

#: Barcodes for printing function type A
BARCODE_TYPE_A: Dict[str, bytes] = {
Expand Down
42 changes: 19 additions & 23 deletions src/escpos/escpos.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import barcode
import qrcode
import six
from barcode.writer import ImageWriter

from escpos.capabilities import get_profile
Expand Down Expand Up @@ -308,12 +307,9 @@ def image(
32 if high_density_vertical else 0
)
header = (
ESC
+ b"*"
+ six.int2byte(density_byte)
+ self._int_low_high(im.width, 2)
ESC + b"*" + density_byte.to_bytes() + self._int_low_high(im.width, 2)
)
outp = [ESC + b"3" + six.int2byte(16)] # Adjust line-feed size
outp = [ESC + b"3" + int.to_bytes(16)] # Adjust line-feed size
for blob in im.to_column_format(high_density_vertical):
outp.append(header + blob + b"\n")
outp.append(ESC + b"2") # Reset line-feed size
Expand Down Expand Up @@ -417,15 +413,15 @@ def qr(
cn = b"1" # Code type for QR code
# Select model: 1, 2 or micro.
self._send_2d_code_data(
six.int2byte(65), cn, six.int2byte(48 + model) + six.int2byte(0)
int.to_bytes(65), cn, (48 + model).to_bytes() + int.to_bytes(0)
)
# Set dot size.
self._send_2d_code_data(six.int2byte(67), cn, six.int2byte(size))
self._send_2d_code_data(int.to_bytes(67), cn, size.to_bytes())
# Set error correction level: L, M, Q, or H
self._send_2d_code_data(six.int2byte(69), cn, six.int2byte(48 + ec))
self._send_2d_code_data(int.to_bytes(69), cn, (48 + ec).to_bytes())
# Send content & print
self._send_2d_code_data(six.int2byte(80), cn, content.encode("utf-8"), b"0")
self._send_2d_code_data(six.int2byte(81), cn, b"", b"0")
self._send_2d_code_data(int.to_bytes(80), cn, content.encode("utf-8"), b"0")
self._send_2d_code_data(int.to_bytes(81), cn, b"", b"0")

def _send_2d_code_data(self, fn, cn, data, m=b"") -> None:
"""Calculate and send correct data length for`GS ( k`.
Expand Down Expand Up @@ -456,7 +452,7 @@ def _int_low_high(inp_number: int, out_bytes: int) -> bytes:
)
outp = b""
for _ in range(0, out_bytes):
outp += six.int2byte(inp_number % 256)
outp += (inp_number % 256).to_bytes()
inp_number //= 256
return outp

Expand Down Expand Up @@ -755,12 +751,12 @@ def _hw_barcode(
self._raw(TXT_STYLE["align"]["center"])
# Height
if 1 <= height <= 255:
self._raw(BARCODE_HEIGHT + six.int2byte(height))
self._raw(BARCODE_HEIGHT + height.to_bytes())
else:
raise BarcodeSizeError(f"height = {height}")
# Width
if 2 <= width <= 6:
self._raw(BARCODE_WIDTH + six.int2byte(width))
self._raw(BARCODE_WIDTH + width.to_bytes())
else:
raise BarcodeSizeError(f"width = {width}")
# Font
Expand All @@ -781,7 +777,7 @@ def _hw_barcode(
self._raw(bc_types[bc.upper()])

if function_type.upper() == "B":
self._raw(six.int2byte(len(code)))
self._raw(len(code).to_bytes())

# Print Code
if code:
Expand Down Expand Up @@ -1110,7 +1106,7 @@ def set(
and 1 <= height <= 8
):
size_byte = TXT_STYLE["width"][width] + TXT_STYLE["height"][height]
self._raw(TXT_SIZE + six.int2byte(size_byte))
self._raw(TXT_SIZE + size_byte.to_bytes())
else:
raise SetVariableError()
elif normal_textsize or double_height or double_width:
Expand All @@ -1135,8 +1131,8 @@ def set(
self._raw(TXT_STYLE["bold"][bold])
if underline is not None:
self._raw(TXT_STYLE["underline"][underline])
if font is not None and font != self._font:
self._raw(SET_FONT(six.int2byte(self.profile.get_font(font))))
if font is not None:
Comment thread
patkan marked this conversation as resolved.
Outdated
self._raw(SET_FONT(self.profile.get_font(font).to_bytes()))
Comment thread
patkan marked this conversation as resolved.
self._font = font
# Force a fresh code page selection as required by some printer
# models (confirmed: NT-5890K).
Expand Down Expand Up @@ -1246,7 +1242,7 @@ def line_spacing(self, spacing: Optional[int] = None, divisor: int = 180) -> Non
"spacing must be a int between 0 and 85 when divisor is 60"
)

self._raw(LINESPACING_FUNCS[divisor] + six.int2byte(spacing))
self._raw(LINESPACING_FUNCS[divisor] + spacing.to_bytes())

def cut(self, mode: str = "FULL", feed: bool = True) -> None:
"""Cut paper.
Expand All @@ -1260,7 +1256,7 @@ def cut(self, mode: str = "FULL", feed: bool = True) -> None:
:raises ValueError: if mode not in ('FULL', 'PART')
"""
if not feed:
self._raw(GS + b"V" + six.int2byte(66) + b"\x00")
self._raw(GS + b"V" + int.to_bytes(66) + b"\x00")
return

self.print_and_feed(6)
Expand Down Expand Up @@ -1368,7 +1364,7 @@ def print_and_feed(self, n: int = 1) -> None:
"""
if 0 <= n <= 255:
# ESC d n
self._raw(ESC + b"d" + six.int2byte(n))
self._raw(ESC + b"d" + n.to_bytes())
else:
raise ValueError("n must be betwen 0 and 255")

Expand Down Expand Up @@ -1403,7 +1399,7 @@ def control(self, ctl: str, count: int = 5, tab_size: int = 8) -> None:
# Set tab positions
self._raw(CTL_SET_HT)
for iterator in range(1, count):
self._raw(six.int2byte(iterator * tab_size))
self._raw((iterator * tab_size).to_bytes())
self._raw(NUL)
elif ctl.upper() == "VT":
self._raw(CTL_VT)
Expand Down Expand Up @@ -1560,7 +1556,7 @@ def buzzer(self, times: int = 2, duration: int = 4) -> None:
if not 1 <= duration <= 9:
raise ValueError("duration must be between 1 and 9")

self._raw(BUZZER + six.int2byte(times) + six.int2byte(duration))
self._raw(BUZZER + times.to_bytes() + duration.to_bytes())


class EscposIO:
Expand Down
4 changes: 1 addition & 3 deletions src/escpos/magicencode.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import re
from builtins import bytes

import six

from .codepages import CodePages
from .constants import CODEPAGE_CHANGE
from .exceptions import Error
Expand Down Expand Up @@ -315,7 +313,7 @@ def write_with_encoding(self, encoding, text):
if encoding != self.encoding:
self.encoding = encoding
self.driver._raw(
CODEPAGE_CHANGE + six.int2byte(self.encoder.get_sequence(encoding))
CODEPAGE_CHANGE + self.encoder.get_sequence(encoding).to_bytes()
)

if text:
Expand Down
2 changes: 1 addition & 1 deletion test/test_functions/test_function_qr_non-native.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
:license: MIT
"""

import unittest.mock as mock
import warnings

import mock
import pytest
from PIL import Image

Expand Down
3 changes: 2 additions & 1 deletion test/test_functions/test_function_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
:license: MIT
"""

import unittest.mock as mock

import hypothesis.strategies as st
import mock
from hypothesis import given

from escpos.printer import Dummy
Expand Down
Loading