<commit_before>#!/usr/bin/env python
"""
irker - a simple IRC multiplexer daemon

Takes JSON objects of the form {'channel':<channel-url>, 'message':<text>}
and relays to IRC channels.

Requires Python 2.6.

"""
import os, sys, json, irclib, getopt
import threading, Queue

class Session():
    "IRC session and message queue processing."
    def __init__(self, url):
        self.url = url
        # The consumer thread
        self.queue = Queue.Queue()
        self.thread = threading.Thread(target=self.dequeue)
        self.thread.daemon = True
        self.thread.start()
        # The channel specification
        if not url.startswith("irc://") or url.count("/") != 3:
            raise ValueError
        else:
            url = url[6:]
        parts = url.split(":", 1)
        if len(parts) == 2:
            self.port = int(parts[1])
        else:
            self.port = 6667
        (self.server, self.channel) = parts[0].split("/", 1)
        # Client setup
        self.client = irclib.SimpleIRCClient()
    def enqueue(self, message):
        "Enque a message for transmission."
        self.queue.put(message)
    def dequeue(self):
        "Try to ship pending messages from the queue."
        while True:
            message = self.queue.get()
            self.ship(self.channel, message)
            self.queue.task_done()
    def await(self):
        "Block until processing of the queue is done."
        self.queue.join()
    def ship(self, channel, message):
        "Ship a message to the channel."
        print "%s: %s" % (channel, message)

class Irker:
    "Persistent IRC multiplexer."<commit_msg>Create an appropriate exception type.<commit_after>#!/usr/bin/env python
"""
irker - a simple IRC multiplexer daemon

Takes JSON objects of the form {'channel':<channel-url>, 'message':<text>}
and relays to IRC channels.

Requires Python 2.6.

"""
import os, sys, json, irclib, exceptions, getopt
import threading, Queue

class SessionException(exceptions.Exception):
    def __init__(self, message):
        exceptions.Exception.__init__(self)
        self.message = message

class Session():
    "IRC session and message queue processing."
    def __init__(self, url):
        self.url = url
        # The consumer thread
        self.queue = Queue.Queue()
        self.thread = threading.Thread(target=self.dequeue)
        self.thread.daemon = True
        self.thread.start()
        # The channel specification
        if not url.startswith("irc://") or url.count("/") != 3:
            raise SessionException("ill-formed IRC URL")
        else:
            url = url[6:]
        parts = url.split(":", 1)
        if len(parts) == 2:
            try:
                self.port = int(parts[1])
            except ValuError:
                raise SessionException("invalid port number")
        else:
            self.port = 6667
        (self.server, self.channel) = parts[0].split("/", 1)
        # Client setup
        self.client = irclib.SimpleIRCClient()
    def enqueue(self, message):
        "Enque a message for transmission."
        self.queue.put(message)
    def dequeue(self):
        "Try to ship pending messages from the queue."
        while True:
            message = self.queue.get()
            self.ship(self.channel, message)
            self.queue.task_done()
    def await(self):
        "Block until processing of the queue is done."
        self.queue.join()
    def ship(self, channel, message):
        "Ship a message to the channel."
        print "%s: %s" % (channel, message)

class Irker:
    "Persistent IRC multiplexer."
{'fraction_non_alphanumeric': 0.11776169265033408, 'fraction_numerical': 0.007238307349665924, 'mean_word_length': 2.19946571682992, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2662776', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1029, 'n_words': 313}