update ircstates to v0.9.0, use const RPL/ERR vars
This commit is contained in:
parent
2d67587938
commit
7232876a75
4 changed files with 32 additions and 48 deletions
|
@ -1,6 +1,5 @@
|
|||
from typing import List, Optional
|
||||
from irctokens import Line
|
||||
from ircstates import NUMERIC_NAMES
|
||||
from .interface import IServer, IMatchResponse, IMatchResponseParam
|
||||
|
||||
class Responses(IMatchResponse):
|
||||
|
@ -33,24 +32,6 @@ class Response(Responses):
|
|||
def __repr__(self) -> str:
|
||||
return f"Response({self._commands[0]}: {self._params!r})"
|
||||
|
||||
|
||||
class Numeric(Response):
|
||||
def __init__(self,
|
||||
name: str,
|
||||
params: List[IMatchResponseParam]=[]):
|
||||
super().__init__(NUMERIC_NAMES.get(name, name), params)
|
||||
|
||||
class Numerics(Responses):
|
||||
def __init__(self,
|
||||
numerics: List[str],
|
||||
params: List[IMatchResponseParam]=[]):
|
||||
self._numerics = numerics
|
||||
numerics = [NUMERIC_NAMES.get(n, n) for n in numerics]
|
||||
super().__init__(numerics, params)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Numerics({self._numerics!r}: {self._params!r})"
|
||||
|
||||
class ResponseOr(IMatchResponse):
|
||||
def __init__(self, *responses: IMatchResponse):
|
||||
self._responses = responses
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
from typing import List
|
||||
from enum import Enum
|
||||
from base64 import b64decode, b64encode
|
||||
from irctokens import build
|
||||
from typing import List
|
||||
from enum import Enum
|
||||
from base64 import b64decode, b64encode
|
||||
from irctokens import build
|
||||
from ircstates.numerics import *
|
||||
|
||||
from .matching import Response, ResponseOr, Numerics, ParamAny
|
||||
from .matching import ResponseOr, Responses, Response, ParamAny
|
||||
from .contexts import ServerContext
|
||||
from .params import SASLParams
|
||||
from .scram import SCRAMContext
|
||||
|
@ -27,10 +28,10 @@ class SASLUnknownMechanismError(SASLError):
|
|||
pass
|
||||
|
||||
AUTHENTICATE_ANY = Response("AUTHENTICATE", [ParamAny()])
|
||||
NUMERICS_FAIL = Numerics(["ERR_SASLFAIL"])
|
||||
NUMERICS_INITIAL = Numerics(
|
||||
["ERR_SASLFAIL", "ERR_SASLALREADY", "RPL_SASLMECHS"])
|
||||
NUMERICS_LAST = Numerics(["RPL_SASLSUCCESS", "ERR_SASLFAIL"])
|
||||
|
||||
NUMERICS_FAIL = Response(ERR_SASLFAIL)
|
||||
NUMERICS_INITIAL = Responses([ERR_SASLFAIL, ERR_SASLALREADY, RPL_SASLMECHS])
|
||||
NUMERICS_LAST = Responses([RPL_SASLSUCCESS, ERR_SASLFAIL])
|
||||
|
||||
def _b64e(s: str):
|
||||
return b64encode(s.encode("utf8")).decode("ascii")
|
||||
|
|
|
@ -2,13 +2,14 @@ from asyncio import Future, PriorityQueue
|
|||
from typing import Awaitable, Deque, Dict, List, Optional, Set, Tuple
|
||||
from collections import deque
|
||||
|
||||
from asyncio_throttle import Throttler
|
||||
from ircstates import Emit, Channel, NUMERIC_NAMES
|
||||
from irctokens import build, Line, tokenise
|
||||
from asyncio_throttle import Throttler
|
||||
from ircstates import Emit, Channel
|
||||
from ircstates.numerics import *
|
||||
from irctokens import build, Line, tokenise
|
||||
|
||||
from .ircv3 import CAPContext, CAP_ECHO, CAP_SASL, CAP_LABEL, LABEL_TAG
|
||||
from .sasl import SASLContext, SASLResult
|
||||
from .matching import ResponseOr, Numerics, Numeric, ParamAny, ParamFolded
|
||||
from .matching import ResponseOr, Response, ParamAny, ParamFolded
|
||||
from .asyncs import MaybeAwait
|
||||
from .struct import Whois
|
||||
|
||||
|
@ -250,7 +251,7 @@ class Server(IServer):
|
|||
|
||||
while folded_names:
|
||||
line = await self.wait_for(
|
||||
Numeric("RPL_CHANNELMODEIS", [ParamAny(), ParamAny()]))
|
||||
Numeric(RPL_CHANNELMODEIS, [ParamAny(), ParamAny()]))
|
||||
|
||||
folded = self.casefold(line.params[1])
|
||||
if folded in folded_names:
|
||||
|
@ -269,23 +270,24 @@ class Server(IServer):
|
|||
params = [ParamAny(), ParamFolded(folded)]
|
||||
obj = Whois()
|
||||
while True:
|
||||
line = await self.wait_for(Numerics([
|
||||
"RPL_WHOISUSER",
|
||||
"RPL_WHOISSERVER",
|
||||
"RPL_WHOISOPERATOR",
|
||||
"RPL_WHOISIDLE",
|
||||
"RPL_WHOISHOST",
|
||||
"RPL_WHOISACCOUNT",
|
||||
"RPL_WHOISSECURE",
|
||||
"RPL_ENDOFWHOIS"
|
||||
line = await self.wait_for(Responses([
|
||||
RPL_WHOISUSER,
|
||||
RPL_WHOISSERVER,
|
||||
RPL_WHOISOPERATOR,
|
||||
RPL_WHOISIDLE,
|
||||
RPL_WHOISHOST,
|
||||
RPL_WHOISACCOUNT,
|
||||
RPL_WHOISSECURE,
|
||||
RPL_ENDOFWHOIS
|
||||
], params))
|
||||
|
||||
if line.command == NUMERIC_NAMES["RPL_WHOISUSER"]:
|
||||
if line.command == RPL_WHOISUSER:
|
||||
obj.username, obj.hostname, _, obj.realname = line.params[2:]
|
||||
elif line.command == NUMERIC_NAMES["RPL_WHOISIDLE"]:
|
||||
obj.idle, obj.signon, _ = line.params[2:]
|
||||
elif line.command == NUMERIC_NAMES["RPL_WHOISACCOUNT"]:
|
||||
elif line.command == RPL_WHOISIDLE:
|
||||
obj.idle, signon, _ = line.params[2:]
|
||||
obj.signon = int(signon)
|
||||
elif line.command == RPL_WHOISACCOUNT:
|
||||
obj.account = line.params[2]
|
||||
elif line.command == NUMERIC_NAMES["RPL_ENDOFWHOIS"]:
|
||||
elif line.command == RPL_ENDOFWHOIS:
|
||||
return obj
|
||||
return MaybeAwait(_assure)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
anyio ==1.3.0
|
||||
asyncio-throttle ==1.0.1
|
||||
dataclasses ==0.6
|
||||
ircstates ==0.8.9
|
||||
ircstates ==0.9.0
|
||||
async_stagger ==0.3.0
|
||||
|
|
Loading…
Reference in a new issue