Add python-eventlet 0.16.1
[packages/trusty/python-eventlet.git] / eventlet / eventlet / green / MySQLdb.py
1 __MySQLdb = __import__('MySQLdb')
2
3 __all__ = __MySQLdb.__all__
4 __patched__ = ["connect", "Connect", 'Connection', 'connections']
5
6 from eventlet.patcher import slurp_properties
7 slurp_properties(
8     __MySQLdb, globals(),
9     ignore=__patched__, srckeys=dir(__MySQLdb))
10
11 from eventlet import tpool
12
13 __orig_connections = __import__('MySQLdb.connections').connections
14
15
16 def Connection(*args, **kw):
17     conn = tpool.execute(__orig_connections.Connection, *args, **kw)
18     return tpool.Proxy(conn, autowrap_names=('cursor',))
19 connect = Connect = Connection
20
21
22 # replicate the MySQLdb.connections module but with a tpooled Connection factory
23 class MySQLdbConnectionsModule(object):
24     pass
25
26 connections = MySQLdbConnectionsModule()
27 for var in dir(__orig_connections):
28     if not var.startswith('__'):
29         setattr(connections, var, getattr(__orig_connections, var))
30 connections.Connection = Connection
31
32 cursors = __import__('MySQLdb.cursors').cursors
33 converters = __import__('MySQLdb.converters').converters
34
35 # TODO support instantiating cursors.FooCursor objects directly
36 # TODO though this is a low priority, it would be nice if we supported
37 # subclassing eventlet.green.MySQLdb.connections.Connection