Пример #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
 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
    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
 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
    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
 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
 def validate_string(cls, value):
     return SimpleModel.validate_string(cls, value) and value in cls.__values__