Skip to content

Commit b95f9a6

Browse files
tests: Remove compatibility code not needed now when we're on Python 3
1 parent 6df0c6c commit b95f9a6

File tree

3 files changed

+14
-36
lines changed

3 files changed

+14
-36
lines changed

share/rpcauth/rpcauth.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6-
import hashlib
76
import sys
87
import os
98
from random import SystemRandom
@@ -25,15 +24,9 @@
2524
salt = "".join([x[2:] for x in hexseq])
2625

2726
#Create 32 byte b64 password
28-
password = base64.urlsafe_b64encode(os.urandom(32))
29-
30-
digestmod = hashlib.sha256
31-
32-
if sys.version_info.major >= 3:
33-
password = password.decode('utf-8')
34-
digestmod = 'SHA256'
27+
password = base64.urlsafe_b64encode(os.urandom(32)).decode("utf-8")
3528

36-
m = hmac.new(bytearray(salt, 'utf-8'), bytearray(password, 'utf-8'), digestmod)
29+
m = hmac.new(bytearray(salt, 'utf-8'), bytearray(password, 'utf-8'), "SHA256")
3730
result = m.hexdigest()
3831

3932
print("String to be appended to bitcoin.conf:")

test/functional/test_framework/key.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import ctypes
1111
import ctypes.util
1212
import hashlib
13-
import sys
1413

1514
ssl = ctypes.cdll.LoadLibrary(ctypes.util.find_library ('ssl') or 'libeay32')
1615

@@ -223,10 +222,5 @@ def __str__(self):
223222
return repr(self)
224223

225224
def __repr__(self):
226-
# Always have represent as b'<secret>' so test cases don't have to
227-
# change for py2/3
228-
if sys.version > '3':
229-
return '%s(%s)' % (self.__class__.__name__, super(CPubKey, self).__repr__())
230-
else:
231-
return '%s(b%s)' % (self.__class__.__name__, super(CPubKey, self).__repr__())
225+
return '%s(%s)' % (self.__class__.__name__, super(CPubKey, self).__repr__())
232226

test/functional/test_framework/script.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@
1010
from .mininode import CTransaction, CTxOut, sha256, hash256, uint256_from_str, ser_uint256, ser_string
1111
from binascii import hexlify
1212
import hashlib
13-
14-
import sys
15-
bchr = chr
16-
bord = ord
17-
if sys.version > '3':
18-
long = int
19-
bchr = lambda x: bytes([x])
20-
bord = lambda x: x
21-
2213
import struct
2314

2415
from .bignum import bn2vch
@@ -40,9 +31,9 @@ class CScriptOp(int):
4031
def encode_op_pushdata(d):
4132
"""Encode a PUSHDATA op, returning bytes"""
4233
if len(d) < 0x4c:
43-
return b'' + bchr(len(d)) + d # OP_PUSHDATA
34+
return b'' + bytes([len(d)]) + d # OP_PUSHDATA
4435
elif len(d) <= 0xff:
45-
return b'\x4c' + bchr(len(d)) + d # OP_PUSHDATA1
36+
return b'\x4c' + bytes([len(d)]) + d # OP_PUSHDATA1
4637
elif len(d) <= 0xffff:
4738
return b'\x4d' + struct.pack(b'<H', len(d)) + d # OP_PUSHDATA2
4839
elif len(d) <= 0xffffffff:
@@ -388,7 +379,7 @@ def encode(obj):
388379
r.append(0x80 if neg else 0)
389380
elif neg:
390381
r[-1] |= 0x80
391-
return bytes(bchr(len(r)) + r)
382+
return bytes(bytes([len(r)]) + r)
392383

393384

394385
class CScript(bytes):
@@ -405,17 +396,17 @@ class CScript(bytes):
405396
def __coerce_instance(cls, other):
406397
# Coerce other into bytes
407398
if isinstance(other, CScriptOp):
408-
other = bchr(other)
399+
other = bytes([other])
409400
elif isinstance(other, CScriptNum):
410401
if (other.value == 0):
411-
other = bchr(CScriptOp(OP_0))
402+
other = bytes([CScriptOp(OP_0)])
412403
else:
413404
other = CScriptNum.encode(other)
414405
elif isinstance(other, int):
415406
if 0 <= other <= 16:
416-
other = bytes(bchr(CScriptOp.encode_op_n(other)))
407+
other = bytes(bytes([CScriptOp.encode_op_n(other)]))
417408
elif other == -1:
418-
other = bytes(bchr(OP_1NEGATE))
409+
other = bytes(bytes([OP_1NEGATE]))
419410
else:
420411
other = CScriptOp.encode_op_pushdata(bn2vch(other))
421412
elif isinstance(other, (bytes, bytearray)):
@@ -458,7 +449,7 @@ def raw_iter(self):
458449
i = 0
459450
while i < len(self):
460451
sop_idx = i
461-
opcode = bord(self[i])
452+
opcode = self[i]
462453
i += 1
463454

464455
if opcode > OP_PUSHDATA4:
@@ -474,21 +465,21 @@ def raw_iter(self):
474465
pushdata_type = 'PUSHDATA1'
475466
if i >= len(self):
476467
raise CScriptInvalidError('PUSHDATA1: missing data length')
477-
datasize = bord(self[i])
468+
datasize = self[i]
478469
i += 1
479470

480471
elif opcode == OP_PUSHDATA2:
481472
pushdata_type = 'PUSHDATA2'
482473
if i + 1 >= len(self):
483474
raise CScriptInvalidError('PUSHDATA2: missing data length')
484-
datasize = bord(self[i]) + (bord(self[i+1]) << 8)
475+
datasize = self[i] + (self[i+1] << 8)
485476
i += 2
486477

487478
elif opcode == OP_PUSHDATA4:
488479
pushdata_type = 'PUSHDATA4'
489480
if i + 3 >= len(self):
490481
raise CScriptInvalidError('PUSHDATA4: missing data length')
491-
datasize = bord(self[i]) + (bord(self[i+1]) << 8) + (bord(self[i+2]) << 16) + (bord(self[i+3]) << 24)
482+
datasize = self[i] + (self[i+1] << 8) + (self[i+2] << 16) + (self[i+3] << 24)
492483
i += 4
493484

494485
else:

0 commit comments

Comments
 (0)