diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index 7e82ae89..8c7abae6 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -14,8 +14,8 @@ try: import state from singleton import Singleton except ImportError: - from pybitmessage import state - from pybitmessage.singleton import Singleton + from . import state + from .singleton import Singleton SafeConfigParser = configparser.SafeConfigParser diff --git a/src/highlevelcrypto.py b/src/highlevelcrypto.py index f89a31c8..995c5d00 100644 --- a/src/highlevelcrypto.py +++ b/src/highlevelcrypto.py @@ -9,10 +9,16 @@ 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 + from bmconfigparser import BMConfigParser + from pyelliptic import OpenSSL + from pyelliptic import arithmetic as a +except ImportError: + from . import pyelliptic + from .bmconfigparser import BMConfigParser + from .pyelliptic import OpenSSL + from .pyelliptic import arithmetic as a def makeCryptor(privkey): diff --git a/src/protocol.py b/src/protocol.py index 4f2d0856..e6200745 100644 --- a/src/protocol.py +++ b/src/protocol.py @@ -13,16 +13,30 @@ 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 + 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 +except ImportError: + from . import defaults + from . import highlevelcrypto + from . 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 + +PY3 = sys.version_info[0] >= 3 # Service flags #: This is a normal network node @@ -100,8 +114,13 @@ 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) + import pdb; pdb.set_trace() + if PY3: + return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \ + socket.inet_aton(host).decode('utf-8') + 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) @@ -210,7 +229,7 @@ def checkIPv6Address(host, hostStandardFormat, private=False): if not private: logger.debug('Ignoring local address: %s', hostStandardFormat) return hostStandardFormat if private else False - if (ord(host[0]) & 0xfe) == 0xfc: + if (ord(str(host[0])) & 0xfe) == 0xfc: if not private: logger.debug( 'Ignoring unique local address: %s', hostStandardFormat) diff --git a/src/tests/test_protocol.py b/src/tests/test_protocol.py index a3c73a73..e5cb3b3a 100644 --- a/src/tests/test_protocol.py +++ b/src/tests/test_protocol.py @@ -4,10 +4,6 @@ Tests for common protocol functions import unittest -from .common import skip_python3 - -skip_python3() - class TestProtocol(unittest.TestCase): """Main protocol test case""" @@ -15,11 +11,12 @@ class TestProtocol(unittest.TestCase): def test_check_local(self): """Check the logic of TCPConnection.local""" from pybitmessage import protocol, state + # import pdb; pdb.set_trace() self.assertTrue( - protocol.checkIPAddress(protocol.encodeHost('127.0.0.1'), True)) + protocol.checkIPAddress(protocol.encodeHost('127.0.0.1').decode('ISO-8859-1'), True)) self.assertTrue( - protocol.checkIPAddress(protocol.encodeHost('192.168.0.1'), True)) + protocol.checkIPAddress(protocol.encodeHost('192.168.0.1').decode('ISO-8859-1'), True)) self.assertTrue( not protocol.checkSocksIP('127.0.0.1')