Python marshmallow.validate.Regexp() Examples
The following are 6
code examples of marshmallow.validate.Regexp().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
marshmallow.validate
, or try the search function
.
Example #1
Source File: test_validation.py From marshmallow-jsonschema with MIT License | 6 votes |
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, }
Example #2
Source File: test_validation.py From marshmallow-jsonschema with MIT License | 5 votes |
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)
Example #3
Source File: common_schema.py From airflow with Apache License 2.0 | 5 votes |
def __init__(self, **metadata): super().__init__(**metadata) self.validators = ( [validate.Regexp("^#[a-fA-F0-9]{3,6}$")] + list(self.validators) )
Example #4
Source File: validates.py From huskar with MIT License | 5 votes |
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))
Example #5
Source File: fields.py From swagger-marshmallow-codegen with MIT License | 5 votes |
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
Example #6
Source File: dispatcher.py From swagger-marshmallow-codegen with MIT License | 5 votes |
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