print ExtPerson().output(0, p) try: print ExtPerson().output(0, "apa") except ExtOutputError as e: pass print ExtPersonData().xsd().xml() try: pd = ExtPersonData().parse(0, dict(person=u"viktor", friends=[u"mort", u"niklas"], name=u"Viktor Fougstedt")) except ExtRegexpMismatchError: pass pd = ExtPersonData().parse( 0, dict(person=u"person-viktor", friends=[u"person-mort", u"person-niklas"], name=u"Viktor Fougstedt")) print pd resp = XMLNode("response") ExtPersonData().to_xml(resp, ExtPersonData().output(0, pd)) soap = resp.xml() print soap import xml.dom.minidom dom = xml.dom.minidom.parseString(soap) tmp = ExtPersonData().from_xml(dom.documentElement) print tmp print ExtPersonData().parse(0, tmp)
def get_wsdl(self, path): """If incoming path matches .get_wsdl_url(True), output a WSDL which is bug-compatible with the Microsoft svcutil toolchain, accomplished by renaming all input parameters to <name> + '_in'. The WSDL/SOAP URI:s reflect the compatability mode (/SOAP_mscompat rather than /SOAP for example). """ #self.types = {} #self.generate_soap_fundefs() # Start by creating the base elements for the respective # components. That way we can add specific subelements as we # go. if path == self.get_wsdl_path(True): mssuffix = "_mscompat" mscompat = True elif path == self.get_wsdl_path(False): mssuffix = "" mscompat = False else: self.logger.error("VOLVO") raise ExtInternalError() wsdl_ns = self.get_wsdl_url(mscompat) schema_ns = self.get_schema_url(mscompat) defattrs = { 'xmlns:self': wsdl_ns, 'xmlns:myxsd': schema_ns, 'xmlns:soap': "http://schemas.xmlsoap.org/wsdl/soap/", 'xmlns': "http://schemas.xmlsoap.org/wsdl/", } name_attr = self.server.service_name if self.version > 0: name_attr += "-" + self.get_version_string(with_dashes=False) wsdl_root = XMLNode('definitions', name=name_attr, targetNamespace=wsdl_ns, _other_attributes=defattrs, _space_children=True) t = wsdl_root.new('types') wsdl_schema_root = t.new('schema', targetNamespace=schema_ns, xmlns="http://www.w3.org/2001/XMLSchema", elementFormDefault="qualified", _space_children=True) # Note that the dashes in the version will be removed by # capsification later p = self.server.service_name p += self.get_version_string(with_dashes=True) p += mssuffix ptname = ExtType.capsify(p + '-port-type') srvname = ExtType.capsify(p + 'service') bndname = ExtType.capsify(p + '-soap-binding') # PortType, Binding and Service are added to the WSDL XML element # last, since the <message> elements should come before them, but # we want to generate the contents of these three nodes at the # same time as the <message> elements. wsdl_porttype_root = XMLNode('portType', name=ptname, _space_children=True) wsdl_binding_root = XMLNode('binding', name=bndname, type="self:" + ptname, _space_children=True) wsdl_binding_root.new('soap:binding', style='document', transport="http://schemas.xmlsoap.org/soap/http") wsdl_service_root = XMLNode('service', name=srvname) prt = wsdl_service_root.new('port', name=srvname + 'Port', binding="self:" + bndname) prt.new('soap:address', location=self.server.get_server_url() + 'SOAP') # TODO ### #faultdef = RPCSOAPTypeDefFactory(self).typedef(SOAPFaultDetailType()._docdict()) #faultmsg = wsdl_root.new("message", name="msgFaultDetail") #faultmsg.new("part", name="fault", element="myxsd:soapFaultDetail") def add_type(schemaelem, already_added, typething): typ = ExtType.instance(typething) if typ._name() in already_added: return already_added.add(typ._name()) schemaelem.add(typ.xsd()) for (_key, subtyp) in typ._subtypes(): add_type(schemaelem, already_added, subtyp) added_types = set() for funcls in self.get_visible_functions(): wsdl_schema_root.add(funcls.xsd_request(mscompat)) wsdl_schema_root.add(funcls.xsd_response()) for (_name, typ, _desc) in funcls.get_parameters(): add_type(wsdl_schema_root, added_types, typ) (typ, _desc) = funcls._returns() add_type(wsdl_schema_root, added_types, typ) # Doc/lit-wrap input message msg = wsdl_root.new('message', name=funcls.input_message_name()) msg.new('part', name='parameters', element="myxsd:" + funcls.request_element_name()) # Doc/lit-wrap output message msg = wsdl_root.new('message', name=funcls.output_message_name()) msg.new('part', name='parameters', element="myxsd:" + funcls.response_element_name()) # PortType operation op = wsdl_porttype_root.new('operation', name=funcls.soap_name()) op.new('input', message="self:" + funcls.input_message_name()) op.new('output', message="self:" + funcls.output_message_name()) op.new('fault', message="self:msgFaultDetail", name="soapFaultDetail") # SOAP operation soapaction = self.server.get_server_url( ) + "SOAP" + "/" + funcls.soap_name() _soapns = self.server.get_server_url() + "WSDL" + mssuffix op2 = wsdl_binding_root.new('operation', name=funcls.soap_name()) op2.new('soap:operation', soapAction=soapaction) op2.new('input').new('soap:body', use='literal') op2.new('output').new('soap:body', use='literal') op2.new('fault', name="soapFaultDetail").new('soap:fault', use='literal', name="soapFaultDetail") # Added here to come after all <message>:s wsdl_root.add(wsdl_porttype_root) wsdl_root.add(wsdl_binding_root) wsdl_root.add(wsdl_service_root) return wsdl_root.xml()
print ExtPersonData().xsd().xml() try: pd = ExtPersonData().parse( 0, dict(person=u"viktor", friends=[u"mort", u"niklas"], name=u"Viktor Fougstedt")) except ExtRegexpMismatchError: pass pd = ExtPersonData().parse( 0, dict(person=u"person-viktor", friends=[u"person-mort", u"person-niklas"], name=u"Viktor Fougstedt")) print pd resp = XMLNode("response") ExtPersonData().to_xml(resp, ExtPersonData().output(0, pd)) soap = resp.xml() print soap import xml.dom.minidom dom = xml.dom.minidom.parseString(soap) tmp = ExtPersonData().from_xml(dom.documentElement) print tmp print ExtPersonData().parse(0, tmp)
def get_wsdl(self, path): """If incoming path matches .get_wsdl_url(True), output a WSDL which is bug-compatible with the Microsoft svcutil toolchain, accomplished by renaming all input parameters to <name> + '_in'. The WSDL/SOAP URI:s reflect the compatability mode (/SOAP_mscompat rather than /SOAP for example). """ #self.types = {} #self.generate_soap_fundefs() # Start by creating the base elements for the respective # components. That way we can add specific subelements as we # go. if path == self.get_wsdl_path(True): mssuffix = "_mscompat" mscompat = True elif path == self.get_wsdl_path(False): mssuffix = "" mscompat = False else: self.logger.error("VOLVO") raise ExtInternalError() wsdl_ns = self.get_wsdl_url(mscompat) schema_ns = self.get_schema_url(mscompat) defattrs = { 'xmlns:self': wsdl_ns, 'xmlns:myxsd': schema_ns, 'xmlns:soap': "http://schemas.xmlsoap.org/wsdl/soap/", 'xmlns': "http://schemas.xmlsoap.org/wsdl/", } name_attr = self.server.service_name if self.version > 0: name_attr += "-" + self.get_version_string(with_dashes=False) wsdl_root = XMLNode('definitions', name=name_attr, targetNamespace=wsdl_ns, _other_attributes=defattrs, _space_children=True) t = wsdl_root.new('types') wsdl_schema_root = t.new('schema', targetNamespace=schema_ns, xmlns="http://www.w3.org/2001/XMLSchema", elementFormDefault="qualified", _space_children=True) # Note that the dashes in the version will be removed by # capsification later p = self.server.service_name p += self.get_version_string(with_dashes=True) p += mssuffix ptname = ExtType.capsify(p + '-port-type') srvname = ExtType.capsify(p + 'service') bndname = ExtType.capsify(p + '-soap-binding') # PortType, Binding and Service are added to the WSDL XML element # last, since the <message> elements should come before them, but # we want to generate the contents of these three nodes at the # same time as the <message> elements. wsdl_porttype_root = XMLNode('portType', name=ptname, _space_children=True) wsdl_binding_root = XMLNode('binding', name=bndname, type="self:" + ptname, _space_children=True) wsdl_binding_root.new('soap:binding', style='document', transport="http://schemas.xmlsoap.org/soap/http") wsdl_service_root = XMLNode('service', name=srvname) prt = wsdl_service_root.new('port', name=srvname + 'Port', binding="self:" + bndname) prt.new('soap:address', location=self.server.get_server_url() + 'SOAP') # TODO ### #faultdef = RPCSOAPTypeDefFactory(self).typedef(SOAPFaultDetailType()._docdict()) #faultmsg = wsdl_root.new("message", name="msgFaultDetail") #faultmsg.new("part", name="fault", element="myxsd:soapFaultDetail") def add_type(schemaelem, already_added, typething): typ = ExtType.instance(typething) if typ._name() in already_added: return already_added.add(typ._name()) schemaelem.add(typ.xsd()) for (_key, subtyp) in typ._subtypes(): add_type(schemaelem, already_added, subtyp) added_types = set() for funcls in self.get_visible_functions(): wsdl_schema_root.add(funcls.xsd_request(mscompat)) wsdl_schema_root.add(funcls.xsd_response()) for (_name, typ, _desc) in funcls.get_parameters(): add_type(wsdl_schema_root, added_types, typ) (typ, _desc) = funcls._returns() add_type(wsdl_schema_root, added_types, typ) # Doc/lit-wrap input message msg = wsdl_root.new('message', name=funcls.input_message_name()) msg.new('part', name='parameters', element="myxsd:" + funcls.request_element_name()) # Doc/lit-wrap output message msg = wsdl_root.new('message', name=funcls.output_message_name()) msg.new('part', name='parameters', element="myxsd:" + funcls.response_element_name()) # PortType operation op = wsdl_porttype_root.new('operation', name=funcls.soap_name()) op.new('input', message="self:" + funcls.input_message_name()) op.new('output', message="self:" + funcls.output_message_name()) op.new('fault', message="self:msgFaultDetail", name="soapFaultDetail") # SOAP operation soapaction = self.server.get_server_url() + "SOAP" + "/" + funcls.soap_name() _soapns = self.server.get_server_url() + "WSDL" + mssuffix op2 = wsdl_binding_root.new('operation', name=funcls.soap_name()) op2.new('soap:operation', soapAction=soapaction) op2.new('input').new('soap:body', use='literal') op2.new('output').new('soap:body', use='literal') op2.new('fault', name="soapFaultDetail").new('soap:fault', use='literal', name="soapFaultDetail") # Added here to come after all <message>:s wsdl_root.add(wsdl_porttype_root) wsdl_root.add(wsdl_binding_root) wsdl_root.add(wsdl_service_root) return wsdl_root.xml()