From a5c76f3f607eea29ebf746c32442d9fb980ad741 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Wed, 16 Nov 2011 17:28:14 -0500 Subject: [PATCH] clean up unicode decoding a bit --- bot.py | 2 +- irc.py | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/bot.py b/bot.py index 1054797..3499178 100755 --- a/bot.py +++ b/bot.py @@ -198,7 +198,7 @@ class Phenny(irc.Bot): self.error(origin) def limit(self, origin, func): - if origin.sender and origin.sender.startswith(b'#'): + if origin.sender and origin.sender.startswith('#'): if hasattr(self.config, 'limit'): limits = self.config.limit.get(origin.sender) if limits and (func.__module__ not in limits): diff --git a/irc.py b/irc.py index 0b04404..e5cf732 100755 --- a/irc.py +++ b/irc.py @@ -15,15 +15,11 @@ class Origin(object): source = re.compile(r'([^!]*)!?([^@]*)@?(.*)') def __init__(self, bot, source, args): - if source: - source = source.decode('utf-8') - else: - source = "" match = Origin.source.match(source) self.nick, self.user, self.host = match.groups() if len(args) > 1: - target = args[1].decode('utf-8') + target = args[1] else: target = None mappings = {bot.nick: self.nick, None: None} @@ -125,19 +121,21 @@ class Bot(asynchat.async_chat): line = line[:-1] self.buffer = b'' - if line.startswith(b':'): - source, line = line[1:].split(b' ', 1) + line = line.decode('utf-8') + + if line.startswith(':'): + source, line = line[1:].split(' ', 1) else: source = None - if b' :' in line: - argstr, text = line.split(b' :', 1) - else: argstr, text = line, b'' + if ' :' in line: + argstr, text = line.split(' :', 1) + else: argstr, text = line, '' args = argstr.split() origin = Origin(self, source, args) self.dispatch(origin, tuple([text] + args)) - if args[0] == b'PING': + if args[0] == 'PING': self.write(('PONG', text)) def dispatch(self, origin, args):