diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2012-01-05 21:42:45 -0500 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2012-01-05 21:42:45 -0500 |
| commit | e6f618be80f36b9a7b1d4eed97e39c927120ea2e (patch) | |
| tree | 47442f253f4cfb26e1676b35b49556fe79f59492 | |
| parent | f7a33447fec5219842c15eef560ca067f4ec06c3 (diff) | |
| download | passlib-e6f618be80f36b9a7b1d4eed97e39c927120ea2e.tar.gz | |
renamed utils.timer -> utils.tick
| -rw-r--r-- | passlib/context.py | 6 | ||||
| -rw-r--r-- | passlib/tests/test_context.py | 10 | ||||
| -rw-r--r-- | passlib/utils/__init__.py | 8 |
3 files changed, 12 insertions, 12 deletions
diff --git a/passlib/context.py b/passlib/context.py index 03cfc7b..48b6b7d 100644 --- a/passlib/context.py +++ b/passlib/context.py @@ -24,7 +24,7 @@ except ImportError: from passlib.registry import get_crypt_handler, _validate_handler_name from passlib.utils import to_bytes, to_unicode, bytes, \ is_crypt_handler, rng, \ - PasslibPolicyWarning, timer, saslprep + PasslibPolicyWarning, tick, saslprep from passlib.utils.compat import is_mapping, iteritems, num_types, \ PY3, PY_MIN_32, unicode, bytes from passlib.utils.compat.aliases import SafeConfigParser, StringIO, BytesIO @@ -1032,9 +1032,9 @@ class _CryptRecord(object): "verify helper - adds min_verify_time delay" mvt = self._min_verify_time assert mvt - start = timer() + start = tick() ok = self.handler.verify(secret, hash, **context) - end = timer() + end = tick() delta = mvt + start - end if delta > 0: sleep(delta) diff --git a/passlib/tests/test_context.py b/passlib/tests/test_context.py index a6f9f60..bb2f78c 100644 --- a/passlib/tests/test_context.py +++ b/passlib/tests/test_context.py @@ -18,7 +18,7 @@ except ImportError: #pkg from passlib import hash from passlib.context import CryptContext, CryptPolicy, LazyCryptContext -from passlib.utils import to_bytes, to_unicode, PasslibPolicyWarning +from passlib.utils import to_bytes, to_unicode, PasslibPolicyWarning, tick from passlib.utils.compat import irange, u import passlib.utils.handlers as uh from passlib.tests.utils import TestCase, mktemp, catch_warnings, \ @@ -917,8 +917,8 @@ class CryptContextTest(TestCase): def test_24_min_verify_time(self): "test verify() honors min_verify_time" - #NOTE: this whole test assumes time.sleep() and time.time() - # have at least 1ms accuracy + #NOTE: this whole test assumes time.sleep() and tick() + # have better than 100ms accuracy - set via delta. delta = .1 min_delay = delta min_verify_time = min_delay + 2*delta @@ -941,9 +941,9 @@ class CryptContextTest(TestCase): cc = CryptContext([TimedHash], min_verify_time=min_verify_time) def timecall(func, *args, **kwds): - start = time.time() + start = tick() result = func(*args, **kwds) - end = time.time() + end = tick() return end-start, result #verify hashing works diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index 1782759..d0dfc5f 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -51,7 +51,7 @@ __all__ = [ "xor_bytes", #random - 'timer', + 'tick', 'rng', 'getrandbytes', 'getrandstr', @@ -803,13 +803,13 @@ def adapted_b64_decode(data, sixthree="."): #randomness #================================================================================= -# pick best timer function to expose as "timer" - lifted from timeit module. +# pick best timer function to expose as "tick" - lifted from timeit module. if sys.platform == "win32": # On Windows, the best timer is time.clock() - from time import clock as timer + from time import clock as tick else: # On most other platforms the best timer is time.time() - from time import time as timer + from time import time as tick # works but not used ##def _get_timer_resolution(timer=timer, repeat=3): |
