Return unicode-decoded values based on type inspection. Smooth over data type issues (esp. with alpha driver versions) and normalize strings as Unicode regardless of user-configured driver encoding settings.
| 3841 | |
| 3842 | |
| 3843 | class _DecodingRow: |
| 3844 | """Return unicode-decoded values based on type inspection. |
| 3845 | |
| 3846 | Smooth over data type issues (esp. with alpha driver versions) and |
| 3847 | normalize strings as Unicode regardless of user-configured driver |
| 3848 | encoding settings. |
| 3849 | |
| 3850 | """ |
| 3851 | |
| 3852 | # Some MySQL-python versions can return some columns as |
| 3853 | # sets.Set(['value']) (seriously) but thankfully that doesn't |
| 3854 | # seem to come up in DDL queries. |
| 3855 | |
| 3856 | _encoding_compat: dict[str, str] = { |
| 3857 | "koi8r": "koi8_r", |
| 3858 | "koi8u": "koi8_u", |
| 3859 | "utf16": "utf-16-be", # MySQL's uft16 is always bigendian |
| 3860 | "utf8mb4": "utf8", # real utf8 |
| 3861 | "utf8mb3": "utf8", # real utf8; saw this happen on CI but I cannot |
| 3862 | # reproduce, possibly mariadb10.6 related |
| 3863 | "eucjpms": "ujis", |
| 3864 | } |
| 3865 | |
| 3866 | def __init__(self, rowproxy: Row[Unpack[_Ts]], charset: Optional[str]): |
| 3867 | self.rowproxy = rowproxy |
| 3868 | self.charset = ( |
| 3869 | self._encoding_compat.get(charset, charset) |
| 3870 | if charset is not None |
| 3871 | else None |
| 3872 | ) |
| 3873 | |
| 3874 | def __getitem__(self, index: int) -> Any: |
| 3875 | item = self.rowproxy[index] |
| 3876 | if self.charset and isinstance(item, bytes): |
| 3877 | return item.decode(self.charset) |
| 3878 | else: |
| 3879 | return item |
| 3880 | |
| 3881 | def __getattr__(self, attr: str) -> Any: |
| 3882 | item = getattr(self.rowproxy, attr) |
| 3883 | if self.charset and isinstance(item, bytes): |
| 3884 | return item.decode(self.charset) |
| 3885 | else: |
| 3886 | return item |
| 3887 | |
| 3888 | |
| 3889 | _info_columns = sql.table( |
no outgoing calls
no test coverage detected