# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # __MySQLdb = __import__('MySQLdb') __all__ = __MySQLdb.__all__ __patched__ = ["connect", "Connect", 'Connection', 'connections'] from evy.patcher import slurp_properties slurp_properties(__MySQLdb, globals(), ignore = __patched__, srckeys = dir(__MySQLdb)) from evy 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(object): pass
# """ The :mod:`zmq` module wraps the :class:`Socket` and :class:`Context` found in :mod:`pyzmq <zmq>` to be non blocking """ from __future__ import with_statement __zmq__ = __import__('zmq') from evy import hubs from evy.patcher import slurp_properties from evy.support import greenlets as greenlet __patched__ = ['Context', 'Socket'] slurp_properties(__zmq__, globals(), ignore = __patched__) from collections import deque class _QueueLock(object): """A Lock that can be acquired by at most one thread. Any other thread calling acquire will be blocked in a queue. When release is called, the threads are awoken in the order they blocked, one at a time. This lock can be required recursively by the same thread.""" def __init__ (self): self._waiters = deque() self._count = 0 self._holder = None self._hub = hubs.get_hub()
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """This module is API-equivalent to the standard library :mod:`profile` module but it is greenthread-aware as well as thread-aware. Use this module to profile Eventlet-based applications in preference to either :mod:`profile` or :mod:`cProfile`. FIXME: No testcases for this module. """ profile_orig = __import__('profile') __all__ = profile_orig.__all__ from evy.patcher import slurp_properties slurp_properties(profile_orig, globals(), srckeys=dir(profile_orig)) import new import sys import traceback import functools from evy.green import threads as greenthread from evy import patcher thread = patcher.original('thread') # non-monkeypatched module needed #This class provides the start() and stop() functions class Profile(profile_orig.Profile): base = profile_orig.Profile
os_orig = __import__("os") import errno socket = __import__("socket") from evy.support import get_errno from evy.io.pipes import GreenPipe from evy.green import threads as greenthread from evy import hubs from evy.patcher import slurp_properties __all__ = os_orig.__all__ __patched__ = ['fdopen', 'read', 'write', 'wait', 'waitpid'] slurp_properties(os_orig, globals(), ignore = __patched__, srckeys = dir(os_orig)) def fdopen (fd, *args, **kw): """ fdopen(fd [, mode='r' [, bufsize]]) -> file_object Return an open file object connected to a file descriptor.""" if not isinstance(fd, int): raise TypeError('fd should be int, not %r' % fd) try: return GreenPipe(fd, *args, **kw) except IOError, e: raise OSError(*e.args) __original_read__ = os_orig.read
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # __MySQLdb = __import__('MySQLdb') __all__ = __MySQLdb.__all__ __patched__ = ["connect", "Connect", 'Connection', 'connections'] from evy.patcher import slurp_properties slurp_properties(__MySQLdb, globals(), ignore=__patched__, srckeys=dir(__MySQLdb)) from evy 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
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # """ The :mod:`zmq` module wraps the :class:`Socket` and :class:`Context` found in :mod:`pyzmq <zmq>` to be non blocking """ from __future__ import with_statement __zmq__ = __import__('zmq') from evy import hubs from evy.patcher import slurp_properties from evy.support import greenlets as greenlet __patched__ = ['Context', 'Socket'] slurp_properties(__zmq__, globals(), ignore=__patched__) from collections import deque class _QueueLock(object): """A Lock that can be acquired by at most one thread. Any other thread calling acquire will be blocked in a queue. When release is called, the threads are awoken in the order they blocked, one at a time. This lock can be required recursively by the same thread.""" def __init__(self): self._waiters = deque() self._count = 0 self._holder = None self._hub = hubs.get_hub()
# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # __ssl = __import__('ssl') from evy.patcher import slurp_properties slurp_properties(__ssl, globals(), srckeys = dir(__ssl)) import sys import errno time = __import__('time') from evy.support import get_errno from evy.hubs import trampoline from evy.io.utils import set_nonblocking, CONNECT_ERR, CONNECT_SUCCESS from evy.io.sockets import GreenSocket, SOCKET_CLOSED orig_socket = __import__('socket') socket = orig_socket.socket if sys.version_info >= (2, 7): has_ciphers = True
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import os import sys __import__('evy.patched._socket_nodns') __socket = sys.modules['evy.patched._socket_nodns'] __all__ = __socket.__all__ __patched__ = __socket.__patched__ + ['gethostbyname', 'getaddrinfo', 'create_connection', ] from evy.patcher import slurp_properties slurp_properties(__socket, globals(), srckeys = dir(__socket)) from evy.green import dns as greendns if greendns: gethostbyname = greendns.gethostbyname getaddrinfo = greendns.getaddrinfo gethostbyname_ex = greendns.gethostbyname_ex getnameinfo = greendns.getnameinfo __patched__ = __patched__ + ['gethostbyname_ex', 'getnameinfo'] def create_connection (address, timeout = _GLOBAL_DEFAULT_TIMEOUT, source_address = None): """Connect to *address* and return the socket object.
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """This module is API-equivalent to the standard library :mod:`profile` module but it is greenthread-aware as well as thread-aware. Use this module to profile Eventlet-based applications in preference to either :mod:`profile` or :mod:`cProfile`. FIXME: No testcases for this module. """ profile_orig = __import__('profile') __all__ = profile_orig.__all__ from evy.patcher import slurp_properties slurp_properties(profile_orig, globals(), srckeys = dir(profile_orig)) import new import sys import traceback import functools from evy.green import threads as greenthread from evy import patcher thread = patcher.original('thread') # non-monkeypatched module needed #This class provides the start() and stop() functions class Profile(profile_orig.Profile): base = profile_orig.Profile
os_orig = __import__("os") import errno socket = __import__("socket") from evy.support import get_errno from evy.io.pipes import GreenPipe from evy.green import threads as greenthread from evy import hubs from evy.patcher import slurp_properties __all__ = os_orig.__all__ __patched__ = ['fdopen', 'read', 'write', 'wait', 'waitpid'] slurp_properties(os_orig, globals(), ignore=__patched__, srckeys=dir(os_orig)) def fdopen(fd, *args, **kw): """ fdopen(fd [, mode='r' [, bufsize]]) -> file_object Return an open file object connected to a file descriptor.""" if not isinstance(fd, int): raise TypeError('fd should be int, not %r' % fd) try: return GreenPipe(fd, *args, **kw) except IOError, e: raise OSError(*e.args)
# # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # __time = __import__('time') from evy.patcher import slurp_properties __patched__ = ['sleep'] slurp_properties(__time, globals(), ignore = __patched__, srckeys = dir(__time)) from evy.green.threads import sleep sleep # silence pyflakes
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # __socket = __import__('socket') __all__ = __socket.__all__ __patched__ = ['fromfd', 'socketpair', 'ssl', 'socket'] from evy.patcher import slurp_properties slurp_properties(__socket, globals(), ignore = __patched__, srckeys = dir(__socket)) os = __import__('os') import warnings from evy.io.sockets import GreenSocket as socket from evy.io.ssl import SSL as _SSL # for exceptions try: __original_fromfd__ = __socket.fromfd def fromfd (*args): return socket(__original_fromfd__(*args)) except AttributeError: pass