Use six in common files - 2

This commit is contained in:
surbhi 2025-02-01 23:58:40 +05:30
parent 4e0731725d
commit 9055a9baf1
Signed by untrusted user: surbhi
GPG Key ID: BD938EA4D030869A
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 struct import pack
from subprocess import call # nosec from subprocess import call # nosec
from six.moves import configparser, queue
from six.moves.reprlib import repr
import defaults import defaults
import helper_inbox import helper_inbox
import helper_msgcoding import helper_msgcoding
@ -28,8 +31,7 @@ import tr
from addresses import decodeAddress, decodeVarint, encodeVarint from addresses import decodeAddress, decodeVarint, encodeVarint
from bmconfigparser import config from bmconfigparser import config
from helper_sql import sqlExecute, sqlQuery from helper_sql import sqlExecute, sqlQuery
from network import knownnodes, StoppableThread, invQueue from network import StoppableThread, invQueue, knownnodes
from six.moves import configparser, queue
def sizeof_fmt(num, suffix='h/s'): def sizeof_fmt(num, suffix='h/s'):

View File

@ -4,9 +4,10 @@ SMTP client thread for delivering emails
# pylint: disable=unused-variable # pylint: disable=unused-variable
import smtplib import smtplib
import urlparse
from email.header import Header 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 queues
import state import state
@ -55,7 +56,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

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

View File

@ -7,6 +7,8 @@ import os
import re import re
import sys import sys
import six
# Only really old versions of Python don't have sys.hexversion. We don't # 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 # support them. The logging module was introduced in Python 2.3
if not hasattr(sys, 'hexversion') or sys.hexversion < 0x20300F0: 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 logging # noqa:E402
import subprocess # nosec B404 import subprocess # nosec B404
from importlib import import_module from importlib import import_module
# We can now use logging so set up a simple configuration # 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' 'PyBitmessage requires Python 2.7.4 or greater'
' (but not Python 3+)') ' (but not Python 3+)')
has_all_dependencies = False has_all_dependencies = False
if sys.hexversion >= 0x3000000: if six.PY3:
logger.error( logger.error(
'PyBitmessage does not support Python 3+. Python 2.7.4' 'PyBitmessage does not support Python 3+. Python 2.7.4'
' or greater is required. Python 2.7.18 is recommended.') ' or greater is required. Python 2.7.18 is recommended.')

View File

@ -3,9 +3,9 @@
import logging import logging
import os import os
import re import re
import sys
import time import time
import six
from six.moves import range from six.moves import range
from bmconfigparser import config 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 # It seems some systems lie about the encoding they use
# so we perform comprehensive decoding tests # so we perform comprehensive decoding tests
elif sys.version_info[0] == 2: elif six.PY2:
try: try:
# Check day names # Check day names
for i in range(7): for i in range(7):
@ -118,7 +118,7 @@ def formatTimestamp(timestamp=None):
except ValueError: except ValueError:
timestring = time.strftime(time_format) timestring = time.strftime(time_format)
if sys.version_info[0] == 2: if six.PY2:
return timestring.decode(encoding) return timestring.decode(encoding)
return timestring return timestring

View File

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

View File

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

View File

@ -15,6 +15,8 @@ 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
import state import state
@ -23,7 +25,6 @@ from bmconfigparser import config
from debug import logger from debug import logger
from helper_sql import sqlQuery from helper_sql import sqlQuery
myECCryptorObjects = {} myECCryptorObjects = {}
MyECSubscriptionCryptorObjects = {} MyECSubscriptionCryptorObjects = {}
# The key in this dictionary is the RIPE hash which is encoded # 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 Reference: http://mattscodecave.com/posts/using-python-and-upnp-to-forward-a-port
""" """
import httplib
import re import re
import socket import socket
import time import time
import urllib2
from random import randint from random import randint
from urlparse 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
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 queues
import state import state
import tr import tr
from bmconfigparser import config from bmconfigparser import config
from debug import logger from debug import logger
from network import connectionpool, knownnodes, StoppableThread from network import StoppableThread, connectionpool, knownnodes
from network.node import Peer from network.node import Peer
@ -108,7 +109,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)