Drop a filter that matched nothing, keep the 79 ports it hid, and exit on a value the registers should not hold
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
|
||||
data-import/httpmethod.py [--source URL_OR_FILE] [--cache DIR] [--out FILE]
|
||||
|
||||
A method whose name is not letters and hyphens does not ship, which drops the `*` the
|
||||
registry holds to stop anyone registering it.
|
||||
A row needs a name of letters and hyphens, which drops the registry's `*`, and both of
|
||||
the answers the registry gives for it.
|
||||
"""
|
||||
import argparse
|
||||
import csv
|
||||
import io
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import source
|
||||
@@ -19,13 +20,19 @@ SOURCE = "https://www.iana.org/assignments/http-methods/methods.csv"
|
||||
OUT = Path(__file__).resolve().parent.parent / "data" / "misc" / "httpmethod.tsv"
|
||||
CACHE = Path(__file__).resolve().parent / "cache"
|
||||
COLUMNS = ["idempotent", "method", "safe"]
|
||||
ANSWERS = ("yes", "no")
|
||||
|
||||
|
||||
def rows(text):
|
||||
for r in csv.DictReader(io.StringIO(text)):
|
||||
method, safe, idempotent = r["Method Name"].strip(), r["Safe"].strip(), r["Idempotent"].strip()
|
||||
if re.match(r"^[A-Za-z][A-Za-z-]*$", method) and safe and idempotent:
|
||||
yield {"idempotent": idempotent, "method": method, "safe": safe}
|
||||
method = (r["Method Name"] or "").strip()
|
||||
safe, idempotent = (r["Safe"] or "").strip(), (r["Idempotent"] or "").strip()
|
||||
if not re.fullmatch(r"[A-Za-z][A-Za-z-]*", method) or not safe or not idempotent:
|
||||
continue
|
||||
for column, answer in (("Safe", safe), ("Idempotent", idempotent)):
|
||||
if answer not in ANSWERS:
|
||||
sys.exit(f"{method}: {column} {answer!r} is neither yes nor no")
|
||||
yield {"idempotent": idempotent, "method": method, "safe": safe}
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user