Beispiel #1
0
 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))
Beispiel #3
0
    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))
Beispiel #4
0
 def __init__(self, cache_domains=''):
     self.cache = WeakKeyCache(self._cache_domains)
     self.cache_domains = cache_domains
Beispiel #5
0
 def __init__(self, user_agent='Scrapy'):
     self.cache = WeakKeyCache(self._user_agent)
     self.user_agent = user_agent
Beispiel #6
0
 def __init__(self, timeout=180):
     self._cache = WeakKeyCache(self._download_timeout)
     self._timeout = timeout
Beispiel #7
0
 def __init__(self, settings=conf.settings):
     self._headers = WeakKeyCache(self._default_headers)
Beispiel #8
0
 def __init__(self):
     self._cache = WeakKeyCache(self._download_timeout)
Beispiel #9
0
 def __init__(self):
     self.cache = WeakKeyCache(self._user_agent)
Beispiel #10
0
 def __init__(self):
     self._cache = WeakKeyCache(self._authorization)