# Path: pyGBot/log.py
# def addScreenHandler(logobj, format):
# def addLogFileHandler(logobj, filename, format):
# 
# Path: pyGBot/format.py
# NUL = chr(0)
# CR = chr(0x0D)
# NL = chr(0x0A)
# LF = NL
# CRLF = CR + LF
# SPC = chr(0x20) # space
# BOLD = chr(2)
# COLOR = chr(3)
# ITALIC = chr(0x16)
# REV = ITALIC # reversed colors - italic or reversed display is client-dependent
# UNDER = chr(0x1f)
# CLEAR = chr(0x0f)
# RE_COLOR  = re.compile(r'\x03(\d{1,2}(,\d{1,2})?)?')
# RE_FORMAT = re.compile('|'.join([BOLD, COLOR, ITALIC, UNDER, CLEAR]))
# def strip(msg):
# def stripcolors(msg):
# def color(fg=None, bg=None):
# def encodeOut(msg):
# def decodeIn(msg):
# 
# Path: pyGBot/BasePlugin.py
# class BasePlugin:
#     def __init__(self, bot, options):
#         self.bot = bot
# 
#     def activate(self, channel=None):
#         """
#         Called when the plugin is activated.
#         """
#         return True
# 
#     def deactivate(self, channel=None):
#         """
#         Called when the plugin is deactivated.
#         """
#         return True
# 
#     # Event handlers for other users
#     def user_join(self, channel, username):
#         pass
# 
#     def user_part(self, channel, username):
#         pass
# 
#     def user_kicked(self, channel, username, kicker, message=""):
#         pass
# 
#     def user_quit(self, username, reason=""):
#         pass
# 
#     def user_nickchange(self, username, newname):
#         pass
# 
#     # Event handlers for this bot
#     def bot_connect(self):
#         pass
# 
#     def bot_join(self, channel):
#         pass
# 
#     def bot_part(self, channel):
#         pass
# 
#     def bot_kicked(self, channel, kicker="", reason=""):
#         pass
# 
#     def bot_disconnect(self):
#         pass
# 
# 
#     # Event handlers for incoming messages
#     def msg_channel(self, channel, user, message):
#         pass
# 
#     def msg_action(self, channel, user, message):
#         pass
# 
#     def msg_private(self, user, message):
#         pass
# 
#     def msg_notice(self, user, message):
#         pass
# 
#     # Event handlers for channel information replies
#     def channel_names(self, channel, nameslist):
#         pass
# 
#     def channel_topic(self, channel, user, topic):
#         pass
# 
#     # Other system event handlers
#     def timer_tick(self):
#         pass


