diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index 1f5d4fce..c969d8fb 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -10,8 +10,8 @@ from datetime import datetime from six import string_types from six.moves import configparser -import state -from singleton import Singleton +from pybitmessage import state +from pybitmessage.singleton import Singleton SafeConfigParser = configparser.SafeConfigParser diff --git a/src/highlevelcrypto.py b/src/highlevelcrypto.py index f89a31c8..7bb9f67c 100644 --- a/src/highlevelcrypto.py +++ b/src/highlevelcrypto.py @@ -9,10 +9,10 @@ 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 +from pybitmessage import pyelliptic +from pybitmessage.bmconfigparser import BMConfigParser +from pybitmessage.pyelliptic import OpenSSL +from pybitmessage.pyelliptic import arithmetic as a def makeCryptor(privkey): diff --git a/src/protocol.py b/src/protocol.py index 4f2d0856..0e44d734 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) @@ -121,10 +155,12 @@ def network_group(host): if not isinstance(host, str): return None network_type = networkType(host) + # import pdb; pdb.set_trace() try: raw_host = encodeHost(host) except socket.error: return host + if network_type == 'IPv4': decoded_host = checkIPv4Address(raw_host[12:], True) if decoded_host: diff --git a/src/tests/test_networkgroup.py b/src/tests/test_networkgroup.py index 79163402..ad30a690 100644 --- a/src/tests/test_networkgroup.py +++ b/src/tests/test_networkgroup.py @@ -2,10 +2,7 @@ Test for network group """ import unittest - -from .common import skip_python3 - -skip_python3() +import sys class TestNetworkGroup(unittest.TestCase): @@ -17,7 +14,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 sys.version_info[0] == 3: + self.assertEqual('\x01\x02', network_group(test_ip)) + else: + self.assertEqual('\x01\x02', network_group(test_ip)) test_ip = '127.0.0.1' self.assertEqual('IPv4', network_group(test_ip))