def _get_spyne_type(v): try: v = NATIVE_MAP.get(v, v) except TypeError: return try: subc = issubclass(v, ModelBase) or issubclass(v, SelfReference) except: subc = False if subc: if issubclass(v, Array) and len(v._type_info) != 1: raise Exception("Invalid Array definition in %s.%s."% (cls_name, k)) return v
def _get_spyne_type(cls_name, k, v): try: v = NATIVE_MAP.get(v, v) except TypeError: return try: subc = issubclass(v, ModelBase) or issubclass(v, SelfReference) except: subc = False if subc: if issubclass(v, Array) and len(v._type_info) != 1: raise Exception("Invalid Array definition in %s.%s."% (cls_name, k)) elif issubclass(v, Point) and v.Attributes.dim is None: raise Exception("Please specify the number of dimensions") return v
"""The 32-bit unsigned integer, alias for :class:`UnsignedInteger32`.""" UnsignedInteger16 = TBoundedUnsignedInteger(16, 'unsignedShort') """The 16-bit unsigned integer, also known as ``unsignedShort``.""" UnsignedShort = UnsignedInteger16 """The 16-bit unsigned integer, alias for :class:`UnsignedInteger16`.""" UnsignedInteger8 = TBoundedUnsignedInteger(8, 'unsignedByte') """The 8-bit unsigned integer, also known as ``unsignedByte``.""" UnsignedByte = UnsignedInteger8 """The 8-bit unsigned integer, alias for :class:`UnsignedInteger8`.""" NATIVE_MAP.update({ float: Double, decimal.Decimal: Decimal, }) if six.PY3: NATIVE_MAP.update({ int: Integer, }) else: NATIVE_MAP.update({ long: Integer, }) if isinstance(0x80000000, long): # 32-bit architecture NATIVE_MAP[int] = Integer32 else: # not 32-bit (so most probably 64-bit) architecture
to a `ComplexModel` sublass.""" @classmethod def customize(cls, **kwargs): """Duplicates cls and overwrites the values in ``cls.Attributes`` with ``**kwargs`` and returns the new class.""" store_as = apply_pssm(kwargs.get('store_as', None), {'json': json, 'xml': xml, 'msgpack': msgpack}) if store_as is not None: kwargs['store_as'] = store_as return super(AnyDict, cls).customize(**kwargs) class Boolean(SimpleModel): """Life is simple here. Just true or false.""" class Attributes(SimpleModel.Attributes): store_as = bool """Method for serializing to persistent storage. One of `bool` or `int` builtins. It makes sense to specify this only when this object belongs to a `ComplexModel` sublass.""" __type_name__ = 'boolean' NATIVE_MAP.update({ bool: Boolean, })
class Attributes(Unicode(pattern=UUID_PATTERN).Attributes): serialize_as = None @staticmethod def validate_string(cls, value): return _uuid_validate[cls.Attributes.serialize_as](cls, value) @staticmethod def validate_native(cls, value): return SimpleModel.validate_native(cls, value) class Ltree(Unicode(LTREE_OPTIMAL_SIZE, unicode_pattern=LTREE_PATTERN)): """A special kind of String type designed to hold the Ltree type from Postgresql.""" __namespace__ = 'http://spyne.io/schema' __type_name__ = 'ltreeString' if not six.PY2: NATIVE_MAP.update({ str: Unicode, }) else: NATIVE_MAP.update({ str: String, unicode: Unicode, })
pattern = None """A regular expression that matches the whole date. See here for more info: http://www.regular-expressions.info/xml.html""" @staticmethod 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 ) # this object tries to follow ISO 8601 standard. class Duration(SimpleModel): """Native type is :class:`datetime.timedelta`.""" __type_name__ = 'duration' Value = datetime.timedelta NATIVE_MAP.update({ datetime.datetime: DateTime, datetime.time: Time, datetime.date: Date, datetime.timedelta: Duration, })
Date objects should be serialized.""" pattern = None """A regular expression that matches the whole date. See here for more info: http://www.regular-expressions.info/xml.html""" @staticmethod 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) # this object tries to follow ISO 8601 standard. class Duration(SimpleModel): """Native type is :class:`datetime.timedelta`.""" __type_name__ = 'duration' Value = datetime.timedelta NATIVE_MAP.update({ datetime.datetime: DateTime, datetime.time: Time, datetime.date: Date, datetime.timedelta: Duration, })
class Attributes(Unicode(pattern=UUID_PATTERN).Attributes): serialize_as = None @staticmethod def validate_string(cls, value): return _uuid_validate[cls.Attributes.serialize_as](cls, value) @staticmethod def validate_native(cls, value): return SimpleModel.validate_native(cls, value) class Ltree(Unicode(LTREE_OPTIMAL_SIZE, unicode_pattern=LTREE_PATTERN)): """A special kind of String type designed to hold the Ltree type from Postgresql.""" __namespace__ = 'http://spyne.io/schema' __type_name__ = 'ltreeString' if six.PY3: NATIVE_MAP.update({ str: Unicode, }) else: NATIVE_MAP.update({ str: String, unicode: Unicode, })
@classmethod def customize(cls, **kwargs): """Duplicates cls and overwrites the values in ``cls.Attributes`` with ``**kwargs`` and returns the new class.""" store_as = apply_pssm(kwargs.get('store_as', None), { 'json': json, 'xml': xml, 'msgpack': msgpack }) if store_as is not None: kwargs['store_as'] = store_as return super(AnyDict, cls).customize(**kwargs) class Boolean(SimpleModel): """Life is simple here. Just true or false.""" class Attributes(SimpleModel.Attributes): store_as = bool """Method for serializing to persistent storage. One of `bool` or `int` builtins. It makes sense to specify this only when this object belongs to a `ComplexModel` sublass.""" __type_name__ = 'boolean' NATIVE_MAP.update({ bool: Boolean, })
UnsignedInteger16 = TBoundedUnsignedInteger(16, 'unsignedShort') """The 16-bit unsigned integer, also known as ``unsignedShort``.""" UnsignedShort = UnsignedInteger16 """The 16-bit unsigned integer, alias for :class:`UnsignedInteger16`.""" UnsignedInteger8 = TBoundedUnsignedInteger(8, 'unsignedByte') """The 8-bit unsigned integer, also known as ``unsignedByte``.""" UnsignedByte = UnsignedInteger8 """The 8-bit unsigned integer, alias for :class:`UnsignedInteger8`.""" NATIVE_MAP.update({ float: Double, decimal.Decimal: Decimal, }) if six.PY3: NATIVE_MAP.update({ int: Integer, }) else: NATIVE_MAP.update({ long: Integer, }) if isinstance(0x80000000, long): # 32-bit architecture NATIVE_MAP[int] = Integer32