Package web2py :: Package gluon :: Package contrib :: Package pymysql
[hide private]
[frames] | no frames]

Source Code for Package web2py.gluon.contrib.pymysql

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