Runnable with both Python3 and Python2, with PyQt4 #2249

Open
kashikoibumi wants to merge 59 commits from kashikoibumi/py3 into v0.6
12 changed files with 27 additions and 21 deletions
Showing only changes of commit f37a973f5f - Show all commits

View File

@ -4,6 +4,7 @@ import os
import platform
import shutil
import sys
import six
from importlib import import_module
from setuptools import setup, Extension
@ -83,7 +84,7 @@ if __name__ == "__main__":
'images/kivy/text_images*.png'
]}
if sys.version_info[0] == 3:
if six.PY3:
packages.extend(
[
'pybitmessage.bitmessagekivy',

View File

@ -6,6 +6,7 @@ and suggest how it may be installed
import os
import re
import sys
import six
# Only really old versions of Python don't have sys.hexversion. We don't
# support them. The logging module was introduced in Python 2.3
@ -438,7 +439,7 @@ def check_dependencies(verbose=False, optional=False):
'PyBitmessage requires Python 2.7.4 or greater'
' (but not Python 3+)')
has_all_dependencies = False
if sys.hexversion >= 0x3000000:
if six.PY3:
logger.error(
'PyBitmessage does not support Python 3+. Python 2.7.4'
' or greater is required. Python 2.7.18 is recommended.')

View File

@ -53,6 +53,7 @@ import collections
import io
import struct
import sys
import six
__version__ = "2.4.1"
"Module version string"
@ -99,9 +100,9 @@ class Ext: # pylint: disable=old-style-class
if not isinstance(type, int) or not (type >= 0 and type <= 127):
raise TypeError("ext type out of range")
# Check data is type bytes
elif sys.version_info[0] == 3 and not isinstance(data, bytes):
elif six.PY3 and not isinstance(data, bytes):
raise TypeError("ext data is not type \'bytes\'")
elif sys.version_info[0] == 2 and not isinstance(data, str):
elif six.PY2 and not isinstance(data, str):
raise TypeError("ext data is not type \'str\'")
self.type = type
self.data = data
@ -990,7 +991,7 @@ def __init():
_float_precision = "single"
# Map packb and unpackb to the appropriate version
if sys.version_info[0] == 3:
if six.PY3:
pack = _pack3
packb = _packb3
dump = _pack3

View File

@ -3,8 +3,8 @@
import logging
import os
import re
import sys
import time
import six
from six.moves import range
@ -61,7 +61,7 @@ if not re.search(r'\d', time.strftime(time_format)):
# It seems some systems lie about the encoding they use
# so we perform comprehensive decoding tests
elif sys.version_info[0] == 2:
elif six.PY2:
try:
# Check day names
for i in range(7):
@ -118,7 +118,7 @@ def formatTimestamp(timestamp=None):
except ValueError:
timestring = time.strftime(time_format)
if sys.version_info[0] == 2:
if six.PY2:
return timestring.decode(encoding)
return timestring

View File

@ -8,6 +8,7 @@ needed openssl functionality in class _OpenSSL.
"""
import ctypes
import sys
import six
# pylint: disable=protected-access
@ -745,7 +746,7 @@ class _OpenSSL(object):
"""
buffer_ = None
if data != 0:
if sys.version_info.major == 3 and isinstance(data, type('')):
if six.PY3 and isinstance(data, type('')):
data = data.encode()
buffer_ = self.create_string_buffer(data, size)
else:

View File

@ -1,7 +1,7 @@
import os
import sys
import time
import unittest
import six
_files = (
@ -33,7 +33,7 @@ def checkup():
def skip_python3():
"""Raise unittest.SkipTest() if detected python3"""
if sys.hexversion >= 0x3000000:
if six.PY3:
raise unittest.SkipTest('Module is not ported to python3')

View File

@ -3,6 +3,7 @@
import os
import sys
import unittest
import six
from pybitmessage import pathmagic
@ -22,7 +23,7 @@ class TestPartialRun(unittest.TestCase):
import state
from debug import logger # noqa:F401 pylint: disable=unused-variable
if sys.hexversion >= 0x3000000:
if six.PY3:
# pylint: disable=no-name-in-module,relative-import
from mockbm import network as network_mock
import network

View File

@ -1,9 +1,9 @@
"""TestAPIThread class definition"""
import sys
import time
from binascii import hexlify, unhexlify
from struct import pack
import six
from six.moves import queue, xmlrpc_client
@ -68,7 +68,7 @@ class TestAPIThread(TestPartialRun):
def test_client_status(self):
"""Ensure the reply of clientStatus corresponds to mock"""
status = self.api.clientStatus()
if sys.hexversion >= 0x3000000:
if six.PY3:
self.assertEqual(status["networkConnections"], 4)
self.assertEqual(status["pendingDownload"], 0)

View File

@ -1,9 +1,9 @@
"""Tests for l10n module"""
import re
import sys
import time
import unittest
import six
from pybitmessage import l10n
@ -16,7 +16,7 @@ class TestL10n(unittest.TestCase):
self.assertFalse(re.search(r'\d', time.strftime("wrong")))
timestring_type = type(time.strftime(l10n.DEFAULT_TIME_FORMAT))
self.assertEqual(timestring_type, str)
if sys.version_info[0] == 2:
if six.PY2:
self.assertEqual(timestring_type, bytes)
def test_getWindowsLocale(self):

View File

@ -1,8 +1,8 @@
"""Tests for logging"""
import subprocess
import sys
import unittest
import six
from pybitmessage import proofofwork
@ -11,7 +11,7 @@ class TestLog(unittest.TestCase):
"""A test case for logging"""
@unittest.skipIf(
sys.hexversion < 0x3000000, 'assertLogs is new in version 3.4')
six.PY2, 'assertLogs is new in version 3.4')
def test_LogOutput(self):
"""Use proofofwork.LogOutput to log output of a shell command"""
with self.assertLogs('default') as cm: # pylint: disable=no-member

View File

@ -2,8 +2,8 @@
Tests for common protocol functions
"""
import sys
import unittest
import six
from pybitmessage import protocol, state
from pybitmessage.helper_startup import fixSocket
@ -79,7 +79,7 @@ class TestProtocol(TestSocketInet):
self.assertEqual(protocol.checkIPAddress(globalhost), '8.8.8.8')
@unittest.skipIf(
sys.hexversion >= 0x3000000, 'this is still not working with python3')
six.PY3, 'this is still not working with python3')
def test_check_local_socks(self):
"""The SOCKS part of the local check"""
self.assertTrue(

View File

@ -3,11 +3,12 @@
import random # noseq
import sys
import unittest
import six
def unittest_discover():
"""Explicit test suite creation"""
if sys.hexversion >= 0x3000000:
if six.PY3:
from pybitmessage import pathmagic
pathmagic.setup()
loader = unittest.defaultTestLoader