HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/Python311/Lib/site-packages/mysql/connector/__pycache__/conversion.cpython-311.pyc
�

�nc�U���dZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
ddlmZddl
mZdZGd	�d
��ZGd�de��ZdS)
z"Converting MySQL and Python types
�N)�Decimal�)�CharacterSet�	FieldFlag�	FieldType)�
HexLiteral)�
NUMERIC_TYPESz.Could not convert '{value}' to python {pytype}c�`�eZdZdZd
d�Zd�Zdd�Zd�Zd	�Ze	d
���Z
e	d���ZdS)�MySQLConverterBasez�Base class for conversion classes

    All class dealing with converting to and from MySQL data types must
    be a subclass of this class.
    �utf8TFc��d|_d|_d|_d|_d|_|�|��||_||_i|_dS)Nr)�python_types�mysql_types�charset�
charset_id�use_unicode�set_charset�str_fallback�_cache_field_types��selfrrrs    �<D:\Python311\Lib\site-packages\mysql/connector/conversion.py�__init__zMySQLConverterBase.__init__5sZ�� �������������������!�!�!�&���(���"$�����c�|�|dvrd}|�||_nd|_tj|j��d|_dS)zSet character set)�utf8mb4�utf8mb3rNr)rr�get_charset_infor)rrs  rrzMySQLConverterBase.set_charset@sL���,�,�	��G��	"�"�D�L�L�"�D�L�&�7���E�E�a�H����rc��||_dS)zSet whether to use UnicodeN)r�r�values  r�set_unicodezMySQLConverterBase.set_unicodeKs�� ����rc��|jj���}	t|d|�d���|��S#t$r|cYSwxYw)�!Convert Python data type to MySQL�_�	_to_mysql)�	__class__�__name__�lower�getattr�AttributeError�rr!�	type_names   r�to_mysqlzMySQLConverterBase.to_mysqlOsg���O�,�2�2�4�4�	�	�:�7�4�!9�Y�!9�!9�!9�:�:�5�A�A�A���	�	�	��L�L�L�	���s�=�A�Ac��|dks|�|dtjkrdS|jspi|_tj���D]J\}}	t|d|����d���|j|d<�;#t$rY�GwxYw	|j|d||��S#t$r|cYSwxYw)�!Convert MySQL data type to Python�Nrr%�
_to_pythonr)	r�BITr�desc�itemsr*r)r+�KeyError)r�vtyper!�name�infos     r�	to_pythonzMySQLConverterBase.to_pythonWs��
�W��	��	�5��8�y�}�3L�	��4��&�		�&(�D�#�'�n�2�2�4�4�
�
�
��d��7>��:�$�*�*�,�,�:�:�:�8�8�D�+�D��G�4�4��&�����D�����	�4�4�*�5��8�4�U�E�B�B�B���	�	�	��L�L�L�	���s$�4B�
B�B�B6�6C�Cc��|S)z"Escape buffer for sending to MySQL��r!s r�escapezMySQLConverterBase.escapen�	���rc� �t|��S)z!Quote buffer for sending to MySQL��str��bufs r�quotezMySQLConverterBase.quotess���3�x�x�rN)rTF)T)r(�
__module__�__qualname__�__doc__rrr"r.r:�staticmethodr>rEr<rrrr.s���������	%�	%�	%�	%�	I�	I�	I�!�!�!�!�������.����\������\���rrc��eZdZdZd&d�Zed���Zed���Zd�Zd	�Z	ed
���Z
ed���Zed���Zd
�Z
d�Zed���Zed���Zed���Zed���Zed���Zed���Zed���Zed���Zed���Zed���Zd�Zed'd���ZeZed'd���ZeZeZeZeZ eZ!d'd�Z"e"Z#ed'd���Z$ed'd���Z%ed'd���Z&e&Z'ed'd ���Z(ed'd!���Z)e)Z*ed'd"���Z+d'd#�Z,d'd$�Z-e-Z.e-Z/d'd%�Z0e0Z1e0Z2e0Z3dS)(�MySQLConvertera�Default conversion class for MySQL Connector/Python.

     o escape method: for escaping values send to MySQL
     o quoting method: for quoting values send to MySQL in statements
     o conversion mapping: maps Python and MySQL data types to
       function for converting them.

    Whenever one needs to convert values differently, a converter_class
    argument can be given while instantiating a new connection like
    cnx.connect(converter_class=CustomMySQLConverterClass).

    NTFc�N�t�||||��i|_dS�N)rrrrs    rrzMySQLConverter.__init__�s*���#�#�D�'�;��M�M�M�"$����rc��|�|St|t��r|St|ttf��r�|�dd��}|�dd��}|�dd��}|�dd	��}|�d
d��}|�dd
��}n�|�dd��}|�dd��}|�dd��}|�dd��}|�dd��}|�dd��}|S)z�
        Escapes special characters as they are expected to by when MySQL
        receives them.
        As found in MySQL source mysys/charset.c

        Returns the value if not a string, or the escaped string.
        N�\s\\�
s\n�
s\r�'s\'�"s\"�s\�\z\\�
z\n�
z\r�'z\'�"z\"�z\)�
isinstancer	�bytes�	bytearray�replacer=s rr>zMySQLConverter.escape�s*���	��L��e�]�+�+�	��L��e�e�Y�/�0�0�
	6��M�M�%��1�1�E��M�M�%��0�0�E��M�M�%��0�0�E��M�M�'�;�7�7�E��M�M�'�;�7�7�E��M�M�'�;�7�7�E�E��M�M�$��/�/�E��M�M�$��.�.�E��M�M�$��.�.�E��M�M�&�*�5�5�E��M�M�&�*�5�5�E��M�M�&�*�5�5�E��rc���t|t��r"t|���d��St|t	d����rtd��Std|zdz��S)a
        Quote the parameters for commands. General rules:
          o numbers are returns as bytes using ascii codec
          o None is returned as bytearray(b'NULL')
          o Everything else is single quoted '<buf>'

        Returns a bytearray object.
        �asciiNsNULLrR)r[r	rB�encode�typer]rCs rrEzMySQLConverter.quote�sk���c�=�)�)�	,��s�8�8�?�?�7�+�+�+��c�4��:�:�&�&�	&��W�%�%�%�����d�*�+�+�+rc��|jj���}	t|d|�d���|��S#t$r?|jr#t
|�����cYStd|�d���d�wxYw)r$r%r&zPython 'z%' cannot be converted to a MySQL typeN)	r'r(r)r*r+rrBra�	TypeErrorr,s   rr.zMySQLConverter.to_mysql�s����O�,�2�2�4�4�	�	�:�7�4�!9�Y�!9�!9�!9�:�:�5�A�A�A���	�	�	�� �
+��5�z�z�(�(�*�*�*�*�*��K�9�K�K�K����
�	���s�=�2B�1Bc��|dkr|dtjkrdS|�dS|jspi|_tj���D]J\}}	t|d|����d���|j|d<�;#t$rY�GwxYw	|j|d||��S#t$r-	|�	d��cYS#t$r|cYcYSwxYwt$r!}t|�d|d�d���|�d}~wt$r!}t|�d|d�d���|�d}~wwxYw)	r0rrNr%r2�utf-8� (field �))
rr3rr4r5r*r)r+r6�decode�UnicodeDecodeError�
ValueErrorrd)rr7r!r8r9�errs      rr:zMySQLConverter.to_python�s����A�:�	�%��(�i�m�3�	��4��	��4��&�		�&(�D�#�'�n�2�2�4�4�
�
�
��d��7>��:�$�*�*�,�,�:�:�:�8�8�D�+�D��G�4�4��&�����D�����	B�4�4�*�5��8�4�U�E�B�B�B���	�	�	�
��|�|�G�,�,�,�,�,��%�
�
�
�������
�����	C�	C�	C���8�8�U�1�X�8�8�8�9�9�s�B������	B�	B�	B��s�7�7�E�!�H�7�7�7�8�8�c�A�����	B���sZ�4B
�

B�B�B8�8
E�C�E�C+�&E�*C+�+E�7D�
E� D<�<Ec� �t|��S�zConvert value to int��intr=s r�
_int_to_mysqlzMySQLConverter._int_to_mysql�����5�z�z�rc� �t|��Srnror=s r�_long_to_mysqlzMySQLConverter._long_to_mysql�rrrc�L�tj|��rdSt|��S)zConvert value to floatN)�math�isnan�floatr=s r�_float_to_mysqlzMySQLConverter._float_to_mysql�s'���:�e���	��4��U�|�|�rc�,�|�|��S)zConvert value to string)�_unicode_to_mysqlr s  r�
_str_to_mysqlzMySQLConverter._str_to_mysql�s���%�%�e�,�,�,rc���|j}|j}|dkrd}tj|��d}|�|��}|tjvrd|vrt
||��S|S)zConvert unicode�binaryrrrO)rrrrra�slash_charsetsr)rr!rr�encodeds     rr{z MySQLConverter._unicode_to_mysql�s{���,���_�
��h��	C��G�%�6�w�?�?��B�J��,�,�w�'�'����4�4�	2��'�!�
2�!�%��1�1�1��rc��|S�zConvert value to bytesr<r=s r�_bytes_to_mysqlzMySQLConverter._bytes_to_mysqlr?rc� �t|��Sr�)r\r=s r�_bytearray_to_mysqlz"MySQLConverter._bytearray_to_mysqls���U�|�|�rc��|rdSdS)zConvert value to booleanrrr<r=s r�_bool_to_mysqlzMySQLConverter._bool_to_mysqls���	��1��qrc��dS)z�
        This would return what None would be in MySQL, but instead we
        leave it None and return it right away. The actual conversion
        from None to NULL happens in the quoting functionality.

        Return None.
        Nr<r=s r�_nonetype_to_mysqlz!MySQLConverter._nonetype_to_mysqls	���trc	�P�|jrSd}|�|j|j|j|j|j|j|j���d��Sd}|�|j|j|j|j|j|j���d��S)z�
        Converts a datetime instance to a string suitable for MySQL.
        The returned string has format: %Y-%m-%d %H:%M:%S[.%f]

        If the instance isn't a datetime.datetime type, it return None.

        Returns a bytes.
        z7{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:06d}r`z/{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d})	�microsecond�format�year�month�day�hour�minute�secondra)r!�fmts  r�_datetime_to_mysqlz!MySQLConverter._datetime_to_mysql"s�����
	�K�C��:�:��
