From 8d785c3a7fdb10bf755a34650423f8b4c8987e42 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 26 Aug 2012 07:08:30 -0400 Subject: [PATCH] Basic debug code. --- irclib.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/irclib.py b/irclib.py index de3ad39..a274d31 100644 --- 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) -- 2.26.2