mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
NetworkCoreWithUtils: wrap irc.to_lower in a lru_cache
This commit is contained in:
parent
f7dfc38688
commit
3bcf0092e9
18
classes.py
18
classes.py
@ -16,6 +16,7 @@ from copy import deepcopy
|
|||||||
import inspect
|
import inspect
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import queue
|
import queue
|
||||||
|
import functools
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ircmatch
|
import ircmatch
|
||||||
@ -473,24 +474,29 @@ class PyLinkNetworkCore(utils.DeprecatedAttributesObject, utils.CamelCaseToSnake
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
|
class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
# Lock for updateTS to make sure only one thread can change the channel TS at one time.
|
# Lock for updateTS to make sure only one thread can change the channel TS at one time.
|
||||||
self._ts_lock = threading.Lock()
|
self._ts_lock = threading.Lock()
|
||||||
|
|
||||||
def to_lower(self, text):
|
@staticmethod
|
||||||
"""Returns a lowercase representation of text based on the IRC object's
|
@functools.lru_cache(maxsize=2048)
|
||||||
casemapping (rfc1459 or ascii)."""
|
def _to_lower_core(text, casemapping='rfc1459'):
|
||||||
if self.casemapping == 'rfc1459':
|
if casemapping == 'rfc1459':
|
||||||
text = text.replace('{', '[')
|
text = text.replace('{', '[')
|
||||||
text = text.replace('}', ']')
|
text = text.replace('}', ']')
|
||||||
text = text.replace('|', '\\')
|
text = text.replace('|', '\\')
|
||||||
text = text.replace('~', '^')
|
text = text.replace('~', '^')
|
||||||
# Encode the text as bytes first, and then lowercase it so that only ASCII characters are
|
# Encode the text as bytes first, and then lowercase it so that only ASCII characters are
|
||||||
# changed. Unicode in channel names, etc. is case sensitive because IRC is just that old of
|
# changed. Unicode in channel names, etc. *is* case sensitive!
|
||||||
# a protocol!!!
|
|
||||||
return text.encode().lower().decode()
|
return text.encode().lower().decode()
|
||||||
|
|
||||||
|
def to_lower(self, text):
|
||||||
|
"""Returns a lowercase representation of text based on the IRC object's
|
||||||
|
casemapping (rfc1459 or ascii)."""
|
||||||
|
return self._to_lower_core(text, casemapping=self.casemapping)
|
||||||
|
|
||||||
def parse_modes(self, target, args):
|
def parse_modes(self, target, args):
|
||||||
"""Parses a modestring list into a list of (mode, argument) tuples.
|
"""Parses a modestring list into a list of (mode, argument) tuples.
|
||||||
['+mitl-o', '3', 'person'] => [('+m', None), ('+i', None), ('+t', None), ('+l', '3'), ('-o', 'person')]
|
['+mitl-o', '3', 'person'] => [('+m', None), ('+i', None), ('+t', None), ('+l', '3'), ('-o', 'person')]
|
||||||
|
Loading…
Reference in New Issue
Block a user