Commits

Gabriel AHTUNE committed fbd8dab

move sescgem.SECSGEMEntity to abc.py

Comments (0)

Files changed (3)

secsgem/__init__.py

 __author__ = 'Gabriel AHTUNE'
 __version__ = '1.0'
 
-import time
-import threading
-from abc import ABCMeta, abstractmethod
-
-
-class SECSGEMEntity(threading.Thread, metaclass=ABCMeta):
-    """
-    Base class for a secsgem communication entity
-    """
-
-    def __init__(self, transport, sessionid):
-        threading.Thread.__init__(self)
-        self.daemon = True
-        self.transport = transport(sessionid=sessionid)
-        self.listeners = []
-        self.statelisteners = []
-        self._connected = False
-        self.getconnection = threading.Event()
-
-    @property
-    def connected(self):
-        return self._connected
-
-    @connected.setter
-    def connected(self, value):
-        self._connected = value
-        if value:
-            self.getconnection.set()
-        else:
-            self.getconnection.clear()
-
-    @connected.getter
-    def connected(self):
-        return self._connected
-
-    def addlistener(self, listener):
-        """
-        Add a listener to the secsgem message
-        """
-
-        self.listeners.append(listener)
-
-    def removelistener(self, listener):
-        """
-        Remove a listener to the secsgem message list of listeners
-        """
-
-        self.listeners.remove(listener)
-
-    def addstatelistener(self, listener):
-        """
-        Add a listener to the server state connection
-        """
-        self.statelisteners.append(listener)
-
-    def feed(self, msg):
-        """
-        Feed the listener of messages
-        """
-        for listener in self.listeners:
-            listener(msg)
-
-    def feedstate(self, msg):
-        """
-        Feed a message through the state channel
-        """
-        for listener in self.statelisteners:
-            listener(msg)
-        self.logger.info('connection state: %s' % str(msg))
-
-    def wait_connection(self):
-        """
-        Wait the entity to be connected
-        """
-        self.getconnection.wait()
-        time.sleep(0.1)
-
-    @abstractmethod
-    def connect(self):
-        raise NotImplementedError
-
-    @abstractmethod
-    def close(self):
-        raise NotImplementedError
-
-    @abstractmethod
-    def send(self, msg):
-        raise NotImplementedError

secsgem/client.py

 from threading import Timer
 from .structures import SGMessage
 from .transports import HSMS, STYPE_TABLE
-from . import SECSGEMEntity
+from .abc import SECSGEMEntity
 
 
 class Client(SECSGEMEntity):

secsgem/server.py

 import time
 from .transports import HSMS, STYPE_TABLE
 from .structures import SGMessage
-from . import SECSGEMEntity
+from .abc import SECSGEMEntity
 
 
 class Server(SECSGEMEntity):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.