From cc367f7c04878b3ee869b775e53ee1074c643c10 Mon Sep 17 00:00:00 2001 From: Muzahid Date: Tue, 18 May 2021 21:27:45 +0530 Subject: [PATCH] py3 porting started on remaining test cases --- src/bmconfigparser.py | 11 ++++-- src/highlevelcrypto.py | 23 ++++++++++--- src/protocol.py | 58 +++++++++++++++++++++++++------- src/tests/test_blindsig.py | 4 +-- src/tests/test_config_process.py | 3 -- src/tests/test_networkgroup.py | 11 ++++-- src/tests/test_process.py | 7 +--- 7 files changed, 85 insertions(+), 32 deletions(-) diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index 1f5d4fce..eb7010c3 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -10,8 +10,15 @@ from datetime import datetime from six import string_types from six.moves import configparser -import state -from singleton import Singleton +try: + import state +except ImportError: + from . import state + +try: + from singleton import Singleton +except ImportError: + from .singleton import Singleton SafeConfigParser = configparser.SafeConfigParser diff --git a/src/highlevelcrypto.py b/src/highlevelcrypto.py index f89a31c8..6f0f2e28 100644 --- a/src/highlevelcrypto.py +++ b/src/highlevelcrypto.py @@ -9,10 +9,25 @@ High level cryptographic functions based on `.pyelliptic` OpenSSL bindings. from binascii import hexlify -import pyelliptic -from bmconfigparser import BMConfigParser -from pyelliptic import OpenSSL -from pyelliptic import arithmetic as a +try: + import pyelliptic +except ImportError: + from . import pyelliptic + +try: + from bmconfigparser import BMConfigParser +except ImportError: + from .bmconfigparser import BMConfigParser + +try: + from pyelliptic import OpenSSL +except ImportError: + from .pyelliptic import OpenSSL + +try: + from pyelliptic import arithmetic as a +except ImportError: + from .pyelliptic import arithmetic as a def makeCryptor(privkey): diff --git a/src/protocol.py b/src/protocol.py index 4f2d0856..5f5609b5 100644 --- a/src/protocol.py +++ b/src/protocol.py @@ -13,16 +13,46 @@ import time from binascii import hexlify from struct import Struct, pack, unpack -import defaults -import highlevelcrypto -import state -from addresses import ( - encodeVarint, decodeVarint, decodeAddress, varintDecodeError) -from bmconfigparser import BMConfigParser -from debug import logger -from fallback import RIPEMD160Hash -from helper_sql import sqlExecute -from version import softwareVersion +try: + import defaults +except ImportError: + from . import defaults +try: + import highlevelcrypto +except ImportError: + from . import highlevelcrypto + +try: + import state +except ImportError: + from . import state + +try: + from addresses import ( + encodeVarint, decodeVarint, decodeAddress, varintDecodeError) +except ImportError: + from .addresses import ( + encodeVarint, decodeVarint, decodeAddress, varintDecodeError) +try: + from bmconfigparser import BMConfigParser +except ImportError: + from .bmconfigparser import BMConfigParser +try: + from debug import logger +except ImportError: + from .debug import logger +try: + from fallback import RIPEMD160Hash +except ImportError: + from .fallback import RIPEMD160Hash +try: + from .helper_sql import sqlExecute +except ImportError: + from .helper_sql import sqlExecute +try: + from version import softwareVersion +except ImportError: + from .version import softwareVersion # Service flags #: This is a normal network node @@ -100,8 +130,12 @@ def encodeHost(host): return '\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode( host.split(".")[0], True) elif host.find(':') == -1: - return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \ - socket.inet_aton(host) + if sys.version_info[0] == 3: + return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \ + str(socket.inet_aton(host)) + else: + return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \ + socket.inet_aton(host) return socket.inet_pton(socket.AF_INET6, host) diff --git a/src/tests/test_blindsig.py b/src/tests/test_blindsig.py index 76902347..955c6d9c 100644 --- a/src/tests/test_blindsig.py +++ b/src/tests/test_blindsig.py @@ -4,9 +4,9 @@ Test for ECC blind signatures import os import unittest from hashlib import sha256 -from .common import skip_python3 +# from .common import skip_python3 -skip_python3() +# skip_python3() from pybitmessage.pyelliptic import ECCBlind, ECCBlindChain, OpenSSL diff --git a/src/tests/test_config_process.py b/src/tests/test_config_process.py index 0a612759..f3cf19f2 100644 --- a/src/tests/test_config_process.py +++ b/src/tests/test_config_process.py @@ -6,9 +6,6 @@ import os import tempfile from pybitmessage.bmconfigparser import BMConfigParser from .test_process import TestProcessProto -from .common import skip_python3 - -skip_python3() class TestProcessConfig(TestProcessProto): diff --git a/src/tests/test_networkgroup.py b/src/tests/test_networkgroup.py index 79163402..28599b2e 100644 --- a/src/tests/test_networkgroup.py +++ b/src/tests/test_networkgroup.py @@ -3,9 +3,9 @@ Test for network group """ import unittest -from .common import skip_python3 +# from .common import skip_python3 -skip_python3() +# skip_python3() class TestNetworkGroup(unittest.TestCase): @@ -17,7 +17,12 @@ class TestNetworkGroup(unittest.TestCase): from pybitmessage.protocol import network_group test_ip = '1.2.3.4' - self.assertEqual('\x01\x02', network_group(test_ip)) + print("network_group(test_ip)") + print(network_group(test_ip)) + if isinstance(network_group(test_ip), bytes): + self.assertEqual('\x01\x02', network_group(test_ip).decode('utf-8')) + else: + self.assertEqual('\x01\x02', network_group(test_ip)) test_ip = '127.0.0.1' self.assertEqual('IPv4', network_group(test_ip)) diff --git a/src/tests/test_process.py b/src/tests/test_process.py index d976aa18..901d2ecc 100644 --- a/src/tests/test_process.py +++ b/src/tests/test_process.py @@ -9,13 +9,8 @@ import sys import tempfile import time import unittest - import psutil - -from .common import cleanup, put_signal_file, skip_python3 - - -skip_python3() +from .common import cleanup, put_signal_file class TestProcessProto(unittest.TestCase):