Permalink
Browse files

fix: any element and elements without subelements

  • Loading branch information...
1 parent 87156f1 commit f11376a02e0f6491ffe3c73152c0d1a3c693ff9a @baverman committed Mar 26, 2012
Showing with 44 additions and 19 deletions.
  1. +8 −0 dropthesoap/schema/model.py
  2. +14 −3 dropthesoap/schema/wsdl.py
  3. +15 −10 dropthesoap/schema/xs.py
  4. +6 −5 dropthesoap/service.py
  5. +1 −1 tests/test_service.py
@@ -75,6 +75,14 @@ def get_node(self, creator):
return node
+class ElementInstance(Instance):
+ def __init__(self, tree):
+ self.value = tree
+
+ def get_node(self, _creator):
+ return self.value
+
+
class BareInstance(object):
def __init__(self, args, kwargs):
self.args = args
View
@@ -6,12 +6,23 @@
types = xs.element('types')(xs.cts(
xs.any(minOccurs=0)))
-message = xs.element('message')(xs.cts(
- xs.element('part')
-))
+message = xs.element('message', minOccurs=0, maxOccurs=xs.unbounded)(
+ xs.complexType()(
+ xs.sequence()(
+ xs.element('part')(
+ xs.complexType()(
+ xs.attribute('name', xs.string),
+ xs.attribute('element', xs.string)
+ )
+ )
+ ),
+ xs.attribute('name', xs.string)
+ )
+)
definitions = xs.element('definitions')(xs.cts(
types,
+ message,
))
schema = xs.schema(namespace)(
View
@@ -1,6 +1,6 @@
from itertools import izip_longest
-from .model import Node, Namespace, Type, Instance, etree, BareInstance
+from .model import Node, Namespace, Type, Instance, etree, BareInstance, ElementInstance
from ..utils import cached_property
namespace = Namespace('http://www.w3.org/2001/XMLSchema', 'xs')
@@ -237,24 +237,29 @@ def fill_node(self, node, instance, creator):
node.attrib[k] = v.type.from_python(value)
- self.realtype.fill_node(node, instance, creator)
+ if self.realtype:
+ self.realtype.fill_node(node, instance, creator)
def init(self, instance, **kwargs):
for k in list(kwargs):
if k in self.attributes:
setattr(instance, k, kwargs[k])
del kwargs[k]
- self.realtype.init(instance, **kwargs)
+ if self.realtype:
+ self.realtype.init(instance, **kwargs)
def from_node(self, node):
kwargs = {}
for k, v in node.items():
kwargs[k] = self.attributes[k].type.to_python(v)
- result = self.realtype.from_node(node)
- if kwargs and isinstance(result, BareInstance):
- result.kwargs.update(kwargs)
+ if self.realtype:
+ result = self.realtype.from_node(node)
+ if kwargs and isinstance(result, BareInstance):
+ result.kwargs.update(kwargs)
+ else:
+ result = BareInstance((), kwargs)
return result
@@ -279,11 +284,8 @@ def __call__(self, *children):
elif isinstance(c, attribute):
attrs[c.name] = c
- if not fields.get('realtype', None):
- raise Exception('No any subtype')
-
if attrs:
- fields['realtype'] = AttributeFiller(fields['realtype'], attrs)
+ fields['realtype'] = AttributeFiller(fields.get('realtype', None), attrs)
return type(name, (complexType,), fields)(**self.attributes)(*children)
@@ -366,6 +368,9 @@ def __init__(self, minOccurs=None, maxOccurs=None, namespace=None, processConten
self.type = anyType
Node.__init__(self, **attributes)
+ def instance(self, node=None):
+ return ElementInstance(node)
+
def match(self, node):
return True
View
@@ -1,7 +1,5 @@
-from functools import wraps
-
-from .schema import xs, soap
-from .schema.model import Namespace
+from .schema import xs, soap, wsdl
+from .schema.model import Namespace, get_root, etree
class customize(object):
def __init__(self, type, minOccurs=None, maxOccurs=None, default=None, nillable=None):
@@ -66,7 +64,10 @@ def inner(func):
return inner
def get_wsdl(self, url):
- return 'Boo'
+ defs = wsdl.definitions.instance()
+ defs.types = wsdl.types.instance(_any=get_root(self.schema))
+
+ return etree.tostring(get_root(defs))
def execute(self, xml):
pass
View
@@ -10,6 +10,6 @@ def test_simple_service():
def add(x=xs.int, y=xs.int):
return x + y
- print tostring(s.schema)
+ print s.get_wsdl('boo')
assert False

0 comments on commit f11376a

Please sign in to comment.