diff options
author | mathieui <mathieui@mathieui.net> | 2021-04-21 23:20:25 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2021-07-03 11:17:15 +0200 |
commit | fed55d3dda2c01dca7e9b9ea036c4b7b756510ff (patch) | |
tree | f58baf97df9a1b1e5c8853999477fc7a9634697d /slixmpp/xmlstream/handler/base.py | |
parent | 4931e7e6041ff6c59817d6807b0776a8994d0377 (diff) | |
download | slixmpp-fed55d3dda2c01dca7e9b9ea036c4b7b756510ff.tar.gz slixmpp-fed55d3dda2c01dca7e9b9ea036c4b7b756510ff.tar.bz2 slixmpp-fed55d3dda2c01dca7e9b9ea036c4b7b756510ff.tar.xz slixmpp-fed55d3dda2c01dca7e9b9ea036c4b7b756510ff.zip |
typing: matchers and senders
Leftover error that I cannot fix:
* https://github.com/python/mypy/issues/708
Leftover error that I am unsure of what to do:
* xml handlers are not properly typed
(it seems like nothing in slix is using it, considering a removal
instead of adding an Union everywhere)
Diffstat (limited to 'slixmpp/xmlstream/handler/base.py')
-rw-r--r-- | slixmpp/xmlstream/handler/base.py | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/slixmpp/xmlstream/handler/base.py b/slixmpp/xmlstream/handler/base.py index 1e657777..e1edb249 100644 --- a/slixmpp/xmlstream/handler/base.py +++ b/slixmpp/xmlstream/handler/base.py @@ -4,10 +4,18 @@ # Part of Slixmpp: The Slick XMPP Library # :copyright: (c) 2011 Nathanael C. Fritz # :license: MIT, see LICENSE for more details +from __future__ import annotations + import weakref +from weakref import ReferenceType +from typing import Optional, TYPE_CHECKING +from slixmpp.xmlstream.matcher.base import MatcherBase + +if TYPE_CHECKING: + from slixmpp.xmlstream import XMLStream, StanzaBase -class BaseHandler(object): +class BaseHandler: """ Base class for stream handlers. Stream handlers are matched with @@ -26,8 +34,13 @@ class BaseHandler(object): :param stream: The :class:`~slixmpp.xmlstream.xmlstream.XMLStream` instance that the handle will respond to. """ + name: str + stream: Optional[ReferenceType[XMLStream]] + _destroy: bool + _matcher: MatcherBase + _payload: Optional[StanzaBase] - def __init__(self, name, matcher, stream=None): + def __init__(self, name: str, matcher: MatcherBase, stream: Optional[XMLStream] = None): #: The name of the handler self.name = name @@ -41,33 +54,33 @@ class BaseHandler(object): self._payload = None self._matcher = matcher - def match(self, xml): + def match(self, xml: StanzaBase) -> bool: """Compare a stanza or XML object with the handler's matcher. :param xml: An XML or - :class:`~slixmpp.xmlstream.stanzabase.ElementBase` object + :class:`~slixmpp.xmlstream.stanzabase.StanzaBase` object """ return self._matcher.match(xml) - def prerun(self, payload): + def prerun(self, payload: StanzaBase) -> None: """Prepare the handler for execution while the XML stream is being processed. - :param payload: A :class:`~slixmpp.xmlstream.stanzabase.ElementBase` + :param payload: A :class:`~slixmpp.xmlstream.stanzabase.StanzaBase` object. """ self._payload = payload - def run(self, payload): + def run(self, payload: StanzaBase) -> None: """Execute the handler after XML stream processing and during the main event loop. - :param payload: A :class:`~slixmpp.xmlstream.stanzabase.ElementBase` + :param payload: A :class:`~slixmpp.xmlstream.stanzabase.StanzaBase` object. """ self._payload = payload - def check_delete(self): + def check_delete(self) -> bool: """Check if the handler should be removed from the list of stream handlers. """ |