Jason R. Coombs avatar Jason R. Coombs committed a0e0786

Replaced global variable ('DEBUG' and print statements with logging infrastructure.

Comments (0)

Files changed (1)

 import ssl as ssl_mod
 import datetime
 import struct
+import logging
 
 try:
     import pkg_resources
 from . import strings
 from . import modes
 
-DEBUG = False
+log = logging.getLogger(__name__)
 
 # set the version tuple
 try:
         self.previous_buffer = lines.pop()
 
         for line in lines:
-            if DEBUG:
-                print "FROM SERVER:", line
+            log.debug("FROM SERVER: %s", line)
 
             if not line:
                 continue
                             command = "ctcpreply"
 
                         m = list(m)
-                        if DEBUG:
-                            print "command: %s, source: %s, target: %s, arguments: %s" % (
-                                command, prefix, target, m)
+                        log.debug("command: %s, source: %s, target: %s, "
+                            "arguments: %s", command, prefix, target, m)
                         self._handle_event(Event(command, NickMask(prefix), target, m))
                         if command == "ctcp" and m[0] == "ACTION":
                             self._handle_event(Event("action", prefix, target, m[1:]))
                     else:
-                        if DEBUG:
-                            print "command: %s, source: %s, target: %s, arguments: %s" % (
-                                command, prefix, target, [m])
+                        log.debug("command: %s, source: %s, target: %s, "
+                            "arguments: %s", command, prefix, target, [m])
                         self._handle_event(Event(command, NickMask(prefix), target, [m]))
             else:
                 target = None
                     if not is_channel(target):
                         command = "umode"
 
-                if DEBUG:
-                    print "command: %s, source: %s, target: %s, arguments: %s" % (
-                        command, prefix, target, arguments)
+                log.debug("command: %s, source: %s, target: %s, "
+                    "arguments: %s", command, prefix, target, arguments)
                 self._handle_event(Event(command, NickMask(prefix), target, arguments))
 
     def _handle_event(self, event):
                 self.ssl.write(string + "\r\n")
             else:
                 self.socket.send(string + "\r\n")
-            if DEBUG:
-                print "TO SERVER:", string
+            log.debug("TO SERVER: %s", string)
         except socket.error:
             # Ouch!
             self.disconnect("Connection reset by peer.")
             self.socket.close()
             self.socket = conn
             self.connected = 1
-            if DEBUG:
-                print "DCC connection from %s:%d" % (
-                    self.peeraddress, self.peerport)
+            log.debug("DCC connection from %s:%d", self.peeraddress,
+                self.peerport)
             self.irclibobj._handle_event(
                 self,
                 Event("dcc_connect", self.peeraddress, None, None))
         prefix = self.peeraddress
         target = None
         for chunk in chunks:
-            if DEBUG:
-                print "FROM PEER:", chunk
+            log.debug("FROM PEER: %s", chunk)
             arguments = [chunk]
-            if DEBUG:
-                print "command: %s, source: %s, target: %s, arguments: %s" % (
-                    command, prefix, target, arguments)
+            log.debug("command: %s, source: %s, target: %s, arguments: %s",
+                command, prefix, target, arguments)
             self.irclibobj._handle_event(
                 self,
                 Event(command, prefix, target, arguments))
             self.socket.send(string)
             if self.dcctype == "chat":
                 self.socket.send("\n")
-            if DEBUG:
-                print "TO PEER: %s\n" % string
+            log.debug("TO PEER: %s\n", string)
         except socket.error:
             # Ouch!
             self.disconnect("Connection reset by peer.")
 
     def _dispatcher(self, c, e):
         """[Internal]"""
-        if DEBUG:
-            print("irclib.py:_dispatcher:%s" % e.eventtype())
+        log.debug("_dispatcher: %s", e.eventtype())
 
         m = "on_" + e.eventtype()
         if hasattr(self, m):
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.