コード例 #1
0
    def __init__(self,
                 app,
                 serializer=None,
                 max_cached_results=None,
                 accept=None,
                 expires=None,
                 expires_type=None,
                 url=None,
                 **kwargs):
        self.app = app
        conf = self.app.conf
        self.serializer = serializer or conf.result_serializer
        (self.content_type, self.content_encoding,
         self.encoder) = serializer_registry._encoders[self.serializer]
        cmax = max_cached_results or conf.result_cache_max
        self._cache = _nulldict() if cmax == -1 else LRUCache(limit=cmax)

        self.expires = self.prepare_expires(expires, expires_type)

        # precedence: accept, conf.result_accept_content, conf.accept_content
        self.accept = conf.result_accept_content if accept is None else accept
        self.accept = conf.accept_content if self.accept is None else self.accept
        self.accept = prepare_accept_content(self.accept)

        self.always_retry = conf.get('result_backend_always_retry', False)
        self.max_sleep_between_retries_ms = conf.get(
            'result_backend_max_sleep_between_retries_ms', 10000)
        self.base_sleep_between_retries_ms = conf.get(
            'result_backend_base_sleep_between_retries_ms', 10)
        self.max_retries = conf.get('result_backend_max_retries', float("inf"))

        self._pending_results = pending_results_t({}, WeakValueDictionary())
        self._pending_messages = BufferMap(MESSAGE_BUFFER_MAX)
        self.url = url
コード例 #2
0
ファイル: base.py プロジェクト: NguyenMo2610/it4421
    def __init__(self,
                 app,
                 serializer=None,
                 max_cached_results=None,
                 accept=None,
                 expires=None,
                 expires_type=None,
                 url=None,
                 **kwargs):
        self.app = app
        conf = self.app.conf
        self.serializer = serializer or conf.result_serializer
        (self.content_type, self.content_encoding,
         self.encoder) = serializer_registry._encoders[self.serializer]
        cmax = max_cached_results or conf.result_cache_max
        self._cache = _nulldict() if cmax == -1 else LRUCache(limit=cmax)

        self.expires = self.prepare_expires(expires, expires_type)

        # precedence: accept, conf.result_accept_content, conf.accept_content
        self.accept = conf.result_accept_content if accept is None else accept
        self.accept = conf.accept_content if self.accept is None else self.accept  # noqa: E501
        self.accept = prepare_accept_content(self.accept)

        self._pending_results = pending_results_t({}, WeakValueDictionary())
        self._pending_messages = BufferMap(MESSAGE_BUFFER_MAX)
        self.url = url
コード例 #3
0
 def test_pop_empty_no_default(self):
     b = BufferMap(10)
     with pytest.raises(b.Empty):
         b.take(1)
コード例 #4
0
 def test_pop_empty_with_default(self):
     b = BufferMap(10)
     sentinel = object()
     assert b.take(1, sentinel) is sentinel
コード例 #5
0
 def test_extend_unlimited(self):
     b = BufferMap(None)
     b.extend(1, list(range(20)))
     self.assert_size_and_first(b, 20, 0)
コード例 #6
0
 def test_extend_limited(self):
     b = BufferMap(10)
     b.extend(1, list(range(20)))
     self.assert_size_and_first(b, 10, 10)
コード例 #7
0
 def test_append_unlimited(self):
     b = BufferMap(None)
     for i in range(20):
         b.put(i, i)
     self.assert_size_and_first(b, 20, 0)
コード例 #8
0
 def test_append_limited(self):
     b = BufferMap(10)
     for i in range(20):
         b.put(i, i)
     self.assert_size_and_first(b, 10, 10)
コード例 #9
0
 def test_pop_empty_no_default(self):
     b = BufferMap(10)
     with pytest.raises(b.Empty):
         b.take(1)
コード例 #10
0
 def test_extend_unlimited(self):
     b = BufferMap(None)
     b.extend(1, list(range(20)))
     self.assert_size_and_first(b, 20, 0)
コード例 #11
0
 def test_pop_empty_with_default(self):
     b = BufferMap(10)
     sentinel = object()
     assert b.take(1, sentinel) is sentinel
コード例 #12
0
 def test_extend_limited(self):
     b = BufferMap(10)
     b.extend(1, list(range(20)))
     self.assert_size_and_first(b, 10, 10)
コード例 #13
0
 def test_append_unlimited(self):
     b = BufferMap(None)
     for i in range(20):
         b.put(i, i)
     self.assert_size_and_first(b, 20, 0)
コード例 #14
0
 def test_append_limited(self):
     b = BufferMap(10)
     for i in range(20):
         b.put(i, i)
     self.assert_size_and_first(b, 10, 10)
コード例 #15
0
 def test_pop_empty_no_default(self):
     b = BufferMap(10)
     with self.assertRaises(b.Empty):
         b.take(1)
コード例 #16
0
 def test_pop_empty_no_default(self):
     b = BufferMap(10)
     with self.assertRaises(b.Empty):
         b.take(1)