def test_weakkeycache(self): class _Weakme(object): pass _values = count() wk = WeakKeyCache(lambda k: next(_values)) k = _Weakme() v = wk[k] self.assertEqual(v, wk[k]) self.assertNotEqual(v, wk[_Weakme()]) self.assertEqual(v, wk[k]) del k self.assertFalse(len(wk._weakdict))
def test_weakkeycache(self): class _Weakme: pass _values = count() wk = WeakKeyCache(lambda k: next(_values)) k = _Weakme() v = wk[k] self.assertEqual(v, wk[k]) self.assertNotEqual(v, wk[_Weakme()]) self.assertEqual(v, wk[k]) del k for _ in range(100): if wk._weakdict: gc.collect() self.assertFalse(len(wk._weakdict))
def test_weakkeycache(self): class _Weakme: pass _values = count() with catch_warnings(): filterwarnings("ignore", category=ScrapyDeprecationWarning) wk = WeakKeyCache(lambda k: next(_values)) k = _Weakme() v = wk[k] self.assertEqual(v, wk[k]) self.assertNotEqual(v, wk[_Weakme()]) self.assertEqual(v, wk[k]) del k for _ in range(100): if wk._weakdict: gc.collect() self.assertFalse(len(wk._weakdict))
def __init__(self, cache_domains=''): self.cache = WeakKeyCache(self._cache_domains) self.cache_domains = cache_domains
def __init__(self, user_agent='Scrapy'): self.cache = WeakKeyCache(self._user_agent) self.user_agent = user_agent
def __init__(self, timeout=180): self._cache = WeakKeyCache(self._download_timeout) self._timeout = timeout
def __init__(self, settings=conf.settings): self._headers = WeakKeyCache(self._default_headers)
def __init__(self): self._cache = WeakKeyCache(self._download_timeout)
def __init__(self): self.cache = WeakKeyCache(self._user_agent)
def __init__(self): self._cache = WeakKeyCache(self._authorization)