def setUpMethods(self, port): '''set up all methods representing the port operations. Parameters: port -- Port that defines the operations. ''' assert isinstance(port, WSDLTools.Port), \ 'expecting WSDLTools.Port not: ' %type(port) sd = self._services.get(port.getService().name) assert sd is not None, 'failed to initialize.' binding = port.getBinding() portType = port.getPortType() action_in = '' for bop in binding.operations: try: op = portType.operations[bop.name] except KeyError, ex: raise WsdlGeneratorError,\ 'Port(%s) PortType(%s) missing operation(%s) defined in Binding(%s)' \ %(port.name,portType.name,bop.name,binding.name) for ext in bop.extensions: if isinstance(ext, WSDLTools.SoapOperationBinding): action_in = ext.soapAction break else: warnings.warn('Port(%s) operation(%s) defined in Binding(%s) missing soapAction' \ %(port.name,op.name,binding.name) ) msgin = op.getInputMessage() msgin_name = TextProtect(msgin.name) method_name = self.getMethodName(op.name) m = sd.newMethod() print >> m, '%sdef %s(self, ps, **kw):' % (self.getIndent(level=1), method_name) if msgin is not None: print >> m, '%srequest = ps.Parse(%s.typecode)' % ( self.getIndent(level=2), msgin_name) else: print >> m, '%s# NO input' % self.getIndent(level=2) msgout = op.getOutputMessage() if msgout is not None: msgout_name = TextProtect(msgout.name) print >> m, '%sreturn request,%s()' % (self.getIndent(level=2), msgout_name) else: print >> m, '%s# NO output' % self.getIndent(level=2) print >> m, '%sreturn request,None' % self.getIndent(level=2) print >> m, '' print >> m, '%ssoapAction[\'%s\'] = \'%s\'' % (self.getIndent( level=1), action_in, method_name) print >>m, '%sroot[(%s.typecode.nspname,%s.typecode.pname)] = \'%s\'' \ %(self.getIndent(level=1), msgin_name, msgin_name, method_name)
def getMethodName(self, method): '''return method name. ''' return '%s_%s' % (self.method_prefix, TextProtect(method))
def setUpMethods(self, port): '''set up all methods representing the port operations. Parameters: port -- Port that defines the operations. ''' assert isinstance(port, WSDLTools.Port), \ 'expecting WSDLTools.Port not: ' %type(port) binding = port.getBinding() portType = port.getPortType() service = port.getService() s = self._services[service.name] for bop in binding.operations: try: op = portType.operations[bop.name] except KeyError, ex: raise WsdlGeneratorError,\ 'Port(%s) PortType(%s) missing operation(%s) defined in Binding(%s)' \ %(port.name, portType.name, op.name, binding.name) soap_action = wsaction_in = wsaction_out = None if op.input is not None: wsaction_in = op.getInputAction() if op.output is not None: wsaction_out = op.getOutputAction() for ext in bop.extensions: if isinstance(ext, WSDLTools.SoapOperationBinding) is False: continue soap_action = ext.soapAction if not soap_action: break if wsaction_in is None: break if wsaction_in == soap_action: break if self.strict is False: warnings.warn(\ 'Port(%s) operation(%s) in Binding(%s) soapAction(%s) != WS-Action(%s)' \ %(port.name, op.name, binding.name, soap_action, wsaction_in), ) break raise WsdlGeneratorError,\ 'Port(%s) operation(%s) in Binding(%s) soapAction(%s) MUST match WS-Action(%s)' \ %(port.name, op.name, binding.name, soap_action, wsaction_in) method_name = self.getMethodName(op.name) m = s.newMethod() print >> m, '%sdef %s(self, ps, address):' % (self.getIndent( level=1), method_name) msgin_name = msgout_name = None msgin, msgout = op.getInputMessage(), op.getOutputMessage() if msgin is not None: msgin_name = TextProtect(msgin.name) if msgout is not None: msgout_name = TextProtect(msgout.name) indent = self.getIndent(level=2) for l in self.createMethodBody(msgin_name, msgout_name): print >> m, indent + l print >> m, '' print >> m, '%ssoapAction[\'%s\'] = \'%s\'' % (self.getIndent( level=1), wsaction_in, method_name) print >> m, '%swsAction[\'%s\'] = \'%s\'' % (self.getIndent( level=1), method_name, wsaction_out) print >>m, '%sroot[(%s.typecode.nspname,%s.typecode.pname)] = \'%s\'' \ %(self.getIndent(level=1), msgin_name, msgin_name, method_name)
def mangle(self, name): return TextProtect(name)