Example #1
0
    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:
                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)

        return
Example #2
0
def _wsdl2py(options, wsdl):

    if options.twisted:
        from pysphere.ZSI.generate.containers import ServiceHeaderContainer
        try:
            ServiceHeaderContainer.imports.remove(
                'from pysphere.ZSI import client')
        except ValueError:
            pass
        ServiceHeaderContainer.imports.append(
            'from pysphere.ZSI.twisted import client')

    if options.simple_naming:
        # Use a different client suffix
        # WriteServiceModule.client_module_suffix = "_client"
        # Write messages definitions to a separate file.
        #wsdl2pyServiceDescription.separate_messages = True
        # Use more simple type and element class names
        containers.SetTypeNameFunc(lambda n: '%s_' % (NC_to_CN(n)))
        containers.SetElementNameFunc(lambda n: '%s' % (NC_to_CN(n)))
        # Don't add "_" to the attribute name (remove when --aname works well)
        containers.ContainerBase.func_aname = lambda instnc, n: TextProtect(
            str(n))
        # write out the modules with their names rather than their number.
        utility.namespace_name = lambda cls, ns: utility.Namespace2ModuleName(
            ns)

    files = []
    append = files.append
    if isinstance(wsdl, XMLSchema.XMLSchema):
        wsm = WriteServiceModule(_XMLSchemaAdapter(wsdl.location, wsdl),
                                 addressing=options.address)
    else:
        wsm = WriteServiceModule(wsdl, addressing=options.address)
        client_mod = wsm.getClientModuleName()
        client_file = join(options.output_dir, '%s.py' % client_mod)
        append(client_file)
        fd = open(client_file, 'w+')
        wsm.writeClient(fd)
        fd.close()

    types_mod = wsm.getTypesModuleName()
    types_file = join(options.output_dir, '%s.py' % types_mod)
    append(types_file)
    fd = open(types_file, 'w+')
    wsm.writeTypes(fd)
    fd.close()

    return files
Example #3
0
 def getMethodName(self, method):
     '''return method name.
     '''
     return '%s_%s' % (self.method_prefix, TextProtect(method))
Example #4
0
    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:
                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)
Example #5
0
 def mangle(self, name):
     return TextProtect(name)