示例#1
0
 def validate_string(cls, value):
     return (     SimpleModel.validate_string(cls, value)
         and (value is None or (
                 len(value) >= cls.Attributes.min_len
             and len(value) <= cls.Attributes.max_len
             and _re_match_with_span(cls.Attributes, value)
         )))
示例#2
0
 def is_default(cls):
     return (
         SimpleModel.is_default(cls)
         and cls.Attributes.min_len == Unicode.Attributes.min_len
         and cls.Attributes.max_len == Unicode.Attributes.max_len
         and cls.Attributes.pattern == Unicode.Attributes.pattern
     )
示例#3
0
    def __new__(cls, *args, **kwargs):
        assert len(args) <= 2

        if len(args) >= 1 and args[0] is not None:
            kwargs['total_digits'] = args[0]
            kwargs['fraction_digits'] = 0
            if len(args) == 2 and args[1] is not None:
                kwargs['fraction_digits'] = args[1]
                assert args[0] > 0, "'total_digits' must be positive."
                assert args[1] <= args[0], "'total_digits' must be greater than" \
                                          " or equal to 'fraction_digits'." \
                                          " %r ! <= %r" % (args[1], args[0])

            # + 1 for decimal separator
            # + 1 for negative sign
            msl = kwargs.get('max_str_len', None)
            if msl is None:
                kwargs['max_str_len'] = (cls.Attributes.total_digits +
                                             cls.Attributes.fraction_digits + 2)
            else:
                kwargs['max_str_len'] = msl

        retval = SimpleModel.__new__(cls,  ** kwargs)

        return retval
示例#4
0
 def validate_string(cls, value):
     return SimpleModel.validate_string(cls, value) and (
         value is None or (
             len(value) <= (cls.Attributes.total_digits +
                                          cls.Attributes.fraction_digits + 1)
                                               # + 1 is for decimal separator
         ))
示例#5
0
 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
         )
示例#6
0
 def validate_native(cls, value):
     return SimpleModel.validate_native(cls, value) and (
         value is None or (
             value >  cls.Attributes.gt and
             value >= cls.Attributes.ge and
             value <  cls.Attributes.lt and
             value <= cls.Attributes.le
         ))
示例#7
0
 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
     )
示例#8
0
    def __new__(cls, dim=None, **kwargs):
        assert dim in (None,2,3)
        if dim is not None:
            kwargs['dim'] = dim
            kwargs['pattern'] = _get_point_pattern(dim)
            kwargs['type_name'] = 'point%dd' % dim

        return SimpleModel.__new__(cls,  ** kwargs)
示例#9
0
 def validate_string(cls, value):
     return (     SimpleModel.validate_string(cls, value)
         and (value is None or (
                 len(value) >= cls.Attributes.min_len
             and len(value) <= cls.Attributes.max_len
             and (cls.Attributes.pattern is None or
                         re.match(cls.Attributes.pattern, value) is not None)
             )))
示例#10
0
    def __new__(cls, *args, **kwargs):
        assert len(args) <= 1

        if len(args) == 1:
            kwargs['max_len'] = args[0]

        retval = SimpleModel.__new__(cls,  ** kwargs)

        return retval
示例#11
0
    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'
        return retval
示例#12
0
    def __new__(cls, dim=None, **kwargs):
        assert dim in (None,2,3)
        if dim is not None:
            kwargs['dim'] = dim
            kwargs['pattern'] = _get_multipolygon_pattern(dim)
            kwargs['type_name'] = 'multipolygon%dd' % dim

        retval = SimpleModel.__new__(cls, **kwargs)
        retval.__namespace__ = 'http://spyne.io/schema'
        return retval
示例#13
0
 def validate_native(cls, value):
     if isinstance(value, datetime.datetime) and value.tzinfo is None:
         value = value.replace(tzinfo=spyne.LOCAL_TZ)
     return SimpleModel.validate_native(cls, value) and (value is None or (
         # min_dt is also a valid value if gt is intact.
         (cls.Attributes.gt is _min_dt or value > cls.Attributes.gt)
         and value >= cls.Attributes.ge
         # max_dt is also a valid value if lt is intact.
         and (cls.Attributes.lt is _max_dt
              or value < cls.Attributes.lt) and value <= cls.Attributes.le))
示例#14
0
 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
     )
示例#15
0
 def validate_native(cls, value):
     if isinstance(value, datetime.datetime) and value.tzinfo is None:
         value = value.replace(tzinfo=spyne.LOCAL_TZ)
     return SimpleModel.validate_native(cls, value) and (
         value is None or (
             value >  cls.Attributes.gt and
             value >= cls.Attributes.ge and
             value <  cls.Attributes.lt and
             value <= cls.Attributes.le
         ))
