本文整理汇总了Python中ZSI.address.Address类的典型用法代码示例。如果您正苦于以下问题:Python Address类的具体用法?Python Address怎么用?Python Address使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Address类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _Dispatch
def _Dispatch(ps, server, SendResponse, SendFault, post, action, nsdict={}, **kw):
"""Send ParsedSoap instance to ServiceContainer, which dispatches to
appropriate service via post, and method via action. Response is a
self-describing pyobj, which is passed to a SoapWriter.
Call SendResponse or SendFault to send the reply back, appropriately.
server -- ServiceContainer instance
"""
localURL = "http://%s:%d%s" % (server.server_name, server.server_port, post)
address = action
service = server.getNode(post)
isWSResource = False
if isinstance(service, WSAResource):
isWSResource = True
service.setServiceURL(localURL)
address = Address()
try:
address.parse(ps)
except Exception, e:
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
if action and action != address.getAction():
e = WSActionException(
'SOAP Action("%s") must match WS-Action("%s") if specified.' % (action, address.getAction())
)
return SendFault(FaultFromException(e, 0, None), **kw)
action = address.getAction()
示例2: processResponse
def processResponse(self, sw, **kw):
if sw is None:
self.address = None
return
request, resource = kw['request'], kw['resource']
if isinstance(request, twisted.web.http.Request) is False:
raise TypeError, '%s instance expected' %http.Request
d = getattr(resource, 'wsAction', None)
key = self.op_name
if d is None or d.has_key(key) is False:
raise WSActionNotSpecified,\
'Error looking for key(%s) in wsAction dictionary(%s)' %(key, str(d))
addressRsp = Address(action=d[key])
if request.transport.TLS == 0:
addressRsp.setResponseFromWSAddress(\
self.address, 'http://%s:%d%s' %(
request.host.host, request.host.port, request.path)
)
else:
addressRsp.setResponseFromWSAddress(\
self.address, 'https://%s:%d%s' %(
request.host.host, request.host.port, request.path)
)
addressRsp.serialize(sw, typed=False)
self.address = None
return sw
示例3: SendResponse
# Verify if Signed
service.verify(ps)
# If No response just return.
if result is None:
return SendResponse('', **kw)
sw = SoapWriter(nsdict=nsdict)
try:
sw.serialize(result)
except Exception, e:
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
if isWSResource is True:
action = service.getResponseAction(ps, action)
addressRsp = Address(action=action)
try:
addressRsp.setResponseFromWSAddress(address, localURL)
addressRsp.serialize(sw)
except Exception, e:
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
# Create Signatures
service.sign(sw)
try:
soapdata = str(sw)
return SendResponse(soapdata, **kw)
except Exception, e:
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
示例4: binding
class _Binding:
'''Object that represents a binding (connection) to a SOAP server.
Once the binding is created, various ways of sending and
receiving SOAP messages are available.
'''
defaultHttpTransport = httplib.HTTPConnection
defaultHttpsTransport = httplib.HTTPSConnection
logger = _GetLogger('ZSI.client.Binding')
def __init__(self, nsdict=None, transport=None, url=None, tracefile=None,
readerclass=None, writerclass=None, soapaction='',
wsAddressURI=None, sig_handler=None, transdict=None, **kw):
'''Initialize.
Keyword arguments include:
transport -- default use HTTPConnection.
transdict -- dict of values to pass to transport.
url -- URL of resource, POST is path
soapaction -- value of SOAPAction header
auth -- (type, name, password) triplet; default is unauth
nsdict -- namespace entries to add
tracefile -- file to dump packet traces
cert_file, key_file -- SSL data (q.v.)
readerclass -- DOM reader class
writerclass -- DOM writer class, implements MessageInterface
wsAddressURI -- namespaceURI of WS-Address to use. By default
it's not used.
sig_handler -- XML Signature handler, must sign and verify.
endPointReference -- optional Endpoint Reference.
'''
self.data = None
self.ps = None
self.user_headers = []
self.nsdict = nsdict or {}
self.transport = transport
self.transdict = transdict or {}
self.url = url
self.trace = tracefile
self.readerclass = readerclass
self.writerclass = writerclass
self.soapaction = soapaction
self.wsAddressURI = wsAddressURI
self.sig_handler = sig_handler
self.address = None
self.endPointReference = kw.get('endPointReference', None)
self.cookies = Cookie.SimpleCookie()
self.http_callbacks = {}
if kw.has_key('auth'):
self.SetAuth(*kw['auth'])
else:
self.SetAuth(AUTH.none)
def SetAuth(self, style, user=None, password=None):
'''Change auth style, return object to user.
'''
self.auth_style, self.auth_user, self.auth_pass = \
style, user, password
return self
def SetURL(self, url):
'''Set the URL we post to.
'''
self.url = url
return self
def ResetHeaders(self):
'''Empty the list of additional headers.
'''
self.user_headers = []
return self
def ResetCookies(self):
'''Empty the list of cookies.
'''
self.cookies = Cookie.SimpleCookie()
def AddHeader(self, header, value):
'''Add a header to send.
'''
self.user_headers.append((header, value))
return self
def __addcookies(self):
'''Add cookies from self.cookies to request in self.h
'''
for cname, morsel in self.cookies.items():
attrs = []
value = morsel.get('version', '')
if value != '' and value != '0':
attrs.append('$Version=%s' % value)
attrs.append('%s=%s' % (cname, morsel.coded_value))
value = morsel.get('path')
if value:
attrs.append('$Path=%s' % value)
value = morsel.get('domain')
if value:
attrs.append('$Domain=%s' % value)
self.h.putheader('Cookie', "; ".join(attrs))
def RPC(self, url, opname, obj, replytype=None, **kw):
#.........这里部分代码省略.........
示例5: Send
def Send(self, url, opname, obj, nsdict={}, soapaction=None, wsaction=None,
endPointReference=None, soapheaders=(), **kw):
'''Send a message. If url is None, use the value from the
constructor (else error). obj is the object (data) to send.
Data may be described with a requesttypecode keyword, the default
is the class's typecode (if there is one), else Any.
Try to serialize as a Struct, if this is not possible serialize an Array. If
data is a sequence of built-in python data types, it will be serialized as an
Array, unless requesttypecode is specified.
arguments:
url --
opname -- struct wrapper
obj -- python instance
key word arguments:
nsdict --
soapaction --
wsaction -- WS-Address Action, goes in SOAP Header.
endPointReference -- set by calling party, must be an
EndPointReference type instance.
soapheaders -- list of pyobj, typically w/typecode attribute.
serialized in the SOAP:Header.
requesttypecode --
'''
url = url or self.url
endPointReference = endPointReference or self.endPointReference
# Serialize the object.
d = {}
d.update(self.nsdict)
d.update(nsdict)
sw = SoapWriter(nsdict=d, header=True, outputclass=self.writerclass,
encodingStyle=kw.get('encodingStyle'),)
requesttypecode = kw.get('requesttypecode')
if kw.has_key('_args'): #NamedParamBinding
tc = requesttypecode or TC.Any(pname=opname, aslist=False)
sw.serialize(kw['_args'], tc)
elif not requesttypecode:
tc = getattr(obj, 'typecode', None) or TC.Any(pname=opname, aslist=False)
try:
if type(obj) in _seqtypes:
obj = dict(map(lambda i: (i.typecode.pname,i), obj))
except AttributeError:
# can't do anything but serialize this in a SOAP:Array
tc = TC.Any(pname=opname, aslist=True)
else:
tc = TC.Any(pname=opname, aslist=False)
sw.serialize(obj, tc)
else:
sw.serialize(obj, requesttypecode)
for i in soapheaders:
sw.serialize_header(i)
#
# Determine the SOAP auth element. SOAP:Header element
if self.auth_style & AUTH.zsibasic:
sw.serialize_header(_AuthHeader(self.auth_user, self.auth_pass),
_AuthHeader.typecode)
#
# Serialize WS-Address
if self.wsAddressURI is not None:
if self.soapaction and wsaction.strip('\'"') != self.soapaction:
raise WSActionException, 'soapAction(%s) and WS-Action(%s) must match'\
%(self.soapaction,wsaction)
self.address = Address(url, self.wsAddressURI)
self.address.setRequest(endPointReference, wsaction)
self.address.serialize(sw)
#
# WS-Security Signature Handler
if self.sig_handler is not None:
self.sig_handler.sign(sw)
scheme,netloc,path,nil,nil,nil = urlparse.urlparse(url)
transport = self.transport
if transport is None and url is not None:
if scheme == 'https':
transport = self.defaultHttpsTransport
elif scheme == 'http':
transport = self.defaultHttpTransport
else:
raise RuntimeError, 'must specify transport or url startswith https/http'
# Send the request.
if issubclass(transport, httplib.HTTPConnection) is False:
raise TypeError, 'transport must be a HTTPConnection'
soapdata = str(sw)
self.h = transport(netloc, None, **self.transdict)
self.h.connect()
self.SendSOAPData(soapdata, url, soapaction, **kw)
示例6: _Dispatch
def _Dispatch(ps, server, SendResponse, SendFault, post, action, nsdict={}, **kw):
'''Send ParsedSoap instance to ServiceContainer, which dispatches to
appropriate service via post, and method via action. Response is a
self-describing pyobj, which is passed to a SoapWriter.
Call SendResponse or SendFault to send the reply back, appropriately.
server -- ServiceContainer instance
'''
localURL = 'http://%s:%d%s' %(server.server_name,server.server_port,post)
address = action
service = server.getNode(post)
isWSResource = False
if isinstance(service, SimpleWSResource):
isWSResource = True
service.setServiceURL(localURL)
address = Address()
try:
address.parse(ps)
except Exception as e:
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
if action and action != address.getAction():
e = WSActionException('SOAP Action("%s") must match WS-Action("%s") if specified.' \
%(action,address.getAction()))
return SendFault(FaultFromException(e, 0, None), **kw)
action = address.getAction()
if isinstance(service, ServiceInterface) is False:
e = NoSuchService('no service at POST(%s) in container: %s' %(post,server))
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
if not service.authorize(None, post, action):
return SendFault(Fault(Fault.Server, "Not authorized"), code=401)
#try:
# raise NotAuthorized()
#except Exception, e:
#return SendFault(FaultFromException(e, 0, None), code=401, **kw)
##return SendFault(FaultFromException(NotAuthorized(), 0, None), code=401, **kw)
try:
method = service.getOperation(ps, address)
except Exception as e:
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
try:
if isWSResource is True:
result = method(ps, address)
else:
result = method(ps)
except Exception as e:
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
# Verify if Signed
service.verify(ps)
# If No response just return.
if result is None:
return
sw = SoapWriter(nsdict=nsdict)
try:
sw.serialize(result)
except Exception as e:
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
if isWSResource is True:
action = service.getResponseAction(action)
addressRsp = Address(action=action)
try:
addressRsp.setResponseFromWSAddress(address, localURL)
addressRsp.serialize(sw)
except Exception as e:
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
# Create Signatures
service.sign(sw)
try:
soapdata = str(sw)
return SendResponse(soapdata, **kw)
except Exception as e:
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
示例7: Send
def Send(self, url, opname, obj, nsdict={}, soapaction=None, wsaction=None,
endPointReference=None, **kw):
'''Send a message. If url is None, use the value from the
constructor (else error). obj is the object (data) to send.
Data may be described with a requesttypecode keyword, or a
requestclass keyword; default is the class's typecode (if
there is one), else Any.
Optional WS-Address Keywords
wsaction -- WS-Address Action, goes in SOAP Header.
endPointReference -- set by calling party, must be an
EndPointReference type instance.
'''
url = url or self.url
# Get the TC for the obj.
if kw.has_key('requesttypecode'):
tc = kw['requesttypecode']
elif kw.has_key('requestclass'):
tc = kw['requestclass'].typecode
elif type(obj) == types.InstanceType:
tc = getattr(obj.__class__, 'typecode')
if tc is None: tc = TC.Any(opname, aslist=1)
else:
tc = TC.Any(opname, aslist=1)
endPointReference = endPointReference or self.endPointReference
# Serialize the object.
d = {}
d.update(self.nsdict)
d.update(nsdict)
useWSAddress = self.wsAddressURI is not None
sw = SoapWriter(nsdict=d, header=True, outputclass=self.writerclass,
encodingStyle=kw.get('encodingStyle'),)
if kw.has_key('_args'):
sw.serialize(kw['_args'], tc)
else:
sw.serialize(obj, tc)
# Determine the SOAP auth element. SOAP:Header element
if self.auth_style & AUTH.zsibasic:
sw.serialize_header(_AuthHeader(self.auth_user, self.auth_pass),
_AuthHeader.typecode)
# Serialize WS-Address
if useWSAddress is True:
if self.soapaction and wsaction.strip('\'"') != self.soapaction:
raise WSActionException, 'soapAction(%s) and WS-Action(%s) must match'\
%(self.soapaction,wsaction)
self.address = Address(url, self.wsAddressURI)
self.address.setRequest(endPointReference, wsaction)
self.address.serialize(sw)
# WS-Security Signature Handler
if self.sig_handler is not None:
self.sig_handler.sign(sw)
soapdata = str(sw)
scheme,netloc,path,nil,nil,nil = urlparse.urlparse(url)
# self.transport httplib.HTTPConnection derived class set-up removed
# from HERE - this now handled by urllib2.urlopen()
self.SendSOAPData(soapdata, url, soapaction, **kw)
示例8: URLlib2Binding
class URLlib2Binding(client.Binding):
def Send(self, url, opname, obj, nsdict={}, soapaction=None, wsaction=None,
endPointReference=None, **kw):
'''Send a message. If url is None, use the value from the
constructor (else error). obj is the object (data) to send.
Data may be described with a requesttypecode keyword, or a
requestclass keyword; default is the class's typecode (if
there is one), else Any.
Optional WS-Address Keywords
wsaction -- WS-Address Action, goes in SOAP Header.
endPointReference -- set by calling party, must be an
EndPointReference type instance.
'''
url = url or self.url
# Get the TC for the obj.
if kw.has_key('requesttypecode'):
tc = kw['requesttypecode']
elif kw.has_key('requestclass'):
tc = kw['requestclass'].typecode
elif type(obj) == types.InstanceType:
tc = getattr(obj.__class__, 'typecode')
if tc is None: tc = TC.Any(opname, aslist=1)
else:
tc = TC.Any(opname, aslist=1)
endPointReference = endPointReference or self.endPointReference
# Serialize the object.
d = {}
d.update(self.nsdict)
d.update(nsdict)
useWSAddress = self.wsAddressURI is not None
sw = SoapWriter(nsdict=d, header=True, outputclass=self.writerclass,
encodingStyle=kw.get('encodingStyle'),)
if kw.has_key('_args'):
sw.serialize(kw['_args'], tc)
else:
sw.serialize(obj, tc)
# Determine the SOAP auth element. SOAP:Header element
if self.auth_style & AUTH.zsibasic:
sw.serialize_header(_AuthHeader(self.auth_user, self.auth_pass),
_AuthHeader.typecode)
# Serialize WS-Address
if useWSAddress is True:
if self.soapaction and wsaction.strip('\'"') != self.soapaction:
raise WSActionException, 'soapAction(%s) and WS-Action(%s) must match'\
%(self.soapaction,wsaction)
self.address = Address(url, self.wsAddressURI)
self.address.setRequest(endPointReference, wsaction)
self.address.serialize(sw)
# WS-Security Signature Handler
if self.sig_handler is not None:
self.sig_handler.sign(sw)
soapdata = str(sw)
scheme,netloc,path,nil,nil,nil = urlparse.urlparse(url)
# self.transport httplib.HTTPConnection derived class set-up removed
# from HERE - this now handled by urllib2.urlopen()
self.SendSOAPData(soapdata, url, soapaction, **kw)
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)
#.........这里部分代码省略.........