Skip to content

Use six everywhere possible #2240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: v0.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/collectd/pybitmessagestatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import collectd
import json
import xmlrpclib
from six.moves import xmlrpc_client as xmlrpclib

pybmurl = ""
api = ""
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import platform
import shutil
import sys
import six

from importlib import import_module
from setuptools import setup, Extension
Expand Down Expand Up @@ -83,7 +84,7 @@ def run(self):
'images/kivy/text_images*.png'
]}

if sys.version_info[0] == 3:
if six.PY3:
packages.extend(
[
'pybitmessage.bitmessagekivy',
Expand Down
1 change: 1 addition & 0 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

import six
from six.moves import configparser, http_client, xmlrpc_server
from six.moves.reprlib import repr

import helper_inbox
import helper_sent
Expand Down
3 changes: 2 additions & 1 deletion src/bitmessagecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
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

Expand Down
15 changes: 8 additions & 7 deletions src/bitmessagecurses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
# * python2-pythondialog
# * dialog

import ConfigParser
from six.moves import configparser
import curses
import os
import sys
import time
from textwrap import fill
from threading import Timer
import six

from dialog import Dialog
import helper_sent
Expand Down Expand Up @@ -105,7 +106,7 @@ def ascii(s):
"""ASCII values"""
r = ""
for c in s:
if ord(c) in range(128):
if six.byte2int(c) in range(128):
r += c
return r

Expand Down Expand Up @@ -326,13 +327,13 @@ def handlech(c, stdscr):
if c != curses.ERR:
global inboxcur, addrcur, sentcur, subcur, abookcur, blackcur
if c in range(256):
if chr(c) in '12345678':
if six.int2byte(c) in '12345678':
global menutab
menutab = int(chr(c))
elif chr(c) == 'q':
menutab = int(six.int2byte(c))
elif six.int2byte(c) == 'q':
global quit_
quit_ = True
elif chr(c) == '\n':
elif six.int2byte(c) == '\n':
curses.curs_set(1)
d = Dialog(dialog="dialog")
if menutab == 1:
Expand Down Expand Up @@ -672,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:
Expand Down
2 changes: 1 addition & 1 deletion src/bitmessagekivy/identiconGeneration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The raw image data can be keep in memory for further access
"""
import hashlib
from io import BytesIO
from six import BytesIO

from PIL import Image
from kivy.core.image import Image as CoreImage
Expand Down
3 changes: 2 additions & 1 deletion src/bitmessagekivy/tests/telenium_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import tempfile
from time import time, sleep
from six.moves import getcwdb

from telenium.tests import TeleniumTestCase
from telenium.client import TeleniumHttpException
Expand All @@ -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):
Expand Down
16 changes: 9 additions & 7 deletions src/bitmessageqt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
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
Expand Down Expand Up @@ -468,7 +470,7 @@ def rerenderTabTreeSubscriptions(self):
# add missing folders
if len(db[toAddress]) > 0:
j = 0
for f, c in db[toAddress].iteritems():
for f, c in six.iteritems(db[toAddress]):
try:
subwidget = Ui_FolderWidget(widget, j, toAddress, f, c['count'])
except KeyError:
Expand Down Expand Up @@ -598,7 +600,7 @@ def rerenderTabTree(self, tab):
# add missing folders
if len(db[toAddress]) > 0:
j = 0
for f, c in db[toAddress].iteritems():
for f, c in six.iteritems(db[toAddress]):
if toAddress is not None and tab == 'messages' and folder == "new":
continue
subwidget = Ui_FolderWidget(widget, j, toAddress, f, c)
Expand Down Expand Up @@ -1075,15 +1077,15 @@ def propagateUnreadCount(self, folder=None, widget=None):
for i in range(root.childCount()):
addressItem = root.child(i)
if addressItem.type == AccountMixin.ALL:
newCount = sum(totalUnread.itervalues())
newCount = sum(six.itervalues(totalUnread))
self.drawTrayIcon(self.currentTrayIconFileName, newCount)
else:
try:
newCount = sum((
newCount = sum(six.itervalues((
broadcastsUnread
if addressItem.type == AccountMixin.SUBSCRIPTION
else normalUnread
)[addressItem.address].itervalues())
)[addressItem.address]))
except KeyError:
newCount = 0
if newCount != addressItem.unreadCount:
Expand Down Expand Up @@ -2871,7 +2873,7 @@ def quit(self):
QtCore.QEventLoop.AllEvents, 1000
)
self.saveSettings()
for attr, obj in self.ui.__dict__.iteritems():
for attr, obj in six.iteritems(self.ui.__dict__):
if hasattr(obj, "__class__") \
and isinstance(obj, settingsmixin.SettingsMixin):
saveMethod = getattr(obj, "saveSettings", None)
Expand Down Expand Up @@ -4209,7 +4211,7 @@ def resetNamecoinConnection(self):

def initSettings(self):
self.loadSettings()
for attr, obj in self.ui.__dict__.iteritems():
for attr, obj in six.iteritems(self.ui.__dict__):
if hasattr(obj, "__class__") and \
isinstance(obj, settingsmixin.SettingsMixin):
loadMethod = getattr(obj, "loadSettings", None)
Expand Down
2 changes: 1 addition & 1 deletion src/bitmessageqt/addressvalidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
# pylint: disable=too-many-branches,too-many-arguments

from Queue import Empty
from six.moves.queue import Empty

from PyQt4 import QtGui

Expand Down
3 changes: 2 additions & 1 deletion src/bitmessageqt/retranslateui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from os import path
import six
from PyQt4 import QtGui
from debug import logger
import widgets
Expand All @@ -7,7 +8,7 @@ class RetranslateMixin(object):
def retranslateUi(self):
defaults = QtGui.QWidget()
widgets.load(self.__class__.__name__.lower() + '.ui', defaults)
for attr, value in defaults.__dict__.iteritems():
for attr, value in six.iteritems(defaults.__dict__):
setTextMethod = getattr(value, "setText", None)
if callable(setTextMethod):
getattr(self, attr).setText(getattr(defaults, attr).text())
Expand Down
5 changes: 2 additions & 3 deletions src/bitmessageqt/safehtmlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -100,29 +99,29 @@
self.sanitised += "/"
self.sanitised += ">"

def handle_starttag(self, tag, attrs):

Check notice on line 102 in src/bitmessageqt/safehtmlparser.py

View check run for this annotation

PyBitmessage Code Quality Checks / Code Quality - pylint

C0111 / missing-docstring

Missing method docstring
if tag in self.acceptable_elements:
self.has_html = True
self.add_if_acceptable(tag, attrs)

def handle_endtag(self, tag):

Check notice on line 107 in src/bitmessageqt/safehtmlparser.py

View check run for this annotation

PyBitmessage Code Quality Checks / Code Quality - pylint

C0111 / missing-docstring

Missing method docstring
self.add_if_acceptable(tag)

def handle_startendtag(self, tag, attrs):

Check notice on line 110 in src/bitmessageqt/safehtmlparser.py

View check run for this annotation

PyBitmessage Code Quality Checks / Code Quality - pylint

C0111 / missing-docstring

Missing method docstring
if tag in self.acceptable_elements:
self.has_html = True
self.add_if_acceptable(tag, attrs)

def handle_data(self, data):

Check notice on line 115 in src/bitmessageqt/safehtmlparser.py

View check run for this annotation

PyBitmessage Code Quality Checks / Code Quality - pylint

C0111 / missing-docstring

Missing method docstring
self.sanitised += data

def handle_charref(self, name):

Check notice on line 118 in src/bitmessageqt/safehtmlparser.py

View check run for this annotation

PyBitmessage Code Quality Checks / Code Quality - pylint

C0111 / missing-docstring

Missing method docstring
self.sanitised += "&#" + name + ";"

def handle_entityref(self, name):

Check notice on line 121 in src/bitmessageqt/safehtmlparser.py

View check run for this annotation

PyBitmessage Code Quality Checks / Code Quality - pylint

C0111 / missing-docstring

Missing method docstring
self.sanitised += "&" + name + ";"

def feed(self, data):

Check notice on line 124 in src/bitmessageqt/safehtmlparser.py

View check run for this annotation

PyBitmessage Code Quality Checks / Code Quality - pylint

C0111 / missing-docstring

Missing method docstring
try:
data = unicode(data, 'utf-8')
except UnicodeDecodeError:
Expand Down
6 changes: 3 additions & 3 deletions src/bitmessageqt/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
This module setting file is for settings
"""
import ConfigParser
from six.moves import configparser
import os
import sys
import tempfile
Expand Down Expand Up @@ -29,9 +29,9 @@
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'):
Expand Down
2 changes: 1 addition & 1 deletion src/bitmessageqt/tests/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Common definitions for bitmessageqt tests"""

import Queue
from six.moves import queue as Queue
import sys
import unittest

Expand Down
2 changes: 1 addition & 1 deletion src/bmconfigparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

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
Expand Down
1 change: 1 addition & 0 deletions src/class_singleWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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'):
Expand Down
6 changes: 3 additions & 3 deletions src/class_smtpDeliver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# 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
Expand Down Expand Up @@ -55,7 +55,7 @@ def run(self):
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(
Expand Down
1 change: 1 addition & 0 deletions src/class_sqlThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import threading
import time
from six.moves.reprlib import repr

try:
import helper_sql
Expand Down
3 changes: 2 additions & 1 deletion src/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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
Expand Down Expand Up @@ -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.')
Expand Down
Loading