comparison libervia/backend/plugins/plugin_xep_0376.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 4b842c1fb686
children 9658c534287e
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
71 client: SatXMPPEntity, 71 client: SatXMPPEntity,
72 service: jid.JID, 72 service: jid.JID,
73 nodeIdentifier: str, 73 nodeIdentifier: str,
74 sub_jid: Optional[jid.JID], 74 sub_jid: Optional[jid.JID],
75 options: Optional[dict], 75 options: Optional[dict],
76 subscribe: bool 76 subscribe: bool,
77 ) -> None: 77 ) -> None:
78 if sub_jid is None: 78 if sub_jid is None:
79 sub_jid = client.jid.userhostJID() 79 sub_jid = client.jid.userhostJID()
80 iq_elt = client.IQ() 80 iq_elt = client.IQ()
81 pam_elt = iq_elt.addElement((NS_PAM, "pam")) 81 pam_elt = iq_elt.addElement((NS_PAM, "pam"))
88 if options: 88 if options:
89 options_elt = pam_elt.addElement((pubsub.NS_PUBSUB, "options")) 89 options_elt = pam_elt.addElement((pubsub.NS_PUBSUB, "options"))
90 options_elt["node"] = nodeIdentifier 90 options_elt["node"] = nodeIdentifier
91 options_elt["jid"] = sub_jid.full() 91 options_elt["jid"] = sub_jid.full()
92 form = data_form.Form( 92 form = data_form.Form(
93 formType='submit', 93 formType="submit", formNamespace=pubsub.NS_PUBSUB_SUBSCRIBE_OPTIONS
94 formNamespace=pubsub.NS_PUBSUB_SUBSCRIBE_OPTIONS
95 ) 94 )
96 form.makeFields(options) 95 form.makeFields(options)
97 options_elt.addChild(form.toElement()) 96 options_elt.addChild(form.toElement())
98 97
99 await iq_elt.send(client.server_jid.full()) 98 await iq_elt.send(client.server_jid.full())
102 self, 101 self,
103 client: SatXMPPEntity, 102 client: SatXMPPEntity,
104 service: jid.JID, 103 service: jid.JID,
105 nodeIdentifier: str, 104 nodeIdentifier: str,
106 sub_jid: Optional[jid.JID] = None, 105 sub_jid: Optional[jid.JID] = None,
107 options: Optional[dict] = None 106 options: Optional[dict] = None,
108 ) -> Tuple[bool, Optional[pubsub.Subscription]]: 107 ) -> Tuple[bool, Optional[pubsub.Subscription]]:
109 if not self.host.hasFeature(client, NS_PAM) or client.is_component: 108 if not self.host.hasFeature(client, NS_PAM) or client.is_component:
110 return True, None 109 return True, None
111 110
112 await self._sub_request(client, service, nodeIdentifier, sub_jid, options, True) 111 await self._sub_request(client, service, nodeIdentifier, sub_jid, options, True)
159 try: 158 try:
160 for attr, key in ( 159 for attr, key in (
161 ("service", "service"), 160 ("service", "service"),
162 ("node", "node"), 161 ("node", "node"),
163 ("jid", "subscriber"), 162 ("jid", "subscriber"),
164 ("subscription", "state") 163 ("subscription", "state"),
165 ): 164 ):
166 sub[key] = subscription_elt[attr] 165 sub[key] = subscription_elt[attr]
167 except KeyError as e: 166 except KeyError as e:
168 log.warning( 167 log.warning(
169 f"Invalid <subscription> element (missing {e.args[0]!r} attribute): " 168 f"Invalid <subscription> element (missing {e.args[0]!r} attribute): "