Mercurial > libervia-backend
comparison tools/xml_tools.py @ 102:94011f553cd0
misc bugfixes
- wix: added forgotten profile in gateways management
- xml_tools: removed XMLClass to the 2 methods as a direct methods
- plugin_xep_100 (gateways discovery): added error callback
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 22 Jun 2010 13:58:53 +0800 |
parents | be206a3d1a9b |
children | 6be927a465ed |
comparison
equal
deleted
inserted
replaced
101:783e9d6980ec | 102:94011f553cd0 |
---|---|
22 from logging import debug, info, error | 22 from logging import debug, info, error |
23 from xml.dom import minidom | 23 from xml.dom import minidom |
24 from wokkel import data_form | 24 from wokkel import data_form |
25 import pdb | 25 import pdb |
26 | 26 |
27 class XMLTools: | 27 """This library help manage XML used in SàT (parameters, registration, etc) """ |
28 """This class help manage XML used in SàT (parameters, registration, etc) """ | |
29 | 28 |
30 | 29 |
31 @staticmethod | 30 def dataForm2xml(form): |
32 def dataForm2xml(form): | 31 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml""" |
33 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml""" | 32 |
33 impl = minidom.getDOMImplementation() | |
34 | |
35 doc = impl.createDocument(None, "form", None) | |
36 top_element = doc.documentElement | |
37 | |
38 #result_xml = ["<form>", "</form>"] | |
39 if form.instructions: | |
40 elem = doc.createElement('elem') | |
41 elem.setAttribute('name','instructions') | |
42 elem.setAttribute('type','text') | |
43 text = doc.createTextNode('\n'.join(form.instructions)) | |
44 elem.appendChild(text) | |
45 top_element.appendChild(elem) | |
46 for field in form.fieldList: | |
47 if field.fieldType == 'fixed': | |
48 __field_type = 'text' | |
49 elif field.fieldType == 'text-single': | |
50 __field_type = "string" | |
51 elif field.fieldType == 'text-private': | |
52 __field_type = "password" | |
53 elif field.fieldType == 'list-single': | |
54 __field_type = "list" | |
55 else: | |
56 error (u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType) | |
57 __field_type = "string" | |
34 | 58 |
35 impl = minidom.getDOMImplementation() | 59 elem = doc.createElement('elem') |
60 if field.var: | |
61 elem.setAttribute('name', field.var) | |
62 elem.setAttribute('type', __field_type) | |
63 elem.setAttribute('label', field.label or "") | |
64 if field.value: | |
65 elem.setAttribute('value', field.value) | |
66 top_element.appendChild(elem) | |
67 for option in field.options: | |
68 opt = doc.createElement('option') | |
69 opt.setAttribute('value', option.value) | |
70 elem.appendChild(opt) | |
71 result = doc.toxml() | |
72 doc.unlink() | |
73 return result | |
36 | 74 |
37 doc = impl.createDocument(None, "form", None) | 75 def tupleList2dataForm(values): |
38 top_element = doc.documentElement | 76 """convert a list of tuples (name,value) to a wokkel submit data form""" |
39 | 77 form = data_form.Form('submit') |
40 #result_xml = ["<form>", "</form>"] | 78 for value in values: |
41 if form.instructions: | 79 field = data_form.Field(var=value[0], value=value[1]) |
42 elem = doc.createElement('elem') | 80 form.addField(field) |
43 elem.setAttribute('name','instructions') | |
44 elem.setAttribute('type','text') | |
45 text = doc.createTextNode('\n'.join(form.instructions)) | |
46 elem.appendChild(text) | |
47 top_element.appendChild(elem) | |
48 for field in form.fieldList: | |
49 if field.fieldType == 'fixed': | |
50 __field_type = 'text' | |
51 elif field.fieldType == 'text-single': | |
52 __field_type = "string" | |
53 elif field.fieldType == 'text-private': | |
54 __field_type = "password" | |
55 elif field.fieldType == 'list-single': | |
56 __field_type = "list" | |
57 else: | |
58 error (u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType) | |
59 __field_type = "string" | |
60 | |
61 elem = doc.createElement('elem') | |
62 if field.var: | |
63 elem.setAttribute('name', field.var) | |
64 elem.setAttribute('type', __field_type) | |
65 elem.setAttribute('label', field.label or "") | |
66 if field.value: | |
67 elem.setAttribute('value', field.value) | |
68 top_element.appendChild(elem) | |
69 for option in field.options: | |
70 opt = doc.createElement('option') | |
71 opt.setAttribute('value', option.value) | |
72 elem.appendChild(opt) | |
73 result = doc.toxml() | |
74 doc.unlink() | |
75 return result | |
76 | 81 |
77 @staticmethod | 82 return form |
78 def tupleList2dataForm(values): | |
79 """convert a list of tuples (name,value) to a wokkel submit data form""" | |
80 form = data_form.Form('submit') | |
81 for value in values: | |
82 field = data_form.Field(var=value[0], value=value[1]) | |
83 form.addField(field) | |
84 | |
85 return form | |
86 | 83 |
87 | 84 |
88 | 85 |