home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / ZSI / wstools / WSDLTools.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  50.8 KB  |  1,697 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. ident = '$Id: WSDLTools.py 1122 2006-02-04 01:24:50Z boverhof $'
  5. import weakref
  6. from cStringIO import StringIO
  7. from Namespaces import OASIS, XMLNS, WSA, WSA_LIST, WSRF_V1_2, WSRF
  8. from Utility import Collection, CollectionNS, DOM, ElementProxy, basejoin
  9. from XMLSchema import XMLSchema, SchemaReader, WSDLToolsAdapter
  10.  
  11. class WSDLReader:
  12.     
  13.     def loadFromStream(self, stream, name = None):
  14.         document = DOM.loadDocument(stream)
  15.         wsdl = WSDL()
  16.         if name:
  17.             wsdl.location = name
  18.         elif hasattr(stream, 'name'):
  19.             wsdl.location = stream.name
  20.         
  21.         wsdl.load(document)
  22.         return wsdl
  23.  
  24.     
  25.     def loadFromURL(self, url):
  26.         document = DOM.loadFromURL(url)
  27.         wsdl = WSDL()
  28.         wsdl.location = url
  29.         wsdl.load(document)
  30.         return wsdl
  31.  
  32.     
  33.     def loadFromString(self, data):
  34.         return self.loadFromStream(StringIO(data))
  35.  
  36.     
  37.     def loadFromFile(self, filename):
  38.         file = open(filename, 'rb')
  39.         
  40.         try:
  41.             wsdl = self.loadFromStream(file)
  42.         finally:
  43.             file.close()
  44.  
  45.         return wsdl
  46.  
  47.  
  48.  
  49. class WSDL:
  50.     
  51.     def __init__(self, targetNamespace = None, strict = 1):
  52.         if not targetNamespace:
  53.             pass
  54.         self.targetNamespace = 'urn:this-document.wsdl'
  55.         self.documentation = ''
  56.         self.location = None
  57.         self.document = None
  58.         self.name = None
  59.         self.services = CollectionNS(self)
  60.         self.messages = CollectionNS(self)
  61.         self.portTypes = CollectionNS(self)
  62.         self.bindings = CollectionNS(self)
  63.         self.imports = Collection(self)
  64.         self.types = Types(self)
  65.         self.extensions = []
  66.         self.strict = strict
  67.  
  68.     
  69.     def __del__(self):
  70.         if self.document is not None:
  71.             self.document.unlink()
  72.         
  73.  
  74.     version = '1.1'
  75.     
  76.     def addService(self, name, documentation = '', targetNamespace = None):
  77.         if self.services.has_key(name):
  78.             raise WSDLError('Duplicate service element: %s' % name)
  79.         self.services.has_key(name)
  80.         item = Service(name, documentation)
  81.         if targetNamespace:
  82.             item.targetNamespace = targetNamespace
  83.         
  84.         self.services[name] = item
  85.         return item
  86.  
  87.     
  88.     def addMessage(self, name, documentation = '', targetNamespace = None):
  89.         if self.messages.has_key(name):
  90.             raise WSDLError('Duplicate message element: %s.' % name)
  91.         self.messages.has_key(name)
  92.         item = Message(name, documentation)
  93.         if targetNamespace:
  94.             item.targetNamespace = targetNamespace
  95.         
  96.         self.messages[name] = item
  97.         return item
  98.  
  99.     
  100.     def addPortType(self, name, documentation = '', targetNamespace = None):
  101.         if self.portTypes.has_key(name):
  102.             raise WSDLError('Duplicate portType element: name')
  103.         self.portTypes.has_key(name)
  104.         item = PortType(name, documentation)
  105.         if targetNamespace:
  106.             item.targetNamespace = targetNamespace
  107.         
  108.         self.portTypes[name] = item
  109.         return item
  110.  
  111.     
  112.     def addBinding(self, name, type, documentation = '', targetNamespace = None):
  113.         if self.bindings.has_key(name):
  114.             raise WSDLError('Duplicate binding element: %s' % name)
  115.         self.bindings.has_key(name)
  116.         item = Binding(name, type, documentation)
  117.         if targetNamespace:
  118.             item.targetNamespace = targetNamespace
  119.         
  120.         self.bindings[name] = item
  121.         return item
  122.  
  123.     
  124.     def addImport(self, namespace, location):
  125.         item = ImportElement(namespace, location)
  126.         self.imports[namespace] = item
  127.         return item
  128.  
  129.     
  130.     def toDom(self):
  131.         namespaceURI = DOM.GetWSDLUri(self.version)
  132.         self.document = DOM.createDocument(namespaceURI, 'wsdl:definitions')
  133.         child = DOM.getElement(self.document, None)
  134.         child.setAttributeNS(None, 'targetNamespace', self.targetNamespace)
  135.         child.setAttributeNS(XMLNS.BASE, 'xmlns:wsdl', namespaceURI)
  136.         child.setAttributeNS(XMLNS.BASE, 'xmlns:xsd', 'http://www.w3.org/1999/XMLSchema')
  137.         child.setAttributeNS(XMLNS.BASE, 'xmlns:soap', 'http://schemas.xmlsoap.org/wsdl/soap/')
  138.         child.setAttributeNS(XMLNS.BASE, 'xmlns:soap12', 'http://schemas.xmlsoap.org/wsdl/soap12/')
  139.         child.setAttributeNS(XMLNS.BASE, 'xmlns:tns', self.targetNamespace)
  140.         if self.name:
  141.             child.setAttributeNS(None, 'name', self.name)
  142.         
  143.         for item in self.imports:
  144.             item.toDom()
  145.         
  146.         for item in self.messages:
  147.             item.toDom()
  148.         
  149.         for item in self.portTypes:
  150.             item.toDom()
  151.         
  152.         for item in self.bindings:
  153.             item.toDom()
  154.         
  155.         for item in self.services:
  156.             item.toDom()
  157.         
  158.  
  159.     
  160.     def load(self, document):
  161.         self.document = document
  162.         definitions = DOM.getElement(document, 'definitions', None, None)
  163.         if definitions is None:
  164.             raise WSDLError('Missing <definitions> element.')
  165.         definitions is None
  166.         self.version = DOM.WSDLUriToVersion(definitions.namespaceURI)
  167.         NS_WSDL = DOM.GetWSDLUri(self.version)
  168.         self.targetNamespace = DOM.getAttr(definitions, 'targetNamespace', None, None)
  169.         self.name = DOM.getAttr(definitions, 'name', None, None)
  170.         self.documentation = GetDocumentation(definitions)
  171.         imported = []
  172.         base_location = self.location
  173.         do_it = True
  174.         while do_it:
  175.             do_it = False
  176.             for element in DOM.getElements(definitions, 'import', NS_WSDL):
  177.                 location = DOM.getAttr(element, 'location')
  178.                 if base_location is not None:
  179.                     location = basejoin(base_location, location)
  180.                 
  181.                 if location not in imported:
  182.                     do_it = True
  183.                     self._import(document, element, base_location)
  184.                     imported.append(location)
  185.                     continue
  186.                 definitions.removeChild(element)
  187.             
  188.             base_location = None
  189.         for element in DOM.getElements(definitions, None, None):
  190.             targetNamespace = DOM.getAttr(element, 'targetNamespace')
  191.             localName = element.localName
  192.             if not DOM.nsUriMatch(element.namespaceURI, NS_WSDL):
  193.                 if localName == 'schema':
  194.                     tns = DOM.getAttr(element, 'targetNamespace')
  195.                     reader = SchemaReader(base_url = self.imports[tns].location)
  196.                     schema = reader.loadFromNode(WSDLToolsAdapter(self), element)
  197.                     self.types.addSchema(schema)
  198.                     continue
  199.                 self.extensions.append(element)
  200.                 continue
  201.                 continue
  202.             if localName == 'message':
  203.                 name = DOM.getAttr(element, 'name')
  204.                 docs = GetDocumentation(element)
  205.                 message = self.addMessage(name, docs, targetNamespace)
  206.                 parts = DOM.getElements(element, 'part', NS_WSDL)
  207.                 message.load(parts)
  208.                 continue
  209.                 continue
  210.             if localName == 'portType':
  211.                 name = DOM.getAttr(element, 'name')
  212.                 docs = GetDocumentation(element)
  213.                 ptype = self.addPortType(name, docs, targetNamespace)
  214.                 ptype.load(element)
  215.                 continue
  216.                 continue
  217.             if localName == 'binding':
  218.                 name = DOM.getAttr(element, 'name')
  219.                 type = DOM.getAttr(element, 'type', default = None)
  220.                 if type is None:
  221.                     raise WSDLError('Missing type attribute for binding %s.' % name)
  222.                 type is None
  223.                 type = ParseQName(type, element)
  224.                 docs = GetDocumentation(element)
  225.                 binding = self.addBinding(name, type, docs, targetNamespace)
  226.                 operations = DOM.getElements(element, 'operation', NS_WSDL)
  227.                 binding.load(operations)
  228.                 binding.load_ex(GetExtensions(element))
  229.                 continue
  230.                 continue
  231.             if localName == 'service':
  232.                 name = DOM.getAttr(element, 'name')
  233.                 docs = GetDocumentation(element)
  234.                 service = self.addService(name, docs, targetNamespace)
  235.                 ports = DOM.getElements(element, 'port', NS_WSDL)
  236.                 service.load(ports)
  237.                 service.load_ex(GetExtensions(element))
  238.                 continue
  239.                 continue
  240.             if localName == 'types':
  241.                 self.types.documentation = GetDocumentation(element)
  242.                 base_location = DOM.getAttr(element, 'base-location')
  243.                 if base_location:
  244.                     element.removeAttribute('base-location')
  245.                 
  246.                 if not base_location:
  247.                     pass
  248.                 base_location = self.location
  249.                 reader = SchemaReader(base_url = base_location)
  250.                 for item in DOM.getElements(element, None, None):
  251.                     if item.localName == 'schema':
  252.                         schema = reader.loadFromNode(WSDLToolsAdapter(self), item)
  253.                         schema.setBaseUrl(base_location)
  254.                         self.types.addSchema(schema)
  255.                         continue
  256.                     self.types.addExtension(item)
  257.                 
  258.                 continue
  259.                 continue
  260.         
  261.  
  262.     
  263.     def _import(self, document, element, base_location = None):
  264.         namespace = DOM.getAttr(element, 'namespace', default = None)
  265.         location = DOM.getAttr(element, 'location', default = None)
  266.         if namespace is None or location is None:
  267.             raise WSDLError('Invalid import element (missing namespace or location).')
  268.         location is None
  269.         if base_location:
  270.             location = basejoin(base_location, location)
  271.             element.setAttributeNS(None, 'location', location)
  272.         
  273.         obimport = self.addImport(namespace, location)
  274.         obimport._loaded = 1
  275.         importdoc = DOM.loadFromURL(location)
  276.         
  277.         try:
  278.             if location.find('#') > -1:
  279.                 idref = location.split('#')[-1]
  280.                 imported = DOM.getElementById(importdoc, idref)
  281.             else:
  282.                 imported = importdoc.documentElement
  283.             if imported is None:
  284.                 raise WSDLError('Import target element not found for: %s' % location)
  285.             imported is None
  286.             imported_tns = DOM.findTargetNS(imported)
  287.             if imported_tns != namespace:
  288.                 return None
  289.             if imported.localName == 'definitions':
  290.                 imported_nodes = imported.childNodes
  291.             else:
  292.                 imported_nodes = [
  293.                     imported]
  294.             parent = element.parentNode
  295.             parent.removeChild(element)
  296.             for node in imported_nodes:
  297.                 if node.nodeType != node.ELEMENT_NODE:
  298.                     continue
  299.                 
  300.                 child = DOM.importNode(document, node, 1)
  301.                 parent.appendChild(child)
  302.                 child.setAttribute('targetNamespace', namespace)
  303.                 attrsNS = imported._attrsNS
  304.                 for attrkey in attrsNS.keys():
  305.                     if attrkey[0] == DOM.NS_XMLNS:
  306.                         attr = attrsNS[attrkey].cloneNode(1)
  307.                         child.setAttributeNode(attr)
  308.                         continue
  309.                 
  310.                 if child.localName == 'import':
  311.                     rlocation = child.getAttributeNS(None, 'location')
  312.                     alocation = basejoin(location, rlocation)
  313.                     child.setAttribute('location', alocation)
  314.                     continue
  315.                 if child.localName == 'types':
  316.                     child.setAttribute('base-location', location)
  317.                     continue
  318.         finally:
  319.             importdoc.unlink()
  320.  
  321.         return location
  322.  
  323.  
  324.  
  325. class Element:
  326.     
  327.     def __init__(self, name = None, documentation = ''):
  328.         self.name = name
  329.         self.documentation = documentation
  330.         self.extensions = []
  331.  
  332.     
  333.     def addExtension(self, item):
  334.         item.parent = weakref.ref(self)
  335.         self.extensions.append(item)
  336.  
  337.     
  338.     def getWSDL(self):
  339.         parent = self
  340.         while isinstance(parent, WSDL):
  341.             return parent
  342.             
  343.             try:
  344.                 parent = parent.parent()
  345.             continue
  346.             break
  347.             continue
  348.  
  349.             continue
  350.             return None
  351.  
  352.  
  353.  
  354. class ImportElement(Element):
  355.     
  356.     def __init__(self, namespace, location):
  357.         self.namespace = namespace
  358.         self.location = location
  359.  
  360.     
  361.     def toDom(self):
  362.         wsdl = self.getWSDL()
  363.         ep = ElementProxy(None, DOM.getElement(wsdl.document, None))
  364.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'import')
  365.         epc.setAttributeNS(None, 'namespace', self.namespace)
  366.         epc.setAttributeNS(None, 'location', self.location)
  367.  
  368.     _loaded = None
  369.  
  370.  
  371. class Types(Collection):
  372.     
  373.     default = lambda self, k: k.targetNamespace
  374.     
  375.     def __init__(self, parent):
  376.         Collection.__init__(self, parent)
  377.         self.documentation = ''
  378.         self.extensions = []
  379.  
  380.     
  381.     def addSchema(self, schema):
  382.         name = schema.targetNamespace
  383.         self[name] = schema
  384.         return schema
  385.  
  386.     
  387.     def addExtension(self, item):
  388.         self.extensions.append(item)
  389.  
  390.  
  391.  
  392. class Message(Element):
  393.     
  394.     def __init__(self, name, documentation = ''):
  395.         Element.__init__(self, name, documentation)
  396.         self.parts = Collection(self)
  397.  
  398.     
  399.     def addPart(self, name, type = None, element = None):
  400.         if self.parts.has_key(name):
  401.             raise WSDLError('Duplicate message part element: %s' % name)
  402.         self.parts.has_key(name)
  403.         if type is None and element is None:
  404.             raise WSDLError('Missing type or element attribute for part: %s' % name)
  405.         element is None
  406.         item = MessagePart(name)
  407.         item.element = element
  408.         item.type = type
  409.         self.parts[name] = item
  410.         return item
  411.  
  412.     
  413.     def load(self, elements):
  414.         for element in elements:
  415.             name = DOM.getAttr(element, 'name')
  416.             part = MessagePart(name)
  417.             self.parts[name] = part
  418.             elemref = DOM.getAttr(element, 'element', default = None)
  419.             typeref = DOM.getAttr(element, 'type', default = None)
  420.             if typeref is None and elemref is None:
  421.                 raise WSDLError('No type or element attribute for part: %s' % name)
  422.             elemref is None
  423.             if typeref is not None:
  424.                 part.type = ParseTypeRef(typeref, element)
  425.             
  426.             if elemref is not None:
  427.                 part.element = ParseTypeRef(elemref, element)
  428.                 continue
  429.         
  430.  
  431.     
  432.     def toDom(self):
  433.         wsdl = self.getWSDL()
  434.         ep = ElementProxy(None, DOM.getElement(wsdl.document, None))
  435.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'message')
  436.         epc.setAttributeNS(None, 'name', self.name)
  437.         for part in self.parts:
  438.             part.toDom(epc._getNode())
  439.         
  440.  
  441.  
  442.  
  443. class MessagePart(Element):
  444.     
  445.     def __init__(self, name):
  446.         Element.__init__(self, name, '')
  447.         self.element = None
  448.         self.type = None
  449.  
  450.     
  451.     def getTypeDefinition(self):
  452.         wsdl = self.getWSDL()
  453.         (nsuri, name) = self.type
  454.         schema = wsdl.types.get(nsuri, { })
  455.         return schema.get(name)
  456.  
  457.     
  458.     def getElementDeclaration(self):
  459.         wsdl = self.getWSDL()
  460.         (nsuri, name) = self.element
  461.         schema = wsdl.types.get(nsuri, { })
  462.         return schema.get(name)
  463.  
  464.     
  465.     def toDom(self, node):
  466.         wsdl = self.getWSDL()
  467.         ep = ElementProxy(None, node)
  468.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'part')
  469.         epc.setAttributeNS(None, 'name', self.name)
  470.         if self.element is not None:
  471.             (ns, name) = self.element
  472.             prefix = epc.getPrefix(ns)
  473.             epc.setAttributeNS(None, 'element', '%s:%s' % (prefix, name))
  474.         elif self.type is not None:
  475.             (ns, name) = self.type
  476.             prefix = epc.getPrefix(ns)
  477.             epc.setAttributeNS(None, 'type', '%s:%s' % (prefix, name))
  478.         
  479.  
  480.  
  481.  
  482. class PortType(Element):
  483.     
  484.     def __init__(self, name, documentation = ''):
  485.         Element.__init__(self, name, documentation)
  486.         self.operations = Collection(self)
  487.         self.resourceProperties = None
  488.  
  489.     
  490.     def getTargetNamespace(self):
  491.         if not self.targetNamespace:
  492.             pass
  493.         return self.getWSDL().targetNamespace
  494.  
  495.     
  496.     def getResourceProperties(self):
  497.         return self.resourceProperties
  498.  
  499.     
  500.     def addOperation(self, name, documentation = '', parameterOrder = None):
  501.         item = Operation(name, documentation, parameterOrder)
  502.         self.operations[name] = item
  503.         return item
  504.  
  505.     
  506.     def load(self, element):
  507.         self.name = DOM.getAttr(element, 'name')
  508.         self.documentation = GetDocumentation(element)
  509.         self.targetNamespace = DOM.getAttr(element, 'targetNamespace')
  510.         for nsuri in WSRF_V1_2.PROPERTIES.XSD_LIST:
  511.             if DOM.hasAttr(element, 'ResourceProperties', nsuri):
  512.                 rpref = DOM.getAttr(element, 'ResourceProperties', nsuri)
  513.                 self.resourceProperties = ParseQName(rpref, element)
  514.                 continue
  515.         
  516.         NS_WSDL = DOM.GetWSDLUri(self.getWSDL().version)
  517.         elements = DOM.getElements(element, 'operation', NS_WSDL)
  518.         for element in elements:
  519.             name = DOM.getAttr(element, 'name')
  520.             docs = GetDocumentation(element)
  521.             param_order = DOM.getAttr(element, 'parameterOrder', default = None)
  522.             if param_order is not None:
  523.                 param_order = param_order.split(' ')
  524.             
  525.             operation = self.addOperation(name, docs, param_order)
  526.             item = DOM.getElement(element, 'input', None, None)
  527.             if item is not None:
  528.                 name = DOM.getAttr(item, 'name')
  529.                 docs = GetDocumentation(item)
  530.                 msgref = DOM.getAttr(item, 'message')
  531.                 message = ParseQName(msgref, item)
  532.                 for WSA in WSA_LIST:
  533.                     action = DOM.getAttr(item, 'Action', WSA.ADDRESS, None)
  534.                     if action:
  535.                         break
  536.                         continue
  537.                 
  538.                 operation.setInput(message, name, docs, action)
  539.             
  540.             item = DOM.getElement(element, 'output', None, None)
  541.             if item is not None:
  542.                 name = DOM.getAttr(item, 'name')
  543.                 docs = GetDocumentation(item)
  544.                 msgref = DOM.getAttr(item, 'message')
  545.                 message = ParseQName(msgref, item)
  546.                 for WSA in WSA_LIST:
  547.                     action = DOM.getAttr(item, 'Action', WSA.ADDRESS, None)
  548.                     if action:
  549.                         break
  550.                         continue
  551.                 
  552.                 operation.setOutput(message, name, docs, action)
  553.             
  554.             for item in DOM.getElements(element, 'fault', None):
  555.                 name = DOM.getAttr(item, 'name')
  556.                 docs = GetDocumentation(item)
  557.                 msgref = DOM.getAttr(item, 'message')
  558.                 message = ParseQName(msgref, item)
  559.                 for WSA in WSA_LIST:
  560.                     action = DOM.getAttr(item, 'Action', WSA.ADDRESS, None)
  561.                     if action:
  562.                         break
  563.                         continue
  564.                 
  565.                 operation.addFault(message, name, docs, action)
  566.             
  567.         
  568.  
  569.     
  570.     def toDom(self):
  571.         wsdl = self.getWSDL()
  572.         ep = ElementProxy(None, DOM.getElement(wsdl.document, None))
  573.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'portType')
  574.         epc.setAttributeNS(None, 'name', self.name)
  575.         if self.resourceProperties:
  576.             (ns, name) = self.resourceProperties
  577.             prefix = epc.getPrefix(ns)
  578.             epc.setAttributeNS(WSRF.PROPERTIES.LATEST, 'ResourceProperties', '%s:%s' % (prefix, name))
  579.         
  580.         for op in self.operations:
  581.             op.toDom(epc._getNode())
  582.         
  583.  
  584.  
  585.  
  586. class Operation(Element):
  587.     
  588.     def __init__(self, name, documentation = '', parameterOrder = None):
  589.         Element.__init__(self, name, documentation)
  590.         self.parameterOrder = parameterOrder
  591.         self.faults = Collection(self)
  592.         self.input = None
  593.         self.output = None
  594.  
  595.     
  596.     def getWSDL(self):
  597.         return self.parent().parent().parent().parent()
  598.  
  599.     
  600.     def getPortType(self):
  601.         return self.parent().parent()
  602.  
  603.     
  604.     def getInputAction(self):
  605.         return GetWSAActionInput(self)
  606.  
  607.     
  608.     def getInputMessage(self):
  609.         if self.input is None:
  610.             return None
  611.         wsdl = self.getPortType().getWSDL()
  612.         return wsdl.messages[self.input.message]
  613.  
  614.     
  615.     def getOutputAction(self):
  616.         return GetWSAActionOutput(self)
  617.  
  618.     
  619.     def getOutputMessage(self):
  620.         if self.output is None:
  621.             return None
  622.         wsdl = self.getPortType().getWSDL()
  623.         return wsdl.messages[self.output.message]
  624.  
  625.     
  626.     def getFaultAction(self, name):
  627.         return GetWSAActionFault(self, name)
  628.  
  629.     
  630.     def getFaultMessage(self, name):
  631.         wsdl = self.getPortType().getWSDL()
  632.         return wsdl.messages[self.faults[name].message]
  633.  
  634.     
  635.     def addFault(self, message, name, documentation = '', action = None):
  636.         if self.faults.has_key(name):
  637.             raise WSDLError('Duplicate fault element: %s' % name)
  638.         self.faults.has_key(name)
  639.         item = MessageRole('fault', message, name, documentation, action)
  640.         self.faults[name] = item
  641.         return item
  642.  
  643.     
  644.     def setInput(self, message, name = '', documentation = '', action = None):
  645.         self.input = MessageRole('input', message, name, documentation, action)
  646.         self.input.parent = weakref.ref(self)
  647.         return self.input
  648.  
  649.     
  650.     def setOutput(self, message, name = '', documentation = '', action = None):
  651.         self.output = MessageRole('output', message, name, documentation, action)
  652.         self.output.parent = weakref.ref(self)
  653.         return self.output
  654.  
  655.     
  656.     def toDom(self, node):
  657.         wsdl = self.getWSDL()
  658.         ep = ElementProxy(None, node)
  659.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'operation')
  660.         epc.setAttributeNS(None, 'name', self.name)
  661.         node = epc._getNode()
  662.         if self.input:
  663.             self.input.toDom(node)
  664.         
  665.         if self.output:
  666.             self.output.toDom(node)
  667.         
  668.         for fault in self.faults:
  669.             fault.toDom(node)
  670.         
  671.  
  672.  
  673.  
  674. class MessageRole(Element):
  675.     
  676.     def __init__(self, type, message, name = '', documentation = '', action = None):
  677.         Element.__init__(self, name, documentation)
  678.         self.message = message
  679.         self.type = type
  680.         self.action = action
  681.  
  682.     
  683.     def getWSDL(self):
  684.         parent = self
  685.         while isinstance(parent, WSDL):
  686.             return parent
  687.             
  688.             try:
  689.                 parent = parent.parent()
  690.             continue
  691.             break
  692.             continue
  693.  
  694.             continue
  695.             return None
  696.  
  697.     
  698.     def getMessage(self):
  699.         wsdl = self.getWSDL()
  700.         return wsdl.messages[self.message]
  701.  
  702.     
  703.     def toDom(self, node):
  704.         wsdl = self.getWSDL()
  705.         ep = ElementProxy(None, node)
  706.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), self.type)
  707.         if not isinstance(self.message, basestring) and len(self.message) == 2:
  708.             (ns, name) = self.message
  709.             prefix = epc.getPrefix(ns)
  710.             epc.setAttributeNS(None, 'message', '%s:%s' % (prefix, name))
  711.         else:
  712.             epc.setAttributeNS(None, 'message', self.message)
  713.         if self.action:
  714.             epc.setAttributeNS(WSA.ADDRESS, 'Action', self.action)
  715.         
  716.         if self.name:
  717.             epc.setAttributeNS(None, 'name', self.name)
  718.         
  719.  
  720.  
  721.  
  722. class Binding(Element):
  723.     
  724.     def __init__(self, name, type, documentation = ''):
  725.         Element.__init__(self, name, documentation)
  726.         self.operations = Collection(self)
  727.         self.type = type
  728.  
  729.     
  730.     def getPortType(self):
  731.         return self.getWSDL().portTypes[self.type]
  732.  
  733.     
  734.     def findBinding(self, kind):
  735.         for item in self.extensions:
  736.             if isinstance(item, kind):
  737.                 return item
  738.         
  739.  
  740.     
  741.     def findBindings(self, kind):
  742.         return _[1]
  743.  
  744.     
  745.     def addOperationBinding(self, name, documentation = ''):
  746.         item = OperationBinding(name, documentation)
  747.         self.operations[name] = item
  748.         return item
  749.  
  750.     
  751.     def load(self, elements):
  752.         for element in elements:
  753.             name = DOM.getAttr(element, 'name')
  754.             docs = GetDocumentation(element)
  755.             opbinding = self.addOperationBinding(name, docs)
  756.             opbinding.load_ex(GetExtensions(element))
  757.             item = DOM.getElement(element, 'input', None, None)
  758.             if item is not None:
  759.                 mbinding = MessageRoleBinding('input')
  760.                 mbinding.documentation = GetDocumentation(item)
  761.                 opbinding.input = mbinding
  762.                 mbinding.load_ex(GetExtensions(item))
  763.                 mbinding.parent = weakref.ref(opbinding)
  764.             
  765.             item = DOM.getElement(element, 'output', None, None)
  766.             if item is not None:
  767.                 mbinding = MessageRoleBinding('output')
  768.                 mbinding.documentation = GetDocumentation(item)
  769.                 opbinding.output = mbinding
  770.                 mbinding.load_ex(GetExtensions(item))
  771.                 mbinding.parent = weakref.ref(opbinding)
  772.             
  773.             for item in DOM.getElements(element, 'fault', None):
  774.                 name = DOM.getAttr(item, 'name')
  775.                 mbinding = MessageRoleBinding('fault', name)
  776.                 mbinding.documentation = GetDocumentation(item)
  777.                 opbinding.faults[name] = mbinding
  778.                 mbinding.load_ex(GetExtensions(item))
  779.                 mbinding.parent = weakref.ref(opbinding)
  780.             
  781.         
  782.  
  783.     
  784.     def load_ex(self, elements):
  785.         for e in elements:
  786.             ns = e.namespaceURI
  787.             name = e.localName
  788.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'binding':
  789.                 transport = DOM.getAttr(e, 'transport', default = None)
  790.                 style = DOM.getAttr(e, 'style', default = 'document')
  791.                 ob = SoapBinding(transport, style)
  792.                 self.addExtension(ob)
  793.                 continue
  794.                 continue
  795.             if ns in DOM.NS_HTTP_BINDING_ALL and name == 'binding':
  796.                 verb = DOM.getAttr(e, 'verb')
  797.                 ob = HttpBinding(verb)
  798.                 self.addExtension(ob)
  799.                 continue
  800.                 continue
  801.             self.addExtension(e)
  802.         
  803.  
  804.     
  805.     def toDom(self):
  806.         wsdl = self.getWSDL()
  807.         ep = ElementProxy(None, DOM.getElement(wsdl.document, None))
  808.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'binding')
  809.         epc.setAttributeNS(None, 'name', self.name)
  810.         (ns, name) = self.type
  811.         prefix = epc.getPrefix(ns)
  812.         epc.setAttributeNS(None, 'type', '%s:%s' % (prefix, name))
  813.         node = epc._getNode()
  814.         for ext in self.extensions:
  815.             ext.toDom(node)
  816.         
  817.         for op_binding in self.operations:
  818.             op_binding.toDom(node)
  819.         
  820.  
  821.  
  822.  
  823. class OperationBinding(Element):
  824.     
  825.     def __init__(self, name, documentation = ''):
  826.         Element.__init__(self, name, documentation)
  827.         self.input = None
  828.         self.output = None
  829.         self.faults = Collection(self)
  830.  
  831.     
  832.     def getBinding(self):
  833.         return self.parent().parent()
  834.  
  835.     
  836.     def getOperation(self):
  837.         return self.getBinding().getPortType().operations[self.name]
  838.  
  839.     
  840.     def findBinding(self, kind):
  841.         for item in self.extensions:
  842.             if isinstance(item, kind):
  843.                 return item
  844.         
  845.  
  846.     
  847.     def findBindings(self, kind):
  848.         return _[1]
  849.  
  850.     
  851.     def addInputBinding(self, binding):
  852.         if self.input is None:
  853.             self.input = MessageRoleBinding('input')
  854.             self.input.parent = weakref.ref(self)
  855.         
  856.         self.input.addExtension(binding)
  857.         return binding
  858.  
  859.     
  860.     def addOutputBinding(self, binding):
  861.         if self.output is None:
  862.             self.output = MessageRoleBinding('output')
  863.             self.output.parent = weakref.ref(self)
  864.         
  865.         self.output.addExtension(binding)
  866.         return binding
  867.  
  868.     
  869.     def addFaultBinding(self, name, binding):
  870.         fault = self.get(name, None)
  871.         if fault is None:
  872.             fault = MessageRoleBinding('fault', name)
  873.         
  874.         fault.addExtension(binding)
  875.         return binding
  876.  
  877.     
  878.     def load_ex(self, elements):
  879.         for e in elements:
  880.             ns = e.namespaceURI
  881.             name = e.localName
  882.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'operation':
  883.                 soapaction = DOM.getAttr(e, 'soapAction', default = None)
  884.                 style = DOM.getAttr(e, 'style', default = None)
  885.                 ob = SoapOperationBinding(soapaction, style)
  886.                 self.addExtension(ob)
  887.                 continue
  888.                 continue
  889.             if ns in DOM.NS_HTTP_BINDING_ALL and name == 'operation':
  890.                 location = DOM.getAttr(e, 'location')
  891.                 ob = HttpOperationBinding(location)
  892.                 self.addExtension(ob)
  893.                 continue
  894.                 continue
  895.             self.addExtension(e)
  896.         
  897.  
  898.     
  899.     def toDom(self, node):
  900.         wsdl = self.getWSDL()
  901.         ep = ElementProxy(None, node)
  902.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'operation')
  903.         epc.setAttributeNS(None, 'name', self.name)
  904.         node = epc._getNode()
  905.         for ext in self.extensions:
  906.             ext.toDom(node)
  907.         
  908.         if self.input:
  909.             self.input.toDom(node)
  910.         
  911.         if self.output:
  912.             self.output.toDom(node)
  913.         
  914.         for fault in self.faults:
  915.             fault.toDom(node)
  916.         
  917.  
  918.  
  919.  
  920. class MessageRoleBinding(Element):
  921.     
  922.     def __init__(self, type, name = '', documentation = ''):
  923.         Element.__init__(self, name, documentation)
  924.         self.type = type
  925.  
  926.     
  927.     def findBinding(self, kind):
  928.         for item in self.extensions:
  929.             if isinstance(item, kind):
  930.                 return item
  931.         
  932.  
  933.     
  934.     def findBindings(self, kind):
  935.         return _[1]
  936.  
  937.     
  938.     def load_ex(self, elements):
  939.         for e in elements:
  940.             ns = e.namespaceURI
  941.             name = e.localName
  942.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'body':
  943.                 encstyle = DOM.getAttr(e, 'encodingStyle', default = None)
  944.                 namespace = DOM.getAttr(e, 'namespace', default = None)
  945.                 parts = DOM.getAttr(e, 'parts', default = None)
  946.                 use = DOM.getAttr(e, 'use', default = None)
  947.                 if use is None:
  948.                     raise WSDLError('Invalid soap:body binding element.')
  949.                 use is None
  950.                 ob = SoapBodyBinding(use, namespace, encstyle, parts)
  951.                 self.addExtension(ob)
  952.                 continue
  953.                 continue
  954.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'fault':
  955.                 encstyle = DOM.getAttr(e, 'encodingStyle', default = None)
  956.                 namespace = DOM.getAttr(e, 'namespace', default = None)
  957.                 name = DOM.getAttr(e, 'name', default = None)
  958.                 use = DOM.getAttr(e, 'use', default = None)
  959.                 if use is None or name is None:
  960.                     raise WSDLError('Invalid soap:fault binding element.')
  961.                 name is None
  962.                 ob = SoapFaultBinding(name, use, namespace, encstyle)
  963.                 self.addExtension(ob)
  964.                 continue
  965.                 continue
  966.             if ns in DOM.NS_SOAP_BINDING_ALL and name in ('header', 'headerfault'):
  967.                 encstyle = DOM.getAttr(e, 'encodingStyle', default = None)
  968.                 namespace = DOM.getAttr(e, 'namespace', default = None)
  969.                 message = DOM.getAttr(e, 'message')
  970.                 part = DOM.getAttr(e, 'part')
  971.                 use = DOM.getAttr(e, 'use')
  972.                 if name == 'header':
  973.                     _class = SoapHeaderBinding
  974.                 else:
  975.                     _class = SoapHeaderFaultBinding
  976.                 message = ParseQName(message, e)
  977.                 ob = _class(message, part, use, namespace, encstyle)
  978.                 self.addExtension(ob)
  979.                 continue
  980.                 continue
  981.             if ns in DOM.NS_HTTP_BINDING_ALL and name == 'urlReplacement':
  982.                 ob = HttpUrlReplacementBinding()
  983.                 self.addExtension(ob)
  984.                 continue
  985.                 continue
  986.             if ns in DOM.NS_HTTP_BINDING_ALL and name == 'urlEncoded':
  987.                 ob = HttpUrlEncodedBinding()
  988.                 self.addExtension(ob)
  989.                 continue
  990.                 continue
  991.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'multipartRelated':
  992.                 ob = MimeMultipartRelatedBinding()
  993.                 self.addExtension(ob)
  994.                 ob.load_ex(GetExtensions(e))
  995.                 continue
  996.                 continue
  997.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'content':
  998.                 part = DOM.getAttr(e, 'part', default = None)
  999.                 type = DOM.getAttr(e, 'type', default = None)
  1000.                 ob = MimeContentBinding(part, type)
  1001.                 self.addExtension(ob)
  1002.                 continue
  1003.                 continue
  1004.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'mimeXml':
  1005.                 part = DOM.getAttr(e, 'part', default = None)
  1006.                 ob = MimeXmlBinding(part)
  1007.                 self.addExtension(ob)
  1008.                 continue
  1009.                 continue
  1010.             self.addExtension(e)
  1011.         
  1012.  
  1013.     
  1014.     def toDom(self, node):
  1015.         wsdl = self.getWSDL()
  1016.         ep = ElementProxy(None, node)
  1017.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), self.type)
  1018.         node = epc._getNode()
  1019.         for item in self.extensions:
  1020.             if item:
  1021.                 item.toDom(node)
  1022.                 continue
  1023.         
  1024.  
  1025.  
  1026.  
  1027. class Service(Element):
  1028.     
  1029.     def __init__(self, name, documentation = ''):
  1030.         Element.__init__(self, name, documentation)
  1031.         self.ports = Collection(self)
  1032.  
  1033.     
  1034.     def getWSDL(self):
  1035.         return self.parent().parent()
  1036.  
  1037.     
  1038.     def addPort(self, name, binding, documentation = ''):
  1039.         item = Port(name, binding, documentation)
  1040.         self.ports[name] = item
  1041.         return item
  1042.  
  1043.     
  1044.     def load(self, elements):
  1045.         for element in elements:
  1046.             name = DOM.getAttr(element, 'name', default = None)
  1047.             docs = GetDocumentation(element)
  1048.             binding = DOM.getAttr(element, 'binding', default = None)
  1049.             if name is None or binding is None:
  1050.                 raise WSDLError('Invalid port element.')
  1051.             binding is None
  1052.             binding = ParseQName(binding, element)
  1053.             port = self.addPort(name, binding, docs)
  1054.             port.load_ex(GetExtensions(element))
  1055.         
  1056.  
  1057.     
  1058.     def load_ex(self, elements):
  1059.         for e in elements:
  1060.             self.addExtension(e)
  1061.         
  1062.  
  1063.     
  1064.     def toDom(self):
  1065.         wsdl = self.getWSDL()
  1066.         ep = ElementProxy(None, DOM.getElement(wsdl.document, None))
  1067.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'service')
  1068.         epc.setAttributeNS(None, 'name', self.name)
  1069.         node = epc._getNode()
  1070.         for port in self.ports:
  1071.             port.toDom(node)
  1072.         
  1073.  
  1074.  
  1075.  
  1076. class Port(Element):
  1077.     
  1078.     def __init__(self, name, binding, documentation = ''):
  1079.         Element.__init__(self, name, documentation)
  1080.         self.binding = binding
  1081.  
  1082.     
  1083.     def getService(self):
  1084.         return self.parent().parent()
  1085.  
  1086.     
  1087.     def getBinding(self):
  1088.         wsdl = self.getService().getWSDL()
  1089.         return wsdl.bindings[self.binding]
  1090.  
  1091.     
  1092.     def getPortType(self):
  1093.         wsdl = self.getService().getWSDL()
  1094.         binding = wsdl.bindings[self.binding]
  1095.         return wsdl.portTypes[binding.type]
  1096.  
  1097.     
  1098.     def getAddressBinding(self):
  1099.         for item in self.extensions:
  1100.             if isinstance(item, SoapAddressBinding) or isinstance(item, HttpAddressBinding):
  1101.                 return item
  1102.         
  1103.         raise WSDLError('No address binding found in port.')
  1104.  
  1105.     
  1106.     def load_ex(self, elements):
  1107.         for e in elements:
  1108.             ns = e.namespaceURI
  1109.             name = e.localName
  1110.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'address':
  1111.                 location = DOM.getAttr(e, 'location', default = None)
  1112.                 ob = SoapAddressBinding(location)
  1113.                 self.addExtension(ob)
  1114.                 continue
  1115.                 continue
  1116.             if ns in DOM.NS_HTTP_BINDING_ALL and name == 'address':
  1117.                 location = DOM.getAttr(e, 'location', default = None)
  1118.                 ob = HttpAddressBinding(location)
  1119.                 self.addExtension(ob)
  1120.                 continue
  1121.                 continue
  1122.             self.addExtension(e)
  1123.         
  1124.  
  1125.     
  1126.     def toDom(self, node):
  1127.         wsdl = self.getWSDL()
  1128.         ep = ElementProxy(None, node)
  1129.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'port')
  1130.         epc.setAttributeNS(None, 'name', self.name)
  1131.         (ns, name) = self.binding
  1132.         prefix = epc.getPrefix(ns)
  1133.         epc.setAttributeNS(None, 'binding', '%s:%s' % (prefix, name))
  1134.         node = epc._getNode()
  1135.         for ext in self.extensions:
  1136.             ext.toDom(node)
  1137.         
  1138.  
  1139.  
  1140.  
  1141. class SoapBinding:
  1142.     
  1143.     def __init__(self, transport, style = 'rpc'):
  1144.         self.transport = transport
  1145.         self.style = style
  1146.  
  1147.     
  1148.     def getWSDL(self):
  1149.         return self.parent().getWSDL()
  1150.  
  1151.     
  1152.     def toDom(self, node):
  1153.         wsdl = self.getWSDL()
  1154.         ep = ElementProxy(None, node)
  1155.         epc = ep.createAppendElement(DOM.GetWSDLSoapBindingUri(wsdl.version), 'binding')
  1156.         if self.transport:
  1157.             epc.setAttributeNS(None, 'transport', self.transport)
  1158.         
  1159.         if self.style:
  1160.             epc.setAttributeNS(None, 'style', self.style)
  1161.         
  1162.  
  1163.  
  1164.  
  1165. class SoapAddressBinding:
  1166.     
  1167.     def __init__(self, location):
  1168.         self.location = location
  1169.  
  1170.     
  1171.     def getWSDL(self):
  1172.         return self.parent().getWSDL()
  1173.  
  1174.     
  1175.     def toDom(self, node):
  1176.         wsdl = self.getWSDL()
  1177.         ep = ElementProxy(None, node)
  1178.         epc = ep.createAppendElement(DOM.GetWSDLSoapBindingUri(wsdl.version), 'address')
  1179.         epc.setAttributeNS(None, 'location', self.location)
  1180.  
  1181.  
  1182.  
  1183. class SoapOperationBinding:
  1184.     
  1185.     def __init__(self, soapAction = None, style = None):
  1186.         self.soapAction = soapAction
  1187.         self.style = style
  1188.  
  1189.     
  1190.     def getWSDL(self):
  1191.         return self.parent().getWSDL()
  1192.  
  1193.     
  1194.     def toDom(self, node):
  1195.         wsdl = self.getWSDL()
  1196.         ep = ElementProxy(None, node)
  1197.         epc = ep.createAppendElement(DOM.GetWSDLSoapBindingUri(wsdl.version), 'operation')
  1198.         if self.soapAction:
  1199.             epc.setAttributeNS(None, 'soapAction', self.soapAction)
  1200.         
  1201.         if self.style:
  1202.             epc.setAttributeNS(None, 'style', self.style)
  1203.         
  1204.  
  1205.  
  1206.  
  1207. class SoapBodyBinding:
  1208.     
  1209.     def __init__(self, use, namespace = None, encodingStyle = None, parts = None):
  1210.         if use not in ('literal', 'encoded'):
  1211.             raise WSDLError('Invalid use attribute value: %s' % use)
  1212.         use not in ('literal', 'encoded')
  1213.         self.encodingStyle = encodingStyle
  1214.         self.namespace = namespace
  1215.         if type(parts) in (type(''), type(u'')):
  1216.             parts = parts.split()
  1217.         
  1218.         self.parts = parts
  1219.         self.use = use
  1220.  
  1221.     
  1222.     def getWSDL(self):
  1223.         return self.parent().getWSDL()
  1224.  
  1225.     
  1226.     def toDom(self, node):
  1227.         wsdl = self.getWSDL()
  1228.         ep = ElementProxy(None, node)
  1229.         epc = ep.createAppendElement(DOM.GetWSDLSoapBindingUri(wsdl.version), 'body')
  1230.         epc.setAttributeNS(None, 'use', self.use)
  1231.         epc.setAttributeNS(None, 'namespace', self.namespace)
  1232.  
  1233.  
  1234.  
  1235. class SoapFaultBinding:
  1236.     
  1237.     def __init__(self, name, use, namespace = None, encodingStyle = None):
  1238.         if use not in ('literal', 'encoded'):
  1239.             raise WSDLError('Invalid use attribute value: %s' % use)
  1240.         use not in ('literal', 'encoded')
  1241.         self.encodingStyle = encodingStyle
  1242.         self.namespace = namespace
  1243.         self.name = name
  1244.         self.use = use
  1245.  
  1246.     
  1247.     def getWSDL(self):
  1248.         return self.parent().getWSDL()
  1249.  
  1250.     
  1251.     def toDom(self, node):
  1252.         wsdl = self.getWSDL()
  1253.         ep = ElementProxy(None, node)
  1254.         epc = ep.createAppendElement(DOM.GetWSDLSoapBindingUri(wsdl.version), 'body')
  1255.         epc.setAttributeNS(None, 'use', self.use)
  1256.         epc.setAttributeNS(None, 'name', self.name)
  1257.         if self.namespace is not None:
  1258.             epc.setAttributeNS(None, 'namespace', self.namespace)
  1259.         
  1260.         if self.encodingStyle is not None:
  1261.             epc.setAttributeNS(None, 'encodingStyle', self.encodingStyle)
  1262.         
  1263.  
  1264.  
  1265.  
  1266. class SoapHeaderBinding:
  1267.     
  1268.     def __init__(self, message, part, use, namespace = None, encodingStyle = None):
  1269.         if use not in ('literal', 'encoded'):
  1270.             raise WSDLError('Invalid use attribute value: %s' % use)
  1271.         use not in ('literal', 'encoded')
  1272.         self.encodingStyle = encodingStyle
  1273.         self.namespace = namespace
  1274.         self.message = message
  1275.         self.part = part
  1276.         self.use = use
  1277.  
  1278.     tagname = 'header'
  1279.  
  1280.  
  1281. class SoapHeaderFaultBinding(SoapHeaderBinding):
  1282.     tagname = 'headerfault'
  1283.  
  1284.  
  1285. class HttpBinding:
  1286.     
  1287.     def __init__(self, verb):
  1288.         self.verb = verb
  1289.  
  1290.  
  1291.  
  1292. class HttpAddressBinding:
  1293.     
  1294.     def __init__(self, location):
  1295.         self.location = location
  1296.  
  1297.  
  1298.  
  1299. class HttpOperationBinding:
  1300.     
  1301.     def __init__(self, location):
  1302.         self.location = location
  1303.  
  1304.  
  1305.  
  1306. class HttpUrlReplacementBinding:
  1307.     pass
  1308.  
  1309.  
  1310. class HttpUrlEncodedBinding:
  1311.     pass
  1312.  
  1313.  
  1314. class MimeContentBinding:
  1315.     
  1316.     def __init__(self, part = None, type = None):
  1317.         self.part = part
  1318.         self.type = type
  1319.  
  1320.  
  1321.  
  1322. class MimeXmlBinding:
  1323.     
  1324.     def __init__(self, part = None):
  1325.         self.part = part
  1326.  
  1327.  
  1328.  
  1329. class MimeMultipartRelatedBinding:
  1330.     
  1331.     def __init__(self):
  1332.         self.parts = []
  1333.  
  1334.     
  1335.     def load_ex(self, elements):
  1336.         for e in elements:
  1337.             ns = e.namespaceURI
  1338.             name = e.localName
  1339.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'part':
  1340.                 self.parts.append(MimePartBinding())
  1341.                 continue
  1342.                 continue
  1343.         
  1344.  
  1345.  
  1346.  
  1347. class MimePartBinding:
  1348.     
  1349.     def __init__(self):
  1350.         self.items = []
  1351.  
  1352.     
  1353.     def load_ex(self, elements):
  1354.         for e in elements:
  1355.             ns = e.namespaceURI
  1356.             name = e.localName
  1357.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'content':
  1358.                 part = DOM.getAttr(e, 'part', default = None)
  1359.                 type = DOM.getAttr(e, 'type', default = None)
  1360.                 ob = MimeContentBinding(part, type)
  1361.                 self.items.append(ob)
  1362.                 continue
  1363.                 continue
  1364.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'mimeXml':
  1365.                 part = DOM.getAttr(e, 'part', default = None)
  1366.                 ob = MimeXmlBinding(part)
  1367.                 self.items.append(ob)
  1368.                 continue
  1369.                 continue
  1370.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'body':
  1371.                 encstyle = DOM.getAttr(e, 'encodingStyle', default = None)
  1372.                 namespace = DOM.getAttr(e, 'namespace', default = None)
  1373.                 parts = DOM.getAttr(e, 'parts', default = None)
  1374.                 use = DOM.getAttr(e, 'use', default = None)
  1375.                 if use is None:
  1376.                     raise WSDLError('Invalid soap:body binding element.')
  1377.                 use is None
  1378.                 ob = SoapBodyBinding(use, namespace, encstyle, parts)
  1379.                 self.items.append(ob)
  1380.                 continue
  1381.                 continue
  1382.         
  1383.  
  1384.  
  1385.  
  1386. class WSDLError(Exception):
  1387.     pass
  1388.  
  1389.  
  1390. def DeclareNSPrefix(writer, prefix, nsuri):
  1391.     if writer.hasNSPrefix(nsuri):
  1392.         return None
  1393.     writer.declareNSPrefix(prefix, nsuri)
  1394.  
  1395.  
  1396. def ParseTypeRef(value, element):
  1397.     parts = value.split(':', 1)
  1398.     if len(parts) == 1:
  1399.         return (DOM.findTargetNS(element), value)
  1400.     nsuri = DOM.findNamespaceURI(parts[0], element)
  1401.     return (nsuri, parts[1])
  1402.  
  1403.  
  1404. def ParseQName(value, element):
  1405.     nameref = value.split(':', 1)
  1406.     if len(nameref) == 2:
  1407.         nsuri = DOM.findNamespaceURI(nameref[0], element)
  1408.         name = nameref[-1]
  1409.     else:
  1410.         nsuri = DOM.findTargetNS(element)
  1411.         name = nameref[-1]
  1412.     return (nsuri, name)
  1413.  
  1414.  
  1415. def GetDocumentation(element):
  1416.     docnode = DOM.getElement(element, 'documentation', None, None)
  1417.     if docnode is not None:
  1418.         return DOM.getElementText(docnode)
  1419.     return ''
  1420.  
  1421.  
  1422. def GetExtensions(element):
  1423.     return _[1]
  1424.  
  1425.  
  1426. def GetWSAActionFault(operation, name):
  1427.     attr = operation.faults[name].action
  1428.     if attr is not None:
  1429.         return attr
  1430.     return WSA.FAULT
  1431.  
  1432.  
  1433. def GetWSAActionInput(operation):
  1434.     attr = operation.input.action
  1435.     if attr is not None:
  1436.         return attr
  1437.     portType = operation.getPortType()
  1438.     targetNamespace = portType.getTargetNamespace()
  1439.     ptName = portType.name
  1440.     msgName = operation.input.name
  1441.     if not msgName:
  1442.         msgName = operation.name + 'Request'
  1443.     
  1444.     if targetNamespace.endswith('/'):
  1445.         return '%s%s/%s' % (targetNamespace, ptName, msgName)
  1446.     return '%s/%s/%s' % (targetNamespace, ptName, msgName)
  1447.  
  1448.  
  1449. def GetWSAActionOutput(operation):
  1450.     attr = operation.output.action
  1451.     if attr is not None:
  1452.         return attr
  1453.     targetNamespace = operation.getPortType().getTargetNamespace()
  1454.     ptName = operation.getPortType().name
  1455.     msgName = operation.output.name
  1456.     if not msgName:
  1457.         msgName = operation.name + 'Response'
  1458.     
  1459.     if targetNamespace.endswith('/'):
  1460.         return '%s%s/%s' % (targetNamespace, ptName, msgName)
  1461.     return '%s/%s/%s' % (targetNamespace, ptName, msgName)
  1462.  
  1463.  
  1464. def FindExtensions(object, kind, t_type = type(())):
  1465.     if isinstance(kind, t_type):
  1466.         result = []
  1467.         (namespaceURI, name) = kind
  1468.         return _[1]
  1469.     return _[2]
  1470.  
  1471.  
  1472. def FindExtension(object, kind, t_type = type(())):
  1473.     pass
  1474.  
  1475.  
  1476. class SOAPCallInfo:
  1477.     
  1478.     def __init__(self, methodName):
  1479.         self.methodName = methodName
  1480.         self.inheaders = []
  1481.         self.outheaders = []
  1482.         self.inparams = []
  1483.         self.outparams = []
  1484.         self.retval = None
  1485.  
  1486.     encodingStyle = DOM.NS_SOAP_ENC
  1487.     documentation = ''
  1488.     soapAction = None
  1489.     transport = None
  1490.     namespace = None
  1491.     location = None
  1492.     use = 'encoded'
  1493.     style = 'rpc'
  1494.     
  1495.     def addInParameter(self, name, type, namespace = None, element_type = 0):
  1496.         parameter = ParameterInfo(name, type, namespace, element_type)
  1497.         self.inparams.append(parameter)
  1498.         return parameter
  1499.  
  1500.     
  1501.     def addOutParameter(self, name, type, namespace = None, element_type = 0):
  1502.         parameter = ParameterInfo(name, type, namespace, element_type)
  1503.         self.outparams.append(parameter)
  1504.         return parameter
  1505.  
  1506.     
  1507.     def setReturnParameter(self, name, type, namespace = None, element_type = 0):
  1508.         parameter = ParameterInfo(name, type, namespace, element_type)
  1509.         self.retval = parameter
  1510.         return parameter
  1511.  
  1512.     
  1513.     def addInHeaderInfo(self, name, type, namespace, element_type = 0, mustUnderstand = 0):
  1514.         headerinfo = HeaderInfo(name, type, namespace, element_type)
  1515.         if mustUnderstand:
  1516.             headerinfo.mustUnderstand = 1
  1517.         
  1518.         self.inheaders.append(headerinfo)
  1519.         return headerinfo
  1520.  
  1521.     
  1522.     def addOutHeaderInfo(self, name, type, namespace, element_type = 0, mustUnderstand = 0):
  1523.         headerinfo = HeaderInfo(name, type, namespace, element_type)
  1524.         if mustUnderstand:
  1525.             headerinfo.mustUnderstand = 1
  1526.         
  1527.         self.outheaders.append(headerinfo)
  1528.         return headerinfo
  1529.  
  1530.     
  1531.     def getInParameters(self):
  1532.         return self.inparams
  1533.  
  1534.     
  1535.     def getOutParameters(self):
  1536.         return self.outparams
  1537.  
  1538.     
  1539.     def getReturnParameter(self):
  1540.         return self.retval
  1541.  
  1542.     
  1543.     def getInHeaders(self):
  1544.         return self.inheaders
  1545.  
  1546.     
  1547.     def getOutHeaders(self):
  1548.         return self.outheaders
  1549.  
  1550.  
  1551.  
  1552. class ParameterInfo:
  1553.     
  1554.     def __init__(self, name, type, namespace = None, element_type = 0):
  1555.         if element_type:
  1556.             self.element_type = 1
  1557.         
  1558.         if namespace is not None:
  1559.             self.namespace = namespace
  1560.         
  1561.         self.name = name
  1562.         self.type = type
  1563.  
  1564.     element_type = 0
  1565.     namespace = None
  1566.     default = None
  1567.  
  1568.  
  1569. class HeaderInfo(ParameterInfo):
  1570.     
  1571.     def __init__(self, name, type, namespace, element_type = None):
  1572.         ParameterInfo.__init__(self, name, type, namespace, element_type)
  1573.  
  1574.     mustUnderstand = 0
  1575.     actor = None
  1576.  
  1577.  
  1578. def callInfoFromWSDL(port, name):
  1579.     wsdl = port.getService().getWSDL()
  1580.     binding = port.getBinding()
  1581.     portType = binding.getPortType()
  1582.     operation = portType.operations[name]
  1583.     opbinding = binding.operations[name]
  1584.     messages = wsdl.messages
  1585.     callinfo = SOAPCallInfo(name)
  1586.     addrbinding = port.getAddressBinding()
  1587.     if not isinstance(addrbinding, SoapAddressBinding):
  1588.         raise ValueError, 'Unsupported binding type.'
  1589.     isinstance(addrbinding, SoapAddressBinding)
  1590.     callinfo.location = addrbinding.location
  1591.     soapbinding = binding.findBinding(SoapBinding)
  1592.     if soapbinding is None:
  1593.         raise ValueError, 'Missing soap:binding element.'
  1594.     soapbinding is None
  1595.     callinfo.transport = soapbinding.transport
  1596.     if not soapbinding.style:
  1597.         pass
  1598.     callinfo.style = 'document'
  1599.     soap_op_binding = opbinding.findBinding(SoapOperationBinding)
  1600.     if soap_op_binding is not None:
  1601.         callinfo.soapAction = soap_op_binding.soapAction
  1602.         if not soap_op_binding.style:
  1603.             pass
  1604.         callinfo.style = callinfo.style
  1605.     
  1606.     parameterOrder = operation.parameterOrder
  1607.     if operation.input is not None:
  1608.         message = messages[operation.input.message]
  1609.         msgrole = opbinding.input
  1610.         mime = msgrole.findBinding(MimeMultipartRelatedBinding)
  1611.         if mime is not None:
  1612.             raise ValueError, 'Mime bindings are not supported.'
  1613.         mime is not None
  1614.         for item in msgrole.findBindings(SoapHeaderBinding):
  1615.             part = messages[item.message].parts[item.part]
  1616.             if not part.element:
  1617.                 pass
  1618.             if not part.element or 1:
  1619.                 pass
  1620.             header = callinfo.addInHeaderInfo(part.name, part.type, item.namespace, element_type = 0)
  1621.             header.encodingStyle = item.encodingStyle
  1622.         
  1623.         body = msgrole.findBinding(SoapBodyBinding)
  1624.         if body is None:
  1625.             raise ValueError, 'Missing soap:body binding.'
  1626.         body is None
  1627.         callinfo.encodingStyle = body.encodingStyle
  1628.         callinfo.namespace = body.namespace
  1629.         callinfo.use = body.use
  1630.         if body.parts is not None:
  1631.             parts = []
  1632.             for name in body.parts:
  1633.                 parts.append(message.parts[name])
  1634.             
  1635.         else:
  1636.             parts = message.parts.values()
  1637.         for part in parts:
  1638.             if not part.element:
  1639.                 pass
  1640.             if not part.element or 1:
  1641.                 pass
  1642.             callinfo.addInParameter(part.name, part.type, element_type = 0)
  1643.         
  1644.     
  1645.     if operation.output is not None:
  1646.         
  1647.         try:
  1648.             message = messages[operation.output.message]
  1649.         except KeyError:
  1650.             if self.strict:
  1651.                 raise RuntimeError('Recieved message not defined in the WSDL schema: %s' % operation.output.message)
  1652.             self.strict
  1653.             message = wsdl.addMessage(operation.output.message)
  1654.             print 'Warning:', 'Recieved message not defined in the WSDL schema.', 'Adding it.'
  1655.             print 'Message:', operation.output.message
  1656.  
  1657.         msgrole = opbinding.output
  1658.         mime = msgrole.findBinding(MimeMultipartRelatedBinding)
  1659.         if mime is not None:
  1660.             raise ValueError, 'Mime bindings are not supported.'
  1661.         mime is not None
  1662.         for item in msgrole.findBindings(SoapHeaderBinding):
  1663.             part = messages[item.message].parts[item.part]
  1664.             if not part.element:
  1665.                 pass
  1666.             if not part.element or 1:
  1667.                 pass
  1668.             header = callinfo.addOutHeaderInfo(part.name, part.type, item.namespace, element_type = 0)
  1669.             header.encodingStyle = item.encodingStyle
  1670.         
  1671.         body = msgrole.findBinding(SoapBodyBinding)
  1672.         if body is None:
  1673.             raise ValueError, 'Missing soap:body binding.'
  1674.         body is None
  1675.         callinfo.encodingStyle = body.encodingStyle
  1676.         callinfo.namespace = body.namespace
  1677.         callinfo.use = body.use
  1678.         if body.parts is not None:
  1679.             parts = []
  1680.             for name in body.parts:
  1681.                 parts.append(message.parts[name])
  1682.             
  1683.         else:
  1684.             parts = message.parts.values()
  1685.         if parts:
  1686.             for part in parts:
  1687.                 if not part.element:
  1688.                     pass
  1689.                 if not part.element or 1:
  1690.                     pass
  1691.                 callinfo.addOutParameter(part.name, part.type, element_type = 0)
  1692.             
  1693.         
  1694.     
  1695.     return callinfo
  1696.  
  1697.