From 75497bf28ea6aff8a965a10d7a45a1762a8f528c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Sat, 24 Dec 2016 05:51:06 +0100
Subject: [PATCH] encoding

---
 README.md              | 10 ++++------
 coolamqp/messages.py   |  3 ++-
 tests/test_basics.py   |  3 +++
 tests/test_failures.py |  4 ++--
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index 714c1c3..950c173 100644
--- a/README.md
+++ b/README.md
@@ -16,12 +16,10 @@ your application that a disconnect happened.
 
 You only need to remember that:
 
-1. Reconnects and redefinitions take a while.
- * Things will happen during that time. It is your responsibility to ensure that your distributed system is built to handle this
-2. CoolAMQP will tell you when it senses losing broker connection.
- * It will also tell you when it regains the connection (that means that everything is redefined and ready to go)
-3. Delivering messages multiple times may happen.
- * Ensure you know when it happens. Keywords: message acknowledgement, amqp specification
+1. Reconnects and redefinitions take a while. Things will happen during that time. It is your responsibility to ensure that your distributed system is built to handle this
+2. CoolAMQP will tell you when it senses losing broker connection. It will also tell you when it regains the connection (that means that everything is redefined and ready to go)
+3. Delivering messages multiple times may happen. Ensure you know when it happens. Keywords: message acknowledgement, amqp specification
+4. CoolAMQP won't unserialize your messages. You send bags of bytes and properties, you get bags of bytes and their properties.
 
 The project is actively maintained and used in a commercial project. Tests can run
 either on Vagrant (Vagrantfile attached) or Travis CI, and run against RabbitMQ.
diff --git a/coolamqp/messages.py b/coolamqp/messages.py
index 4815e34..c30db8a 100644
--- a/coolamqp/messages.py
+++ b/coolamqp/messages.py
@@ -13,7 +13,8 @@ class Message(object):
         :type body: str (py2) or bytes (py3)
         :param properties: AMQP properties to be sent along
         """
-        assert isinstance(body, six.binary_type)
+        if not isinstance(body, six.binary_type):
+            raise TypeError('Message body must be binary!')
         self.body = body
         self.properties = {} if properties is None else properties
 
diff --git a/tests/test_basics.py b/tests/test_basics.py
index 90cfc8a..cb702a5 100644
--- a/tests/test_basics.py
+++ b/tests/test_basics.py
@@ -42,6 +42,9 @@ class TestBasics(unittest.TestCase):
 
         self.assertIs(self.amqp.drain(wait=1), None)
 
+    def test_send_bullshit(self):
+        self.assertRaises(TypeError, lambda: Message(u'what the fuck'))
+
     def test_nacknowledge(self):
         myq = Queue('myqueue', exclusive=True)
 
diff --git a/tests/test_failures.py b/tests/test_failures.py
index 9cc2f7b..5eb6a96 100644
--- a/tests/test_failures.py
+++ b/tests/test_failures.py
@@ -85,7 +85,7 @@ class TestFailures(unittest.TestCase):
 
         os.system("sudo service rabbitmq-server stop")
         self.assertIsInstance(self.amqp.drain(wait=4), ConnectionDown)
-        result = self.amqp.send(Message('what the fuck'), '', routing_key='wtf1')
+        result = self.amqp.send(Message(b'what the fuck'), '', routing_key='wtf1')
         result.cancel()
 
         os.system("sudo service rabbitmq-server start")
@@ -120,7 +120,7 @@ class TestFailures(unittest.TestCase):
 
         os.system('sudo service rabbitmq-server restart')
 
-        self.amqp.send(Message('hello'), xchg)
+        self.amqp.send(Message(b'hello'), xchg)
         self.assertIsInstance(self.amqp.drain(wait=4), ConnectionDown)
         self.assertIsInstance(self.amqp.drain(wait=10), ConnectionUp)
         self.assertIsInstance(self.amqp.drain(wait=4), MessageReceived)
-- 
GitLab