Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit ff82286

Browse files
committed
reorganize Codecs.reset()
1 parent cd6ee9f commit ff82286

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

multihash.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,22 +178,23 @@ class Codecs:
178178
def reset(cls):
179179
"""Reset the registry to the standard codecs."""
180180
# Try to import codecs mentioned in the hashlib spec.
181-
import binascii as ba
182-
import base64 as b64
183-
try:
184-
import base58 as b58
185-
except ImportError:
186-
b58 = None
181+
import binascii
182+
import base64
187183

188184
c = cls._codec
189185
cls._codecs = {
190-
'hex': c(ba.b2a_hex, ba.a2b_hex),
191-
'base32': c(b64.b32encode, b64.b32decode),
192-
'base64': c(b64.b64encode, b64.b64decode)
186+
'hex': c(binascii.b2a_hex, binascii.a2b_hex),
187+
'base32': c(base64.b32encode, base64.b32decode),
188+
'base64': c(base64.b64encode, base64.b64decode)
193189
}
194-
if b58:
190+
191+
# The spec doesn't have compulsory codes, though.
192+
try:
193+
import base58
195194
cls._codecs['base58'] = c(
196-
lambda s: bytes(b58.b58encode(s)), b58.b58decode)
195+
lambda s: bytes(base58.b58encode(s)), base58.b58decode)
196+
except ImportError:
197+
pass
197198

198199
@classmethod
199200
def get_encoder(cls, encoding):

0 commit comments

Comments
 (0)