本文整理汇总了Python中spyne.model.SimpleModel类的典型用法代码示例。如果您正苦于以下问题:Python SimpleModel类的具体用法?Python SimpleModel怎么用?Python SimpleModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __new__
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
示例2: validate_string
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)
)))
示例3: is_default
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
)
示例4: is_default
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
)
示例5: validate_string
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
))
示例6: __new__
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)
示例7: validate_string
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)
)))
示例8: validate_native
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
))
示例9: __new__
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
示例10: __new__
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
示例11: validate_native
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
))
示例12: validate_native
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
))
示例13: validate_native
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
))
示例14: __new__
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
示例15: __new__
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)