PySpec SSZ Bytes instantiated from hex

This commit is contained in:
Carl Beekhuizen
2019-12-27 09:37:26 +01:00
parent b698eff2a7
commit 765176ec8c
5 changed files with 15 additions and 14 deletions

View File

@@ -451,10 +451,15 @@ class BaseBytes(bytes, Elements, metaclass=BytesType):
@classmethod
def extract_args(cls, *args):
x = args
if len(x) == 1 and isinstance(x[0], (GeneratorType, bytes)):
if len(x) == 1 and isinstance(x[0], (GeneratorType, bytes, str)):
x = x[0]
if isinstance(x, bytes): # Includes BytesLike
return x
if isinstance(x, str):
if x[:2] == '0x':
return bytes.fromhex(x[2:])
else:
return bytes.fromhex(x)
else:
return bytes(x) # E.g. GeneratorType put into bytes.