����	��
������!����f�W�o�o�
�@���z�z��J��K��I��J��L��L�

�
��&��/�/�	rc�`�|jd�d|jd�d|jd���d��S)z�
        Converts a date instance to a string suitable for MySQL.
        The returned string has format: %Y-%m-%d

        If the instance isn't a datetime.date type, it return None.

        Returns a bytes.
        �04d�-�02dr`)r�r�r�rar=s r�_date_to_mysqlzMySQLConverter._date_to_mysqlBs=���*�D�D�D�5�;�D�D�D�U�Y�D�D�D�K�K�G�T�T�Trc��|jr(|�d���d��S|�d���d��S)z�
        Converts a time instance to a string suitable for MySQL.
        The returned string has format: %H:%M:%S[.%f]

        If the instance isn't a datetime.time type, it return None.

        Returns a bytes.
        z%H:%M:%S.%fr`z%H:%M:%S)r��strftimerar=s r�_time_to_mysqlzMySQLConverter._time_to_mysqlNsP����	A��>�>�-�0�0�7�7��@�@�@��~�~�j�)�)�0�0��9�9�9rc�R�tjd|���d��S)z�
        Converts a time.struct_time sequence to a string suitable
        for MySQL.
        The returned string has format: %Y-%m-%d %H:%M:%S

        Returns a bytes or None when not valid.
        z%Y-%m-%d %H:%M:%Sr`)�timer�rar=s r�_struct_time_to_mysqlz$MySQLConverter._struct_time_to_mysql\s%���}�0�%�8�8�?�?��H�H�Hrc��t|jdz|jz��}|jr%d}|jdkrd|jz
}|dz}n
|j}nd}|jdkrd|z}t	|d��\}}t	|d	��\}}|jr|�||||��}n|�|||��}|�d
��S)z�
        Converts a timedelta instance to a string suitable for MySQL.
        The returned string has format: %H:%M:%S

        Returns a bytes.
        i�Qz{0:02d}:{1:02d}:{2:02d}.{3:06d}ri@Brz{0:02d}:{1:02d}:{2:02d}r�i�<r`)�abs�days�seconds�microseconds�divmodr�ra)	r!r�r��mcs�hours�	remainder�mins�secs�results	         r�_timedelta_to_mysqlz"MySQLConverter._timedelta_to_mysqlgs����e�j�5�(�5�=�8�9�9����	,�3�C��z�A�~�
)��� 2�2���1�����(���+�C��:��>�	���)�C�#�G�T�2�2���	��i��,�,���t���	3��Z�Z��t�T�3�7�7�F�F��Z�Z��t�T�2�2�F��}�}�W�%�%�%rc�t�t|t��r"t|���d��SdS)z�
        Converts a decimal.Decimal instance to a string suitable for
        MySQL.

        Returns a bytes or None when not valid.
        r`N)r[rrBrar=s r�_decimal_to_mysqlz MySQLConverter._decimal_to_mysql�s5���e�W�%�%�	.��u�:�:�$�$�W�-�-�-��trc���d}dgt|��z}|jspi|_tj���D]J\}}	t|d|����d���|j|d<�;#t$rY�GwxYw|D]�}|d}||dkr|tjks||�|dz
}�4	|j||||��||<ns#t$r>	||�
d��||<n#t$r||||<YnwxYwYn,ttf$r}	|	�d|d�d�|	_�d}	~	wwxYw|dz
}��t|��S)	a Convert a MySQL text result row to Python types

        The row argument is a sequence containing text result returned
        by a MySQL server. Each value of the row is converted to the
        using the field type information in the fields argument.

        Returns a tuple.
        rNr%r2rrfrgrh)�lenrrr4r5r*r)r+r3r6rirjrkrd�message�tuple)
