MCPcopy
hub / github.com/MagicStack/asyncpg / main

Function main

tools/generate_exceptions.py:68–184  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66
67
68def main():
69 parser = argparse.ArgumentParser(
70 description='generate _exceptions.py from postgres/errcodes.txt')
71 parser.add_argument('errcodesfile', type=str,
72 help='path to errcodes.txt in PostgreSQL source')
73
74 args = parser.parse_args()
75
76 with open(args.errcodesfile, 'r') as errcodes_f:
77 errcodes = errcodes_f.read()
78
79 section_re = re.compile(r'^Section: .*')
80
81 tpl = """\
82class {clsname}({base}):
83 {docstring}{sqlstate}"""
84
85 new_section = True
86 section_class = None
87
88 buf = '# GENERATED FROM postgresql/src/backend/utils/errcodes.txt\n' + \
89 '# DO NOT MODIFY, use tools/generate_exceptions.py to update\n\n' + \
90 'from ._base import * # NOQA\nfrom . import _base\n\n\n'
91
92 classes = []
93 clsnames = set()
94
95 def _add_class(clsname, base, sqlstate, docstring):
96 if sqlstate:
97 sqlstate = "sqlstate = '{}'".format(sqlstate)
98 else:
99 sqlstate = ''
100
101 txt = tpl.format(clsname=clsname, base=base, sqlstate=sqlstate,
102 docstring=docstring)
103
104 if not sqlstate and not docstring:
105 txt += 'pass'
106
107 if len(txt.splitlines()[0]) > 79:
108 txt = txt.replace('(', '(\n ', 1)
109
110 classes.append(txt)
111 clsnames.add(clsname)
112
113 for line in errcodes.splitlines():
114 if not line.strip() or line.startswith('#'):
115 continue
116
117 if section_re.match(line):
118 new_section = True
119 continue
120
121 parts = re.split(r'\s+', line)
122
123 if len(parts) < 4:
124 continue
125

Callers 1

Calls 4

_get_error_nameFunction · 0.85
_add_classFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…