def send(self, request): """Send the request.""" response = self._session.post(request.url, data=request.message, headers=request.headers, stream=True) return Reply(response.status_code, response.headers, response.content)
def send(self, request): """ Returns a fake Reply builded with data from a xml file. The xml file must be defined with the method "define" before the soap request is send. """ dom = parseString(request.message) body = dom.documentElement.getElementsByTagNameNS('*', 'Body')[0] method = body.firstChild.localName if method.startswith('get'): filename = '%s_get.xml' % self._output_file elif method.startswith('list'): filename = '%s_list.xml' % self._output_file elif method.startswith('update'): filename = '%s_update.xml' % self._output_file elif method.startswith('remove'): filename = '%s_remove.xml' % self._output_file elif method.startswith('add'): filename = '%s_add.xml' % self._output_file else: filename = '%s.xml' % self._output_file with open(os.path.join(os.path.dirname(__file__), 'soap', filename), 'rb') as f: message = f.read() self._lastrequest = request return Reply(200, request.headers, message)
def send(self, request): headers, message = self.http.request(request.url, "POST", body=request.message, headers=request.headers) response = Reply(200, headers, message) return response
def send(self, request): """ POST to the service using requests. """ self.addcredentials(request) resp = requests.post(request.url, data=request.message, headers=request.headers) result = Reply(resp.status_code, resp.headers, resp.content) return result
def send(self, request): self.addcredentials(request) resp = requests.post(request.url, data=request.message, headers=request.headers, verify=self.cert) result = Reply(resp.status_code, resp.headers, resp.content) return result
def send(self, request): try: resp = self._session.post(request.url, data=request.message, headers=request.headers, slug=self.slug, related_objects=self.related_objects, timeout=self.timeout) if resp.headers.get('content-type') not in {'text/xml', 'application/soap+xml'}: resp.raise_for_status() return Reply(resp.status_code, resp.headers, resp.content) finally: self.related_objects = ()
def test_reply_constructor(code, headers, message): reply = Reply(code, headers, message) assert reply.code == code assert reply.headers == headers assert reply.message == message
def send(self, request): """Send the request.""" response = requests.post(request.url, data=request.message, headers=request.headers, cert=self.cert, verify=self.verify, stream=True) return Reply(response.status_code, response.headers, response.content)
def send(self, request): try: result = self._service.call(request, request.message) except Exception as e: result = soap.Fault.instance(faultcode='Server', faultstring=e.message, detail=traceback.format_exc()) return Reply('200 OK', {}, soap.response_tostring(result))
def _reply(content): return Reply(httplib.OK, {}, b''' <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Header></soap:Header> <soap:Body> ''' + content + b''' </soap:Body> </soap:Envelope> ''')
def test_reply_as_string(message): code = 17 reply = Reply(code, {"aaa": 1}, message) expected = u"""\ CODE: %s HEADERS: %s MESSAGE: %s""" % (code, reply.headers, message) assert unicode(reply) == expected if sys.version_info < (3, 0): assert str(reply) == expected.encode("utf-8")
def test_string_representation(self, message): code = 17 reply = Reply(code, {"aaa": 1}, message) expected = u("""\ CODE: %s HEADERS: %s MESSAGE: %s""") % (code, reply.headers, message.decode("raw_unicode_escape")) assert text_type(reply) == expected if sys.version_info < (3, ): assert str(reply) == expected.encode("utf-8")
def send(self, request): resp = requests.post( request.url, data=request.message, headers=request.headers, verify=self.verify, auth=self.auth, ) resp.raise_for_status() result = Reply(resp.status_code, resp.headers, resp.content) return result
def send(self, request): response = post(settings.BANGO_PROXY, data=request.message, headers={HEADERS_SERVICE: request.url}, verify=False) if response.status_code in FATAL_PROXY_STATUS_CODES: msg = ('Proxy returned: %s from: %s' % (response.status_code, request.url)) log.error(msg) raise ProxyError(msg) return Reply(response.status_code, {}, response.content)
def send(self, request): url = request.url msg = request.message headers = request.headers self.proxy = self.options.proxy log.debug('sending:\n%s', request) resp = self.doOpen(url, data=msg, headers=headers, cookies=self.cookiejar) if resp.status_code not in (200,): raise TransportError("Error: %s"%resp.reason, resp.status_code, DummyFile(resp.content)) result = Reply(resp.status_code, resp.headers, resp.content) log.debug('received:\n%s', result) #except u2.HTTPError, e: # if e.code in (202,204): # result = None # else: # raise TransportError(e.msg, e.code, e.fp) return result
def send(self, request): """ Send soap message. Implementations are expected to handle: - proxies - I{http} headers - cookies - sending message - brokering exceptions into L{TransportError} @param request: A transport request. @type request: L{Request} @return: The reply @rtype: L{Reply} @raise TransportError: On all transport errors. """ consumer = yield self._request(request, "POST") res_headers = dict(consumer.response.headers.getAllRawHeaders()) result = Reply(consumer.response.code, res_headers, consumer.body) defer.returnValue(result)
def send(self, request): result = None url = request.url msg = request.message headers = request.headers try: u2request = u2.Request(url, msg, headers) self.addcookies(u2request) self.proxy = self.options.proxy request.headers.update(u2request.headers) log.debug('sending:\n%s', request) fp = self.u2open(u2request) self.getcookies(fp, u2request) result = Reply(200, fp.headers, fp.read()) log.debug('received:\n%s', result) except HTTPError as e: if e.code in (202, 204): result = None else: raise TransportError(e.msg, e.code, e.fp) return result
def send(self, request): response = self._call(request, 'post') return Reply(response.status_code, response.headers, response.content)
def test_construction(self, code, headers, message): reply = Reply(code, headers, message) assert reply.code is code assert reply.headers is headers assert reply.message is message