Kelvin Wong avatar Kelvin Wong committed 2630b11 Draft

Minor style changes

Comments (0)

Files changed (3)

django_scrypt/hashers.py

 """Create and store Scrypt message digests
 """
 from __future__ import unicode_literals
+import re
+import sys
 from django.contrib.auth.hashers import BasePasswordHasher, mask_hash
 from django.utils.datastructures import SortedDict
 from django.utils.crypto import constant_time_compare
 from django.utils.translation import ugettext_noop as _
 
 import scrypt
-import re
-import sys
+
+
 PYTHON3 = sys.version_info >= (3, 0)
 
+
 class ScryptPasswordHasher(BasePasswordHasher):
     """
     A secure password hasher using the Scrypt algorithm
         return re.sub(self.WHITESPACE, self.EMPTY, s)
 
     def liststringify(self, x):
-        return [ self.stringify(i) for i in x ]
+        return [self.stringify(i) for i in x]
 
     def verify(self, password, encoded):
         """

tests/test_django_scrypt.py

 class TestScrypt(TestCase):
 
     def setUp(self):
-        scrypt_hashers = ("django_scrypt.hashers.ScryptPasswordHasher",) + default_hashers
+        scrypt_hashers = (
+            "django_scrypt.hashers.ScryptPasswordHasher",) + default_hashers
         load_hashers(password_hashers=scrypt_hashers)
         self.password = 'letmein'
-        self.unicode_text = utf8(b'\xe1\x93\x84\xe1\x93\x87\xe1\x95\x97\xe1\x92\xbb\xe1\x92\xa5\xe1\x90\x85\xe1\x91\xa6')
+        self.unicode_text = utf8(
+            b'\xe1\x93\x84\xe1\x93\x87\xe1\x95\x97\xe1\x92\xbb\xe1\x92\xa5\xe1'
+            b'\x90\x85\xe1\x91\xa6')
         self.bad_password = 'letmeinz'
         self.expected_hash_prefix = "scrypt"
-        self.old_format_encoded_hash = "scrypt$FYY1dftUuK0b$16384$8$1$64$/JYOBEED7nMzJgvlqfzDj1JKGVLup0eYLyG39WA2KCywgnB1ubN0uzFYyaEQthINm6ynjjqr+D+U\nw5chi74WVw=="
-        self.old_format_fix_encoded_hash = "scrypt$FYY1dftUuK0b$14$8$1$64$/JYOBEED7nMzJgvlqfzDj1JKGVLup0eYLyG39WA2KCywgnB1ubN0uzFYyaEQthINm6ynjjqr+D+U\nw5chi74WVw=="
-        self.encoded_hash = "scrypt$gwQg9TZ3eyub$14$8$1$64$lQhi3+c0xkYDUj35BvS6jVTlHRAH/RS4nkpd1tKMc0r9PcFyjCjPj1k9/CkSCRvcTvHiWfFYpHfB\nZDCHMNIeHA=="
+        self.old_format_encoded_hash = (
+            "scrypt$FYY1dftUuK0b$16384$8$1$64$/JYOBEED7nMzJgvlqfzDj1JKGVLup0e"
+            "YLyG39WA2KCywgnB1ubN0uzFYyaEQthINm6ynjjqr+D+U\nw5chi74WVw==")
+        self.old_format_fix_encoded_hash = (
+            "scrypt$FYY1dftUuK0b$14$8$1$64$/JYOBEED7nMzJgvlqfzDj1JKGVLup0eYLy"
+            "G39WA2KCywgnB1ubN0uzFYyaEQthINm6ynjjqr+D+U\nw5chi74WVw==")
+        self.encoded_hash = (
+            "scrypt$gwQg9TZ3eyub$14$8$1$64$lQhi3+c0xkYDUj35BvS6jVTlHRAH/RS4nk"
+            "pd1tKMc0r9PcFyjCjPj1k9/CkSCRvcTvHiWfFYpHfB\nZDCHMNIeHA==")
 
     def test_version_string_set(self):
         """Test for version string on package"""
         self.assertTrue(len(django_scrypt.__version__) > 0)
 
     def test_encoder_default_hash_less_than_128_characters(self):
-        """Test that returned encoded hash is less than db limit of 128 characters"""
+        """Test that returned encoded hash is less than db limit of 128
+        characters
+        """
         encoded = make_password(self.password)
         self.assertTrue(len(encoded) < 128)
 
         self.assertTrue(is_password_usable(encoded))
 
     def test_encoder_hash_starts_with_algorithm_string(self):
-        """Test that encoded hash string has correct prefix with first separator"""
+        """Test that encoded hash string has correct prefix with first
+        separator
+        """
         encoded = make_password(self.password)
         self.assertTrue(encoded.startswith(self.expected_hash_prefix + "$"))
 
         self.assertTrue(len(h))
 
     def test_safe_summary_has_required_sections(self):
-        """Test safe_summary returns string with required informative sections"""
+        """Test safe_summary returns string with required informative
+        sections
+        """
         encoded = make_password(self.password)
         hasher = get_hasher('scrypt')
         d = hasher.safe_summary(encoded)
     def test_verify_old_hash_format_raises_error(self):
         """Ensure deprecated, old encoded hash format raises an Exception
 
-        The old format hashes store N == 16384 whereas new format store Nexp == 14.
+        The old-format hashes store N == 16384 whereas new format stores
+        Nexp == 14.
+
         The fix is to replace 16384 with 14 in each hash.
         """
         with self.assertRaises(Exception) as cm:
 
         Specifically, replace 16384 with 14 at position 3 of the encoded hash
         """
-        self.assertTrue(check_password(self.password, self.old_format_fix_encoded_hash))
+        self.assertTrue(check_password(self.password,
+                                       self.old_format_fix_encoded_hash))
 
     def test_class_algorithm_string_matches_expected(self):
-        """Test django_scrypt algorithm string matches expected value 'scrypt'"""
-        self.assertEqual(ScryptPasswordHasher.algorithm, self.expected_hash_prefix)
+        """Test django_scrypt algorithm string matches expected value
+        'scrypt'
+        """
+        self.assertEqual(ScryptPasswordHasher.algorithm,
+                         self.expected_hash_prefix)
 
     def test_no_upgrade_on_incorrect_pass(self):
         self.assertEqual('scrypt', get_hasher('default').algorithm)
 
             def setter():
                 state['upgraded'] = True
-            self.assertFalse(check_password(self.bad_password, encoded, setter))
+            self.assertFalse(check_password(self.bad_password,
+                                            encoded, setter))
             self.assertFalse(state['upgraded'])
 
     def test_no_upgrade(self):

tests/test_subclassing.py

         self.assertTrue(check_password(self.password, encoded))
 
     def test_LongTimeScryptHasher_takes_long_time(self):
-        """Test operation of the extended time hasher uses more time than default"""
+        """Test operation of the extended time hasher uses more time than
+        default
+        """
         start = time.clock()
         encoded = make_password(self.password, hasher='scrypt')
         self.assertTrue(check_password(self.password, encoded))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.