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.
| 3897 | |
| 3898 | |
| 3899 | class _DecodingRow: |
| 3900 | """Return unicode-decoded values based on type inspection. |
| 3901 | |
| 3902 | Smooth over data type issues (esp. with alpha driver versions) and |
| 3903 | normalize strings as Unicode regardless of user-configured driver |
| 3904 | encoding settings. |
| 3905 | |
| 3906 | """ |
| 3907 | |
| 3908 | # Some MySQL-python versions can return some columns as |
| 3909 | # sets.Set(['value']) (seriously) but thankfully that doesn't |
| 3910 | # seem to come up in DDL queries. |
| 3911 | |
| 3912 | _encoding_compat: Dict[str, str] = { |
| 3913 | "koi8r": "koi8_r", |
| 3914 | "koi8u": "koi8_u", |
| 3915 | "utf16": "utf-16-be", # MySQL's uft16 is always bigendian |
| 3916 | "utf8mb4": "utf8", # real utf8 |
| 3917 | "utf8mb3": "utf8", # real utf8; saw this happen on CI but I cannot |
| 3918 | # reproduce, possibly mariadb10.6 related |
| 3919 | "eucjpms": "ujis", |
| 3920 | } |
| 3921 | |
| 3922 | def __init__(self, rowproxy: Row[Any], charset: Optional[str]): |
| 3923 | self.rowproxy = rowproxy |
| 3924 | self.charset = ( |
| 3925 | self._encoding_compat.get(charset, charset) |
| 3926 | if charset is not None |
| 3927 | else None |
| 3928 | ) |
| 3929 | |
| 3930 | def __getitem__(self, index: int) -> Any: |
| 3931 | item = self.rowproxy[index] |
| 3932 | if self.charset and isinstance(item, bytes): |
| 3933 | return item.decode(self.charset) |
| 3934 | else: |
| 3935 | return item |
| 3936 | |
| 3937 | def __getattr__(self, attr: str) -> Any: |
| 3938 | item = getattr(self.rowproxy, attr) |
| 3939 | if self.charset and isinstance(item, bytes): |
| 3940 | return item.decode(self.charset) |
| 3941 | else: |
| 3942 | return item |
| 3943 | |
| 3944 | |
| 3945 | _info_columns = sql.table( |
no outgoing calls
no test coverage detected