From: <bov...@us...> - 2007-05-11 18:43:06
|
Revision: 1378 http://svn.sourceforge.net/pywebsvcs/?rev=1378&view=rev Author: boverhof Date: 2007-05-11 11:43:06 -0700 (Fri, 11 May 2007) Log Message: ----------- M test/test_zsi_net.py M test/wsdl2py/runTests.py A test/test_callhome.py M ZSI/ServiceProxy.py M ZSI/generate/commands.py Modified Paths: -------------- trunk/zsi/ZSI/ServiceProxy.py trunk/zsi/ZSI/generate/commands.py trunk/zsi/test/test_zsi_net.py trunk/zsi/test/wsdl2py/runTests.py Added Paths: ----------- trunk/zsi/test/test_callhome.py Modified: trunk/zsi/ZSI/ServiceProxy.py =================================================================== --- trunk/zsi/ZSI/ServiceProxy.py 2007-05-08 20:54:37 UTC (rev 1377) +++ trunk/zsi/ZSI/ServiceProxy.py 2007-05-11 18:43:06 UTC (rev 1378) @@ -18,8 +18,6 @@ from ZSI.schema import GED, GTD import wstools -#from ZSI.wstools.Utility import SplitQName -#from ZSI.wstools.Namespaces import WSDL #url_to_mod = re.compile(r'<([^ \t\n\r\f\v:]+:)?include\s+location\s*=\s*"(\S+)"') @@ -95,18 +93,19 @@ else: # dont do anything to anames containers.ContainerBase.func_aname = lambda instnc,n: str(n) - #client,types = commands.wsdl2py(['-u', wsdl,'-o', cachedir, '-t', "%s_types.py" %]) - types = _urn_to_module(wsdl) - commands.wsdl2py(['-u', wsdl,'-o', cachedir, '-t', types]) + files = commands.wsdl2py(['-o', cachedir, wsdl]) if cp is None: cp = ConfigParser() if not cp.has_section(section): cp.add_section(section) + + types = filter(lambda f: f.endswith('_types.py'), files)[0] cp.set(section, option, types) cp.write(open(file, 'w')) if os.path.abspath(cachedir) not in sys.path: sys.path.append(os.path.abspath(cachedir)) - self._mod = __import__(types) + mod = os.path.split(types)[-1].rstrip('.py') + self._mod = __import__(mod) def _call(self, name, *args, **kwargs): """Call the named remote web service method.""" @@ -198,7 +197,7 @@ if self._asdict: self._nullpyclass(response) return binding.Receive(replytype=response, encodingStyle=callinfo.encodingStyle) - + def _nullpyclass(cls, typecode): typecode.pyclass = None if not hasattr(typecode, 'ofwhat'): return @@ -207,198 +206,6 @@ else: #Struct/ComplexType for i in typecode.ofwhat: cls._nullpyclass(i) _nullpyclass = classmethod(_nullpyclass) - - -# -# -# def _getTypeCodes(self, callinfo): -# """Returns typecodes representing input and output messages, if request and/or -# response fails to be generated return None for either or both. -# -# callinfo -- WSDLTools.SOAPCallInfo instance describing an operation. -# """ -# prefix = None -# self._resetPrefixDict() -# if callinfo.use == 'encoded': -# prefix = self._getPrefix(callinfo.namespace) -# try: -# requestTC = self._getTypeCode(parameters=callinfo.getInParameters(), literal=(callinfo.use=='literal')) -# except EvaluateException, ex: -# print "DEBUG: Request Failed to generate --", ex -# requestTC = None -# -# self._resetPrefixDict() -# try: -# replyTC = self._getTypeCode(parameters=callinfo.getOutParameters(), literal=(callinfo.use=='literal')) -# except EvaluateException, ex: -# print "DEBUG: Response Failed to generate --", ex -# replyTC = None -# -# request = response = None -# if callinfo.style == 'rpc': -# if requestTC: request = TC.Struct(pyclass=None, ofwhat=requestTC, pname=callinfo.methodName) -# if replyTC: response = TC.Struct(pyclass=None, ofwhat=replyTC, pname='%sResponse' %callinfo.methodName) -# else: -# if requestTC: request = requestTC[0] -# if replyTC: response = replyTC[0] -# -# #THIS IS FOR RPC/ENCODED, DOC/ENCODED Wrapper -# if request and prefix and callinfo.use == 'encoded': -# request.oname = '%(prefix)s:%(name)s xmlns:%(prefix)s="%(namespaceURI)s"' \ -# %{'prefix':prefix, 'name':request.aname, 'namespaceURI':callinfo.namespace} -# -# return request, response -# -# def _getTypeCode(self, parameters, literal=False): -# """Returns typecodes representing a parameter set -# parameters -- list of WSDLTools.ParameterInfo instances representing -# the parts of a WSDL Message. -# """ -# ofwhat = [] -# for part in parameters: -# namespaceURI,localName = part.type -# -# if part.element_type: -# #global element -# element = self._wsdl.types[namespaceURI].elements[localName] -# tc = self._getElement(element, literal=literal, local=False, namespaceURI=namespaceURI) -# else: -# #local element -# name = part.name -# typeClass = self._getTypeClass(namespaceURI, localName) -# if not typeClass: -# tp = self._wsdl.types[namespaceURI].types[localName] -# tc = self._getType(tp, name, literal, local=True, namespaceURI=namespaceURI) -# else: -# tc = typeClass(name) -# ofwhat.append(tc) -# return ofwhat -# -# def _globalElement(self, typeCode, namespaceURI, literal): -# """namespaces typecodes representing global elements with -# literal encoding. -# typeCode -- typecode representing an element. -# namespaceURI -- namespace -# literal -- True/False -# """ -# if literal: -# typeCode.oname = '%(prefix)s:%(name)s xmlns:%(prefix)s="%(namespaceURI)s"' \ -# %{'prefix':self._getPrefix(namespaceURI), 'name':typeCode.oname, 'namespaceURI':namespaceURI} -# -# def _getPrefix(self, namespaceURI): -# """Retrieves a prefix/namespace mapping. -# namespaceURI -- namespace -# """ -# prefixDict = self._getPrefixDict() -# if prefixDict.has_key(namespaceURI): -# prefix = prefixDict[namespaceURI] -# else: -# prefix = 'ns1' -# while prefix in prefixDict.values(): -# prefix = 'ns%d' %int(prefix[-1]) + 1 -# prefixDict[namespaceURI] = prefix -# return prefix -# -# def _getPrefixDict(self): -# """Used to hide the actual prefix dictionary. -# """ -# if not hasattr(self, '_prefixDict'): -# self.__prefixDict = {} -# return self.__prefixDict -# -# def _resetPrefixDict(self): -# """Clears the prefix dictionary, this needs to be done -# before creating a new typecode for a message -# (ie. before, and after creating a new message typecode) -# """ -# self._getPrefixDict().clear() -# -# def _getElement(self, element, literal=False, local=False, namespaceURI=None): -# """Returns a typecode instance representing the passed in element. -# element -- XMLSchema.ElementDeclaration instance -# literal -- literal encoding? -# local -- is locally defined? -# namespaceURI -- namespace -# """ -# if not element.isElement(): -# raise TypeError, 'Expecting an ElementDeclaration' -# -# tc = None -# elementName = element.getAttribute('name') -# tp = element.getTypeDefinition('type') -# -# typeObj = None -# if not (tp or element.content): -# nsuriType,localName = element.getAttribute('type') -# typeClass = self._getTypeClass(nsuriType,localName) -# -# typeObj = typeClass(elementName) -# elif not tp: -# tp = element.content -# -# if not typeObj: -# typeObj = self._getType(tp, elementName, literal, local, namespaceURI) -# -# minOccurs = int(element.getAttribute('minOccurs')) -# typeObj.optional = not minOccurs -# typeObj.minOccurs = minOccurs -# -# maxOccurs = element.getAttribute('maxOccurs') -# typeObj.repeatable = (maxOccurs == 'unbounded') or (int(maxOccurs) > 1) -# -# return typeObj -# -# def _getType(self, tp, name, literal, local, namespaceURI): -# """Returns a typecode instance representing the passed in type and name. -# tp -- XMLSchema.TypeDefinition instance -# name -- element name -# literal -- literal encoding? -# local -- is locally defined? -# namespaceURI -- namespace -# """ -# ofwhat = [] -# if not (tp.isDefinition() and tp.isComplex()): -# raise EvaluateException, 'only supporting complexType definition' -# elif tp.content.isComplex(): -# if hasattr(tp.content, 'derivation') and tp.content.derivation.isRestriction(): -# derived = tp.content.derivation -# typeClass = self._getTypeClass(*derived.getAttribute('base')) -# if typeClass == TC.Array: -# attrs = derived.attr_content[0].attributes[WSDL.BASE] -# prefix, localName = SplitQName(attrs['arrayType']) -# nsuri = derived.attr_content[0].getXMLNS(prefix=prefix) -# localName = localName.split('[')[0] -# simpleTypeClass = self._getTypeClass(namespaceURI=nsuri, localName=localName) -# if simpleTypeClass: -# ofwhat = simpleTypeClass() -# else: -# tp = self._wsdl.types[nsuri].types[localName] -# ofwhat = self._getType(tp=tp, name=None, literal=literal, local=True, namespaceURI=nsuri) -# else: -# raise EvaluateException, 'only support soapenc:Array restrictions' -# return typeClass(atype=name, ofwhat=ofwhat, pname=name, childNames='item') -# else: -# raise EvaluateException, 'complexContent only supported for soapenc:Array derivations' -# elif tp.content.isModelGroup(): -# modelGroup = tp.content -# for item in modelGroup.content: -# ofwhat.append(self._getElement(item, literal=literal, local=True)) -# -# tc = TC.Struct(pyclass=None, ofwhat=ofwhat, pname=name) -# if not local: -# self._globalElement(tc, namespaceURI=namespaceURI, literal=literal) -# return tc -# -# raise EvaluateException, 'only supporting complexType w/ model group, or soapenc:Array restriction' -# -# def _getTypeClass(self, namespaceURI, localName): -# """Returns a typecode class representing the type we are looking for. -# localName -- name of the type we are looking for. -# namespaceURI -- defining XMLSchema targetNamespace. -# """ -# bti = BaseTypeInterpreter() -# simpleTypeClass = bti.get_typeclass(localName, namespaceURI) -# return simpleTypeClass class MethodProxy: Modified: trunk/zsi/ZSI/generate/commands.py =================================================================== --- trunk/zsi/ZSI/generate/commands.py 2007-05-08 20:54:37 UTC (rev 1377) +++ trunk/zsi/ZSI/generate/commands.py 2007-05-11 18:43:06 UTC (rev 1378) @@ -179,11 +179,11 @@ if isinstance(wsdl, XMLSchema.XMLSchema): wsdl.location = location - _wsdl2py(options, wsdl) - return + return _wsdl2py(options, wsdl) - _wsdl2py(options, wsdl) - _wsdl2dispatch(options, wsdl) + modules = _wsdl2py(options, wsdl) + modules.append(_wsdl2dispatch(options, wsdl)) + return modules def _wsdl2py(options, wsdl): @@ -231,20 +231,32 @@ wsm = WriteServiceModule(wsdl, addressing=options.address) # if options.types != None: # wsm.setTypesModuleName(options.types) + + files = [] + append = files.append if options.schema is False: - fd = open(os.path.join(options.output_dir, '%s.py' %wsm.getClientModuleName()), 'w+') + client_mod = wsm.getClientModuleName() + client_file = os.path.join(options.output_dir, '%s.py' %client_mod) + append(client_file) + fd = open(client_file, 'w+') + # simple naming writes the messages to a separate file if not options.simple_naming: wsm.writeClient(fd) else: # provide a separate file to store messages to. - msg_fd = open(os.path.join(options.output_dir, '%s.py' %wsm.getMessagesModuleName()), 'w+') + msg_fd = open( os.path.join(options.output_dir, '%s.py' %wsm.getMessagesModuleName()), 'w+' ) wsm.writeClient(fd, msg_fd=msg_fd) msg_fd.close() fd.close() - fd = open( os.path.join(options.output_dir, '%s.py' %wsm.getTypesModuleName()), 'w+') + + types_mod = wsm.getTypesModuleName() + types_file = os.path.join(options.output_dir, '%s.py' %types_mod) + append(types_file) + fd = open( os.path.join(options.output_dir, '%s.py' %types_mod), 'w+' ) wsm.writeTypes(fd) fd.close() + return files def wsdl2dispatch(args=None): @@ -296,7 +308,7 @@ else: wsdl = reader.loadFromURL(args[0]) - _wsdl2dispatch(options, wsdl) + return _wsdl2dispatch(options, wsdl) def _wsdl2dispatch(options, wsdl): @@ -322,6 +334,9 @@ ss = ServiceDescription() ss.fromWSDL(wsdl) - fd = open( os.path.join(options.output_dir, ss.getServiceModuleName()+'.py'), 'w+') + module_name = ss.getServiceModuleName()+'.py' + fd = open( os.path.join(options.output_dir, module_name), 'w+') ss.write(fd) + + return module_name fd.close() Added: trunk/zsi/test/test_callhome.py =================================================================== --- trunk/zsi/test/test_callhome.py (rev 0) +++ trunk/zsi/test/test_callhome.py 2007-05-11 18:43:06 UTC (rev 1378) @@ -0,0 +1,24 @@ +#!/usr/bin/env python +import os,unittest +from ZSI import version +from ZSI.wstools.logging import gridLog + +os.environ['GRIDLOG_ON'] = '1' +os.environ['GRIDLOG_DEST'] = "gridlog-udp://portnoy.lbl.gov:15100" + + +class TestCase(unittest.TestCase): + def ping(self): + gridLog(program="test_callhome.py", zsi="v%d.%d.%d" % version.Version, event="ping") + +def makeTestSuite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestCase, "ping")) + return suite + +def main(): + unittest.main(defaultTest="makeTestSuite") + +if __name__ == '__main__': + main() + Modified: trunk/zsi/test/test_zsi_net.py =================================================================== --- trunk/zsi/test/test_zsi_net.py 2007-05-08 20:54:37 UTC (rev 1377) +++ trunk/zsi/test/test_zsi_net.py 2007-05-11 18:43:06 UTC (rev 1378) @@ -14,6 +14,7 @@ import test_URI import test_list import test_rfc2617 +import test_callhome def makeTestSuite(): return unittest.TestSuite( Modified: trunk/zsi/test/wsdl2py/runTests.py =================================================================== --- trunk/zsi/test/wsdl2py/runTests.py 2007-05-08 20:54:37 UTC (rev 1377) +++ trunk/zsi/test/wsdl2py/runTests.py 2007-05-11 18:43:06 UTC (rev 1378) @@ -3,9 +3,13 @@ # Joshua R. Boverhof, LBNL # See Copyright for copyright notice! ########################################################################### -import unittest, warnings +import unittest, warnings, os +from ZSI import version +from ZSI.wstools.logging import gridLog from ServiceTest import main, CONFIG_PARSER, DOCUMENT, LITERAL, BROKE, TESTS +os.environ['GRIDLOG_ON'] = '1' +os.environ['GRIDLOG_DEST'] = "gridlog-udp://portnoy.lbl.gov:15100" # General targets def dispatch(): @@ -95,6 +99,7 @@ if __name__ == "__main__": + gridLog(program="runTests.py", zsi="v%d.%d.%d" % version.Version, event="ping") main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |