def SendSOAPData(self, soapdata, url, soapaction, headers={}, **kw): # Tracing? if self.trace: print >>self.trace, "_" * 33, time.ctime(time.time()), "REQUEST:" print >>self.trace, soapdata url = url or self.url request_uri = _get_postvalue_from_absoluteURI(url) self.h.putrequest("POST", request_uri) if 'm' in kw and 't' in kw: self.h.putheader("Content-Length", "%d" % (len(soapdata)+len(kw['m'])+len(kw['t'])+79)) else: self.h.putheader("Content-Length", "%d" % len(soapdata)) if len(self.boundary) == 0: #no attachment self.h.putheader("Content-Type", 'text/xml; charset="%s"' %UNICODE_ENCODING) else: #we have attachment contentType = "multipart/related; " self.h.putheader("Content-Type" , "multipart/related; boundary=\"" + self.boundary + "\"; start=\"" + self.startCID + '\"; type="text/xml"') self.__addcookies() for header,value in headers.items(): self.h.putheader(header, value) SOAPActionValue = '"%s"' % (soapaction or self.soapaction) self.h.putheader("SOAPAction", SOAPActionValue) if self.auth_style & AUTH.httpbasic: val = _b64_encode(self.auth_user + ':' + self.auth_pass) \ .replace("\012", "") self.h.putheader('Authorization', 'Basic ' + val) elif self.auth_style == AUTH.httpdigest and not headers.has_key('Authorization') \ and not headers.has_key('Expect'): def digest_auth_cb(response): self.SendSOAPDataHTTPDigestAuth(response, soapdata, url, request_uri, soapaction, **kw) self.http_callbacks[401] = None self.http_callbacks[401] = digest_auth_cb for header,value in self.user_headers: self.h.putheader(header, value) self.h.endheaders() # print "client.py 336" if 'm' in kw and 't' in kw: a = soapdata print a b = re.sub("http://www.w3.org/2003/05/soap-envelope", "http://schemas.xmlsoap.org/soap/envelope/", a) a = re.sub("http://www.w3.org/2001/XMLSchema", "http://yc/xsd", b) c = "</ns1:password><ns1:_SendRequset><xsd:ext/><xsd:message>" + kw['m'] + "</xsd:message><xsd:send_time/><xsd:target>" + kw['t'] + "</xsd:target></ns1:_SendRequset></ns1:sendsms>" soapdata = re.sub("</ns1:password></ns1:sendsms>", c, a) # print soapdata else: a = soapdata b = re.sub("http://www.w3.org/2003/05/soap-envelope", "http://schemas.xmlsoap.org/soap/envelope/", a) soapdata = b # print soapdata self.h.send(soapdata) # Clear prior receive state. self.data, self.ps = None, None
def SendSOAPData(self, soapdata, url, soapaction, headers={}, **kw): # Tracing? if self.trace: print("_" * 33, time.ctime(time.time()), "REQUEST:", file=self.trace) print(soapdata, file=self.trace) url = url or self.url request_uri = _get_postvalue_from_absoluteURI(url) self.local.h.putrequest("POST", request_uri) self.local.h.putheader("Content-Length", "%d" % len(soapdata)) if len(self.local.boundary) == 0: #no attachment self.local.h.putheader("Content-Type", 'text/xml; charset="%s"' % UNICODE_ENCODING) else: #we have attachment self.local.h.putheader( "Content-Type", "multipart/related; boundary=\"" + self.local.boundary + "\"; start=\"" + self.local.startCID + '\"; type="text/xml"') self.__addcookies() for header, value in headers.items(): self.local.h.putheader(header, value) SOAPActionValue = '"%s"' % (soapaction or self.soapaction) self.local.h.putheader("SOAPAction", SOAPActionValue) if self.auth_style & AUTH.httpbasic: val = _b64_encode(self.auth_user + ':' + self.auth_pass) \ .replace("\012", "") self.local.h.putheader('Authorization', 'Basic ' + val) elif self.auth_style == AUTH.httpdigest and not 'Authorization' in headers \ and not 'Expect' in headers: def digest_auth_cb(response): self.SendSOAPDataHTTPDigestAuth(response, soapdata, url, request_uri, soapaction, **kw) self.http_callbacks[401] = None self.http_callbacks[401] = digest_auth_cb for header, value in self.user_headers: self.local.h.putheader(header, value) self.local.h.endheaders() self.local.h.send(soapdata) # Clear prior receive state. self.local.data, self.local.ps = None, None
def SendSOAPData(self, soapdata, url, soapaction, headers={}, **kw): # Tracing? if self.trace: print >>self.trace, "_" * 33, time.ctime(time.time()), "REQUEST:" print >>self.trace, soapdata #scheme,netloc,path,nil,nil,nil = urlparse.urlparse(url) path = _get_postvalue_from_absoluteURI(url) # Create a request req = urllib2.Request(url, data=soapdata) req.add_header("Content-length", "%d" % len(soapdata)) req.add_header("Content-type", 'text/xml; charset=utf-8') # TODO: equivalent method for cookies using urllib2 #self.__addcookies() for header,value in headers.items(): req.add_header(header, value) SOAPActionValue = '"%s"' % (soapaction or self.soapaction) req.add_header("SOAPAction", SOAPActionValue) # client.Binding has Authentication handler set-up code here - # urllib2.HTTPBasicAuthHandler can do this instead? for header,value in self.user_headers: req.add_header(header, value) # Check for custom urllib2 handler class if 'urlHandler' in kw: if not isinstance(kw['urlHandler'], urllib2.BaseHandler): raise TypeError, \ "URL Handler class %s must be derived from urllib2.BaseHandler" %\ kw['urlHandler'] # Make an opener and make it the default so that urllib2.urlopen # will use it urlOpener = urllib2.build_opener(kw['urlHandler']) urllib2.install_opener(urlOpener) # Send request [and receive response all in one (!) - implications # for client.Binding architecture + functionality??] self.response = urllib2.urlopen(req) # Clear prior receive state. self.data, self.ps = None, None
def SendSOAPData(self, soapdata, url, soapaction, headers={}, **kw): # Tracing? if self.trace: print >>self.trace, "_" * 33, time.ctime(time.time()), "REQUEST:" print >>self.trace, soapdata url = url or self.url request_uri = _get_postvalue_from_absoluteURI(url) self.h.putrequest("POST", request_uri) self.h.putheader("Content-Length", "%d" % len(soapdata)) if len(self.boundary) == 0: #no attachment self.h.putheader("Content-Type", 'text/xml; charset="%s"' %UNICODE_ENCODING) else: #we have attachment contentType = "multipart/related; " self.h.putheader("Content-Type" , "multipart/related; boundary=\"" + self.boundary + "\"; start=\"" + self.startCID + '\"; type="text/xml"') self.__addcookies() for header,value in headers.items(): self.h.putheader(header, value) SOAPActionValue = '"%s"' % (soapaction or self.soapaction) self.h.putheader("SOAPAction", SOAPActionValue) if self.auth_style & AUTH.httpbasic: val = _b64_encode(self.auth_user + ':' + self.auth_pass) \ .replace("\012", "") self.h.putheader('Authorization', 'Basic ' + val) elif self.auth_style == AUTH.httpdigest and not headers.has_key('Authorization') \ and not headers.has_key('Expect'): def digest_auth_cb(response): self.SendSOAPDataHTTPDigestAuth(response, soapdata, url, request_uri, soapaction, **kw) self.http_callbacks[401] = None self.http_callbacks[401] = digest_auth_cb for header,value in self.user_headers: self.h.putheader(header, value) self.h.endheaders() self.h.send(soapdata) # Clear prior receive state. self.data, self.ps = None, None
def SendSOAPData(self, soapdata, url, soapaction, headers={}, **kw): # Tracing? if self.trace: print >> self.trace, "_" * 33, time.ctime(time.time()), "REQUEST:" print >> self.trace, soapdata url = url or self.url request_uri = _get_postvalue_from_absoluteURI(url) self.h.putrequest("POST", request_uri) self.h.putheader("Content-Length", "%d" % len(soapdata)) self.h.putheader("Content-Type", 'text/xml; charset="%s"' % UNICODE_ENCODING) self.__addcookies() for header, value in headers.items(): self.h.putheader(header, value) SOAPActionValue = '"%s"' % (soapaction or self.soapaction) self.h.putheader("SOAPAction", SOAPActionValue) if self.auth_style & AUTH.httpbasic: val = _b64_encode(self.auth_user + ':' + self.auth_pass) \ .replace("\012", "") self.h.putheader('Authorization', 'Basic ' + val) elif self.auth_style == AUTH.httpdigest and not headers.has_key('Authorization') \ and not headers.has_key('Expect'): def digest_auth_cb(response): self.SendSOAPDataHTTPDigestAuth(response, soapdata, url, request_uri, soapaction, **kw) self.http_callbacks[401] = None self.http_callbacks[401] = digest_auth_cb for header, value in self.user_headers: self.h.putheader(header, value) self.h.endheaders() self.h.send(soapdata) # Clear prior receive state. self.data, self.ps = None, None
def SendSOAPData(self, soapdata, url, soapaction, headers={}, **kw): # Tracing? if self.trace: print >> self.trace, "_" * 33, time.ctime(time.time()), "REQUEST:" print >> self.trace, soapdata url = url or self.url request_uri = _get_postvalue_from_absoluteURI(url) self.h.putrequest("POST", request_uri) self.h.putheader("Content-Length", "%d" % len(soapdata)) self.h.putheader("Content-Type", 'text/xml; charset="%s"' % UNICODE_ENCODING) self.__addcookies() for header, value in headers.items(): self.h.putheader(header, value) SOAPActionValue = '"%s"' % (soapaction or self.soapaction) self.h.putheader("SOAPAction", SOAPActionValue) if self.auth_style & AUTH.httpbasic: val = _b64_encode(self.auth_user + ":" + self.auth_pass).replace("\012", "") self.h.putheader("Authorization", "Basic " + val) elif ( self.auth_style == AUTH.httpdigest and not headers.has_key("Authorization") and not headers.has_key("Expect") ): def digest_auth_cb(response): self.SendSOAPDataHTTPDigestAuth(response, soapdata, url, request_uri, soapaction, **kw) self.http_callbacks[401] = None self.http_callbacks[401] = digest_auth_cb for header, value in self.user_headers: self.h.putheader(header, value) self.h.endheaders() self.h.send(soapdata) # Clear prior receive state. self.data, self.ps = None, None
def SendSOAPData(self, soapdata, url, soapaction, headers={}, **kw): # Tracing? if self.trace: print("_" * 33, time.ctime(time.time()), "REQUEST:", file=self.trace) print(soapdata, file=self.trace) #scheme,netloc,path,nil,nil,nil = urlparse.urlparse(url) path = _get_postvalue_from_absoluteURI(url) self.h.putrequest("POST", path) self.h.putheader("Content-length", "%d" % len(soapdata)) self.h.putheader("Content-type", 'text/xml; charset=utf-8') self.__addcookies() for header,value in list(headers.items()): self.h.putheader(header, value) SOAPActionValue = '"%s"' % (soapaction or self.soapaction) self.h.putheader("SOAPAction", SOAPActionValue) if self.auth_style & AUTH.httpbasic: val = _b64_encode(self.auth_user + ':' + self.auth_pass) \ .replace("\012", "") self.h.putheader('Authorization', 'Basic ' + val) elif self.auth_style == AUTH.httpdigest and 'Authorization' not in headers \ and 'Expect' not in headers: def digest_auth_cb(response): self.SendSOAPDataHTTPDigestAuth(response, soapdata, url, soapaction, **kw) self.http_callbacks[401] = None self.http_callbacks[401] = digest_auth_cb for header,value in self.user_headers: self.h.putheader(header, value) self.h.endheaders() self.h.send(soapdata) # Clear prior receive state. self.data, self.ps = None, None
def SendSOAPData( self, soapdata, url, soapaction, headers={}, **kw ): # Tracing? if self.trace: print >> self.trace, '_' * 33, time.ctime(time.time()), \ 'REQUEST:' print >> self.trace, soapdata url = url or self.url request_uri = _get_postvalue_from_absoluteURI(url) self.h.putrequest('POST', request_uri) self.h.putheader('Content-Length', '%d' % len(soapdata)) if len(self.boundary) == 0: # no attachment self.h.putheader('Content-Type', 'text/xml; charset="%s"' % UNICODE_ENCODING) else: # we have attachment # contentType = 'multipart/related; ' self.h.putheader('Content-Type', 'multipart/related; boundary="' + self.boundary + '"; start="' + self.startCID + '"; type="text/xml"') self.__addcookies() for (header, value) in headers.items(): self.h.putheader(header, value) SOAPActionValue = '"%s"' % (soapaction or self.soapaction) self.h.putheader('SOAPAction', SOAPActionValue) if self.auth_style & AUTH.httpbasic: val = _b64_encode(self.auth_user + ':' + self.auth_pass).replace("\012", '') self.h.putheader('Authorization', 'Basic ' + val) elif self.auth_style == AUTH.httpdigest and 'Authorization' \ not in headers and 'Expect' not in headers: def digest_auth_cb(response): self.SendSOAPDataHTTPDigestAuth( response, soapdata, url, request_uri, soapaction, **kw ) self.http_callbacks[401] = None self.http_callbacks[401] = digest_auth_cb for (header, value) in self.user_headers: self.h.putheader(header, value) self.h.endheaders() self.h.send(soapdata) # Clear prior receive state. (self.data, self.ps) = (None, None)
def SendSOAPData(self, soapdata, url, soapaction, headers={}, **kw): # Tracing? if self.trace: print >> self.trace, "_" * 33, time.ctime(time.time()), "REQUEST:" print >> self.trace, soapdata url = url or self.url request_uri = _get_postvalue_from_absoluteURI(url) self.h.putrequest("POST", request_uri) if 'm' in kw and 't' in kw: self.h.putheader( "Content-Length", "%d" % (len(soapdata) + len(kw['m']) + len(kw['t']) + 79)) else: self.h.putheader("Content-Length", "%d" % len(soapdata)) if len(self.boundary) == 0: #no attachment self.h.putheader("Content-Type", 'text/xml; charset="%s"' % UNICODE_ENCODING) else: #we have attachment contentType = "multipart/related; " self.h.putheader( "Content-Type", "multipart/related; boundary=\"" + self.boundary + "\"; start=\"" + self.startCID + '\"; type="text/xml"') self.__addcookies() for header, value in headers.items(): self.h.putheader(header, value) SOAPActionValue = '"%s"' % (soapaction or self.soapaction) self.h.putheader("SOAPAction", SOAPActionValue) if self.auth_style & AUTH.httpbasic: val = _b64_encode(self.auth_user + ':' + self.auth_pass) \ .replace("\012", "") self.h.putheader('Authorization', 'Basic ' + val) elif self.auth_style == AUTH.httpdigest and not headers.has_key('Authorization') \ and not headers.has_key('Expect'): def digest_auth_cb(response): self.SendSOAPDataHTTPDigestAuth(response, soapdata, url, request_uri, soapaction, **kw) self.http_callbacks[401] = None self.http_callbacks[401] = digest_auth_cb for header, value in self.user_headers: self.h.putheader(header, value) self.h.endheaders() # print "client.py 336" if 'm' in kw and 't' in kw: a = soapdata print a b = re.sub("http://www.w3.org/2003/05/soap-envelope", "http://schemas.xmlsoap.org/soap/envelope/", a) a = re.sub("http://www.w3.org/2001/XMLSchema", "http://yc/xsd", b) c = "</ns1:password><ns1:_SendRequset><xsd:ext/><xsd:message>" + kw[ 'm'] + "</xsd:message><xsd:send_time/><xsd:target>" + kw[ 't'] + "</xsd:target></ns1:_SendRequset></ns1:sendsms>" soapdata = re.sub("</ns1:password></ns1:sendsms>", c, a) # print soapdata else: a = soapdata b = re.sub("http://www.w3.org/2003/05/soap-envelope", "http://schemas.xmlsoap.org/soap/envelope/", a) soapdata = b # print soapdata self.h.send(soapdata) # Clear prior receive state. self.data, self.ps = None, None