From 1d81df145f9d973d419c52fc0f28c85809e7aa21 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Mon, 2 May 2022 09:13:51 -0600 Subject: [PATCH 1/6] Correct type annotation Corrected by making arguments more general --- adafruit_binascii.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/adafruit_binascii.py b/adafruit_binascii.py index dc629bd..804e9d9 100644 --- a/adafruit_binascii.py +++ b/adafruit_binascii.py @@ -23,6 +23,8 @@ """ try: + from typing import Union + from circuitpython_typing import ReadableBuffer from binascii import hexlify, unhexlify except ImportError: pass @@ -63,11 +65,12 @@ class Error(Exception): if not "unhexlify" in globals(): # pylint: disable=function-redefined - def unhexlify(hexstr: str) -> bytes: + def unhexlify(hexstr: Union[str, ReadableBuffer]) -> bytes: """Return the binary data represented by hexstr. - :param str hexstr: Hexadecimal string. - + + :param str|ReadableBuffer hexstr: Hexadecimal string. """ + if len(hexstr) % 2 != 0: raise Error("Odd-length string") @@ -76,7 +79,7 @@ def unhexlify(hexstr: str) -> bytes: if not "hexlify" in globals(): # pylint: disable=function-redefined - def hexlify(data: bytes) -> bytes: + def hexlify(data: ReadableBuffer) -> bytes: """Return the hexadecimal representation of the binary data. Every byte of data is converted into the corresponding 2-digit hex representation. @@ -84,10 +87,10 @@ def hexlify(data: bytes) -> bytes: as long as the length of data. :param bytes data: Binary data, as bytes. - """ if not data: raise TypeError("Data provided is zero-length") + data = "".join("%02x" % i for i in data) return bytes(data, "utf-8") @@ -106,12 +109,12 @@ def _transform(n: int) -> str: assert len(TABLE_A2B_B64) == 256 -def a2b_base64(b64_data: bytes) -> bytes: +def a2b_base64(b64_data: ReadableBuffer) -> bytes: """Convert a block of base64 data back to binary and return the binary data. :param bytes b64_data: Base64 data. - """ + res = [] quad_pos = 0 leftchar = 0 @@ -148,12 +151,12 @@ def a2b_base64(b64_data: bytes) -> bytes: return b"".join(res) -def b2a_base64(bin_data: bytes) -> bytes: +def b2a_base64(bin_data: ReadableBuffer) -> bytes: """Convert binary data to a line of ASCII characters in base64 coding. - :param bytes bin_data: Binary data string, as bytes - + :param ReadableBuffer bin_data: Binary data string, as bytes """ + newlength = (len(bin_data) + 2) // 3 newlength = newlength * 4 + 1 res = [] From a62f6faf707ba33df41feb24578ea863a3ccf6b8 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Mon, 2 May 2022 09:14:54 -0600 Subject: [PATCH 2/6] Added adafruit-circuitpython-typing to setup.py --- setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2ccc7f0..d72936b 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,10 @@ # Author details author="Adafruit Industries", author_email="circuitpython@adafruit.com", - install_requires=["Adafruit-Blinka"], + install_requires=[ + "Adafruit-Blinka", + "adafruit-circuitpython-typing", + ], # Choose your license license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers From 5f02785bd9553babbb2d5360cc632b0d9a7fd745 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Mon, 2 May 2022 09:15:24 -0600 Subject: [PATCH 3/6] Added adafruit-circuitpython-typing to requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 5a1e7de..f85602a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ # SPDX-License-Identifier: Unlicense Adafruit-Blinka +adafruit-circuitpython-typing From caf9521267521e114fe183fe36abfc24455b3409 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 2 May 2022 09:20:17 -0600 Subject: [PATCH 4/6] Fixed whitespace formatting --- adafruit_binascii.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_binascii.py b/adafruit_binascii.py index 804e9d9..3ad72e3 100644 --- a/adafruit_binascii.py +++ b/adafruit_binascii.py @@ -67,7 +67,7 @@ class Error(Exception): # pylint: disable=function-redefined def unhexlify(hexstr: Union[str, ReadableBuffer]) -> bytes: """Return the binary data represented by hexstr. - + :param str|ReadableBuffer hexstr: Hexadecimal string. """ From 6b6d85a59864e19feb95c517614bae31bb9cd18b Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 2 May 2022 09:20:36 -0600 Subject: [PATCH 5/6] Changed typing package requirement to Blinka>=7.0.0 --- requirements.txt | 3 +-- setup.py | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index f85602a..63ac617 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,4 @@ # # SPDX-License-Identifier: Unlicense -Adafruit-Blinka -adafruit-circuitpython-typing +Adafruit-Blinka>=7.0.0 diff --git a/setup.py b/setup.py index d72936b..a3ea725 100644 --- a/setup.py +++ b/setup.py @@ -33,10 +33,7 @@ # Author details author="Adafruit Industries", author_email="circuitpython@adafruit.com", - install_requires=[ - "Adafruit-Blinka", - "adafruit-circuitpython-typing", - ], + install_requires=["Adafruit-Blinka>=7.0.0"], # Choose your license license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers From 12fe3dba3a7fe293ca6e96f8b5e764884471b45f Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 2 May 2022 12:53:41 -0400 Subject: [PATCH 6/6] Require Blinka>=7.2.3 --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 63ac617..e5808dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ # # SPDX-License-Identifier: Unlicense -Adafruit-Blinka>=7.0.0 +Adafruit-Blinka>=7.2.3 diff --git a/setup.py b/setup.py index a3ea725..44ab308 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ # Author details author="Adafruit Industries", author_email="circuitpython@adafruit.com", - install_requires=["Adafruit-Blinka>=7.0.0"], + install_requires=["Adafruit-Blinka>=7.2.3"], # Choose your license license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers