:param key: Database Encoding :return: [Postgres_encoding, Python_encoding] - Postgres encoding, Python encoding, type cast encoding
(key)
| 25 | |
| 26 | |
| 27 | def 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 | |
| 55 | def configure_driver_encodings(encodings): |
no test coverage detected