comparison tools/xml_tools.py @ 33:b9bb5d8e0cc7

In-band-registration: data form 2 xml conversion
author Goffi <goffi@goffi.org>
date Tue, 08 Dec 2009 09:54:44 +0100
parents
children c45deebb40a5
comparison
equal deleted inserted replaced
32:c4badbf3dd97 33:b9bb5d8e0cc7
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 """
5 SAT: a jabber client
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """
21
22 from logging import debug, info, error
23 from xml.dom import minidom
24 import pdb
25
26 class XMLTools:
27 """This class help manage XML used in SàT (parameters, registration, etc) """
28
29
30 @staticmethod
31 def dataForm2xml(form):
32 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml"""
33 result_xml = ["<form>", "</form>"]
34 if form.instructions:
35 result_xml.insert(1,"<elem name='instructions' value='%s' type='text' />" % '\n'.join(form.instructions))
36 for field in form.fieldList:
37 if field.fieldType == 'text-single':
38 __field_type = "string"
39 elif field.fieldType == 'text-private':
40 __field_type = "password"
41 else:
42 error (u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType)
43 __field_type = "string_field"
44
45 result_xml.insert(-1,"<elem name='%s' type='%s' label='%s'>" % (field.var, __field_type, field.label))
46
47 return '\n'.join(result_xml)
48
49
50
51
52 pdb.set_trace()