From 7ebc4c9f45ed329da2d0788a6409310a782ed30d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Mon, 2 Jan 2017 09:02:45 +0100
Subject: [PATCH] New Year legalese, broker API clean up

---
 LICENSE                           |  4 ++--
 coolamqp/connection/definition.py |  5 -----
 coolamqp/connection/state.py      | 22 ++++++++++++++++++++++
 coolamqp/uplink/handshake.py      | 10 +++++++---
 tests/run.py                      | 20 +++-----------------
 5 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/LICENSE b/LICENSE
index a08e076..21a8338 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 The MIT License (MIT)
 
-Copyright (c) 2016 DMS Serwis s.c.
+Copyright (c) 2016-2017 DMS Serwis s.c.
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -21,4 +21,4 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 
 
-resources/*: Copyright (c) 2016 OASIS
\ No newline at end of file
+resources/*: Copyright (c) 2016-2017 OASIS
\ No newline at end of file
diff --git a/coolamqp/connection/definition.py b/coolamqp/connection/definition.py
index 58682be..fe4695f 100644
--- a/coolamqp/connection/definition.py
+++ b/coolamqp/connection/definition.py
@@ -26,8 +26,3 @@ class NodeDefinition(object):
         self.virtual_host = virtual_host
         self.heartbeat = heartbeat
 
-    def to_connection_object(self):
-        """
-        Return a Connection object that
-        :return:
-        """
diff --git a/coolamqp/connection/state.py b/coolamqp/connection/state.py
index b1c75e4..b5013cc 100644
--- a/coolamqp/connection/state.py
+++ b/coolamqp/connection/state.py
@@ -22,6 +22,28 @@ class Broker(object):
 
         self.free_channels = [] # list of channels usable for consuming shit
 
+    @staticmethod
+    def from_node_def(node_def, listener_thread, debug=True):
+        """
+        :param node_def: NodeDefinition to use
+        :param listener_thread: ListenerThread to use
+        :return: a Broker with Connection.
+        """
+        import socket
+        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        s.connect((node_def.host, node_def.port))
+        s.settimeout(0)
+        s.send('AMQP\x00\x00\x09\x01')
+
+        from coolamqp.uplink import Connection
+        con = Connection(s, listener_thread)
+
+        if debug:
+            from coolamqp.uplink.transcript import SessionTranscript
+            con.transcript = SessionTranscript()
+
+        return Broker(con, node_def)
+
 
     def connect(self):
         """Return an LinkSetup order to get when it connects"""
diff --git a/coolamqp/uplink/handshake.py b/coolamqp/uplink/handshake.py
index 48e50c1..3cba0c0 100644
--- a/coolamqp/uplink/handshake.py
+++ b/coolamqp/uplink/handshake.py
@@ -15,9 +15,13 @@ CLIENT_DATA = [
         # because RabbitMQ is some kind of a fascist and does not allow
         # these fields to be of type short-string
         (b'product', (b'CoolAMQP', b'S')),
-        (b'version', (b'1.0', b'S')),
-        (b'copyright', (b'Copyright (C) 2016 DMS Serwis', b'S')),
-        (b'information', (b'Licensed under the MIT License. See https://github.com/smok-serwis/coolamqp for details', b'S'))
+        (b'version', (b'develop', b'S')),
+        (b'copyright', (b'Copyright (C) 2016-2017 DMS Serwis', b'S')),
+        (b'information', (b'Licensed under the MIT License.\nSee https://github.com/smok-serwis/coolamqp for details', b'S')),
+        (b'capabilities', ([
+                               (b'consumer_cancel_notify', (True, b't')),
+                               (b'connection.blocked', (True, b't'))
+            ], b'F'))
       ]
 
 
diff --git a/tests/run.py b/tests/run.py
index 262ea2f..d74a933 100644
--- a/tests/run.py
+++ b/tests/run.py
@@ -1,36 +1,22 @@
 # coding=UTF-8
 from __future__ import absolute_import, division, print_function
-from coolamqp.uplink import ListenerThread, Connection
-import socket
+from coolamqp.uplink import ListenerThread
 import time
 from coolamqp.connection.state import Broker
 from coolamqp.connection import NodeDefinition
 
-from coolamqp.uplink.transcript import SessionTranscript
 
 
-def newc():
-    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-    s.connect(('127.0.0.1', 5672))
-    s.settimeout(0)
-    s.send('AMQP\x00\x00\x09\x01')
-    return s
-
-
-from coolamqp.uplink import Handshaker
 NODE = NodeDefinition('127.0.0.1', 5672, 'user', 'user', heartbeat=5)
 
 
-
 if __name__ == '__main__':
     lt = ListenerThread()
     lt.start()
 
-    con = Connection(newc(), lt)
-    con.transcript = SessionTranscript()
-    broker = Broker(con, NODE)
+    broker = Broker.from_node_def(NODE, lt)
 
-    broker.connect()
+    broker.connect().wait()
 
     time.sleep(50)
 
-- 
GitLab