当前位置: 首页>>代码示例>>Python>>正文


Python Address.setRequest方法代码示例

本文整理汇总了Python中ZSI.address.Address.setRequest方法的典型用法代码示例。如果您正苦于以下问题:Python Address.setRequest方法的具体用法?Python Address.setRequest怎么用?Python Address.setRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZSI.address.Address的用法示例。


在下文中一共展示了Address.setRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: binding

# 需要导入模块: from ZSI.address import Address [as 别名]
# 或者: from ZSI.address.Address import setRequest [as 别名]

#.........这里部分代码省略.........
			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)

	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
开发者ID:japina,项目名称:ZSI-hacking,代码行数:69,代码来源:client.py

示例2: URLlib2Binding

# 需要导入模块: from ZSI.address import Address [as 别名]
# 或者: from ZSI.address.Address import setRequest [as 别名]
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)
        
#.........这里部分代码省略.........
开发者ID:philipkershaw,项目名称:ndg-security,代码行数:103,代码来源:VocabServerAPIService_client.py


注:本文中的ZSI.address.Address.setRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。