clean up unicode decoding a bit

master
mutantmonkey 2011-11-16 17:28:14 -05:00
parent d5a614d530
commit a5c76f3f60
2 changed files with 10 additions and 12 deletions

2
bot.py
View File

@ -198,7 +198,7 @@ class Phenny(irc.Bot):
self.error(origin) self.error(origin)
def limit(self, origin, func): 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'): if hasattr(self.config, 'limit'):
limits = self.config.limit.get(origin.sender) limits = self.config.limit.get(origin.sender)
if limits and (func.__module__ not in limits): if limits and (func.__module__ not in limits):

20
irc.py
View File

@ -15,15 +15,11 @@ class Origin(object):
source = re.compile(r'([^!]*)!?([^@]*)@?(.*)') source = re.compile(r'([^!]*)!?([^@]*)@?(.*)')
def __init__(self, bot, source, args): def __init__(self, bot, source, args):
if source:
source = source.decode('utf-8')
else:
source = ""
match = Origin.source.match(source) match = Origin.source.match(source)
self.nick, self.user, self.host = match.groups() self.nick, self.user, self.host = match.groups()
if len(args) > 1: if len(args) > 1:
target = args[1].decode('utf-8') target = args[1]
else: target = None else: target = None
mappings = {bot.nick: self.nick, None: None} mappings = {bot.nick: self.nick, None: None}
@ -125,19 +121,21 @@ class Bot(asynchat.async_chat):
line = line[:-1] line = line[:-1]
self.buffer = b'' self.buffer = b''
if line.startswith(b':'): line = line.decode('utf-8')
source, line = line[1:].split(b' ', 1)
if line.startswith(':'):
source, line = line[1:].split(' ', 1)
else: source = None else: source = None
if b' :' in line: if ' :' in line:
argstr, text = line.split(b' :', 1) argstr, text = line.split(' :', 1)
else: argstr, text = line, b'' else: argstr, text = line, ''
args = argstr.split() args = argstr.split()
origin = Origin(self, source, args) origin = Origin(self, source, args)
self.dispatch(origin, tuple([text] + args)) self.dispatch(origin, tuple([text] + args))
if args[0] == b'PING': if args[0] == 'PING':
self.write(('PONG', text)) self.write(('PONG', text))
def dispatch(self, origin, args): def dispatch(self, origin, args):