source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/gluon/contrib/pymysql/__init__.py

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 4.4 KB
Line 
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 ._compat import PY2
27from .constants import FIELD_TYPE
28from .converters import escape_dict, escape_sequence, escape_string
29from .err import (
30    Warning, Error, InterfaceError, DataError,
31    DatabaseError, OperationalError, IntegrityError, InternalError,
32    NotSupportedError, ProgrammingError, MySQLError)
33from .times import (
34    Date, Time, Timestamp,
35    DateFromTicks, TimeFromTicks, TimestampFromTicks)
36
37
38VERSION = (0, 7, 9, None)
39threadsafety = 1
40apilevel = "2.0"
41paramstyle = "pyformat"
42
43
44class DBAPISet(frozenset):
45
46    def __ne__(self, other):
47        if isinstance(other, set):
48            return frozenset.__ne__(self, other)
49        else:
50            return other not in self
51
52    def __eq__(self, other):
53        if isinstance(other, frozenset):
54            return frozenset.__eq__(self, other)
55        else:
56            return other in self
57
58    def __hash__(self):
59        return frozenset.__hash__(self)
60
61
62STRING    = DBAPISet([FIELD_TYPE.ENUM, FIELD_TYPE.STRING,
63                     FIELD_TYPE.VAR_STRING])
64BINARY    = DBAPISet([FIELD_TYPE.BLOB, FIELD_TYPE.LONG_BLOB,
65                     FIELD_TYPE.MEDIUM_BLOB, FIELD_TYPE.TINY_BLOB])
66NUMBER    = DBAPISet([FIELD_TYPE.DECIMAL, FIELD_TYPE.DOUBLE, FIELD_TYPE.FLOAT,
67                     FIELD_TYPE.INT24, FIELD_TYPE.LONG, FIELD_TYPE.LONGLONG,
68                     FIELD_TYPE.TINY, FIELD_TYPE.YEAR])
69DATE      = DBAPISet([FIELD_TYPE.DATE, FIELD_TYPE.NEWDATE])
70TIME      = DBAPISet([FIELD_TYPE.TIME])
71TIMESTAMP = DBAPISet([FIELD_TYPE.TIMESTAMP, FIELD_TYPE.DATETIME])
72DATETIME  = TIMESTAMP
73ROWID     = DBAPISet()
74
75
76def Binary(x):
77    """Return x as a binary type."""
78    if PY2:
79        return bytearray(x)
80    else:
81        return bytes(x)
82
83
84def Connect(*args, **kwargs):
85    """
86    Connect to the database; see connections.Connection.__init__() for
87    more information.
88    """
89    from .connections import Connection
90    return Connection(*args, **kwargs)
91
92from . import connections as _orig_conn
93if _orig_conn.Connection.__init__.__doc__ is not None:
94    Connect.__doc__ = _orig_conn.Connection.__init__.__doc__
95del _orig_conn
96
97
98def get_client_info():  # for MySQLdb compatibility
99    return '.'.join(map(str, VERSION))
100
101connect = Connection = Connect
102
103# we include a doctored version_info here for MySQLdb compatibility
104version_info = (1,2,6,"final",0)
105
106NULL = "NULL"
107
108__version__ = get_client_info()
109
110def thread_safe():
111    return True  # match MySQLdb.thread_safe()
112
113def install_as_MySQLdb():
114    """
115    After this function is called, any application that imports MySQLdb or
116    _mysql will unwittingly actually use
117    """
118    sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"]
119
120
121__all__ = [
122    'BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'Date',
123    'Time', 'Timestamp', 'DateFromTicks', 'TimeFromTicks', 'TimestampFromTicks',
124    'DataError', 'DatabaseError', 'Error', 'FIELD_TYPE', 'IntegrityError',
125    'InterfaceError', 'InternalError', 'MySQLError', 'NULL', 'NUMBER',
126    'NotSupportedError', 'DBAPISet', 'OperationalError', 'ProgrammingError',
127    'ROWID', 'STRING', 'TIME', 'TIMESTAMP', 'Warning', 'apilevel', 'connect',
128    'connections', 'constants', 'converters', 'cursors',
129    'escape_dict', 'escape_sequence', 'escape_string', 'get_client_info',
130    'paramstyle', 'threadsafety', 'version_info',
131
132    "install_as_MySQLdb",
133    "NULL", "__version__",
134]
Note: See TracBrowser for help on using the repository browser.