Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pymysql/__init__.py: 74%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2PyMySQL: A pure-Python MySQL client library.
4Copyright (c) 2010-2016 PyMySQL contributors
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22THE SOFTWARE.
23"""
25import sys
27from .constants import FIELD_TYPE
28from .err import (
29 Warning,
30 Error,
31 InterfaceError,
32 DataError,
33 DatabaseError,
34 OperationalError,
35 IntegrityError,
36 InternalError,
37 NotSupportedError,
38 ProgrammingError,
39 MySQLError,
40)
41from .times import (
42 Date,
43 Time,
44 Timestamp,
45 DateFromTicks,
46 TimeFromTicks,
47 TimestampFromTicks,
48)
50# PyMySQL version.
51# Used by setuptools and connection_attrs
52VERSION = (1, 1, 2, "final")
53VERSION_STRING = "1.1.2"
55### for mysqlclient compatibility
56### Django checks mysqlclient version.
57version_info = (1, 4, 6, "final", 1)
58__version__ = "1.4.6"
61def get_client_info(): # for MySQLdb compatibility
62 return __version__
65def install_as_MySQLdb():
66 """
67 After this function is called, any application that imports MySQLdb
68 will unwittingly actually use pymysql.
69 """
70 sys.modules["MySQLdb"] = sys.modules["pymysql"]
73# end of mysqlclient compatibility code
75threadsafety = 1
76apilevel = "2.0"
77paramstyle = "pyformat"
79from . import connections # noqa: E402
82class DBAPISet(frozenset):
83 def __ne__(self, other):
84 if isinstance(other, set):
85 return frozenset.__ne__(self, other)
86 else:
87 return other not in self
89 def __eq__(self, other):
90 if isinstance(other, frozenset):
91 return frozenset.__eq__(self, other)
92 else:
93 return other in self
95 def __hash__(self):
96 return frozenset.__hash__(self)
99STRING = DBAPISet([FIELD_TYPE.ENUM, FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING])
100BINARY = DBAPISet(
101 [
102 FIELD_TYPE.BLOB,
103 FIELD_TYPE.LONG_BLOB,
104 FIELD_TYPE.MEDIUM_BLOB,
105 FIELD_TYPE.TINY_BLOB,
106 ]
107)
108NUMBER = DBAPISet(
109 [
110 FIELD_TYPE.DECIMAL,
111 FIELD_TYPE.DOUBLE,
112 FIELD_TYPE.FLOAT,
113 FIELD_TYPE.INT24,
114 FIELD_TYPE.LONG,
115 FIELD_TYPE.LONGLONG,
116 FIELD_TYPE.TINY,
117 FIELD_TYPE.YEAR,
118 ]
119)
120DATE = DBAPISet([FIELD_TYPE.DATE, FIELD_TYPE.NEWDATE])
121TIME = DBAPISet([FIELD_TYPE.TIME])
122TIMESTAMP = DBAPISet([FIELD_TYPE.TIMESTAMP, FIELD_TYPE.DATETIME])
123DATETIME = TIMESTAMP
124ROWID = DBAPISet()
127def Binary(x):
128 """Return x as a binary type."""
129 return bytes(x)
132def thread_safe():
133 return True # match MySQLdb.thread_safe()
136Connect = connect = Connection = connections.Connection
137NULL = "NULL"
140__all__ = [
141 "BINARY",
142 "Binary",
143 "Connect",
144 "Connection",
145 "DATE",
146 "Date",
147 "Time",
148 "Timestamp",
149 "DateFromTicks",
150 "TimeFromTicks",
151 "TimestampFromTicks",
152 "DataError",
153 "DatabaseError",
154 "Error",
155 "FIELD_TYPE",
156 "IntegrityError",
157 "InterfaceError",
158 "InternalError",
159 "MySQLError",
160 "NULL",
161 "NUMBER",
162 "NotSupportedError",
163 "DBAPISet",
164 "OperationalError",
165 "ProgrammingError",
166 "ROWID",
167 "STRING",
168 "TIME",
169 "TIMESTAMP",
170 "Warning",
171 "apilevel",
172 "connect",
173 "connections",
174 "constants",
175 "converters",
176 "cursors",
177 "get_client_info",
178 "paramstyle",
179 "threadsafety",
180 "version_info",
181 "install_as_MySQLdb",
182 "__version__",
183]