diff options
| author | Vik <vmuriart@users.noreply.github.com> | 2016-06-06 06:29:25 -0700 |
|---|---|---|
| committer | Vik <vmuriart@users.noreply.github.com> | 2016-06-06 06:29:25 -0700 |
| commit | b9d81ac4fe49114f57dc33c0d635f99ff56e62f2 (patch) | |
| tree | 88642eeb84d318511191a822fd781b44e1d63df1 /sqlparse/utils.py | |
| parent | c6a5e7ac2a5ecc993f4e5292ab16e6df6b84f26c (diff) | |
| parent | 5747015634a39191511de8db576f2cd0aa5eafc9 (diff) | |
| download | sqlparse-b9d81ac4fe49114f57dc33c0d635f99ff56e62f2.tar.gz | |
Merge pull request #251 from andialbrecht/filters_sql
Update Filters sql
Diffstat (limited to 'sqlparse/utils.py')
| -rw-r--r-- | sqlparse/utils.py | 71 |
1 files changed, 1 insertions, 70 deletions
diff --git a/sqlparse/utils.py b/sqlparse/utils.py index 2513c26..4da44c6 100644 --- a/sqlparse/utils.py +++ b/sqlparse/utils.py @@ -7,78 +7,9 @@ import itertools import re -from collections import OrderedDict, deque +from collections import deque from contextlib import contextmanager - -class Cache(OrderedDict): - """Cache with LRU algorithm using an OrderedDict as basis - """ - - def __init__(self, maxsize=100): - OrderedDict.__init__(self) - - self._maxsize = maxsize - - def __getitem__(self, key, *args, **kwargs): - # Get the key and remove it from the cache, or raise KeyError - value = OrderedDict.__getitem__(self, key) - del self[key] - - # Insert the (key, value) pair on the front of the cache - OrderedDict.__setitem__(self, key, value) - - # Return the value from the cache - return value - - def __setitem__(self, key, value, *args, **kwargs): - # Key was inserted before, remove it so we put it at front later - if key in self: - del self[key] - - # Too much items on the cache, remove the least recent used - elif len(self) >= self._maxsize: - self.popitem(False) - - # Insert the (key, value) pair on the front of the cache - OrderedDict.__setitem__(self, key, value, *args, **kwargs) - - -def memoize_generator(func): - """Memoize decorator for generators - - Store `func` results in a cache according to their arguments as 'memoize' - does but instead this works on decorators instead of regular functions. - Obviusly, this is only useful if the generator will always return the same - values for each specific parameters... - """ - cache = Cache() - - def wrapped_func(*args, **kwargs): - params = (args, tuple(sorted(kwargs.items()))) - - # Look if cached - try: - cached = cache[params] - - # Not cached, exec and store it - except KeyError: - cached = [] - - for item in func(*args, **kwargs): - cached.append(item) - yield item - - cache[params] = cached - - # Cached, yield its items - else: - for item in cached: - yield item - - return wrapped_func - - # This regular expression replaces the home-cooked parser that was here before. # It is much faster, but requires an extra post-processing step to get the # desired results (that are compatible with what you would expect from the |
