comparison sat/plugins/plugin_xep_0060.py @ 3815:853cbaf56e9e

plugin XEP-0060: type hints
author Goffi <goffi@goffi.org>
date Wed, 29 Jun 2022 11:36:31 +0200
parents c61233f51b86
children bc24ce903835
comparison
equal deleted inserted replaced
3814:4edfd7521418 3815:853cbaf56e9e
15 15
16 # You should have received a copy of the GNU Affero General Public License 16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 19
20 from typing import Optional, List, Tuple, Dict, Union
21 from collections import namedtuple 20 from collections import namedtuple
22 import urllib.request, urllib.parse, urllib.error
23 from functools import reduce 21 from functools import reduce
24 from zope.interface import implementer 22 from typing import Any, Dict, List, Optional, Tuple, Union
23 import urllib.error
24 import urllib.parse
25 import urllib.request
26
27 from twisted.internet import defer, reactor
28 from twisted.words.protocols.jabber import error, jid
25 from twisted.words.xish import domish 29 from twisted.words.xish import domish
26 from twisted.words.protocols.jabber import jid, error
27 from twisted.internet import reactor, defer
28 from wokkel import disco 30 from wokkel import disco
29 from wokkel import data_form 31 from wokkel import data_form
30 # XXX: sat_tmp.wokkel.pubsub is actually use instead of wokkel version
31 # mam and rsm come from sat_tmp.wokkel too
32 from wokkel import pubsub 32 from wokkel import pubsub
33 from wokkel import rsm 33 from wokkel import rsm
34 from wokkel import mam 34 from wokkel import mam
35 from zope.interface import implementer
36
37 from sat.core import exceptions
38 from sat.core.constants import Const as C
39 from sat.core.core_types import SatXMPPEntity
35 from sat.core.i18n import _ 40 from sat.core.i18n import _
36 from sat.core.constants import Const as C
37 from sat.core.log import getLogger 41 from sat.core.log import getLogger
38 from sat.core.core_types import SatXMPPEntity
39 from sat.core import exceptions
40 from sat.tools import utils 42 from sat.tools import utils
41 from sat.tools import sat_defer 43 from sat.tools import sat_defer
42 from sat.tools import xml_tools 44 from sat.tools import xml_tools
43 from sat.tools.common import data_format 45 from sat.tools.common import data_format
44 46
556 try: 558 try:
557 return published_ids[0] 559 return published_ids[0]
558 except IndexError: 560 except IndexError:
559 return item_id 561 return item_id
560 562
561 async def sendItems(self, client, service, nodeIdentifier, items, extra=None): 563 async def sendItems(
564 self,
565 client: SatXMPPEntity,
566 service: jid.JID,
567 nodeIdentifier: str,
568 items: List[domish.Element],
569 extra: Optional[Dict[str, Any]] = None
570 ) -> List[str]:
562 """High level method to send several items at once 571 """High level method to send several items at once
563 572
564 @param service(jid.JID, None): service to send the item to 573 @param service: service to send the item to
565 None to use PEP 574 None to use PEP
566 @param NodeIdentifier(unicode): PubSub node to use 575 @param NodeIdentifier: PubSub node to use
567 @param items(list[domish.Element]): whole item elements to send, 576 @param items: whole item elements to send,
568 "id" will be used if set 577 "id" will be used if set
569 @param extra(dict, None): extra options. Key can be: 578 @param extra: extra options. Key can be:
570 - self.EXTRA_PUBLISH_OPTIONS(dict): publish options, cf. XEP-0060 § 7.1.5 579 - self.EXTRA_PUBLISH_OPTIONS(dict): publish options, cf. XEP-0060 § 7.1.5
571 the dict maps option name to value(s) 580 the dict maps option name to value(s)
572 - self.EXTRA_ON_PRECOND_NOT_MET(str): policy to have when publishing is 581 - self.EXTRA_ON_PRECOND_NOT_MET(str): policy to have when publishing is
573 failing du to failing precondition. Value can be: 582 failing du to failing precondition. Value can be:
574 * raise (default): raise the exception 583 * raise (default): raise the exception
575 * publish_without_options: re-publish without the publish-options. 584 * publish_without_options: re-publish without the publish-options.
576 A warning will be logged showing that the publish-options could not 585 A warning will be logged showing that the publish-options could not
577 be used 586 be used
578 @return (list[unicode]): ids of the created items 587 @return: ids of the created items
579 """ 588 """
580 if extra is None: 589 if extra is None:
581 extra = {} 590 extra = {}
582 parsed_items = [] 591 parsed_items = []
583 for item in items: 592 for item in items: