def action_peek_json(body): """Determine action to invoke.""" try: decoded = jsonutils.loads(body) except ValueError: msg = _("cannot understand JSON") raise exception.MalformedRequestBody(reason=msg) # Make sure there's exactly one key... if len(decoded) != 1: msg = _("too many body keys") raise exception.MalformedRequestBody(reason=msg) # Return the action and the decoded body... return decoded.keys()[0]
def default(self, string): """Deserialize an xml-formatted cell create request.""" try: node = minidom.parseString(string) except expat.ExpatError: msg = _("cannot understand XML") raise exception.MalformedRequestBody(reason=msg) return {'body': {'cell': self._extract_cell(node)}}
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)
def safe_minidom_parse_string(xml_string): """Parse an XML string using minidom safely.""" try: return minidom.parseString(xml_string, parser=ProtectedExpatParser()) except (sax.SAXParseException, ValueError, expat.ExpatError, LookupError) as e: #NOTE(Vijaya Erukala): XML input such as # <?xml version="1.0" encoding="TF-8"?> # raises LookupError: unknown encoding: TF-8 raise exception.MalformedRequestBody(reason=str(e))
def action_peek(body): """Determine action to invoke. This looks inside the json body and fetches out the action method name. """ try: decoded = jsonutils.loads(body) except ValueError: msg = _("cannot understand JSON") raise exception.MalformedRequestBody(reason=msg) # Make sure there's exactly one key... if len(decoded) != 1: msg = _("too many body keys") raise exception.MalformedRequestBody(reason=msg) # Return the action name return list(decoded.keys())[0]
def default(self, string): try: node = minidom.parseString(string) except expat.ExpatError: msg = _("cannot understand XML") raise exception.MalformedRequestBody(reason=msg) updates = {} for child in node.childNodes[0].childNodes: updates[child.tagName] = self.extract_text(child) return dict(body=updates)
def default(self, string): try: node = minidom.parseString(string) except expat.ExpatError: msg = _("cannot understand XML") raise exception.MalformedRequestBody(reason=msg) updates = {} updates_node = self.find_first_child_named(node, 'updates') if updates_node is not None: maintenance = self.find_first_child_named(updates_node, 'maintenance_mode') if maintenance is not None: updates[maintenance.tagName] = self.extract_text(maintenance) status = self.find_first_child_named(updates_node, 'status') if status is not None: updates[status.tagName] = self.extract_text(status) return dict(body=updates)
def _from_json(self, datastring): try: return jsonutils.loads(datastring) except ValueError: msg = _("cannot understand JSON") raise exception.MalformedRequestBody(reason=msg)