Email and URL validators
StrictYAML can validate emails (using a simplified regex) and URLs.
from strictyaml import Email, Url, Map, load
from ensure import Ensure
schema = Map({"a": Email(), "b": Url()})
Parsed:
a: billg@microsoft.com
b: https://user:pass@example.com:443/path?k=v#frag
Ensure(load(yaml_snippet, schema)).equals({"a": "billg@microsoft.com", "b": "https://user:pass@example.com:443/path?k=v#frag"})
Exception:
a: notanemail
b: notaurl
load(yaml_snippet, schema)
strictyaml.exceptions.YAMLValidationError:
when expecting an email address
found non-matching string
in "<unicode string>", line 1, column 1:
a: notanemail
^ (line: 1)
Executable specification
Documentation automatically generated from email-url.story storytests.