diff --git a/qa/rpc-tests/test_framework/authproxy.py b/qa/rpc-tests/test_framework/authproxy.py index c3b3e7eb3..c36042e1d 100644 --- a/qa/rpc-tests/test_framework/authproxy.py +++ b/qa/rpc-tests/test_framework/authproxy.py @@ -34,18 +34,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -try: - import http.client as httplib -except ImportError: - import httplib +import http.client import base64 import decimal -import json +from pyutil import jsonutil as json import logging -try: - import urllib.parse as urlparse -except ImportError: - import urlparse +import urllib.parse USER_AGENT = "AuthServiceProxy/0.1" @@ -59,22 +53,14 @@ class JSONRPCException(Exception): self.error = rpc_error -def EncodeDecimal(o): - if isinstance(o, decimal.Decimal): - return round(o, 8) - raise TypeError(repr(o) + " is not JSON serializable") - -class AuthServiceProxy(object): +class AuthServiceProxy(): __id_count = 0 def __init__(self, service_url, service_name=None, timeout=HTTP_TIMEOUT, connection=None): self.__service_url = service_url self.__service_name = service_name - self.__url = urlparse.urlparse(service_url) - if self.__url.port is None: - port = 80 - else: - port = self.__url.port + self.__url = urllib.parse.urlparse(service_url) + (user, passwd) = (self.__url.username, self.__url.password) try: user = user.encode('utf8') @@ -87,17 +73,21 @@ class AuthServiceProxy(object): authpair = user + b':' + passwd self.__auth_header = b'Basic ' + base64.b64encode(authpair) - if connection: - # Callables re-use the connection of the original proxy - self.__conn = connection - elif self.__url.scheme == 'https': - self.__conn = httplib.HTTPSConnection(self.__url.hostname, port, - None, None, False, - timeout) - else: - self.__conn = httplib.HTTPConnection(self.__url.hostname, port, - False, timeout) + self.timeout = timeout + self._set_conn(connection) + def _set_conn(self, connection=None): + port = 80 if self.__url.port is None else self.__url.port + if connection: + self.__conn = connection + self.timeout = connection.timeout + elif self.__url.scheme == 'https': + self.__conn = http.client.HTTPSConnection(self.__url.hostname, port, timeout=self.timeout) + else: + self.__conn = http.client.HTTPConnection(self.__url.hostname, port, timeout=self.timeout) + + + def __getattr__(self, name): if name.startswith('__') and name.endswith('__'): # Python internal stuff @@ -105,7 +95,7 @@ class AuthServiceProxy(object): if self.__service_name is not None: name = "%s.%s" % (self.__service_name, name) return AuthServiceProxy(self.__service_url, name, connection=self.__conn) - + def _request(self, method, path, postdata): ''' Do a HTTP request, with retry if we get disconnected (e.g. due to a timeout). @@ -120,12 +110,10 @@ class AuthServiceProxy(object): return self._get_response() except Exception as e: # If connection was closed, try again. - # Python 2.7 error message was changed in https://github.com/python/cpython/pull/2825 # Python 3.5+ raises BrokenPipeError instead of BadStatusLine when the connection was reset. # ConnectionResetError happens on FreeBSD with Python 3.4. # These classes don't exist in Python 2.x, so we can't refer to them directly. - if ((isinstance(e, httplib.BadStatusLine) - and e.line in ("''", "No status line received - the server has closed the connection")) + if ((isinstance(e, http.client.BadStatusLine) and e.line == "''") or e.__class__.__name__ in ('BrokenPipeError', 'ConnectionResetError')): self.__conn.close() self.__conn.request(method, path, postdata, headers) @@ -137,11 +125,11 @@ class AuthServiceProxy(object): AuthServiceProxy.__id_count += 1 log.debug("-%s-> %s %s"%(AuthServiceProxy.__id_count, self.__service_name, - json.dumps(args, default=EncodeDecimal))) + json.dumps(args))) postdata = json.dumps({'version': '1.1', 'method': self.__service_name, 'params': args, - 'id': AuthServiceProxy.__id_count}, default=EncodeDecimal) + 'id': AuthServiceProxy.__id_count}) response = self._request('POST', self.__url.path, postdata) if response['error'] is not None: raise JSONRPCException(response['error']) @@ -152,7 +140,7 @@ class AuthServiceProxy(object): return response['result'] def _batch(self, rpc_call_list): - postdata = json.dumps(list(rpc_call_list), default=EncodeDecimal) + postdata = json.dumps(list(rpc_call_list)) log.debug("--> "+postdata) return self._request('POST', self.__url.path, postdata) @@ -165,7 +153,7 @@ class AuthServiceProxy(object): responsedata = http_response.read().decode('utf8') response = json.loads(responsedata, parse_float=decimal.Decimal) if "error" in response and response["error"] is None: - log.debug("<-%s- %s"%(response["id"], json.dumps(response["result"], default=EncodeDecimal))) + log.debug("<-%s- %s"%(response["id"], json.dumps(response["result"]))) else: log.debug("<-- "+responsedata) return response diff --git a/qa/rpc-tests/test_framework/bignum.py b/qa/rpc-tests/test_framework/bignum.py index 29658d4c6..5c7c5e45b 100644 --- a/qa/rpc-tests/test_framework/bignum.py +++ b/qa/rpc-tests/test_framework/bignum.py @@ -10,8 +10,6 @@ """Bignum routines""" -from __future__ import absolute_import, division, print_function, unicode_literals - import struct diff --git a/qa/rpc-tests/test_framework/blockstore.py b/qa/rpc-tests/test_framework/blockstore.py index fc157f718..f3cea3d2c 100644 --- a/qa/rpc-tests/test_framework/blockstore.py +++ b/qa/rpc-tests/test_framework/blockstore.py @@ -6,12 +6,12 @@ from mininode import CBlock, CBlockHeader, CBlockLocator, CTransaction, msg_block, msg_headers, msg_tx import sys -import cStringIO -import dbm +import io +import anydbm -class BlockStore(object): +class BlockStore(): def __init__(self, datadir): - self.blockDB = dbm.open(datadir + "/blocks", 'c') + self.blockDB = anydbm.open(datadir + "/blocks", 'c') self.currentBlock = 0L def close(self): @@ -23,7 +23,7 @@ class BlockStore(object): serialized_block = self.blockDB[repr(blockhash)] except KeyError: return None - f = cStringIO.StringIO(serialized_block) + f = io.StringIO(serialized_block) ret = CBlock() ret.deserialize(f) ret.calc_sha256() @@ -62,7 +62,7 @@ class BlockStore(object): try: self.blockDB[repr(block.sha256)] = bytes(block.serialize()) except TypeError as e: - print "Unexpected error: ", sys.exc_info()[0], e.args + print("Unexpected error: ", sys.exc_info()[0], e.args) self.currentBlock = block.sha256 def get_blocks(self, inv): @@ -96,7 +96,7 @@ class BlockStore(object): class TxStore(object): def __init__(self, datadir): - self.txDB = dbm.open(datadir + "/transactions", 'c') + self.txDB = anydbm.open(datadir + "/transactions", 'c') def close(self): self.txDB.close() @@ -107,7 +107,7 @@ class TxStore(object): serialized_tx = self.txDB[repr(txhash)] except KeyError: return None - f = cStringIO.StringIO(serialized_tx) + f = io.StringIO(serialized_tx) ret = CTransaction() ret.deserialize(f) ret.calc_sha256() @@ -118,7 +118,7 @@ class TxStore(object): try: self.txDB[repr(tx.sha256)] = bytes(tx.serialize()) except TypeError as e: - print "Unexpected error: ", sys.exc_info()[0], e.args + print("Unexpected error: ", sys.exc_info()[0], e.args) def get_transactions(self, inv): responses = [] diff --git a/qa/rpc-tests/test_framework/comptool.py b/qa/rpc-tests/test_framework/comptool.py index 153ded981..b51a01758 100755 --- a/qa/rpc-tests/test_framework/comptool.py +++ b/qa/rpc-tests/test_framework/comptool.py @@ -140,13 +140,13 @@ class TestNode(NodeConnCB): # across all connections. (If outcome of final tx is specified as true # or false, then only the last tx is tested against outcome.) -class TestInstance(object): +class TestInstance(): def __init__(self, objects=None, sync_every_block=True, sync_every_tx=False): self.blocks_and_transactions = objects if objects else [] self.sync_every_block = sync_every_block self.sync_every_tx = sync_every_tx -class TestManager(object): +class TestManager(): def __init__(self, testgen, datadir): self.test_generator = testgen @@ -335,7 +335,7 @@ class TestManager(object): if (not self.check_mempool(tx.sha256, tx_outcome)): raise AssertionError("Mempool test failed at test %d" % test_number) - print "Test %d: PASS" % test_number, [ c.rpc.getblockcount() for c in self.connections ] + print("Test %d: PASS" % test_number, [ c.rpc.getblockcount() for c in self.connections ]) test_number += 1 [ c.disconnect_node() for c in self.connections ] diff --git a/qa/rpc-tests/test_framework/equihash.py b/qa/rpc-tests/test_framework/equihash.py index e40451978..f025095cd 100755 --- a/qa/rpc-tests/test_framework/equihash.py +++ b/qa/rpc-tests/test_framework/equihash.py @@ -24,7 +24,7 @@ def expand_array(inp, out_len, bit_len, byte_pad=0): acc_value = 0; j = 0 - for i in xrange(len(inp)): + for i in range(len(inp)): acc_value = ((acc_value << 8) & word_mask) | inp[i] acc_bits += 8 @@ -32,7 +32,7 @@ def expand_array(inp, out_len, bit_len, byte_pad=0): # output element. if acc_bits >= bit_len: acc_bits -= bit_len - for x in xrange(byte_pad, out_width): + for x in range(byte_pad, out_width): out[j+x] = ( # Big-endian acc_value >> (acc_bits+(8*(out_width-x-1))) @@ -59,12 +59,12 @@ def compress_array(inp, out_len, bit_len, byte_pad=0): acc_value = 0; j = 0 - for i in xrange(out_len): + for i in range(out_len): # When we have fewer than 8 bits left in the accumulator, read the next # input element. if acc_bits < 8: acc_value = ((acc_value << bit_len) & word_mask) | inp[j] - for x in xrange(byte_pad, in_width): + for x in range(byte_pad, in_width): acc_value = acc_value | ( ( # Apply bit_len_mask across byte boundaries @@ -135,7 +135,7 @@ def gbp_basic(digest, n, k): indices_per_hash_output = 512/n # 1) Generate first list - if DEBUG: print 'Generating first list' + if DEBUG: print('Generating first list') X = [] tmp_hash = '' for i in range(0, 2**(collision_length+1)): @@ -153,16 +153,16 @@ def gbp_basic(digest, n, k): # 3) Repeat step 2 until 2n/(k+1) bits remain for i in range(1, k): - if DEBUG: print 'Round %d:' % i + if DEBUG:print('Round %d:' % i) # 2a) Sort the list - if DEBUG: print '- Sorting list' + if DEBUG: print('- Sorting list') X.sort(key=itemgetter(0)) if DEBUG and VERBOSE: for Xi in X[-32:]: - print '%s %s' % (print_hash(Xi[0]), Xi[1]) + print('%s %s' % (print_hash(Xi[0]), Xi[1])) - if DEBUG: print '- Finding collisions' + if DEBUG: print('- Finding collisions') Xc = [] while len(X) > 0: # 2b) Find next set of unordered pairs with collisions on first n/(k+1) bits @@ -192,13 +192,13 @@ def gbp_basic(digest, n, k): # k+1) Find a collision on last 2n(k+1) bits if DEBUG: - print 'Final round:' - print '- Sorting list' + print('Final round:') + print('- Sorting list') X.sort(key=itemgetter(0)) if DEBUG and VERBOSE: for Xi in X[-32:]: - print '%s %s' % (print_hash(Xi[0]), Xi[1]) - if DEBUG: print '- Finding collisions' + print('%s %s' % (print_hash(Xi[0]), Xi[1])) + if DEBUG: print('- Finding collisions') solns = [] while len(X) > 0: j = 1 @@ -213,9 +213,9 @@ def gbp_basic(digest, n, k): res = xor(X[-1-l][0], X[-1-m][0]) if count_zeroes(res) == 8*hash_length and distinct_indices(X[-1-l][1], X[-1-m][1]): if DEBUG and VERBOSE: - print 'Found solution:' - print '- %s %s' % (print_hash(X[-1-l][0]), X[-1-l][1]) - print '- %s %s' % (print_hash(X[-1-m][0]), X[-1-m][1]) + print('Found solution:') + print('- %s %s' % (print_hash(X[-1-l][0]), X[-1-l][1])) + print('- %s %s' % (print_hash(X[-1-m][0]), X[-1-m][1])) if X[-1-l][1][0] < X[-1-m][1][0]: solns.append(list(X[-1-l][1] + X[-1-m][1])) else: @@ -235,8 +235,8 @@ def gbp_validate(digest, minimal, n, k): solution_width = (1 << k)*(collision_length+1)//8 if len(minimal) != solution_width: - print 'Invalid solution length: %d (expected %d)' % \ - (len(minimal), solution_width) + print('Invalid solution length: %d (expected %d)' % \ + (len(minimal), solution_width)) return False X = [] @@ -256,23 +256,23 @@ def gbp_validate(digest, minimal, n, k): Xc = [] for i in range(0, len(X), 2): if not has_collision(X[i][0], X[i+1][0], r, collision_length): - print 'Invalid solution: invalid collision length between StepRows' + print('Invalid solution: invalid collision length between StepRows') return False if X[i+1][1][0] < X[i][1][0]: - print 'Invalid solution: Index tree incorrectly ordered' + print('Invalid solution: Index tree incorrectly ordered') return False if not distinct_indices(X[i][1], X[i+1][1]): - print 'Invalid solution: duplicate indices' + print('Invalid solution: duplicate indices') return False Xc.append((xor(X[i][0], X[i+1][0]), X[i][1] + X[i+1][1])) X = Xc if len(X) != 1: - print 'Invalid solution: incorrect length after end of rounds: %d' % len(X) + print('Invalid solution: incorrect length after end of rounds: %d' % len(X)) return False if count_zeroes(X[0][0]) != 8*hash_length: - print 'Invalid solution: incorrect number of zeroes: %d' % count_zeroes(X[0][0]) + print('Invalid solution: incorrect number of zeroes: %d' % count_zeroes(X[0][0])) return False return True diff --git a/qa/rpc-tests/test_framework/mininode.py b/qa/rpc-tests/test_framework/mininode.py index ee323c580..0bbbd9e77 100755 --- a/qa/rpc-tests/test_framework/mininode.py +++ b/qa/rpc-tests/test_framework/mininode.py @@ -24,7 +24,7 @@ import binascii import time import sys import random -import cStringIO +import io import hashlib from threading import RLock from threading import Thread @@ -32,7 +32,7 @@ import logging import copy from pyblake2 import blake2b -from .equihash import ( +from test_framework.equihash import ( gbp_basic, gbp_validate, hash_nonce, @@ -100,14 +100,14 @@ def ser_string(s): return chr(len(s)) + s elif len(s) < 0x10000: return chr(253) + struct.pack(">= 32 return rs def uint256_from_str(s): - r = 0L + r = 0 t = struct.unpack("> 24) & 0xFF - v = (c & 0xFFFFFFL) << (8 * (nbytes - 3)) + v = (c & 0xFFFFFF) << (8 * (nbytes - 3)) return v @@ -144,7 +144,7 @@ def deser_vector(f, c): elif nit == 255: nit = struct.unpack(" 21000000L * 100000000L: + if tout.nValue < 0 or tout.nValue > 2100000 * 100000000: return False return True @@ -778,7 +778,7 @@ class CTransaction(object): return r -class CBlockHeader(object): +class CBlockHeader(): def __init__(self, header=None): if header is None: self.set_null() @@ -878,7 +878,7 @@ class CBlock(CBlockHeader): hashes.append(ser_uint256(tx.sha256)) while len(hashes) > 1: newhashes = [] - for i in xrange(0, len(hashes), 2): + for i in range(0, len(hashes), 2): i2 = min(i+1, len(hashes)-1) newhashes.append(hash256(hashes[i] + hashes[i2])) hashes = newhashes @@ -929,7 +929,7 @@ class CBlock(CBlockHeader): self.nNonce, self.nSolution, self.vtx) -class CUnsignedAlert(object): +class CUnsignedAlert(): def __init__(self): self.nVersion = 1 self.nRelayUntil = 0 @@ -984,7 +984,7 @@ class CUnsignedAlert(object): self.strComment, self.strStatusBar, self.strReserved) -class CAlert(object): +class CAlert(): def __init__(self): self.vchMsg = "" self.vchSig = "" @@ -1005,7 +1005,7 @@ class CAlert(object): # Objects that correspond to messages on the wire -class msg_version(object): +class msg_version(): command = "version" def __init__(self, protocol_version=SPROUT_PROTO_VERSION): @@ -1060,7 +1060,7 @@ class msg_version(object): self.strSubVer, self.nStartingHeight) -class msg_verack(object): +class msg_verack(): command = "verack" def __init__(self): @@ -1076,7 +1076,7 @@ class msg_verack(object): return "msg_verack()" -class msg_addr(object): +class msg_addr(): command = "addr" def __init__(self): @@ -1092,7 +1092,7 @@ class msg_addr(object): return "msg_addr(addrs=%r)" % (self.addrs,) -class msg_alert(object): +class msg_alert(): command = "alert" def __init__(self): @@ -1111,7 +1111,7 @@ class msg_alert(object): return "msg_alert(alert=%r)" % (self.alert,) -class msg_inv(object): +class msg_inv(): command = "inv" def __init__(self, inv=None): @@ -1130,7 +1130,7 @@ class msg_inv(object): return "msg_inv(inv=%r)" % (self.inv,) -class msg_getdata(object): +class msg_getdata(): command = "getdata" def __init__(self): @@ -1146,7 +1146,7 @@ class msg_getdata(object): return "msg_getdata(inv=%r)" % (self.inv,) -class msg_notfound(object): +class msg_notfound(): command = "notfound" def __init__(self): @@ -1162,12 +1162,12 @@ class msg_notfound(object): return "msg_notfound(inv=%r)" % (self.inv,) -class msg_getblocks(object): +class msg_getblocks(): command = "getblocks" def __init__(self): self.locator = CBlockLocator() - self.hashstop = 0L + self.hashstop = 0 def deserialize(self, f): self.locator = CBlockLocator() @@ -1185,7 +1185,7 @@ class msg_getblocks(object): % (self.locator, self.hashstop) -class msg_tx(object): +class msg_tx(): command = "tx" def __init__(self, tx=CTransaction()): @@ -1201,7 +1201,7 @@ class msg_tx(object): return "msg_tx(tx=%r)" % (self.tx,) -class msg_block(object): +class msg_block(): command = "block" def __init__(self, block=None): @@ -1220,7 +1220,7 @@ class msg_block(object): return "msg_block(block=%r)" % (self.block,) -class msg_getaddr(object): +class msg_getaddr(): command = "getaddr" def __init__(self): @@ -1236,7 +1236,7 @@ class msg_getaddr(object): return "msg_getaddr()" -class msg_ping_prebip31(object): +class msg_ping_prebip31(): command = "ping" def __init__(self): @@ -1252,10 +1252,10 @@ class msg_ping_prebip31(object): return "msg_ping() (pre-bip31)" -class msg_ping(object): +class msg_ping(): command = "ping" - def __init__(self, nonce=0L): + def __init__(self, nonce=0): self.nonce = nonce def deserialize(self, f): @@ -1270,10 +1270,10 @@ class msg_ping(object): return "msg_ping(nonce=%08x)" % self.nonce -class msg_pong(object): +class msg_pong(): command = "pong" - def __init__(self, nonce=0L): + def __init__(self, nonce=0): self.nonce = nonce def deserialize(self, f): @@ -1288,7 +1288,7 @@ class msg_pong(object): return "msg_pong(nonce=%08x)" % self.nonce -class msg_mempool(object): +class msg_mempool(): command = "mempool" def __init__(self): @@ -1308,12 +1308,12 @@ class msg_mempool(object): # number of entries # vector of hashes # hash_stop (hash of last desired block header, 0 to get as many as possible) -class msg_getheaders(object): +class msg_getheaders(): command = "getheaders" def __init__(self): self.locator = CBlockLocator() - self.hashstop = 0L + self.hashstop = 0 def deserialize(self, f): self.locator = CBlockLocator() @@ -1333,7 +1333,7 @@ class msg_getheaders(object): # headers message has # -class msg_headers(object): +class msg_headers(): command = "headers" def __init__(self): @@ -1353,14 +1353,14 @@ class msg_headers(object): return "msg_headers(headers=%r)" % (self.headers,) -class msg_reject(object): +class msg_reject(): command = "reject" def __init__(self): self.message = "" self.code = "" self.reason = "" - self.data = 0L + self.data = 0 def deserialize(self, f): self.message = deser_string(f) @@ -1382,7 +1382,7 @@ class msg_reject(object): % (self.message, self.code, self.reason, self.data) -class msg_filteradd(object): +class msg_filteradd(): command = "filteradd" def __init__(self): @@ -1398,7 +1398,7 @@ class msg_filteradd(object): return "msg_filteradd(data=%r)" % (self.data,) -class msg_filterclear(object): +class msg_filterclear(): command = "filterclear" def __init__(self): @@ -1416,7 +1416,7 @@ class msg_filterclear(object): # This is what a callback should look like for NodeConn # Reimplement the on_* functions to provide handling for events -class NodeConnCB(object): +class NodeConnCB(): def __init__(self): self.verack_received = False @@ -1448,8 +1448,8 @@ class NodeConnCB(object): try: self.cbmap[message.command](conn, message) except: - print "ERROR delivering %r (%s)" % (message, - sys.exc_info()[0]) + print("ERROR delivering %r (%s)" % (message, + sys.exc_info()[0])) def on_version(self, conn, message): if message.nVersion >= 209: @@ -1540,8 +1540,8 @@ class NodeConn(asyncore.dispatcher): vt.addrFrom.ip = "0.0.0.0" vt.addrFrom.port = 0 self.send_message(vt, True) - print 'MiniNode: Connecting to Bitcoin Node IP # ' + dstaddr + ':' \ - + str(dstport) + ' using version ' + str(protocol_version) + print('MiniNode: Connecting to Bitcoin Node IP # ' + dstaddr + ':' \ + + str(dstport) + ' using version ' + str(protocol_version)) try: self.connect((dstaddr, dstport)) @@ -1625,7 +1625,7 @@ class NodeConn(asyncore.dispatcher): raise ValueError("got bad checksum %r" % (self.recvbuf,)) self.recvbuf = self.recvbuf[4+12+4+4+msglen:] if command in self.messagemap: - f = cStringIO.StringIO(msg) + f = io.StringIO(msg) t = self.messagemap[command]() t.deserialize(f) self.got_message(t) diff --git a/qa/rpc-tests/test_framework/netutil.py b/qa/rpc-tests/test_framework/netutil.py index ba1e8b0d6..38e0dab26 100644 --- a/qa/rpc-tests/test_framework/netutil.py +++ b/qa/rpc-tests/test_framework/netutil.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or https://www.opensource.org/licenses/mit-license.php . diff --git a/qa/rpc-tests/test_framework/script.py b/qa/rpc-tests/test_framework/script.py index e7aa12e93..4440ae940 100644 --- a/qa/rpc-tests/test_framework/script.py +++ b/qa/rpc-tests/test_framework/script.py @@ -1,4 +1,3 @@ -# # script.py # # This file is modified from python-bitcoinlib. @@ -12,8 +11,6 @@ Functionality to build scripts, as well as SignatureHash(). """ -from __future__ import absolute_import, division, print_function, unicode_literals - from test_framework.mininode import CTransaction, CTxOut, hash256 import sys diff --git a/qa/rpc-tests/test_framework/socks5.py b/qa/rpc-tests/test_framework/socks5.py index 813654e52..1e2dda807 100644 --- a/qa/rpc-tests/test_framework/socks5.py +++ b/qa/rpc-tests/test_framework/socks5.py @@ -4,8 +4,8 @@ ''' Dummy Socks5 server for testing. ''' -from __future__ import print_function, division, unicode_literals -import socket, threading, Queue + +import socket, threading import traceback, sys ### Protocol constants @@ -117,7 +117,7 @@ class Socks5Connection(object): self.serv.queue.put(cmdin) print('Proxy: ', cmdin) # Fall through to disconnect - except Exception,e: + except Exception as e: traceback.print_exc(file=sys.stderr) self.serv.queue.put(e) finally: @@ -132,7 +132,7 @@ class Socks5Server(object): self.s.listen(5) self.running = False self.thread = None - self.queue = Queue.Queue() # report connections and exceptions to client + self.queue = queue.Queue() # report connections and exceptions to client def run(self): while self.running: diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index 067b2dce3..30fe52691 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or https://www.opensource.org/licenses/mit-license.php . @@ -13,8 +13,8 @@ import shutil import tempfile import traceback -from authproxy import JSONRPCException -from util import assert_equal, check_json_precision, \ +from .authproxy import JSONRPCException +from .util import assert_equal, check_json_precision, \ initialize_chain, initialize_chain_clean, \ start_nodes, connect_nodes_bi, stop_nodes, \ sync_blocks, sync_mempools, wait_bitcoinds @@ -172,7 +172,7 @@ class ComparisonTestFramework(BitcoinTestFramework): help="bitcoind binary to use for reference nodes (if any)") def setup_chain(self): - print "Initializing test directory "+self.options.tmpdir + print("Initializing test directory "+self.options.tmpdir) initialize_chain_clean(self.options.tmpdir, self.num_nodes) def setup_network(self): diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index a2095cd65..bf1da0904 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -21,7 +21,7 @@ import subprocess import time import re -from authproxy import AuthServiceProxy +from .authproxy import AuthServiceProxy PRE_BLOSSOM_BLOCK_TARGET_SPACING = 150 POST_BLOSSOM_BLOCK_TARGET_SPACING = 75 @@ -147,11 +147,11 @@ def initialize_chain(test_dir): args.append("-connect=127.0.0.1:"+str(p2p_port(0))) bitcoind_processes[i] = subprocess.Popen(args) if os.getenv("PYTHON_DEBUG", ""): - print "initialize_chain: bitcoind started, calling bitcoin-cli -rpcwait getblockcount" + print("initialize_chain: bitcoind started, calling bitcoin-cli -rpcwait getblockcount") subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir, "-rpcwait", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): - print "initialize_chain: bitcoin-cli -rpcwait getblockcount completed" + print("initialize_chain: bitcoin-cli -rpcwait getblockcount completed") devnull.close() rpcs = [] for i in range(4): @@ -239,12 +239,12 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") if os.getenv("PYTHON_DEBUG", ""): - print "start_node: bitcoind started, calling bitcoin-cli -rpcwait getblockcount" + print("start_node: bitcoind started, calling bitcoin-cli -rpcwait getblockcount") subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir] + _rpchost_to_args(rpchost) + ["-rpcwait", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): - print "start_node: calling bitcoin-cli -rpcwait getblockcount returned" + print("start_node: calling bitcoin-cli -rpcwait getblockcount returned") devnull.close() url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) if timewait is not None: @@ -442,7 +442,7 @@ def fail(message=""): def wait_and_assert_operationid_status_result(node, myopid, in_status='success', in_errormsg=None, timeout=300): print('waiting for async operation {}'.format(myopid)) result = None - for _ in xrange(1, timeout): + for _ in range(1, timeout): results = node.z_getoperationresult([myopid]) if len(results) > 0: result = results[0]