Python3 porting 3: common files-2 #2283

Open
PeterSurda wants to merge 1 commits from gitea-132 into v0.6
9 changed files with 29 additions and 20 deletions

View File

@ -12,6 +12,9 @@ from binascii import hexlify, unhexlify
from struct import pack
from subprocess import call # nosec
from six.moves import configparser, queue
from six.moves.reprlib import repr
import defaults
import helper_inbox
import helper_msgcoding
@ -28,8 +31,7 @@ import tr
from addresses import decodeAddress, decodeVarint, encodeVarint
from bmconfigparser import config
from helper_sql import sqlExecute, sqlQuery
from network import knownnodes, StoppableThread, invQueue
from six.moves import configparser, queue
from network import StoppableThread, invQueue, knownnodes
def sizeof_fmt(num, suffix='h/s'):

View File

@ -4,9 +4,10 @@ SMTP client thread for delivering emails
# pylint: disable=unused-variable
import smtplib
import urlparse
from email.header import Header
from email.mime.text import MIMEText
from six.moves import email_mime_text
from six.moves.urllib import parse as urlparse
import queues
import state
@ -55,7 +56,7 @@ class smtpDeliver(StoppableThread):
u = urlparse.urlparse(dest)
to = urlparse.parse_qs(u.query)['to']
client = smtplib.SMTP(u.hostname, u.port)
msg = MIMEText(body, 'plain', 'utf-8')
msg = email_mime_text(body, 'plain', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = fromAddress + '@' + SMTPDOMAIN
toLabel = map(

View File

@ -9,6 +9,8 @@ import sys
import threading
import time
from six.moves.reprlib import repr
try:
import helper_sql
import helper_startup

View File

@ -7,6 +7,8 @@ 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
if not hasattr(sys, 'hexversion') or sys.hexversion < 0x20300F0:
@ -18,7 +20,6 @@ if not hasattr(sys, 'hexversion') or sys.hexversion < 0x20300F0:
import logging # noqa:E402
import subprocess # nosec B404
from importlib import import_module
# We can now use logging so set up a simple configuration
@ -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

@ -3,9 +3,9 @@
import logging
import os
import re
import sys
import time
import six
from six.moves import range
from bmconfigparser import config
@ -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

@ -4,12 +4,13 @@ Namecoin queries
# pylint: disable=too-many-branches,protected-access
import base64
import httplib
import json
import os
import socket
import sys
from six.moves import http_client as httplib
import defaults
from addresses import decodeAddress
from bmconfigparser import config
@ -296,7 +297,7 @@ def lookupNamecoinFolder():
"""
app = "namecoin"
from os import path, environ
from os import environ, path
if sys.platform == "darwin":
if "HOME" in environ:
dataFolder = path.join(os.environ["HOME"],

View File

@ -16,8 +16,8 @@ from struct import Struct, pack, unpack
import defaults
import highlevelcrypto
import state
from addresses import (
encodeVarint, decodeVarint, decodeAddress, varintDecodeError)
from addresses import (decodeAddress, decodeVarint, encodeVarint,
varintDecodeError)
from bmconfigparser import config
from debug import logger
from helper_sql import sqlExecute

View File

@ -15,6 +15,8 @@ import subprocess # nosec B404
import sys
from binascii import hexlify
from six.moves.reprlib import repr
# Project imports.
import highlevelcrypto
import state
@ -23,7 +25,6 @@ from bmconfigparser import config
from debug import logger
from helper_sql import sqlQuery
myECCryptorObjects = {}
MyECSubscriptionCryptorObjects = {}
# The key in this dictionary is the RIPE hash which is encoded

View File

@ -4,22 +4,23 @@ Complete UPnP port forwarding implementation in separate thread.
Reference: http://mattscodecave.com/posts/using-python-and-upnp-to-forward-a-port
"""
import httplib
import re
import socket
import time
import urllib2
from random import randint
from urlparse import urlparse
from xml.dom.minidom import Document # nosec B408
from defusedxml.minidom import parseString
from six.moves import http_client as httplib
from six.moves.urllib.parse import urlparse
from six.moves.urllib.request import urlopen
import queues
import state
import tr
from bmconfigparser import config
from debug import logger
from network import connectionpool, knownnodes, StoppableThread
from network import StoppableThread, connectionpool, knownnodes
from network.node import Peer
@ -108,7 +109,7 @@ class Router: # pylint: disable=old-style-class
logger.error("UPnP: missing location header")
# get the profile xml file and read it into a variable
directory = urllib2.urlopen(header['location']).read()
directory = urlopen(header['location']).read()
# create a DOM object that represents the `directory` document
dom = parseString(directory)