From 81e04269fd7278eb36e4a95e72c07c19342f454e Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Sun, 29 Apr 2018 00:10:58 -0700 Subject: [PATCH] Remove ratelimit library --- lib/ratelimit/__init__.py | 59 --------------------------------------- lib/ratelimit/version.py | 9 ------ 2 files changed, 68 deletions(-) delete mode 100644 lib/ratelimit/__init__.py delete mode 100644 lib/ratelimit/version.py diff --git a/lib/ratelimit/__init__.py b/lib/ratelimit/__init__.py deleted file mode 100644 index 115a65dd..00000000 --- a/lib/ratelimit/__init__.py +++ /dev/null @@ -1,59 +0,0 @@ -from math import floor - -import time -import sys -import threading -import functools - - -def clamp(value): - ''' - Clamp integer between 1 and max - - There must be at least 1 method invocation - made over the time period. Make sure the - value passed is at least 1 and is not a - fraction of an invocation. - - :param float value: The number of method invocations. - :return: Clamped number of invocations. - :rtype: int - ''' - return max(1, min(sys.maxsize, floor(value))) - - -class RateLimitDecorator: - def __init__(self, period=1, every=1.0): - self.frequency = abs(every) / float(clamp(period)) - self.last_called = 0.0 - self.lock = threading.RLock() - - def __call__(self, func): - ''' - Extend the behaviour of the following - function, forwarding method invocations - if the time window hes elapsed. - - :param function func: The function to decorate. - :return: Decorated function. - :rtype: function - ''' - @functools.wraps(func) - def wrapper(*args, **kwargs): - '''Decorator wrapper function''' - with self.lock: - elapsed = time.time() - self.last_called - left_to_wait = self.frequency - elapsed - if left_to_wait > 0: - time.sleep(left_to_wait) - self.last_called = time.time() - return func(*args, **kwargs) - return wrapper - - -rate_limited = RateLimitDecorator - - -__all__ = [ - 'rate_limited' -] diff --git a/lib/ratelimit/version.py b/lib/ratelimit/version.py deleted file mode 100644 index 68a84cc9..00000000 --- a/lib/ratelimit/version.py +++ /dev/null @@ -1,9 +0,0 @@ -class Version(object): - '''Version of the package''' - - def __setattr__(self, *args): - raise TypeError('cannot modify immutable instance') - __delattr__ = __setattr__ - - def __init__(self, num): - super(Version, self).__setattr__('number', num)