[XML-SIG] [PATCH] wsdllib.py
Mark Bucciarelli
mark@easymailings.com
Mon, 3 Mar 2003 13:30:45 -0500
On Monday 03 March 2003 12:35 am, Uche Ogbuji wrote:
> Is there any chance you could put together a patch to update wsdllib.py
Patch enclosed below (output of diff -u -b). Please review and comment.
Mark
--- /home/mark/downloads/wsdllib.py 2003-01-06 15:26:37.000000000 -0500
+++ wsdllib.py 2003-03-03 13:19:18.000000000 -0500
@@ -24,10 +24,28 @@
"""
import urllib, UserDict, cStringIO
-from Ft.Lib import pDomlette
-from xml import xpath
-from xml.xpath import Conversions
-from xml.dom.ext import PrettyPrint, SplitQName
+import os
+
+# Release 0.12 of 4Suite unified the domelettes and removed pDomlette
+DOMLETTE_UNIFICATION = False
+try:
+ import Ft.Xml.Domlette
+ DOMLETTE_UNIFICATION = True
+except ImportError:
+ from Ft.Lib import pDomlette
+
+if DOMLETTE_UNIFICATION:
+ from Ft.Xml import XPath
+ xpath = XPath
+ from Ft.Xml.XPath import Conversions
+ PrettyPrint = Ft.Xml.Domlette.PrettyPrint
+ from Ft.Rdf.Inference.Common import SplitQName
+ import xml.dom
+else:
+ from xml import xpath
+ from xml.xpath import Conversions
+ from xml.dom.ext import PrettyPrint, SplitQName
+
from xml.dom import Node
WSDL_NAMESPACE='http://schemas.xmlsoap.org/wsdl/'
@@ -50,9 +68,25 @@
g_faultExpression = xpath.Compile('w:fault')
g_portsExpression = xpath.Compile('w:port')
-def ReadFromStream(stream):
- """Read in a WSDL message from a steam object"""
+class WsdlException(Exception):
+ def __init__(self, msg):
+ self.msg = msg
+ def __str__(self):
+ return self.msg
+
+
+def ReadFromStream(stream, uri='file://' + os.getcwd() + os.sep + 'foo'):
+ """Read in a WSDL message from a steam object
+
+ 4Suite 0.12 requires a URI when parsing xml data, as it is required to
+ resolve XIncludes and entities. It is also required for some XSLT (for
+ example xsl:include and xsl:import) and RDF."""
+
ws = Wsdl()
+ if DOMLETTE_UNIFICATION:
+ dom = Ft.Xml.Domlette.NonvalidatingReader.parseStream(stream, uri)
+ ws.fromDom(dom)
+ else:
reader = pDomlette.PyExpatReader()
dom = reader.fromStream(stream)
ws.fromDom(dom)
@@ -68,10 +102,17 @@
def ReadFromUri(uri):
"""Read in a WSDL message from a URI"""
st = urllib.urlopen(uri)
- ws = ReadFromStream(st)
+ ws = ReadFromStream(st, uri)
st.close()
return ws
+def getAttributeNSWrapper(node, namespaceprefix, attribute):
+ """Newer stuff uses xml.dom.EMPTY_NAMESPACE (None) instead of ''."""
+
+ if not namespaceprefix and DOMLETTE_UNIFICATION:
+ return node.getAttributeNS(xml.dom.EMPTY_NAMESPACE, attribute)
+ else:
+ return node.getAttributeNS(namespaceprefix, attribute)
class Wsdl:
"""This class represents the entire WSDL definition. It can be created
from one of the above
@@ -218,13 +259,14 @@
for m in messages:
con = xpath.Context.Context(m, processorNss={'w':
WSDL_NAMESPACE})
documentation = DocumentationFromDom(con)
- msg = self.addMessage(m.getAttributeNS('','name'),documentation)
+ msg = self.addMessage(getAttributeNSWrapper(m,'','name'),
+ documentation)
parts = g_partsExpression.evaluate(con)
for p in parts:
- n = p.getAttributeNS('','name')
- element = p.getAttributeNS('','element')
- _type = p.getAttributeNS('','type')
+ n = getAttributeNSWrapper(p,'','name')
+ element = getAttributeNSWrapper(p,'','element')
+ _type = getAttributeNSWrapper(p,'','type')
msg.addPart(n,element,_type)
def toDom(self,doc):
@@ -241,7 +283,8 @@
def addPart(self,name,element='',_type=''):
"""Add a new part to a message"""
if self.parts.has_key(name):
- raise WsdlException("Message %s already has part %s exists" %
(self.name,name))
+ raise WsdlException("Message '%s' already has part '%s' exists" \
+ % (self.name,name))
p = Part(name)
p.element = element
p.type = _type
@@ -296,13 +339,13 @@
con = xpath.Context.Context(pt, processorNss={'w':
WSDL_NAMESPACE})
documentation = DocumentationFromDom(con)
- p = self.addPortType(pt.getAttributeNS('','name'),documentation)
+ p =
self.addPortType(getAttributeNSWrapper(pt,'','name'),documentation)
operations = g_operationsExpression.evaluate(con)
for op in operations:
con = xpath.Context.Context(op, processorNss={'w':
WSDL_NAMESPACE})
documentation = DocumentationFromDom(con)
- o =
p.addOperation(op.getAttributeNS('','name'),documentation)
+ o =
p.addOperation(getAttributeNSWrapper(op,'','name'),documentation)
self.__inputFromDom(con,o)
self.__outputFromDom(con,o)
self.__faultsFromDom(con,o)
@@ -322,8 +365,8 @@
input = g_inputExpression.evaluate(con)
if len(input):
input = input[0]
- msg = input.getAttributeNS('','message')
- name = input.getAttributeNS('','name')
+ msg = getAttributeNSWrapper(input,'','message')
+ name = getAttributeNSWrapper(input,'','name')
icon = xpath.Context.Context(input, processorNss={'w':
WSDL_NAMESPACE})
documentation = DocumentationFromDom(icon)
o.setInput(msg,name,documentation)
@@ -332,8 +375,8 @@
output = g_outputExpression.evaluate(con)
if len(output):
output = output[0]
- msg = output.getAttributeNS('','message')
- name = output.getAttributeNS('','name')
+ msg = getAttributeNSWrapper(output,'','message')
+ name = getAttributeNSWrapper(output,'','name')
ocon = xpath.Context.Context(output, processorNss={'w':
WSDL_NAMESPACE})
documentation = DocumentationFromDom(ocon)
o.setOutput(msg,name,documentation)
@@ -341,8 +384,8 @@
def __faultsFromDom(self,con,o):
faults = g_faultExpression.evaluate(con)
for fault in faults:
- msg = fault.getAttributeNS('','message')
- name = fault.getAttributeNS('','name')
+ msg = getAttributeNSWrapper(fault,'','message')
+ name = getAttributeNSWrapper(fault,'','name')
fcon = xpath.Context.Context(fault, processorNss={'w':
WSDL_NAMESPACE})
documentation = DocumentationFromDom(fcon)
o.addFault(name,msg,documentation)
@@ -530,7 +573,8 @@
con = xpath.Context.Context(b, processorNss={'w':
WSDL_NAMESPACE})
documentation = DocumentationFromDom(con)
- bi =
self.addBinding(b.getAttributeNS('','name'),b.getAttributeNS('','type'),documentation)
+ bi = self.addBinding(getAttributeNSWrapper(b,'','name'),
+ getAttributeNSWrapper(b,'','type'),documentation)
for child in b.childNodes:
if child.nodeType != Node.ELEMENT_NODE:
@@ -542,7 +586,8 @@
con = xpath.Context.Context(child, processorNss={'w':
WSDL_NAMESPACE})
documentation = DocumentationFromDom(con)
- o =
bi.addOperation(child.getAttributeNS('','name'),documentation)
+ o =
bi.addOperation(getAttributeNSWrapper(child,'','name'),
+ documentation)
self.__readInputFromDom(con,o)
self.__readOutputFromDom(con,o)
@@ -609,7 +654,7 @@
else:
#An extension
extensions.append(ExtensionFromDom(iChild))
- bf = op.addFault(fault.getAttributeNS('','name'),documentation)
+ bf =
op.addFault(getAttributeNSWrapper(fault,'','name'),documentation)
for e in extensions:
bf.addExtension(e)
@@ -785,12 +830,13 @@
con = xpath.Context.Context(serv, processorNss={'w':
WSDL_NAMESPACE})
documentation = DocumentationFromDom(con)
- s = self.addService(serv.getAttributeNS('','name'),documentation)
+ s =
self.addService(getAttributeNSWrapper(serv,'','name'),documentation)
for pd in g_portsExpression.evaluate(con):
pcon = xpath.Context.Context(pd, processorNss={'w':
WSDL_NAMESPACE})
documentation = DocumentationFromDom(pcon)
- p =
s.addPort(pd.getAttributeNS('','name'),pd.getAttributeNS('','binding'),documentation)
+ p = s.addPort(getAttributeNSWrapper(pd,'','name'),
+ getAttributeNSWrapper(pd,'','binding'),documentation)
for child in pd.childNodes:
if child.nodeType != Node.ELEMENT_NODE: