75
75
from .constants import (
76
76
CONN_ATTRS_DN ,
77
77
DEFAULT_CONFIGURATION ,
78
+ DEPRECATED_METHOD_WARNING ,
78
79
MYSQL_DEFAULT_CHARSET_ID_57 ,
79
80
MYSQL_DEFAULT_CHARSET_ID_80 ,
80
81
OPENSSL_CS_NAMES ,
107
108
trace ,
108
109
)
109
110
111
+ from ._decorating import deprecated
110
112
from .optionfiles import read_option_files
111
113
from .tls_ciphers import UNACCEPTABLE_TLS_CIPHERSUITES , UNACCEPTABLE_TLS_VERSIONS
112
114
from .types import (
@@ -597,15 +599,15 @@ def config(self, **kwargs: Any) -> None:
597
599
# Configure client flags
598
600
try :
599
601
default = ClientFlag .get_default ()
600
- self .set_client_flags ( config ["client_flags" ] or default )
602
+ self .client_flags = config ["client_flags" ] or default
601
603
del config ["client_flags" ]
602
604
except KeyError :
603
605
pass # Missing client_flags-argument is OK
604
606
605
607
try :
606
608
if config ["compress" ]:
607
609
self ._compress = True
608
- self .set_client_flags ( [ClientFlag .COMPRESS ])
610
+ self .client_flags = [ClientFlag .COMPRESS ]
609
611
except KeyError :
610
612
pass # Missing compress argument is OK
611
613
@@ -627,9 +629,9 @@ def config(self, **kwargs: Any) -> None:
627
629
):
628
630
raise AttributeError ("allow_local_infile_in_path must be a directory" )
629
631
if self ._allow_local_infile or self ._allow_local_infile_in_path :
630
- self .set_client_flags ( [ClientFlag .LOCAL_FILES ])
632
+ self .client_flags = [ClientFlag .LOCAL_FILES ]
631
633
else :
632
- self .set_client_flags ( [- ClientFlag .LOCAL_FILES ])
634
+ self .client_flags = [- ClientFlag .LOCAL_FILES ]
633
635
634
636
try :
635
637
if not config ["consume_results" ]:
@@ -655,7 +657,7 @@ def config(self, **kwargs: Any) -> None:
655
657
656
658
# Set converter class
657
659
try :
658
- self .set_converter_class ( config ["converter_class" ])
660
+ self .converter_class = config ["converter_class" ]
659
661
except KeyError :
660
662
pass # Using default converter class
661
663
except TypeError as err :
@@ -949,6 +951,7 @@ def _check_server_version(server_version: StrOrBytes) -> Tuple[int, ...]:
949
951
950
952
return version
951
953
954
+ @deprecated (DEPRECATED_METHOD_WARNING .format (property_name = "server_version" ))
952
955
def get_server_version (self ) -> Optional [Tuple [int , ...]]:
953
956
"""Gets the MySQL version.
954
957
@@ -958,9 +961,30 @@ def get_server_version(self) -> Optional[Tuple[int, ...]]:
958
961
"""
959
962
return self ._server_version
960
963
964
+ @deprecated (DEPRECATED_METHOD_WARNING .format (property_name = "server_info" ))
961
965
def get_server_info (self ) -> Optional [str ]:
962
966
"""Gets the original MySQL version information.
963
967
968
+ Returns:
969
+ The original MySQL server as text. If not previously connected, it will
970
+ return `None`.
971
+ """
972
+ return self .server_info
973
+
974
+ @property
975
+ def server_version (self ) -> Optional [Tuple [int , ...]]:
976
+ """Gets the MySQL Server version the connector is connected to.
977
+
978
+ Returns:
979
+ The MySQL server version as a tuple. If not previously connected, it will
980
+ return `None`.
981
+ """
982
+ return self ._server_version
983
+
984
+ @property
985
+ def server_info (self ) -> Optional [str ]:
986
+ """Gets the original MySQL server version information.
987
+
964
988
Returns:
965
989
The original MySQL server as text. If not previously connected, it will
966
990
return `None`.
@@ -992,6 +1016,7 @@ def in_transaction(self) -> bool:
992
1016
```
993
1017
"""
994
1018
1019
+ @deprecated (DEPRECATED_METHOD_WARNING .format (property_name = "client_flags" ))
995
1020
def set_client_flags (self , flags : Union [int , Sequence [int ]]) -> int :
996
1021
"""Sets the client flags.
997
1022
@@ -1020,6 +1045,40 @@ def set_client_flags(self, flags: Union[int, Sequence[int]]) -> int:
1020
1045
>>> cnx.reconnect()
1021
1046
```
1022
1047
"""
1048
+ self .client_flags = flags
1049
+ return self .client_flags
1050
+
1051
+ @property
1052
+ def client_flags (self ) -> int :
1053
+ """Gets the client flags of the current session."""
1054
+ return self ._client_flags
1055
+
1056
+ @client_flags .setter
1057
+ def client_flags (self , flags : Union [int , Sequence [int ]]) -> None :
1058
+ """Sets the client flags.
1059
+
1060
+ The flags-argument can be either an int or a list (or tuple) of
1061
+ ClientFlag-values. If it is an integer, it will set client_flags
1062
+ to flags as is.
1063
+
1064
+ If flags is a sequence, each item in the sequence sets the flag when the
1065
+ value is positive or unsets it when negative (see example below).
1066
+
1067
+ Args:
1068
+ flags: A list (or tuple), each flag will be set or unset when it's negative.
1069
+
1070
+ Raises:
1071
+ ProgrammingError: When the flags argument is not a set or an integer
1072
+ bigger than 0.
1073
+
1074
+ Examples:
1075
+ ```
1076
+ For example, to unset `LONG_FLAG` and set the `FOUND_ROWS` flags:
1077
+ >>> from mysql.connector.constants import ClientFlag
1078
+ >>> cnx.client_flags = [ClientFlag.FOUND_ROWS, -ClientFlag.LONG_FLAG]
1079
+ >>> cnx.reconnect()
1080
+ ```
1081
+ """
1023
1082
if isinstance (flags , int ) and flags > 0 :
1024
1083
self ._client_flags = flags
1025
1084
elif isinstance (flags , (tuple , list )):
@@ -1029,8 +1088,7 @@ def set_client_flags(self, flags: Union[int, Sequence[int]]) -> int:
1029
1088
else :
1030
1089
self ._client_flags |= flag
1031
1090
else :
1032
- raise ProgrammingError ("set_client_flags expect integer (>0) or set" )
1033
- return self ._client_flags
1091
+ raise ProgrammingError ("client_flags setter expect integer (>0) or set" )
1034
1092
1035
1093
def shutdown (self ) -> NoReturn :
1036
1094
"""Shuts down connection to MySQL Server.
@@ -1129,17 +1187,28 @@ def set_login(
1129
1187
else :
1130
1188
self ._password = ""
1131
1189
1190
+ @deprecated (DEPRECATED_METHOD_WARNING .format (property_name = "use_unicode" ))
1132
1191
def set_unicode (self , value : bool = True ) -> None :
1133
- """Toggles unicode mode.
1192
+ """Sets whether we return string fields as unicode or not.
1193
+
1194
+ Args:
1195
+ value: A boolean - default is `True`.
1196
+ """
1197
+ self .use_unicode = value
1198
+
1199
+ @property
1200
+ def use_unicode (self ) -> bool :
1201
+ """Gets whether we return string fields as unicode or not."""
1202
+ return self ._use_unicode
1134
1203
1135
- Sets whether we return string fields as unicode or not.
1204
+ @use_unicode .setter
1205
+ @abstractmethod
1206
+ def use_unicode (self , value : bool ) -> None :
1207
+ """Sets whether we return string fields as unicode or not.
1136
1208
1137
1209
Args:
1138
1210
value: A boolean - default is `True`.
1139
1211
"""
1140
- self ._use_unicode = value
1141
- if self .converter :
1142
- self .converter .set_unicode (value )
1143
1212
1144
1213
@property
1145
1214
def autocommit (self ) -> bool :
@@ -1882,18 +1951,35 @@ def reset_session(
1882
1951
cur .execute (f"SET SESSION `{ key } ` = { value } " )
1883
1952
cur .close ()
1884
1953
1954
+ @deprecated (DEPRECATED_METHOD_WARNING .format (property_name = "converter_class" ))
1885
1955
def set_converter_class (self , convclass : Optional [Type [MySQLConverter ]]) -> None :
1886
1956
"""
1887
1957
Sets the converter class to be used.
1888
1958
1959
+ Args:
1960
+ convclass: Should be a class overloading methods and members of
1961
+ `conversion.MySQLConverter`.
1962
+ """
1963
+ self .converter_class = convclass
1964
+
1965
+ @property
1966
+ def converter_class (self ) -> Optional [Type [MySQLConverter ]]:
1967
+ """Gets the converter class set for the current session."""
1968
+ return self ._converter_class
1969
+
1970
+ @converter_class .setter
1971
+ def converter_class (self , convclass : Optional [Type [MySQLConverter ]]) -> None :
1972
+ """
1973
+ Sets the converter class to be used.
1974
+
1889
1975
Args:
1890
1976
convclass: Should be a class overloading methods and members of
1891
1977
`conversion.MySQLConverter`.
1892
1978
"""
1893
1979
if convclass and issubclass (convclass , MySQLConverterBase ):
1894
1980
charset_name = self ._character_set .get_info (self ._charset_id )[0 ]
1895
1981
self ._converter_class = convclass
1896
- self .converter = convclass (charset_name , self ._use_unicode )
1982
+ self .converter = convclass (charset_name , self .use_unicode )
1897
1983
self .converter .str_fallback = self ._converter_str_fallback
1898
1984
else :
1899
1985
raise TypeError (
@@ -3010,7 +3096,7 @@ def lastrowid(self) -> Optional[int]:
3010
3096
3011
3097
@property
3012
3098
def warnings (self ) -> Optional [List [WarningType ]]:
3013
- """Returns a list of tuples (WarningType) containing warnings generated
3099
+ """Gets a list of tuples (WarningType) containing warnings generated
3014
3100
by the previously executed operation.
3015
3101
3016
3102
Examples:
@@ -3053,6 +3139,7 @@ def statement(self) -> Optional[str]:
3053
3139
except (AttributeError , UnicodeDecodeError ):
3054
3140
return cast (str , self ._executed .strip ())
3055
3141
3142
+ @deprecated (DEPRECATED_METHOD_WARNING .format (property_name = "warnings" ))
3056
3143
def fetchwarnings (self ) -> Optional [List [WarningType ]]:
3057
3144
"""Returns a list of tuples (WarningType) containing warnings generated by
3058
3145
the previously executed operation.
0 commit comments