MCPcopy
hub / github.com/psycopg/psycopg / parse_errors_txt

Function parse_errors_txt

tools/update_errors.py:37–67  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

35
36
37def parse_errors_txt(url):
38 classes = {}
39 errors = defaultdict(dict)
40
41 page = urlopen(url)
42 for line in page.read().decode("ascii").splitlines():
43 # Strip comments and skip blanks
44
45 if not (line := line.split("#")[0].strip()):
46 continue
47
48 # Parse a section
49 if m := re.match("Section: (Class (..) - .+)", line):
50 label, class_ = m.groups()
51 classes[class_] = label
52 continue
53
54 # Parse an error
55 if m := re.match(r"(.....)\s+(?:E|W|S)\s+ERRCODE_(\S+)(?:\s+(\S+))?$", line):
56 sqlstate, macro, spec = m.groups()
57 # skip sqlstates without specs as they are not publicly visible
58 if not spec:
59 continue
60 errlabel = spec.upper()
61 errors[class_][sqlstate] = errlabel
62 continue
63
64 # We don't expect anything else
65 raise ValueError("unexpected line:\n%s" % line)
66
67 return classes, errors
68
69
70def tag_from_version(version: str) -> str:

Callers 1

fetch_errorsFunction · 0.85

Calls 2

upperMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected