pyhton3 port

This commit is contained in:
cis-kuldeep 2021-06-08 23:20:56 +05:30
parent 16a11775e8
commit 5c4817d7dc
No known key found for this signature in database
GPG Key ID: 67B47D8A06FA45E4
4 changed files with 61 additions and 23 deletions

View File

@ -10,8 +10,8 @@ from datetime import datetime
from six import string_types from six import string_types
from six.moves import configparser from six.moves import configparser
import state from pybitmessage import state
from singleton import Singleton from pybitmessage.singleton import Singleton
SafeConfigParser = configparser.SafeConfigParser SafeConfigParser = configparser.SafeConfigParser

View File

@ -9,10 +9,10 @@ High level cryptographic functions based on `.pyelliptic` OpenSSL bindings.
from binascii import hexlify from binascii import hexlify
import pyelliptic from pybitmessage import pyelliptic
from bmconfigparser import BMConfigParser from pybitmessage.bmconfigparser import BMConfigParser
from pyelliptic import OpenSSL from pybitmessage.pyelliptic import OpenSSL
from pyelliptic import arithmetic as a from pybitmessage.pyelliptic import arithmetic as a
def makeCryptor(privkey): def makeCryptor(privkey):

View File

@ -13,16 +13,46 @@ import time
from binascii import hexlify from binascii import hexlify
from struct import Struct, pack, unpack from struct import Struct, pack, unpack
import defaults try:
import highlevelcrypto import defaults
import state except ImportError:
from addresses import ( 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) encodeVarint, decodeVarint, decodeAddress, varintDecodeError)
from bmconfigparser import BMConfigParser except ImportError:
from debug import logger from .addresses import (
from fallback import RIPEMD160Hash encodeVarint, decodeVarint, decodeAddress, varintDecodeError)
from helper_sql import sqlExecute try:
from version import softwareVersion 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 # Service flags
#: This is a normal network node #: This is a normal network node
@ -100,6 +130,10 @@ def encodeHost(host):
return '\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode( return '\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode(
host.split(".")[0], True) host.split(".")[0], True)
elif host.find(':') == -1: elif host.find(':') == -1:
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' + \ return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \
socket.inet_aton(host) socket.inet_aton(host)
return socket.inet_pton(socket.AF_INET6, host) return socket.inet_pton(socket.AF_INET6, host)
@ -121,10 +155,12 @@ def network_group(host):
if not isinstance(host, str): if not isinstance(host, str):
return None return None
network_type = networkType(host) network_type = networkType(host)
# import pdb; pdb.set_trace()
try: try:
raw_host = encodeHost(host) raw_host = encodeHost(host)
except socket.error: except socket.error:
return host return host
if network_type == 'IPv4': if network_type == 'IPv4':
decoded_host = checkIPv4Address(raw_host[12:], True) decoded_host = checkIPv4Address(raw_host[12:], True)
if decoded_host: if decoded_host:

View File

@ -2,10 +2,7 @@
Test for network group Test for network group
""" """
import unittest import unittest
import sys
from .common import skip_python3
skip_python3()
class TestNetworkGroup(unittest.TestCase): class TestNetworkGroup(unittest.TestCase):
@ -17,6 +14,11 @@ class TestNetworkGroup(unittest.TestCase):
from pybitmessage.protocol import network_group from pybitmessage.protocol import network_group
test_ip = '1.2.3.4' test_ip = '1.2.3.4'
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)) self.assertEqual('\x01\x02', network_group(test_ip))
test_ip = '127.0.0.1' test_ip = '127.0.0.1'