File: MySQLdb.py

package info (click to toggle)
python-eventlet 0.40.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,200 kB
  • sloc: python: 25,101; sh: 78; makefile: 31
file content (40 lines) | stat: -rw-r--r-- 1,196 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
__MySQLdb = __import__('MySQLdb')

__all__ = __MySQLdb.__all__
__patched__ = ["connect", "Connect", 'Connection', 'connections']

from eventlet.patcher import slurp_properties
slurp_properties(
    __MySQLdb, globals(),
    ignore=__patched__, srckeys=dir(__MySQLdb))

from eventlet import tpool

__orig_connections = __import__('MySQLdb.connections').connections


def Connection(*args, **kw):
    conn = tpool.execute(__orig_connections.Connection, *args, **kw)
    return tpool.Proxy(conn, autowrap_names=('cursor',))


connect = Connect = Connection


# replicate the MySQLdb.connections module but with a tpooled Connection factory
class MySQLdbConnectionsModule:
    pass


connections = MySQLdbConnectionsModule()
for var in dir(__orig_connections):
    if not var.startswith('__'):
        setattr(connections, var, getattr(__orig_connections, var))
connections.Connection = Connection

cursors = __import__('MySQLdb.cursors').cursors
converters = __import__('MySQLdb.converters').converters

# TODO support instantiating cursors.FooCursor objects directly
# TODO though this is a low priority, it would be nice if we supported
# subclassing eventlet.green.MySQLdb.connections.Connection