Пример #1
0
 def _parse_xml(self, response):
     """INTERNAL: parse an XML response"""
     ctype = response.getheader('Content-Type')
     body = response.body
     if ctype not in ('application/xml', 'text/xml'):
         reason = 'Expecting an XML response (got: %s)' % ctype
         raise ResponseError(reason, detail=body)
     try:
         obj = schema.create_from_xml(body)
     except Exception, e:
         reason = 'Could not parse XML response: %s' % str(e)
         raise ResponseError(reason, detail=body)
Пример #2
0
 def read_object(self):
     """If input was provided via stdin, then parse it and return a binding
     instance."""
     stdin = self.context.terminal.stdin
     # REVISE: this is somewhat of a hack (this detects a '<<' redirect by
     # checking if stdin is a StringIO)
     if not hasattr(stdin, 'len'):
         return
     buf = stdin.read()
     try:
         obj = schema.create_from_xml(buf)
     except rhev.ParseError:
         self.error('could not parse input')
     return obj