We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Kombu compression "encodes" the body ?
At https://github.com/ask/kombu/blob/master/kombu/compression.py#L61, we see:

```
return encoder(body.encode("utf-8")), content_type
```

Same for decoding. What gives? It crashes with msgpack (which can't be encoded). Is there any reason for that ?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kombu/compression.py`
Content:
```
1 """
2 kombu.compression
3 =================
4 
5 Compression utilities.
6 
7 :copyright: (c) 2009 - 2012 by Ask Solem.
8 :license: BSD, see LICENSE for more details.
9 
10 """
11 from __future__ import absolute_import
12 
13 import zlib
14 
15 _aliases = {}
16 _encoders = {}
17 _decoders = {}
18 
19 __all__ = ["register", "encoders", "get_encoder",
20            "get_decoder", "compress", "decompress"]
21 
22 
23 def register(encoder, decoder, content_type, aliases=[]):
24     """Register new compression method.
25 
26     :param encoder: Function used to compress text.
27     :param decoder: Function used to decompress previously compressed text.
28     :param content_type: The mime type this compression method identifies as.
29     :param aliases: A list of names to associate with this compression method.
30 
31     """
32     _encoders[content_type] = encoder
33     _decoders[content_type] = decoder
34     _aliases.update((alias, content_type) for alias in aliases)
35 
36 
37 def encoders():
38     """Returns a list of available compression methods."""
39     return _encoders.keys()
40 
41 
42 def get_encoder(t):
43     """Get encoder by alias name."""
44     t = _aliases.get(t, t)
45     return _encoders[t], t
46 
47 
48 def get_decoder(t):
49     """Get decoder by alias name."""
50     return _decoders[_aliases.get(t, t)]
51 
52 
53 def compress(body, content_type):
54     """Compress text.
55 
56     :param body: The text to compress.
57     :param content_type: mime-type of compression method to use.
58 
59     """
60     encoder, content_type = get_encoder(content_type)
61     return encoder(body.encode("utf-8")), content_type
62 
63 
64 def decompress(body, content_type):
65     """Decompress compressed text.
66 
67     :param body: Previously compressed text to uncompress.
68     :param content_type: mime-type of compression method used.
69 
70     """
71     return get_decoder(content_type)(body).decode("utf-8")
72 
73 
74 register(zlib.compress,
75          zlib.decompress,
76          "application/x-gzip", aliases=["gzip", "zlib"])
77 try:
78     import bz2
79 except ImportError:
80     pass  # Jython?
81 else:
82     register(bz2.compress,
83              bz2.decompress,
84              "application/x-bz2", aliases=["bzip2", "bzip"])
85
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kombu/compression.py b/kombu/compression.py
--- a/kombu/compression.py
+++ b/kombu/compression.py
@@ -10,6 +10,8 @@
 """
 from __future__ import absolute_import
 
+from kombu.utils.encoding import ensure_bytes, bytes_to_str
+
 import zlib
 
 _aliases = {}
@@ -58,7 +60,7 @@
 
     """
     encoder, content_type = get_encoder(content_type)
-    return encoder(body.encode("utf-8")), content_type
+    return encoder(ensure_bytes(body)), content_type
 
 
 def decompress(body, content_type):
@@ -68,7 +70,7 @@
     :param content_type: mime-type of compression method used.
 
     """
-    return get_decoder(content_type)(body).decode("utf-8")
+    return bytes_to_str(get_decoder(content_type)(body))
 
 
 register(zlib.compress,

{"golden_diff": "diff --git a/kombu/compression.py b/kombu/compression.py\n--- a/kombu/compression.py\n+++ b/kombu/compression.py\n@@ -10,6 +10,8 @@\n \"\"\"\n from __future__ import absolute_import\n \n+from kombu.utils.encoding import ensure_bytes, bytes_to_str\n+\n import zlib\n \n _aliases = {}\n@@ -58,7 +60,7 @@\n \n     \"\"\"\n     encoder, content_type = get_encoder(content_type)\n-    return encoder(body.encode(\"utf-8\")), content_type\n+    return encoder(ensure_bytes(body)), content_type\n \n \n def decompress(body, content_type):\n@@ -68,7 +70,7 @@\n     :param content_type: mime-type of compression method used.\n \n     \"\"\"\n-    return get_decoder(content_type)(body).decode(\"utf-8\")\n+    return bytes_to_str(get_decoder(content_type)(body))\n \n \n register(zlib.compress,\n", "issue": "Kombu compression \"encodes\" the body ?\nAt https://github.com/ask/kombu/blob/master/kombu/compression.py#L61, we see:\n\n```\nreturn encoder(body.encode(\"utf-8\")), content_type\n```\n\nSame for decoding. What gives? It crashes with msgpack (which can't be encoded). Is there any reason for that ?\n\n", "before_files": [{"content": "\"\"\"\nkombu.compression\n=================\n\nCompression utilities.\n\n:copyright: (c) 2009 - 2012 by Ask Solem.\n:license: BSD, see LICENSE for more details.\n\n\"\"\"\nfrom __future__ import absolute_import\n\nimport zlib\n\n_aliases = {}\n_encoders = {}\n_decoders = {}\n\n__all__ = [\"register\", \"encoders\", \"get_encoder\",\n           \"get_decoder\", \"compress\", \"decompress\"]\n\n\ndef register(encoder, decoder, content_type, aliases=[]):\n    \"\"\"Register new compression method.\n\n    :param encoder: Function used to compress text.\n    :param decoder: Function used to decompress previously compressed text.\n    :param content_type: The mime type this compression method identifies as.\n    :param aliases: A list of names to associate with this compression method.\n\n    \"\"\"\n    _encoders[content_type] = encoder\n    _decoders[content_type] = decoder\n    _aliases.update((alias, content_type) for alias in aliases)\n\n\ndef encoders():\n    \"\"\"Returns a list of available compression methods.\"\"\"\n    return _encoders.keys()\n\n\ndef get_encoder(t):\n    \"\"\"Get encoder by alias name.\"\"\"\n    t = _aliases.get(t, t)\n    return _encoders[t], t\n\n\ndef get_decoder(t):\n    \"\"\"Get decoder by alias name.\"\"\"\n    return _decoders[_aliases.get(t, t)]\n\n\ndef compress(body, content_type):\n    \"\"\"Compress text.\n\n    :param body: The text to compress.\n    :param content_type: mime-type of compression method to use.\n\n    \"\"\"\n    encoder, content_type = get_encoder(content_type)\n    return encoder(body.encode(\"utf-8\")), content_type\n\n\ndef decompress(body, content_type):\n    \"\"\"Decompress compressed text.\n\n    :param body: Previously compressed text to uncompress.\n    :param content_type: mime-type of compression method used.\n\n    \"\"\"\n    return get_decoder(content_type)(body).decode(\"utf-8\")\n\n\nregister(zlib.compress,\n         zlib.decompress,\n         \"application/x-gzip\", aliases=[\"gzip\", \"zlib\"])\ntry:\n    import bz2\nexcept ImportError:\n    pass  # Jython?\nelse:\n    register(bz2.compress,\n             bz2.decompress,\n             \"application/x-bz2\", aliases=[\"bzip2\", \"bzip\"])\n", "path": "kombu/compression.py"}], "after_files": [{"content": "\"\"\"\nkombu.compression\n=================\n\nCompression utilities.\n\n:copyright: (c) 2009 - 2012 by Ask Solem.\n:license: BSD, see LICENSE for more details.\n\n\"\"\"\nfrom __future__ import absolute_import\n\nfrom kombu.utils.encoding import ensure_bytes, bytes_to_str\n\nimport zlib\n\n_aliases = {}\n_encoders = {}\n_decoders = {}\n\n__all__ = [\"register\", \"encoders\", \"get_encoder\",\n           \"get_decoder\", \"compress\", \"decompress\"]\n\n\ndef register(encoder, decoder, content_type, aliases=[]):\n    \"\"\"Register new compression method.\n\n    :param encoder: Function used to compress text.\n    :param decoder: Function used to decompress previously compressed text.\n    :param content_type: The mime type this compression method identifies as.\n    :param aliases: A list of names to associate with this compression method.\n\n    \"\"\"\n    _encoders[content_type] = encoder\n    _decoders[content_type] = decoder\n    _aliases.update((alias, content_type) for alias in aliases)\n\n\ndef encoders():\n    \"\"\"Returns a list of available compression methods.\"\"\"\n    return _encoders.keys()\n\n\ndef get_encoder(t):\n    \"\"\"Get encoder by alias name.\"\"\"\n    t = _aliases.get(t, t)\n    return _encoders[t], t\n\n\ndef get_decoder(t):\n    \"\"\"Get decoder by alias name.\"\"\"\n    return _decoders[_aliases.get(t, t)]\n\n\ndef compress(body, content_type):\n    \"\"\"Compress text.\n\n    :param body: The text to compress.\n    :param content_type: mime-type of compression method to use.\n\n    \"\"\"\n    encoder, content_type = get_encoder(content_type)\n    return encoder(ensure_bytes(body)), content_type\n\n\ndef decompress(body, content_type):\n    \"\"\"Decompress compressed text.\n\n    :param body: Previously compressed text to uncompress.\n    :param content_type: mime-type of compression method used.\n\n    \"\"\"\n    return bytes_to_str(get_decoder(content_type)(body))\n\n\nregister(zlib.compress,\n         zlib.decompress,\n         \"application/x-gzip\", aliases=[\"gzip\", \"zlib\"])\ntry:\n    import bz2\nexcept ImportError:\n    pass  # Jython?\nelse:\n    register(bz2.compress,\n             bz2.decompress,\n             \"application/x-bz2\", aliases=[\"bzip2\", \"bzip\"])\n", "path": "kombu/compression.py"}]}