Table of contents Index

# Module irclib

    class Connection # Base class for IRC connections.
    class DCCConnection(Connection) # Unimplemented.
    class Event # Class representing an IRC event.
    class IRC # Class that handles one or several IRC server connections.
    class IRCError(Exception) # Represents an IRC exception.
    class ServerConnection(Connection) # This class represents an IRC server connection.
    class ServerConnectionError(IRCError)
    class SimpleIRCClient # A simple single-server IRC client class.
    def _ctcp_dequote(message) # [Internal] Dequote a message according to CTCP specifications.
    def _parse_modes(mode_string, unary_modes='') # [Internal]
    def _ping_ponger(connection, event) # [Internal]
    def irc_lower(s) # Returns a lowercased string.
    def is_channel(string) # Check if a string is a channel name.
    def mask_matches(nick, mask) # Check if a nick matches a mask.
    def nm_to_h(s) # Get the host part of a nickmask.
    def nm_to_n(s) # Get the nick part of a nickmask.
    def nm_to_u(s) # Get the user part of a nickmask.
    def nm_to_uh(s) # Get the userhost part of a nickmask.
    def parse_channel_modes(mode_string) # Parse a channel mode string.
    def parse_nick_modes(mode_string) # Parse a nick mode string.
    int DEBUG = 0
    tuple VERSION = (0, 3, 1)
    string _CTCP_DELIMITER = '\001'
    string _CTCP_LEVEL_QUOTE = '\\'
    string _LOW_LEVEL_QUOTE = '\020'
    string __file__ = './irclib.py'
    string _alpha = 'abcdefghijklmnopqrstuvxyz'
    string _ircstring_translation = '\000\001\002\003\004\005\00...\371\372\373\374\375\376\377'
    instance _linesep_regexp = re.RegexObject instance
    dictionary _low_level_mapping = {'\020': '\020', '0': '\000', 'n': '\012', 'r': '\015'}
    instance _low_level_regexp = re.RegexObject instance
    instance _rfc_1459_command_regexp = re.RegexObject instance
    string _special = '-[]\\`^{}'
    list all_events = ['disconnect', 'ctcp', 'ctcpreply', 'error', 'join', 'kick', ...]
    list generated_events = ['disconnect', 'ctcp', 'ctcpreply']
    string nick_characters = 'abcdefghijklmnopqrstuvxyzAB...QRSTUVXYZ0123456789-[]\\`^{}'
    dictionary numeric_events = {'001': 'welcome', '002': 'yourhost', '003': 'created', '004': 'myinfo', ...}
    list protocol_events = ['error', 'join', 'kick', 'mode', 'part', 'ping', ...]

## Description

This library is intended to encapsulate the IRC protocol at a quite low level. It provides an event-driven IRC client framework. It has a fairly thorough support for the basic IRC protocol and CTCP, but DCC connection support is not yet implemented.

In order to understand how to make an IRC client, I'm afraid you more or less must understand the IRC specifications. They are available here: IRC specifications.

### The main features of the IRC client framework are:

- Abstraction of the IRC protocol.
- Handles multiple simultaneous IRC server connections.
- Handles server PONGing transparently.
- Messages to the IRC server are done by calling methods on an IRC connection object.
- Messages from an IRC server triggers events, which can be caught by event handlers.
- Reading from and writing to IRC server sockets are normally done by an internal select() loop, but the select()ing may be done by an external main loop.
- Functions can be registered to execute at specified times by the event-loop.
- Decodes CTCP tagging correctly (hopefully); I haven't seen any other IRC client implementation that handles the CTCP specification subtilties.
- A kind of simple, single-server, object-oriented IRC client class that dispatches events to instance methods is included.

### Current limitations:

- The IRC protocol shines through the abstraction a bit too much.
- Data is not written asynchronously to the server, i.e. the write() may block if the TCP buffers are stuffed.
- There are no support for DCC connections.
- The author haven't even read RFC 2810, 2811, 2812 and 2813.
- Like most projects, documentation is lacking...

Since I seldom use IRC anymore, I will probably not work much on the library. If you want to help or continue developing the library, please contact me (Joel Rosdahl <joel@rosdahl.net>).

## _ctcp_dequote(message)

[Internal] Dequote a message according to CTCP specifications.

The function returns a list where each element can be either a string (normal message) or a tuple of one or two strings (tagged messages). If a tuple has only one element (ie is a singleton), that element is the tag; otherwise the tuple has two elements: the tag and the data.

## irc_lower(s)

Returns a lowercased string.

The definition of lowercased comes from the IRC specification (RFC 1459).

## is_channel(string)

Check if a string is a channel name.

Returns true if the argument is a channel name, otherwise false.

## mask_matches(nick, mask)

Check if a nick matches a mask.

Returns true if the nick matches, otherwise false.

## nm_to_h(s)

Get the host part of a nickmask.

(The source of an Event is a nickmask.)

## nm_to_n(s)

Get the nick part of a nickmask.

(The source of an Event is a nickmask.)

## nm_to_u(s)

Get the user part of a nickmask.

(The source of an Event is a nickmask.)

## nm_to_uh(s)

Get the userhost part of a nickmask.

(The source of an Event is a nickmask.)

## parse_channel_modes(mode_string)

Parse a channel mode string.

The function returns a list of lists with three members: sign, mode and argument. The sign is "+" or "-". The argument is None if mode isn't one of "b", "k", "l", "v" or "o".Example:

    >>> irclib.parse_channel_modes("+ab-c foo")
    [['+', 'a', None], ['+', 'b', 'foo'], ['-', 'c', None]]

## parse_nick_modes(mode_string)

Parse a nick mode string.

The function returns a list of lists with three members: sign, mode and argument. The sign is "+" or "-". The argument is always None.

Example:

    >>> irclib.parse_nick_modes("+ab-c")
    [['+', 'a', None], ['+', 'b', None], ['-', 'c', None]]