from pyGBot import log
from pyGBot import format
from pyGBot.BasePlugin import BasePlugin
from HTMLParser import HTMLParser, HTMLParseError
from htmlentitydefs import name2codepoint
from urllib import quote, urlencode
from urllib2 import urlopen, URLError
import re
import json
                return True
        except (IndexError, KeyError, TypeError):
            # Network error or bad response structure
            return None

    def getPreview(self, title, maxlen):
        """Get a preview of the article (the first few hundred characters).
        This assumes the article exists (i.e. check self.articleExists first!)
        If an error accessing the article occurs, an empty string is returned.
        If the data received is malformed, None is returned."""

        # If preview length is 0, no preview; exit early
        if maxlen <= 0:
            return ""

        results = self.getApiResponse(title)

        # if getApiResponse() returns None, failed to retrieve or parse data
        if not results: return None

        try:
            htmlText = results['query']['pages'].values()[0]['revisions'][0]['*']
        except (KeyError, IndexError, TypeError) as e:
            log.logging.exception("reference.Wiki: A %s exception occurred " +\
                "while retrieving article text for '%s': %s",\
                e.__class__.__name__, format.encodeOut(title), str(e))
            return None
        except:
            log.logging.exception("reference.Wiki: An error occurred while " +\
                "retrieving the content of '%s' (maybe malformed JSON?)",\

# Path: pyGBot/log.py
# def addScreenHandler(logobj, format):
# def addLogFileHandler(logobj, filename, format):
# 
# Path: pyGBot/format.py
# NUL = chr(0)
# CR = chr(0x0D)
# NL = chr(0x0A)
# LF = NL
# CRLF = CR + LF
# SPC = chr(0x20) # space
# BOLD = chr(2)
# COLOR = chr(3)
# ITALIC = chr(0x16)
# REV = ITALIC # reversed colors - italic or reversed display is client-dependent
# UNDER = chr(0x1f)
# CLEAR = chr(0x0f)
# RE_COLOR  = re.compile(r'\x03(\d{1,2}(,\d{1,2})?)?')
# RE_FORMAT = re.compile('|'.join([BOLD, COLOR, ITALIC, UNDER, CLEAR]))
# def strip(msg):
# def stripcolors(msg):
# def color(fg=None, bg=None):
# def encodeOut(msg):
# def decodeIn(msg):
# 
# Path: pyGBot/BasePlugin.py
# class BasePlugin:
#     def __init__(self, bot, options):
#         self.bot = bot
# 
#     def activate(self, channel=None):
#         """
#         Called when the plugin is activated.
#         """
#         return True
# 
#     def deactivate(self, channel=None):
#         """
#         Called when the plugin is deactivated.
#         """
#         return True
# 
#     # Event handlers for other users
#     def user_join(self, channel, username):
#         pass
# 
#     def user_part(self, channel, username):
#         pass
# 
#     def user_kicked(self, channel, username, kicker, message=""):
#         pass
# 
#     def user_quit(self, username, reason=""):
#         pass
# 
#     def user_nickchange(self, username, newname):
#         pass
# 
#     # Event handlers for this bot
#     def bot_connect(self):
#         pass
# 
#     def bot_join(self, channel):
#         pass
# 
#     def bot_part(self, channel):
#         pass
# 
#     def bot_kicked(self, channel, kicker="", reason=""):
#         pass
# 
#     def bot_disconnect(self):
#         pass
# 
# 
#     # Event handlers for incoming messages
#     def msg_channel(self, channel, user, message):
#         pass
# 
#     def msg_action(self, channel, user, message):
#         pass
# 
#     def msg_private(self, user, message):
#         pass
# 
#     def msg_notice(self, user, message):
#         pass
# 
#     # Event handlers for channel information replies
#     def channel_names(self, channel, nameslist):
#         pass
# 
#     def channel_topic(self, channel, user, topic):
#         pass
# 
#     # Other system event handlers
#     def timer_tick(self):
#         pass


# Path: pyGBot/Plugins/reference/Wiki.py
from pyGBot import log
from pyGBot import format
from pyGBot.BasePlugin import BasePlugin
from HTMLParser import HTMLParser, HTMLParseError
from htmlentitydefs import name2codepoint
from urllib import quote, urlencode
from urllib2 import urlopen, URLError
import re
import json

                return True
        except (IndexError, KeyError, TypeError):
            # Network error or bad response structure
            return None

    def getPreview(self, title, maxlen):
        """Get a preview of the article (the first few hundred characters).
        This assumes the article exists (i.e. check self.articleExists first!)
        If an error accessing the article occurs, an empty string is returned.
        If the data received is malformed, None is returned."""

        # If preview length is 0, no preview; exit early
        if maxlen <= 0:
            return ""

        results = self.getApiResponse(title)

        # if getApiResponse() returns None, failed to retrieve or parse data
        if not results: return None

        try:
            htmlText = results['query']['pages'].values()[0]['revisions'][0]['*']
        except (KeyError, IndexError, TypeError) as e:
            log.logging.exception("reference.Wiki: A %s exception occurred " +\
                "while retrieving article text for '%s': %s",\
                e.__class__.__name__, format.encodeOut(title), str(e))
            return None
        except:
            log.logging.exception("reference.Wiki: An error occurred while " +\
                "retrieving the content of '%s' (maybe malformed JSON?)",\

                format.encodeOut(title))