MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / get_encoding

Function get_encoding

web/pgadmin/utils/driver/psycopg3/encoding.py:27–52  ·  view source on GitHub ↗

:param key: Database Encoding :return: [Postgres_encoding, Python_encoding] - Postgres encoding, Python encoding, type cast encoding

(key)

Source from the content-addressed store, hash-verified

25
26
27def get_encoding(key):
28 """
29 :param key: Database Encoding
30 :return:
31 [Postgres_encoding, Python_encoding] -
32 Postgres encoding, Python encoding, type cast encoding
33 """
34 #
35 # Reference: https://www.postgresql.org/docs/11/multibyte.html
36 #
37 if key == 'ascii':
38 key = 'raw_unicode_escape'
39 try:
40 postgres_encoding = psycopg._encodings.py2pgenc(key).decode()
41 except Exception as e:
42 # For unsupported encodings by psycopg like UNICODE
43 current_app.logger.error(e)
44 postgres_encoding = 'utf-8'
45
46 python_encoding = psycopg._encodings._py_codecs.get(postgres_encoding,
47 'utf-8')
48
49 _dict = encode_dict.get(postgres_encoding.upper(),
50 [postgres_encoding,
51 python_encoding])
52 return _dict
53
54
55def configure_driver_encodings(encodings):

Callers 2

_initializeMethod · 0.85
loadMethod · 0.85

Calls 3

decodeMethod · 0.80
errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected