@@ -220,7 +220,7 @@ def to_regex(
220
220
for i , (name , value ) in enumerate (properties .items ()):
221
221
subregex = f"{ whitespace_pattern } { re .escape (name )} :"
222
222
if value .get ("type" ) == "object" :
223
- subregex += r"( \{{\} }|\n"
223
+ subregex += r"( \{\ }|\n"
224
224
elif value .get ("$ref" ) is not None :
225
225
# exception, we might refer to an object or something else
226
226
pass
@@ -319,9 +319,12 @@ def to_regex(
319
319
elif isinstance (choice , type (None )) and choice is None :
320
320
choices .append (NULL )
321
321
elif type (choice ) in [int , float , str ]:
322
- choices .append (
323
- re .escape (yaml .dump (choice ).strip ().removesuffix ("..." ).strip ())
324
- )
322
+ # HACK: `.removesuffix` not available in python3.8, so we have a more verbose solution
323
+ c = yaml .dump (choice ).strip ()
324
+ suffix = "..."
325
+ c = c [: - len (suffix )].strip () if c .endswith (suffix ) else c
326
+ c = re .escape (c )
327
+ choices .append (c )
325
328
else :
326
329
raise TypeError (f"Unsupported data type in enum: { type (choice )} " )
327
330
return f"({ '|' .join (choices )} )"
@@ -336,7 +339,12 @@ def to_regex(
336
339
elif isinstance (const , type (None )):
337
340
return NULL
338
341
elif type (const ) in [int , float , str ]:
339
- const = re .escape (yaml .dump (const ).strip ().removesuffix ("..." ).strip ())
342
+ # HACK: `.removesuffix` not available in python3.8, so we have a more verbose solution
343
+ c = yaml .dump (const ).strip ()
344
+ suffix = "..."
345
+ c = c [: - len (suffix )].strip () if c .endswith (suffix ) else c
346
+ c = re .escape (c )
347
+ const = c
340
348
else :
341
349
raise TypeError (f"Unsupported data type in const: { type (const )} " )
342
350
return const
0 commit comments