From a046bbeb313827001c718c6919c47b4af4cd6895 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Thu, 24 Oct 2024 04:08:49 +0300 Subject: [PATCH] Addressed pylint too-many-positional-arguments in structure.Object --- minode/manager.py | 4 ++-- minode/proofofwork.py | 4 ++-- minode/structure.py | 9 +++++---- minode/tests/test_structure.py | 14 +++++++------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/minode/manager.py b/minode/manager.py index 612fcc1..1650652 100644 --- a/minode/manager.py +++ b/minode/manager.py @@ -272,7 +272,7 @@ class Manager(threading.Thread): dest_pub_raw = base64.b64decode( shared.i2p_dest_pub, altchars=b'-~') obj = structure.Object( - b'\x00' * 8, int(time.time() + 2 * 3600), + int(time.time() + 2 * 3600), shared.i2p_dest_obj_type, shared.i2p_dest_obj_version, - shared.stream, dest_pub_raw) + shared.stream, object_payload=dest_pub_raw) proofofwork.do_pow_and_publish(obj) diff --git a/minode/proofofwork.py b/minode/proofofwork.py index f8aa69f..c1e99dd 100644 --- a/minode/proofofwork.py +++ b/minode/proofofwork.py @@ -39,8 +39,8 @@ def _worker(obj): logging.debug( 'Finished doing POW, nonce: %s, time: %ss', nonce, time.time() - t) obj = structure.Object( - nonce, obj.expires_time, obj.object_type, obj.version, - obj.stream_number, obj.object_payload) + obj.expires_time, obj.object_type, obj.version, obj.stream_number, + object_payload=obj.object_payload, nonce=nonce) logging.debug( 'Object vector is %s', base64.b16encode(obj.vector).decode()) diff --git a/minode/structure.py b/minode/structure.py index 405da1a..a9d3c09 100644 --- a/minode/structure.py +++ b/minode/structure.py @@ -48,8 +48,8 @@ class VarInt(): class Object(): """The 'object' message payload""" def __init__( - self, nonce, expires_time, object_type, version, - stream_number, object_payload + self, expires_time, object_type, version, stream_number, + *, object_payload, tag=None, nonce=b'\x00' * 8 ): self.nonce = nonce self.expires_time = expires_time @@ -60,7 +60,7 @@ class Object(): self.vector = hashlib.sha512(hashlib.sha512( self.to_bytes()).digest()).digest()[:32] - self.tag = ( + self.tag = tag or ( # broadcast from version 5 and pubkey/getpukey from version 4 self.object_payload[:32] if object_type == 3 and version == 5 or (object_type in (0, 1) and version == 4) @@ -84,7 +84,8 @@ class Object(): payload[:stream_number_varint_length]).n payload = payload[stream_number_varint_length:] return cls( - nonce, expires_time, object_type, version, stream_number, payload) + expires_time, object_type, version, stream_number, + object_payload=payload, nonce=nonce) def to_bytes(self): """Serialize to bytes""" diff --git a/minode/tests/test_structure.py b/minode/tests/test_structure.py index 970c152..f003655 100644 --- a/minode/tests/test_structure.py +++ b/minode/tests/test_structure.py @@ -19,7 +19,7 @@ sample_addr_data = unhexlify( # data for an object with expires_time 1697063939 # structure.Object( -# b'\x00' * 8, expires_time, 42, 1, 2, b'HELLO').to_bytes() +# expires_time, 42, 1, 2, object_payload=b'HELLO').to_bytes() sample_object_data = unhexlify( '000000000000000000000000652724030000002a010248454c4c4f') @@ -135,13 +135,13 @@ class TestStructure(unittest.TestCase): self.assertEqual(obj.object_payload, b'HELLO') obj = structure.Object( - b'\x00' * 8, int(time.time() + 3000000), 42, 1, 1, b'HELLO') + int(time.time() + 3000000), 42, 1, 1, object_payload=b'HELLO') self.assertFalse(obj.is_valid()) obj.expires_time = int(time.time() - 11000) self.assertFalse(obj.is_valid()) obj = structure.Object( - b'\x00' * 8, int(time.time() + 300), 42, 1, 2, b'HELLO') + int(time.time() + 300), 42, 1, 2, object_payload=b'HELLO') vector = obj.vector proofofwork._worker(obj) # pylint: disable=protected-access obj = shared.objects.popitem()[1] @@ -159,8 +159,8 @@ class TestStructure(unittest.TestCase): """Check the main proofofwork call and worker""" shared.vector_advertise_queue = queue.Queue() obj = structure.Object( - b'\x00' * 8, int(time.time() + 300), 42, 1, - shared.stream, b'HELLO') + int(time.time() + 300), 42, 1, + shared.stream, object_payload=b'HELLO') start_time = time.time() proofofwork.do_pow_and_publish(obj) try: @@ -189,6 +189,6 @@ class TestStructure(unittest.TestCase): self.fail("No nonce found in the queue") obj = structure.Object( - nonce, obj.expires_time, obj.object_type, obj.version, - obj.stream_number, obj.object_payload) + obj.expires_time, obj.object_type, obj.version, obj.stream_number, + object_payload=obj.object_payload, nonce=nonce) self.assertTrue(obj.is_valid())