@@ -220,7 +220,7 @@ def to_regex(
220220 for i , (name , value ) in enumerate (properties .items ()):
221221 subregex = f"{ whitespace_pattern } { re .escape (name )} :"
222222 if value .get ("type" ) == "object" :
223- subregex += r"( \{{\} }|\n"
223+ subregex += r"( \{\ }|\n"
224224 elif value .get ("$ref" ) is not None :
225225 # exception, we might refer to an object or something else
226226 pass
@@ -319,9 +319,12 @@ def to_regex(
319319 elif isinstance (choice , type (None )) and choice is None :
320320 choices .append (NULL )
321321 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 )
325328 else :
326329 raise TypeError (f"Unsupported data type in enum: { type (choice )} " )
327330 return f"({ '|' .join (choices )} )"
@@ -336,7 +339,12 @@ def to_regex(
336339 elif isinstance (const , type (None )):
337340 return NULL
338341 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
340348 else :
341349 raise TypeError (f"Unsupported data type in const: { type (const )} " )
342350 return const
0 commit comments