Mercurial > libervia-backend
comparison src/plugins/plugin_exp_pubsub_schema.py @ 2395:713cedc99752
plugin pubsub schema: allow any data_form schema:
the schema is actually the schema needed for the items, so it should not in pubsub schema namespace.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 Oct 2017 17:54:00 +0200 |
parents | 4c883d1c3e81 |
children | 3ff9d7a7fe71 |
comparison
equal
deleted
inserted
replaced
2394:7bfcc431f66d | 2395:713cedc99752 |
---|---|
32 from zope.interface import implements | 32 from zope.interface import implements |
33 from collections import Iterable | 33 from collections import Iterable |
34 import copy | 34 import copy |
35 | 35 |
36 NS_SCHEMA = 'https://salut-a-toi/protocol/schema:0' | 36 NS_SCHEMA = 'https://salut-a-toi/protocol/schema:0' |
37 NS_SCHEMA_FORM = 'https://salut-a-toi/protocol/schema#schema:0' | |
38 | 37 |
39 PLUGIN_INFO = { | 38 PLUGIN_INFO = { |
40 C.PI_NAME: "PubSub Schema", | 39 C.PI_NAME: "PubSub Schema", |
41 C.PI_IMPORT_NAME: "PUBSUB_SCHEMA", | 40 C.PI_IMPORT_NAME: "PUBSUB_SCHEMA", |
42 C.PI_TYPE: "EXP", | 41 C.PI_TYPE: "EXP", |
96 def _getSchemaCb(self, iq_elt): | 95 def _getSchemaCb(self, iq_elt): |
97 try: | 96 try: |
98 schema_elt = next(iq_elt.elements(NS_SCHEMA, 'schema')) | 97 schema_elt = next(iq_elt.elements(NS_SCHEMA, 'schema')) |
99 except StopIteration: | 98 except StopIteration: |
100 raise exceptions.DataError('missing <schema> element') | 99 raise exceptions.DataError('missing <schema> element') |
101 schema_form = data_form.findForm(schema_elt, NS_SCHEMA_FORM) | 100 try: |
102 if schema_form is None: | 101 x_elt = next(schema_elt.elements((data_form.NS_X_DATA, 'x'))) |
102 except StopIteration: | |
103 # there is not schema on this node | 103 # there is not schema on this node |
104 return None | 104 return None |
105 # we get again the form because we need all elements/namespaces | |
106 # while schema_form.toElement while only keep XEP-0004 elements | |
107 x_elt = next(schema_elt.elements(data_form.NS_X_DATA, 'x')) | |
108 return x_elt | 105 return x_elt |
109 | 106 |
110 def getSchema(self, client, service, nodeIdentifier): | 107 def getSchema(self, client, service, nodeIdentifier): |
111 """retrieve PubSub node schema | 108 """retrieve PubSub node schema |
112 | 109 |