From: Eric S. Raymond Date: Sat, 25 Aug 2012 13:03:40 +0000 (-0400) Subject: How to parse the channel spec. X-Git-Tag: 1.0~137 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0d5323d2940c8ceeebcf55c6103e1f367d21dfa1;p=irker.git How to parse the channel spec. --- diff --git a/irker.py b/irker.py index 396ac30..fe2b743 100755 --- a/irker.py +++ b/irker.py @@ -13,12 +13,30 @@ import threading, Queue class Session(): "IRC session and message queue processing." - def __init__(self, channel): - self.channel = channel + 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: + try: + self.port = int(parts[1]) + except ValueError: + print "Error: Erroneous port." + sys.exit(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)