Merge pull request #4701 from kshitijcode/weakkeycache-cleanup-4684

Code cleanup scrapy.utils.python.WeakKeyCache #4684
This commit is contained in:
Andrey Rahmatullin 2020-08-05 17:48:41 +05:00 committed by GitHub
commit 1f0722c87e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -6,10 +6,12 @@ import gc
import inspect
import re
import sys
import warnings
import weakref
from functools import partial, wraps
from itertools import chain
from scrapy.exceptions import ScrapyDeprecationWarning
from scrapy.utils.decorators import deprecated
@ -127,6 +129,7 @@ def re_rsearch(pattern, text, chunk_size=1024):
In case the pattern wasn't found, None is returned, otherwise it returns a tuple containing
the start position of the match, and the ending (regarding the entire text).
"""
def _chunk_iter():
offset = len(text)
while True:
@ -158,6 +161,7 @@ def memoizemethod_noargs(method):
if self not in cache:
cache[self] = method(self, *args, **kwargs)
return cache[self]
return new_method
@ -276,6 +280,7 @@ def equal_attributes(obj1, obj2, attributes):
class WeakKeyCache:
def __init__(self, default_factory):
warnings.warn("The WeakKeyCache class is deprecated", category=ScrapyDeprecationWarning, stacklevel=2)
self.default_factory = default_factory
self._weakdict = weakref.WeakKeyDictionary()