[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/develop] Revert "Remove clear abuses of str.strip() and str.rstrip()"



commit 9a4cf49b975fd219bac868884bd573f705bf629e
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Wed May 6 20:22:14 2015 +0000

    Revert "Remove clear abuses of str.strip() and str.rstrip()"
    
    This reverts commit 4e773f346f2b442a1726af94b7b2da231b73c1d6.
---
 lib/bridgedb/Bridges.py                       |    3 +--
 lib/bridgedb/bridges.py                       |    6 ++----
 lib/bridgedb/test/test_Main.py                |    3 +--
 lib/bridgedb/test/test_Tests.py               |    3 +--
 lib/bridgedb/test/test_bridgedb.py            |    3 +--
 lib/bridgedb/test/test_captcha.py             |    7 +++----
 lib/bridgedb/test/test_configure.py           |    3 +--
 lib/bridgedb/test/test_crypto.py              |    3 +--
 lib/bridgedb/test/test_email_autoresponder.py |    3 +--
 lib/bridgedb/test/test_https.py               |    3 +--
 lib/bridgedb/test/test_smtp.py                |    3 +--
 lib/bridgedb/util.py                          |    9 ---------
 12 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/lib/bridgedb/Bridges.py b/lib/bridgedb/Bridges.py
index eb39d47..58a81cd 100644
--- a/lib/bridgedb/Bridges.py
+++ b/lib/bridgedb/Bridges.py
@@ -29,7 +29,6 @@ from bridgedb.parse.fingerprint import toHex
 from bridgedb.parse.fingerprint import fromHex
 from bridgedb.parse.fingerprint import isValidFingerprint
 from bridgedb.safelog import logSafely
-from bridgedb.util import remove_prefix
 
 try:
     from cStringIO import StringIO
@@ -651,7 +650,7 @@ class FilteredBridgeSplitter(BridgeHolder):
         subringName = [self.distributorName]
         for filterName in filterNames:
             if filterName != 'filterAssignBridgesToRing':
-                subringName.append(remove_prefix(filterName, 'filterBridgesBy'))
+                subringName.append(filterName.strip('filterBridgesBy'))
         subringName = '-'.join([x for x in subringName])
         subring.setName(subringName)
 
diff --git a/lib/bridgedb/bridges.py b/lib/bridgedb/bridges.py
index 6ea7d3f..2922fa1 100644
--- a/lib/bridgedb/bridges.py
+++ b/lib/bridgedb/bridges.py
@@ -38,8 +38,6 @@ from bridgedb.parse.fingerprint import isValidFingerprint
 from bridgedb.parse.fingerprint import toHex
 from bridgedb.parse.fingerprint import fromHex
 from bridgedb.parse.nickname import isValidRouterNickname
-from bridgedb.util import remove_prefix
-from bridgedb.util import remove_suffix
 
 
 class PluggableTransportUnavailable(Exception):
@@ -1499,8 +1497,8 @@ class Bridge(BridgeBackwardsCompatibility):
             sequence = asn1.DerSequence()
 
             key = self.signingKey
-            key = remove_prefix(key, TOR_SIGNING_KEY_HEADER)
-            key = remove_suffix(key, TOR_SIGNING_KEY_FOOTER)
+            key = key.strip(TOR_SIGNING_KEY_HEADER)
+            key = key.strip(TOR_SIGNING_KEY_FOOTER)
             key = key.replace('\n', '')
             key = base64.b64decode(key)
 
diff --git a/lib/bridgedb/test/test_Main.py b/lib/bridgedb/test/test_Main.py
index 6c603fb..5ae4025 100644
--- a/lib/bridgedb/test/test_Main.py
+++ b/lib/bridgedb/test/test_Main.py
@@ -29,14 +29,13 @@ from twisted.trial import unittest
 from bridgedb import Main
 from bridgedb.Bridges import BridgeHolder
 from bridgedb.parse.options import parseOptions
-from bridgedb.util import remove_suffix
 
 
 logging.getLogger().disabled = True
 
 
 HERE = os.getcwd()
-TOPDIR = remove_suffix(HERE, '_trial_temp')
+TOPDIR = HERE.rstrip('_trial_temp')
 CI_RUNDIR = os.path.join(TOPDIR, 'run')
 
 # A networkstatus descriptor with two invalid ORAddress (127.0.0.1 and ::1)
diff --git a/lib/bridgedb/test/test_Tests.py b/lib/bridgedb/test/test_Tests.py
index 01fc1ca..84c3f8b 100644
--- a/lib/bridgedb/test/test_Tests.py
+++ b/lib/bridgedb/test/test_Tests.py
@@ -29,7 +29,6 @@ from twisted.trial import unittest
 
 from bridgedb.test import legacy_Tests as Tests
 from bridgedb.test import deprecated
