pyhton3 port
This commit is contained in:
parent
16a11775e8
commit
5c4817d7dc
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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))
|
||||
|
|
Reference in New Issue
Block a user