__init__.py 4.2 KB

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