r�row�fields�ir�r8r9�field�
field_typerls
          r�
row_to_pythonzMySQLConverter.row_to_python�s���
����#�f�+�+�%���&�		�&(�D�#�'�n�2�2�4�4�
�
�
��d��7>��:�$�*�*�,�,�:�:�:�8�8�D�+�D��G�4�4��&�����D������	�	�E��q��J��A��!��
�
�i�m� ;�
��A��
��Q����

�?�D�3�J�?��A���N�N��q�	�	���
'�
'�
'�'� #�A��
�
�g� 6� 6�F�1�I�I��)�'�'�'� #�A��F�1�I�I�I�'�������	�*�
�
�
�!$�9�9�e�A�h�9�9�9��������
����
��F�A�A��V�}�}�sT�4A=�=
B
�	B
� C%�%
E�0D�E�D'�$E�&D'�'E�,E�<E�Ec� �t|��S)z.
        Returns value as float type.
        )rx�r!r4s  r�_float_to_pythonzMySQLConverter._float_to_python�s��
�U�|�|�rc� �t|��S)z,
        Returns value as int type.
        ror�s  r�_int_to_pythonzMySQLConverter._int_to_python����
�5�z�z�rc�T�|�|j��}t|��S)z5
        Returns value as a decimal.Decimal.
        )rirr)rr!r4�vals    r�_decimal_to_pythonz!MySQLConverter._decimal_to_python�s#���l�l�4�<�(�(���s�|�|�rc� �t|��S)z,
        Returns value as str type.
        rAr�s  r�_strzMySQLConverter._str�r�rc��|}t|��dkrddt|��z
