Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pymysql/__init__.py: 74%

42 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-25 06:28 +0000

1""" 

2PyMySQL: A pure-Python MySQL client library. 

3 

4Copyright (c) 2010-2016 PyMySQL contributors 

5 

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: 

12 

13The above copyright notice and this permission notice shall be included in 

14all copies or substantial portions of the Software. 

15 

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""" 

24import sys 

25 

26from .constants import FIELD_TYPE 

27from .err import ( 

28 Warning, 

29 Error, 

30 InterfaceError, 

31 DataError, 

32 DatabaseError, 

33 OperationalError, 

34 IntegrityError, 

35 InternalError, 

36 NotSupportedError, 

37 ProgrammingError, 

38 MySQLError, 

39) 

40from .times import ( 

41 Date, 

42 Time, 

43 Timestamp, 

44 DateFromTicks, 

45 TimeFromTicks, 

46 TimestampFromTicks, 

47) 

48 

49# PyMySQL version. 

50# Used by setuptools and connection_attrs 

51VERSION = (1, 1, 0, "final", 1) 

52VERSION_STRING = "1.1.0" 

53 

54### for mysqlclient compatibility 

55### Django checks mysqlclient version. 

56version_info = (1, 4, 6, "final", 1) 

57__version__ = "1.4.6" 

58 

59 

60def get_client_info(): # for MySQLdb compatibility 

61 return __version__ 

62 

63 

64def install_as_MySQLdb(): 

65 """ 

66 After this function is called, any application that imports MySQLdb 

67 will unwittingly actually use pymysql. 

68 """ 

69 sys.modules["MySQLdb"] = sys.modules["pymysql"] 

70 

71 

72# end of mysqlclient compatibility code 

73 

74threadsafety = 1 

75apilevel = "2.0" 

76paramstyle = "pyformat" 

77 

78from . import connections # noqa: E402 

79 

80 

81class DBAPISet(frozenset): 

82 def __ne__(self, other): 

83 if isinstance(other, set): 

84 return frozenset.__ne__(self, other) 

85 else: 

86 return other not in self 

87 

88 def __eq__(self, other): 

89 if isinstance(other, frozenset): 

90 return frozenset.__eq__(self, other) 

91 else: 

92 return other in self 

93 

94 def __hash__(self): 

95 return frozenset.__hash__(self) 

96 

97 

98STRING = DBAPISet([FIELD_TYPE.ENUM, FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING]) 

99BINARY = DBAPISet( 

100 [ 

101 FIELD_TYPE.BLOB, 

102 FIELD_TYPE.LONG_BLOB, 

103 FIELD_TYPE.MEDIUM_BLOB, 

104 FIELD_TYPE.TINY_BLOB, 

105 ] 

106) 

107NUMBER = DBAPISet( 

108 [ 

109 FIELD_TYPE.DECIMAL, 

110 FIELD_TYPE.DOUBLE, 

111 FIELD_TYPE.FLOAT, 

112 FIELD_TYPE.INT24, 

113 FIELD_TYPE.LONG, 

114 FIELD_TYPE.LONGLONG, 

115 FIELD_TYPE.TINY, 

116 FIELD_TYPE.YEAR, 

117 ] 

118) 

119DATE = DBAPISet([FIELD_TYPE.DATE, FIELD_TYPE.NEWDATE]) 

120TIME = DBAPISet([FIELD_TYPE.TIME]) 

121TIMESTAMP = DBAPISet([FIELD_TYPE.TIMESTAMP, FIELD_TYPE.DATETIME]) 

122DATETIME = TIMESTAMP 

123ROWID = DBAPISet() 

124 

125 

126def Binary(x): 

127 """Return x as a binary type.""" 

128 return bytes(x) 

129 

130 

131def thread_safe(): 

132 return True # match MySQLdb.thread_safe() 

133 

134 

135Connect = connect = Connection = connections.Connection 

136NULL = "NULL" 

137 

138 

139__all__ = [ 

140 "BINARY", 

141 "Binary", 

142 "Connect", 

143 "Connection", 

144 "DATE", 

145 "Date", 

146 "Time", 

147 "Timestamp", 

148 "DateFromTicks", 

149 "TimeFromTicks", 

150 "TimestampFromTicks", 

151 "DataError", 

152 "DatabaseError", 

153 "Error", 

154 "FIELD_TYPE", 

155 "IntegrityError", 

156 "InterfaceError", 

157 "InternalError", 

158 "MySQLError", 

159 "NULL", 

160 "NUMBER", 

161 "NotSupportedError", 

162 "DBAPISet", 

163 "OperationalError", 

164 "ProgrammingError", 

165 "ROWID", 

166 "STRING", 

167 "TIME", 

168 "TIMESTAMP", 

169 "Warning", 

170 "apilevel", 

171 "connect", 

172 "connections", 

173 "constants", 

174 "converters", 

175 "cursors", 

176 "get_client_info", 

177 "paramstyle", 

178 "threadsafety", 

179 "version_info", 

180 "install_as_MySQLdb", 

181 "__version__", 

182]