-from bridgedb.util import remove_suffix
 
 
 warnings.filterwarnings('ignore', module="bridgedb\.test\.legacy_Tests")
@@ -181,7 +180,7 @@ class DynamicTestCaseMeta(type):
                     origFunc = origName.split('.')[-2:]
                     origName = '_'.join(origFunc)
                 if origName.endswith('_py'):  # this happens with doctests
-                    origName = remove_suffix(origName, '_py')
+                    origName = origName.strip('_py')
                 methName = str(methodPrefix + origName).replace('.', '_')
                 meth = testMethodFactory(test, methName)
                 logging.debug("Set %s.%s=%r" % (cls.__name__, methName, meth))
diff --git a/lib/bridgedb/test/test_bridgedb.py b/lib/bridgedb/test/test_bridgedb.py
index 301309a..70c71f0 100644
--- a/lib/bridgedb/test/test_bridgedb.py
+++ b/lib/bridgedb/test/test_bridgedb.py
@@ -23,7 +23,6 @@ from twisted.trial.unittest import SkipTest
 
 from bridgedb.test.util import processExists
 from bridgedb.test.util import getBridgeDBPID
-from bridgedb.util import remove_suffix
 
 
 class BridgeDBCliTest(unittest.TestCase):
@@ -31,7 +30,7 @@ class BridgeDBCliTest(unittest.TestCase):
 
     def setUp(self):
         here = os.getcwd()
-        topdir = remove_suffix(here, '_trial_temp')
+        topdir = here.rstrip('_trial_temp')
         self.rundir = os.path.join(topdir, 'run')
         self.pidfile = os.path.join(self.rundir, 'bridgedb.pid')
         self.pid = getBridgeDBPID(self.pidfile)
diff --git a/lib/bridgedb/test/test_captcha.py b/lib/bridgedb/test/test_captcha.py
index 4db476d..1000477 100644
--- a/lib/bridgedb/test/test_captcha.py
+++ b/lib/bridgedb/test/test_captcha.py
@@ -23,7 +23,6 @@ from zope.interface import providedBy
 
 from bridgedb import captcha
 from bridgedb import crypto
-from bridgedb.util import remove_suffix
 
 
 class CaptchaTests(unittest.TestCase):
@@ -98,7 +97,7 @@ class GimpCaptchaTests(unittest.TestCase):
 
     def setUp(self):
         here             = os.getcwd()
-        self.topDir      = remove_suffix(here, '_trial_temp')
+        self.topDir      = here.rstrip('_trial_temp')
         self.cacheDir    = os.path.join(self.topDir, 'captchas')
         self.badCacheDir = os.path.join(here, 'capt')
 
@@ -132,7 +131,7 @@ class GimpCaptchaTests(unittest.TestCase):
         """GimpCaptcha with bad cacheDir should raise GimpCaptchaError."""
         self.assertRaises(captcha.GimpCaptchaError, captcha.GimpCaptcha,
                           self.publik, self.sekrit, self.hmacKey,
-                          remove_suffix(self.cacheDir, 'chas'))
+                          self.cacheDir.rstrip('chas'))
 
     def test_init(self):
         """Test that __init__ correctly initialised all the values."""
@@ -239,7 +238,7 @@ class GimpCaptchaTests(unittest.TestCase):
         c = captcha.GimpCaptcha(self.publik, self.sekrit, self.hmacKey,
                                 self.cacheDir)
         image, challenge = c.get()
-        challengeBadB64 = remove_suffix(challenge, '==') + "\x42\x42\x42"
+        challengeBadB64 = challenge.rstrip('==') + "\x42\x42\x42"
         self.assertEquals(
             c.check(challenge, c.answer, c.secretKey, c.hmacKey),
             True)
diff --git a/lib/bridgedb/test/test_configure.py b/lib/bridgedb/test/test_configure.py
index c70e7de..ebac95a 100644
--- a/lib/bridgedb/test/test_configure.py
+++ b/lib/bridgedb/test/test_configure.py
@@ -16,7 +16,6 @@ import os
 from twisted.trial import unittest
 
 from bridgedb import configure
-from bridgedb.util import remove_suffix
 
 
 class ConfigureTests(unittest.TestCase):
@@ -25,7 +24,7 @@ class ConfigureTests(unittest.TestCase):
     def setUp(self):
         """Find the config file in the top directory of this repo."""
         here = os.getcwd()
-        topdir = remove_suffix(here, '_trial_temp')
+        topdir = here.rstrip('_trial_temp')
         self.configFilename = os.path.join(topdir, 'bridgedb.conf')
 
     def test_loadConfig_with_file(self):
diff --git a/lib/bridgedb/test/test_crypto.py b/lib/bridgedb/test/test_crypto.py
index a10dde9..3264ace 100644
--- a/lib/bridgedb/test/test_crypto.py
+++ b/lib/bridgedb/test/test_crypto.py
@@ -35,7 +35,6 @@ from bridgedb import txrecaptcha
 from bridgedb.persistent import Conf
 from bridgedb.test.util import fileCheckDecorator
 from bridgedb.test.email_helpers import _createConfig
