Nuked ircutils.nick. Good riddance.

This commit is contained in:
Jeremy Fincher 2003-08-12 19:12:12 +00:00
parent 7fb632c49f
commit 2a4c2ea185
3 changed files with 56 additions and 41 deletions

View File

@ -151,15 +151,13 @@ class Channel(object):
__slots__ = ('users', 'ops', 'halfops', 'voices', 'topic')
def __init__(self):
self.topic = ''
self.users = sets.Set()
self.ops = sets.Set()
self.halfops = sets.Set()
self.voices = sets.Set()
self.users = ircutils.IrcSet() # sets.Set()
self.ops = ircutils.IrcSet() # sets.Set()
self.halfops = ircutils.IrcSet() # sets.Set()
self.voices = ircutils.IrcSet() # sets.Set()
def addUser(self, user):
nick = user.lstrip('@%+')
if not isinstance(nick, ircutils.nick):
nick = ircutils.nick(nick)
while user and user[0] in '@%+':
(marker, user) = (user[0], user[1:])
if marker == '@':
@ -174,18 +172,12 @@ class Channel(object):
# Note that this doesn't have to have the sigil (@%+) that users
# have to have for addUser; it just changes the name of the user
# without changing any of his categories.
if not isinstance(oldNick, ircutils.nick):
oldNick = ircutils.nick(oldNick)
if not isinstance(newNick, ircutils.nick):
newNick = ircutils.nick(newNick)
for s in (self.users, self.ops, self.halfops, self.voices):
if oldNick in s:
s.discard(oldNick)
s.add(newNick)
def removeUser(self, user):
if not isinstance(user, ircutils.nick):
user = ircutils.nick(user)
self.users.discard(user)
self.ops.discard(user)
self.halfops.discard(user)
@ -305,7 +297,7 @@ class IrcState(IrcCommandDispatcher):
chan.topic = msg.args[2]
def doNick(self, irc, msg):
newNick = ircutils.nick(msg.args[0])
newNick = msg.args[0]
oldNick = msg.nick
try:
if msg.user and msg.host:
@ -340,7 +332,7 @@ class Irc(object):
self.password = password
self.user = user or nick # Default to nick if user isn't provided.
self.ident = ident or nick # Ditto.
self.prefix = '%s!%s@%s' % (nick, ident, 'unset')
self.prefix = '%s!%s@%s' % (nick, ident, 'unset.domain')
if callbacks is None:
self.callbacks = []
else:
@ -447,18 +439,25 @@ class Irc(object):
def feedMsg(self, msg):
debug.msg('%s %s' % (time.strftime(conf.timestampFormat), msg), 'low')
# Yeah, so this is odd. Some networks (oftc) seem to give us certain
# messages with our nick instead of our prefix. We'll fix that here.
if msg.prefix == self.nick:
debug.msg('Got one of those odd nick-instead-of-prefix msgs.')
msg = ircmsgs.IrcMsg(prefix=self.prefix,
command=msg.command,
args=msg.args)
# First, make sure self.nick is always consistent with the server.
if msg.command == 'NICK' and msg.nick == self.nick:
if ircdb.users.hasUser(self.nick):
ircdb.users.delUser(self.nick)
if ircdb.users.hasUser(self.prefix):
ircdb.users.delUser(self.prefix)
self.nick = ircutils.nick(msg.args[0])
self.nick = msg.args[0]
(nick, user, domain) = ircutils.splitHostmask(msg.prefix)
self.prefix = '%s!%s@%s' % (self.nick, user, domain)
elif msg.command in self._nickSetters:
#debug.printf('msg.command in self._nickSetters')
newnick = ircutils.nick(msg.args[0])
newnick = msg.args[0]
if self.nick != newnick:
debug.printf('Hmm...self.nick != newnick. Odd.')
self.nick = newnick

View File

@ -39,6 +39,7 @@ IRC-case-insensitive fashion), and numerous other things.
from fix import *
import re
import sets
import string
import fnmatch
import operator
@ -59,7 +60,7 @@ def isServerHostmask(s):
def nickFromHostmask(hostmask):
"""Returns the nick from a user hostmask."""
assert isUserHostmask(hostmask)
return nick(hostmask.split('!', 1)[0])
return hostmask.split('!', 1)[0]
def userFromHostmask(hostmask):
"""Returns the user from a user hostmask."""
@ -74,9 +75,9 @@ def hostFromHostmask(hostmask):
def splitHostmask(hostmask):
"""Returns the nick, user, host of a user hostmask."""
assert isUserHostmask(hostmask)
nck, rest = hostmask.split('!', 1)
nick, rest = hostmask.split('!', 1)
user, host = rest.split('@', 1)
return (nick(nck), user, host)
return (nick, user, host)
def joinHostmask(nick, ident, host):
"""Joins the nick, ident, host into a user hostmask."""
@ -296,26 +297,26 @@ def shrinkList(L, sep='', limit=425):
L.pop()
class nick(str):
"""This class does case-insensitive comparison and hashing of nicks."""
def __init__(self, s):
self.original = s
self.lowered = toLower(s)
## class nick(str):
## """This class does case-insensitive comparison and hashing of nicks."""
## def __init__(self, s):
## self.original = s
## self.lowered = toLower(s)
def __repr__(self):
return repr(self.original)
## def __repr__(self):
## return repr(self.original)
def __str__(self):
return str(self.original)
## def __str__(self):
## return str(self.original)
def __eq__(self, s):
try:
return toLower(s) == self.lowered
except:
return False
## def __eq__(self, s):
## try:
## return toLower(s) == self.lowered
## except:
## return False
def __hash__(self):
return hash(self.lowered)
## def __hash__(self):
## return hash(self.lowered)
class IrcDict(dict):
@ -333,6 +334,21 @@ class IrcDict(dict):
def __delitem__(self, s):
dict.__delitem__(self, toLower(s))
class IrcSet(sets.Set):
def add(self, s):
return sets.Set.add(self, toLower(s))
def remove(self, s):
return sets.Set.remove(self, toLower(s))
def discard(self, s):
return sets.Set.discard(self, toLower(s))
def __contains__(self, s):
return sets.Set.__contains__(self, toLower(s))
has_key = __contains__
if __name__ == '__main__':
import sys, doctest

View File

@ -141,12 +141,12 @@ class FunctionsTestCase(unittest.TestCase):
self.assertEqual('jemfinch', ircutils.toLower('jemfinch'))
self.assertEqual('{}|^', ircutils.toLower('[]\\~'))
def testNick(self):
nicks = ['jemfinch', 'jemfinch\\[]~']
for nick in nicks:
self.assertEqual(str(ircutils.nick(nick)), str(nick))
self.assertEqual(ircutils.nick(nick), nick)
self.assertEqual(ircutils.nick(nick), ircutils.toLower(nick))
## def testNick(self):
## nicks = ['jemfinch', 'jemfinch\\[]~']
## for nick in nicks:
## self.assertEqual(str(ircutils.nick(nick)), str(nick))
## self.assertEqual(ircutils.nick(nick), nick)
## self.assertEqual(ircutils.nick(nick), ircutils.toLower(nick))
def testReplyTo(self):
prefix = 'foo!bar@baz'