Skip to content

Commit

Permalink
Merge 5d17594 into 37072f8
Browse files Browse the repository at this point in the history
  • Loading branch information
alisaifee committed May 19, 2020
2 parents 37072f8 + 5d17594 commit ffd6bcd
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 259 deletions.
11 changes: 9 additions & 2 deletions limits/__init__.py
Expand Up @@ -2,12 +2,19 @@
Rate limiting utilities
"""
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions

from .limits import (
RateLimitItem, RateLimitItemPerYear, RateLimitItemPerMonth,
RateLimitItemPerDay, RateLimitItemPerHour, RateLimitItemPerMinute,
RateLimitItemPerSecond
)
from .util import parse, parse_many

__version__ = get_versions()['version']
del get_versions

__all__ = [
"RateLimitItem", "RateLimitItemPerYear", "RateLimitItemPerMonth",
"RateLimitItemPerDay", "RateLimitItemPerHour", "RateLimitItemPerMinute",
"RateLimitItemPerSecond", "parse", "parse_many"
]
193 changes: 0 additions & 193 deletions limits/backports/counter.py

This file was deleted.

32 changes: 0 additions & 32 deletions limits/backports/total_ordering.py

This file was deleted.

7 changes: 2 additions & 5 deletions limits/limits.py
Expand Up @@ -3,10 +3,7 @@
"""
from six import add_metaclass

try:
from functools import total_ordering
except ImportError: # pragma: no cover
from .backports.total_ordering import total_ordering # pragma: no cover
from functools import total_ordering


def safe_string(value):
Expand Down Expand Up @@ -41,7 +38,7 @@ def __new__(cls, name, parents, dct):
return granularity


#pylint: disable=no-member
# pylint: disable=no-member
@add_metaclass(RateLimitItemMeta)
@total_ordering
class RateLimitItem(object):
Expand Down
19 changes: 7 additions & 12 deletions limits/storage.py
Expand Up @@ -6,10 +6,7 @@

from six.moves import urllib

try:
from collections import Counter
except ImportError: # pragma: no cover
from .backports.counter import Counter # pragma: no cover
from collections import Counter

import threading
import time
Expand Down Expand Up @@ -144,8 +141,8 @@ def __expire_events(self):
for event in list(self.events[key]):
with event:
if (
event.expiry <= time.time() and
event in self.events[key]
event.expiry <= time.time()
and event in self.events[key]
):
self.events[key].remove(event)
for key in list(self.expirations.keys()):
Expand Down Expand Up @@ -404,7 +401,7 @@ def __init__(self, uri, **options):
`rediss://[:password]@host:port`, `redis+unix:///path/to/sock` etc.
This uri is passed directly to :func:`redis.from_url` except for the
case of `redis+unix` where it is replaced with `unix`.
:param \*\*options: all remaining keyword arguments are passed
:param options: all remaining keyword arguments are passed
directly to the constructor of :class:`redis.Redis`
:raise ConfigurationError: when the redis library is not available
"""
Expand Down Expand Up @@ -510,7 +507,7 @@ def __init__(self, uri, service_name=None, **options):
"""
:param str uri: url of the form `redis+sentinel://host:port,host:port/service_name`
:param str service_name, optional: sentinel service name (if not provided in `uri`)
:param \*\*options: all remaining keyword arguments are passed
:param options: all remaining keyword arguments are passed
directly to the constructor of :class:`redis.sentinel.Sentinel`
:raise ConfigurationError: when the redis library is not available
or if the redis master host cannot be pinged.
Expand Down Expand Up @@ -553,7 +550,6 @@ def get(self, key):
"""
return super(RedisStorage, self).get(key, self.storage_slave)


def get_expiry(self, key):
"""
:param str key: the key to get the expiry for
Expand All @@ -578,7 +574,7 @@ class RedisClusterStorage(RedisStorage):
def __init__(self, uri, **options):
"""
:param str uri: url of the form `redis+cluster://[:password]@host:port,host:port`
:param \*\*options: all remaining keyword arguments are passed
:param options: all remaining keyword arguments are passed
directly to the constructor of :class:`rediscluster.RedisCluster`
:raise ConfigurationError: when the rediscluster library is not available
or if the redis host cannot be pinged.
Expand Down Expand Up @@ -631,7 +627,7 @@ def __init__(self, uri, **options):
"""
:param str uri: memcached location of the form
`memcached://host:port,host:port`, `memcached:///var/tmp/path/to/sock`
:param \*\*options: all remaining keyword arguments are passed
:param options: all remaining keyword arguments are passed
directly to the constructor of :class:`pymemcache.client.base.Client`
:raise ConfigurationError: when `pymemcache` is not available or memcached
location cannot be parsed.
Expand Down Expand Up @@ -696,7 +692,6 @@ def storage(self):

return self.local_storage.storage


def get(self, key):
"""
:param str key: the key to get the counter value for
Expand Down
2 changes: 1 addition & 1 deletion limits/strategies.py
Expand Up @@ -5,7 +5,6 @@
from abc import ABCMeta, abstractmethod
import weakref
import six
import time


@six.add_metaclass(ABCMeta)
Expand Down Expand Up @@ -53,6 +52,7 @@ def get_window_stats(self, item, *identifiers):
def clear(self, item, *identifiers):
return self.storage().clear(item.key_for(*identifiers))


class MovingWindowRateLimiter(RateLimiter):
"""
Reference: :ref:`moving-window`
Expand Down
4 changes: 2 additions & 2 deletions requirements/ci.txt
@@ -1,2 +1,2 @@
-r test.txt
coveralls
-r dev.txt
coveralls
2 changes: 1 addition & 1 deletion requirements/dev.txt
@@ -1,4 +1,4 @@
-r ci.txt
-r test.txt
flake8
keyring
twine
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -31,5 +31,5 @@
classifiers=[k for k in open('CLASSIFIERS').read().split('\n') if k],
description='Rate limiting utilities',
long_description=open('README.rst').read(),
packages=find_packages(exclude=['google.*','google', 'tests*']),
packages=find_packages(exclude=['google.*', 'google', 'tests*']),
)

0 comments on commit ffd6bcd

Please sign in to comment.