Skip to content

Commit

Permalink
XmlObject -> XmlDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
plq committed Oct 29, 2012
1 parent d019a41 commit 12af453
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 92 deletions.
6 changes: 3 additions & 3 deletions doc/source/manual/02_helloworld.rst
Expand Up @@ -164,16 +164,16 @@ a Rest-like protocol, but it doesn't care about HTTP verbs (yet). ::
from spyne.protocol.http import HttpRpc

The HttpRpc serializer does not support complex types. So we will use the
XmlObject serializer as the out_protocol to prevent the clients from dealing
XmlDocument serializer as the out_protocol to prevent the clients from dealing
with Soap cruft. ::

from spyne.protocol.http import XmlObject
from spyne.protocol.http import XmlDocument

Besides the imports, the only difference between the SOAP and the HTTP version
is the application instantiation line: ::

application = Application([HelloWorldService], 'spyne.examples.hello.http',
in_protocol=HttpRpc(), out_protocol=XmlObject())
in_protocol=HttpRpc(), out_protocol=XmlDocument())

Here's how you can test your service using curl: ::

Expand Down
4 changes: 2 additions & 2 deletions examples/helloworld_http.py
Expand Up @@ -53,7 +53,7 @@

from spyne.application import Application
from spyne.decorator import srpc
from spyne.protocol.xml import XmlObject
from spyne.protocol.xml import XmlDocument
from spyne.protocol.http import HttpRpc
from spyne.service import ServiceBase
from spyne.model.complex import Iterable
Expand Down Expand Up @@ -83,7 +83,7 @@ def say_hello(name, times):
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)

application = Application([HelloWorldService], 'spyne.examples.hello.http',
in_protocol=HttpRpc(), out_protocol=XmlObject())
in_protocol=HttpRpc(), out_protocol=XmlDocument())

server = make_server('127.0.0.1', 7789, WsgiApplication(application))

Expand Down
6 changes: 3 additions & 3 deletions examples/multiple_protocols/presentation/pres.tex
Expand Up @@ -17,7 +17,7 @@
keywordstyle=\color{keywords},
commentstyle=\color{comments}\emph,
stringstyle=\ttfamily\color{darkgreen},
emph={Soap11,XmlObject,HtmlMicroFormat},emphstyle=\color{red}\textbf
emph={Soap11,XmlDocument,HtmlMicroFormat},emphstyle=\color{red}\textbf
}

\title{A Quick Look At Spyne}
Expand Down Expand Up @@ -342,12 +342,12 @@
\begin{lstlisting}
from spyne.application import Application
from spyne.protocol.http import HttpRpc
from spyne.protocol.xml import XmlObject
from spyne.protocol.xml import XmlDocument

xml = Application([DateTimeService],
tns='spyne.examples.multiprot',
in_protocol=HttpRpc(),
out_protocol=XmlObject()
out_protocol=XmlDocument()
)
\end{lstlisting}
\end{frame}
Expand Down
4 changes: 2 additions & 2 deletions examples/multiple_protocols/server.py
Expand Up @@ -58,7 +58,7 @@

from spyne.model.primitive import DateTime

from spyne.protocol.xml import XmlObject
from spyne.protocol.xml import XmlDocument
from spyne.protocol.soap import Soap11
from spyne.protocol.http import HttpRpc
from spyne.protocol.html import HtmlMicroFormat
Expand All @@ -83,7 +83,7 @@ def get_utc_time():
in_protocol=HttpRpc(), out_protocol=HttpRpc())

xml = Application([HelloWorldService], tns=tns,
in_protocol=HttpRpc(), out_protocol=XmlObject())
in_protocol=HttpRpc(), out_protocol=XmlDocument())

soap = Application([HelloWorldService], tns=tns,
in_protocol=HttpRpc(), out_protocol=Soap11())
Expand Down
4 changes: 2 additions & 2 deletions examples/twisted/_service.py
Expand Up @@ -37,7 +37,7 @@
from spyne.application import Application
from spyne.decorator import srpc
from spyne.protocol.http import HttpRpc
from spyne.protocol.xml import XmlObject
from spyne.protocol.xml import XmlDocument
from spyne.service import ServiceBase
from spyne.model.primitive import Integer

