How to use the spyne.model.SimpleModel function in spyne

To help you get started, we’ve selected a few spyne examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arskom / spyne / spyne / model / primitive.py View on Github external
def is_default(cls):
        return (    SimpleModel.is_default(cls)
                and cls.Attributes.gt == DateTime.Attributes.gt
                and cls.Attributes.ge == DateTime.Attributes.ge
                and cls.Attributes.lt == DateTime.Attributes.lt
                and cls.Attributes.le == DateTime.Attributes.le
                and cls.Attributes.pattern == DateTime.Attributes.pattern
        )
github arskom / spyne / spyne / model / primitive.py View on Github external
def __new__(cls, dim=None, **kwargs):
        assert dim in (None,2,3)
        if dim is not None:
            kwargs['dim'] = dim
            kwargs['pattern'] = _get_multipoint_pattern(dim)
            kwargs['type_name'] = 'multiPoint%dd' % dim

        retval = SimpleModel.__new__(cls, **kwargs)
        retval.__namespace__ = 'http://spyne.io/schema'
        retval.__extends__ = Unicode
        retval.__orig__ = Unicode
        return retval
github arskom / spyne / spyne / model / binary.py View on Github external
binary_encoding_handlers = {
    None: ''.join,
    BINARY_ENCODING_HEX: ByteArray.to_hex,
    BINARY_ENCODING_BASE64: ByteArray.to_base64,
    BINARY_ENCODING_URLSAFE_BASE64: ByteArray.to_urlsafe_base64,
}

binary_decoding_handlers = {
    None: lambda x: [x],
    BINARY_ENCODING_HEX: ByteArray.from_hex,
    BINARY_ENCODING_BASE64: ByteArray.from_base64,
    BINARY_ENCODING_URLSAFE_BASE64: ByteArray.from_urlsafe_base64,
}


class File(SimpleModel):
    """A compact way of dealing with incoming files for protocols with a
    standard way of encoding file metadata along with binary data. (E.g. Http)
    """

    __type_name__ = 'base64Binary'
    __namespace__ = "http://www.w3.org/2001/XMLSchema"

    class Attributes(SimpleModel.Attributes):
        encoding = None
        """The binary encoding to use when the protocol does not enforce an
        encoding for binary data.

        One of (None, 'base64', 'hex')
        """

    class Value(object):
github arskom / spyne / spyne / model / primitive / datetime.py View on Github external
def is_default(cls):
        return (    SimpleModel.is_default(cls)
                and cls.Attributes.gt == Date.Attributes.gt
                and cls.Attributes.ge == Date.Attributes.ge
                and cls.Attributes.lt == Date.Attributes.lt
                and cls.Attributes.le == Date.Attributes.le
                and cls.Attributes.pattern == Date.Attributes.pattern
        )
github arskom / spyne / spyne / model / binary.py View on Github external
None: lambda x: [x],
    BINARY_ENCODING_HEX: ByteArray.from_hex,
    BINARY_ENCODING_BASE64: ByteArray.from_base64,
    BINARY_ENCODING_URLSAFE_BASE64: ByteArray.from_urlsafe_base64,
}


class File(SimpleModel):
    """A compact way of dealing with incoming files for protocols with a
    standard way of encoding file metadata along with binary data. (E.g. Http)
    """

    __type_name__ = 'base64Binary'
    __namespace__ = "http://www.w3.org/2001/XMLSchema"

    class Attributes(SimpleModel.Attributes):
        encoding = None
        """The binary encoding to use when the protocol does not enforce an
        encoding for binary data.

        One of (None, 'base64', 'hex')
        """

    class Value(object):
        """The class for values marked as ``File``.

        :param name: Original name of the file
        :param path: Current path to the file.
        :param type: The mime type of the file's contents.
        :param data: Optional sequence of ``str`` or ``bytes`` instances
            that contain the file's data.
        :param handle: :class:`file` object that contains the file's data.
github arskom / spyne / spyne / model / primitive / number.py View on Github external
def is_default(cls):
            return (    SimpleModel.is_default(cls)
                    and cls.Attributes.gt == Double.Attributes.gt
                    and cls.Attributes.ge == Double.Attributes.ge
                    and cls.Attributes.lt == Double.Attributes.lt
                    and cls.Attributes.le == Double.Attributes.le
                )
github arskom / spyne / spyne / protocol / dictdoc / simple.py View on Github external
for k, v in fti.items():
                new_prefix = list(prefix)
                new_prefix.append(k)
                subinst = getattr(inst, k, None)

                if (issubclass(v, Array) or v.Attributes.max_occurs > 1) and \
                                                            subinst is not None:
                    if issubclass(v, Array):
                        subtype, = v._type_info.values()
                    else:
                        subtype = v

                    # for simple types, the same key is repeated with multiple
                    # values
                    if issubclass(subtype, SimpleModel):
                        key = self.hier_delim.join(new_prefix)
                        l = []
                        for ssv in subinst:
                            l.append(subinst_eater(self, ssv, subtype))
                        retval[key] = l

                    else:
                        # for complex types, brackets are used for each value.
                        last_prefix = new_prefix[-1]
                        i = -1
                        for i, ssv in enumerate(subinst):
                            new_prefix[-1] = '%s[%d]' % (last_prefix, i)
                            self.object_to_simple_dict(subtype, ssv,
                                    retval, new_prefix,
                                         subinst_eater=subinst_eater, tags=tags)
github arskom / spyne / spyne / model / primitive.py View on Github external
def validate_string(cls, value):
        return (     SimpleModel.validate_string(cls, value)
            and (value is None or (
                cls.Attributes.min_len <= len(value) <= cls.Attributes.max_len
            )))
github arskom / spyne / spyne / model / primitive / datetime.py View on Github external
import re
import spyne
import datetime

from spyne.model import SimpleModel
from spyne.model.primitive import NATIVE_MAP

FLOAT_PATTERN = r'-?[0-9]+\.?[0-9]*(e-?[0-9]+)?'
DATE_PATTERN = r'(?P\d{4})-(?P\d{2})-(?P\d{2})'
TIME_PATTERN = r'(?P<hr>\d{2}):(?P\d{2}):(?P\d{2})(?P\.\d+)?'
OFFSET_PATTERN = r'(?P[+-]\d{2}):(?P\d{2})'
DATETIME_PATTERN = DATE_PATTERN + '[T ]' + TIME_PATTERN


class Time(SimpleModel):
    """Just that, Time. No time zone support.

    Native type is :class:`datetime.time`.
    """

    __type_name__ = 'time'
    Value = datetime.time

    class Attributes(SimpleModel.Attributes):
        """Customizable attributes of the :class:`spyne.model.primitive.Time`
        type."""

        gt = None  # minExclusive
        """The time should be greater than this time."""

        ge = datetime.time(0, 0, 0, 0)  # minInclusive
github arskom / spyne / spyne / model / primitive / number.py View on Github external
def is_default(cls):
        return (    SimpleModel.is_default(cls)
                and cls.Attributes.gt == Decimal.Attributes.gt
                and cls.Attributes.ge == Decimal.Attributes.ge
                and cls.Attributes.lt == Decimal.Attributes.lt
                and cls.Attributes.le == Decimal.Attributes.le
                and cls.Attributes.total_digits ==
                                             Decimal.Attributes.total_digits
                and cls.Attributes.fraction_digits ==
                                             Decimal.Attributes.fraction_digits
            )