[qa] Use python2/3 syntax

This commit is contained in:
MarcoFalke
2016-03-19 21:36:32 +01:00
parent 28ad4d9fc2
commit fa524d9ddb
21 changed files with 78 additions and 75 deletions

View File

@@ -3,8 +3,9 @@
# and for constructing a getheaders message
#
from mininode import *
from .mininode import *
import dbm
from io import BytesIO
class BlockStore(object):
def __init__(self, datadir):
@@ -21,7 +22,7 @@ class BlockStore(object):
serialized_block = self.blockDB[repr(blockhash)]
except KeyError:
return None
f = cStringIO.StringIO(serialized_block)
f = BytesIO(serialized_block)
ret = CBlock()
ret.deserialize(f)
ret.calc_sha256()
@@ -115,7 +116,7 @@ class TxStore(object):
serialized_tx = self.txDB[repr(txhash)]
except KeyError:
return None
f = cStringIO.StringIO(serialized_tx)
f = BytesIO(serialized_tx)
ret = CTransaction()
ret.deserialize(f)
ret.calc_sha256()

View File

@@ -4,8 +4,8 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
from mininode import *
from script import CScript, OP_TRUE, OP_CHECKSIG
from .mininode import *
from .script import CScript, OP_TRUE, OP_CHECKSIG
# Create a block (with regtest difficulty)
def create_block(hashprev, coinbase, nTime=None):

View File

@@ -4,9 +4,9 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
from mininode import *
from blockstore import BlockStore, TxStore
from util import p2p_port
from .mininode import *
from .blockstore import BlockStore, TxStore
from .util import p2p_port
'''
This is a tool for comparing two or more bitcoinds to each other

View File

@@ -24,7 +24,8 @@ import binascii
import time
import sys
import random
import cStringIO
from io import BytesIO
from codecs import encode
import hashlib
from threading import RLock
from threading import Thread
@@ -75,12 +76,12 @@ def deser_string(f):
def ser_string(s):
if len(s) < 253:
return chr(len(s)) + s
return struct.pack("B", len(s)) + s
elif len(s) < 0x10000:
return chr(253) + struct.pack("<H", len(s)) + s
return struct.pack("B", 253) + struct.pack("<H", len(s)) + s
elif len(s) < 0x100000000L:
return chr(254) + struct.pack("<I", len(s)) + s
return chr(255) + struct.pack("<Q", len(s)) + s
return struct.pack("B", 254) + struct.pack("<I", len(s)) + s
return struct.pack("B", 255) + struct.pack("<Q", len(s)) + s
def deser_uint256(f):
@@ -132,13 +133,13 @@ def deser_vector(f, c):
def ser_vector(l):
r = ""
if len(l) < 253:
r = chr(len(l))
r = struct.pack("B", len(l))
elif len(l) < 0x10000:
r = chr(253) + struct.pack("<H", len(l))
r = struct.pack("B", 253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
r = chr(254) + struct.pack("<I", len(l))
r = struct.pack("B", 254) + struct.pack("<I", len(l))
else:
r = chr(255) + struct.pack("<Q", len(l))
r = struct.pack("B", 255) + struct.pack("<Q", len(l))
for i in l:
r += i.serialize()
return r
@@ -162,13 +163,13 @@ def deser_uint256_vector(f):
def ser_uint256_vector(l):
r = ""
if len(l) < 253:
r = chr(len(l))
r = struct.pack("B", len(l))
elif len(l) < 0x10000:
r = chr(253) + struct.pack("<H", len(l))
r = struct.pack("B", 253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
r = chr(254) + struct.pack("<I", len(l))
r = struct.pack("B", 254) + struct.pack("<I", len(l))
else:
r = chr(255) + struct.pack("<Q", len(l))
r = struct.pack("B", 255) + struct.pack("<Q", len(l))
for i in l:
r += ser_uint256(i)
return r
@@ -192,13 +193,13 @@ def deser_string_vector(f):
def ser_string_vector(l):
r = ""
if len(l) < 253:
r = chr(len(l))
r = struct.pack("B", len(l))
elif len(l) < 0x10000:
r = chr(253) + struct.pack("<H", len(l))
r = struct.pack("B", 253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
r = chr(254) + struct.pack("<I", len(l))
r = struct.pack("B", 254) + struct.pack("<I", len(l))
else:
r = chr(255) + struct.pack("<Q", len(l))
r = struct.pack("B", 255) + struct.pack("<Q", len(l))
for sv in l:
r += ser_string(sv)
return r
@@ -222,20 +223,20 @@ def deser_int_vector(f):
def ser_int_vector(l):
r = ""
if len(l) < 253:
r = chr(len(l))
r = struct.pack("B", len(l))
elif len(l) < 0x10000:
r = chr(253) + struct.pack("<H", len(l))
r = struct.pack("B", 253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
r = chr(254) + struct.pack("<I", len(l))
r = struct.pack("B", 254) + struct.pack("<I", len(l))
else:
r = chr(255) + struct.pack("<Q", len(l))
r = struct.pack("B", 255) + struct.pack("<Q", len(l))
for i in l:
r += struct.pack("<i", i)
return r
# Deserialize from a hex string representation (eg from RPC)
def FromHex(obj, hex_string):
obj.deserialize(cStringIO.StringIO(binascii.unhexlify(hex_string)))
obj.deserialize(BytesIO(binascii.unhexlify(hex_string)))
return obj
# Convert a binary-serializable object to hex (eg for submission via RPC)
@@ -423,7 +424,7 @@ class CTransaction(object):
def calc_sha256(self):
if self.sha256 is None:
self.sha256 = uint256_from_str(hash256(self.serialize()))
self.hash = hash256(self.serialize())[::-1].encode('hex_codec')
self.hash = encode(hash256(self.serialize())[::-1], 'hex')
def is_valid(self):
self.calc_sha256()
@@ -492,7 +493,7 @@ class CBlockHeader(object):
r += struct.pack("<I", self.nBits)
r += struct.pack("<I", self.nNonce)
self.sha256 = uint256_from_str(hash256(r))
self.hash = hash256(r)[::-1].encode('hex_codec')
self.hash = encode(hash256(r)[::-1], 'hex')
def rehash(self):
self.sha256 = None
@@ -1281,7 +1282,7 @@ class NodeConn(asyncore.dispatcher):
raise ValueError("got bad checksum " + repr(self.recvbuf))
self.recvbuf = self.recvbuf[4+12+4+4+msglen:]
if command in self.messagemap:
f = cStringIO.StringIO(msg)
f = BytesIO(msg)
t = self.messagemap[command]()
t.deserialize(f)
self.got_message(t)

View File

@@ -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:

View File

@@ -26,7 +26,7 @@ from .util import (
check_json_precision,
initialize_chain_clean,
)
from authproxy import AuthServiceProxy, JSONRPCException
from .authproxy import AuthServiceProxy, JSONRPCException
class BitcoinTestFramework(object):
@@ -140,7 +140,7 @@ class BitcoinTestFramework(object):
print("JSONRPC error: "+e.error['message'])
traceback.print_tb(sys.exc_info()[2])
except AssertionError as e:
print("Assertion failed: "+e.message)
print("Assertion failed: "+ str(e))
traceback.print_tb(sys.exc_info()[2])
except Exception as e:
print("Unexpected exception caught during testing: "+str(e))