def build_interface_document(self, url): """Build the wsdl for the application.""" self.build_schema_nodes() self.url = REGEX_WSDL.sub('', url) service_name = self.interface.get_name() # create wsdl root node self.root_elt = root = etree.Element(WSDL11("definitions"), nsmap=self.interface.nsmap) root.set('targetNamespace', self.interface.tns) root.set('name', service_name) # create types node types = SubElement(root, WSDL11("types")) for s in self.schema_dict.values(): types.append(s) messages = set() for s in self.interface.services: self.add_messages_for_methods(s, root, messages) if self._with_plink: plink = SubElement(root, PLINK("partnerLinkType")) plink.set('name', service_name) self.__add_partner_link(service_name, plink) # create service nodes in advance. they're to be filled in subsequent # add_port_type calls. for s in self.interface.services: if not s.is_auxiliary(): self._get_or_create_service_node( self._get_applied_service_name(s)) # create portType nodes for s in self.interface.services: if not s.is_auxiliary(): self.add_port_type(s, root, service_name, types, self.url) cb_binding = None for s in self.interface.services: if not s.is_auxiliary(): cb_binding = self.add_bindings_for_methods( s, root, service_name, cb_binding) if self.interface.app.transport is None: raise Exception("You must set the 'transport' property of the " "parent 'Application' instance") self.event_manager.fire_event('document_built', self) self.event_manager.fire_event('wsdl_document_built', self) self.__wsdl = etree.tostring(root, xml_declaration=True, encoding="UTF-8")
def __add_partner_link(self, service_name, plink): """Add the partnerLinkType node to the wsdl.""" ns_tns = self.interface.tns pref_tns = self.interface.get_namespace_prefix(ns_tns) role = SubElement(plink, PLINK("role")) role.set('name', service_name) plink_port_type = SubElement(role, PLINK("portType")) plink_port_type.set('name', '%s:%s' % (pref_tns, service_name)) if self._has_callbacks(): role = SubElement(plink, PLINK("role")) role.set('name', '%sCallback' % service_name) plink_port_type = SubElement(role, PLINK("portType")) plink_port_type.set('name', '%s:%sCallback' % (pref_tns, service_name))
def build_interface_document(self, url): """Build the wsdl for the application.""" self.build_schema_nodes() self.url = REGEX_WSDL.sub('', url) service_name = self.interface.get_name() # create wsdl root node self.root_elt = root = etree.Element(WSDL11("definitions"), nsmap=self.interface.nsmap) if self.xsl_href is not None: # example: # <?xml-stylesheet type="text/xsl" href="wsdl-viewer.xsl"?>" # pi.attrib.__setitem__ is ignored, so we get a proper list of # attributes to pass with the following hack. pitext = etree.tostring(etree.Element("dummy", dict(type='text/xsl', href=self.xsl_href)), encoding='unicode') \ .split(" ", 1)[-1][:-2] pi = etree.ProcessingInstruction("xml-stylesheet", pitext) self.root_elt.addprevious(pi) self.root_tree = root.getroottree() root.set('targetNamespace', self.interface.tns) root.set('name', service_name) # create types node types = SubElement(root, WSDL11("types")) for s in self.schema_dict.values(): types.append(s) messages = set() for s in self.interface.services: self.add_messages_for_methods(s, root, messages) if self._with_plink: plink = SubElement(root, PLINK("partnerLinkType")) plink.set('name', service_name) self.__add_partner_link(service_name, plink) # create service nodes in advance. they're to be filled in subsequent # add_port_type calls. for s in self.interface.services: if not s.is_auxiliary(): self._get_or_create_service_node( self._get_applied_service_name(s)) # create portType nodes for s in self.interface.services: if not s.is_auxiliary(): self.add_port_type(s, root, service_name, types, self.url) cb_binding = None for s in self.interface.services: if not s.is_auxiliary(): cb_binding = self.add_bindings_for_methods( s, root, service_name, cb_binding) if self.interface.app.transport is None: raise Exception("You must set the 'transport' property of the " "parent 'Application' instance") self.event_manager.fire_event('document_built', self) self.event_manager.fire_event('wsdl_document_built', self) self.__wsdl = etree.tostring(self.root_tree, xml_declaration=True, encoding="UTF-8")