Use six everywhere possible #2240

Open
kashikoibumi wants to merge 6 commits from kashikoibumi/six into v0.6
27 changed files with 40 additions and 38 deletions
Showing only changes of commit a11df0c583 - Show all commits

View File

@ -2,7 +2,7 @@
import collectd import collectd
import json import json
import xmlrpclib from six.moves import xmlrpc_client as xmlrpclib
pybmurl = "" pybmurl = ""
api = "" api = ""

View File

@ -70,6 +70,7 @@ from struct import pack, unpack
import six import six
from six.moves import configparser, http_client, xmlrpc_server from six.moves import configparser, http_client, xmlrpc_server
from six.moves.reprlib import repr
import helper_inbox import helper_inbox
import helper_sent import helper_sent

View File

@ -21,7 +21,8 @@ import os
import socket import socket
import sys import sys
import time import time
import xmlrpclib from six.moves import xmlrpc_client as xmlrpclib
from six.moves import input as raw_input
from bmconfigparser import config from bmconfigparser import config

View File

@ -10,7 +10,7 @@ Bitmessage commandline interface
# * python2-pythondialog # * python2-pythondialog
# * dialog # * dialog
import ConfigParser from six.moves import configparser
import curses import curses
import os import os
import sys import sys
@ -673,7 +673,7 @@ def handlech(c, stdscr):
elif t == "2" and m is False: elif t == "2" and m is False:
try: try:
mn = config.get(a, "mailinglistname") mn = config.get(a, "mailinglistname")
except ConfigParser.NoOptionError: except configparser.NoOptionError:
mn = "" mn = ""
r, t = d.inputbox("Mailing list name", init=mn) r, t = d.inputbox("Mailing list name", init=mn)
if r == d.DIALOG_OK: if r == d.DIALOG_OK:

View File

