comparison sat/plugins/plugin_xep_0346.py @ 3509:b977c74f9c85

plugin XEP-0346: bridge method to retrieve template, submitted, or application namespaces
author Goffi <goffi@goffi.org>
date Thu, 22 Apr 2021 18:20:41 +0200
parents be6d91572633
children edc79cefe968 422049bb81d3
comparison
equal deleted inserted replaced
3508:9d9fb871a75c 3509:b977c74f9c85
93 out_sign="s", 93 out_sign="s",
94 method=self._getSchemaDict, 94 method=self._getSchemaDict,
95 async_=True, 95 async_=True,
96 ) 96 )
97 host.bridge.addMethod( 97 host.bridge.addMethod(
98 "psSchemaApplicationNSGet",
99 ".plugin",
100 in_sign="s",
101 out_sign="s",
102 method=self.getApplicationNS,
103 )
104 host.bridge.addMethod(
105 "psSchemaTemplateNodeGet",
106 ".plugin",
107 in_sign="s",
108 out_sign="s",
109 method=self.getTemplateNS,
110 )
111 host.bridge.addMethod(
112 "psSchemaSubmittedNodeGet",
113 ".plugin",
114 in_sign="s",
115 out_sign="s",
116 method=self.getSubmittedNS,
117 )
118 host.bridge.addMethod(
98 "psItemsFormGet", 119 "psItemsFormGet",
99 ".plugin", 120 ".plugin",
100 in_sign="ssssiassa{ss}s", 121 in_sign="ssssiassa{ss}s",
101 out_sign="(asa{ss})", 122 out_sign="(asa{ss})",
102 method=self._getDataFormItems, 123 method=self._getDataFormItems,
119 if namespace.startswith(SUBMITTED_PREFIX): 140 if namespace.startswith(SUBMITTED_PREFIX):
120 namespace = namespace[len(SUBMITTED_PREFIX):] 141 namespace = namespace[len(SUBMITTED_PREFIX):]
121 elif namespace.startswith(TEMPLATE_PREFIX): 142 elif namespace.startswith(TEMPLATE_PREFIX):
122 namespace = namespace[len(TEMPLATE_PREFIX):] 143 namespace = namespace[len(TEMPLATE_PREFIX):]
123 return namespace 144 return namespace
145
146 def getTemplateNS(self, namespace: str) -> str:
147 """Returns node used for data template (i.e. schema)"""
148 app_ns = self.getApplicationNS(namespace)
149 return f"{TEMPLATE_PREFIX}{app_ns}"
124 150
125 def getSubmittedNS(self, namespace: str) -> str: 151 def getSubmittedNS(self, namespace: str) -> str:
126 """Returns node to use to submit forms""" 152 """Returns node to use to submit forms"""
127 return f"{SUBMITTED_PREFIX}{self.getApplicationNS(namespace)}" 153 return f"{SUBMITTED_PREFIX}{self.getApplicationNS(namespace)}"
128 154
242 """Set or replace PubSub node schema 268 """Set or replace PubSub node schema
243 269
244 @param schema(domish.Element, None): schema to set 270 @param schema(domish.Element, None): schema to set
245 None if schema need to be removed 271 None if schema need to be removed
246 """ 272 """
247 app_ns = self.getApplicationNS(nodeIdentifier) 273 node_id = self.getTemplateNS(nodeIdentifier)
248 node_id = f"{TEMPLATE_PREFIX}{app_ns}"
249 node_options = { 274 node_options = {
250 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN, 275 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
251 self._p.OPT_PERSIST_ITEMS: 1, 276 self._p.OPT_PERSIST_ITEMS: 1,
252 self._p.OPT_MAX_ITEMS: 1, 277 self._p.OPT_MAX_ITEMS: 1,
253 self._p.OPT_DELIVER_PAYLOADS: 1, 278 self._p.OPT_DELIVER_PAYLOADS: 1,
478 # only XHTML fields are handled for now 503 # only XHTML fields are handled for now
479 raise NotImplementedError 504 raise NotImplementedError
480 505
481 field.values = values_list 506 field.values = values_list
482 507
483 await self._p.sendItem( 508 return await self._p.sendItem(
484 client, service, nodeIdentifier, form.toElement(), item_id, extra 509 client, service, nodeIdentifier, form.toElement(), item_id, extra
485 ) 510 )
486 511
487 ## filters ## 512 ## filters ##
488 # filters useful for data form to XMLUI conversion # 513 # filters useful for data form to XMLUI conversion #
678 'created' and 'updated' will be forced to current time: 703 'created' and 'updated' will be forced to current time:
679 - 'created' is set if item_id is None, i.e. if it's a new ticket 704 - 'created' is set if item_id is None, i.e. if it's a new ticket
680 - 'updated' is set everytime 705 - 'updated' is set everytime
681 @param extra(dict, None): same as for [XEP-0060.sendItem] with additional keys: 706 @param extra(dict, None): same as for [XEP-0060.sendItem] with additional keys:
682 - update(bool): if True, get previous item data to merge with current one 707 - update(bool): if True, get previous item data to merge with current one
683 if True, item_id must be None 708 if True, item_id must be set
684 @param form_ns (unicode, None): namespace of the form 709 @param form_ns (unicode, None): namespace of the form
685 needed when an update is done 710 needed when an update is done
686 @param default_node(unicode, None): value to use if node is not set 711 @param default_node(unicode, None): value to use if node is not set
687 other arguments are same as for [self._s.sendDataFormItem] 712 other arguments are same as for [self._s.sendDataFormItem]
688 @return (unicode): id of the created item 713 @return (unicode): id of the created item