9
9
10
10
from ..catalog import CUSTOM_SCHEMA_NAMES , SCHEMA_CATALOG
11
11
from ..checker import SchemaChecker
12
- from ..formats import KNOWN_FORMATS , RegexVariantName
12
+ from ..formats import KNOWN_FORMATS
13
13
from ..instance_loader import InstanceLoader
14
14
from ..parsers import SUPPORTED_FILE_FORMATS
15
+ from ..regex_variants import RegexImplementation , RegexVariantName
15
16
from ..reporter import REPORTER_BY_NAME , Reporter
16
17
from ..schema_loader import (
17
18
BuiltinSchemaLoader ,
@@ -68,10 +69,11 @@ def pretty_helptext_list(values: list[str] | tuple[str, ...]) -> str:
68
69
date, date-time, email, ipv4, ipv6, regex, uuid
69
70
70
71
\b
71
- For the "regex" format, there are multiple modes which can be specified with
72
- '--format-regex':
73
- default | check that the string is a valid ECMAScript regex
74
- python | check that the string is a valid python regex
72
+ For handling of regexes, there are multiple modes which can be specified with
73
+ '--regex-variant':
74
+ default | use ECMAScript regex syntax (via regress)
75
+ nonunicode | use ECMAScript regex syntax, but in non-unicode mode (via regress)
76
+ python | use python regex syntax
75
77
76
78
\b
77
79
The '--builtin-schema' flag supports the following schema names:
@@ -138,11 +140,18 @@ def pretty_helptext_list(values: list[str] | tuple[str, ...]) -> str:
138
140
)
139
141
@click .option (
140
142
"--format-regex" ,
143
+ hidden = True ,
144
+ help = "Legacy name for `--regex-variant`." ,
145
+ default = None ,
146
+ type = click .Choice ([x .value for x in RegexVariantName ], case_sensitive = False ),
147
+ )
148
+ @click .option (
149
+ "--regex-variant" ,
141
150
help = (
142
- "Set the mode of format validation for regexes. "
143
- "If `--disable-formats regex` is used, this option has no effect ."
151
+ "Name of which regex dialect should be used for format checking "
152
+ "and 'pattern' matching ."
144
153
),
145
- default = RegexVariantName . default . value ,
154
+ default = None ,
146
155
type = click .Choice ([x .value for x in RegexVariantName ], case_sensitive = False ),
147
156
)
148
157
@click .option (
@@ -230,7 +239,8 @@ def main(
230
239
no_cache : bool ,
231
240
cache_filename : str | None ,
232
241
disable_formats : tuple [list [str ], ...],
233
- format_regex : t .Literal ["python" , "default" ],
242
+ format_regex : t .Literal ["python" , "nonunicode" , "default" ] | None ,
243
+ regex_variant : t .Literal ["python" , "nonunicode" , "default" ] | None ,
234
244
default_filetype : t .Literal ["json" , "yaml" , "toml" , "json5" ],
235
245
traceback_mode : t .Literal ["full" , "short" ],
236
246
data_transform : t .Literal ["azure-pipelines" , "gitlab-ci" ] | None ,
@@ -243,6 +253,8 @@ def main(
243
253
) -> None :
244
254
args = ParseResult ()
245
255
256
+ args .set_regex_variant (regex_variant , legacy_opt = format_regex )
257
+
246
258
args .set_schema (schemafile , builtin_schema , check_metaschema )
247
259
args .set_validator (validator_class )
248
260
@@ -257,7 +269,6 @@ def main(
257
269
else :
258
270
args .disable_formats = normalized_disable_formats
259
271
260
- args .format_regex = RegexVariantName (format_regex )
261
272
args .disable_cache = no_cache
262
273
args .default_filetype = default_filetype
263
274
args .fill_defaults = fill_defaults
@@ -318,6 +329,7 @@ def build_checker(args: ParseResult) -> SchemaChecker:
318
329
instance_loader ,
319
330
reporter ,
320
331
format_opts = args .format_opts ,
332
+ regex_impl = RegexImplementation (args .regex_variant ),
321
333
traceback_mode = args .traceback_mode ,
322
334
fill_defaults = args .fill_defaults ,
323
335
)
0 commit comments