mirror of
https://github.com/jlu5/PyLink.git
synced 2025-10-14 23:47:22 +02:00
relay: mangle <( to [ and >) to ] for better displays
This commit is contained in:
parent
729abbd6bf
commit
caa94f983f
@ -133,6 +133,14 @@ IRC_ASCII_ALLOWED_CHARS = string.digits + string.ascii_letters + '/^|\\-_[]{}`'
|
|||||||
FALLBACK_SEPARATOR = '|'
|
FALLBACK_SEPARATOR = '|'
|
||||||
FALLBACK_CHARACTER = '-'
|
FALLBACK_CHARACTER = '-'
|
||||||
|
|
||||||
|
def _replace_special(text):
|
||||||
|
"""
|
||||||
|
Replaces brackets and spaces by similar IRC-representable characters.
|
||||||
|
"""
|
||||||
|
for pair in {('(', '['), (')', ']'), (' ', FALLBACK_CHARACTER), ('<', '['), ('>', ']')}:
|
||||||
|
text = text.replace(pair[0], pair[1])
|
||||||
|
return text
|
||||||
|
|
||||||
def _sanitize(text, extrachars=''):
|
def _sanitize(text, extrachars=''):
|
||||||
"""Replaces characters not in IRC_ASCII_ALLOWED_CHARS with FALLBACK_CHARACTER."""
|
"""Replaces characters not in IRC_ASCII_ALLOWED_CHARS with FALLBACK_CHARACTER."""
|
||||||
whitelist = IRC_ASCII_ALLOWED_CHARS + extrachars
|
whitelist = IRC_ASCII_ALLOWED_CHARS + extrachars
|
||||||
@ -165,9 +173,9 @@ def normalize_nick(irc, netname, nick, times_tagged=0, uid=''):
|
|||||||
nick = base64.b64encode(nick.encode(irc.encoding, 'replace'), altchars=b'[]')
|
nick = base64.b64encode(nick.encode(irc.encoding, 'replace'), altchars=b'[]')
|
||||||
nick = nick.decode()
|
nick = nick.decode()
|
||||||
|
|
||||||
# Normalize spaces to hyphens
|
# Normalize spaces to hyphens, () => []
|
||||||
nick = nick.replace(' ', FALLBACK_CHARACTER)
|
nick = _replace_special(nick)
|
||||||
netname = netname.replace(' ', FALLBACK_CHARACTER)
|
netname = _replace_special(netname)
|
||||||
|
|
||||||
# Get the nick/net separator
|
# Get the nick/net separator
|
||||||
separator = irc.serverdata.get('separator') or \
|
separator = irc.serverdata.get('separator') or \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user