summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2020-10-06 14:16:20 -0400
committerEli Collins <elic@assurancetechnologies.com>2020-10-06 14:16:20 -0400
commit582508faa9eb193bd6941c3d484cc75eff8f2cc0 (patch)
treea478d62d91a70450184ab5a9d22cf6b5be1d49d0
parent65f4a25efd41639552df52dba40bfc377ae00871 (diff)
downloadpasslib-582508faa9eb193bd6941c3d484cc75eff8f2cc0.tar.gz
cleanup old python compat -- removed some sys.version_info refs
-rw-r--r--passlib/tests/test_totp.py22
-rw-r--r--passlib/totp.py14
2 files changed, 6 insertions, 30 deletions
diff --git a/passlib/tests/test_totp.py b/passlib/tests/test_totp.py
index 1d81f0b..4dc16ed 100644
--- a/passlib/tests/test_totp.py
+++ b/passlib/tests/test_totp.py
@@ -3,6 +3,7 @@
# imports
#=============================================================================
# core
+from binascii import Error as DecodeError
import datetime
from functools import partial
import logging; log = logging.getLogger(__name__)
@@ -25,16 +26,6 @@ __all__ = [
# helpers
#=============================================================================
-# XXX: python 3 changed what error base64.b16decode() throws, from TypeError to base64.Error().
-# it wasn't until 3.3 that base32decode() also got changed.
-# really should normalize this in the code to a single BinaryDecodeError,
-# predicting this cross-version is getting unmanagable.
-Base32DecodeError = Base16DecodeError = TypeError
-if sys.version_info >= (3,0):
- from binascii import Error as Base16DecodeError
-if sys.version_info >= (3,3):
- from binascii import Error as Base32DecodeError
-
PASS1 = "abcdef"
PASS2 = b"\x00\xFF"
KEY1 = '4AOGGDBBQSYHNTUZ'
@@ -629,13 +620,13 @@ class TotpTest(TestCase):
self.assertEqual(TOTP(' 4aog gdbb qsyh ntuz ').key, KEY1_RAW)
# .. w/ invalid char
- self.assertRaises(Base32DecodeError, TOTP, 'ao!ggdbbqsyhntuz')
+ self.assertRaises(DecodeError, TOTP, 'ao!ggdbbqsyhntuz')
# handle hex encoding
self.assertEqual(TOTP('e01c630c2184b076ce99', 'hex').key, KEY1_RAW)
# .. w/ invalid char
- self.assertRaises(Base16DecodeError, TOTP, 'X01c630c2184b076ce99', 'hex')
+ self.assertRaises(DecodeError, TOTP, 'X01c630c2184b076ce99', 'hex')
# handle raw bytes
self.assertEqual(TOTP(KEY1_RAW, "raw").key, KEY1_RAW)
@@ -1278,8 +1269,8 @@ class TotpTest(TestCase):
self.assertRaises(ValueError, from_uri, "otpauth://totp/Example:alice@google.com?digits=6")
# undecodable secret
- self.assertRaises(Base32DecodeError, from_uri, "otpauth://totp/Example:alice@google.com?"
- "secret=JBSWY3DPEHP@3PXP")
+ self.assertRaises(DecodeError, from_uri, "otpauth://totp/Example:alice@google.com?"
+ "secret=JBSWY3DPEHP@3PXP")
#--------------------------------------------------------------------------------
# label param
@@ -1468,8 +1459,7 @@ class TotpTest(TestCase):
self.assertRaises(ValueError, from_dict, dict(v=1, type="totp"))
# undecodable secret
- self.assertRaises(Base32DecodeError, from_dict,
- dict(v=1, type="totp", key="JBSWY3DPEHP@3PXP"))
+ self.assertRaises(DecodeError, from_dict, dict(v=1, type="totp", key="JBSWY3DPEHP@3PXP"))
#--------------------------------------------------------------------------------
# label & issuer params
diff --git a/passlib/totp.py b/passlib/totp.py
index b636c51..1835632 100644
--- a/passlib/totp.py
+++ b/passlib/totp.py
@@ -54,20 +54,6 @@ __all__ = [
]
#=============================================================================
-# HACK: python < 2.7.4's urlparse() won't parse query strings unless the url scheme
-# is one of the schemes in the urlparse.uses_query list. 2.7 abandoned
-# this, and parses query if present, regardless of the scheme.
-# as a workaround for older versions, we add "otpauth" to the known list.
-# this was fixed by https://bugs.python.org/issue9374, in 2.7.4 release.
-#=============================================================================
-if sys.version_info < (2,7,4):
- from urlparse import uses_query
- if "otpauth" not in uses_query:
- uses_query.append("otpauth")
- log.debug("registered 'otpauth' scheme with urlparse.uses_query")
- del uses_query
-
-#=============================================================================
# internal helpers
#=============================================================================