-from bridgedb.util import remove_suffix
 
 
 logging.disable(50)
@@ -101,7 +100,7 @@ class InitializeGnuPGTests(unittest.TestCase):
         :returns: The full path to the new gnupg home directory.
         """
         here         = os.getcwd()
-        topDir       = remove_suffix(here, '_trial_temp')
+        topDir       = here.rstrip('_trial_temp')
         gnupghome    = os.path.join(topDir, '.gnupg')
         gnupghomeNew = os.path.join(here, '.gnupg')
 
diff --git a/lib/bridgedb/test/test_email_autoresponder.py b/lib/bridgedb/test/test_email_autoresponder.py
index 4c36be4..2895802 100644
--- a/lib/bridgedb/test/test_email_autoresponder.py
+++ b/lib/bridgedb/test/test_email_autoresponder.py
@@ -29,7 +29,6 @@ from bridgedb.Dist import TooSoonEmail
 from bridgedb.test.email_helpers import _createConfig
 from bridgedb.test.email_helpers import _createMailServerContext
 from bridgedb.test.email_helpers import DummyEmailDistributorWithState
-from bridgedb.util import remove_suffix
 
 
 class CreateResponseBodyTests(unittest.TestCase):
@@ -37,7 +36,7 @@ class CreateResponseBodyTests(unittest.TestCase):
 
     def _moveGPGTestKeyfile(self):
         here          = os.getcwd()
-        topDir        = remove_suffix(here, '_trial_temp')
+        topDir        = here.rstrip('_trial_temp')
         self.gpgFile  = os.path.join(topDir, '.gnupg', 'TESTING.subkeys.sec')
         self.gpgMoved = os.path.join(here, 'TESTING.subkeys.sec')
         shutil.copy(self.gpgFile, self.gpgMoved)
diff --git a/lib/bridgedb/test/test_https.py b/lib/bridgedb/test/test_https.py
index fb88abe..1e0c778 100644
--- a/lib/bridgedb/test/test_https.py
+++ b/lib/bridgedb/test/test_https.py
@@ -37,7 +37,6 @@ from twisted.trial.unittest import SkipTest
 
 from bridgedb.test.util import processExists
 from bridgedb.test.util import getBridgeDBPID
-from bridgedb.util import remove_suffix
 
 HTTP_ROOT = 'http://127.0.0.1:6788'
 CAPTCHA_RESPONSE = 'Tvx74Pmy'
@@ -46,7 +45,7 @@ CAPTCHA_RESPONSE = 'Tvx74Pmy'
 class HTTPTests(unittest.TestCase):
     def setUp(self):
         here = os.getcwd()
-        topdir = remove_suffix(here, '_trial_temp')
+        topdir = here.rstrip('_trial_temp')
         self.rundir = os.path.join(topdir, 'run')
         self.pidfile = os.path.join(self.rundir, 'bridgedb.pid')
         self.pid = getBridgeDBPID(self.pidfile)
diff --git a/lib/bridgedb/test/test_smtp.py b/lib/bridgedb/test/test_smtp.py
index b4cf8f9..1cbafba 100644
--- a/lib/bridgedb/test/test_smtp.py
+++ b/lib/bridgedb/test/test_smtp.py
@@ -17,7 +17,6 @@ from twisted.trial.unittest import SkipTest
 
 from bridgedb.test.util import processExists
 from bridgedb.test.util import getBridgeDBPID
-from bridgedb.util import remove_suffix
 
 # ------------- SMTP Client Config
 SMTP_DEBUG_LEVEL = 0  # set to 1 to see SMTP message exchange
@@ -119,7 +118,7 @@ class SMTPTests(unittest.TestCase):
         running.
         '''
         here = os.getcwd()
-        topdir = remove_suffix(here, '_trial_temp')
+        topdir = here.rstrip('_trial_temp')
         self.rundir = os.path.join(topdir, 'run')
         self.pidfile = os.path.join(self.rundir, 'bridgedb.pid')
         self.pid = getBridgeDBPID(self.pidfile)
diff --git a/lib/bridgedb/util.py b/lib/bridgedb/util.py
index e6ecbd1..f3d87bd 100644
--- a/lib/bridgedb/util.py
+++ b/lib/bridgedb/util.py
@@ -302,12 +302,3 @@ class mixin:
         expect mixin classes to end in ``'mixin'``.
     """
     __metaclass__ = abc.ABCMeta
-
-def remove_prefix(s, f):
-    assert s.startswith(f)
-    return s[len(f):]
-
-def remove_suffix(s, f):
-    assert s.endswith(f)
-    return s[:-len(f)]
-



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits