[refactor] Extract flags check to caller
authorVictor Shyba <victor.shyba@gmail.com>
Wed, 29 Jul 2015 16:30:41 +0000 (13:30 -0300)
committerVictor Shyba <victor.shyba@gmail.com>
Wed, 29 Jul 2015 16:30:41 +0000 (13:30 -0300)
Checking was done inside of emit method. Doing on emit function at
a module level makes it cleaner with less lines inside of check.

src/leap/common/events/client.py

index 8d8d522..4790fc3 100644 (file)
@@ -170,10 +170,9 @@ class EventsClient(object):
         :param content: The content of the event.
         :type content: list
         """
-        if flags.EVENTS_ENABLED:
-            logger.debug("Emitting event: (%s, %s)" % (event, content))
-            payload = str(event) + b'\0' + pickle.dumps(content)
-            self._send(payload)
+        logger.debug("Emitting event: (%s, %s)" % (event, content))
+        payload = str(event) + b'\0' + pickle.dumps(content)
+        self._send(payload)
 
     def _handle_event(self, event, content):
         """
@@ -537,7 +536,8 @@ def emit(event, *content):
     :param content: The content of the event.
     :type content: list
     """
-    return EventsClientThread.instance().emit(event, *content)
+    if flags.EVENTS_ENABLED:
+        return EventsClientThread.instance().emit(event, *content)
 
 
 def instance():