示例#16
0
 def validate_native(cls, value):
     if isinstance(value, datetime.datetime) and value.tzinfo is None:
         value = value.replace(tzinfo=spyne.LOCAL_TZ)
     return SimpleModel.validate_native(cls, value) and (
         value is None or (
                 value >  cls.Attributes.gt
             and value >= cls.Attributes.ge
             and value <  cls.Attributes.lt
             and value <= cls.Attributes.le
         ))
示例#17
0
文件: primitive.py 项目: esauro/spyne
 def validate_native(cls, value):
     if value is not None and isinstance(value, datetime.datetime):
         value = value.replace(tzinfo=pytz.utc)
     return SimpleModel.validate_native(cls, value) and (
         value is None or (
             value >  cls.Attributes.gt and
             value >= cls.Attributes.ge and
             value <  cls.Attributes.lt and
             value <= cls.Attributes.le
         ))
示例#18
0
 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
         )
示例#19
0
    def __new__(cls, dim=None, **kwargs):
        assert dim in (None, 2, 3)
        if dim is not None:
            kwargs["dim"] = dim
            kwargs["pattern"] = _get_multipolygon_pattern(dim)
            kwargs["type_name"] = "multipolygon%dd" % dim

        retval = SimpleModel.__new__(cls, **kwargs)
        retval.__namespace__ = "http://spyne.io/schema"
        retval.__extends__ = Unicode
        retval.__orig__ = Unicode
        return retval
示例#20
0
    def __new__(cls, dim=None, **kwargs):
        assert dim in (None,2,3)
        if dim is not None:
            kwargs['dim'] = dim
            kwargs['pattern'] = _get_linestring_pattern(dim)
            kwargs['type_name'] = 'line%dd' % dim

        retval = SimpleModel.__new__(cls, **kwargs)
        retval.__namespace__ = 'http://spyne.io/schema'
        retval.__extends__ = Unicode
        retval.__orig__ = Unicode
        return retval
示例#21
0
文件: spatial.py 项目: yanni21/spyne
    def __new__(cls, dim=None, **kwargs):
        assert dim in (None, 2, 3)
        if dim is not None:
            kwargs['dim'] = dim
            kwargs['pattern'] = _get_multilinestring_pattern(dim)
            kwargs['type_name'] = 'multiLine%dd' % dim

        retval = SimpleModel.__new__(cls, **kwargs)
        retval.__namespace__ = 'http://spyne.io/schema'
        retval.__extends__ = Unicode
        retval.__orig__ = Unicode
        return retval
示例#22
0
    def __new__(cls, *args, **kwargs):
        assert len(args) <= 2

        if len(args) >= 1 and args[0] is not None:
            kwargs['total_digits'] = args[0]
            kwargs['fraction_digits'] = 0
            if len(args) == 2 and args[1] is not None:
                kwargs['fraction_digits'] = args[1]

        retval = SimpleModel.__new__(cls, **kwargs)

        return retval
示例#23
0
文件: datetime.py 项目: plq/spyne
 def validate_native(cls, value):
     if isinstance(value, datetime.datetime) and value.tzinfo is None:
         value = value.replace(tzinfo=spyne.LOCAL_TZ)
     return SimpleModel.validate_native(cls, value) and (
         value is None or (
             # min_dt is also a valid value if gt is intact.
                 (cls.Attributes.gt is None or value > cls.Attributes.gt)
             and value >= cls.Attributes.ge
             # max_dt is also a valid value if lt is intact.
             and (cls.Attributes.lt is None or value < cls.Attributes.lt)
             and value <= cls.Attributes.le
         ))
示例#24
0
    def __new__(cls, **kwargs):
        if 'encoding' in kwargs:
            v = kwargs['encoding']

            if v in (None, 'base64'):
                kwargs['type_name'] = 'base64Binary'
            elif v == 'hex':
                kwargs['type_name'] = 'hexBinary'
            else:
                raise ValueError("'encoding' must be one of: %r" % \
                                (tuple(ByteArray._encoding.handlers.values()),))

        return SimpleModel.__new__(cls, **kwargs)
示例#25
0
文件: binary.py 项目: amgibson/spyne
    def __new__(cls, **kwargs):
        if 'encoding' in kwargs:
            v = kwargs['encoding']

            if v in (None, 'base64'):
                kwargs['type_name'] = 'base64Binary'
            elif v == 'hex':
                kwargs['type_name'] = 'hexBinary'
            else:
                raise ValueError("'encoding' must be one of: %r" % \
                                (tuple(ByteArray._encoding.handlers.values()),))


        return SimpleModel.__new__(cls, **kwargs)