Expand All @@ -59,7 +59,7 @@ def initialize():


application = Application([SomeService], 'spyne.examples.hello.twisted',
in_protocol=HttpRpc(), out_protocol=XmlObject())
in_protocol=HttpRpc(), out_protocol=XmlDocument())

application.interface.nsmap[None] = application.interface.nsmap['tns']
application.interface.prefmap[application.interface.nsmap['tns']] = None
Expand Down
4 changes: 2 additions & 2 deletions spyne/protocol/html.py
Expand Up @@ -81,7 +81,7 @@ def __init__(self, app=None, validator=None, skip_depth=0):
"""Protocol that returns the response object as a html microformat. See
https://en.wikipedia.org/wiki/Microformats for more info.
The simple flavour is like the XmlObject protocol, but returns data in
The simple flavour is like the XmlDocument protocol, but returns data in
<div> or <span> tags.
:param app: A spyne.application.Application instance.
Expand Down Expand Up @@ -167,7 +167,7 @@ def __init__(self, app=None, validator=None, root_tag='div',
"""Protocol that returns the response object as a html microformat. See
https://en.wikipedia.org/wiki/Microformats for more info.
The simple flavour is like the XmlObject protocol, but returns data in
The simple flavour is like the XmlDocument protocol, but returns data in
<div> or <span> tags.
:param app: A spyne.application.Application instance.
Expand Down
8 changes: 4 additions & 4 deletions spyne/protocol/soap/soap11.py
Expand Up @@ -44,7 +44,7 @@
from spyne.error import RequestNotAllowed
from spyne.model.fault import Fault
from spyne.model.primitive import DateTime
from spyne.protocol.xml import XmlObject
from spyne.protocol.xml import XmlDocument
from spyne.protocol.xml.model import nillable_value
from spyne.protocol.xml.model import TBaseFromElement
from spyne.protocol.soap.mime import collapse_swa
Expand Down Expand Up @@ -139,7 +139,7 @@ def _datetime_to_parent_element(prot, cls, value, tns, parent_elt, name='retval'
_datetime_from_element = TBaseFromElement(lambda cls, s: cls.default_parse(s))


class Soap11(XmlObject):
class Soap11(XmlDocument):
"""The base implementation of a subset of the Soap 1.1 standard. The
document is available here: http://www.w3.org/TR/soap11/
Expand All @@ -159,7 +159,7 @@ class Soap11(XmlObject):

def __init__(self, app=None, validator=None, wrapped=True,
xml_declaration=True, cleanup_namespaces=False):
XmlObject.__init__(self, app, validator, xml_declaration,
XmlDocument.__init__(self, app, validator, xml_declaration,
cleanup_namespaces)

self.__wrapped = wrapped
Expand Down Expand Up @@ -190,7 +190,7 @@ def create_in_document(self, ctx, charset=None):

ctx.in_document = _parse_xml_string(ctx.in_string, charset)

def decompose_incoming_envelope(self, ctx, message=XmlObject.REQUEST):
def decompose_incoming_envelope(self, ctx, message=XmlDocument.REQUEST):
envelope_xml, xmlids = ctx.in_document
header_document, body_document = _from_soap(envelope_xml, xmlids)

Expand Down
2 changes: 1 addition & 1 deletion spyne/protocol/xml/__init__.py
Expand Up @@ -17,4 +17,4 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
#

from spyne.protocol.xml._base import XmlObject
from spyne.protocol.xml._base import XmlDocument
7 changes: 5 additions & 2 deletions spyne/protocol/xml/_base.py
Expand Up @@ -78,7 +78,7 @@ def __init__(self, faultstring):
Fault.__init__(self, 'Client.SchemaValidationError', faultstring)


class XmlObject(ProtocolBase):
class XmlDocument(ProtocolBase):
"""The Xml Schema serialization protocol.
See the following material for more (much much more!) information.
Expand All @@ -89,7 +89,7 @@ class XmlObject(ProtocolBase):
:param app: The owner application instance.
:param validator: One of (None, 'soft', 'lxml', 'schema',
ProtocolBase.SOFT_VALIDATION, XmlObject.SCHEMA_VALIDATION).
ProtocolBase.SOFT_VALIDATION, XmlDocument.SCHEMA_VALIDATION).
:param xml_declaration: Whether to add xml_declaration to the responses
Default is 'True'.
:param cleanup_namespaces: Whether to add clean up namespace declarations
Expand Down Expand Up @@ -328,3 +328,6 @@ def __validate_lxml(self, payload):
if ret == False:
raise SchemaValidationError(
str(self.validation_schema.error_log.last_error))