z|z}tjd|��dS)z!Returns BIT columntype as integer�r1z>Qr)r��struct�unpack)r!�dsc�int_vals   r�_bit_to_pythonzMySQLConverter._bit_to_python�sM�����w�<�<�!��	=���S��\�\�!1�2�W�<�G��}�T�7�+�+�A�.�.rc���t|tj��r|S	|�d��}t	|��dkr"td|�dt	|�������	tjt
|d��t
|d��t
|d����S#t
$rYdSwxYw#tt
f$rtd	|�d
���d�wxYw)z�Converts TIME column MySQL to a python datetime.datetime type.

        Raises ValueError if the value can not be converted.

        Returns DATE column type as datetime.date type.
        �-��invalid datetime format: � len: rr�NzCould not convert z to python datetime.timedelta)r[�datetime�date�splitr�rkrp�
IndexError)r!r��partss   r�_date_to_pythonzMySQLConverter._date_to_python�s���e�X�]�+�+�	��L�	��K�K��%�%�E��5�z�z�Q��
X� �!V�U�!V�!V�#�e�*�*�!V�!V�W�W�W�
��}�S��q��]�]�C��a��M�M�3�u�Q�x�=�=�Q�Q�Q���
�
�
��t�t�
������J�'�	�	�	��I�U�I�I�I����
�	���s+�A
C	�)AB8�8
C�C	�C�C	�	&C/c��	|�d��\}}t|�dd����}n#ttf$r|}d}YnwxYw	d�|�d��D��\}}}|ddks|ddkr	|||}}}tj||||�	��S#tttf$r+t	t�	|d
�����d�wxYw)
aConverts TIME column value to python datetime.time value type.

        Converts the TIME column MySQL type passed as bytes to a python
        datetime.datetime type.

        Raises ValueError if the value can not be converted.

        Returns datetime.time type.
        �.��0rc�,�g|]}t|����Sr<ro)�.0�ds  r�
