本文整理汇总了Python中marshmallow.validate.Regexp方法的典型用法代码示例。如果您正苦于以下问题:Python validate.Regexp方法的具体用法?Python validate.Regexp怎么用?Python validate.Regexp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marshmallow.validate
的用法示例。
在下文中一共展示了validate.Regexp方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_regexp
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Regexp [as 别名]
def test_regexp():
ipv4_regex = (
r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}"
r"([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
)
class TestSchema(Schema):
ip_address = fields.String(validate=validate.Regexp(ipv4_regex))
schema = TestSchema()
dumped = validate_and_dump(schema)
assert dumped["definitions"]["TestSchema"]["properties"]["ip_address"] == {
"title": "ip_address",
"type": "string",
"pattern": ipv4_regex,
}
示例2: test_regexp_error
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Regexp [as 别名]
def test_regexp_error():
class TestSchema(Schema):
test_regexp = fields.Int(validate=validate.Regexp(r"\d+"))
schema = TestSchema()
with pytest.raises(UnsupportedValueError):
dumped = validate_and_dump(schema)
示例3: __init__
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Regexp [as 别名]
def __init__(self, **metadata):
super().__init__(**metadata)
self.validators = (
[validate.Regexp("^#[a-fA-F0-9]{3,6}$")] + list(self.validators)
)
示例4: key_name_validate
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Regexp [as 别名]
def key_name_validate(value):
regex_validate = validate.Regexp(
r'^(?!^\.+$)\S+$',
error=u'Key({input}) should not starts with dots or contains CRLF.'
)
value = regex_validate(value)
if not all(0x00 < ord(c) < 0x7F for c in unicode(value)):
raise ValidationError(
u'Key({}) contains unicode characters.'.format(value))
示例5: __init__
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Regexp [as 别名]
def __init__(self, pattern, nested_field, *args, **kwargs):
fields.Field.__init__(self, *args, **kwargs)
self.key_field = fields.Str(validate=validate.Regexp(pattern))
self.nested_field = nested_field
示例6: dispatch_validator
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Regexp [as 别名]
def dispatch_validator(self, c, value):
from marshmallow.validate import Length, Regexp, OneOf
from .validate import Range, MultipleOf, Unique, ItemsRange
if isinstance(value, (Regexp)):
c.import_("re") # xxx
c.from_("marshmallow.validate", value.__class__.__name__)
elif isinstance(value, (Length, OneOf)):
c.from_("marshmallow.validate", value.__class__.__name__)
elif isinstance(value, (Range, MultipleOf, Unique, ItemsRange)):
c.from_("swagger_marshmallow_codegen.validate", value.__class__.__name__)
return value