Basic debug code.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 26 Aug 2012 11:08:30 +0000 (07:08 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 26 Aug 2012 11:08:30 +0000 (07:08 -0400)
irclib.py

index de3ad39904d5bc833441d87efdde8ea7a3d30e4c..a274d311092f7aa96c88e5be4e93d1d11571fa09 100644 (file)
--- a/irclib.py
+++ b/irclib.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 # Copyright (C) 1999-2002  Joel Rosdahl
-# Portions Copyright © 2011 Jason R. Coombs
+# Portions Copyright 2011 Jason R. Coombs
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -72,6 +72,7 @@ import time
 import types
 import ssl as ssl_mod
 import datetime
+import sys
 
 try:
     import pkg_resources
@@ -132,7 +133,8 @@ class IRC(object):
 
     def __init__(self, fn_to_add_socket=None,
                  fn_to_remove_socket=None,
-                 fn_to_add_timeout=None):
+                 fn_to_add_timeout=None,
+                 debuglevel=0):
         """Constructor for IRC objects.
 
         Optional arguments are fn_to_add_socket, fn_to_remove_socket
@@ -164,12 +166,15 @@ class IRC(object):
             self.fn_to_remove_socket = None
 
         self.fn_to_add_timeout = fn_to_add_timeout
+        self.debuglevel = debuglevel
         self.connections = []
         self.handlers = {}
         self.delayed_commands = []  # list of DelayedCommands
 
         self.add_global_handler("ping", _ping_ponger, -42)
 
+        self.debug(1, "IRC object created")
+
     def server(self):
         """Creates and returns a ServerConnection object."""
 
@@ -346,6 +351,11 @@ class IRC(object):
             if handler[1](connection, event) == "NO MORE":
                 return
 
+    def debug(self, level, errmsg):
+        """Display debugging information."""
+        #if self.debuglevel >= level:
+        sys.stderr.write("irclib[%d]: %s\n" % (self.debuglevel, errmsg))
+
     def _remove_connection(self, connection):
         """[Internal]"""
         self.connections.remove(connection)