diff --git a/share/rpcauth/rpcauth.py b/share/rpcauth/rpcauth.py --- a/share/rpcauth/rpcauth.py +++ b/share/rpcauth/rpcauth.py @@ -1,9 +1,8 @@ #!/usr/bin/env python3 -# Copyright (c) 2015-2016 The Bitcoin Core developers +# Copyright (c) 2015-2017 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -import hashlib import sys import os from random import SystemRandom @@ -25,15 +24,9 @@ salt = "".join([x[2:] for x in hexseq]) # Create 32 byte b64 password -password = base64.urlsafe_b64encode(os.urandom(32)) +password = base64.urlsafe_b64encode(os.urandom(32)).decode("utf-8") -digestmod = hashlib.sha256 - -if sys.version_info.major >= 3: - password = password.decode('utf-8') - digestmod = 'SHA256' - -m = hmac.new(bytearray(salt, 'utf-8'), bytearray(password, 'utf-8'), digestmod) +m = hmac.new(bytearray(salt, 'utf-8'), bytearray(password, 'utf-8'), "SHA256") result = m.hexdigest() print("String to be appended to bitcoin.conf:") diff --git a/test/functional/test_framework/key.py b/test/functional/test_framework/key.py --- a/test/functional/test_framework/key.py +++ b/test/functional/test_framework/key.py @@ -10,7 +10,6 @@ import ctypes import ctypes.util import hashlib -import sys ssl = ctypes.cdll.LoadLibrary(ctypes.util.find_library('ssl') or 'libeay32') @@ -240,9 +239,4 @@ return repr(self) def __repr__(self): - # Always have represent as b'' so test cases don't have to - # change for py2/3 - if sys.version > '3': - return '{}({})'.format(self.__class__.__name__, super(CPubKey, self).__repr__()) - else: - return '{}(b{})'.format(self.__class__.__name__, super(CPubKey, self).__repr__()) + return '{}({})'.format(self.__class__.__name__, super(CPubKey, self).__repr__()) diff --git a/test/functional/test_framework/script.py b/test/functional/test_framework/script.py --- a/test/functional/test_framework/script.py +++ b/test/functional/test_framework/script.py @@ -11,7 +11,6 @@ from binascii import hexlify import hashlib import struct -import sys from .messages import ( CTransaction, @@ -23,15 +22,6 @@ uint256_from_str, ) -bchr = chr -bord = ord -if sys.version > '3': - long = int - - def bchr(x): return bytes([x]) - - def bord(x): return x - MAX_SCRIPT_ELEMENT_SIZE = 520 @@ -53,9 +43,11 @@ def encode_op_pushdata(d): """Encode a PUSHDATA op, returning bytes""" if len(d) < 0x4c: - return b'' + bchr(len(d)) + d # OP_PUSHDATA + # OP_PUSHDATA + return b'' + bytes([len(d)]) + d elif len(d) <= 0xff: - return b'\x4c' + bchr(len(d)) + d # OP_PUSHDATA1 + # OP_PUSHDATA1 + return b'\x4c' + bytes([len(d)]) + d elif len(d) <= 0xffff: return b'\x4d' + struct.pack(b' OP_PUSHDATA4: @@ -509,7 +501,7 @@ if i >= len(self): raise CScriptInvalidError( 'PUSHDATA1: missing data length') - datasize = bord(self[i]) + datasize = self[i] i += 1 elif opcode == OP_PUSHDATA2: @@ -517,7 +509,7 @@ if i + 1 >= len(self): raise CScriptInvalidError( 'PUSHDATA2: missing data length') - datasize = bord(self[i]) + (bord(self[i + 1]) << 8) + datasize = self[i] + (self[i + 1] << 8) i += 2 elif opcode == OP_PUSHDATA4: @@ -525,8 +517,8 @@ if i + 3 >= len(self): raise CScriptInvalidError( 'PUSHDATA4: missing data length') - datasize = bord(self[i]) + (bord(self[i + 1]) << 8) + \ - (bord(self[i + 2]) << 16) + (bord(self[i + 3]) << 24) + datasize = self[i] + (self[i + 1] << 8) + \ + (self[i + 2] << 16) + (self[i + 3] << 24) i += 4 else: