本文整理匯總了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