MCPcopy
hub / github.com/psycopg/psycopg / make_regexp

Function make_regexp

tools/update_error_prefixes.py:24–45  ·  view source on GitHub ↗
(pgroot: Path)

Source from the content-addressed store, hash-verified

22
23
24def make_regexp(pgroot: Path) -> str:
25 logger.info("looking for translations in %s", pgroot)
26 msgids = "DEBUG INFO NOTICE WARNING ERROR LOG FATAL PANIC".split()
27 bylang = defaultdict[str, list[str]](list)
28 bylang["en"].extend(msgids)
29 for fn in (pgroot / "src/backend/po").glob("*.po"):
30 lang = fn.name.rsplit(".")[0]
31 pofile = polib.pofile(str(fn))
32 for msgid in msgids:
33 if not (entry := pofile.find(msgid)):
34 continue
35 bylang[lang].append(entry.msgstr)
36
37 pattern = "\n | ".join(
38 "%s # %s" % (" | ".join(re.escape(msg) for msg in msgs), lang)
39 for lang, msgs in sorted(bylang.items())
40 )
41 return rf''' r"""
42 ^ (?:
43 {pattern}
44 ) : \s+
45 """, # noqa: E501'''
46
47
48def update_file(fn: Path, content: str) -> None:

Callers 1

mainFunction · 0.85

Calls 2

infoMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected