diff --git a/test/functional/abc-p2p-fullblocktest.py b/test/functional/abc-p2p-fullblocktest.py --- a/test/functional/abc-p2p-fullblocktest.py +++ b/test/functional/abc-p2p-fullblocktest.py @@ -22,7 +22,7 @@ MAX_BLOCK_SIGOPS_PER_MB, MAX_TX_SIGOPS_COUNT) -class PreviousSpendableOutput(object): +class PreviousSpendableOutput(): def __init__(self, tx=CTransaction(), n=-1): self.tx = tx diff --git a/test/functional/mempool-accept-txn.py b/test/functional/mempool-accept-txn.py --- a/test/functional/mempool-accept-txn.py +++ b/test/functional/mempool-accept-txn.py @@ -24,7 +24,7 @@ TXNS_TOO_MANY_SIGOPS_ERROR.decode("utf-8") -class PreviousSpendableOutput(object): +class PreviousSpendableOutput(): def __init__(self, tx=CTransaction(), n=-1): self.tx = tx diff --git a/test/functional/p2p-fullblocktest.py b/test/functional/p2p-fullblocktest.py --- a/test/functional/p2p-fullblocktest.py +++ b/test/functional/p2p-fullblocktest.py @@ -15,8 +15,7 @@ from test_framework.cdefs import LEGACY_MAX_BLOCK_SIZE, MAX_BLOCK_SIGOPS_PER_MB -class PreviousSpendableOutput(object): - +class PreviousSpendableOutput(): def __init__(self, tx=CTransaction(), n=-1): self.tx = tx self.n = n # the output we're spending diff --git a/test/functional/test_framework/authproxy.py b/test/functional/test_framework/authproxy.py --- a/test/functional/test_framework/authproxy.py +++ b/test/functional/test_framework/authproxy.py @@ -34,24 +34,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -try: - import http.client as httplib -except ImportError: - import httplib import base64 import decimal +import http.client import json import logging import socket import time -try: - import urllib.parse as urlparse -except ImportError: - import urlparse - -USER_AGENT = "AuthServiceProxy/0.1" +import urllib.parse HTTP_TIMEOUT = 30 +USER_AGENT = "AuthServiceProxy/0.1" log = logging.getLogger("BitcoinRPC") @@ -62,7 +55,7 @@ errmsg = '%(message)s (%(code)i)' % rpc_error except (KeyError, TypeError): errmsg = '' - Exception.__init__(self, errmsg) + super().__init__(errmsg) self.error = rpc_error @@ -72,7 +65,7 @@ raise TypeError(repr(o) + " is not JSON serializable") -class AuthServiceProxy(object): +class AuthServiceProxy(): __id_count = 0 # ensure_ascii: escape unicode as \uXXXX, passed to json.dumps @@ -80,20 +73,12 @@ self.__service_url = service_url self._service_name = service_name self.ensure_ascii = ensure_ascii # can be toggled on the fly by tests - self.__url = urlparse.urlparse(service_url) - if self.__url.port is None: - port = 80 - else: - port = self.__url.port - (user, passwd) = (self.__url.username, self.__url.password) - try: - user = user.encode('utf8') - except AttributeError: - pass - try: - passwd = passwd.encode('utf8') - except AttributeError: - pass + self.__url = urllib.parse.urlparse(service_url) + port = 80 if self.__url.port is None else self.__url.port + user = None if self.__url.username is None else self.__url.username.encode( + 'utf8') + passwd = None if self.__url.password is None else self.__url.password.encode( + 'utf8') authpair = user + b':' + passwd self.__auth_header = b'Basic ' + base64.b64encode(authpair) @@ -101,11 +86,11 @@ # 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, - timeout=timeout) + self.__conn = http.client.HTTPSConnection( + self.__url.hostname, port, timeout=timeout) else: - self.__conn = httplib.HTTPConnection(self.__url.hostname, port, - timeout=timeout) + self.__conn = http.client.HTTPConnection( + self.__url.hostname, port, timeout=timeout) def __getattr__(self, name): if name.startswith('__') and name.endswith('__'): @@ -127,7 +112,7 @@ try: self.__conn.request(method, path, postdata, headers) return self._get_response() - except httplib.BadStatusLine as e: + except http.client.BadStatusLine as e: if e.line == "''": # if connection was closed, try again self.__conn.close() self.__conn.request(method, path, postdata, headers) @@ -163,7 +148,7 @@ else: return response['result'] - def _batch(self, rpc_call_list): + def batch(self, rpc_call_list): postdata = json.dumps( list(rpc_call_list), default=EncodeDecimal, ensure_ascii=self.ensure_ascii) log.debug("--> " + postdata) diff --git a/test/functional/test_framework/blockstore.py b/test/functional/test_framework/blockstore.py --- a/test/functional/test_framework/blockstore.py +++ b/test/functional/test_framework/blockstore.py @@ -2,10 +2,7 @@ # Copyright (c) 2015-2016 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -# BlockStore: a helper class that keeps a map of blocks and implements -# helper functions for responding to getheaders and getdata, -# and for constructing a getheaders message -# +"""BlockStore and TxStore helper classes.""" from .mininode import * from io import BytesIO @@ -14,7 +11,13 @@ logger = logging.getLogger("TestFramework.blockstore") -class BlockStore(object): +class BlockStore(): + """BlockStore helper class. + + BlockStore keeps a map of blocks and implements helper functions for + responding to getheaders and getdata, and for constructing a getheaders + message. + """ def __init__(self, datadir): self.blockDB = dbmd.open(datadir + "/blocks", 'c') @@ -126,8 +129,7 @@ return locator -class TxStore(object): - +class TxStore(): def __init__(self, datadir): self.txDB = dbmd.open(datadir + "/transactions", 'c') diff --git a/test/functional/test_framework/comptool.py b/test/functional/test_framework/comptool.py --- a/test/functional/test_framework/comptool.py +++ b/test/functional/test_framework/comptool.py @@ -31,11 +31,8 @@ global mininode_lock -class RejectResult(object): - - ''' - Outcome that expects rejection of a transaction or block. - ''' +class RejectResult(): + """Outcome that expects rejection of a transaction or block.""" def __init__(self, code, reason=b''): self.code = code @@ -174,16 +171,14 @@ # 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 self.connections = [] diff --git a/test/functional/test_framework/coverage.py b/test/functional/test_framework/coverage.py --- a/test/functional/test_framework/coverage.py +++ b/test/functional/test_framework/coverage.py @@ -17,7 +17,7 @@ REFERENCE_FILENAME = 'rpc_interface.txt' -class AuthServiceProxyWrapper(object): +class AuthServiceProxyWrapper(): """ An object that wraps AuthServiceProxy to record specific RPC calls. 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 @@ -96,7 +96,7 @@ ssl.EC_KEY_new_by_curve_name.errcheck = _check_result -class CECKey(object): +class CECKey(): """Wrapper around OpenSSL's EC_KEY""" POINT_CONVERSION_COMPRESSED = 2 diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py --- a/test/functional/test_framework/mininode.py +++ b/test/functional/test_framework/mininode.py @@ -239,8 +239,7 @@ # Objects that map to bitcoind objects, which can be serialized/deserialized -class CAddress(object): - +class CAddress(): def __init__(self): self.nServices = 1 self.pchReserved = b"\x00" * 10 + b"\xff" * 2 @@ -269,7 +268,7 @@ MSG_WITNESS_FLAG = 1 << 30 -class CInv(object): +class CInv(): typemap = { 0: "Error", 1: "TX", @@ -298,8 +297,7 @@ % (self.typemap[self.type], self.hash) -class CBlockLocator(object): - +class CBlockLocator(): def __init__(self): self.nVersion = MY_VERSION self.vHave = [] @@ -319,8 +317,7 @@ % (self.nVersion, repr(self.vHave)) -class COutPoint(object): - +class COutPoint(): def __init__(self, hash=0, n=0): self.hash = hash self.n = n @@ -339,8 +336,7 @@ return "COutPoint(hash=%064x n=%i)" % (self.hash, self.n) -class CTxIn(object): - +class CTxIn(): def __init__(self, outpoint=None, scriptSig=b"", nSequence=0): if outpoint is None: self.prevout = COutPoint() @@ -368,8 +364,7 @@ self.nSequence) -class CTxOut(object): - +class CTxOut(): def __init__(self, nValue=0, scriptPubKey=b""): self.nValue = nValue self.scriptPubKey = scriptPubKey @@ -390,8 +385,7 @@ bytes_to_hex_str(self.scriptPubKey)) -class CScriptWitness(object): - +class CScriptWitness(): def __init__(self): # stack is a vector of strings self.stack = [] @@ -406,8 +400,7 @@ return True -class CTxInWitness(object): - +class CTxInWitness(): def __init__(self): self.scriptWitness = CScriptWitness() @@ -424,8 +417,7 @@ return self.scriptWitness.is_null() -class CTxWitness(object): - +class CTxWitness(): def __init__(self): self.vtxinwit = [] @@ -453,8 +445,7 @@ return True -class CTransaction(object): - +class CTransaction(): def __init__(self, tx=None): if tx is None: self.nVersion = 1 @@ -559,8 +550,7 @@ % (self.nVersion, repr(self.vin), repr(self.vout), repr(self.wit), self.nLockTime) -class CBlockHeader(object): - +class CBlockHeader(): def __init__(self, header=None): if header is None: self.set_null() @@ -700,8 +690,7 @@ time.ctime(self.nTime), self.nBits, self.nNonce, repr(self.vtx)) -class CUnsignedAlert(object): - +class CUnsignedAlert(): def __init__(self): self.nVersion = 1 self.nRelayUntil = 0 @@ -756,8 +745,7 @@ self.strComment, self.strStatusBar, self.strReserved) -class CAlert(object): - +class CAlert(): def __init__(self): self.vchMsg = b"" self.vchSig = b"" @@ -777,8 +765,7 @@ % (len(self.vchMsg), len(self.vchSig)) -class PrefilledTransaction(object): - +class PrefilledTransaction(): def __init__(self, index=0, tx=None): self.index = index self.tx = tx @@ -806,8 +793,7 @@ # This is what we send on the wire, in a cmpctblock message. -class P2PHeaderAndShortIDs(object): - +class P2PHeaderAndShortIDs(): def __init__(self): self.header = CBlockHeader() self.nonce = 0 @@ -867,8 +853,7 @@ # encoding into indices that can be used for lookup. -class HeaderAndShortIDs(object): - +class HeaderAndShortIDs(): def __init__(self, p2pheaders_and_shortids=None): self.header = CBlockHeader() self.nonce = 0 @@ -932,7 +917,7 @@ return "HeaderAndShortIDs(header=%s, nonce=%d, shortids=%s, prefilledtxn=%s" % (repr(self.header), self.nonce, repr(self.shortids), repr(self.prefilled_txn)) -class BlockTransactionsRequest(object): +class BlockTransactionsRequest(): def __init__(self, blockhash=0, indexes=None): self.blockhash = blockhash @@ -972,7 +957,7 @@ return "BlockTransactionsRequest(hash=%064x indexes=%s)" % (self.blockhash, repr(self.indexes)) -class BlockTransactions(object): +class BlockTransactions(): def __init__(self, blockhash=0, transactions=None): self.blockhash = blockhash @@ -996,7 +981,7 @@ # Objects that correspond to messages on the wire -class msg_version(object): +class msg_version(): command = b"version" def __init__(self): @@ -1064,7 +1049,7 @@ self.strSubVer, self.nStartingHeight, self.nRelay) -class msg_verack(object): +class msg_verack(): command = b"verack" def __init__(self): @@ -1080,7 +1065,7 @@ return "msg_verack()" -class msg_addr(object): +class msg_addr(): command = b"addr" def __init__(self): @@ -1096,7 +1081,7 @@ return "msg_addr(addrs=%s)" % (repr(self.addrs)) -class msg_alert(object): +class msg_alert(): command = b"alert" def __init__(self): @@ -1115,7 +1100,7 @@ return "msg_alert(alert=%s)" % (repr(self.alert), ) -class msg_inv(object): +class msg_inv(): command = b"inv" def __init__(self, inv=None): @@ -1134,7 +1119,7 @@ return "msg_inv(inv=%s)" % (repr(self.inv)) -class msg_getdata(object): +class msg_getdata(): command = b"getdata" def __init__(self, inv=None): @@ -1150,7 +1135,7 @@ return "msg_getdata(inv=%s)" % (repr(self.inv)) -class msg_getblocks(object): +class msg_getblocks(): command = b"getblocks" def __init__(self): @@ -1173,7 +1158,7 @@ % (repr(self.locator), self.hashstop) -class msg_tx(object): +class msg_tx(): command = b"tx" def __init__(self, tx=CTransaction()): @@ -1195,7 +1180,7 @@ return self.tx.serialize_with_witness() -class msg_block(object): +class msg_block(): command = b"block" def __init__(self, block=None): @@ -1217,8 +1202,7 @@ # note that the user must supply the name of the command, and the data -class msg_generic(object): - +class msg_generic(): def __init__(self, command, data=None): self.command = command self.data = data @@ -1237,7 +1221,7 @@ return r -class msg_getaddr(object): +class msg_getaddr(): command = b"getaddr" def __init__(self): @@ -1253,7 +1237,7 @@ return "msg_getaddr()" -class msg_ping_prebip31(object): +class msg_ping_prebip31(): command = b"ping" def __init__(self): @@ -1269,7 +1253,7 @@ return "msg_ping() (pre-bip31)" -class msg_ping(object): +class msg_ping(): command = b"ping" def __init__(self, nonce=0): @@ -1287,7 +1271,7 @@ return "msg_ping(nonce=%08x)" % self.nonce -class msg_pong(object): +class msg_pong(): command = b"pong" def __init__(self, nonce=0): @@ -1305,7 +1289,7 @@ return "msg_pong(nonce=%08x)" % self.nonce -class msg_mempool(object): +class msg_mempool(): command = b"mempool" def __init__(self): @@ -1321,7 +1305,7 @@ return "msg_mempool()" -class msg_sendheaders(object): +class msg_sendheaders(): command = b"sendheaders" def __init__(self): @@ -1341,7 +1325,7 @@ # 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 = b"getheaders" def __init__(self): @@ -1366,7 +1350,7 @@ # headers message has # -class msg_headers(object): +class msg_headers(): command = b"headers" def __init__(self): @@ -1386,7 +1370,7 @@ return "msg_headers(headers=%s)" % repr(self.headers) -class msg_reject(object): +class msg_reject(): command = b"reject" REJECT_MALFORMED = 1 @@ -1417,10 +1401,11 @@ return "msg_reject: %s %d %s [%064x]" \ % (self.message, self.code, self.reason, self.data) -# Helper function - def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf')): + ''' + This function is subsequently remove in core's PR11712 + ''' attempt = 0 elapsed = 0 @@ -1435,7 +1420,7 @@ return False -class msg_feefilter(object): +class msg_feefilter(): command = b"feefilter" def __init__(self, feerate=0): @@ -1453,7 +1438,7 @@ return "msg_feefilter(feerate=%08x)" % self.feerate -class msg_sendcmpct(object): +class msg_sendcmpct(): command = b"sendcmpct" def __init__(self): @@ -1474,7 +1459,7 @@ return "msg_sendcmpct(announce=%s, version=%lu)" % (self.announce, self.version) -class msg_cmpctblock(object): +class msg_cmpctblock(): command = b"cmpctblock" def __init__(self, header_and_shortids=None): @@ -1493,7 +1478,7 @@ return "msg_cmpctblock(HeaderAndShortIDs=%s)" % repr(self.header_and_shortids) -class msg_getblocktxn(object): +class msg_getblocktxn(): command = b"getblocktxn" def __init__(self): @@ -1512,7 +1497,7 @@ return "msg_getblocktxn(block_txn_request=%s)" % (repr(self.block_txn_request)) -class msg_blocktxn(object): +class msg_blocktxn(): command = b"blocktxn" def __init__(self): @@ -1538,7 +1523,7 @@ return r -class NodeConnCB(object): +class NodeConnCB(): """Callback and helper functions for P2P connection to a bitcoind node. Individual testcases should subclass this and override the on_* methods 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 @@ -635,7 +635,7 @@ # This is used, eg, for blockchain heights in coinbase scripts (bip34) -class CScriptNum(object): +class CScriptNum(): def __init__(self, d=0): self.value = d diff --git a/test/functional/test_framework/socks5.py b/test/functional/test_framework/socks5.py --- a/test/functional/test_framework/socks5.py +++ b/test/functional/test_framework/socks5.py @@ -41,8 +41,8 @@ # Implementation classes -class Socks5Configuration(object): - '''Proxy configuration''' +class Socks5Configuration(): + """Proxy configuration.""" def __init__(self): self.addr = None # Bind address (must be set) @@ -51,8 +51,8 @@ self.auth = False # Support authentication -class Socks5Command(object): - '''Information about an incoming socks5 command''' +class Socks5Command(): + """Information about an incoming socks5 command.""" def __init__(self, cmd, atyp, addr, port, username, password): self.cmd = cmd # Command (one of Command.*) @@ -66,7 +66,7 @@ return 'Socks5Command(%s,%s,%s,%s,%s,%s)' % (self.cmd, self.atyp, self.addr, self.port, self.username, self.password) -class Socks5Connection(object): +class Socks5Connection(): def __init__(self, serv, conn, peer): self.serv = serv self.conn = conn @@ -142,7 +142,7 @@ self.conn.close() -class Socks5Server(object): +class Socks5Server(): def __init__(self, conf): self.conf = conf self.s = socket.socket(conf.af) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -51,7 +51,7 @@ BITCOIND_PROC_WAIT_TIMEOUT = 60 -class BitcoinTestFramework(object): +class BitcoinTestFramework(): """Base class for a bitcoin test script. Individual bitcoin test scripts should subclass this class and override the following methods: diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -479,8 +479,7 @@ sys.exit(1) -class RPCCoverage(object): - +class RPCCoverage(): """ Coverage reporting utilities for test_runner.