XmlObject = XmlDocument
"""DEPRECATED. Use XmlDocument instead"""
36 changes: 18 additions & 18 deletions spyne/test/model/test_complex.py
Expand Up @@ -38,7 +38,7 @@
from spyne.model.primitive import String

from spyne.protocol.dictobj import DictObject
from spyne.protocol.xml import XmlObject
from spyne.protocol.xml import XmlDocument

from spyne.test import FakeApp

Expand Down Expand Up @@ -108,17 +108,17 @@ def test_simple_class(self):
a.longitude = 88.0

element = etree.Element('test')
XmlObject().to_parent_element(Address, a, ns_test, element)
XmlDocument().to_parent_element(Address, a, ns_test, element)
element = element[0]
self.assertEquals(5, len(element.getchildren()))

a.since = datetime.datetime(year=2011, month=12, day=31)
element = etree.Element('test')
XmlObject().to_parent_element(Address, a, ns_test, element)
XmlDocument().to_parent_element(Address, a, ns_test, element)
element = element[0]
self.assertEquals(6, len(element.getchildren()))

r = XmlObject().from_element(Address, element)
r = XmlDocument().from_element(Address, element)

self.assertEquals(a.street, r.street)
self.assertEquals(a.city, r.city)
Expand All @@ -130,7 +130,7 @@ def test_simple_class(self):
def test_nested_class(self): # FIXME: this test is incomplete
p = Person()
element = etree.Element('test')
XmlObject().to_parent_element(Person, p, ns_test, element)
XmlDocument().to_parent_element(Person, p, ns_test, element)
element = element[0]

self.assertEquals(None, p.name)
Expand All @@ -154,12 +154,12 @@ def test_class_array(self):

element = etree.Element('test')

XmlObject().to_parent_element(type, peeps, ns_test, element)
XmlDocument().to_parent_element(type, peeps, ns_test, element)
element = element[0]

self.assertEquals(4, len(element.getchildren()))

peeps2 = XmlObject().from_element(type, element)
peeps2 = XmlDocument().from_element(type, element)
for i in range(0, 4):
self.assertEquals(peeps2[i].name, names[i])
self.assertEquals(peeps2[i].birthdate, dob)
Expand All @@ -185,12 +185,12 @@ def test_class_nested_array(self):
type = Array(Person)
type.resolve_namespace(type, __name__)
element = etree.Element('test')
XmlObject().to_parent_element(type, peeps, ns_test, element)
XmlDocument().to_parent_element(type, peeps, ns_test, element)
element = element[0]

self.assertEquals(4, len(element.getchildren()))

peeps2 = XmlObject().from_element(type, element)
peeps2 = XmlDocument().from_element(type, element)
for peep in peeps2:
self.assertEquals(27, peep.age)
self.assertEquals(25, len(peep.addresses))
Expand All @@ -215,9 +215,9 @@ def test_complex_class(self):
l.level4.append(a)

element = etree.Element('test')
XmlObject().to_parent_element(Level1, l, ns_test, element)
XmlDocument().to_parent_element(Level1, l, ns_test, element)
element = element[0]
l1 = XmlObject().from_element(Level1, element)
l1 = XmlDocument().from_element(Level1, element)

