Skip to content

Commit 333c5d8

Browse files
committed
Merge pull request #127 from taavi/master
Precompiles is_host_name regex.
2 parents 7998eef + a4d931f commit 333c5d8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

jsonschema/_format.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ def is_ipv6(instance):
131131
return socket.inet_pton(socket.AF_INET6, instance)
132132

133133

134+
_host_name_re = re.compile(r"^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$")
135+
134136
@_checks_drafts(draft3="host-name", draft4="hostname")
135137
def is_host_name(instance):
136-
pattern = "^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$"
137-
if not re.match(pattern, instance):
138+
if not _host_name_re.match(instance):
138139
return False
139140
components = instance.split(".")
140141
for component in components:

0 commit comments

Comments
 (0)