<listcomp>z2MySQLConverter._time_to_python.<locals>.<listcomp>s��"C�"C�"C�a�3�q�6�6�"C�"C�"Cr�:�-r�)r��minutesr�r��datetime.timedelta�r!�pytypeN)
r�rp�ljustrdrkr��	timedeltar��
CONVERT_ERRORr�)r!r��hmsr�r�r�r�s       r�_time_to_pythonzMySQLConverter._time_to_pythons5��	����T�*�*�J�S�#��c�i�i��4�(�(�)�)�C�C���:�&�	�	�	��C��C�C�C�	����
	�"C�"C�3�9�9�T�?�?�"C�"C�"C��U�D�$��Q�x�2�~�
5��q��S��
5�#'�%�$����C�d���%��T�4�c����
���I�z�2�	�	�	���$�$�5�9M�$�N�N����
�	���s�;>�A�A�AB6�6AC8c���t|tj��r|Sd}	|�d��\}}t|��dkr<|�d��\}}t	|�dd����}n|}d}d�|�d	��D��d
�|�d��D��z|gz}t|��dkr"t
d|�d
t|�������	tj|�}n#t$rYdSwxYwn?#ttf$r+t
t�
|d�����d�wxYw|S)z�Converts DATETIME column value to python datetime.time value type.

        Converts the DATETIME column MySQL type passed as bytes to a python
        datetime.datetime type.

        Returns: datetime.datetime type.
        N� r�r�r�r�rc�,�g|]}t|����Sr<ro�r�r�s  rr�z6MySQLConverter._datetime_to_python.<locals>.<listcomp>>s��3�3�3�A��Q���3�3�3rr�c�,�g|]}t|����Sr<ror�s  rr�z6MySQLConverter._datetime_to_python.<locals>.<listcomp>?s��3�3�3�a�3�q�6�6�3�3�3rr�r�r�r�r�)r[r�r�r�rpr�rkr�rdr�r�)r!r��datetime_val�date_�time_r�r��dtvals        r�_datetime_to_pythonz"MySQLConverter._datetime_to_python)s����e�X�.�/�/�	��L���	�"�[�[��.�.�N�U�E��5�z�z�A�~�
�"�[�[��.�.�
��c��#�)�)�A�t�,�,�-�-�������3�3����T�!2�!2�3�3�3�3�3�3�9�9�T�?�?�3�3�3�4����
��5�z�z�A�~�
X� �!V�U�!V�!V�#�e�*�*�!V�!V�W�W�W�

�'�0�%�8�����
�
�
��t�t�
�������I�&�	�	�	���$�$�5�9M�$�N�N����
�	����
�s0�C#D%�D�D%�
D!�D%� D!�!D%�%<E!c�t�	t|��}n&#t$r}td|�d���|�d}~wwxYw|S)z#Returns YEAR column type as integerzFailed converting YEAR to int (rhN)rprk)r!r4r�rls    r�_year_to_pythonzMySQLConverter._year_to_pythonWs[��	R��u�:�:�D�D���	R�	R�	R��G�u�G�G�G�H�H�c�Q�����	R�����s��
5�0�5c���d}|�|j��}|st��S	t|�d����}n&#t$r}t	d|�d���|�d}~wwxYw|S)z�Returns SET column type as set

        Actually, MySQL protocol sees a SET as a string type field. So this
        code isn't called directly, but used by STRING_to_python() method.

        Returns SET column type as a set.
        N�,zCould not convert set z to a sequence)rir�setr�rk)rr!r��set_typer�rls      r�_set_to_pythonzMySQLConverter._set_to_pythonas������l�l�4�<�(�(���	��5�5�L�	V��3�9�9�S�>�>�*�*�H�H���	V�	V�	V��K�e�K�K�K�L�L�RU�U�����	V�����s�"A�
A4�A/�/A4c��|jdkr|S|�p|dtjkr!|jr|�|j��S|dt
jzr|�||��S|ddkr|St|ttf��r4|jr-	|�|j��S#t$r|cYSwxYw|S)z�
        Note that a SET is a string too, but using the FieldFlag we can see
        whether we have to split it.

        Returns string typed columns as string type.
        r~Nr�r��?)rr�JSONrrir�SETr�r[r\r]rj�rr!r�s   r�_string_to_pythonz MySQLConverter._string_to_pythonss����<�8�#�	��L��	��1�v���'�
2�D�,<�
2��|�|�D�L�1�1�1��1�v�	�
�%�
7��*�*�5�#�6�6�6��1�v��|�
����e�e�Y�/�0�0�	�T�5E�	�
��|�|�D�L�1�1�1��%�
�
�
�����
�����s�$B>�>C
�C
c��|�E|dtjzr0|dtjzr|ddkrt|��S|�||��S)z!Convert BLOB data type to Python.Nr�r�r�)r�BLOB�BINARYr\rrs   r�_blob_to_pythonzMySQLConverter._blob_to_python�sg���	$��A����'�
$���F�Y�-�-�
$���F�b�L�
$�
�U�|�|�#��%�%�e�S�1�1�1r)NTFrM)4r(rFrGrHrrIr>rEr.r:rqrtryr|r{r�r�r�r�r�r�r�r�r�r�r�r��_double_to_pythonr��_tiny_to_python�_short_to_python�_int24_to_python�_long_to_python�_longlong_to_pythonr��_newdecimal_to_pythonr�r�r��_NEWDATE_to_pythonr�r��_timestamp_to_pythonr�r�r�_var_string_to_python�_json_to_pythonr�_long_blob_to_python�_medium_blob_to_python�_tiny_blob_to_pythonr<rrrKrKys���������%�%�%�%�����\��8�
,�
,��\�
,�
�
�
�B�B�B�@����\������\������\��-�-�-��������\������\������\������\������\��>�	U�	U��\�	U��:�:��\�:��I�I��\�I��&�&��\�&�@�
�
��\�
�-�-�-�`�����\��)�������\��%�O�%��%��$�O�(������/�������\���/�/�/��\�/������\��,)�������\��8�)�)�)��\�)�V/�������\������$����0.��'�O�	2�	2�	2�	2�+��,��*���rrK)rHr�rvr�r��decimalr�	constantsrrr�custom_typesr�utilsr	r�rrKr<rr�<module>rs���:����������
�
�
�
�����������9�9�9�9�9�9�9�9�9�9�$�$�$�$�$�$� � � � � � �@�
�H�H�H�H�H�H�H�H�Vb+�b+�b+�b+�b+�'�b+�b+�b+�b+�b+r