uid stringlengths 24 24 | split stringclasses 1
value | category stringclasses 2
values | content stringlengths 5 482k | signature stringlengths 1 14k | suffix stringlengths 1 482k | prefix stringlengths 9 14k | prefix_token_count int64 3 5.01k | prefix_token_budget int64 64 256 | element_token_count int64 1 292k | signature_token_count int64 1 5.01k | prefix_context_token_count int64 0 255 | repo stringlengths 7 112 | path stringlengths 4 208 | language stringclasses 1
value | name stringlengths 1 218 | qualname stringlengths 1 218 | start_line int64 1 26.7k | end_line int64 1 26.7k | signature_start_line int64 1 26.7k | signature_end_line int64 1 26.7k | source_hash stringlengths 40 40 | source_dataset stringclasses 1
value | source_split stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
9456376042e27de785c76123 | train | class | class CTxIn(object):
def __init__(self, outpoint=None, scriptSig=b"", nSequence=0):
if outpoint is None:
self.prevout = COutPoint()
else:
self.prevout = outpoint
self.scriptSig = scriptSig
self.nSequence = nSequence
def deserialize(self, f):
self.... | class CTxIn(object):
| def __init__(self, outpoint=None, scriptSig=b"", nSequence=0):
if outpoint is None:
self.prevout = COutPoint()
else:
self.prevout = outpoint
self.scriptSig = scriptSig
self.nSequence = nSequence
def deserialize(self, f):
self.prevout = COutPoint()... | r = b""
r += ser_uint256(self.hash)
r += struct.pack("<I", self.n)
return r
def __repr__(self):
return "COutPoint(hash=%064x n=%i)" % (self.hash, self.n)
class CTxIn(object):
| 64 | 64 | 210 | 6 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | CTxIn | CTxIn | 307 | 332 | 307 | 307 | c099397d3a9d0fddd12e5a9c1a23d24bd9b24331 | bigcode/the-stack | train |
96e3dc15dfdf071d316ef557 | train | class | class msg_getblocktxn(object):
command = b"getblocktxn"
def __init__(self):
self.block_txn_request = None
def deserialize(self, f):
self.block_txn_request = BlockTransactionsRequest()
self.block_txn_request.deserialize(f)
def serialize(self):
r = b""
r += self.... | class msg_getblocktxn(object):
| command = b"getblocktxn"
def __init__(self):
self.block_txn_request = None
def deserialize(self, f):
self.block_txn_request = BlockTransactionsRequest()
self.block_txn_request.deserialize(f)
def serialize(self):
r = b""
r += self.block_txn_request.serialize()
... | .deserialize(f)
def serialize(self):
r = b""
r += self.header_and_shortids.serialize()
return r
def __repr__(self):
return "msg_cmpctblock(HeaderAndShortIDs=%s)" % repr(self.header_and_shortids)
class msg_getblocktxn(object):
| 64 | 64 | 114 | 7 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_getblocktxn | msg_getblocktxn | 1,242 | 1,258 | 1,242 | 1,242 | 4aff90b4e83977a9d4fcd6fce5804dcc7c9dcf5c | bigcode/the-stack | train |
c064510f0e7140e9f4239678 | train | class | class msg_pong(object):
command = b"pong"
def __init__(self, nonce=0):
self.nonce = nonce
def deserialize(self, f):
self.nonce = struct.unpack("<Q", f.read(8))[0]
def serialize(self):
r = b""
r += struct.pack("<Q", self.nonce)
return r
def __repr__(self):
... | class msg_pong(object):
| command = b"pong"
def __init__(self, nonce=0):
self.nonce = nonce
def deserialize(self, f):
self.nonce = struct.unpack("<Q", f.read(8))[0]
def serialize(self):
r = b""
r += struct.pack("<Q", self.nonce)
return r
def __repr__(self):
return "msg_pong... | ", f.read(8))[0]
def serialize(self):
r = b""
r += struct.pack("<Q", self.nonce)
return r
def __repr__(self):
return "msg_ping(nonce=%08x)" % self.nonce
class msg_pong(object):
| 64 | 64 | 106 | 6 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_pong | msg_pong | 1,060 | 1,075 | 1,060 | 1,060 | cf9ee144233e893b1ab6fc3f9b391d7113f55dd5 | bigcode/the-stack | train |
646dc93708c8918f04e1523c | train | class | class BlockTransactionsRequest(object):
def __init__(self, blockhash=0, indexes = None):
self.blockhash = blockhash
self.indexes = indexes if indexes != None else []
def deserialize(self, f):
self.blockhash = deser_uint256(f)
indexes_length = deser_compact_size(f)
for i... | class BlockTransactionsRequest(object):
| def __init__(self, blockhash=0, indexes = None):
self.blockhash = blockhash
self.indexes = indexes if indexes != None else []
def deserialize(self, f):
self.blockhash = deser_uint256(f)
indexes_length = deser_compact_size(f)
for i in range(indexes_length):
se... | _list:
self.shortids.append(calculate_shortid(k0, k1, block.vtx[i].sha256))
def __repr__(self):
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... | 86 | 86 | 287 | 6 | 80 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | BlockTransactionsRequest | BlockTransactionsRequest | 725 | 762 | 725 | 726 | 2cf3f33bf7f9b5ebbb319f59d88faf8f49439178 | bigcode/the-stack | train |
fbc09b3870275f86ef02bdc8 | train | class | class CTransaction(object):
def __init__(self, tx=None):
if tx is None:
self.nVersion = 1
self.vin = []
self.vout = []
self.nLockTime = 0
self.sha256 = None
self.hash = None
else:
self.nVersion = tx.nVersion
... | class CTransaction(object):
| def __init__(self, tx=None):
if tx is None:
self.nVersion = 1
self.vin = []
self.vout = []
self.nLockTime = 0
self.sha256 = None
self.hash = None
else:
self.nVersion = tx.nVersion
self.vin = copy.deepcopy... | def deserialize(self, f):
self.nValue = struct.unpack("<q", f.read(8))[0]
self.scriptPubKey = deser_string(f)
def serialize(self):
r = b""
r += struct.pack("<q", self.nValue)
r += ser_string(self.scriptPubKey)
return r
def __repr__(self):
return "CTxOut... | 129 | 129 | 433 | 5 | 124 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | CTransaction | CTransaction | 356 | 407 | 356 | 356 | e6f85832c00d0a52337fa567ae91dc97d0acf396 | bigcode/the-stack | train |
7e43e570083d6ef861e4f31a | train | class | class EarlyDisconnectError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
| class EarlyDisconnectError(Exception):
| def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
| .handle_close() for obj in disconnected ]
asyncore.loop(0.1, use_poll=True, map=mininode_socket_map, count=1)
# An exception we can raise if we detect a potential disconnect
# (p2p or rpc) before the test is complete
class EarlyDisconnectError(Exception):
| 64 | 64 | 34 | 6 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | EarlyDisconnectError | EarlyDisconnectError | 1,610 | 1,615 | 1,610 | 1,610 | 9368f2f3846a68946e57b224613091b90fd2ec30 | bigcode/the-stack | train |
0fc9021a5aab4680ae5a0fb4 | train | class | class msg_getaddr(object):
command = b"getaddr"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_getaddr()"
| class msg_getaddr(object):
| command = b"getaddr"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_getaddr()"
| , and the data
class msg_generic(object):
def __init__(self, command, data=None):
self.command = command
self.data = data
def serialize(self):
return self.data
def __repr__(self):
return "msg_generic()"
class msg_getaddr(object):
| 64 | 64 | 59 | 6 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_getaddr | msg_getaddr | 1,010 | 1,023 | 1,010 | 1,010 | ece78a7e32b302a7399ff10cec68543f2bbaf583 | bigcode/the-stack | train |
998c81baaf3420a2a0702f13 | train | class | class msg_addr(object):
command = b"addr"
def __init__(self):
self.addrs = []
def deserialize(self, f):
self.addrs = deser_vector(f, CAddress)
def serialize(self):
return ser_vector(self.addrs)
def __repr__(self):
return "msg_addr(addrs=%s)" % (repr(self.addrs))
| class msg_addr(object):
| command = b"addr"
def __init__(self):
self.addrs = []
def deserialize(self, f):
self.addrs = deser_vector(f, CAddress)
def serialize(self):
return ser_vector(self.addrs)
def __repr__(self):
return "msg_addr(addrs=%s)" % (repr(self.addrs))
| class msg_verack(object):
command = b"verack"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_verack()"
class msg_addr(object):
| 64 | 64 | 81 | 5 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_addr | msg_addr | 870 | 883 | 870 | 870 | b312067ca7f2f882b0e82518bb1745d61366898d | bigcode/the-stack | train |
ce7f96c8d371bedc3f5b36a4 | train | class | class NetworkThread(Thread):
def run(self):
while mininode_socket_map:
# We check for whether to disconnect outside of the asyncore
# loop to workaround the behavior of asyncore when using
# select
disconnected = []
for fd, obj in mininode_socket_m... | class NetworkThread(Thread):
| def run(self):
while mininode_socket_map:
# We check for whether to disconnect outside of the asyncore
# loop to workaround the behavior of asyncore when using
# select
disconnected = []
for fd, obj in mininode_socket_map.items():
i... | + 30 * 60 < time.time():
self.send_message(self.messagemap[b'ping']())
self.show_debug_msg("Recv %s" % repr(message))
self.cb.deliver(self, message)
def disconnect_node(self):
self.disconnect = True
class NetworkThread(Thread):
| 64 | 64 | 108 | 5 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | NetworkThread | NetworkThread | 1,594 | 1,605 | 1,594 | 1,594 | 2e6977b1bbea0f0ede243ad87364307fcbb6466d | bigcode/the-stack | train |
b365d6d7615b5e6c863ca82c | train | class | class CBlockHeader(object):
def __init__(self, header=None):
if header is None:
self.set_null()
else:
self.nVersion = header.nVersion
self.hashPrevBlock = header.hashPrevBlock
self.hashMerkleRoot = header.hashMerkleRoot
self.nTime = header.... | class CBlockHeader(object):
| def __init__(self, header=None):
if header is None:
self.set_null()
else:
self.nVersion = header.nVersion
self.hashPrevBlock = header.hashPrevBlock
self.hashMerkleRoot = header.hashMerkleRoot
self.nTime = header.nTime
self.nBits... | LockTime)
return r
def rehash(self):
self.sha256 = None
self.calc_sha256()
def calc_sha256(self):
if self.sha256 is None:
self.sha256 = uint256_from_str(hash256(self.serialize()))
self.hash = encode(hash256(self.serialize())[::-1], 'hex_codec').decode('ascii... | 183 | 183 | 613 | 6 | 177 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | CBlockHeader | CBlockHeader | 410 | 475 | 410 | 410 | 4dce5453f398283cf4d28e05fe7ba280a95a03c0 | bigcode/the-stack | train |
350f95e01ee33f5869ca46f7 | train | function | def ser_vector(l):
r = ser_compact_size(len(l))
for i in l:
r += i.serialize()
return r
| def ser_vector(l):
| r = ser_compact_size(len(l))
for i in l:
r += i.serialize()
return r
| * (nbytes - 3))
return v
def deser_vector(f, c):
nit = deser_compact_size(f)
r = []
for i in range(nit):
t = c()
t.deserialize(f)
r.append(t)
return r
def ser_vector(l):
| 64 | 64 | 31 | 5 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | ser_vector | ser_vector | 150 | 154 | 150 | 150 | 487123d5499f557564ba75e59ea1553081a83a6e | bigcode/the-stack | train |
f7c9cf1b15c4088d0eb55a48 | train | function | def ToHex(obj):
return bytes_to_hex_str(obj.serialize())
| def ToHex(obj):
| return bytes_to_hex_str(obj.serialize())
| i)
return r
# Deserialize from a hex string representation (eg from RPC)
def FromHex(obj, hex_string):
obj.deserialize(BytesIO(hex_str_to_bytes(hex_string)))
return obj
# Convert a binary-serializable object to hex (eg for submission via RPC)
def ToHex(obj):
| 64 | 64 | 14 | 5 | 59 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | ToHex | ToHex | 210 | 211 | 210 | 210 | 39524ae7896f4d97fd52c85edc36995245daf181 | bigcode/the-stack | train |
0a834b6b1ffe98c786bba54c | train | function | def deser_string_vector(f):
nit = deser_compact_size(f)
r = []
for i in range(nit):
t = deser_string(f)
r.append(t)
return r
| def deser_string_vector(f):
| nit = deser_compact_size(f)
r = []
for i in range(nit):
t = deser_string(f)
r.append(t)
return r
| i in range(nit):
t = deser_uint256(f)
r.append(t)
return r
def ser_uint256_vector(l):
r = ser_compact_size(len(l))
for i in l:
r += ser_uint256(i)
return r
def deser_string_vector(f):
| 64 | 64 | 43 | 6 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | deser_string_vector | deser_string_vector | 173 | 179 | 173 | 173 | d6f6b053be9770b4c12e316b6ab3ad3493dc2cb2 | bigcode/the-stack | train |
a6b95f84309f6d9f2b571c7c | train | function | def deser_uint256_vector(f):
nit = deser_compact_size(f)
r = []
for i in range(nit):
t = deser_uint256(f)
r.append(t)
return r
| def deser_uint256_vector(f):
| nit = deser_compact_size(f)
r = []
for i in range(nit):
t = deser_uint256(f)
r.append(t)
return r
| for i in range(nit):
t = c()
t.deserialize(f)
r.append(t)
return r
def ser_vector(l):
r = ser_compact_size(len(l))
for i in l:
r += i.serialize()
return r
def deser_uint256_vector(f):
| 64 | 64 | 45 | 7 | 56 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | deser_uint256_vector | deser_uint256_vector | 157 | 163 | 157 | 157 | e2da6cca1a5e001d90e693ae42bb7e4245485078 | bigcode/the-stack | train |
5e6cb04b030355fec3bb93cd | train | class | class msg_reject(object):
command = b"reject"
REJECT_MALFORMED = 1
def __init__(self):
self.message = b""
self.code = 0
self.reason = b""
self.data = 0
def deserialize(self, f):
self.message = deser_string(f)
self.code = struct.unpack("<B", f.read(1))[0]... | class msg_reject(object):
| command = b"reject"
REJECT_MALFORMED = 1
def __init__(self):
self.message = b""
self.code = 0
self.reason = b""
self.data = 0
def deserialize(self, f):
self.message = deser_string(f)
self.code = struct.unpack("<B", f.read(1))[0]
self.reason = des... | blocks = deser_vector(f, CBlock)
for x in blocks:
self.headers.append(CBlockHeader(x))
def serialize(self):
blocks = [CBlock(x) for x in self.headers]
return ser_vector(blocks)
def __repr__(self):
return "msg_headers(headers=%s)" % repr(self.headers)
class msg_reje... | 77 | 77 | 258 | 6 | 71 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_reject | msg_reject | 1,158 | 1,187 | 1,158 | 1,158 | 9c77591e6056a7f5e8067686ec47f83e4ec9df41 | bigcode/the-stack | train |
0bfd71a913c757821559588f | train | class | class msg_generic(object):
def __init__(self, command, data=None):
self.command = command
self.data = data
def serialize(self):
return self.data
def __repr__(self):
return "msg_generic()"
| class msg_generic(object):
| def __init__(self, command, data=None):
self.command = command
self.data = data
def serialize(self):
return self.data
def __repr__(self):
return "msg_generic()"
| .block.serialize()
def __repr__(self):
return "msg_block(block=%s)" % (repr(self.block))
# for cases where a user needs tighter control over what is sent over the wire
# note that the user must supply the name of the command, and the data
class msg_generic(object):
| 64 | 64 | 53 | 5 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_generic | msg_generic | 999 | 1,008 | 999 | 999 | fd59545273be5959594a4f410d70dc1caa04d9b6 | bigcode/the-stack | train |
7ad18655ec5f4161324311b2 | train | class | class CTxOut(object):
def __init__(self, nValue=0, scriptPubKey=b""):
self.nValue = nValue
self.scriptPubKey = scriptPubKey
def deserialize(self, f):
self.nValue = struct.unpack("<q", f.read(8))[0]
self.scriptPubKey = deser_string(f)
def serialize(self):
r = b""
... | class CTxOut(object):
| def __init__(self, nValue=0, scriptPubKey=b""):
self.nValue = nValue
self.scriptPubKey = scriptPubKey
def deserialize(self, f):
self.nValue = struct.unpack("<q", f.read(8))[0]
self.scriptPubKey = deser_string(f)
def serialize(self):
r = b""
r += struct.pack(... | I", self.nSequence)
return r
def __repr__(self):
return "CTxIn(prevout=%s scriptSig=%s nSequence=%i)" \
% (repr(self.prevout), bytes_to_hex_str(self.scriptSig),
self.nSequence)
class CTxOut(object):
| 64 | 64 | 167 | 6 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | CTxOut | CTxOut | 335 | 353 | 335 | 335 | e70eaae39547eec036a7a0a4d7257992133a61e6 | bigcode/the-stack | train |
27a88527142b8e3718b38e58 | train | function | def deser_int_vector(f):
nit = deser_compact_size(f)
r = []
for i in range(nit):
t = struct.unpack("<i", f.read(4))[0]
r.append(t)
return r
| def deser_int_vector(f):
| nit = deser_compact_size(f)
r = []
for i in range(nit):
t = struct.unpack("<i", f.read(4))[0]
r.append(t)
return r
| for i in range(nit):
t = deser_string(f)
r.append(t)
return r
def ser_string_vector(l):
r = ser_compact_size(len(l))
for sv in l:
r += ser_string(sv)
return r
def deser_int_vector(f):
| 64 | 64 | 51 | 6 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | deser_int_vector | deser_int_vector | 189 | 195 | 189 | 189 | 3c988334f2c4e241cf6b69de865a0122cbd290d3 | bigcode/the-stack | train |
5edf9609762e0ddb2d12d7e2 | train | class | class CBlock(CBlockHeader):
def __init__(self, header=None):
super(CBlock, self).__init__(header)
self.vtx = []
def deserialize(self, f):
super(CBlock, self).deserialize(f)
self.vtx = deser_vector(f, CTransaction)
def serialize(self):
r = b""
r += super(CBlo... | class CBlock(CBlockHeader):
| def __init__(self, header=None):
super(CBlock, self).__init__(header)
self.vtx = []
def deserialize(self, f):
super(CBlock, self).deserialize(f)
self.vtx = deser_vector(f, CTransaction)
def serialize(self):
r = b""
r += super(CBlock, self).serialize()
... | hash(r))
self.hash = encode(coinvesthash(r)[::-1], 'hex_codec').decode('ascii')
def rehash(self):
self.sha256 = None
self.calc_sha256()
return self.sha256
def __repr__(self):
return "CBlockHeader(nVersion=%i hashPrevBlock=%064x hashMerkleRoot=%064x nTime=%s nBits=%0... | 137 | 137 | 458 | 7 | 130 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | CBlock | CBlock | 478 | 532 | 478 | 478 | 0d12fb1b6f9568cf26a9cd179c04c77d271baf62 | bigcode/the-stack | train |
8aec6a27b7a26d1439b0dbb5 | train | class | class msg_cmpctblock(object):
command = b"cmpctblock"
def __init__(self, header_and_shortids = None):
self.header_and_shortids = header_and_shortids
def deserialize(self, f):
self.header_and_shortids = P2PHeaderAndShortIDs()
self.header_and_shortids.deserialize(f)
def serializ... | class msg_cmpctblock(object):
| command = b"cmpctblock"
def __init__(self, header_and_shortids = None):
self.header_and_shortids = header_and_shortids
def deserialize(self, f):
self.header_and_shortids = P2PHeaderAndShortIDs()
self.header_and_shortids.deserialize(f)
def serialize(self):
r = b""
... | += struct.pack("<?", self.announce)
r += struct.pack("<Q", self.version)
return r
def __repr__(self):
return "msg_sendcmpct(announce=%s, version=%lu)" % (self.announce, self.version)
class msg_cmpctblock(object):
| 64 | 64 | 127 | 7 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_cmpctblock | msg_cmpctblock | 1,224 | 1,240 | 1,224 | 1,224 | 12135bcd351b2b898bb3b27f361becd890421229 | bigcode/the-stack | train |
42909fde6f47c9f45ed128f4 | train | function | def sha256(s):
return hashlib.new('sha256', s).digest()
| def sha256(s):
| return hashlib.new('sha256', s).digest()
| and whenever adding anything to the send buffer (in send_message()). This
# lock should be acquired in the thread running the test logic to synchronize
# access to any data shared with the NodeConnCB or NodeConn.
mininode_lock = RLock()
# Serialization/deserialization tools
def sha256(s):
| 64 | 64 | 17 | 5 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | sha256 | sha256 | 71 | 72 | 71 | 71 | d856fa315d3189b434c52c9b9666fcbc8c1d528c | bigcode/the-stack | train |
df23402ad93eb9e79ea087ac | train | class | class msg_sendcmpct(object):
command = b"sendcmpct"
def __init__(self):
self.announce = False
self.version = 1
def deserialize(self, f):
self.announce = struct.unpack("<?", f.read(1))[0]
self.version = struct.unpack("<Q", f.read(8))[0]
def serialize(self):
r = ... | class msg_sendcmpct(object):
| command = b"sendcmpct"
def __init__(self):
self.announce = False
self.version = 1
def deserialize(self, f):
self.announce = struct.unpack("<?", f.read(1))[0]
self.version = struct.unpack("<Q", f.read(8))[0]
def serialize(self):
r = b""
r += struct.pack(... |
elapsed = 0
while attempt < attempts and elapsed < timeout:
with mininode_lock:
if predicate():
return True
attempt += 1
elapsed += 0.05
time.sleep(0.05)
return False
class msg_sendcmpct(object):
| 64 | 64 | 147 | 7 | 56 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_sendcmpct | msg_sendcmpct | 1,204 | 1,222 | 1,204 | 1,204 | 35fef64c8b99a300eb6396ca4442cbb8a7ba64bb | bigcode/the-stack | train |
4b769675c2c4f05cbfc71e2d | train | class | class COutPoint(object):
def __init__(self, hash=0, n=0):
self.hash = hash
self.n = n
def deserialize(self, f):
self.hash = deser_uint256(f)
self.n = struct.unpack("<I", f.read(4))[0]
def serialize(self):
r = b""
r += ser_uint256(self.hash)
r += stru... | class COutPoint(object):
| def __init__(self, hash=0, n=0):
self.hash = hash
self.n = n
def deserialize(self, f):
self.hash = deser_uint256(f)
self.n = struct.unpack("<I", f.read(4))[0]
def serialize(self):
r = b""
r += ser_uint256(self.hash)
r += struct.pack("<I", self.n)
... | .pack("<i", self.nVersion)
r += ser_uint256_vector(self.vHave)
return r
def __repr__(self):
return "CBlockLocator(nVersion=%i vHave=%s)" \
% (self.nVersion, repr(self.vHave))
class COutPoint(object):
| 64 | 64 | 129 | 6 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | COutPoint | COutPoint | 288 | 304 | 288 | 288 | 0857a159abee57a55f48664f030878ede005ca78 | bigcode/the-stack | train |
996e8cb8637dc25c7d1e5a45 | train | function | def FromHex(obj, hex_string):
obj.deserialize(BytesIO(hex_str_to_bytes(hex_string)))
return obj
| def FromHex(obj, hex_string):
| obj.deserialize(BytesIO(hex_str_to_bytes(hex_string)))
return obj
| r.append(t)
return r
def ser_int_vector(l):
r = ser_compact_size(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):
| 64 | 64 | 24 | 8 | 56 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | FromHex | FromHex | 205 | 207 | 205 | 205 | f7229e9e7c5e72dacd9979fe2f3c6885ff0a4f40 | bigcode/the-stack | train |
c3870fe1f957139a6c2e5218 | train | class | class CAlert(object):
def __init__(self):
self.vchMsg = b""
self.vchSig = b""
def deserialize(self, f):
self.vchMsg = deser_string(f)
self.vchSig = deser_string(f)
def serialize(self):
r = b""
r += ser_string(self.vchMsg)
r += ser_string(self.vchSig)... | class CAlert(object):
| def __init__(self):
self.vchMsg = b""
self.vchSig = b""
def deserialize(self, f):
self.vchMsg = deser_string(f)
self.vchSig = deser_string(f)
def serialize(self):
r = b""
r += ser_string(self.vchMsg)
r += ser_string(self.vchSig)
return r
... | strReserved %s)" \
% (self.nVersion, self.nRelayUntil, self.nExpiration, self.nID,
self.nCancel, self.nMinVer, self.nMaxVer, self.nPriority,
self.strComment, self.strStatusBar, self.strReserved)
class CAlert(object):
| 64 | 64 | 134 | 5 | 59 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | CAlert | CAlert | 590 | 607 | 590 | 590 | 6503b8397265c70b06c85ef20056349cf9691c19 | bigcode/the-stack | train |
da8329285c67c0c344d6caa5 | train | class | class msg_ping(object):
command = b"ping"
def __init__(self, nonce=0):
self.nonce = nonce
def deserialize(self, f):
self.nonce = struct.unpack("<Q", f.read(8))[0]
def serialize(self):
r = b""
r += struct.pack("<Q", self.nonce)
return r
def __repr__(self):
... | class msg_ping(object):
| command = b"ping"
def __init__(self, nonce=0):
self.nonce = nonce
def deserialize(self, f):
self.nonce = struct.unpack("<Q", f.read(8))[0]
def serialize(self):
r = b""
r += struct.pack("<Q", self.nonce)
return r
def __repr__(self):
return "msg_ping... | (object):
command = b"ping"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_ping() (pre-bip31)"
class msg_ping(object):
| 63 | 64 | 104 | 5 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_ping | msg_ping | 1,042 | 1,057 | 1,042 | 1,042 | 296bf4177812be16e02b3013d37631b23e5e6ae4 | bigcode/the-stack | train |
23b25dac925848851441227b | train | class | class msg_getblocks(object):
command = b"getblocks"
def __init__(self):
self.locator = CBlockLocator()
self.hashstop = 0
def deserialize(self, f):
self.locator = CBlockLocator()
self.locator.deserialize(f)
self.hashstop = deser_uint256(f)
def serialize(self):
... | class msg_getblocks(object):
| command = b"getblocks"
def __init__(self):
self.locator = CBlockLocator()
self.hashstop = 0
def deserialize(self, f):
self.locator = CBlockLocator()
self.locator.deserialize(f)
self.hashstop = deser_uint256(f)
def serialize(self):
r = b""
r += s... | inv != None else []
def deserialize(self, f):
self.inv = deser_vector(f, CInv)
def serialize(self):
return ser_vector(self.inv)
def __repr__(self):
return "msg_getdata(inv=%s)" % (repr(self.inv))
class msg_getblocks(object):
| 64 | 64 | 139 | 6 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_getblocks | msg_getblocks | 940 | 960 | 940 | 940 | 71bee244a65cf8a0e9035db9c4b35c2db2d7a258 | bigcode/the-stack | train |
32a82e5e615ea42935e18d41 | train | class | class msg_headers(object):
command = b"headers"
def __init__(self):
self.headers = []
def deserialize(self, f):
# comment in coinvestd indicates these should be deserialized as blocks
blocks = deser_vector(f, CBlock)
for x in blocks:
self.headers.append(CBlockHe... | class msg_headers(object):
| command = b"headers"
def __init__(self):
self.headers = []
def deserialize(self, f):
# comment in coinvestd indicates these should be deserialized as blocks
blocks = deser_vector(f, CBlock)
for x in blocks:
self.headers.append(CBlockHeader(x))
def serialize... | 256(self.hashstop)
return r
def __repr__(self):
return "msg_getheaders(locator=%s, stop=%064x)" \
% (repr(self.locator), self.hashstop)
# headers message has
# <count> <vector of block headers>
class msg_headers(object):
| 64 | 64 | 119 | 5 | 59 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_headers | msg_headers | 1,138 | 1,155 | 1,138 | 1,138 | 9fa76acbbf29f9d45ceeb58390feed4e726f63e1 | bigcode/the-stack | train |
c1a626afa187521742b8f76c | train | function | def ser_compact_size(l):
r = b""
if l < 253:
r = struct.pack("B", l)
elif l < 0x10000:
r = struct.pack("<BH", 253, l)
elif l < 0x100000000:
r = struct.pack("<BI", 254, l)
else:
r = struct.pack("<BQ", 255, l)
return r
| def ser_compact_size(l):
| r = b""
if l < 253:
r = struct.pack("B", l)
elif l < 0x10000:
r = struct.pack("<BH", 253, l)
elif l < 0x100000000:
r = struct.pack("<BI", 254, l)
else:
r = struct.pack("<BQ", 255, l)
return r
| RLock()
# Serialization/deserialization tools
def sha256(s):
return hashlib.new('sha256', s).digest()
def hash256(s):
return sha256(sha256(s))
def coinvesthash(s):
return coinvest_hash.getPoWHash(s)
def ser_compact_size(l):
| 64 | 64 | 97 | 7 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | ser_compact_size | ser_compact_size | 81 | 91 | 81 | 81 | 0fd42c0eb00457f0aa992da1600c4d7a1b83176d | bigcode/the-stack | train |
e808c53d93126557ae95b13b | train | function | def deser_vector(f, c):
nit = deser_compact_size(f)
r = []
for i in range(nit):
t = c()
t.deserialize(f)
r.append(t)
return r
| def deser_vector(f, c):
| nit = deser_compact_size(f)
r = []
for i in range(nit):
t = c()
t.deserialize(f)
r.append(t)
return r
| 32)
return r
def uint256_from_compact(c):
nbytes = (c >> 24) & 0xFF
v = (c & 0xFFFFFF) << (8 * (nbytes - 3))
return v
def deser_vector(f, c):
| 64 | 64 | 47 | 7 | 56 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | deser_vector | deser_vector | 140 | 147 | 140 | 140 | a51e3e1569ce05487a326e3def5b8bf41332c4b0 | bigcode/the-stack | train |
2cb35c83da576037aae513db | train | function | def uint256_from_compact(c):
nbytes = (c >> 24) & 0xFF
v = (c & 0xFFFFFF) << (8 * (nbytes - 3))
return v
| def uint256_from_compact(c):
| nbytes = (c >> 24) & 0xFF
v = (c & 0xFFFFFF) << (8 * (nbytes - 3))
return v
|
return rs
def uint256_from_str(s):
r = 0
t = struct.unpack("<IIIIIIII", s[:32])
for i in range(8):
r += t[i] << (i * 32)
return r
def uint256_from_compact(c):
| 64 | 64 | 50 | 8 | 55 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | uint256_from_compact | uint256_from_compact | 134 | 137 | 134 | 134 | f3af217c76e8624ca574d08e2feea039f3fea516 | bigcode/the-stack | train |
c53be9507f032a3a35912cd5 | train | class | class msg_alert(object):
command = b"alert"
def __init__(self):
self.alert = CAlert()
def deserialize(self, f):
self.alert = CAlert()
self.alert.deserialize(f)
def serialize(self):
r = b""
r += self.alert.serialize()
return r
def __repr__(self):
... | class msg_alert(object):
| command = b"alert"
def __init__(self):
self.alert = CAlert()
def deserialize(self, f):
self.alert = CAlert()
self.alert.deserialize(f)
def serialize(self):
r = b""
r += self.alert.serialize()
return r
def __repr__(self):
return "msg_alert(a... | rs = []
def deserialize(self, f):
self.addrs = deser_vector(f, CAddress)
def serialize(self):
return ser_vector(self.addrs)
def __repr__(self):
return "msg_addr(addrs=%s)" % (repr(self.addrs))
class msg_alert(object):
| 64 | 64 | 91 | 5 | 59 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_alert | msg_alert | 886 | 902 | 886 | 886 | e07505226b70d9dfa334ffb60543251061d750b8 | bigcode/the-stack | train |
3abbe07551096806f54a673b | train | function | def ser_int_vector(l):
r = ser_compact_size(len(l))
for i in l:
r += struct.pack("<i", i)
return r
| def ser_int_vector(l):
| r = ser_compact_size(len(l))
for i in l:
r += struct.pack("<i", i)
return r
| (sv)
return r
def deser_int_vector(f):
nit = deser_compact_size(f)
r = []
for i in range(nit):
t = struct.unpack("<i", f.read(4))[0]
r.append(t)
return r
def ser_int_vector(l):
| 64 | 64 | 36 | 6 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | ser_int_vector | ser_int_vector | 198 | 202 | 198 | 198 | 7825f251ce497dd074b66c7ad54bb19e501f386b | bigcode/the-stack | train |
03c5fc611b2efc5b1ae3b6af | train | class | class BlockTransactions(object):
def __init__(self, blockhash=0, transactions = None):
self.blockhash = blockhash
self.transactions = transactions if transactions != None else []
def deserialize(self, f):
self.blockhash = deser_uint256(f)
self.transactions = deser_vector(f, CTr... | class BlockTransactions(object):
| def __init__(self, blockhash=0, transactions = None):
self.blockhash = blockhash
self.transactions = transactions if transactions != None else []
def deserialize(self, f):
self.blockhash = deser_uint256(f)
self.transactions = deser_vector(f, CTransaction)
def serialize(self... | es:
absolute_indexes.append(x+last_index+1)
last_index = absolute_indexes[-1]
return absolute_indexes
def __repr__(self):
return "BlockTransactionsRequest(hash=%064x indexes=%s)" % (self.blockhash, repr(self.indexes))
class BlockTransactions(object):
| 64 | 64 | 131 | 5 | 59 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | BlockTransactions | BlockTransactions | 765 | 782 | 765 | 766 | 981fe810472963f1f1f192349bb92648adb39569 | bigcode/the-stack | train |
19c3d7a68c3ac043b2f20fa6 | train | function | def ser_string(s):
return ser_compact_size(len(s)) + s
| def ser_string(s):
| return ser_compact_size(len(s)) + s
| struct.unpack("<I", f.read(4))[0]
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
return nit
def deser_string(f):
nit = deser_compact_size(f)
return f.read(nit)
def ser_string(s):
| 64 | 64 | 17 | 5 | 59 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | ser_string | ser_string | 107 | 108 | 107 | 107 | 5309412d59ce6a2ef284a2e13835aefd25c7ef86 | bigcode/the-stack | train |
151f2faa40881e18c6cf1987 | train | class | class CAddress(object):
def __init__(self):
self.nServices = 1
self.pchReserved = b"\x00" * 10 + b"\xff" * 2
self.ip = "0.0.0.0"
self.port = 0
def deserialize(self, f):
self.nServices = struct.unpack("<Q", f.read(8))[0]
self.pchReserved = f.read(12)
self.... | class CAddress(object):
| def __init__(self):
self.nServices = 1
self.pchReserved = b"\x00" * 10 + b"\xff" * 2
self.ip = "0.0.0.0"
self.port = 0
def deserialize(self, f):
self.nServices = struct.unpack("<Q", f.read(8))[0]
self.pchReserved = f.read(12)
self.ip = socket.inet_ntoa(f.... | (BytesIO(hex_str_to_bytes(hex_string)))
return obj
# Convert a binary-serializable object to hex (eg for submission via RPC)
def ToHex(obj):
return bytes_to_hex_str(obj.serialize())
# Objects that map to coinvestd objects, which can be serialized/deserialized
class CAddress(object):
| 66 | 66 | 221 | 5 | 60 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | CAddress | CAddress | 215 | 238 | 215 | 215 | 0615441a6a5c8b83f4eab9fb658c1a0b79e45a45 | bigcode/the-stack | train |
f3df58128ecd6b13561f90d3 | train | function | def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf')):
attempt = 0
elapsed = 0
while attempt < attempts and elapsed < timeout:
with mininode_lock:
if predicate():
return True
attempt += 1
elapsed += 0.05
time.sleep(0.05)
r... | def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf')):
| attempt = 0
elapsed = 0
while attempt < attempts and elapsed < timeout:
with mininode_lock:
if predicate():
return True
attempt += 1
elapsed += 0.05
time.sleep(0.05)
return False
| return r
def __repr__(self):
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')):
| 64 | 64 | 78 | 16 | 47 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | wait_until | wait_until | 1,190 | 1,202 | 1,190 | 1,190 | 90fbc33405a865b2139472b809b3e19429684fe6 | bigcode/the-stack | train |
f5405aaecfb227ee5cd3c9e5 | train | class | class NodeConn(asyncore.dispatcher):
messagemap = {
b"version": msg_version,
b"verack": msg_verack,
b"addr": msg_addr,
b"alert": msg_alert,
b"inv": msg_inv,
b"getdata": msg_getdata,
b"getblocks": msg_getblocks,
b"tx": msg_tx,
b"block": msg_bloc... | class NodeConn(asyncore.dispatcher):
| messagemap = {
b"version": msg_version,
b"verack": msg_verack,
b"addr": msg_addr,
b"alert": msg_alert,
b"inv": msg_inv,
b"getdata": msg_getdata,
b"getblocks": msg_getblocks,
b"tx": msg_tx,
b"block": msg_block,
b"getaddr": msg_getaddr,
... | functions for NodeConnCB's which have a single NodeConn
class SingleNodeConnCB(NodeConnCB):
def __init__(self):
NodeConnCB.__init__(self)
self.connection = None
self.ping_counter = 1
self.last_pong = msg_pong()
def add_connection(self, conn):
self.connection = conn
... | 256 | 256 | 1,737 | 8 | 247 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | NodeConn | NodeConn | 1,395 | 1,591 | 1,395 | 1,395 | 92f0634a9361237c6cd07d275c95b8dcb95cde70 | bigcode/the-stack | train |
452224ab4614a3905fd54efb | train | class | class msg_block(object):
command = b"block"
def __init__(self, block=None):
if block is None:
self.block = CBlock()
else:
self.block = block
def deserialize(self, f):
self.block.deserialize(f)
def serialize(self):
return self.block.serialize()
... | class msg_block(object):
| command = b"block"
def __init__(self, block=None):
if block is None:
self.block = CBlock()
else:
self.block = block
def deserialize(self, f):
self.block.deserialize(f)
def serialize(self):
return self.block.serialize()
def __repr__(self):
... | __(self, tx=CTransaction()):
self.tx = tx
def deserialize(self, f):
self.tx.deserialize(f)
def serialize(self):
return self.tx.serialize()
def __repr__(self):
return "msg_tx(tx=%s)" % (repr(self.tx))
class msg_block(object):
| 64 | 64 | 90 | 5 | 59 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_block | msg_block | 979 | 995 | 979 | 979 | e47c40a6e860387dc248b6e354b85b8c42d495aa | bigcode/the-stack | train |
2de6418f8944eeda318a3437 | train | class | class msg_inv(object):
command = b"inv"
def __init__(self, inv=None):
if inv is None:
self.inv = []
else:
self.inv = inv
def deserialize(self, f):
self.inv = deser_vector(f, CInv)
def serialize(self):
return ser_vector(self.inv)
def __repr_... | class msg_inv(object):
| command = b"inv"
def __init__(self, inv=None):
if inv is None:
self.inv = []
else:
self.inv = inv
def deserialize(self, f):
self.inv = deser_vector(f, CInv)
def serialize(self):
return ser_vector(self.inv)
def __repr__(self):
return... | ):
self.alert = CAlert()
self.alert.deserialize(f)
def serialize(self):
r = b""
r += self.alert.serialize()
return r
def __repr__(self):
return "msg_alert(alert=%s)" % (repr(self.alert), )
class msg_inv(object):
| 64 | 64 | 94 | 5 | 59 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_inv | msg_inv | 905 | 921 | 905 | 905 | 056b82847a2ed7fe6e9faa4ad1f86c61a85a1ce6 | bigcode/the-stack | train |
e484d18323182f9ac0dfce5d | train | function | def deser_compact_size(f):
nit = struct.unpack("<B", f.read(1))[0]
if nit == 253:
nit = struct.unpack("<H", f.read(2))[0]
elif nit == 254:
nit = struct.unpack("<I", f.read(4))[0]
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
return nit
| def deser_compact_size(f):
| nit = struct.unpack("<B", f.read(1))[0]
if nit == 253:
nit = struct.unpack("<H", f.read(2))[0]
elif nit == 254:
nit = struct.unpack("<I", f.read(4))[0]
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
return nit
| r = struct.pack("<BH", 253, l)
elif l < 0x100000000:
r = struct.pack("<BI", 254, l)
else:
r = struct.pack("<BQ", 255, l)
return r
def deser_compact_size(f):
| 64 | 64 | 92 | 7 | 56 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | deser_compact_size | deser_compact_size | 93 | 101 | 93 | 93 | dedae7345a74cc649c750e8a983214460f73a205 | bigcode/the-stack | train |
847d0cf01afa6e4b2f2d8995 | train | function | def ser_uint256(u):
rs = b""
for i in range(8):
rs += struct.pack("<I", u & 0xFFFFFFFF)
u >>= 32
return rs
| def ser_uint256(u):
| rs = b""
for i in range(8):
rs += struct.pack("<I", u & 0xFFFFFFFF)
u >>= 32
return rs
| act_size(len(s)) + s
def deser_uint256(f):
r = 0
for i in range(8):
t = struct.unpack("<I", f.read(4))[0]
r += t << (i * 32)
return r
def ser_uint256(u):
| 64 | 64 | 45 | 6 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | ser_uint256 | ser_uint256 | 118 | 123 | 118 | 118 | ad9b01fd823e67b41f45a68ee674e9e16b9daaa3 | bigcode/the-stack | train |
376a2d185e49ee0181cdd681 | train | class | class msg_getdata(object):
command = b"getdata"
def __init__(self, inv=None):
self.inv = inv if inv != None else []
def deserialize(self, f):
self.inv = deser_vector(f, CInv)
def serialize(self):
return ser_vector(self.inv)
def __repr__(self):
return "msg_getdata(... | class msg_getdata(object):
| command = b"getdata"
def __init__(self, inv=None):
self.inv = inv if inv != None else []
def deserialize(self, f):
self.inv = deser_vector(f, CInv)
def serialize(self):
return ser_vector(self.inv)
def __repr__(self):
return "msg_getdata(inv=%s)" % (repr(self.inv))... | self.inv = inv
def deserialize(self, f):
self.inv = deser_vector(f, CInv)
def serialize(self):
return ser_vector(self.inv)
def __repr__(self):
return "msg_inv(inv=%s)" % (repr(self.inv))
class msg_getdata(object):
| 64 | 64 | 88 | 6 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_getdata | msg_getdata | 924 | 937 | 924 | 924 | 4fc0ed036f2c406f9d0d193e22fa3e85e7e06f1e | bigcode/the-stack | train |
85c1cb035a322153fbb6bdc6 | train | class | class msg_verack(object):
command = b"verack"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_verack()"
| class msg_verack(object):
| command = b"verack"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_verack()"
| StartingHeight=%i nRelay=%i)' \
% (self.nVersion, self.nServices, time.ctime(self.nTime),
repr(self.addrTo), repr(self.addrFrom), self.nNonce,
self.strSubVer, self.nStartingHeight, self.nRelay)
class msg_verack(object):
| 64 | 64 | 59 | 6 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_verack | msg_verack | 854 | 867 | 854 | 854 | 489d9c25105042d3f36fb92c6f13fd0a7d293503 | bigcode/the-stack | train |
587e3288a48437e3f13b6de4 | train | function | def uint256_from_str(s):
r = 0
t = struct.unpack("<IIIIIIII", s[:32])
for i in range(8):
r += t[i] << (i * 32)
return r
| def uint256_from_str(s):
| r = 0
t = struct.unpack("<IIIIIIII", s[:32])
for i in range(8):
r += t[i] << (i * 32)
return r
| t << (i * 32)
return r
def ser_uint256(u):
rs = b""
for i in range(8):
rs += struct.pack("<I", u & 0xFFFFFFFF)
u >>= 32
return rs
def uint256_from_str(s):
| 64 | 64 | 51 | 7 | 56 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | uint256_from_str | uint256_from_str | 126 | 131 | 126 | 126 | 1542beb9f545ee20bd3180690796d7e47d01324f | bigcode/the-stack | train |
1ce568c08bd5c2ee559b0bb2 | train | class | class msg_sendheaders(object):
command = b"sendheaders"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_sendheaders()"
| class msg_sendheaders(object):
| command = b"sendheaders"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_sendheaders()"
| ool(object):
command = b"mempool"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_mempool()"
class msg_sendheaders(object):
| 64 | 64 | 59 | 6 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_sendheaders | msg_sendheaders | 1,093 | 1,106 | 1,093 | 1,093 | e52278e6b58cd0d3ed7447234d9d416198c9262c | bigcode/the-stack | train |
53b802d550df0838b8c791a7 | train | function | def calculate_shortid(k0, k1, tx_hash):
expected_shortid = siphash256(k0, k1, tx_hash)
expected_shortid &= 0x0000ffffffffffff
return expected_shortid
| def calculate_shortid(k0, k1, tx_hash):
| expected_shortid = siphash256(k0, k1, tx_hash)
expected_shortid &= 0x0000ffffffffffff
return expected_shortid
| (repr(self.header), self.nonce, self.shortids_length, repr(self.shortids), self.prefilled_txn_length, repr(self.prefilled_txn))
# Calculate the BIP 152-compact blocks shortid for a given transaction hash
def calculate_shortid(k0, k1, tx_hash):
| 64 | 64 | 49 | 13 | 50 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | calculate_shortid | calculate_shortid | 666 | 669 | 666 | 666 | dd6d35ee418faf4d18b997b8834e1cf7606bb321 | bigcode/the-stack | train |
324efc779057bf5a3df2ea5b | train | function | def coinvesthash(s):
return coinvest_hash.getPoWHash(s)
| def coinvesthash(s):
| return coinvest_hash.getPoWHash(s)
| access to any data shared with the NodeConnCB or NodeConn.
mininode_lock = RLock()
# Serialization/deserialization tools
def sha256(s):
return hashlib.new('sha256', s).digest()
def hash256(s):
return sha256(sha256(s))
def coinvesthash(s):
| 64 | 64 | 17 | 6 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | coinvesthash | coinvesthash | 78 | 79 | 78 | 78 | b711db0a93ee69b273e77410d88f25919387a4ae | bigcode/the-stack | train |
b162d80c4390cb6a5bb57f5e | train | class | class NodeConnCB(object):
def __init__(self):
self.verack_received = False
# deliver_sleep_time is helpful for debugging race conditions in p2p
# tests; it causes message delivery to sleep for the specified time
# before acquiring the global lock and delivering the next message.
... | class NodeConnCB(object):
| def __init__(self):
self.verack_received = False
# deliver_sleep_time is helpful for debugging race conditions in p2p
# tests; it causes message delivery to sleep for the specified time
# before acquiring the global lock and delivering the next message.
self.deliver_sleep_tim... | def __init__(self):
self.block_txn_request = None
def deserialize(self, f):
self.block_txn_request = BlockTransactionsRequest()
self.block_txn_request.deserialize(f)
def serialize(self):
r = b""
r += self.block_txn_request.serialize()
return r
def __repr__... | 220 | 220 | 736 | 6 | 213 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | NodeConnCB | NodeConnCB | 1,279 | 1,360 | 1,279 | 1,279 | 33d41d75f71d4e14e55ed08b06922ab60012620a | bigcode/the-stack | train |
d447ac96847410291ecb7590 | train | class | class msg_version(object):
command = b"version"
def __init__(self):
self.nVersion = MY_VERSION
self.nServices = 1
self.nTime = int(time.time())
self.addrTo = CAddress()
self.addrFrom = CAddress()
self.nNonce = random.getrandbits(64)
self.strSubVer = MY_SU... | class msg_version(object):
| command = b"version"
def __init__(self):
self.nVersion = MY_VERSION
self.nServices = 1
self.nTime = int(time.time())
self.addrTo = CAddress()
self.addrFrom = CAddress()
self.nNonce = random.getrandbits(64)
self.strSubVer = MY_SUBVERSION
self.nStar... | def __repr__(self):
return "BlockTransactionsRequest(hash=%064x indexes=%s)" % (self.blockhash, repr(self.indexes))
class BlockTransactions(object):
def __init__(self, blockhash=0, transactions = None):
self.blockhash = blockhash
self.transactions = transactions if transactions != Non... | 178 | 178 | 596 | 5 | 172 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_version | msg_version | 786 | 851 | 786 | 786 | 0eed6ab98cbb0a8d9c0d69bb5aeac4a0e04f2750 | bigcode/the-stack | train |
77257ee90c7f725117ae2eb3 | train | class | class PrefilledTransaction(object):
def __init__(self, index=0, tx = None):
self.index = index
self.tx = tx
def deserialize(self, f):
self.index = deser_compact_size(f)
self.tx = CTransaction()
self.tx.deserialize(f)
def serialize(self):
r = b""
r +=... | class PrefilledTransaction(object):
| def __init__(self, index=0, tx = None):
self.index = index
self.tx = tx
def deserialize(self, f):
self.index = deser_compact_size(f)
self.tx = CTransaction()
self.tx.deserialize(f)
def serialize(self):
r = b""
r += ser_compact_size(self.index)
... | Msg)
r += ser_string(self.vchSig)
return r
def __repr__(self):
return "CAlert(vchMsg.sz %d, vchSig.sz %d)" \
% (len(self.vchMsg), len(self.vchSig))
class PrefilledTransaction(object):
| 64 | 64 | 125 | 6 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | PrefilledTransaction | PrefilledTransaction | 610 | 627 | 610 | 610 | 0374b49158f130a3293ba00cbf22a2940a68625b | bigcode/the-stack | train |
d64f79a45194001c2eb4508f | train | class | class CInv(object):
typemap = {
0: "Error",
1: "TX",
2: "Block",
20: "CompactBlock"
}
def __init__(self, t=0, h=0):
self.type = t
self.hash = h
def deserialize(self, f):
self.type = struct.unpack("<i", f.read(4))[0]
self.hash = deser_uint... | class CInv(object):
| typemap = {
0: "Error",
1: "TX",
2: "Block",
20: "CompactBlock"
}
def __init__(self, t=0, h=0):
self.type = t
self.hash = h
def deserialize(self, f):
self.type = struct.unpack("<i", f.read(4))[0]
self.hash = deser_uint256(f)
def seri... | socket.inet_aton(self.ip)
r += struct.pack(">H", self.port)
return r
def __repr__(self):
return "CAddress(nServices=%i ip=%s port=%i)" % (self.nServices,
self.ip, self.port)
class CInv(object):
| 64 | 64 | 168 | 5 | 59 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | CInv | CInv | 241 | 265 | 241 | 241 | 629e2b60bbf4bfbd0cad6d03512e4623541c3fb8 | bigcode/the-stack | train |
20b5585d0508980af3c8b8e6 | train | function | def deser_string(f):
nit = deser_compact_size(f)
return f.read(nit)
| def deser_string(f):
| nit = deser_compact_size(f)
return f.read(nit)
| .unpack("<H", f.read(2))[0]
elif nit == 254:
nit = struct.unpack("<I", f.read(4))[0]
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
return nit
def deser_string(f):
| 64 | 64 | 21 | 5 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | deser_string | deser_string | 103 | 105 | 103 | 103 | 528b93c5ba25eed124ba00dea862cf54614ca9b4 | bigcode/the-stack | train |
a8b559d6e3a23c1c12a49376 | train | class | class CBlockLocator(object):
def __init__(self):
self.nVersion = MY_VERSION
self.vHave = []
def deserialize(self, f):
self.nVersion = struct.unpack("<i", f.read(4))[0]
self.vHave = deser_uint256_vector(f)
def serialize(self):
r = b""
r += struct.pack("<i", s... | class CBlockLocator(object):
| def __init__(self):
self.nVersion = MY_VERSION
self.vHave = []
def deserialize(self, f):
self.nVersion = struct.unpack("<i", f.read(4))[0]
self.vHave = deser_uint256_vector(f)
def serialize(self):
r = b""
r += struct.pack("<i", self.nVersion)
r += se... | "
r += struct.pack("<i", self.type)
r += ser_uint256(self.hash)
return r
def __repr__(self):
return "CInv(type=%s hash=%064x)" \
% (self.typemap[self.type], self.hash)
class CBlockLocator(object):
| 64 | 64 | 135 | 6 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | CBlockLocator | CBlockLocator | 268 | 285 | 268 | 268 | 51950d0779f3ce0f4d104a7d4582cdd41fdff494 | bigcode/the-stack | train |
418582ae8076ada30380983b | train | class | class msg_tx(object):
command = b"tx"
def __init__(self, tx=CTransaction()):
self.tx = tx
def deserialize(self, f):
self.tx.deserialize(f)
def serialize(self):
return self.tx.serialize()
def __repr__(self):
return "msg_tx(tx=%s)" % (repr(self.tx))
| class msg_tx(object):
| command = b"tx"
def __init__(self, tx=CTransaction()):
self.tx = tx
def deserialize(self, f):
self.tx.deserialize(f)
def serialize(self):
return self.tx.serialize()
def __repr__(self):
return "msg_tx(tx=%s)" % (repr(self.tx))
| ""
r += self.locator.serialize()
r += ser_uint256(self.hashstop)
return r
def __repr__(self):
return "msg_getblocks(locator=%s hashstop=%064x)" \
% (repr(self.locator), self.hashstop)
class msg_tx(object):
| 64 | 64 | 75 | 5 | 59 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_tx | msg_tx | 963 | 976 | 963 | 963 | 665cb3a1964bd0338c4df44764bc5c7712f002e1 | bigcode/the-stack | train |
f0276810790c48732bef7628 | train | function | def ser_uint256_vector(l):
r = ser_compact_size(len(l))
for i in l:
r += ser_uint256(i)
return r
| def ser_uint256_vector(l):
| r = ser_compact_size(len(l))
for i in l:
r += ser_uint256(i)
return r
| l:
r += i.serialize()
return r
def deser_uint256_vector(f):
nit = deser_compact_size(f)
r = []
for i in range(nit):
t = deser_uint256(f)
r.append(t)
return r
def ser_uint256_vector(l):
| 64 | 64 | 35 | 7 | 56 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | ser_uint256_vector | ser_uint256_vector | 166 | 170 | 166 | 166 | 452b4dee118cc6918c1199f2539f7636914db813 | bigcode/the-stack | train |
f28a4bdc24c1bb660c9e6a29 | train | function | def ser_string_vector(l):
r = ser_compact_size(len(l))
for sv in l:
r += ser_string(sv)
return r
| def ser_string_vector(l):
| r = ser_compact_size(len(l))
for sv in l:
r += ser_string(sv)
return r
| in l:
r += ser_uint256(i)
return r
def deser_string_vector(f):
nit = deser_compact_size(f)
r = []
for i in range(nit):
t = deser_string(f)
r.append(t)
return r
def ser_string_vector(l):
| 64 | 64 | 34 | 6 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | ser_string_vector | ser_string_vector | 182 | 186 | 182 | 182 | 5a41ca47fb6eef35bdb0a3a44942d40eb03d2033 | bigcode/the-stack | train |
5cef583ae97713663d7c51bb | train | class | class msg_getheaders(object):
command = b"getheaders"
def __init__(self):
self.locator = CBlockLocator()
self.hashstop = 0
def deserialize(self, f):
self.locator = CBlockLocator()
self.locator.deserialize(f)
self.hashstop = deser_uint256(f)
def serialize(self):... | class msg_getheaders(object):
| command = b"getheaders"
def __init__(self):
self.locator = CBlockLocator()
self.hashstop = 0
def deserialize(self, f):
self.locator = CBlockLocator()
self.locator.deserialize(f)
self.hashstop = deser_uint256(f)
def serialize(self):
r = b""
r += ... | (self):
return b""
def __repr__(self):
return "msg_sendheaders()"
# getheaders message has
# 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):
| 64 | 64 | 139 | 6 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_getheaders | msg_getheaders | 1,113 | 1,133 | 1,113 | 1,113 | a41fe290c8e548ff0e88f83ab85c988a111e94f2 | bigcode/the-stack | train |
51183163484be22bf9529f4b | train | class | class SingleNodeConnCB(NodeConnCB):
def __init__(self):
NodeConnCB.__init__(self)
self.connection = None
self.ping_counter = 1
self.last_pong = msg_pong()
def add_connection(self, conn):
self.connection = conn
# Wrapper for the NodeConn's send_message function
d... | class SingleNodeConnCB(NodeConnCB):
| def __init__(self):
NodeConnCB.__init__(self)
self.connection = None
self.ping_counter = 1
self.last_pong = msg_pong()
def add_connection(self, conn):
self.connection = conn
# Wrapper for the NodeConn's send_message function
def send_message(self, message):
... | ctblock(self, conn, message): pass
def on_getblocktxn(self, conn, message): pass
def on_blocktxn(self, conn, message): pass
# More useful callbacks and functions for NodeConnCB's which have a single NodeConn
class SingleNodeConnCB(NodeConnCB):
| 64 | 64 | 211 | 9 | 54 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | SingleNodeConnCB | SingleNodeConnCB | 1,363 | 1,391 | 1,363 | 1,363 | 2c523c0645966a11ce415e028350dae92c17c2a6 | bigcode/the-stack | train |
06e75083b387ccb0731673db | train | function | def deser_uint256(f):
r = 0
for i in range(8):
t = struct.unpack("<I", f.read(4))[0]
r += t << (i * 32)
return r
| def deser_uint256(f):
| r = 0
for i in range(8):
t = struct.unpack("<I", f.read(4))[0]
r += t << (i * 32)
return r
| :
nit = struct.unpack("<Q", f.read(8))[0]
return nit
def deser_string(f):
nit = deser_compact_size(f)
return f.read(nit)
def ser_string(s):
return ser_compact_size(len(s)) + s
def deser_uint256(f):
| 64 | 64 | 50 | 6 | 57 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | deser_uint256 | deser_uint256 | 110 | 115 | 110 | 110 | 29b391a33e2abf0e99e3f8b2a85c2d8a503d57b0 | bigcode/the-stack | train |
7d1648d83a982c1e8dda2daa | train | class | class HeaderAndShortIDs(object):
def __init__(self, p2pheaders_and_shortids = None):
self.header = CBlockHeader()
self.nonce = 0
self.shortids = []
self.prefilled_txn = []
if p2pheaders_and_shortids != None:
self.header = p2pheaders_and_shortids.header
... | class HeaderAndShortIDs(object):
| def __init__(self, p2pheaders_and_shortids = None):
self.header = CBlockHeader()
self.nonce = 0
self.shortids = []
self.prefilled_txn = []
if p2pheaders_and_shortids != None:
self.header = p2pheaders_and_shortids.header
self.nonce = p2pheaders_and_sho... | ShortIDs(header=%s, nonce=%d, shortids_length=%d, shortids=%s, prefilled_txn_length=%d, prefilledtxn=%s" % (repr(self.header), self.nonce, self.shortids_length, repr(self.shortids), self.prefilled_txn_length, repr(self.prefilled_txn))
# Calculate the BIP 152-compact blocks shortid for a given transaction hash
def cal... | 171 | 171 | 571 | 7 | 164 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | HeaderAndShortIDs | HeaderAndShortIDs | 673 | 722 | 673 | 673 | 80b95d15372ff7204186ceaee8b9c7be4a84101f | bigcode/the-stack | train |
20050d2bb2e432224dbe84eb | train | class | class P2PHeaderAndShortIDs(object):
def __init__(self):
self.header = CBlockHeader()
self.nonce = 0
self.shortids_length = 0
self.shortids = []
self.prefilled_txn_length = 0
self.prefilled_txn = []
def deserialize(self, f):
self.header.deserialize(f)
... | class P2PHeaderAndShortIDs(object):
| def __init__(self):
self.header = CBlockHeader()
self.nonce = 0
self.shortids_length = 0
self.shortids = []
self.prefilled_txn_length = 0
self.prefilled_txn = []
def deserialize(self, f):
self.header.deserialize(f)
self.nonce = struct.unpack("<Q",... | f):
self.index = deser_compact_size(f)
self.tx = CTransaction()
self.tx.deserialize(f)
def serialize(self):
r = b""
r += ser_compact_size(self.index)
r += self.tx.serialize()
return r
def __repr__(self):
return "PrefilledTransaction(index=%d, tx... | 114 | 114 | 382 | 10 | 104 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | P2PHeaderAndShortIDs | P2PHeaderAndShortIDs | 630 | 662 | 630 | 630 | c55e37e71ed95967d8c40872eec645118112f12a | bigcode/the-stack | train |
654e67b2605ed05d5b8f7dba | train | class | class msg_blocktxn(object):
command = b"blocktxn"
def __init__(self):
self.block_transactions = BlockTransactions()
def deserialize(self, f):
self.block_transactions.deserialize(f)
def serialize(self):
r = b""
r += self.block_transactions.serialize()
return r
... | class msg_blocktxn(object):
| command = b"blocktxn"
def __init__(self):
self.block_transactions = BlockTransactions()
def deserialize(self, f):
self.block_transactions.deserialize(f)
def serialize(self):
r = b""
r += self.block_transactions.serialize()
return r
def __repr__(self):
... | .deserialize(f)
def serialize(self):
r = b""
r += self.block_txn_request.serialize()
return r
def __repr__(self):
return "msg_getblocktxn(block_txn_request=%s)" % (repr(self.block_txn_request))
class msg_blocktxn(object):
| 64 | 64 | 91 | 6 | 58 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_blocktxn | msg_blocktxn | 1,260 | 1,275 | 1,260 | 1,260 | ad44c7dcea248d50e33cbecec04d838f2cc99be6 | bigcode/the-stack | train |
87fa44ea33e07d8a2eea3259 | train | class | class CUnsignedAlert(object):
def __init__(self):
self.nVersion = 1
self.nRelayUntil = 0
self.nExpiration = 0
self.nID = 0
self.nCancel = 0
self.setCancel = []
self.nMinVer = 0
self.nMaxVer = 0
self.setSubVer = []
self.nPriority = 0
... | class CUnsignedAlert(object):
| def __init__(self):
self.nVersion = 1
self.nRelayUntil = 0
self.nExpiration = 0
self.nID = 0
self.nCancel = 0
self.setCancel = []
self.nMinVer = 0
self.nMaxVer = 0
self.setSubVer = []
self.nPriority = 0
self.strComment = b""
... |
for tx in self.vtx:
if not tx.is_valid():
return False
if self.calc_merkle_root() != self.hashMerkleRoot:
return False
return True
def solve(self):
self.rehash()
target = uint256_from_compact(self.nBits)
while self.sha256 > ta... | 180 | 180 | 602 | 6 | 174 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | CUnsignedAlert | CUnsignedAlert | 535 | 587 | 535 | 535 | b45f9c600c1762ce5fcbb659751b34bd347e0176 | bigcode/the-stack | train |
bb497749e7fcce9351d94d08 | train | class | class msg_mempool(object):
command = b"mempool"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_mempool()"
| class msg_mempool(object):
| command = b"mempool"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_mempool()"
| .read(8))[0]
def serialize(self):
r = b""
r += struct.pack("<Q", self.nonce)
return r
def __repr__(self):
return "msg_pong(nonce=%08x)" % self.nonce
class msg_mempool(object):
| 64 | 64 | 62 | 7 | 56 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_mempool | msg_mempool | 1,078 | 1,091 | 1,078 | 1,078 | f4dedeb44dc21bd3ed77136a46afb893bedc6218 | bigcode/the-stack | train |
a22c971df1a653c436b5157e | train | class | class msg_ping_prebip31(object):
command = b"ping"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_ping() (pre-bip31)"
| class msg_ping_prebip31(object):
| command = b"ping"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_ping() (pre-bip31)"
| (object):
command = b"getaddr"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_getaddr()"
class msg_ping_prebip31(object):
| 64 | 64 | 65 | 9 | 54 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | msg_ping_prebip31 | msg_ping_prebip31 | 1,026 | 1,039 | 1,026 | 1,026 | 5ceef326ca7285989c941417c094df9d206f8e89 | bigcode/the-stack | train |
a7e2d9c76a68a03ec4ea37f6 | train | function | def hash256(s):
return sha256(sha256(s))
| def hash256(s):
| return sha256(sha256(s))
| lock should be acquired in the thread running the test logic to synchronize
# access to any data shared with the NodeConnCB or NodeConn.
mininode_lock = RLock()
# Serialization/deserialization tools
def sha256(s):
return hashlib.new('sha256', s).digest()
def hash256(s):
| 64 | 64 | 14 | 5 | 59 | TGIF-CoinVest/TGIF | qa/rpc-tests/test_framework/mininode.py | Python | hash256 | hash256 | 75 | 76 | 75 | 75 | d53e1d8d5b5d0556060a0efca20f663e01b96916 | bigcode/the-stack | train |
9a49b5e2a9066139170354d2 | train | function | @pytest.mark.parametrize("accel_type", ACCEL_TYPES)
def test_forward_mobilenet_v1(accel_type):
"""Test the Mobilenet V1 TF Lite model."""
np.random.seed(23)
tflite_model_file = tf_testing.get_workload_official(
"https://storage.googleapis.com/download.tensorflow.org/"
"models/mobilenet_v1_20... | @pytest.mark.parametrize("accel_type", ACCEL_TYPES)
def test_forward_mobilenet_v1(accel_type):
| """Test the Mobilenet V1 TF Lite model."""
np.random.seed(23)
tflite_model_file = tf_testing.get_workload_official(
"https://storage.googleapis.com/download.tensorflow.org/"
"models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz",
"mobilenet_v1_1.0_224_quant.tflite",
)
... | import partition_for_ethosu
import tvm.relay.testing.tf as tf_testing
from . import infra
ACCEL_TYPES = ["ethos-u55-256", "ethos-u55-128", "ethos-u55-64", "ethos-u55-32", "ethos-u65-256"]
@pytest.mark.parametrize("accel_type", ACCEL_TYPES)
def test_forward_mobilenet_v1(accel_type):
| 90 | 91 | 306 | 24 | 66 | oneflyingfish/tvm | tests/python/contrib/test_ethosu/test_networks.py | Python | test_forward_mobilenet_v1 | test_forward_mobilenet_v1 | 40 | 65 | 40 | 41 | ed4ecd9e2f1c68151c606a0711e82df8b3c1dd84 | bigcode/the-stack | train |
ebdcc9e75130b3dede40033c | train | class | class SphereMesh(object):
def __init__(self, level=4):
t = (1.0 + np.sqrt(5.0)) / 2.0
self.vertices = np.array(
[
(-1, t, 0),
(1, t, 0),
(-1, -t, 0),
(1, -t, 0),
(0, -1, t),
(0, 1, t),
... | class SphereMesh(object):
| def __init__(self, level=4):
t = (1.0 + np.sqrt(5.0)) / 2.0
self.vertices = np.array(
[
(-1, t, 0),
(1, t, 0),
(-1, -t, 0),
(1, -t, 0),
(0, -1, t),
(0, 1, t),
(0, -1, -t),
... | """Mesh generation.
References:
* http://prideout.net/blog/?p=44
* http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html
"""
import numpy as np
class SphereMesh(object):
| 58 | 201 | 672 | 5 | 52 | ademidun/mordred | mordred/surface_area/_mesh.py | Python | SphereMesh | SphereMesh | 12 | 101 | 12 | 12 | d929350b1ed7109bccd1ce7eef38ac528e311401 | bigcode/the-stack | train |
1af4a095cfdf446546cf16e6 | train | function | def test_query_fail_without_engine():
for engine in ENGINE_DICT.keys():
response = client.get(f"/search/?engine={engine}&query=\"Who am I\"")
assert response.status_code in 200
| def test_query_fail_without_engine():
| for engine in ENGINE_DICT.keys():
response = client.get(f"/search/?engine={engine}&query=\"Who am I\"")
assert response.status_code in 200
| == 200
assert response.json() == {"message": "Hello World"}
def test_query_fail_without_engine():
response = client.get("/search/")
assert response.status_code == 404
assert response.json() == {"detail": "Specified Engine Does not Exist"}
def test_query_fail_without_engine():
| 64 | 64 | 44 | 7 | 57 | bisoncorps/search-engine-api | tests/test_routes.py | Python | test_query_fail_without_engine | test_query_fail_without_engine | 18 | 21 | 18 | 18 | fe6b4dd887f998a07b6d84cb6515e61410470e30 | bigcode/the-stack | train |
9ca2923a41043e7e6c42c259 | train | function | def test_read_main():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Hello World"}
| def test_read_main():
| response = client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Hello World"}
| from starlette.testclient import TestClient
from search_engine_parser.core.engines import ENGINE_DICT
from main import app
client = TestClient(app)
def test_read_main():
| 36 | 64 | 33 | 5 | 31 | bisoncorps/search-engine-api | tests/test_routes.py | Python | test_read_main | test_read_main | 8 | 11 | 8 | 8 | 90a465d920d77cc67352b6cda6715ea7ccaebfa6 | bigcode/the-stack | train |
156a7b6f5610952c6e1aecba | train | function | def test_query_fail_without_engine():
response = client.get("/search/")
assert response.status_code == 404
assert response.json() == {"detail": "Specified Engine Does not Exist"}
| def test_query_fail_without_engine():
| response = client.get("/search/")
assert response.status_code == 404
assert response.json() == {"detail": "Specified Engine Does not Exist"}
| Client
from search_engine_parser.core.engines import ENGINE_DICT
from main import app
client = TestClient(app)
def test_read_main():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Hello World"}
def test_query_fail_without_engine():
| 64 | 64 | 40 | 7 | 57 | bisoncorps/search-engine-api | tests/test_routes.py | Python | test_query_fail_without_engine | test_query_fail_without_engine | 13 | 16 | 13 | 13 | 8a9e064decde615ec352902e01adc6ee995d5e66 | bigcode/the-stack | train |
345a7af4ac5a77e12db28697 | train | function | def init(model_path: pathlib.Path):
"""
Initialization function for the inference executors.
Should only be called from an inference executor.
:param model_path: path to the model that the executors should load.
"""
global model
from tensorflow import keras
model = keras.models.load_m... | def init(model_path: pathlib.Path):
| """
Initialization function for the inference executors.
Should only be called from an inference executor.
:param model_path: path to the model that the executors should load.
"""
global model
from tensorflow import keras
model = keras.models.load_model(model_path)
| import numpy as np
import logging
import time
from pathlib import Path
from concurrent.futures import ProcessPoolExecutor
from dlserver.labels import Labels
# Global storing loaded model
model = None
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
def init(model_path: pathlib.Path):
| 64 | 64 | 68 | 8 | 56 | shenghaoyang/CE4171 | dlserver/executors/iexecutor.py | Python | init | init | 26 | 37 | 26 | 26 | df9e9017af2890057b12ae6d28326840a64ae09a | bigcode/the-stack | train |
11ba3eca3f49b20c8062aae4 | train | function | def warmup(*args, **kwargs):
"""
Warmup function that just sleeps to force initializer execution.
todo: maybe this isn't the best way to do things.
"""
time.sleep(0.1)
| def warmup(*args, **kwargs):
| """
Warmup function that just sleeps to force initializer execution.
todo: maybe this isn't the best way to do things.
"""
time.sleep(0.1)
| ference(get_spectrogram(tensor))
# noinspection PyUnresolvedReferences
# suppressed because init() will set global ``model`` to a loaded model.
label = tf.argmax(model.predict(spect), axis=1)[0]
return Labels(label)
def warmup(*args, **kwargs):
| 64 | 64 | 46 | 9 | 55 | shenghaoyang/CE4171 | dlserver/executors/iexecutor.py | Python | warmup | warmup | 62 | 68 | 62 | 62 | 6b2e83ccc42037197ebe4787959f7a14c793f3bc | bigcode/the-stack | train |
fc01a1c0492358edbb66875d | train | function | def infer(audio_samples: np.ndarray) -> Labels:
"""
Run inference on the audio samples.
Should only be called from an inference executor.
:param audio_samples: samples to use. 1-D NumPy vector of type ``float32``.
:return: inferred label.
"""
global model
import tensorflow as tf
fr... | def infer(audio_samples: np.ndarray) -> Labels:
| """
Run inference on the audio samples.
Should only be called from an inference executor.
:param audio_samples: samples to use. 1-D NumPy vector of type ``float32``.
:return: inferred label.
"""
global model
import tensorflow as tf
from dlserver.preprocess import get_spectrogram, t... | inference executors.
Should only be called from an inference executor.
:param model_path: path to the model that the executors should load.
"""
global model
from tensorflow import keras
model = keras.models.load_model(model_path)
def infer(audio_samples: np.ndarray) -> Labels:
| 64 | 64 | 170 | 11 | 53 | shenghaoyang/CE4171 | dlserver/executors/iexecutor.py | Python | infer | infer | 40 | 59 | 40 | 40 | f2af448f00d24b0125c2c329e2ec6295e04397a6 | bigcode/the-stack | train |
f535e032366440f701769079 | train | class | class Inferer:
def __init__(self, model_path: Path, workers: int = 1, mp_context=None):
"""
Create a new inferrer, that performs inference using a model
by delegating inference work to created subprocesses.
:param model_path: path to the model to use.
:param workers: workers... | class Inferer:
| def __init__(self, model_path: Path, workers: int = 1, mp_context=None):
"""
Create a new inferrer, that performs inference using a model
by delegating inference work to created subprocesses.
:param model_path: path to the model to use.
:param workers: workers to start.
... | model_path: path to the model that the executors should load.
"""
global model
from tensorflow import keras
model = keras.models.load_model(model_path)
def infer(audio_samples: np.ndarray) -> Labels:
"""
Run inference on the audio samples.
Should only be called from an inference executo... | 256 | 256 | 937 | 4 | 252 | shenghaoyang/CE4171 | dlserver/executors/iexecutor.py | Python | Inferer | Inferer | 71 | 211 | 71 | 71 | d7614fb9d869fb8f18ec1ec9284a620989cf7a22 | bigcode/the-stack | train |
e833246b087e0cb4b5cce5d1 | train | class | class FundClassificationBGridStrategy(basestrategy):
'''
重写买入条件和卖出条件,
'''
def __init__(self,startdate=(2011, 1, 1),enddate=[],emafast=12,emaslow=26,demday=9):
self.pre_MA = False
self.curr_MA = False
self.buyprice = 0
self.startingprice = 0
self.buytimes =... | class FundClassificationBGridStrategy(basestrategy):
| '''
重写买入条件和卖出条件,
'''
def __init__(self,startdate=(2011, 1, 1),enddate=[],emafast=12,emaslow=26,demday=9):
self.pre_MA = False
self.curr_MA = False
self.buyprice = 0
self.startingprice = 0
self.buytimes = 0
self.selltimes = 0
super(FundClas... | # -*- coding:utf-8 -*-
from nsnqtlib.strategies.strategy import basestrategy
import pandas as pd
import tushare as ts
class FundClassificationBGridStrategy(basestrategy):
| 43 | 256 | 3,415 | 11 | 31 | harry0519/nsnqt | nsnqtlib/strategies/FundClassificationBGridStrategy.py | Python | FundClassificationBGridStrategy | FundClassificationBGridStrategy | 6 | 373 | 6 | 6 | cefce052f86d80ec8ac12579779d427fa281dbde | bigcode/the-stack | train |
6c000e05ba963cc05223f4c8 | train | function | @route('/wind', method='GET')
@enable_cors
def get_wind_parameters():
data = Weather_Data_Access()
req_data = data.get_wind_parameters()
return json.dumps(req_data)
| @route('/wind', method='GET')
@enable_cors
def get_wind_parameters():
| data = Weather_Data_Access()
req_data = data.get_wind_parameters()
return json.dumps(req_data)
| the actual response
return fn(*args, **kwargs)
return _enable_cors
@route('/', method='GET')
@enable_cors
def index():
return "use routes to get data"
@route('/wind', method='GET')
@enable_cors
def get_wind_parameters():
| 64 | 64 | 45 | 20 | 44 | FrancisDinh/Smart-Energy-Project | application/WeatherService/app.py | Python | get_wind_parameters | get_wind_parameters | 28 | 33 | 28 | 30 | 561032231d513b313cd38091aff185a640a5a63c | bigcode/the-stack | train |
9e1fd8c9bd469b3b91655902 | train | function | def enable_cors(fn):
def _enable_cors(*args, **kwargs):
# set CORS headers
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Ty... | def enable_cors(fn):
| def _enable_cors(*args, **kwargs):
# set CORS headers
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With,... | import json
import bottle
import os
from bottle import route, run, request, abort, response
from datetime import datetime
from DataAccessLayer.Weather_Data_Access import Weather_Data_Access
def enable_cors(fn):
| 48 | 64 | 122 | 6 | 41 | FrancisDinh/Smart-Energy-Project | application/WeatherService/app.py | Python | enable_cors | enable_cors | 10 | 21 | 10 | 10 | d40419d9a06a64495a5111b133471958471520de | bigcode/the-stack | train |
7916c7587a30a2791ff06e15 | train | function | @route('/PV', method='GET')
@enable_cors
def get_pv_parameters():
data = Weather_Data_Access()
req_data = data.get_PV_Parameters()
return json.dumps(req_data)
| @route('/PV', method='GET')
@enable_cors
def get_pv_parameters():
| data = Weather_Data_Access()
req_data = data.get_PV_Parameters()
return json.dumps(req_data)
| ', method='GET')
@enable_cors
def get_wind_forecast_values():
data = Weather_Data_Access()
req_data= data.get_wind_forecast()
return json.dumps(req_data)
@route('/PV', method='GET')
@enable_cors
def get_pv_parameters():
| 64 | 64 | 46 | 20 | 44 | FrancisDinh/Smart-Energy-Project | application/WeatherService/app.py | Python | get_pv_parameters | get_pv_parameters | 43 | 48 | 43 | 45 | f4e3d3e680b30b8344cce82541ead6880265c279 | bigcode/the-stack | train |
86035b6605cb44df07525cba | train | function | @route('/windforecast', method='GET')
@enable_cors
def get_wind_forecast_values():
data = Weather_Data_Access()
req_data= data.get_wind_forecast()
return json.dumps(req_data)
| @route('/windforecast', method='GET')
@enable_cors
def get_wind_forecast_values():
| data = Weather_Data_Access()
req_data= data.get_wind_forecast()
return json.dumps(req_data)
| ', method='GET')
@enable_cors
def get_wind_parameters():
data = Weather_Data_Access()
req_data = data.get_wind_parameters()
return json.dumps(req_data)
@route('/windforecast', method='GET')
@enable_cors
def get_wind_forecast_values():
| 64 | 64 | 49 | 23 | 41 | FrancisDinh/Smart-Energy-Project | application/WeatherService/app.py | Python | get_wind_forecast_values | get_wind_forecast_values | 36 | 41 | 36 | 38 | 1bff80b0bbfc5f9f999ac23a130d4440198fd07c | bigcode/the-stack | train |
32e55fe4576cd42cddf982b6 | train | function | @route('/', method='GET')
@enable_cors
def index():
return "use routes to get data"
| @route('/', method='GET')
@enable_cors
def index():
| return "use routes to get data"
| -Type, X-Requested-With, X-CSRF-Token'
if bottle.request.method != 'OPTIONS':
# actual request; reply with the actual response
return fn(*args, **kwargs)
return _enable_cors
@route('/', method='GET')
@enable_cors
def index():
| 64 | 64 | 24 | 15 | 48 | FrancisDinh/Smart-Energy-Project | application/WeatherService/app.py | Python | index | index | 23 | 26 | 23 | 25 | 9d779d627c8dac24e6fe81a55af87337955a0f9b | bigcode/the-stack | train |
7cf75aa2ab0f2e295c5e3e12 | train | function | @route('/PVforecast', method='GET')
@enable_cors
def get_PV_forecast_values():
data = Weather_Data_Access()
req_data= data.get_PV_forecast()
return json.dumps(req_data)
| @route('/PVforecast', method='GET')
@enable_cors
def get_PV_forecast_values():
| data = Weather_Data_Access()
req_data= data.get_PV_forecast()
return json.dumps(req_data)
| method='GET')
@enable_cors
def get_pv_parameters():
data = Weather_Data_Access()
req_data = data.get_PV_Parameters()
return json.dumps(req_data)
@route('/PVforecast', method='GET')
@enable_cors
def get_PV_forecast_values():
| 64 | 64 | 49 | 23 | 41 | FrancisDinh/Smart-Energy-Project | application/WeatherService/app.py | Python | get_PV_forecast_values | get_PV_forecast_values | 50 | 55 | 50 | 52 | 082b852cb6fd684b9c0ccc36da0222e50a8a2cd2 | bigcode/the-stack | train |
5f1179a0f4bea28fc29320f3 | train | function | def scoped(required: Optional[str] = None,
resource: Optional[Callable] = None,
authorizer: Optional[Callable] = None,
unauthorized: Optional[Callable] = None) -> Callable:
"""
Generate a decorator to enforce authorization requirements.
Parameters
----------
require... | def scoped(required: Optional[str] = None,
resource: Optional[Callable] = None,
authorizer: Optional[Callable] = None,
unauthorized: Optional[Callable] = None) -> Callable:
| """
Generate a decorator to enforce authorization requirements.
Parameters
----------
required : str
The scope required on a user or client session in order use the
decorated route. See :mod:`arxiv.users.auth.scopes`. If not provided,
no scope will be enforced.
resource ... | Global scope (`:*`), e.g. for administrators.
- Resource-specific scope (`:[resource_id]`), i.e. explicitly granted for a
particular resource.
- Generic scope (no resource part).
- If an authorization function was provided, the function is called only if
a required scope was not provided, or if only the gen... | 256 | 256 | 1,172 | 44 | 212 | SamanthaFeidFischer/arxiv-auth | users/arxiv/users/auth/decorators.py | Python | scoped | scoped | 95 | 231 | 95 | 98 | 9cd05859d996d78dcd65b59862c8d425b2566d4b | bigcode/the-stack | train |
813d6541507e31aa12e06799 | train | class | class PrmVisible(Parametre):
"""Commande 'distinctions visible'.
"""
def __init__(self):
"""Constructeur du paramètre"""
Parametre.__init__(self, "visible", "visible")
self.schema = "(<message>)"
self.aide_courte = "manipule la distinction visible"
self... | class PrmVisible(Parametre):
| """Commande 'distinctions visible'.
"""
def __init__(self):
"""Constructeur du paramètre"""
Parametre.__init__(self, "visible", "visible")
self.schema = "(<message>)"
self.aide_courte = "manipule la distinction visible"
self.aide_longue = \
"Cett... | OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
"""Fichier contenant le paramètre 'visible' de la commande 'distinctions'."""
from primaires.interpreteur.masq... | 87 | 87 | 293 | 9 | 77 | stormi/tsunami | src/primaires/joueur/commandes/distinctions/visible.py | Python | PrmVisible | PrmVisible | 35 | 68 | 35 | 36 | be28f56c6e8aa0d52f0a1abcd1edd991532da60a | bigcode/the-stack | train |
b26c2a2eab35188540048b12 | train | function | def test_address_equality() -> None:
assert "Not really an address" != Address("a/b", target_name="c")
assert Address("dir") == Address("dir")
assert Address("dir") == Address("dir", target_name="dir")
assert Address("dir") != Address("another_dir")
assert Address("a/b", target_name="c") == Addres... | def test_address_equality() -> None:
| assert "Not really an address" != Address("a/b", target_name="c")
assert Address("dir") == Address("dir")
assert Address("dir") == Address("dir", target_name="dir")
assert Address("dir") != Address("another_dir")
assert Address("a/b", target_name="c") == Address("a/b", target_name="c")
assert ... | generated_name, though.
assert Address("a/b", relative_file_path="BUILD").spec == "a/b/BUILD"
assert Address("a/b", target_name="BUILD").spec == "a/b:BUILD"
assert Address("a/b", generated_name="BUILD").spec == "a/b#BUILD"
def test_address_equality() -> None:
| 75 | 75 | 250 | 9 | 66 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_equality | test_address_equality | 297 | 316 | 297 | 297 | 2e8be7b19ccda740ec181b489029dd0cbcf22fda | bigcode/the-stack | train |
b4f49c20811ccd9fcf83934a | train | function | def test_address_spec() -> None:
def assert_spec(address: Address, *, expected: str, expected_path_spec: str) -> None:
assert address.spec == expected
assert str(address) == expected
assert address.path_safe_spec == expected_path_spec
assert_spec(Address("a/b"), expected="a/b:b", expect... | def test_address_spec() -> None:
| def assert_spec(address: Address, *, expected: str, expected_path_spec: str) -> None:
assert address.spec == expected
assert str(address) == expected
assert address.path_safe_spec == expected_path_spec
assert_spec(Address("a/b"), expected="a/b:b", expected_path_spec="a.b")
assert_s... | an address" != Address("a/b", target_name="c")
assert Address("dir") == Address("dir")
assert Address("dir") == Address("dir", target_name="dir")
assert Address("dir") != Address("another_dir")
assert Address("a/b", target_name="c") == Address("a/b", target_name="c")
assert Address("a/b", target_... | 244 | 244 | 814 | 8 | 236 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_spec | test_address_spec | 319 | 406 | 319 | 319 | a11fbfe3d7c8b0b9ac721f7f2b2c2027015912cb | bigcode/the-stack | train |
0224a05de8665f359d12eaef | train | function | @pytest.mark.parametrize(
"spec",
["..", ".", "//..", "//.", "a/.", "a/..", "../a", "a/../a", "a/:a", "a/b/:b", "/a", "///a"],
)
def test_address_input_parse_bad_path_component(spec: str) -> None:
with pytest.raises(InvalidSpecPath):
AddressInput.parse(spec)
| @pytest.mark.parametrize(
"spec",
["..", ".", "//..", "//.", "a/.", "a/..", "../a", "a/../a", "a/:a", "a/b/:b", "/a", "///a"],
)
def test_address_input_parse_bad_path_component(spec: str) -> None:
| with pytest.raises(InvalidSpecPath):
AddressInput.parse(spec)
| @pytest.mark.parametrize(
"spec",
["..", ".", "//..", "//.", "a/.", "a/..", "../a", "a/../a", "a/:a", "a/b/:b", "/a", "///a"],
)
def test_address_input_parse_bad_path_component(spec: str) -> None:
| 70 | 64 | 85 | 70 | 0 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_input_parse_bad_path_component | test_address_input_parse_bad_path_component | 107 | 113 | 107 | 111 | 28b785d47f0c672c4a5cded2909d687b39d93341 | bigcode/the-stack | train |
f1289c189591c58c7f66b1ab | train | function | @pytest.mark.parametrize(
"params,expected", (({}, ""), ({"k": "v"}, "@k=v"), ({"k1": "v", "k2": "v"}, "@k1=v,k2=v"))
)
def test_address_parameters_repr(params: dict[str, str], expected: str) -> None:
assert Address("", target_name="foo", parameters=params).parameters_repr == expected
| @pytest.mark.parametrize(
"params,expected", (({}, ""), ({"k": "v"}, "@k=v"), ({"k1": "v", "k2": "v"}, "@k1=v,k2=v"))
)
def test_address_parameters_repr(params: dict[str, str], expected: str) -> None:
| assert Address("", target_name="foo", parameters=params).parameters_repr == expected
| @pytest.mark.parametrize(
"params,expected", (({}, ""), ({"k": "v"}, "@k=v"), ({"k1": "v", "k2": "v"}, "@k1=v,k2=v"))
)
def test_address_parameters_repr(params: dict[str, str], expected: str) -> None:
| 67 | 64 | 84 | 67 | 0 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_parameters_repr | test_address_parameters_repr | 409 | 413 | 409 | 412 | 5ae83a78eb8f50603a9da6a9c988ba1df7c3c565 | bigcode/the-stack | train |
0fe0f8e208282f021026d3c8 | train | function | def test_address_input_from_dir() -> None:
assert AddressInput("a").dir_to_address() == Address("a")
assert AddressInput("a", target_component="b").dir_to_address() == Address("a", target_name="b")
assert AddressInput(
"a", target_component="b", generated_component="gen"
).dir_to_address() == Ad... | def test_address_input_from_dir() -> None:
| assert AddressInput("a").dir_to_address() == Address("a")
assert AddressInput("a", target_component="b").dir_to_address() == Address("a", target_name="b")
assert AddressInput(
"a", target_component="b", generated_component="gen"
).dir_to_address() == Address("a", target_name="b", generated_name=... | (InvalidTargetName):
AddressInput("f.txt").file_to_address()
assert AddressInput("f.txt", target_component="tgt").file_to_address() == Address(
"", relative_file_path="f.txt", target_name="tgt"
)
def test_address_input_from_dir() -> None:
| 64 | 64 | 92 | 10 | 54 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_input_from_dir | test_address_input_from_dir | 268 | 273 | 268 | 268 | 036c22f556b4ebfa7be02de95266e55fb1c17667 | bigcode/the-stack | train |
5395d5bee472c4534ecea07a | train | function | def test_address_validate_build_in_spec_path() -> None:
with pytest.raises(InvalidSpecPath):
Address("a/b/BUILD")
with pytest.raises(InvalidSpecPath):
Address("a/b/BUILD.ext")
with pytest.raises(InvalidSpecPath):
Address("a/b/BUILD", target_name="foo")
# It's fine to use BUILD i... | def test_address_validate_build_in_spec_path() -> None:
| with pytest.raises(InvalidSpecPath):
Address("a/b/BUILD")
with pytest.raises(InvalidSpecPath):
Address("a/b/BUILD.ext")
with pytest.raises(InvalidSpecPath):
Address("a/b/BUILD", target_name="foo")
# It's fine to use BUILD in the relative_file_path, target_name, or generated_name... | Address("a/b/c", target_name=None)
assert Address("a/b/c", target_name="c", relative_file_path="f.txt") == Address(
"a/b/c", target_name=None, relative_file_path="f.txt"
)
def test_address_validate_build_in_spec_path() -> None:
| 64 | 64 | 152 | 12 | 52 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_validate_build_in_spec_path | test_address_validate_build_in_spec_path | 283 | 294 | 283 | 283 | 26492b79a1e8fb5e825da4dcfc601fe99f7bee28 | bigcode/the-stack | train |
62d222c10b16c061c1987169 | train | function | @pytest.mark.parametrize(
"addr,expected",
[
(Address("a/b/c"), AddressInput("a/b/c", target_component="c")),
(Address("a/b/c", target_name="tgt"), AddressInput("a/b/c", "tgt")),
(
Address("a/b/c", target_name="tgt", generated_name="gen"),
AddressInput("a/b/c", "t... | @pytest.mark.parametrize(
"addr,expected",
[
(Address("a/b/c"), AddressInput("a/b/c", target_component="c")),
(Address("a/b/c", target_name="tgt"), AddressInput("a/b/c", "tgt")),
(
Address("a/b/c", target_name="tgt", generated_name="gen"),
AddressInput("a/b/c", "t... | """Check that Address.spec <-> AddressInput.parse() is idempotent."""
assert AddressInput.parse(addr.spec) == expected
| @pytest.mark.parametrize(
"addr,expected",
[
(Address("a/b/c"), AddressInput("a/b/c", target_component="c")),
(Address("a/b/c", target_name="tgt"), AddressInput("a/b/c", "tgt")),
(
Address("a/b/c", target_name="tgt", generated_name="gen"),
AddressInput("a/b/c", "t... | 549 | 173 | 577 | 549 | 0 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_spec_to_address_input | test_address_spec_to_address_input | 459 | 511 | 459 | 509 | b740f28a6fae5d7596bed31503ed14ee3022671b | bigcode/the-stack | train |
097784567570b664b30c33ab | train | function | @pytest.mark.parametrize("spec", ["//:t#gen!", "//:t#gen?", "//:t#gen=", "//:t#gen#"])
def test_address_generated_name(spec: str) -> None:
with pytest.raises(InvalidTargetName):
AddressInput.parse(spec).dir_to_address()
| @pytest.mark.parametrize("spec", ["//:t#gen!", "//:t#gen?", "//:t#gen=", "//:t#gen#"])
def test_address_generated_name(spec: str) -> None:
| with pytest.raises(InvalidTargetName):
AddressInput.parse(spec).dir_to_address()
| None:
with pytest.raises(UnsupportedWildcard):
AddressInput.parse(spec).dir_to_address()
@pytest.mark.parametrize("spec", ["//:t#gen!", "//:t#gen?", "//:t#gen=", "//:t#gen#"])
def test_address_generated_name(spec: str) -> None:
| 64 | 64 | 63 | 44 | 20 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_generated_name | test_address_generated_name | 176 | 179 | 176 | 177 | b4ebc27e3c7c221ed93daffef3de78c42a0b3176 | bigcode/the-stack | train |
7d7cf81249f78f21f96ff44f | train | function | def test_address_normalize_target_name() -> None:
assert Address("a/b/c", target_name="c") == Address("a/b/c", target_name=None)
assert Address("a/b/c", target_name="c", relative_file_path="f.txt") == Address(
"a/b/c", target_name=None, relative_file_path="f.txt"
)
| def test_address_normalize_target_name() -> None:
| assert Address("a/b/c", target_name="c") == Address("a/b/c", target_name=None)
assert Address("a/b/c", target_name="c", relative_file_path="f.txt") == Address(
"a/b/c", target_name=None, relative_file_path="f.txt"
)
| _to_address() == Address("a", target_name="b")
assert AddressInput(
"a", target_component="b", generated_component="gen"
).dir_to_address() == Address("a", target_name="b", generated_name="gen")
def test_address_normalize_target_name() -> None:
| 64 | 64 | 77 | 11 | 53 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_normalize_target_name | test_address_normalize_target_name | 276 | 280 | 276 | 276 | f059f4e87875466819d662e5d666bc9dfb76f9b7 | bigcode/the-stack | train |
387bb9778da5c645d0e8b870 | train | function | def test_address_input_from_file() -> None:
assert AddressInput("a/b/c.txt", target_component=None).file_to_address() == Address(
"a/b", relative_file_path="c.txt"
)
assert AddressInput("a/b/c.txt", target_component="original").file_to_address() == Address(
"a/b", target_name="original", re... | def test_address_input_from_file() -> None:
| assert AddressInput("a/b/c.txt", target_component=None).file_to_address() == Address(
"a/b", relative_file_path="c.txt"
)
assert AddressInput("a/b/c.txt", target_component="original").file_to_address() == Address(
"a/b", target_name="original", relative_file_path="c.txt"
)
assert Ad... | " == ai.path_component
assert ai.target_component is None
ai = parse("src/python/parent:george", "src/python")
assert "src/python/parent" == ai.path_component
assert "george" == ai.target_component
ai = parse(":rel", "src/python/parent")
assert "src/python/parent" == ai.path_component
asse... | 101 | 101 | 337 | 10 | 90 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_input_from_file | test_address_input_from_file | 237 | 265 | 237 | 237 | 594f00ccdf30ed1006c63d5943f441a500434603 | bigcode/the-stack | train |
fbc137742a00f2cb42af77a5 | train | function | @pytest.mark.parametrize(
"spec",
[
"!",
"!a",
"!a:x",
"!a#x",
],
)
def test_address_bad_ignore(spec: str) -> None:
with pytest.raises(UnsupportedIgnore):
AddressInput.parse(spec).dir_to_address()
| @pytest.mark.parametrize(
"spec",
[
"!",
"!a",
"!a:x",
"!a#x",
],
)
def test_address_bad_ignore(spec: str) -> None:
| with pytest.raises(UnsupportedIgnore):
AddressInput.parse(spec).dir_to_address()
| None:
with pytest.raises(InvalidTargetName):
AddressInput.parse(spec).dir_to_address()
@pytest.mark.parametrize(
"spec",
[
"!",
"!a",
"!a:x",
"!a#x",
],
)
def test_address_bad_ignore(spec: str) -> None:
| 64 | 64 | 61 | 43 | 21 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_bad_ignore | test_address_bad_ignore | 147 | 158 | 147 | 156 | 9c341f5583916ad9cd58089abf00c7d18102589e | bigcode/the-stack | train |
f636990c1bbea43d7ecc9c78 | train | function | @pytest.mark.parametrize(
"spec",
[
"a::",
"a:",
"a:b:",
"a:b::",
"a#b:",
],
)
def test_address_bad_wildcard(spec: str) -> None:
with pytest.raises(UnsupportedWildcard):
AddressInput.parse(spec).dir_to_address()
| @pytest.mark.parametrize(
"spec",
[
"a::",
"a:",
"a:b:",
"a:b::",
"a#b:",
],
)
def test_address_bad_wildcard(spec: str) -> None:
| with pytest.raises(UnsupportedWildcard):
AddressInput.parse(spec).dir_to_address()
| ):
AddressInput.parse(spec).dir_to_address()
@pytest.mark.parametrize(
"spec",
[
"a::",
"a:",
"a:b:",
"a:b::",
"a#b:",
],
)
def test_address_bad_wildcard(spec: str) -> None:
| 64 | 64 | 71 | 53 | 11 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_bad_wildcard | test_address_bad_wildcard | 161 | 173 | 161 | 171 | d82e91a2a72971adb218130abb1b03e117d19485 | bigcode/the-stack | train |
d3d688dac1d807de7cf0a2a5 | train | function | def test_address_input_subproject_spec() -> None:
# Ensure that a spec referring to a subproject gets assigned to that subproject properly.
def parse(spec, relative_to):
return AddressInput.parse(
spec,
relative_to=relative_to,
subproject_roots=["subprojectA", "path/t... | def test_address_input_subproject_spec() -> None:
# Ensure that a spec referring to a subproject gets assigned to that subproject properly.
| def parse(spec, relative_to):
return AddressInput.parse(
spec,
relative_to=relative_to,
subproject_roots=["subprojectA", "path/to/subprojectB"],
)
# Ensure that a spec in subprojectA is determined correctly.
ai = parse("src/python/alib", "subprojectA/src/... | dir_to_address()
@pytest.mark.parametrize("spec", ["//:t#gen!", "//:t#gen?", "//:t#gen=", "//:t#gen#"])
def test_address_generated_name(spec: str) -> None:
with pytest.raises(InvalidTargetName):
AddressInput.parse(spec).dir_to_address()
@pytest.mark.parametrize("spec", ["//:t@k=#gen", "//:t@k#gen=v"])
d... | 151 | 151 | 506 | 30 | 121 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_input_subproject_spec | test_address_input_subproject_spec | 188 | 234 | 188 | 189 | 7a599ae0be11d5575662eda15d837ed14cb93139 | bigcode/the-stack | train |
34c2ae695f29da2607392359 | train | function | @pytest.mark.parametrize("spec", ["//:t@k=#gen", "//:t@k#gen=v"])
def test_address_invalid_params(spec: str) -> None:
with pytest.raises(InvalidParameters):
AddressInput.parse(spec).dir_to_address()
| @pytest.mark.parametrize("spec", ["//:t@k=#gen", "//:t@k#gen=v"])
def test_address_invalid_params(spec: str) -> None:
| with pytest.raises(InvalidParameters):
AddressInput.parse(spec).dir_to_address()
| _generated_name(spec: str) -> None:
with pytest.raises(InvalidTargetName):
AddressInput.parse(spec).dir_to_address()
@pytest.mark.parametrize("spec", ["//:t@k=#gen", "//:t@k#gen=v"])
def test_address_invalid_params(spec: str) -> None:
| 64 | 64 | 54 | 36 | 28 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_invalid_params | test_address_invalid_params | 182 | 185 | 182 | 183 | 210cb867f59efb18d84d3fce0209a279ca1e14c9 | bigcode/the-stack | train |
2400b0f237ec5a49091ad9c5 | train | function | @pytest.mark.parametrize(
"spec,expected",
[
("a@t=,y", "one or more key=value pairs"),
("a#", "non-empty generated target name"),
],
)
def test_address_input_parse(spec: str, expected: str) -> None:
with pytest.raises(AddressParseException) as e:
AddressInput.parse(spec)
ass... | @pytest.mark.parametrize(
"spec,expected",
[
("a@t=,y", "one or more key=value pairs"),
("a#", "non-empty generated target name"),
],
)
def test_address_input_parse(spec: str, expected: str) -> None:
| with pytest.raises(AddressParseException) as e:
AddressInput.parse(spec)
assert expected in str(e.value)
| AddressInput.parse(spec)
@pytest.mark.parametrize(
"spec,expected",
[
("a@t=,y", "one or more key=value pairs"),
("a#", "non-empty generated target name"),
],
)
def test_address_input_parse(spec: str, expected: str) -> None:
| 64 | 64 | 84 | 59 | 5 | wonlay/pants | src/python/pants/build_graph/address_test.py | Python | test_address_input_parse | test_address_input_parse | 116 | 126 | 116 | 123 | 15273f745a3b3359642d7703abaf264aed0b65e2 | bigcode/the-stack | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.