Fix proper lowercasing, take 2

This commit is contained in:
Vgr E. Barry 2017-01-13 12:13:32 -05:00
parent 2cd410ace8
commit fb7bf56579
2 changed files with 8 additions and 6 deletions

View File

@ -71,11 +71,13 @@ def _send(data, first, sep, client, send_type, name):
extra, line = line[:length], line[length:] extra, line = line[:length], line[length:]
client.send("{0} {1} :{2}{3}".format(send_type, name, first, extra)) client.send("{0} {1} :{2}{3}".format(send_type, name, first, extra))
def lower(nick, *, host=False): def lower(nick, *, casemapping=None):
if nick is None: if nick is None:
return None return None
if isinstance(nick, IRCContext) or host: if isinstance(nick, IRCContext):
return nick.lower() return nick.lower()
if casemapping is None:
casemapping = Features["CASEMAPPING"]
mapping = { mapping = {
"[": "{", "[": "{",
@ -84,9 +86,9 @@ def lower(nick, *, host=False):
"^": "~", "^": "~",
} }
if Features["CASEMAPPING"] == "strict-rfc1459": if casemapping == "strict-rfc1459":
mapping.pop("^") mapping.pop("^")
elif Features["CASEMAPPING"] == "ascii": elif casemapping == "ascii":
mapping.clear() mapping.clear()
return nick.lower().translate(str.maketrans(mapping)) return nick.lower().translate(str.maketrans(mapping))

View File

@ -279,7 +279,7 @@ class User(IRCContext):
return self._compare(other, __class__, "nick", "ident", "host", "realname", "account") return self._compare(other, __class__, "nick", "ident", "host", "realname", "account")
def lower(self): def lower(self):
temp = type(self)(self.client, lower(self.nick), lower(self.ident), lower(self.host, host=True), lower(self.realname), lower(self.account)) temp = type(self)(self.client, lower(self.nick), lower(self.ident), lower(self.host, casemapping="ascii"), lower(self.realname), lower(self.account))
if temp is not self: # If everything is already lowercase, we'll get back the same instance if temp is not self: # If everything is already lowercase, we'll get back the same instance
temp.channels = self.channels temp.channels = self.channels
temp.ref = self.ref or self temp.ref = self.ref or self
@ -573,7 +573,7 @@ class BotUser(User): # TODO: change all the 'if x is Bot' for 'if isinstance(x,
temp = type(self)(self.client, lower(self.nick)) temp = type(self)(self.client, lower(self.nick))
if temp is not self: if temp is not self:
temp.ident = lower(self.ident) temp.ident = lower(self.ident)
temp.host = lower(self.host, host=True) temp.host = lower(self.host, casemapping="ascii")
temp.realname = lower(self.realname) temp.realname = lower(self.realname)
temp.account = lower(self.account) temp.account = lower(self.account)
temp.modes = self.modes temp.modes = self.modes