PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/testClient/pymysql/__init__.py

https://github.com/flavioruiz/CloudStack
Python | 131 lines | 125 code | 0 blank | 6 comment | 0 complexity | 6b6fae7d580e74ae89291a36d4cd14d0 MD5 | raw file
  1. '''
  2. PyMySQL: A pure-Python drop-in replacement for MySQLdb.
  3. Copyright (c) 2010 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. VERSION = (0, 4, None)
  21. from constants import FIELD_TYPE
  22. from converters import escape_dict, escape_sequence, escape_string
  23. from err import Warning, Error, InterfaceError, DataError, \
  24. DatabaseError, OperationalError, IntegrityError, InternalError, \
  25. NotSupportedError, ProgrammingError, MySQLError
  26. from times import Date, Time, Timestamp, \
  27. DateFromTicks, TimeFromTicks, TimestampFromTicks
  28. import sys
  29. try:
  30. frozenset
  31. except NameError:
  32. from sets import ImmutableSet as frozenset
  33. try:
  34. from sets import BaseSet as set
  35. except ImportError:
  36. from sets import Set as set
  37. threadsafety = 1
  38. apilevel = "2.0"
  39. paramstyle = "format"
  40. class DBAPISet(frozenset):
  41. def __ne__(self, other):
  42. if isinstance(other, set):
  43. return super(DBAPISet, self).__ne__(self, other)
  44. else:
  45. return other not in self
  46. def __eq__(self, other):
  47. if isinstance(other, frozenset):
  48. return frozenset.__eq__(self, other)
  49. else:
  50. return other in self
  51. def __hash__(self):
  52. return frozenset.__hash__(self)
  53. STRING = DBAPISet([FIELD_TYPE.ENUM, FIELD_TYPE.STRING,
  54. FIELD_TYPE.VAR_STRING])
  55. BINARY = DBAPISet([FIELD_TYPE.BLOB, FIELD_TYPE.LONG_BLOB,
  56. FIELD_TYPE.MEDIUM_BLOB, FIELD_TYPE.TINY_BLOB])
  57. NUMBER = DBAPISet([FIELD_TYPE.DECIMAL, FIELD_TYPE.DOUBLE, FIELD_TYPE.FLOAT,
  58. FIELD_TYPE.INT24, FIELD_TYPE.LONG, FIELD_TYPE.LONGLONG,
  59. FIELD_TYPE.TINY, FIELD_TYPE.YEAR])
  60. DATE = DBAPISet([FIELD_TYPE.DATE, FIELD_TYPE.NEWDATE])
  61. TIME = DBAPISet([FIELD_TYPE.TIME])
  62. TIMESTAMP = DBAPISet([FIELD_TYPE.TIMESTAMP, FIELD_TYPE.DATETIME])
  63. DATETIME = TIMESTAMP
  64. ROWID = DBAPISet()
  65. def Binary(x):
  66. """Return x as a binary type."""
  67. return str(x)
  68. def Connect(*args, **kwargs):
  69. """
  70. Connect to the database; see connections.Connection.__init__() for
  71. more information.
  72. """
  73. from connections import Connection
  74. return Connection(*args, **kwargs)
  75. def get_client_info(): # for MySQLdb compatibility
  76. return '%s.%s.%s' % VERSION
  77. connect = Connection = Connect
  78. # we include a doctored version_info here for MySQLdb compatibility
  79. version_info = (1,2,2,"final",0)
  80. NULL = "NULL"
  81. __version__ = get_client_info()
  82. def thread_safe():
  83. return True # match MySQLdb.thread_safe()
  84. def install_as_MySQLdb():
  85. """
  86. After this function is called, any application that imports MySQLdb or
  87. _mysql will unwittingly actually use
  88. """
  89. sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"]
  90. __all__ = [
  91. 'BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'Date',
  92. 'Time', 'Timestamp', 'DateFromTicks', 'TimeFromTicks', 'TimestampFromTicks',
  93. 'DataError', 'DatabaseError', 'Error', 'FIELD_TYPE', 'IntegrityError',
  94. 'InterfaceError', 'InternalError', 'MySQLError', 'NULL', 'NUMBER',
  95. 'NotSupportedError', 'DBAPISet', 'OperationalError', 'ProgrammingError',
  96. 'ROWID', 'STRING', 'TIME', 'TIMESTAMP', 'Warning', 'apilevel', 'connect',
  97. 'connections', 'constants', 'converters', 'cursors',
  98. 'escape_dict', 'escape_sequence', 'escape_string', 'get_client_info',
  99. 'paramstyle', 'threadsafety', 'version_info',
  100. "install_as_MySQLdb",
  101. "NULL","__version__",
  102. ]