|
From: <bov...@us...> - 2007-06-05 04:48:41
|
Revision: 1388
http://svn.sourceforge.net/pywebsvcs/?rev=1388&view=rev
Author: boverhof
Date: 2007-06-04 21:48:41 -0700 (Mon, 04 Jun 2007)
Log Message:
-----------
M test/wsdl2py/test_EchoWSAddr200403.py
M test/wsdl2py/servers/EchoServer.py
M test/test_t4.py
M test/test_t5.py
_M ZSI
M ZSI/__init__.py
M ZSI/TC.py
M ZSI/parse.py
M ZSI/TCcompound.py
M ZSI/writer.py
M ZSI/address.py
-- fixed basic ws-addressing, pass EPR's around
Modified Paths:
--------------
branches/zsi-element-tree/ZSI/TC.py
branches/zsi-element-tree/ZSI/TCcompound.py
branches/zsi-element-tree/ZSI/__init__.py
branches/zsi-element-tree/ZSI/address.py
branches/zsi-element-tree/ZSI/parse.py
branches/zsi-element-tree/test/wsdl2py/servers/EchoServer.py
branches/zsi-element-tree/test/wsdl2py/test_EchoWSAddr200403.py
Added Paths:
-----------
branches/zsi-element-tree/ZSI/elementtreeproxy.py
Modified: branches/zsi-element-tree/ZSI/TC.py
===================================================================
--- branches/zsi-element-tree/ZSI/TC.py 2007-06-04 21:56:51 UTC (rev 1387)
+++ branches/zsi-element-tree/ZSI/TC.py 2007-06-05 04:48:41 UTC (rev 1388)
@@ -10,7 +10,8 @@
_find_xmlns_prefix, _get_element_nsuri_name, _get_idstr, \
EvaluateException, \
_valid_encoding, ParseException
-
+
+from lxml import etree
from ZSI.wstools.Namespaces import SCHEMA, SOAP
#from ZSI.wstools.Utility import SplitQName
#from ZSI.wstools.c14n import Canonicalize
@@ -26,6 +27,7 @@
except ImportError:
from StringIO import StringIO
+_is_etree_element = lambda E: type(E) is etree._Element
_is_xsd_or_soap_ns = lambda ns: ns in [
SCHEMA.XSD3, SOAP.ENC, SCHEMA.XSD1, SCHEMA.XSD2, ]
@@ -207,8 +209,6 @@
elt -- the DOM element being parsed
ps -- the ParsedSoap object.
'''
- print "ELT: ", elt
- print "PS: ", ps
# attr = _find_type(elt)
# if attr is None:
# return (None,None)
@@ -283,8 +283,6 @@
# in [ _Node.TEXT_NODE, _Node.CDATA_SECTION_NODE ]])
# ElementTree: need to strip??
- print "ELT: ", elt
- print "TEXT: ", elt.text
return elt.text
def parse_attributes(self, elt, ps):
@@ -581,7 +579,8 @@
ps.Backtrace(elt))
elt = ps.FindLocalHREF(href, elt)
(ns,type) = self.checktype(elt, ps)
- if not type and elt.namespaceURI == SOAP.ENC:
+ #if not type and elt.namespaceURI == SOAP.ENC:
+ if not type and _get_element_nsuri_name(elt)[0] == SOAP.ENC:
ns,type = SOAP.ENC, elt.localName
if not type or (ns,type) == (SOAP.ENC,'Array'):
if self.aslist or _find_arraytype(elt):
@@ -1422,7 +1421,12 @@
raise TypeError, 'pyobj is a typecode instance.'
what = getattr(pyobj, 'typecode', None)
- if what is not None and type(pyobj) is types.InstanceType:
+ if what is None and _is_etree_element(pyobj):
+ e = elt._etree
+ e.append(pyobj)
+ return
+
+ if what is None and type(pyobj) is types.InstanceType:
tc = pyobj.__class__
what = Any.serialmap.get(tc)
if not what:
@@ -1479,13 +1483,16 @@
what.typed = True
return pyobj
- if skip:
- what = XML(pname=(nspname,pname), wrapped=False)
- elif self.processContents == 'lax':
- what = Any(pname=(nspname,pname), unique=True)
- else:
- what = Any(pname=(nspname,pname), unique=True)
+ #if skip:
+ # what = XML(pname=(nspname,pname), wrapped=False)
+ #elif self.processContents == 'lax':
+ # what = Any(pname=(nspname,pname), unique=True)
+ #else:
+ # what = Any(pname=(nspname,pname), unique=True)
+ if what is None:
+ return elt
+
try:
pyobj = what.parse(elt, ps)
except EvaluateException, ex:
Modified: branches/zsi-element-tree/ZSI/TCcompound.py
===================================================================
--- branches/zsi-element-tree/ZSI/TCcompound.py 2007-06-04 21:56:51 UTC (rev 1387)
+++ branches/zsi-element-tree/ZSI/TCcompound.py 2007-06-05 04:48:41 UTC (rev 1388)
@@ -198,6 +198,9 @@
if what.name_match(c_elt):
match = True
value = what.parse(c_elt, ps)
+ elif isinstance(what,AnyElement):
+ match = True
+ value = what.parse(c_elt, ps)
else:
# substitutionGroup head must be a global element declaration
# if successful delegate to matching GED
@@ -229,37 +232,38 @@
if self.inorder is True and i == j:
raise EvaluateException('Out of order complexType',
ps.Backtrace(c_elt))
- else:
- # only supporting 1 <any> declaration in content.
- if isinstance(what,AnyElement):
- any = what
- elif hasattr(what, 'default'):
- v[what.aname] = what.default
- elif what.minOccurs > 0 and not v.has_key(what.aname):
- raise EvaluateException('Element "' + what.aname + \
- '" missing from complexType', ps.Backtrace(elt))
+# else:
+# # only supporting 1 <any> declaration in content.
+# if isinstance(what,AnyElement):
+# any = what
+# elif hasattr(what, 'default'):
+# v[what.aname] = what.default
+# elif what.minOccurs > 0 and not v.has_key(what.aname):
+# raise EvaluateException('Element "' + what.aname + \
+# '" missing from complexType', ps.Backtrace(elt))
+#
# Look for wildcards and unprocessed children
# XXX Stick all this stuff in "any", hope for no collisions
- if any is not None:
- occurs = 0
- v[any.aname] = []
- for j,c_elt in [ (j, c[j]) for j in crange if c[j] ]:
- value = any.parse(c_elt, ps)
- if any.maxOccurs == UNBOUNDED or any.maxOccurs > 1:
- v[any.aname].append(value)
- else:
- v[any.aname] = value
+# if any is not None:
+# occurs = 0
+# v[any.aname] = []
+# for j,c_elt in [ (j, c[j]) for j in crange if c[j] ]:
+# value = any.parse(c_elt, ps)
+# if any.maxOccurs == UNBOUNDED or any.maxOccurs > 1:
+# v[any.aname].append(value)
+# else:
+# v[any.aname] = value
+#
+# occurs += 1
+#
+# # No such thing as nillable <any>
+# if any.maxOccurs == 1 and occurs == 0:
+# v[any.aname] = None
+# elif occurs < any.minOccurs or (any.maxOccurs!=UNBOUNDED and any.maxOccurs<occurs):
+# raise EvaluateException('occurances of <any> elements(#%d) bound by (%d,%s)' %(
+# occurs, any.minOccurs,str(any.maxOccurs)), ps.Backtrace(elt))
- occurs += 1
-
- # No such thing as nillable <any>
- if any.maxOccurs == 1 and occurs == 0:
- v[any.aname] = None
- elif occurs < any.minOccurs or (any.maxOccurs!=UNBOUNDED and any.maxOccurs<occurs):
- raise EvaluateException('occurances of <any> elements(#%d) bound by (%d,%s)' %(
- occurs, any.minOccurs,str(any.maxOccurs)), ps.Backtrace(elt))
-
if not self.pyclass:
return v
Modified: branches/zsi-element-tree/ZSI/__init__.py
===================================================================
--- branches/zsi-element-tree/ZSI/__init__.py 2007-06-04 21:56:51 UTC (rev 1387)
+++ branches/zsi-element-tree/ZSI/__init__.py 2007-06-05 04:48:41 UTC (rev 1388)
@@ -300,8 +300,6 @@
# )
# lxml ElementTree API Extension
- print prefix
- print E.nsmap
return E.nsmap[prefix]
Modified: branches/zsi-element-tree/ZSI/address.py
===================================================================
--- branches/zsi-element-tree/ZSI/address.py 2007-06-04 21:56:51 UTC (rev 1387)
+++ branches/zsi-element-tree/ZSI/address.py 2007-06-05 04:48:41 UTC (rev 1388)
@@ -186,11 +186,12 @@
ReferenceProperties = getattr(endPointReference, '_ReferenceProperties', None)
if ReferenceProperties is not None:
for v in getattr(ReferenceProperties, '_any', ()):
- if not hasattr(v,'typecode'):
- raise EvaluateException, '<any> element, instance missing typecode attribute'
+ #if not hasattr(v,'typecode'):
+ # raise EvaluateException, '<any> element, instance missing typecode attribute'
pyobjs.append(v)
+
self.header_pyobjs = tuple(pyobjs)
def setResponseFromWSAddress(self, address, localURL):
@@ -224,7 +225,10 @@
'''
for pyobj in self.header_pyobjs:
if hasattr(pyobj, 'typecode') is False:
- raise RuntimeError, 'all header pyobjs must have a typecode attribute'
+ #raise RuntimeError, 'all header pyobjs must have a typecode attribute'
+ # TODO: Assuming I know this is EPR/ReferenceParameters/any
+ sw.serialize_header(pyobj, typecode=AnyElement(), **kw)
+ continue
sw.serialize_header(pyobj, **kw)
Added: branches/zsi-element-tree/ZSI/elementtreeproxy.py
===================================================================
--- branches/zsi-element-tree/ZSI/elementtreeproxy.py (rev 0)
+++ branches/zsi-element-tree/ZSI/elementtreeproxy.py 2007-06-05 04:48:41 UTC (rev 1388)
@@ -0,0 +1,116 @@
+############################################################################
+# Joshua R. Boverhof, LBNL
+# See Copyright for copyright notice!
+###########################################################################
+#from Ft.Xml.Domlette import NonvalidatingReaderBase, NonvalidatingReader
+#from ZSI.wstools.c14n import Canonicalize
+from ZSI.wstools.Namespaces import SCHEMA, XMLNS
+#from ZSI.wstools.Utility import DOMException
+from ZSI.wstools.Utility import MessageInterface
+
+#from xml.etree import ElementTree
+from lxml import etree as ElementTree
+
+#class DomletteReader(NonvalidatingReaderBase):
+# '''Used with ZSI.parse.ParsedSoap
+# '''
+# fromString = NonvalidatingReaderBase.parseString
+# fromStream = NonvalidatingReaderBase.parseStream
+
+class ElementProxyException(Exception):
+ '''TODO: Should probably rename DOMException ElementProxyException.
+ '''
+
+class ElementTreeProxy(MessageInterface):
+ '''ElementTree wrapper
+ TODO: add c14n for message signatures, issue with "getPrefix"
+ '''
+
+ def __init__(self, sw, message=None):
+ '''Initialize.
+ sw -- SoapWriter
+ '''
+ assert message is None, 'TODO'
+ self._etree = None
+
+ def __str__(self):
+ return self.toString()
+
+ def toString(self):
+ return ElementTree.tostring(self._etree)
+
+ #############################################
+ #Methods used in TypeCodes
+ #############################################
+ def createAppendElement(self, namespaceURI, localName, prefix=None):
+ '''Create a new element (namespaceURI,name), append it
+ to current node, and return the newly created node.
+ Keyword arguments:
+ namespaceURI -- namespace of element to create
+ localName -- local name of new element
+ prefix -- if namespaceURI is not defined, declare prefix. defaults
+ to 'ns1' if left unspecified.
+ '''
+ assert prefix is None, 'TODO: can really do this'
+ e = ElementTree.Element("{%s}%s" %(namespaceURI, localName))
+ self._etree.append(e)
+
+ eproxy = ElementTreeProxy(None)
+ eproxy._etree = e
+ return eproxy
+
+ def createAppendTextNode(self, pyobj):
+ '''TODO: obviously mixed text content cannot be accurately
+ represented via this interface. Only 1 possible text node/element
+ '''
+ self._etree.text = pyobj
+
+ def createDocument(self, namespaceURI, localName):
+ self._etree = ElementTree.Element('{%s}%s' %(namespaceURI, localName))
+
+ def getElement(self, namespaceURI, localName):
+ for e in self._etree.getchildren():
+ l = e.tag.strip('{').split('}')
+ if not namespaceURI:
+ if len(l) == 1 and l[0] == localName:
+ eproxy = ElementTreeProxy(None)
+ eproxy._etree = e
+ return eproxy
+ elif len(l) == 2 and l[0] == namespaceURI and l[1] == localName:
+ eproxy = ElementTreeProxy(None)
+ eproxy._etree = e
+ return eproxy
+
+ raise ElementProxyException,\
+ 'No such element(%s,%s)' %(namespaceURI,localName)
+
+ def getPrefix(self, namespaceURI):
+ '''TODO: this is not possible w/elementTree since namespace prefix
+ mappings aren't done until serialization. completely abstraced out.
+ '''
+ raise NotImplementedError, 'this func isnt going to work'
+
+ def setAttributeNS(self, namespaceURI, localName, value):
+ '''
+ Keyword arguments:
+ namespaceURI -- namespace of attribute to create, None is for
+ attributes in no namespace.
+ localName -- local name of new attribute
+ value -- value of new attribute
+ '''
+ self._etree.attrib["{%s}%s" %(namespaceURI, localName)] = value
+
+ def setAttributeType(self, namespaceURI, localName):
+ '''xsi:type attribute, value must be a QName
+ '''
+ self.setAttributeNS(SCHEMA.XSI3, 'type',
+ ElementTree.QName('{%s}%s' %(namespaceURI,localName))
+ )
+
+ def setNamespaceAttribute(self, prefix, namespaceURI):
+ '''TODO: Not sure how to force this to be used by ElementTree
+ Keyword arguments:
+ prefix -- xmlns prefix
+ namespaceURI -- value of prefix
+ '''
+ self._etree.attrib["xmlns:%s" %prefix] = namespaceURI
Modified: branches/zsi-element-tree/ZSI/parse.py
===================================================================
--- branches/zsi-element-tree/ZSI/parse.py 2007-06-04 21:56:51 UTC (rev 1387)
+++ branches/zsi-element-tree/ZSI/parse.py 2007-06-05 04:48:41 UTC (rev 1388)
@@ -13,7 +13,7 @@
import types
from ZSI.wstools.Namespaces import SOAP, XMLNS
-from ZSI.wstools.Utility import SplitQName
+#from ZSI.wstools.Utility import SplitQName
#_find_actor = lambda E: E.getAttributeNS(SOAP.ENV, "actor") or None
#_find_mu = lambda E: E.getAttributeNS(SOAP.ENV, "mustUnderstand")
@@ -103,9 +103,6 @@
# raise ParseException('Document has "' + elt.localName + \
# '" element, not Envelope', 0)
if _get_element_nsuri_name(elt) != (SOAP.ENV, "Envelope"):
- print "X: ", _get_element_nsuri_name(elt) != (SOAP.ENV, "Envelope")
- print "A: ",_get_element_nsuri_name(elt)
- print "V: ",(SOAP.ENV, "Envelope")
raise ParseException('Document has "' + \
str(_get_element_nsuri_name(elt)) + \
'" element, not Envelope', 0)
@@ -388,11 +385,11 @@
v = []
occurs = 0
namespaceURI,tagName = what.nspname,what.pname
- for j,c_elt in [ (j, c[j]) for j in crange if c[j] ]:
+ for j,c_elt in [ (j, c[j]) for j in crange if c[j] is not None]:
# prefix,name = SplitQName(c_elt.tagName)
# nsuri = _resolve_prefix(c_elt, prefix)
# if tagName == name and namespaceURI == nsuri:
- if _get_element_nsuri_name(c_elt) == (nsuri, name):
+ if _get_element_nsuri_name(c_elt) == (namespaceURI,tagName):
pyobj = what.parse(c_elt, self)
else:
continue
Modified: branches/zsi-element-tree/test/wsdl2py/servers/EchoServer.py
===================================================================
--- branches/zsi-element-tree/test/wsdl2py/servers/EchoServer.py 2007-06-04 21:56:51 UTC (rev 1387)
+++ branches/zsi-element-tree/test/wsdl2py/servers/EchoServer.py 2007-06-05 04:48:41 UTC (rev 1388)
@@ -5,6 +5,8 @@
###########################################################################
import sys
from ZSI.ServiceContainer import AsServer
+from ZSI.wstools.logging import setBasicLoggerDEBUG
+setBasicLoggerDEBUG()
from EchoServer_server import EchoServer
"""
@@ -18,7 +20,7 @@
class Service(EchoServer):
def soap_Echo(self, ps):
response = EchoServer.soap_Echo(self, ps)
- response.EchoResult = self.request.EchoIn
+ response.EchoResult = self.request.EchoIn or "NO ECHO??"
return response
Modified: branches/zsi-element-tree/test/wsdl2py/test_EchoWSAddr200403.py
===================================================================
--- branches/zsi-element-tree/test/wsdl2py/test_EchoWSAddr200403.py 2007-06-04 21:56:51 UTC (rev 1387)
+++ branches/zsi-element-tree/test/wsdl2py/test_EchoWSAddr200403.py 2007-06-05 04:48:41 UTC (rev 1388)
@@ -5,7 +5,7 @@
###########################################################################
import os, sys, unittest
from ServiceTest import main, ServiceTestCase, ServiceTestSuite
-from ZSI import FaultException, TC
+from ZSI import ParsedSoap, FaultException, TC
from ZSI.schema import GED, GTD
"""
@@ -55,10 +55,27 @@
kw['wsAddressURI'] = 'http://schemas.xmlsoap.org/ws/2004/03/addressing'
return kw
- def test_local_Echo(self):
+ def Xtest_local_Echo(self):
msg = self.client_module.EchoRequest()
rsp = self.client_module.EchoResponse()
+ def test_local_EPR(self):
+ MSG = """
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"><soapenv:Header><wsa:MessageID soapenv:mustUnderstand="0">uuid:61f126b0-12ef-11dc-9fd4-a15ae8e2e52b</wsa:MessageID><wsa:To soapenv:mustUnderstand="0">http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:To><wsa:Action soapenv:mustUnderstand="0">http://counter.com/CounterPortType/createCounterResponse</wsa:Action><wsa:From soapenv:mustUnderstand="0"><wsa:Address>http://192.168.15.4:8080/wsrf/services/CounterService</wsa:Address></wsa:From><wsa:RelatesTo RelationshipType="wsa:Reply" soapenv:mustUnderstand="0">uuid:1180998026.34</wsa:RelatesTo></soapenv:Header><soapenv:Body>
+ <wsa:EndpointReference>
+ <wsa:Address>http://192.168.15.4:8080/wsrf/services/CounterService</wsa:Address>
+ <wsa:ReferenceProperties><CounterKey>21201606</CounterKey></wsa:ReferenceProperties>
+ <wsa:ReferenceParameters/>
+ </wsa:EndpointReference>
+</soapenv:Body></soapenv:Envelope>
+"""
+ ps = ParsedSoap(MSG)
+ pyobj = ps.Parse( GED('http://schemas.xmlsoap.org/ws/2004/03/addressing','EndpointReference') )
+ print "PYOBJ: ", pyobj
+ print "\t", pyobj.Address
+ print "\t", pyobj.ReferenceProperties
+ print "\t", pyobj.ReferenceProperties.Any
+
def test_dispatch_Echo(self):
loc = self.client_module.EchoWSAddr200403ServerLocator()
port = loc.getport(**self.getPortKWArgs())
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|