From a11df0c5832c2671e53c8f0d0839b8891fce6378 Mon Sep 17 00:00:00 2001 From: Kashiko Koibumi Date: Sun, 26 May 2024 09:50:42 +0900 Subject: [PATCH] use six.moves --- packages/collectd/pybitmessagestatus.py | 2 +- src/api.py | 1 + src/bitmessagecli.py | 3 ++- src/bitmessagecurses/__init__.py | 4 ++-- src/bitmessagekivy/tests/telenium_process.py | 3 ++- src/bitmessageqt/__init__.py | 1 + src/bitmessageqt/addressvalidator.py | 2 +- src/bitmessageqt/safehtmlparser.py | 5 ++--- src/bitmessageqt/settings.py | 6 +++--- src/bitmessageqt/tests/main.py | 2 +- src/bmconfigparser.py | 2 +- src/class_singleWorker.py | 1 + src/class_smtpDeliver.py | 6 +++--- src/class_sqlThread.py | 1 + src/fallback/umsgpack/umsgpack.py | 3 ++- src/multiqueue.py | 2 +- src/namecoin.py | 2 +- src/network/asyncore_pollchoose.py | 1 + src/network/invthread.py | 2 +- src/network/knownnodes.py | 5 +---- src/network/node.py | 2 +- src/network/receivequeuethread.py | 2 +- src/plugins/menu_qrcode.py | 4 ++-- src/shared.py | 1 + src/storage/storage.py | 5 +---- src/tests/core.py | 2 +- src/upnp.py | 8 ++++---- 27 files changed, 40 insertions(+), 38 deletions(-) diff --git a/packages/collectd/pybitmessagestatus.py b/packages/collectd/pybitmessagestatus.py index d15c3a48..cb29a071 100644 --- a/packages/collectd/pybitmessagestatus.py +++ b/packages/collectd/pybitmessagestatus.py @@ -2,7 +2,7 @@ import collectd import json -import xmlrpclib +from six.moves import xmlrpc_client as xmlrpclib pybmurl = "" api = "" diff --git a/src/api.py b/src/api.py index a4445569..7b9c3c33 100644 --- a/src/api.py +++ b/src/api.py @@ -70,6 +70,7 @@ from struct import pack, unpack import six from six.moves import configparser, http_client, xmlrpc_server +from six.moves.reprlib import repr import helper_inbox import helper_sent diff --git a/src/bitmessagecli.py b/src/bitmessagecli.py index 84c618af..a0d0ea6c 100644 --- a/src/bitmessagecli.py +++ b/src/bitmessagecli.py @@ -21,7 +21,8 @@ import os import socket import sys import time -import xmlrpclib +from six.moves import xmlrpc_client as xmlrpclib +from six.moves import input as raw_input from bmconfigparser import config diff --git a/src/bitmessagecurses/__init__.py b/src/bitmessagecurses/__init__.py index c2764d1c..6f905963 100644 --- a/src/bitmessagecurses/__init__.py +++ b/src/bitmessagecurses/__init__.py @@ -10,7 +10,7 @@ Bitmessage commandline interface # * python2-pythondialog # * dialog -import ConfigParser +from six.moves import configparser import curses import os import sys @@ -673,7 +673,7 @@ def handlech(c, stdscr): elif t == "2" and m is False: try: mn = config.get(a, "mailinglistname") - except ConfigParser.NoOptionError: + except configparser.NoOptionError: mn = "" r, t = d.inputbox("Mailing list name", init=mn) if r == d.DIALOG_OK: diff --git a/src/bitmessagekivy/tests/telenium_process.py b/src/bitmessagekivy/tests/telenium_process.py index 0a81044d..5fc26e3b 100644 --- a/src/bitmessagekivy/tests/telenium_process.py +++ b/src/bitmessagekivy/tests/telenium_process.py @@ -6,6 +6,7 @@ import os import shutil import tempfile from time import time, sleep +from six.moves import getcwdb from telenium.tests import TeleniumTestCase from telenium.client import TeleniumHttpException @@ -32,7 +33,7 @@ def cleanup(files=_files): class TeleniumTestProcess(TeleniumTestCase): """Setting Screen Functionality Testing""" - cmd_entrypoint = [os.path.join(os.path.abspath(os.getcwd()), 'src', 'mockbm', 'kivy_main.py')] + cmd_entrypoint = [os.path.join(os.path.abspath(getcwdb()), 'src', 'mockbm', 'kivy_main.py')] @classmethod def setUpClass(cls): diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index b4ce8678..a60e3427 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -15,6 +15,7 @@ import time from datetime import datetime, timedelta from sqlite3 import register_adapter import six +from six.moves import range as xrange from PyQt4 import QtCore, QtGui from PyQt4.QtNetwork import QLocalSocket, QLocalServer diff --git a/src/bitmessageqt/addressvalidator.py b/src/bitmessageqt/addressvalidator.py index dc61b41c..fe1240ec 100644 --- a/src/bitmessageqt/addressvalidator.py +++ b/src/bitmessageqt/addressvalidator.py @@ -3,7 +3,7 @@ Address validator module. """ # pylint: disable=too-many-branches,too-many-arguments -from Queue import Empty +from six.moves.queue import Empty from PyQt4 import QtGui diff --git a/src/bitmessageqt/safehtmlparser.py b/src/bitmessageqt/safehtmlparser.py index d408d2c7..1bb56ce8 100644 --- a/src/bitmessageqt/safehtmlparser.py +++ b/src/bitmessageqt/safehtmlparser.py @@ -2,10 +2,9 @@ import inspect import re -from HTMLParser import HTMLParser +from six.moves.html_parser import HTMLParser -from urllib import quote_plus -from urlparse import urlparse +from six.moves.urllib.parse import quote_plus, urlparse class SafeHTMLParser(HTMLParser): diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index 3d05db25..4e2d15cf 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -1,7 +1,7 @@ """ This module setting file is for settings """ -import ConfigParser +from six.moves import configparser import os import sys import tempfile @@ -29,9 +29,9 @@ from tr import _translate def getSOCKSProxyType(config): """Get user socksproxytype setting from *config*""" try: - result = ConfigParser.SafeConfigParser.get( + result = configparser.SafeConfigParser.get( config, 'bitmessagesettings', 'socksproxytype') - except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): + except (configparser.NoSectionError, configparser.NoOptionError): return None else: if result.lower() in ('', 'none', 'false'): diff --git a/src/bitmessageqt/tests/main.py b/src/bitmessageqt/tests/main.py index b3aa67fa..41231235 100644 --- a/src/bitmessageqt/tests/main.py +++ b/src/bitmessageqt/tests/main.py @@ -1,6 +1,6 @@ """Common definitions for bitmessageqt tests""" -import Queue +from six.moves import queue as Queue import sys import unittest diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index abf285ad..ec05af3e 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -21,7 +21,7 @@ config_ready = Event() class BMConfigParser(SafeConfigParser): """ - Singleton class inherited from :class:`ConfigParser.SafeConfigParser` + Singleton class inherited from :class:`configparser.SafeConfigParser` with additional methods specific to bitmessage config. """ # pylint: disable=too-many-ancestors diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index f2821f65..47b002ff 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -30,6 +30,7 @@ from bmconfigparser import config from helper_sql import sqlExecute, sqlQuery from network import knownnodes, StoppableThread from six.moves import configparser, queue +from six.moves.reprlib import repr def sizeof_fmt(num, suffix='h/s'): diff --git a/src/class_smtpDeliver.py b/src/class_smtpDeliver.py index 9e3b8ab3..490f296b 100644 --- a/src/class_smtpDeliver.py +++ b/src/class_smtpDeliver.py @@ -4,9 +4,9 @@ SMTP client thread for delivering emails # pylint: disable=unused-variable import smtplib -import urlparse +from six.moves.urllib import parse as urlparse from email.header import Header -from email.mime.text import MIMEText +from six.moves import email_mime_text import queues import state @@ -55,7 +55,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( diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index 7df9e253..8b064a76 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -8,6 +8,7 @@ import sqlite3 import sys import threading import time +from six.moves.reprlib import repr try: import helper_sql diff --git a/src/fallback/umsgpack/umsgpack.py b/src/fallback/umsgpack/umsgpack.py index cac4986f..68d5869a 100644 --- a/src/fallback/umsgpack/umsgpack.py +++ b/src/fallback/umsgpack/umsgpack.py @@ -49,7 +49,8 @@ License: MIT # pylint: disable=too-many-lines,too-many-branches,too-many-statements,global-statement,too-many-return-statements # pylint: disable=unused-argument -import collections +from six.moves import collections_abc as collections +from six.moves import range as xrange import struct import sys import six diff --git a/src/multiqueue.py b/src/multiqueue.py index 88b6a4dd..80598220 100644 --- a/src/multiqueue.py +++ b/src/multiqueue.py @@ -3,7 +3,7 @@ A queue with multiple internal subqueues. Elements are added into a random subqueue, and retrieval rotates """ -from collections import deque +from six.moves.collections_abc import deque from six.moves import queue diff --git a/src/namecoin.py b/src/namecoin.py index a16cb3d7..2cc8f0fd 100644 --- a/src/namecoin.py +++ b/src/namecoin.py @@ -4,7 +4,7 @@ Namecoin queries # pylint: disable=too-many-branches,protected-access import base64 -import httplib +from six.moves import http_client as httplib import json import os import socket diff --git a/src/network/asyncore_pollchoose.py b/src/network/asyncore_pollchoose.py index bdd312c6..a41145a1 100644 --- a/src/network/asyncore_pollchoose.py +++ b/src/network/asyncore_pollchoose.py @@ -18,6 +18,7 @@ from errno import ( ENOTCONN, ENOTSOCK, EPIPE, ESHUTDOWN, ETIMEDOUT, EWOULDBLOCK, errorcode ) from threading import current_thread +from six.moves.reprlib import repr import helper_random diff --git a/src/network/invthread.py b/src/network/invthread.py index b55408d4..dd8c4f9e 100644 --- a/src/network/invthread.py +++ b/src/network/invthread.py @@ -1,7 +1,7 @@ """ Thread to send inv annoucements """ -import Queue +from six.moves import queue as Queue import random from time import time diff --git a/src/network/knownnodes.py b/src/network/knownnodes.py index f0fd6d90..702f59c6 100644 --- a/src/network/knownnodes.py +++ b/src/network/knownnodes.py @@ -10,10 +10,7 @@ import os import pickle # nosec B403 import threading import time -try: - from collections.abc import Iterable -except ImportError: - from collections import Iterable +from six.moves.collections_abc import Iterable import six import state diff --git a/src/network/node.py b/src/network/node.py index 4c532b81..e580778b 100644 --- a/src/network/node.py +++ b/src/network/node.py @@ -1,7 +1,7 @@ """ Named tuples representing the network peers """ -import collections +from six.moves import collections_abc as collections Peer = collections.namedtuple('Peer', ['host', 'port']) Node = collections.namedtuple('Node', ['services', 'host', 'port']) diff --git a/src/network/receivequeuethread.py b/src/network/receivequeuethread.py index 10f2acea..61af353e 100644 --- a/src/network/receivequeuethread.py +++ b/src/network/receivequeuethread.py @@ -2,7 +2,7 @@ Process data incoming from network """ import errno -import Queue +from six.moves import queue as Queue import socket import connectionpool diff --git a/src/plugins/menu_qrcode.py b/src/plugins/menu_qrcode.py index ea322a49..e5d41822 100644 --- a/src/plugins/menu_qrcode.py +++ b/src/plugins/menu_qrcode.py @@ -3,7 +3,7 @@ A menu plugin showing QR-Code for bitmessage address in modal dialog. """ -import urllib +from six.moves.urllib.parse import urlencode import qrcode from PyQt4 import QtCore, QtGui @@ -93,7 +93,7 @@ def connect_plugin(form): return dialog.render( 'bitmessage:%s' % account.address + ( - '?' + urllib.urlencode({'label': label.encode('utf-8')}) + '?' + urlencode({'label': label.encode('utf-8')}) if label != account.address else '') ) dialog.exec_() diff --git a/src/shared.py b/src/shared.py index b85ddb20..64eea088 100644 --- a/src/shared.py +++ b/src/shared.py @@ -14,6 +14,7 @@ import stat import subprocess # nosec B404 import sys from binascii import hexlify +from six.moves.reprlib import repr # Project imports. import highlevelcrypto diff --git a/src/storage/storage.py b/src/storage/storage.py index 9b33eef7..d89be837 100644 --- a/src/storage/storage.py +++ b/src/storage/storage.py @@ -4,10 +4,7 @@ Storing inventory items from abc import abstractmethod from collections import namedtuple -try: - from collections import MutableMapping # pylint: disable=deprecated-class -except ImportError: - from collections.abc import MutableMapping +from six.moves.collections_abc import MutableMapping # pylint: disable=deprecated-class InventoryItem = namedtuple('InventoryItem', 'type stream payload expires tag') diff --git a/src/tests/core.py b/src/tests/core.py index e24293b0..7000223d 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -6,7 +6,7 @@ Tests for core and those that do not work outside import atexit import os import pickle # nosec -import Queue +from six.moves import queue as Queue import random # nosec import shutil import socket diff --git a/src/upnp.py b/src/upnp.py index 42ff0c6d..a21164d7 100644 --- a/src/upnp.py +++ b/src/upnp.py @@ -4,13 +4,13 @@ Complete UPnP port forwarding implementation in separate thread. Reference: http://mattscodecave.com/posts/using-python-and-upnp-to-forward-a-port """ -import httplib +from six.moves import http_client as httplib import re import socket import time -import urllib2 +from six.moves.urllib.request import urlopen from random import randint -from urlparse import urlparse +from six.moves.urllib.parse import urlparse from xml.dom.minidom import Document # nosec B408 from defusedxml.minidom import parseString @@ -108,7 +108,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)