Skip to content

Commit 0be9bd2

Browse files
author
surbhi
committed
Use six in common files - 2
1 parent 0e199ab commit 0be9bd2

File tree

9 files changed

+29
-20
lines changed

9 files changed

+29
-20
lines changed

src/class_singleWorker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
from struct import pack
1313
from subprocess import call # nosec
1414

15+
from six.moves import configparser, queue
16+
from six.moves.reprlib import repr
17+
1518
import defaults
1619
import helper_inbox
1720
import helper_msgcoding
@@ -28,8 +31,7 @@
2831
from addresses import decodeAddress, decodeVarint, encodeVarint
2932
from bmconfigparser import config
3033
from helper_sql import sqlExecute, sqlQuery
31-
from network import knownnodes, StoppableThread, invQueue
32-
from six.moves import configparser, queue
34+
from network import StoppableThread, invQueue, knownnodes
3335

3436

3537
def sizeof_fmt(num, suffix='h/s'):

src/class_smtpDeliver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
# pylint: disable=unused-variable
55

66
import smtplib
7-
import urlparse
87
from email.header import Header
9-
from email.mime.text import MIMEText
8+
9+
from six.moves import email_mime_text
10+
from six.moves.urllib import parse as urlparse
1011

1112
import queues
1213
import state
@@ -55,7 +56,7 @@ def run(self):
5556
u = urlparse.urlparse(dest)
5657
to = urlparse.parse_qs(u.query)['to']
5758
client = smtplib.SMTP(u.hostname, u.port)
58-
msg = MIMEText(body, 'plain', 'utf-8')
59+
msg = email_mime_text(body, 'plain', 'utf-8')
5960
msg['Subject'] = Header(subject, 'utf-8')
6061
msg['From'] = fromAddress + '@' + SMTPDOMAIN
6162
toLabel = map(

src/class_sqlThread.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import threading
1010
import time
1111

12+
from six.moves.reprlib import repr
13+
1214
try:
1315
import helper_sql
1416
import helper_startup

src/depends.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import re
88
import sys
99

10+
import six
11+
1012
# Only really old versions of Python don't have sys.hexversion. We don't
1113
# support them. The logging module was introduced in Python 2.3
1214
if not hasattr(sys, 'hexversion') or sys.hexversion < 0x20300F0:
@@ -18,7 +20,6 @@
1820

1921
import logging # noqa:E402
2022
import subprocess # nosec B404
21-
2223
from importlib import import_module
2324

2425
# We can now use logging so set up a simple configuration
@@ -438,7 +439,7 @@ def check_dependencies(verbose=False, optional=False):
438439
'PyBitmessage requires Python 2.7.4 or greater'
439440
' (but not Python 3+)')
440441
has_all_dependencies = False
441-
if sys.hexversion >= 0x3000000:
442+
if six.PY3:
442443
logger.error(
443444
'PyBitmessage does not support Python 3+. Python 2.7.4'
444445
' or greater is required. Python 2.7.18 is recommended.')

src/l10n.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import logging
44
import os
55
import re
6-
import sys
76
import time
87

8+
import six
99
from six.moves import range
1010

1111
from bmconfigparser import config
@@ -61,7 +61,7 @@
6161

6262
# It seems some systems lie about the encoding they use
6363
# so we perform comprehensive decoding tests
64-
elif sys.version_info[0] == 2:
64+
elif six.PY2:
6565
try:
6666
# Check day names
6767
for i in range(7):
@@ -118,7 +118,7 @@ def formatTimestamp(timestamp=None):
118118
except ValueError:
119119
timestring = time.strftime(time_format)
120120

121-
if sys.version_info[0] == 2:
121+
if six.PY2:
122122
return timestring.decode(encoding)
123123
return timestring
124124

src/namecoin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
# pylint: disable=too-many-branches,protected-access
55

66
import base64
7-
import httplib
87
import json
98
import os
109
import socket
1110
import sys
1211

12+
from six.moves import http_client as httplib
13+
1314
import defaults
1415
from addresses import decodeAddress
1516
from bmconfigparser import config
@@ -296,7 +297,7 @@ def lookupNamecoinFolder():
296297
"""
297298

298299
app = "namecoin"
299-
from os import path, environ
300+
from os import environ, path
300301
if sys.platform == "darwin":
301302
if "HOME" in environ:
302303
dataFolder = path.join(os.environ["HOME"],

src/protocol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import defaults
1717
import highlevelcrypto
1818
import state
19-
from addresses import (
20-
encodeVarint, decodeVarint, decodeAddress, varintDecodeError)
19+
from addresses import (decodeAddress, decodeVarint, encodeVarint,
20+
varintDecodeError)
2121
from bmconfigparser import config
2222
from debug import logger
2323
from helper_sql import sqlExecute

src/shared.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import sys
1616
from binascii import hexlify
1717

18+
from six.moves.reprlib import repr
19+
1820
# Project imports.
1921
import highlevelcrypto
2022
import state
@@ -23,7 +25,6 @@
2325
from debug import logger
2426
from helper_sql import sqlQuery
2527

26-
2728
myECCryptorObjects = {}
2829
MyECSubscriptionCryptorObjects = {}
2930
# The key in this dictionary is the RIPE hash which is encoded

src/upnp.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
Reference: http://mattscodecave.com/posts/using-python-and-upnp-to-forward-a-port
55
"""
66

7-
import httplib
87
import re
98
import socket
109
import time
11-
import urllib2
1210
from random import randint
13-
from urlparse import urlparse
1411
from xml.dom.minidom import Document # nosec B408
12+
1513
from defusedxml.minidom import parseString
14+
from six.moves import http_client as httplib
15+
from six.moves.urllib.parse import urlparse
16+
from six.moves.urllib.request import urlopen
1617

1718
import queues
1819
import state
1920
import tr
2021
from bmconfigparser import config
2122
from debug import logger
22-
from network import connectionpool, knownnodes, StoppableThread
23+
from network import StoppableThread, connectionpool, knownnodes
2324
from network.node import Peer
2425

2526

@@ -108,7 +109,7 @@ def __init__(self, ssdpResponse, address):
108109
logger.error("UPnP: missing location header")
109110

110111
# get the profile xml file and read it into a variable
111-
directory = urllib2.urlopen(header['location']).read()
112+
directory = urlopen(header['location']).read()
112113

113114
# create a DOM object that represents the `directory` document
114115
dom = parseString(directory)

0 commit comments

Comments
 (0)