MCPcopy
hub / github.com/psycopg/psycopg / pg2pyenc

Function pg2pyenc

psycopg/psycopg/_encodings.py:120–130  ·  view source on GitHub ↗

Convert a PostgreSQL encoding name to Python encoding name. Raise NotSupportedError if the PostgreSQL encoding is not supported by Python.

(name: bytes)

Source from the content-addressed store, hash-verified

118
119@cache
120def pg2pyenc(name: bytes) -> str:
121 """Convert a PostgreSQL encoding name to Python encoding name.
122
123 Raise NotSupportedError if the PostgreSQL encoding is not supported by
124 Python.
125 """
126 try:
127 return py_codecs[name.replace(b"-", b"").replace(b"_", b"").upper()]
128 except KeyError:
129 sname = name.decode("utf8", "replace")
130 raise NotSupportedError(f"codec not available in Python: {sname!r}")
131
132
133def _as_python_identifier(s: str, prefix: str = "f") -> str:

Callers 3

test_encodingFunction · 0.90
conninfo_encodingFunction · 0.85
_encodingMethod · 0.85

Calls 2

NotSupportedErrorClass · 0.85
upperMethod · 0.80

Tested by 1

test_encodingFunction · 0.72