forked from LBRYCommunity/lbry-sdk
Removes six
From Project (#1660)
* Replaces `six` urllib with python 3's urllib * Replaces `six`'s int2byte method with native `bytes` class * Removes edge case testing for python2 vs python3 * Removes useless object inheritance * Uses native io.BytesIO instead of six.BytesIO * Removes six from dependencies
This commit is contained in:
parent
0c999083cc
commit
b3fde9d78d
9 changed files with 15 additions and 39 deletions
|
@ -1,6 +1,6 @@
|
|||
import asyncio
|
||||
import logging
|
||||
from six.moves.urllib import parse as urlparse
|
||||
from urllib import parse as urlparse
|
||||
import json
|
||||
import inspect
|
||||
import signal
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import six
|
||||
import struct
|
||||
import binascii
|
||||
from torba.client.hash import double_sha256
|
||||
|
@ -17,7 +16,7 @@ def get_hash_for_outpoint(txhash, nout, height_of_last_takeover):
|
|||
|
||||
|
||||
# noinspection PyPep8
|
||||
def verify_proof(proof, rootHash, name):
|
||||
def verify_proof(proof, root_hash, name):
|
||||
previous_computed_hash = None
|
||||
reverse_computed_name = ''
|
||||
verified_value = False
|
||||
|
@ -32,7 +31,7 @@ def verify_proof(proof, rootHash, name):
|
|||
if previous_child_character >= child['character']:
|
||||
raise InvalidProofError("children not in increasing order")
|
||||
previous_child_character = child['character']
|
||||
to_hash += six.int2byte(child['character'])
|
||||
to_hash += bytes((child['character'],))
|
||||
if 'nodeHash' in child:
|
||||
if len(child['nodeHash']) != 64:
|
||||
raise InvalidProofError("invalid child nodeHash")
|
||||
|
@ -70,7 +69,7 @@ def verify_proof(proof, rootHash, name):
|
|||
|
||||
previous_computed_hash = double_sha256(to_hash)
|
||||
|
||||
if previous_computed_hash != binascii.unhexlify(rootHash)[::-1]:
|
||||
if previous_computed_hash != binascii.unhexlify(root_hash)[::-1]:
|
||||
raise InvalidProofError("computed hash does not match roothash")
|
||||
if 'txhash' in proof and 'nOut' in proof:
|
||||
if not verified_value:
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import six
|
||||
import lbrynet.schema
|
||||
from lbrynet.schema.base import b58encode, b58decode, validate_b58_checksum
|
||||
from lbrynet.schema.hashing import double_sha256, hash160
|
||||
|
@ -12,10 +11,7 @@ def validate_address_length(addr_bytes):
|
|||
|
||||
|
||||
def validate_address_prefix(addr_bytes):
|
||||
if six.PY3:
|
||||
prefix = addr_bytes[0]
|
||||
else:
|
||||
prefix = ord(addr_bytes[0])
|
||||
prefix = addr_bytes[0]
|
||||
if prefix not in ADDRESS_PREFIXES[lbrynet.schema.BLOCKCHAIN_NAME].values():
|
||||
raise InvalidAddress("Invalid address prefix: %.2X" % prefix)
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import six
|
||||
from lbrynet.schema.schema import ADDRESS_CHECKSUM_LENGTH
|
||||
from lbrynet.schema.hashing import double_sha256
|
||||
from lbrynet.schema.error import InvalidAddress
|
||||
|
@ -7,20 +6,6 @@ from lbrynet.schema.error import InvalidAddress
|
|||
alphabet = b'123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
||||
|
||||
|
||||
if six.PY2:
|
||||
iseq, bseq, buffer = (
|
||||
lambda s: map(ord, s),
|
||||
lambda s: ''.join(map(chr, s)),
|
||||
lambda s: s,
|
||||
)
|
||||
elif six.PY3:
|
||||
iseq, bseq, buffer = (
|
||||
lambda s: s,
|
||||
bytes,
|
||||
lambda s: s.buffer,
|
||||
)
|
||||
|
||||
|
||||
def scrub_input(v):
|
||||
if isinstance(v, str) and not isinstance(v, bytes):
|
||||
v = v.encode('ascii')
|
||||
|
@ -48,7 +33,7 @@ def b58encode(v):
|
|||
nPad -= len(v)
|
||||
|
||||
p, acc = 1, 0
|
||||
for c in iseq(reversed(v)):
|
||||
for c in reversed(v):
|
||||
acc += p * c
|
||||
p = p << 8
|
||||
|
||||
|
@ -84,7 +69,7 @@ def b58decode(v):
|
|||
acc, mod = divmod(acc, 256)
|
||||
result.append(mod)
|
||||
|
||||
return (b'\0' * (origlen - newlen) + bseq(reversed(result)))
|
||||
return b'\0' * (origlen - newlen) + bytes(reversed(result))
|
||||
|
||||
|
||||
def validate_b58_checksum(addr_bytes):
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import json
|
||||
import binascii
|
||||
from google.protobuf import json_format # pylint: disable=no-name-in-module
|
||||
import six
|
||||
|
||||
from lbrynet.schema.error import DecodeError, InvalidAddress
|
||||
from lbrynet.schema.legacy.migrate import migrate as schema_migrator
|
||||
|
@ -48,15 +47,15 @@ def smart_decode(claim_value):
|
|||
|
||||
if claim_value[0] in ['{', ord('{')]:
|
||||
try:
|
||||
if six.PY3 and isinstance(claim_value, six.binary_type):
|
||||
if isinstance(claim_value, bytes):
|
||||
claim_value = claim_value.decode()
|
||||
decoded_json = json.loads(claim_value)
|
||||
return migrate_json_claim_value(decoded_json)
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
try:
|
||||
if six.PY3 and isinstance(claim_value, six.text_type):
|
||||
if isinstance(claim_value, str):
|
||||
claim_value = claim_value.encode()
|
||||
return ClaimDict.deserialize(claim_value)
|
||||
except (DecodeError, InvalidAddress, KeyError, TypeError):
|
||||
raise DecodeError(claim_value)
|
||||
raise DecodeError(claim_value)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import six
|
||||
import hashlib
|
||||
|
||||
|
||||
def sha256(x):
|
||||
if isinstance(x, six.text_type):
|
||||
if isinstance(x, str):
|
||||
x = x.encode('utf-8')
|
||||
return hashlib.sha256(x).digest()
|
||||
|
||||
|
@ -13,7 +12,7 @@ def double_sha256(x):
|
|||
|
||||
|
||||
def ripemd160(x):
|
||||
if isinstance(x, six.text_type):
|
||||
if isinstance(x, str):
|
||||
x = x.encode('utf-8')
|
||||
md = hashlib.new('ripemd160')
|
||||
md.update(x)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from string import hexdigits
|
||||
import six
|
||||
import ecdsa
|
||||
import hashlib
|
||||
import binascii
|
||||
|
@ -20,13 +19,13 @@ from lbrynet.schema.schema import NIST256p, NIST384p, SECP256k1, ECDSA_CURVES, C
|
|||
def validate_claim_id(claim_id):
|
||||
if not len(claim_id) == 40:
|
||||
raise Exception("Incorrect claimid length: %i" % len(claim_id))
|
||||
if isinstance(claim_id, six.binary_type):
|
||||
if isinstance(claim_id, bytes):
|
||||
claim_id = claim_id.decode('utf-8')
|
||||
if set(claim_id).difference(hexdigits):
|
||||
raise Exception("Claim id is not hex encoded")
|
||||
|
||||
|
||||
class Validator(object):
|
||||
class Validator:
|
||||
CURVE_NAME = None
|
||||
HASHFUNC = hashlib.sha256
|
||||
|
||||
|
|
1
setup.py
1
setup.py
|
@ -43,7 +43,6 @@ setup(
|
|||
'treq',
|
||||
'docopt',
|
||||
'colorama==0.3.7',
|
||||
'six'
|
||||
],
|
||||
extras_require={
|
||||
'test': (
|
||||
|
|
|
@ -8,7 +8,7 @@ from tests.mocks import mock_conf_settings
|
|||
from cryptography.hazmat.primitives.ciphers.algorithms import AES
|
||||
import random
|
||||
import string
|
||||
from six import BytesIO
|
||||
from io import BytesIO
|
||||
import os
|
||||
|
||||
AES_BLOCK_SIZE_BYTES = int(AES.block_size / 8)
|
||||
|
|
Loading…
Reference in a new issue