diff options
author | mathieui <mathieui@mathieui.net> | 2021-07-15 10:01:03 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2021-07-15 10:01:03 +0200 |
commit | 22fa8bc4d91d38a1176b09d03e0d41313b1adcaa (patch) | |
tree | 7344f9e7d72b913e9dfef29fe9b926364e7db587 /slixmpp/xmlstream/handler/base.py | |
parent | b1411d8ed79792c6839f4aace13061256337e69b (diff) | |
parent | 5c54806578260adcb54b12b00a16cc8707a19263 (diff) | |
download | slixmpp-22fa8bc4d91d38a1176b09d03e0d41313b1adcaa.tar.gz slixmpp-22fa8bc4d91d38a1176b09d03e0d41313b1adcaa.tar.bz2 slixmpp-22fa8bc4d91d38a1176b09d03e0d41313b1adcaa.tar.xz slixmpp-22fa8bc4d91d38a1176b09d03e0d41313b1adcaa.zip |
Merge branch 'more-typing' into 'master'
Add more typing
See merge request poezio/slixmpp!166
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. """ |