Skip to content

Commit

Permalink
Rename Code to Command for clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jul 14, 2024
1 parent 90d541b commit d0df1e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion irc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def _process_line(self, line):
grp = _rfc_1459_command_regexp.match(line).group

source = NickMask.from_group(grp("prefix"))
command = events.Code.lookup(grp("command"))
command = events.Command.lookup(grp("command"))
arguments = message.Arguments.from_group(grp('argument'))
tags = message.Tag.from_group(grp('tags'))

Expand Down
26 changes: 13 additions & 13 deletions irc/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from importlib_resources import files


class Code(str):
class Command(str):
def __new__(cls, code, name):
return super().__new__(cls, name)

Expand All @@ -20,24 +20,24 @@ def __int__(self):
return int(self.code)

@staticmethod
def lookup(command) -> 'Code':
def lookup(raw) -> 'Command':
"""
Lookup a command by numeric or by name.
>>> Code.lookup('002')
>>> Command.lookup('002')
'yourhost'
>>> Code.lookup('002').code
>>> Command.lookup('002').code
'002'
>>> int(Code.lookup('002'))
>>> int(Command.lookup('002'))
2
>>> int(Code.lookup('yourhost'))
>>> int(Command.lookup('yourhost'))
2
>>> Code.lookup('yourhost').code
>>> Command.lookup('yourhost').code
'002'
If a command is supplied that's an unrecognized name or code,
a Code object is still returned.
>>> fallback = Code.lookup('Unknown-command')
a Command object is still returned.
>>> fallback = Command.lookup('Unknown-command')
>>> fallback
'unknown-command'
>>> fallback.code
Expand All @@ -46,18 +46,18 @@ def lookup(command) -> 'Code':
Traceback (most recent call last):
...
ValueError: invalid literal for int() with base 10: 'unknown-command'
>>> fallback = Code.lookup('999')
>>> fallback = Command.lookup('999')
>>> fallback
'999'
>>> int(fallback)
999
"""
fallback = Code(command.lower(), command.lower())
return numeric.get(command, _by_name.get(command.lower(), fallback))
fallback = Command(raw.lower(), raw.lower())
return numeric.get(raw, _by_name.get(raw.lower(), fallback))


_codes = itertools.starmap(
Code,
Command,
map(
str.split,
map(drop_comment, clean(lines_from(files().joinpath('codes.txt')))),
Expand Down

0 comments on commit d0df1e3

Please sign in to comment.