mirror of https://github.com/Shizmob/pydle.git
#2 removed `async` references in `ircv3/cap`
This commit is contained in:
parent
2e15894c35
commit
471fce4b24
|
@ -1,7 +1,6 @@
|
|||
## cap.py
|
||||
# Server <-> client optional extension indication support.
|
||||
# See also: http://ircv3.atheme.org/specification/capability-negotiation-3.1
|
||||
from pydle import async
|
||||
import pydle.protocol
|
||||
from pydle.features import rfc1459
|
||||
|
||||
|
@ -29,17 +28,16 @@ class CapabilityNegotiationSupport(rfc1459.RFC1459Support):
|
|||
self._capabilities_requested = set()
|
||||
self._capabilities_negotiating = set()
|
||||
|
||||
@async.coroutine
|
||||
def _register(self):
|
||||
async def _register(self):
|
||||
""" Hijack registration to send a CAP LS first. """
|
||||
if self.registered:
|
||||
return
|
||||
|
||||
# Ask server to list capabilities.
|
||||
yield from self.rawmsg('CAP', 'LS', '302')
|
||||
await self.rawmsg('CAP', 'LS', '302')
|
||||
|
||||
# Register as usual.
|
||||
yield from super()._register()
|
||||
await super()._register()
|
||||
|
||||
def _capability_normalize(self, cap):
|
||||
cap = cap.lstrip(PREFIXES).lower()
|
||||
|
@ -53,19 +51,17 @@ class CapabilityNegotiationSupport(rfc1459.RFC1459Support):
|
|||
|
||||
## API.
|
||||
|
||||
@async.coroutine
|
||||
def _capability_negotiated(self, capab):
|
||||
async def _capability_negotiated(self, capab):
|
||||
""" Mark capability as negotiated, and end negotiation if we're done. """
|
||||
self._capabilities_negotiating.discard(capab)
|
||||
|
||||
if not self._capabilities_requested and not self._capabilities_negotiating:
|
||||
yield from self.rawmsg('CAP', 'END')
|
||||
await self.rawmsg('CAP', 'END')
|
||||
|
||||
|
||||
## Message handlers.
|
||||
|
||||
@async.coroutine
|
||||
def on_raw_cap(self, message):
|
||||
async def on_raw_cap(self, message):
|
||||
""" Handle CAP message. """
|
||||
target, subcommand = message.params[:2]
|
||||
params = message.params[2:]
|
||||
|
@ -73,12 +69,11 @@ class CapabilityNegotiationSupport(rfc1459.RFC1459Support):
|
|||
# Call handler.
|
||||
attr = 'on_raw_cap_' + pydle.protocol.identifierify(subcommand)
|
||||
if hasattr(self, attr):
|
||||
yield from getattr(self, attr)(params)
|
||||
await getattr(self, attr)(params)
|
||||
else:
|
||||
self.logger.warning('Unknown CAP subcommand sent from server: %s', subcommand)
|
||||
|
||||
@async.coroutine
|
||||
def on_raw_cap_ls(self, params):
|
||||
async def on_raw_cap_ls(self, params):
|
||||
""" Update capability mapping. Request capabilities. """
|
||||
to_request = set()
|
||||
|
||||
|
@ -91,7 +86,7 @@ class CapabilityNegotiationSupport(rfc1459.RFC1459Support):
|
|||
|
||||
# Check if we support the capability.
|
||||
attr = 'on_capability_' + pydle.protocol.identifierify(capab) + '_available'
|
||||
supported = (yield from getattr(self, attr)(value)) if hasattr(self, attr) else False
|
||||
supported = (await getattr(self, attr)(value)) if hasattr(self, attr) else False
|
||||
|
||||
if supported:
|
||||
if isinstance(supported, str):
|
||||
|
@ -104,13 +99,12 @@ class CapabilityNegotiationSupport(rfc1459.RFC1459Support):
|
|||
if to_request:
|
||||
# Request some capabilities.
|
||||
self._capabilities_requested.update(x.split(CAPABILITY_VALUE_DIVIDER, 1)[0] for x in to_request)
|
||||
yield from self.rawmsg('CAP', 'REQ', ' '.join(to_request))
|
||||
await self.rawmsg('CAP', 'REQ', ' '.join(to_request))
|
||||
else:
|
||||
# No capabilities requested, end negotiation.
|
||||
yield from self.rawmsg('CAP', 'END')
|
||||
await self.rawmsg('CAP', 'END')
|
||||
|
||||
@async.coroutine
|
||||
def on_raw_cap_list(self, params):
|
||||
async def on_raw_cap_list(self, params):
|
||||
""" Update active capabilities. """
|
||||
self._capabilities = { capab: False for capab in self._capabilities }
|
||||
|
||||
|
@ -118,8 +112,7 @@ class CapabilityNegotiationSupport(rfc1459.RFC1459Support):
|
|||
capab, value = self._capability_normalize(capab)
|
||||
self._capabilities[capab] = value if value else True
|
||||
|
||||
@async.coroutine
|
||||
def on_raw_cap_ack(self, params):
|
||||
async def on_raw_cap_ack(self, params):
|
||||
""" Update active capabilities: requested capability accepted. """
|
||||
for capab in params[0].split():
|
||||
cp, value = self._capability_normalize(capab)
|
||||
|
@ -139,11 +132,11 @@ class CapabilityNegotiationSupport(rfc1459.RFC1459Support):
|
|||
|
||||
# Indicate we're gonna use this capability if needed.
|
||||
if capab.startswith(ACKNOWLEDGEMENT_REQUIRED_PREFIX):
|
||||
yield from self.rawmsg('CAP', 'ACK', cp)
|
||||
await self.rawmsg('CAP', 'ACK', cp)
|
||||
|
||||
# Run callback.
|
||||
if hasattr(self, attr):
|
||||
status = yield from getattr(self, attr)()
|
||||
status = await getattr(self, attr)()
|
||||
else:
|
||||
status = NEGOTIATED
|
||||
|
||||
|
@ -154,15 +147,14 @@ class CapabilityNegotiationSupport(rfc1459.RFC1459Support):
|
|||
# Ruh-roh, negotiation failed. Disable the capability.
|
||||
self.logger.warning('Capability negotiation for %s failed. Attempting to disable capability again.', cp)
|
||||
|
||||
yield from self.rawmsg('CAP', 'REQ', '-' + cp)
|
||||
await self.rawmsg('CAP', 'REQ', '-' + cp)
|
||||
self._capabilities_requested.add(cp)
|
||||
|
||||
# If we have no capabilities left to process, end it.
|
||||
if not self._capabilities_requested and not self._capabilities_negotiating:
|
||||
yield from self.rawmsg('CAP', 'END')
|
||||
await self.rawmsg('CAP', 'END')
|
||||
|
||||
@async.coroutine
|
||||
def on_raw_cap_nak(self, params):
|
||||
async def on_raw_cap_nak(self, params):
|
||||
""" Update active capabilities: requested capability rejected. """
|
||||
for capab in params[0].split():
|
||||
capab, _ = self._capability_normalize(capab)
|
||||
|
@ -171,39 +163,34 @@ class CapabilityNegotiationSupport(rfc1459.RFC1459Support):
|
|||
|
||||
# If we have no capabilities left to process, end it.
|
||||
if not self._capabilities_requested and not self._capabilities_negotiating:
|
||||
yield from self.rawmsg('CAP', 'END')
|
||||
await self.rawmsg('CAP', 'END')
|
||||
|
||||
@async.coroutine
|
||||
def on_raw_cap_del(self, params):
|
||||
async def on_raw_cap_del(self, params):
|
||||
for capab in params[0].split():
|
||||
attr = 'on_capability_{}_disabled'.format(pydle.protocol.identifierify(capab))
|
||||
if self._capabilities.get(capab, False) and hasattr(self, attr):
|
||||
yield from getattr(self, attr)()
|
||||
yield from self.on_raw_cap_nak(params)
|
||||
await getattr(self, attr)()
|
||||
await self.on_raw_cap_nak(params)
|
||||
|
||||
@async.coroutine
|
||||
def on_raw_cap_new(self, params):
|
||||
yield from self.on_raw_cap_ls(params)
|
||||
async def on_raw_cap_new(self, params):
|
||||
await self.on_raw_cap_ls(params)
|
||||
|
||||
@async.coroutine
|
||||
def on_raw_410(self, message):
|
||||
async def on_raw_410(self, message):
|
||||
""" Unknown CAP subcommand or CAP error. Force-end negotiations. """
|
||||
self.logger.error('Server sent "Unknown CAP subcommand: %s". Aborting capability negotiation.', message.params[0])
|
||||
|
||||
self._capabilities_requested = set()
|
||||
self._capabilities_negotiating = set()
|
||||
yield from self.rawmsg('CAP', 'END')
|
||||
await self.rawmsg('CAP', 'END')
|
||||
|
||||
@async.coroutine
|
||||
def on_raw_421(self, message):
|
||||
async def on_raw_421(self, message):
|
||||
""" Hijack to ignore the absence of a CAP command. """
|
||||
if message.params[0] == 'CAP':
|
||||
return
|
||||
yield from super().on_raw_421(message)
|
||||
await super().on_raw_421(message)
|
||||
|
||||
@async.coroutine
|
||||
def on_raw_451(self, message):
|
||||
async def on_raw_451(self, message):
|
||||
""" Hijack to ignore the absence of a CAP command. """
|
||||
if message.params[0] == 'CAP':
|
||||
return
|
||||
yield from super().on_raw_451(message)
|
||||
await super().on_raw_451(message)
|
||||
|
|
Loading…
Reference in New Issue