示例#26
0
    def __new__(cls, *args, **kwargs):
        assert len(args) <= 2

        if len(args) >= 1 and args[0] is not None:
            kwargs['total_digits'] = args[0]
            kwargs['fraction_digits'] = 0
            if len(args) == 2 and args[1] is not None:
                kwargs['fraction_digits'] = args[1]
                assert args[0] <= args[1], "Total digits should be greater than" \
                                          " or equal to fraction digits." \
                                          " %r ! <= %r" % (args[0], args[1])

        retval = SimpleModel.__new__(cls,  ** kwargs)

        return retval
示例#27
0
    def __new__(cls, *args, **kwargs):
        assert len(args) <= 2

        if len(args) >= 1 and args[0] is not None:
            kwargs['total_digits'] = args[0]
            kwargs['fraction_digits'] = 0
            if len(args) == 2 and args[1] is not None:
                kwargs['fraction_digits'] = args[1]
                assert args[0] <= args[1], "Total digits should be greater than" \
                                          " or equal to fraction digits." \
                                          " %r ! <= %r" % (args[0], args[1])

        retval = SimpleModel.__new__(cls, **kwargs)

        return retval
示例#28
0
    def __new__(cls, *args, **kwargs):
        assert len(args) <= 2

        if len(args) >= 1 and args[0] is not None:
            kwargs['total_digits'] = args[0]
            kwargs['fraction_digits'] = 0
            if len(args) == 2 and args[1] is not None:
                kwargs['fraction_digits'] = args[1]
                assert args[0] > 0, "'total_digits' must be positive."
                assert args[1] <= args[0], "'total_digits' must be greater than" \
                                          " or equal to 'fraction_digits'." \
                                          " %r ! <= %r" % (args[1], args[0])

        retval = SimpleModel.__new__(cls,  ** kwargs)

        return retval
示例#29
0
    def __new__(cls, *args, **kwargs):
        assert len(args) <= 2

        if len(args) >= 1 and args[0] is not None:
            kwargs['total_digits'] = args[0]
            kwargs['fraction_digits'] = 0
            if len(args) == 2 and args[1] is not None:
                kwargs['fraction_digits'] = args[1]
                assert args[0] > 0, "'total_digits' must be positive."
                assert args[1] <= args[0], "'total_digits' must be greater than" \
                                          " or equal to 'fraction_digits'." \
                                          " %r ! <= %r" % (args[1], args[0])

            # + 1 for decimal separator
            # + 1 for negative sign
            kwargs['max_str_len'] = min(
                cls.Attributes.total_digits + cls.Attributes.fraction_digits +
                2, kwargs.get('max_str_len', 0))

        retval = SimpleModel.__new__(cls, **kwargs)

        return retval
示例#30
0
 def validate_native(cls, value):
     return SimpleModel.validate_native(cls, value) and (
         value is None or
         (value > cls.Attributes.gt and value >= cls.Attributes.ge
          and value < cls.Attributes.lt and value <= cls.Attributes.le))
示例#31
0
 def validate_native(cls, value):
     return (SimpleModel.validate_native(cls, value)
             and (value is None or
                  (_re_match_with_span(cls.Attributes, value))))
示例#32
0
 def validate_string(cls, value):
     return (SimpleModel.validate_string(cls, value)
             and (value is None or
                  (len(value) >= cls.Attributes.min_len
                   and len(value) <= cls.Attributes.max_len
                   and _re_match_with_span(cls.Attributes, value))))
示例#33
0
 def is_default(cls):
     return (SimpleModel.is_default(cls)
             and cls.Attributes.min_len == Unicode.Attributes.min_len
             and cls.Attributes.max_len == Unicode.Attributes.max_len
             and cls.Attributes.pattern == Unicode.Attributes.pattern)
示例#34
0
 def validate_native(cls, value):
     return SimpleModel.validate_native(cls, value)
示例#35
0
 def validate_native(cls, value):
     return (SimpleModel.validate_native(cls, value)
         and (value is None or (
             _re_match_with_span(cls.Attributes, value)
         )))
示例#36
0
 def validate_native(cls, value):
     return SimpleModel.validate_native(cls, value)
示例#37
0
文件: enum.py 项目: tunks/spyne
 def validate_string(cls, value):
     return (    SimpleModel.validate_string(cls, value)
             and value in cls.__values__
         )
示例#38
0
 def validate_string(cls, value):
     return SimpleModel.validate_string(
         cls, value) and (value is None or
                          (len(value) <= cls.Attributes.max_str_len))
示例#39
0
 def validate_string(cls, value):
     return SimpleModel.validate_string(cls, value) and (
         value is None or (len(value) <= cls.Attributes.max_str_len)
     )
示例#40
0
 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)
示例#41
0
文件: enum.py 项目: jpunwin/spyne
 def validate_string(cls, value):
     return SimpleModel.validate_string(cls, value) and value in cls.__values__