self.assertEquals(l1.level2.arg1, l.level2.arg1)
self.assertEquals(l1.level2.arg2, l.level2.arg2)
Expand Down Expand Up @@ -274,28 +274,28 @@ def test_x(self):
x = X()
x.x = [1, 2]
element = etree.Element('test')
XmlObject().to_parent_element(X, x, 'tns', element)
XmlDocument().to_parent_element(X, x, 'tns', element)
msg = element[0]
r = XmlObject().from_element(X, msg)
r = XmlDocument().from_element(X, msg)
self.assertEqual(r.x, [1, 2])

def test_y_fromxml(self):
x = X()
x.x = [1, 2]
element = etree.Element('test')
XmlObject().to_parent_element(X, x, 'tns', element)
XmlDocument().to_parent_element(X, x, 'tns', element)
msg = element[0]
r = XmlObject().from_element(Y, msg)
r = XmlDocument().from_element(Y, msg)
self.assertEqual(r.x, [1, 2])

def test_y_toxml(self):
y = Y()
y.x = [1, 2]
y.y = 38
element = etree.Element('test')
XmlObject().to_parent_element(Y, y, 'tns', element)
XmlDocument().to_parent_element(Y, y, 'tns', element)
msg = element[0]
r = XmlObject().from_element(Y, msg)
r = XmlDocument().from_element(Y, msg)

class SisMsg(ComplexModel):
"""Container with metadata for Jiva integration messages
Expand All @@ -318,7 +318,7 @@ class EncExtractSisMsg(SisMsg):
"""Message indicating a Jiva episode needs to be extracted.
Desirable API: Will it work?
>>> msg = XmlObject().from_element(EncExtractSisMsg, raw_xml)
>>> msg = XmlDocument().from_element(EncExtractSisMsg, raw_xml)
>>> msg.body.mbr_idn
"""
body = EncExtractXs
Expand Down
14 changes: 7 additions & 7 deletions spyne/test/model/test_enum.py
Expand Up @@ -26,7 +26,7 @@
from spyne.const.xml_ns import xsd as _ns_xsd
from spyne.interface.wsdl.wsdl11 import Wsdl11
from spyne.model.complex import Array
from spyne.protocol.xml import XmlObject
from spyne.protocol.xml import XmlDocument
from spyne.protocol.soap.soap11 import Soap11

from spyne.server.wsgi import WsgiApplication
Expand Down Expand Up @@ -93,9 +93,9 @@ def test_serialize(self):
print((repr(mo)))

elt = etree.Element('test')
XmlObject().to_parent_element(DaysOfWeekEnum, mo, 'test_namespace', elt)
XmlDocument().to_parent_element(DaysOfWeekEnum, mo, 'test_namespace', elt)
elt = elt[0]
ret = XmlObject().from_element(DaysOfWeekEnum, elt)
ret = XmlDocument().from_element(DaysOfWeekEnum, elt)

self.assertEquals(mo, ret)

Expand Down Expand Up @@ -124,11 +124,11 @@ def test_serialize_complex_array(self):
DaysOfWeekEnumArray.__namespace__ = 'tns'

elt = etree.Element('test')
XmlObject().to_parent_element(DaysOfWeekEnumArray, days,
XmlDocument().to_parent_element(DaysOfWeekEnumArray, days,
'test_namespace', elt)

elt = elt[0]
ret = XmlObject().from_element(Array(DaysOfWeekEnum), elt)
ret = XmlDocument().from_element(Array(DaysOfWeekEnum), elt)
assert days == ret

print((etree.tostring(elt, pretty_print=True)))
Expand All @@ -151,12 +151,12 @@ def test_serialize_simple_array(self):
Test.resolve_namespace(Test, 'tns')

elt = etree.Element('test')
XmlObject().to_parent_element(Test, t, 'test_namespace', elt)
XmlDocument().to_parent_element(Test, t, 'test_namespace', elt)
elt = elt[0]

print((etree.tostring(elt, pretty_print=True)))

ret = XmlObject().from_element(Test, elt)
ret = XmlDocument().from_element(Test, elt)
self.assertEquals(t.days, ret.days)

if __name__ == '__main__':
Expand Down

0 comments on commit 12af453

Please sign in to comment.