3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-24 19:52:53 +01:00

Move _get_SID/_get_UID to IRCCommonProtocol

This commit is contained in:
James Lu 2017-07-02 22:36:47 -07:00
parent bbc4dec8dd
commit 640e903dd6
2 changed files with 24 additions and 26 deletions

View File

@ -1096,32 +1096,6 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
_clear()
_apply()
# TODO: these wrappers really need to be standardized
def _get_SID(self, sname):
"""Returns the SID of a server with the given name, if present."""
name = sname.lower()
if name in self.servers:
return name
for k, v in self.servers.items():
if v.name.lower() == name:
return k
else:
return sname # Fall back to given text instead of None
_getSid = _get_SID
def _get_UID(self, target):
"""Converts a nick argument to its matching UID. This differs from irc.nick_to_uid()
in that it returns the original text instead of None, if no matching nick is found."""
if target in self.users:
return target
target = self.nick_to_uid(target) or target
return target
_getUid = _get_UID
class IRCNetwork(PyLinkNetworkCoreWithUtils):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

View File

@ -19,6 +19,30 @@ class IRCCommonProtocol(IRCNetwork):
port = self.serverdata['port']
assert type(port) == int and 0 < port < 65535, "Invalid port %r for network %s" % (port, self.name)
# TODO: these wrappers really need to be standardized
def _get_SID(self, sname):
"""Returns the SID of a server with the given name, if present."""
name = sname.lower()
if name in self.servers:
return name
for k, v in self.servers.items():
if v.name.lower() == name:
return k
else:
return sname # Fall back to given text instead of None
def _get_UID(self, target):
"""Converts a nick argument to its matching UID. This differs from irc.nick_to_uid()
in that it returns the original text instead of None, if no matching nick is found."""
if target in self.users:
return target
target = self.nick_to_uid(target) or target
return target
@staticmethod
def parse_args(args):
"""