Exemplo n.º 1
0
    def __init__(self,
                 channel,
                 body=None,
                 delivery_tag=None,
                 content_type=None,
                 content_encoding=None,
                 delivery_info={},
                 properties=None,
                 headers=None,
                 postencode=None,
                 accept=None,
                 **kwargs):
        self.channel = channel
        self.delivery_tag = delivery_tag
        self.content_type = content_type
        self.content_encoding = content_encoding
        self.delivery_info = delivery_info
        self.headers = headers or {}
        self.properties = properties or {}
        self._decoded_cache = None
        self._state = 'RECEIVED'
        self.accept = accept

        try:
            body = decompress(body, self.headers['compression'])
        except KeyError:
            pass
        if postencode and isinstance(body, unicode):
            body = body.encode(postencode)
        self.body = body
Exemplo n.º 2
0
    def __init__(
        self,
        channel,
        body=None,
        delivery_tag=None,
        content_type=None,
        content_encoding=None,
        delivery_info={},
        properties=None,
        headers=None,
        postencode=None,
        **kwargs
    ):
        self.channel = channel
        self.body = body
        self.delivery_tag = delivery_tag
        self.content_type = content_type
        self.content_encoding = content_encoding
        self.delivery_info = delivery_info
        self.headers = headers or {}
        self.properties = properties or {}
        self._decoded_cache = None
        self._state = "RECEIVED"

        compression = self.headers.get("compression")
        if compression:
            self.body = decompress(self.body, compression)
        if postencode and isinstance(self.body, unicode):
            self.body = self.body.encode(postencode)
Exemplo n.º 3
0
Arquivo: base.py Projeto: Vayana/kombu
    def __init__(
        self,
        channel,
        body=None,
        delivery_tag=None,
        content_type=None,
        content_encoding=None,
        delivery_info={},
        properties=None,
        headers=None,
        postencode=None,
        **kwargs
    ):
        self.channel = channel
        self.delivery_tag = delivery_tag
        self.content_type = content_type
        self.content_encoding = content_encoding
        self.delivery_info = delivery_info
        self.headers = headers or {}
        self.properties = properties or {}
        self._decoded_cache = None
        self._state = "RECEIVED"

        try:
            body = decompress(body, self.headers["compression"])
        except KeyError:
            pass
        if postencode and isinstance(body, text_t):
            body = body.encode(postencode)
        self.body = body
Exemplo n.º 4
0
    def __init__(self,
                 channel,
                 body=None,
                 delivery_tag=None,
                 content_type=None,
                 content_encoding=None,
                 delivery_info={},
                 properties=None,
                 headers=None,
                 postencode=None,
                 **kwargs):
        self.channel = channel
        self.body = body
        self.delivery_tag = delivery_tag
        self.content_type = content_type
        self.content_encoding = content_encoding
        self.delivery_info = delivery_info
        self.headers = headers or {}
        self.properties = properties or {}
        self._decoded_cache = None
        self._state = "RECEIVED"

        compression = self.headers.get("compression")
        if compression:
            self.body = decompress(self.body, compression)
        if postencode and isinstance(self.body, unicode):
            self.body = self.body.encode(postencode)
Exemplo n.º 5
0
 def test_compress__decompress__bzip2(self):
     if not self.has_bzip2:
         raise SkipTest('bzip2 not available')
     text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
     c, ctype = compression.compress(text, 'bzip2')
     self.assertNotEqual(text, c)
     d = compression.decompress(c, ctype)
     self.assertEqual(d, text)
Exemplo n.º 6
0
    def test_compress__decompress__zstd(self):
        pytest.importorskip('zstandard')

        text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
        c, ctype = compression.compress(text, 'zstd')
        assert text != c
        d = compression.decompress(c, ctype)
        assert d == text
Exemplo n.º 7
0
    def test_compress__decompress__backports_lzma(self):
        pytest.importorskip('backports.lzma')

        text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
        c, ctype = compression.compress(text, 'lzma')
        assert text != c
        d = compression.decompress(c, ctype)
        assert d == text
Exemplo n.º 8
0
 def test_compress__decompress__bzip2(self):
     if not self.has_bzip2:
         raise SkipTest('bzip2 not available')
     text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
     c, ctype = compression.compress(text, 'bzip2')
     self.assertNotEqual(text, c)
     d = compression.decompress(c, ctype)
     self.assertEqual(d, text)
Exemplo n.º 9
0
    def test_compress__decompress__backports_lzma(self):
        pytest.importorskip('backports.lzma')

        text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
        c, ctype = compression.compress(text, 'lzma')
        assert text != c
        d = compression.decompress(c, ctype)
        assert d == text
Exemplo n.º 10
0
    def test_compress__decompress__zstd(self):
        pytest.importorskip('zstandard')

        text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
        c, ctype = compression.compress(text, 'zstd')
        assert text != c
        d = compression.decompress(c, ctype)
        assert d == text
Exemplo n.º 11
0
 def test_compress__decompress__zlib(self):
     text = b'The Quick Brown Fox Jumps Over The Lazy Dog'
     c, ctype = compression.compress(text, 'zlib')
     self.assertNotEqual(text, c)
     d = compression.decompress(c, ctype)
     self.assertEqual(d, text)
Exemplo n.º 12
0
 def test_compress__decompress__zlib(self):
     text = b'The Quick Brown Fox Jumps Over The Lazy Dog'
     c, ctype = compression.compress(text, 'zlib')
     assert text != c
     d = compression.decompress(c, ctype)
     assert d == text
Exemplo n.º 13
0
 def test_compress__decompress__bzip2(self):
     text = b"The Brown Quick Fox Over The Lazy Dog Jumps"
     c, ctype = compression.compress(text, "bzip2")
     assert text != c
     d = compression.decompress(c, ctype)
     assert d == text
Exemplo n.º 14
0
 def test_compress__decompress__zlib(self):
     text = b"The Quick Brown Fox Jumps Over The Lazy Dog"
     c, ctype = compression.compress(text, "zlib")
     assert text != c
     d = compression.decompress(c, ctype)
     assert d == text
Exemplo n.º 15
0
 def test_compress__decompress__bzip2(self):
     text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
     c, ctype = compression.compress(text, 'bzip2')
     self.assertNotEqual(text, c)
     d = compression.decompress(c, ctype)
     self.assertEqual(d, text)
Exemplo n.º 16
0
 def test_compress__decompress__zlib(self):
     text = "The Quick Brown Fox Jumps Over The Lazy Dog"
     c, ctype = compression.compress(text, "zlib")
     self.assertNotEqual(text, c)
     d = compression.decompress(c, ctype)
     self.assertEqual(d, text)
Exemplo n.º 17
0
 def test_compress__decompress__bzip2(self):
     text = "The Brown Quick Fox Over The Lazy Dog Jumps"
     c, ctype = compression.compress(text, "bzip2")
     self.assertNotEqual(text, c)
     d = compression.decompress(c, ctype)
     self.assertEqual(d, text)
Exemplo n.º 18
0
 def test_compress__decompress__bzip2(self):
     text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
     c, ctype = compression.compress(text, 'bzip2')
     assert text != c
     d = compression.decompress(c, ctype)
     assert d == text