Previous topic

Enum

Next topic

Fault

This Page

Complex

The spyne.model.complex module contains spyne.model.complex.ComplexBase class and its helper objects and subclasses. These are mainly container classes for other simple or complex objects – they don’t carry any data by themselves.

class spyne.model.complex.Array(*args, **kwargs)[source]

Bases: spyne.model.complex.ComplexModelBase

This class generates a ComplexModel child that has one attribute that has the same name as the serialized class. It’s contained in a Python list.

class spyne.model.complex.ComplexModel(*args, **kwargs)[source]

Bases: spyne.model.complex.ComplexModelBase

The general complexType factory. The __call__ method of this class will return instances, contrary to primivites where the same call will result in customized duplicates of the original class definition. Those who’d like to customize the class should use the customize method. (see :class:spyne.model.ModelBase).

class spyne.model.complex.ComplexModelBase(*args, **kwargs)[source]

Bases: spyne.model._base.ModelBase

If you want to make a better class type, this is what you should inherit from.

class Attributes[source]

Bases: spyne.model._base.Attributes

ComplexModel-specific attributes

child_attrs = None

Customize child attributes in one go. It’s a dict of dicts. This is ignored unless used via explicit customization.

declare_order = None

The order fields of the :class:ComplexModel are to be declared in the SOAP WSDL. If this is left as None or explicitly set to 'random' declares then the fields appear in whatever order the Python’s hash map implementation seems fit in the WSDL. This randomised order can change every time the program is run. This is what Spyne <2.11 did if you didn’t set _type_info as an explicit sequence (e.g. using a list, odict, etc.). It means that clients who are manually complied or generated from the WSDL will likely need to be recompiled every time it changes. The string name means the field names are alphabetically sorted in the WSDL declaration. The string declared means in the order the field type was declared in Python 2, and the order the field was declared in Python 3.

In order to get declared field order in Python 2, the spyne.util.meta.Preparable class inspects the frame stack in order to locate the class definition, re-parses it to get declaration order from the AST and uses that information to order elements.

It’s a horrible hack that we tested to work with CPython 2.6 through 3.3 and PyPy. It breaks in Nuitka as Nuitka does away with code objects. Other platforms were not tested.

It’s not recommended to use set this to 'declared' in Python 2 unless you’re sure you fully understand the consequences.

methods = None

FIXME: document me yo.

parent_variant = None

FIXME: document me yo.

sqla_mapper = None

The sqlalchemy mapper object

sqla_mapper_args = None

A dict that will be passed to sqlalchemy.orm.mapper() constructor as. **kwargs.

sqla_metadata = None

None or sqlalchemy.MetaData instance.

sqla_table = None

The sqlalchemy table object

sqla_table_args = None

A dict that will be passed to sqlalchemy.schema.Table constructor as **kwargs.

validate_freq = True

When False, soft validation ignores missing mandatory attributes.

classmethod ComplexModelBase.customize(**kwargs)[source]

Duplicates cls and overwrites the values in cls.Attributes with **kwargs and returns the new class.

classmethod ComplexModelBase.get_deserialization_instance()[source]

Get an empty native type so that the deserialization logic can set its attributes.

classmethod ComplexModelBase.get_serialization_instance(value)[source]

Returns the native object corresponding to the serialized form passed in the value argument.

Parameters:value

This argument can be: * A list or tuple of native types aligned with cls._type_info. * A dict of native types. * The native type itself.

If the value type is not a list, tuple or dict, the value is returned untouched.

static ComplexModelBase.produce(namespace, type_name, members)[source]

Lets you create a class programmatically.

class spyne.model.complex.ComplexModelMeta(cls_name, cls_bases, cls_dict)[source]

Bases: spyne.util.meta.NewBase

This metaclass sets _type_info, __type_name__ and __extends__ which are going to be used for (de)serialization and schema generation.

class spyne.model.complex.Iterable(*args, **kwargs)[source]

Bases: spyne.model.complex.Array

This class generates a ComplexModel child that has one attribute that has the same name as the serialized class. It’s contained in a Python iterable. The distinction with the Array is made in the protocol implementation, this is just a marker.

Whenever you return a generator instead of a list, you should use this type as this suggests the intermediate machinery to NEVER actually try to iterate over the value. An Array could be iterated over for e.g. logging purposes.

spyne.model.complex.Mandatory(cls, **_kwargs)[source]

Customizes the given type to be a mandatory one. Has special cases for spyne.model.primitive.Unicode and spyne.model.complex.Array.

class spyne.model.complex.SelfReference[source]

Bases: object

Use this as a placeholder type in classes that contain themselves. See spyne.test.model.test_complex.TestComplexModel.test_self_reference().

class spyne.model.complex.XmlAttribute[source]

Bases: spyne.model.complex.XmlModifier

Items which are marshalled as attributes of the parent element. If attribute_of is passed, it’s marshalled as the attribute of the element with given name.

class spyne.model.complex.XmlAttributeRef(ref, use=None)[source]

Bases: spyne.model.complex.XmlAttribute

Reference to an Xml attribute.

class spyne.model.complex.XmlData[source]

Bases: spyne.model.complex.XmlModifier

Items which are marshalled as data of the parent element.

spyne.model.complex.TTableModel(metadata=None)[source]

A TableModel template that generates a new TableModel class for each call. If metadata is not supplied, a new one is instantiated.