|
21 | 21 | # This Software includes and/or makes use of Third-Party Software each |
22 | 22 | # subject to its own license. |
23 | 23 | # DM24-0278 |
24 | | -from io import StringIO |
25 | | -from pathlib import Path |
26 | | - |
27 | | -from abnf_to_regexp.main import run as run_abnf_to_regexp, Params, Format |
28 | 24 |
|
29 | 25 | # from https://semver.org/ |
30 | 26 | VERSION_PATTERN = r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$" |
|
41 | 37 | LENGTH_CHECK_PATTERN = r"(?=.{3,1000}$)" |
42 | 38 |
|
43 | 39 |
|
44 | | -# use abnf-to-regexp as library to catch the output str of the equivalent of |
45 | | -# abnf-to-regexp --format python-nested -i ssvc_namespace_pattern.abnf |
46 | | -# and execute it as python code |
47 | | - |
48 | | -_abnf_python_code = StringIO() |
49 | | -_err = StringIO() |
50 | | -_input_pth = Path(__file__).parent / "ssvc_namespace_pattern.abnf" |
51 | | -_params = Params( |
52 | | - input_path=_input_pth, |
53 | | - output_path=None, |
54 | | - fmt=Format.PYTHON_NESTED, |
| 40 | +# fmt: off |
| 41 | +# --- the following section is generated with |
| 42 | +# abnf-to-regexp --format python-nested -i ssvc_namespace_pattern.abnf | \ |
| 43 | +# sed --expression='s/{,/{0,/g' --expression='s/\\\\#/\#/g' |
| 44 | +alnum = '[a-zA-Z0-9]' |
| 45 | +lower = '[a-z]' |
| 46 | +alnumlow = f'({lower}|[0-9])' |
| 47 | +dash = '-' |
| 48 | +alnumlowdash = f'({alnumlow}|{dash})' |
| 49 | +label = f'{alnumlow}(({alnumlowdash}){{0,61}}{alnumlow})?' |
| 50 | +reverse_dns = f'{label}(\\.{label})+' |
| 51 | +dot = '\\.' |
| 52 | +specialchar = f'({dot}|{dash})' |
| 53 | +fragment_seg = f'({alnumlow})+({specialchar}({alnumlow})+)*' |
| 54 | +x_name = f'{reverse_dns}#{fragment_seg}' |
| 55 | +x_base = f'x_{x_name}' |
| 56 | +ns_core = f'{lower}{alnumlow}(({specialchar})?({alnumlow})+)+' |
| 57 | +reg_base = f'{ns_core}(#{fragment_seg})?' |
| 58 | +base_ns = f'({x_base}|{reg_base})' |
| 59 | +singleton = '[0-9A-WY-Za-wy-z]' |
| 60 | +bcp47 = ( |
| 61 | + '(([a-zA-Z]{2,3}(-[a-zA-Z]{3}(-[a-zA-Z]{3}){0,2})?|[a-z' |
| 62 | + 'A-Z]{4,8})(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-' |
| 63 | + f'(({alnum}){{5,8}}|[0-9]({alnum}){{3}}))*(-{singleton}(-' |
| 64 | + f'({alnum}){{2,8}})+)*(-[xX](-({alnum}){{2,8}})+)?|[xX](-' |
| 65 | + f'({alnum}){{2,8}})+|i-default|i-mingo)' |
55 | 66 | ) |
56 | | - |
57 | | -if ( |
58 | | - run_abnf_to_regexp(params=_params, stdout=_abnf_python_code, stderr=_err) |
59 | | - > 0 |
60 | | -): |
61 | | - raise RuntimeError( |
62 | | - f"Reading of {_input_pth} failed with {_err.getvalue()}" |
63 | | - ) |
64 | | - |
65 | | -exec(_abnf_python_code.getvalue()) |
66 | | - |
67 | | -# we do not need them anymore |
68 | | -del _abnf_python_code |
69 | | -del _err |
| 67 | +translation = f'\\.({reverse_dns}|{x_name})\\${bcp47}' |
| 68 | +ext_seg = f'({bcp47}|\\.{x_name}|{translation})' |
| 69 | +lang_ext = f'(/|/{bcp47})' |
| 70 | +extensions = f'{lang_ext}((/{ext_seg})+)?' |
| 71 | +namespace = f'{base_ns}({extensions})?' |
| 72 | +# --- end of generated output |
| 73 | +# fmt: on |
70 | 74 |
|
71 | 75 | # --- define base patterns to be compatible with previously existing tests |
72 | 76 | BASE_PATTERN = ns_core |
|
0 commit comments