diff options
author | Julian Berman <Julian@GrayVines.com> | 2013-10-15 17:00:18 -0700 |
---|---|---|
committer | Julian Berman <Julian@GrayVines.com> | 2013-10-15 17:00:18 -0700 |
commit | 333c5d8effb42de3d66296522fb7b8ed07b34b37 (patch) | |
tree | e2d4517c9123c08142fba2f38a8dc40ea359e43d | |
parent | 7998eef27b9faf7e67eb69e8ab700ce8ec3823d0 (diff) | |
parent | a4d931f86b3a7dbbb3f815e946a3391fbdd3a2f3 (diff) | |
download | jsonschema-333c5d8effb42de3d66296522fb7b8ed07b34b37.tar.gz |
Merge pull request #127 from taavi/master
Precompiles is_host_name regex.
-rw-r--r-- | jsonschema/_format.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/jsonschema/_format.py b/jsonschema/_format.py index edfe97d..85e6bb3 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -131,10 +131,11 @@ if hasattr(socket, "inet_pton"): return socket.inet_pton(socket.AF_INET6, instance) +_host_name_re = re.compile(r"^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$") + @_checks_drafts(draft3="host-name", draft4="hostname") def is_host_name(instance): - pattern = "^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$" - if not re.match(pattern, instance): + if not _host_name_re.match(instance): return False components = instance.split(".") for component in components: |