Support 'strict-rfc1459' case mapping

This commit is contained in:
jesopo 2018-09-12 10:18:12 +01:00
parent 58bc741177
commit 08aa72de82

View file

@ -8,6 +8,8 @@ REGEX_HTTP = re.compile("https?://", re.I)
RFC1459_UPPER = r'\[]~' RFC1459_UPPER = r'\[]~'
RFC1459_LOWER = r'|{}^' RFC1459_LOWER = r'|{}^'
STRICT_RFC1459_UPPER = r'\[]'
STRICT_RFC1459_LOWER = r'|{}'
def remove_colon(s): def remove_colon(s):
if s.startswith(":"): if s.startswith(":"):
@ -21,11 +23,17 @@ def _rfc1459_lower(s):
for upper, lower in zip(RFC1459_UPPER, RFC1459_LOWER): for upper, lower in zip(RFC1459_UPPER, RFC1459_LOWER):
s = s.replace(upper, lower) s = s.replace(upper, lower)
return s.lower() return s.lower()
def _strict_rfc1459_lower(s):
for upper, lower in zip(STRICT_RFC1459_UPPER, STRICT_RFC1459_LOWER):
s = s.replace(upper, lower)
return s.lower()
def irc_lower(server, s): def irc_lower(server, s):
if server.case_mapping == "ascii": if server.case_mapping == "ascii":
return s.lower() return s.lower()
elif server.case_mapping == "rfc1459": elif server.case_mapping == "rfc1459":
return _rfc1459_lower(s) return _rfc1459_lower(s)
elif server.case_mapping == "strict-rfc1459":
return _strict_rfc1459_lower(s)
else: else:
raise ValueError("unknown casemapping '%s'" % server.case_mapping) raise ValueError("unknown casemapping '%s'" % server.case_mapping)