2222 https://github.com/adafruit/circuitpython/releases
2323
2424"""
25+
2526try :
27+ from binascii import hexlify , unhexlify
2628 from typing import Union
29+
2730 from circuitpython_typing import ReadableBuffer
28- from binascii import hexlify , unhexlify
2931except ImportError :
3032 pass
3133
5961class Error (Exception ):
6062 """Exception raised on errors. These are usually programming errors."""
6163
62- # pylint: disable=unnecessary-pass
6364 pass
6465
6566
6667if not "unhexlify" in globals ():
67- # pylint: disable=function-redefined
68+
6869 def unhexlify (hexstr : Union [str , ReadableBuffer ]) -> bytes :
6970 """Return the binary data represented by hexstr.
7071
@@ -78,7 +79,7 @@ def unhexlify(hexstr: Union[str, ReadableBuffer]) -> bytes:
7879
7980
8081if not "hexlify" in globals ():
81- # pylint: disable=function-redefined
82+
8283 def hexlify (data : ReadableBuffer ) -> bytes :
8384 """Return the hexadecimal representation of the
8485 binary data. Every byte of data is converted into
@@ -122,7 +123,7 @@ def a2b_base64(b64_data: ReadableBuffer) -> bytes:
122123 last_char_was_a_pad = False
123124
124125 for char in b64_data :
125- char = chr (char )
126+ char = chr (char ) # noqa: PLW2901
126127 if char == "=" :
127128 if quad_pos > 2 or (quad_pos == 2 and last_char_was_a_pad ):
128129 break # stop on 'xxx=' or on 'xx=='
@@ -137,12 +138,10 @@ def a2b_base64(b64_data: ReadableBuffer) -> bytes:
137138 quad_pos = (quad_pos + 1 ) & 3
138139 leftchar = (leftchar << 6 ) | n
139140 leftbits += 6
140- #
141141 if leftbits >= 8 :
142142 leftbits -= 8
143143 res .append ((leftchar >> leftbits ).to_bytes (1 , "big" ))
144144 leftchar &= (1 << leftbits ) - 1
145- #
146145 last_char_was_a_pad = False
147146 else :
148147 if leftbits != 0 :
@@ -172,7 +171,6 @@ def b2a_base64(bin_data: ReadableBuffer) -> bytes:
172171 if leftbits >= 6 :
173172 res .append (TABLE_B2A_B64 [(leftchar >> (leftbits - 6 )) & 0x3F ])
174173 leftbits -= 6
175- #
176174 if leftbits == 2 :
177175 res .append (TABLE_B2A_B64 [(leftchar & 3 ) << 4 ])
178176 res .append ("=" )
0 commit comments