[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/develop] Replace usage of unicode function
commit a3104da794ba4fcbe78ac5293d6855f75fc119a8
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Jan 11 15:35:39 2020 -0800
Replace usage of unicode function
In most cases unicode() is being called on static strings that are already
unicode in python 3.x. In the few instances where these actually seem to
attempt normalization the proper way to convert bytes is
"my_bytes.decode('utf-8')".
This fixes the following exceptions...
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/twisted/trial/runner.py", line 823, in loadByName
return self.suiteFactory([self.findByName(name, recurse=recurse)])
File "/usr/local/lib/python3.5/dist-packages/twisted/trial/runner.py", line 702, in findByName
__import__(name)
File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_persistentSaveAndLoad.py", line 31, in <module>
TEST_CONFIG_FILE = io.StringIO(unicode("""\
builtins.NameError: name 'unicode' is not defined
Test results change as follows...
before: FAILED (skips=106, failures=6, errors=182, successes=375)
after: FAILED (skips=106, failures=16, errors=273, successes=409)
---
bridgedb/distributors/email/server.py | 2 +-
bridgedb/test/email_helpers.py | 4 ++--
bridgedb/test/https_helpers.py | 4 ++--
bridgedb/test/moat_helpers.py | 4 ++--
bridgedb/test/test_captcha.py | 2 +-
bridgedb/test/test_email_dkim.py | 4 ++--
bridgedb/test/test_email_templates.py | 2 +-
bridgedb/test/test_persistent.py | 4 ++--
bridgedb/test/test_persistentSaveAndLoad.py | 4 ++--
bridgedb/test/test_txrecaptcha.py | 2 +-
10 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/bridgedb/distributors/email/server.py b/bridgedb/distributors/email/server.py
index 051ce74..c1ce56f 100644
--- a/bridgedb/distributors/email/server.py
+++ b/bridgedb/distributors/email/server.py
@@ -253,7 +253,7 @@ class SMTPMessage(object):
"""
rawMessage = io.StringIO()
for line in self.lines:
- rawMessage.writelines(unicode(line.decode('utf8')) + u'\n')
+ rawMessage.writelines(line.decode('utf8') + '\n')
rawMessage.seek(0)
return rfc822.Message(rawMessage)
diff --git a/bridgedb/test/email_helpers.py b/bridgedb/test/email_helpers.py
index 2fe8cdc..edc8196 100644
--- a/bridgedb/test/email_helpers.py
+++ b/bridgedb/test/email_helpers.py
@@ -52,7 +52,7 @@ EMAIL_FROM_ADDR = "bridges@localhost"
EMAIL_BIND_IP = "127.0.0.1"
EMAIL_PORT = 5225
-TEST_CONFIG_FILE = io.StringIO(unicode("""\
+TEST_CONFIG_FILE = io.StringIO("""\
EMAIL_DIST = %s
EMAIL_ROTATION_PERIOD = %s
EMAIL_INCLUDE_FINGERPRINTS = %s
@@ -96,7 +96,7 @@ EMAIL_PORT = %s
repr(EMAIL_N_BRIDGES_PER_ANSWER),
repr(EMAIL_FROM_ADDR),
repr(EMAIL_BIND_IP),
- repr(EMAIL_PORT))))
+ repr(EMAIL_PORT)))
def _createConfig(configFile=TEST_CONFIG_FILE):
diff --git a/bridgedb/test/https_helpers.py b/bridgedb/test/https_helpers.py
index 8c77085..ca268c9 100644
--- a/bridgedb/test/https_helpers.py
+++ b/bridgedb/test/https_helpers.py
@@ -50,7 +50,7 @@ CSP_ENABLED = True
CSP_REPORT_ONLY = True
CSP_INCLUDE_SELF = True
-TEST_CONFIG_FILE = io.StringIO(unicode("""\
+TEST_CONFIG_FILE = io.StringIO("""\
SERVER_PUBLIC_FQDN = %r
SERVER_PUBLIC_EXTERNAL_IP = %r
HTTPS_DIST = %r
@@ -100,7 +100,7 @@ CSP_INCLUDE_SELF = %r
GIMP_CAPTCHA_RSA_KEYFILE,
CSP_ENABLED,
CSP_REPORT_ONLY,
- CSP_INCLUDE_SELF)))
+ CSP_INCLUDE_SELF))
def _createConfig(configFile=TEST_CONFIG_FILE):
diff --git a/bridgedb/test/moat_helpers.py b/bridgedb/test/moat_helpers.py
index 8c40c82..236b529 100644
--- a/bridgedb/test/moat_helpers.py
+++ b/bridgedb/test/moat_helpers.py
@@ -48,7 +48,7 @@ MOAT_ROTATION_PERIOD = "3 hours"
MOAT_GIMP_CAPTCHA_HMAC_KEYFILE = 'moat_captcha_hmac_key'
MOAT_GIMP_CAPTCHA_RSA_KEYFILE = 'moat_captcha_rsa_key'
-TEST_CONFIG_FILE = io.StringIO(unicode("""\
+TEST_CONFIG_FILE = io.StringIO("""\
GIMP_CAPTCHA_DIR = %r
SERVER_PUBLIC_FQDN = %r
SUPPORTED_TRANSPORTS = %r
@@ -88,7 +88,7 @@ MOAT_GIMP_CAPTCHA_RSA_KEYFILE = %r
MOAT_N_IP_CLUSTERS,
MOAT_ROTATION_PERIOD,
MOAT_GIMP_CAPTCHA_HMAC_KEYFILE,
- MOAT_GIMP_CAPTCHA_RSA_KEYFILE)))
+ MOAT_GIMP_CAPTCHA_RSA_KEYFILE))
def _createConfig(configFile=TEST_CONFIG_FILE):
configuration = {}
diff --git a/bridgedb/test/test_captcha.py b/bridgedb/test/test_captcha.py
index 24a14a4..92cc716 100644
--- a/bridgedb/test/test_captcha.py
+++ b/bridgedb/test/test_captcha.py
@@ -291,7 +291,7 @@ class GimpCaptchaTests(unittest.TestCase):
c = captcha.GimpCaptcha(self.publik, self.sekrit, self.hmacKey,
self.cacheDir)
image, challenge = c.get()
- solution = unicode(c.answer)
+ solution = c.answer if isinstance(c.answer, str) else c.answer.decode('utf-8')
self.assertEquals(
c.check(challenge, solution, c.secretKey, c.hmacKey),
True)
diff --git a/bridgedb/test/test_email_dkim.py b/bridgedb/test/test_email_dkim.py
index be34370..e8fe3f3 100644
--- a/bridgedb/test/test_email_dkim.py
+++ b/bridgedb/test/test_email_dkim.py
@@ -46,8 +46,8 @@ get bridges
}
def _createMessage(self, messageString):
- """Create an ``rfc822.Message`` from a string."""
- messageIO = io.StringIO(unicode(messageString))
+ """Create an ``email.message.Message`` from a string."""
+ messageIO = io.StringIO(messageString if isinstance(messageString, str) else messageString.decode('utf-8'))
return rfc822.Message(messageIO)
def test_checkDKIM_good(self):
diff --git a/bridgedb/test/test_email_templates.py b/bridgedb/test/test_email_templates.py
index 8464fe9..4703019 100644
--- a/bridgedb/test/test_email_templates.py
+++ b/bridgedb/test/test_email_templates.py
@@ -27,7 +27,7 @@ class EmailTemplatesTests(unittest.TestCase):
"""Unittests for :func:`b.e.templates`."""
def setUp(self):
- self.t = NullTranslations(StringIO(unicode('test')))
+ self.t = NullTranslations(StringIO('test'))
self.client = Address('blackhole@xxxxxxxxxxxxxx')
self.answer = 'obfs3 1.1.1.1:1111\nobfs3 2.2.2.2:2222'
# This is the fingerprint of BridgeDB's offline, certification-only
diff --git a/bridgedb/test/test_persistent.py b/bridgedb/test/test_persistent.py
index 72b4b85..269cc86 100644
--- a/bridgedb/test/test_persistent.py
+++ b/bridgedb/test/test_persistent.py
@@ -33,9 +33,9 @@ from sure import the
from sure import expect
-TEST_CONFIG_FILE = io.StringIO(unicode("""\
+TEST_CONFIG_FILE = io.StringIO("""\
BRIDGE_FILES = ['bridge-descriptors', 'bridge-descriptors.new']
-LOGFILE = 'bridgedb.log'"""))
+LOGFILE = 'bridgedb.log'""")
class StateTest(unittest.TestCase):
diff --git a/bridgedb/test/test_persistentSaveAndLoad.py b/bridgedb/test/test_persistentSaveAndLoad.py
index 07ea73b..d01a536 100644
--- a/bridgedb/test/test_persistentSaveAndLoad.py
+++ b/bridgedb/test/test_persistentSaveAndLoad.py
@@ -28,9 +28,9 @@ from twisted.trial import unittest
from bridgedb import persistent
-TEST_CONFIG_FILE = io.StringIO(unicode("""\
+TEST_CONFIG_FILE = io.StringIO("""\
BRIDGE_FILES = ['bridge-descriptors', 'bridge-descriptors.new']
-LOGFILE = 'bridgedb.log'"""))
+LOGFILE = 'bridgedb.log'""")
class StateSaveAndLoadTests(unittest.TestCase):
diff --git a/bridgedb/test/test_txrecaptcha.py b/bridgedb/test/test_txrecaptcha.py
index 22505b9..fd7365f 100644
--- a/bridgedb/test/test_txrecaptcha.py
+++ b/bridgedb/test/test_txrecaptcha.py
@@ -270,7 +270,7 @@ class MiscTests(unittest.TestCase):
""":func:`txrecapcha._encodeIfNecessary` should convert unicode objects
into strings.
"""
- origString = unicode('abc')
+ origString = 'abc'
self.assertIsInstance(origString, unicode)
newString = txrecaptcha._encodeIfNecessary(origString)
self.assertIsInstance(newString, str)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits