Add option to disable condensing and converting form values.

XEP-0115 needs to use the raw XML character data.
This commit is contained in:
Lance Stout 2011-12-30 21:43:39 -05:00
parent 8eb225bdec
commit 6722b0224a

View file

@ -79,19 +79,21 @@ class FormField(ElementBase):
reqXML = self.xml.find('{%s}required' % self.namespace) reqXML = self.xml.find('{%s}required' % self.namespace)
return reqXML is not None return reqXML is not None
def get_value(self): def get_value(self, convert=True):
valsXML = self.xml.findall('{%s}value' % self.namespace) valsXML = self.xml.findall('{%s}value' % self.namespace)
if len(valsXML) == 0: if len(valsXML) == 0:
return None return None
elif self._type == 'boolean': elif self._type == 'boolean':
return valsXML[0].text in self.true_values if convert:
return valsXML[0].text in self.true_values
return valsXML[0].text
elif self._type in self.multi_value_types or len(valsXML) > 1: elif self._type in self.multi_value_types or len(valsXML) > 1:
values = [] values = []
for valXML in valsXML: for valXML in valsXML:
if valXML.text is None: if valXML.text is None:
valXML.text = '' valXML.text = ''
values.append(valXML.text) values.append(valXML.text)
if self._type == 'text-multi': if self._type == 'text-multi' and condense:
values = "\n".join(values) values = "\n".join(values)
return values return values
else: else: