From 94871830dc8384aa88b3c39582cb1e28a60471a8 Mon Sep 17 00:00:00 2001
From: Piotr Maslanka <piotr.maslanka@henrietta.com.pl>
Date: Mon, 9 Jan 2017 14:43:29 +0100
Subject: [PATCH] refactor - Attache base class

---
 coolamqp/attaches/channeler.py | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/coolamqp/attaches/channeler.py b/coolamqp/attaches/channeler.py
index 4eb229d..4c298e7 100644
--- a/coolamqp/attaches/channeler.py
+++ b/coolamqp/attaches/channeler.py
@@ -18,7 +18,26 @@ ST_SYNCING = 1  # A process targeted at consuming has been started
 ST_ONLINE = 2   # Consumer is declared all right
 
 
-class Channeler(object):
+
+class Attache(object):
+    """
+    Something that can be attached to connection.
+    """
+    def __init__(self):
+        self.cancelled = False      #: public, if this is True, it won't be attached to next connection
+        self.state = ST_OFFLINE
+        self.connection = None
+
+    def attach(self, connection):
+        """
+        Attach to a connection.
+
+        :param connection: Connection instance of any state
+        """
+        self.connection = connection
+
+
+class Channeler(Attache):
     """
     A base class for Consumer/Publisher implementing link set up and tear down.
 
@@ -44,8 +63,7 @@ class Channeler(object):
         """
         [EXTEND ME!]
         """
-        self.state = ST_OFFLINE
-        self.connection = None
+        super(Channeler, self).__init__()
         self.channel_id = None      # channel obtained from Connection
 
     def attach(self, connection):
@@ -54,7 +72,7 @@ class Channeler(object):
 
         :param connection: Connection instance to use
         """
-        self.connection = connection
+        super(Channeler, self).attach(connection)
         connection.call_on_connected(self.on_uplink_established)
 
     # ------- event handlers
-- 
GitLab