zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""
Type hint aliases hub
"""
import os
 
from datetime import date, datetime, time, timedelta
from decimal import Decimal
from time import struct_time
from typing import (
    TYPE_CHECKING,
    Dict,
    List,
    Mapping,
    Optional,
    Sequence,
    Set,
    Tuple,
    Union,
)
 
if TYPE_CHECKING:
    from .custom_types import HexLiteral
    from .network import MySQLTCPSocket, MySQLUnixSocket
 
 
StrOrBytes = Union[str, bytes]
StrOrBytesPath = Union[StrOrBytes, os.PathLike]
 
 
""" Conversion """
ToPythonOutputTypes = Optional[
    Union[
        float,
        int,
        Decimal,
        StrOrBytes,
        date,
        timedelta,
        datetime,
        Set[str],
    ]
]
ToMysqlInputTypes = Optional[
    Union[
        int,
        float,
        Decimal,
        StrOrBytes,
        bool,
        datetime,
        date,
        time,
        struct_time,
        timedelta,
    ]
]
ToMysqlOutputTypes = Optional[Union[int, float, bytes, "HexLiteral"]]
 
 
""" Network """
SocketType = Union["MySQLUnixSocket", "MySQLTCPSocket"]
 
 
""" Protocol """
HandShakeType = Dict[str, Optional[Union[int, StrOrBytes]]]
OkPacketType = Dict[str, Optional[Union[int, str]]]
EofPacketType = OkPacketType
StatsPacketType = Dict[str, Union[int, Decimal]]
SupportedMysqlBinaryProtocolTypes = Optional[
    Union[int, StrOrBytes, Decimal, float, datetime, date, timedelta, time]
]
QueryAttrType = List[
    # 2-Tuple: (str, attr_types)
    Tuple[str, SupportedMysqlBinaryProtocolTypes]
]
ParseValueFromBinaryResultPacketTypes = Optional[
    Union[
        int,
        float,
        Decimal,
        date,
        datetime,
        timedelta,
        str,
    ]
]
DescriptionType = Tuple[
    # Sometimes it can be represented as a 2-Tuple of the form:
    # Tuple[str, int],  # field name, field type,
    # but we will stick with the 9-Tuple format produced by
    # the protocol module.
    str,  # field name
    int,  # field type
    None,  # you can ignore it or take a look at protocol.parse_column()
    None,
    None,
    None,
    Union[bool, int],  # null ok
    int,  # field flags
    int,  # MySQL charset ID
]
 
 
""" Connection """
ConnAttrsType = Dict[str, Optional[Union[str, Tuple[str, str]]]]
ResultType = Mapping[
    str, Optional[Union[int, str, EofPacketType, List[DescriptionType]]]
]
 
 
""" Connection C-EXT """
CextEofPacketType = Dict[str, int]
CextResultType = Dict[str, Union[CextEofPacketType, List[DescriptionType]]]
 
 
""" Cursor """
ParamsSequenceType = Sequence[ToMysqlInputTypes]
ParamsDictType = Dict[str, ToMysqlInputTypes]
ParamsSequenceOrDictType = Union[ParamsDictType, ParamsSequenceType]
RowType = Tuple[ToPythonOutputTypes, ...]
WarningType = Tuple[str, int, str]