def send(self, request=None): """The request is transmitted and the response object is returned.""" if (not request == None): self.setRequest(request) try: response = urlopen(self.getHTTPRequest()) except URLError: raise artbeater.webapi.ServerError, 'There is no response from the server. Please execute it after a while again.' except HTTPError: raise artbeater.webapi.ServerError, 'There is no response from the server. Please execute it after a while again.' if response.info().get('Content-Encoding') == 'gzip': file = StringIO(response.read()) content = gzip.GzipFile(fileobj=file) else: content = response parser = ResponseParser(self._multi_element) try: result = parser.parse(content) except ExpatError: raise artbeater.webapi.InvalidResponse, 'Xml not an invalid response was received.' return Response({ 'code': response.code, 'message': response.msg, 'request': request, 'headers': response.info(), 'result': result })
def execute(self, values={}): parser = ResponseParser() res = parser.parse('response.xml') return Response({ 'result': res })