diff options
Diffstat (limited to 'slixmpp/xmlstream/handler/base.py')
-rw-r--r-- | slixmpp/xmlstream/handler/base.py | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/slixmpp/xmlstream/handler/base.py b/slixmpp/xmlstream/handler/base.py index 1e657777..0bae5674 100644 --- a/slixmpp/xmlstream/handler/base.py +++ b/slixmpp/xmlstream/handler/base.py @@ -4,10 +4,19 @@ # 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, Union +from slixmpp.xmlstream.matcher.base import MatcherBase +from xml.etree.ElementTree import Element + +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 +35,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 +55,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. """ |