Beispiel #1
0
 def _from_xml(self, datastring):
     if datastring is None:
         return None
     plurals = set(self.metadata.get('plurals', {}))
     try:
         node = self._parseXML(datastring)
         root_tag = self._get_key(node.tag)
         # Deserialize link node was needed by unit test for verifying
         # the request's response
         links = self._get_links(root_tag, node)
         result = self._from_xml_node(node, plurals)
         # root_tag = constants.VIRTUAL_ROOT_KEY and links is not None
         # is not possible because of the way data are serialized.
         if root_tag == constants.VIRTUAL_ROOT_KEY:
             return result
         return dict({root_tag: result}, **links)
     except Exception as e:
         parseError = False
         # Python2.7
         if (hasattr(etree, 'ParseError')
                 and isinstance(e, getattr(etree, 'ParseError'))):
             parseError = True
         # Python2.6
         elif isinstance(e, expat.ExpatError):
             parseError = True
         if parseError:
             msg = _("Cannot understand XML")
             raise exception.MalformedRequestBody(reason=msg)
         else:
             raise
Beispiel #2
0
 def _from_xml(self, datastring):
     plurals = set(self.metadata.get('plurals', {}))
     try:
         node = minidom.parseString(datastring).childNodes[0]
         return {node.nodeName: self._from_xml_node(node, plurals)}
     except expat.ExpatError:
         msg = _("cannot understand XML")
         raise exception.MalformedRequestBody(reason=msg)
Beispiel #3
0
 def _from_json(self, datastring):
     try:
         return jsonutils.loads(datastring)
     except ValueError:
         msg = _("cannot understand JSON")
         raise exception.MalformedRequestBody(reason=msg)