py3 porting started on remaining test cases

This commit is contained in:
Muzahid 2021-05-18 21:27:45 +05:30
parent 73c7a09cb9
commit cc367f7c04
Signed by untrusted user: cis-muzahid
GPG Key ID: 1DC85E7D3AB613EA
7 changed files with 85 additions and 32 deletions

View File

@ -10,8 +10,15 @@ 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 try:
from singleton import Singleton import state
except ImportError:
from . import state
try:
from singleton import Singleton
except ImportError:
from .singleton import Singleton
SafeConfigParser = configparser.SafeConfigParser SafeConfigParser = configparser.SafeConfigParser

View File

@ -9,10 +9,25 @@ High level cryptographic functions based on `.pyelliptic` OpenSSL bindings.
from binascii import hexlify from binascii import hexlify
import pyelliptic try:
from bmconfigparser import BMConfigParser import pyelliptic
from pyelliptic import OpenSSL except ImportError:
from pyelliptic import arithmetic as a 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): 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)

View File

@ -4,9 +4,9 @@ Test for ECC blind signatures
import os import os
import unittest import unittest
from hashlib import sha256 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 from pybitmessage.pyelliptic import ECCBlind, ECCBlindChain, OpenSSL

View File

@ -6,9 +6,6 @@ import os
import tempfile import tempfile
from pybitmessage.bmconfigparser import BMConfigParser from pybitmessage.bmconfigparser import BMConfigParser
from .test_process import TestProcessProto from .test_process import TestProcessProto
from .common import skip_python3
skip_python3()
class TestProcessConfig(TestProcessProto): class TestProcessConfig(TestProcessProto):

View File

@ -3,9 +3,9 @@ Test for network group
""" """
import unittest import unittest
from .common import skip_python3 # from .common import skip_python3
skip_python3() # skip_python3()
class TestNetworkGroup(unittest.TestCase): class TestNetworkGroup(unittest.TestCase):
@ -17,6 +17,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 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)) self.assertEqual('\x01\x02', network_group(test_ip))
test_ip = '127.0.0.1' test_ip = '127.0.0.1'

View File

@ -9,13 +9,8 @@ import sys
import tempfile import tempfile
import time import time
import unittest import unittest
import psutil import psutil
from .common import cleanup, put_signal_file
from .common import cleanup, put_signal_file, skip_python3
skip_python3()
class TestProcessProto(unittest.TestCase): class TestProcessProto(unittest.TestCase):