Convert a PostgreSQL encoding name to Python encoding name. Raise NotSupportedError if the PostgreSQL encoding is not supported by Python.
(name: bytes)
| 118 | |
| 119 | @cache |
| 120 | def 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 | |
| 133 | def _as_python_identifier(s: str, prefix: str = "f") -> str: |