@ -6,6 +6,7 @@ import os
import shutil import shutil
import tempfile import tempfile
from time import time, sleep from time import time, sleep
from six.moves import getcwdb
from telenium.tests import TeleniumTestCase from telenium.tests import TeleniumTestCase
from telenium.client import TeleniumHttpException from telenium.client import TeleniumHttpException
@ -32,7 +33,7 @@ def cleanup(files=_files):
class TeleniumTestProcess(TeleniumTestCase): class TeleniumTestProcess(TeleniumTestCase):
"""Setting Screen Functionality Testing""" """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 @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -15,6 +15,7 @@ import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from sqlite3 import register_adapter from sqlite3 import register_adapter
import six import six
from six.moves import range as xrange
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from PyQt4.QtNetwork import QLocalSocket, QLocalServer from PyQt4.QtNetwork import QLocalSocket, QLocalServer

View File

@ -3,7 +3,7 @@ Address validator module.
""" """
# pylint: disable=too-many-branches,too-many-arguments # pylint: disable=too-many-branches,too-many-arguments
from Queue import Empty from six.moves.queue import Empty
from PyQt4 import QtGui from PyQt4 import QtGui

View File

@ -2,10 +2,9 @@
import inspect import inspect
import re import re
from HTMLParser import HTMLParser from six.moves.html_parser import HTMLParser
from urllib import quote_plus from six.moves.urllib.parse import quote_plus, urlparse
from urlparse import urlparse
class SafeHTMLParser(HTMLParser): class SafeHTMLParser(HTMLParser):

View File

@ -1,7 +1,7 @@
""" """
This module setting file is for settings This module setting file is for settings
""" """
import ConfigParser from six.moves import configparser
import os import os
import sys import sys
import tempfile import tempfile
@ -29,9 +29,9 @@ from tr import _translate
def getSOCKSProxyType(config): def getSOCKSProxyType(config):
"""Get user socksproxytype setting from *config*""" """Get user socksproxytype setting from *config*"""
try: try:
result = ConfigParser.SafeConfigParser.get( result = configparser.SafeConfigParser.get(
config, 'bitmessagesettings', 'socksproxytype') config, 'bitmessagesettings', 'socksproxytype')
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): except (configparser.NoSectionError, configparser.NoOptionError):
return None return None
else: else:
if result.lower() in ('', 'none', 'false'): if result.lower() in ('', 'none', 'false'):

View File

@ -1,6 +1,6 @@
"""Common definitions for bitmessageqt tests""" """Common definitions for bitmessageqt tests"""
import Queue from six.moves import queue as Queue
import sys import sys
import unittest import unittest

View File

@ -21,7 +21,7 @@ config_ready = Event()
class BMConfigParser(SafeConfigParser): class BMConfigParser(SafeConfigParser):
""" """
Singleton class inherited from :class:`ConfigParser.SafeConfigParser` Singleton class inherited from :class:`configparser.SafeConfigParser`
with additional methods specific to bitmessage config. with additional methods specific to bitmessage config.
""" """
# pylint: disable=too-many-ancestors # pylint: disable=too-many-ancestors

View File

@ -30,6 +30,7 @@ from bmconfigparser import config
from helper_sql import sqlExecute, sqlQuery from helper_sql import sqlExecute, sqlQuery
from network import knownnodes, StoppableThread from network import knownnodes, StoppableThread
from six.moves import configparser, queue from six.moves import configparser, queue
from six.moves.reprlib import repr
def sizeof_fmt(num, suffix='h/s'): def sizeof_fmt(num, suffix='h/s'):

View File

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

View File

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

View File

@ -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=too-many-lines,too-many-branches,too-many-statements,global-statement,too-many-return-statements
# pylint: disable=unused-argument # pylint: disable=unused-argument
import collections from six.moves import collections_abc as collections
from six.moves import range as xrange
import struct import struct
import sys import sys
import six import six

View File

@ -3,7 +3,7 @@ A queue with multiple internal subqueues.
Elements are added into a random subqueue, and retrieval rotates 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 from six.moves import queue

View File

@ -4,7 +4,7 @@ Namecoin queries
# pylint: disable=too-many-branches,protected-access # pylint: disable=too-many-branches,protected-access
import base64 import base64
import httplib from six.moves import http_client as httplib
import json import json
import os import os
import socket import socket

View File

@ -18,6 +18,7 @@ from errno import (
ENOTCONN, ENOTSOCK, EPIPE, ESHUTDOWN, ETIMEDOUT, EWOULDBLOCK, errorcode ENOTCONN, ENOTSOCK, EPIPE, ESHUTDOWN, ETIMEDOUT, EWOULDBLOCK, errorcode
) )
from threading import current_thread from threading import current_thread
from six.moves.reprlib import repr
import helper_random import helper_random

View File

@ -1,7 +1,7 @@
""" """
Thread to send inv annoucements Thread to send inv annoucements
""" """
import Queue from six.moves import queue as Queue
import random import random
from time import time from time import time

View File

@ -10,10 +10,7 @@ import os
import pickle # nosec B403 import pickle # nosec B403
import threading import threading
import time import time
try: from six.moves.collections_abc import Iterable
from collections.abc import Iterable
except ImportError:
from collections import Iterable
import six import six
import state import state

View File

@ -1,7 +1,7 @@
""" """
Named tuples representing the network peers Named tuples representing the network peers
""" """
import collections from six.moves import collections_abc as collections
Peer = collections.namedtuple('Peer', ['host', 'port']) Peer = collections.namedtuple('Peer', ['host', 'port'])
Node = collections.namedtuple('Node', ['services', 'host', 'port']) Node = collections.namedtuple('Node', ['services', 'host', 'port'])

View File

@ -2,7 +2,7 @@
Process data incoming from network Process data incoming from network
""" """
import errno import errno
import Queue from six.moves import queue as Queue
import socket import socket
import connectionpool import connectionpool

View File

@ -3,7 +3,7 @@
A menu plugin showing QR-Code for bitmessage address in modal dialog. A menu plugin showing QR-Code for bitmessage address in modal dialog.
""" """
import urllib from six.moves.urllib.parse import urlencode
import qrcode import qrcode
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -93,7 +93,7 @@ def connect_plugin(form):
return return
dialog.render( dialog.render(
'bitmessage:%s' % account.address + ( 'bitmessage:%s' % account.address + (
'?' + urllib.urlencode({'label': label.encode('utf-8')}) '?' + urlencode({'label': label.encode('utf-8')})
if label != account.address else '') if label != account.address else '')
) )
dialog.exec_() dialog.exec_()

View File

@ -14,6 +14,7 @@ import stat
import subprocess # nosec B404 import subprocess # nosec B404
import sys import sys
from binascii import hexlify from binascii import hexlify
from six.moves.reprlib import repr
# Project imports. # Project imports.
import highlevelcrypto import highlevelcrypto

View File

@ -4,10 +4,7 @@ Storing inventory items
from abc import abstractmethod from abc import abstractmethod
from collections import namedtuple from collections import namedtuple
try: from six.moves.collections_abc import MutableMapping # pylint: disable=deprecated-class
from collections import MutableMapping # pylint: disable=deprecated-class
except ImportError:
from collections.abc import MutableMapping
InventoryItem = namedtuple('InventoryItem', 'type stream payload expires tag') InventoryItem = namedtuple('InventoryItem', 'type stream payload expires tag')

View File

@ -6,7 +6,7 @@ Tests for core and those that do not work outside
import atexit import atexit
import os import os
import pickle # nosec import pickle # nosec
import Queue from six.moves import queue as Queue
import random # nosec import random # nosec
import shutil import shutil
import socket import socket

View File

@ -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 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 re
import socket import socket
import time import time
import urllib2 from six.moves.urllib.request import urlopen
from random import randint from random import randint
from urlparse import urlparse from six.moves.urllib.parse import urlparse
from xml.dom.minidom import Document # nosec B408 from xml.dom.minidom import Document # nosec B408
from defusedxml.minidom import parseString from defusedxml.minidom import parseString
@ -108,7 +108,7 @@ class Router: # pylint: disable=old-style-class
logger.error("UPnP: missing location header") logger.error("UPnP: missing location header")
# get the profile xml file and read it into a variable # 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 # create a DOM object that represents the `directory` document
dom = parseString(directory) dom = parseString(directory)