mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 14:59:34 +01:00
Re-enabled ircutils.nick under a new name (IrcString) and for a different purpose (to make IrcDict and IrcSet work properly).
This commit is contained in:
parent
0231cdcfd4
commit
936c1fd85e
@ -297,55 +297,56 @@ def shrinkList(L, sep='', limit=425):
|
|||||||
L.pop()
|
L.pop()
|
||||||
|
|
||||||
|
|
||||||
## class nick(str):
|
class IrcString(str):
|
||||||
## """This class does case-insensitive comparison and hashing of nicks."""
|
"""This class does case-insensitive comparison and hashing of nicks."""
|
||||||
## def __init__(self, s):
|
def __init__(self, s):
|
||||||
## self.original = s
|
s = str(s)
|
||||||
## self.lowered = toLower(s)
|
self.original = s
|
||||||
|
self.lowered = toLower(s)
|
||||||
|
|
||||||
## def __repr__(self):
|
def __repr__(self):
|
||||||
## return repr(self.original)
|
return repr(self.original)
|
||||||
|
|
||||||
## def __str__(self):
|
def __str__(self):
|
||||||
## return str(self.original)
|
return str(self.original)
|
||||||
|
|
||||||
## def __eq__(self, s):
|
def __eq__(self, s):
|
||||||
## try:
|
try:
|
||||||
## return toLower(s) == self.lowered
|
return toLower(s) == self.lowered
|
||||||
## except:
|
except:
|
||||||
## return False
|
return False
|
||||||
|
|
||||||
## def __hash__(self):
|
def __hash__(self):
|
||||||
## return hash(self.lowered)
|
return hash(self.lowered)
|
||||||
|
|
||||||
|
|
||||||
class IrcDict(dict):
|
class IrcDict(dict):
|
||||||
"""Subclass of dict to make key comparison IRC-case insensitive."""
|
"""Subclass of dict to make key comparison IRC-case insensitive."""
|
||||||
def __contains__(self, s):
|
def __contains__(self, s):
|
||||||
return dict.__contains__(self, toLower(s))
|
return dict.__contains__(self, IrcString(s))
|
||||||
has_key = __contains__
|
has_key = __contains__
|
||||||
|
|
||||||
def __setitem__(self, s, v):
|
def __setitem__(self, s, v):
|
||||||
dict.__setitem__(self, toLower(s), v)
|
dict.__setitem__(self, IrcString(s), v)
|
||||||
|
|
||||||
def __getitem__(self, s):
|
def __getitem__(self, s):
|
||||||
return dict.__getitem__(self, toLower(s))
|
return dict.__getitem__(self, IrcString(s))
|
||||||
|
|
||||||
def __delitem__(self, s):
|
def __delitem__(self, s):
|
||||||
dict.__delitem__(self, toLower(s))
|
dict.__delitem__(self, IrcString(s))
|
||||||
|
|
||||||
class IrcSet(sets.Set):
|
class IrcSet(sets.Set):
|
||||||
def add(self, s):
|
def add(self, s):
|
||||||
return sets.Set.add(self, toLower(s))
|
return sets.Set.add(self, IrcString(s))
|
||||||
|
|
||||||
def remove(self, s):
|
def remove(self, s):
|
||||||
return sets.Set.remove(self, toLower(s))
|
return sets.Set.remove(self, IrcString(s))
|
||||||
|
|
||||||
def discard(self, s):
|
def discard(self, s):
|
||||||
return sets.Set.discard(self, toLower(s))
|
return sets.Set.discard(self, IrcString(s))
|
||||||
|
|
||||||
def __contains__(self, s):
|
def __contains__(self, s):
|
||||||
return sets.Set.__contains__(self, toLower(s))
|
return sets.Set.__contains__(self, IrcString(s))
|
||||||
|
|
||||||
has_key = __contains__
|
has_key = __contains__
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user