diff options
author | Zac Hatfield-Dodds <Zac-HD@users.noreply.github.com> | 2019-10-04 11:50:48 +1000 |
---|---|---|
committer | Zac-HD <zac.hatfield.dodds@gmail.com> | 2019-10-07 12:34:33 +1100 |
commit | 51fc2f7a90ea8609090ddfd2a45ca4724e594462 (patch) | |
tree | d419290f0c71cd55256587d8c0f5e90f0658c0b0 /jsonschema/_validators.py | |
parent | 0cb551ab5fe6001134a9aa0baf73e890f4d9b7e3 (diff) | |
download | jsonschema-51fc2f7a90ea8609090ddfd2a45ca4724e594462.tar.gz |
Use JS regex syntax
Note that js_regex.compile has a cache, just like re.compile, so calling it in loops does a lot of dict lookups but very little work.
Diffstat (limited to 'jsonschema/_validators.py')
-rw-r--r-- | jsonschema/_validators.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py index 179fec0..39ff905 100644 --- a/jsonschema/_validators.py +++ b/jsonschema/_validators.py @@ -1,4 +1,4 @@ -import re +import js_regex from jsonschema._utils import ( ensure_list, @@ -19,7 +19,7 @@ def patternProperties(validator, patternProperties, instance, schema): for pattern, subschema in iteritems(patternProperties): for k, v in iteritems(instance): - if re.search(pattern, k): + if js_regex.compile(pattern).search(k): for error in validator.descend( v, subschema, path=k, schema_path=pattern, ): @@ -197,7 +197,7 @@ def uniqueItems(validator, uI, instance, schema): def pattern(validator, patrn, instance, schema): if ( validator.is_type(instance, "string") and - not re.search(patrn, instance) + not js_regex.compile(patrn).search(instance) ): yield ValidationError("%r does not match %r" % (instance, patrn)) |