예제 #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:
         with excutils.save_and_reraise_exception():
             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)
예제 #2
0
 def _from_json(self, datastring):
     try:
         return jsonutils.loads(
             datastring
         )  #/usr/lib/python2.7/site-packages/neutron/openstack/common/jsonutils.py(171)loads()
     except ValueError:
         msg = _("Cannot understand JSON")
         raise exception.MalformedRequestBody(reason=msg)
예제 #3
0
 def _from_json(self, datastring):
     try:
         return jsonutils.loads(datastring)
     except ValueError:
         msg = _("Cannot understand JSON")
         raise exception.MalformedRequestBody(reason=msg)