22
22
https://github.com/adafruit/circuitpython/releases
23
23
24
24
"""
25
+
25
26
try :
27
+ from binascii import hexlify , unhexlify
26
28
from typing import Union
29
+
27
30
from circuitpython_typing import ReadableBuffer
28
- from binascii import hexlify , unhexlify
29
31
except ImportError :
30
32
pass
31
33
59
61
class Error (Exception ):
60
62
"""Exception raised on errors. These are usually programming errors."""
61
63
62
- # pylint: disable=unnecessary-pass
63
64
pass
64
65
65
66
66
67
if not "unhexlify" in globals ():
67
- # pylint: disable=function-redefined
68
+
68
69
def unhexlify (hexstr : Union [str , ReadableBuffer ]) -> bytes :
69
70
"""Return the binary data represented by hexstr.
70
71
@@ -78,7 +79,7 @@ def unhexlify(hexstr: Union[str, ReadableBuffer]) -> bytes:
78
79
79
80
80
81
if not "hexlify" in globals ():
81
- # pylint: disable=function-redefined
82
+
82
83
def hexlify (data : ReadableBuffer ) -> bytes :
83
84
"""Return the hexadecimal representation of the
84
85
binary data. Every byte of data is converted into
@@ -122,7 +123,7 @@ def a2b_base64(b64_data: ReadableBuffer) -> bytes:
122
123
last_char_was_a_pad = False
123
124
124
125
for char in b64_data :
125
- char = chr (char )
126
+ char = chr (char ) # noqa: PLW2901
126
127
if char == "=" :
127
128
if quad_pos > 2 or (quad_pos == 2 and last_char_was_a_pad ):
128
129
break # stop on 'xxx=' or on 'xx=='
@@ -137,12 +138,10 @@ def a2b_base64(b64_data: ReadableBuffer) -> bytes:
137
138
quad_pos = (quad_pos + 1 ) & 3
138
139
leftchar = (leftchar << 6 ) | n
139
140
leftbits += 6
140
- #
141
141
if leftbits >= 8 :
142
142
leftbits -= 8
143
143
res .append ((leftchar >> leftbits ).to_bytes (1 , "big" ))
144
144
leftchar &= (1 << leftbits ) - 1
145
- #
146
145
last_char_was_a_pad = False
147
146
else :
148
147
if leftbits != 0 :
@@ -172,7 +171,6 @@ def b2a_base64(bin_data: ReadableBuffer) -> bytes:
172
171
if leftbits >= 6 :
173
172
res .append (TABLE_B2A_B64 [(leftchar >> (leftbits - 6 )) & 0x3F ])
174
173
leftbits -= 6
175
- #
176
174
if leftbits == 2 :
177
175
res .append (TABLE_B2A_B64 [(leftchar & 3 ) << 4 ])
178
176
res .append ("=" )
0 commit comments