Reformat with autopep8
This commit is contained in:
parent
765d7df36d
commit
93f2a8d068
@ -73,7 +73,8 @@ def launch_heavy_threads():
|
||||
server_sock.bind(('localhost', 0))
|
||||
server_sock.listen(50)
|
||||
addr = ('localhost', server_sock.getsockname()[1])
|
||||
accepter_thread = threading.Thread(None, heavy_accepter, "accepter thread", (server_sock, threads))
|
||||
accepter_thread = threading.Thread(
|
||||
None, heavy_accepter, "accepter thread", (server_sock, threads))
|
||||
accepter_thread.start()
|
||||
threads.append(accepter_thread)
|
||||
for i in six.moves.range(CONCURRENCY):
|
||||
@ -112,4 +113,5 @@ if __name__ == "__main__":
|
||||
print("green:", results[launch_green_threads])
|
||||
if opts.threading:
|
||||
print("threads:", results[launch_heavy_threads])
|
||||
print("%", (results[launch_green_threads] - results[launch_heavy_threads]) / results[launch_heavy_threads] * 100)
|
||||
print("%", (results[launch_green_threads] - results[launch_heavy_threads]
|
||||
) / results[launch_heavy_threads] * 100)
|
||||
|
@ -127,7 +127,8 @@ except ImportError:
|
||||
from eventlet.green.OpenSSL import SSL
|
||||
except ImportError:
|
||||
def wrap_ssl_impl(*a, **kw):
|
||||
raise ImportError("To use SSL with Eventlet, you must install PyOpenSSL or use Python 2.6 or later.")
|
||||
raise ImportError(
|
||||
"To use SSL with Eventlet, you must install PyOpenSSL or use Python 2.6 or later.")
|
||||
else:
|
||||
def wrap_ssl_impl(sock, keyfile=None, certfile=None, server_side=False,
|
||||
cert_reqs=None, ssl_version=None, ca_certs=None,
|
||||
|
@ -317,73 +317,107 @@ class GenericConnectionWrapper(object):
|
||||
# setattr(class, name, lambda self, *a, **kw: getattr(self._base, name)(*a, **kw))
|
||||
# * def __getattr__(self, name): if name in (...): return getattr(self._base, name)
|
||||
# * other?
|
||||
def __enter__(self): return self._base.__enter__()
|
||||
def __enter__(self):
|
||||
return self._base.__enter__()
|
||||
|
||||
def __exit__(self, exc, value, tb): return self._base.__exit__(exc, value, tb)
|
||||
def __exit__(self, exc, value, tb):
|
||||
return self._base.__exit__(exc, value, tb)
|
||||
|
||||
def __repr__(self): return self._base.__repr__()
|
||||
def __repr__(self):
|
||||
return self._base.__repr__()
|
||||
|
||||
def affected_rows(self): return self._base.affected_rows()
|
||||
def affected_rows(self):
|
||||
return self._base.affected_rows()
|
||||
|
||||
def autocommit(self, *args, **kwargs): return self._base.autocommit(*args, **kwargs)
|
||||
def autocommit(self, *args, **kwargs):
|
||||
return self._base.autocommit(*args, **kwargs)
|
||||
|
||||
def begin(self): return self._base.begin()
|
||||
def begin(self):
|
||||
return self._base.begin()
|
||||
|
||||
def change_user(self, *args, **kwargs): return self._base.change_user(*args, **kwargs)
|
||||
def change_user(self, *args, **kwargs):
|
||||
return self._base.change_user(*args, **kwargs)
|
||||
|
||||
def character_set_name(self, *args, **kwargs): return self._base.character_set_name(*args, **kwargs)
|
||||
def character_set_name(self, *args, **kwargs):
|
||||
return self._base.character_set_name(*args, **kwargs)
|
||||
|
||||
def close(self, *args, **kwargs): return self._base.close(*args, **kwargs)
|
||||
def close(self, *args, **kwargs):
|
||||
return self._base.close(*args, **kwargs)
|
||||
|
||||
def commit(self, *args, **kwargs): return self._base.commit(*args, **kwargs)
|
||||
def commit(self, *args, **kwargs):
|
||||
return self._base.commit(*args, **kwargs)
|
||||
|
||||
def cursor(self, *args, **kwargs): return self._base.cursor(*args, **kwargs)
|
||||
def cursor(self, *args, **kwargs):
|
||||
return self._base.cursor(*args, **kwargs)
|
||||
|
||||
def dump_debug_info(self, *args, **kwargs): return self._base.dump_debug_info(*args, **kwargs)
|
||||
def dump_debug_info(self, *args, **kwargs):
|
||||
return self._base.dump_debug_info(*args, **kwargs)
|
||||
|
||||
def errno(self, *args, **kwargs): return self._base.errno(*args, **kwargs)
|
||||
def errno(self, *args, **kwargs):
|
||||
return self._base.errno(*args, **kwargs)
|
||||
|
||||
def error(self, *args, **kwargs): return self._base.error(*args, **kwargs)
|
||||
def error(self, *args, **kwargs):
|
||||
return self._base.error(*args, **kwargs)
|
||||
|
||||
def errorhandler(self, *args, **kwargs): return self._base.errorhandler(*args, **kwargs)
|
||||
def errorhandler(self, *args, **kwargs):
|
||||
return self._base.errorhandler(*args, **kwargs)
|
||||
|
||||
def insert_id(self, *args, **kwargs): return self._base.insert_id(*args, **kwargs)
|
||||
def insert_id(self, *args, **kwargs):
|
||||
return self._base.insert_id(*args, **kwargs)
|
||||
|
||||
def literal(self, *args, **kwargs): return self._base.literal(*args, **kwargs)
|
||||
def literal(self, *args, **kwargs):
|
||||
return self._base.literal(*args, **kwargs)
|
||||
|
||||
def set_character_set(self, *args, **kwargs): return self._base.set_character_set(*args, **kwargs)
|
||||
def set_character_set(self, *args, **kwargs):
|
||||
return self._base.set_character_set(*args, **kwargs)
|
||||
|
||||
def set_sql_mode(self, *args, **kwargs): return self._base.set_sql_mode(*args, **kwargs)
|
||||
def set_sql_mode(self, *args, **kwargs):
|
||||
return self._base.set_sql_mode(*args, **kwargs)
|
||||
|
||||
def show_warnings(self): return self._base.show_warnings()
|
||||
def show_warnings(self):
|
||||
return self._base.show_warnings()
|
||||
|
||||
def warning_count(self): return self._base.warning_count()
|
||||
def warning_count(self):
|
||||
return self._base.warning_count()
|
||||
|
||||
def ping(self, *args, **kwargs): return self._base.ping(*args, **kwargs)
|
||||
def ping(self, *args, **kwargs):
|
||||
return self._base.ping(*args, **kwargs)
|
||||
|
||||
def query(self, *args, **kwargs): return self._base.query(*args, **kwargs)
|
||||
def query(self, *args, **kwargs):
|
||||
return self._base.query(*args, **kwargs)
|
||||
|
||||
def rollback(self, *args, **kwargs): return self._base.rollback(*args, **kwargs)
|
||||
def rollback(self, *args, **kwargs):
|
||||
return self._base.rollback(*args, **kwargs)
|
||||
|
||||
def select_db(self, *args, **kwargs): return self._base.select_db(*args, **kwargs)
|
||||
def select_db(self, *args, **kwargs):
|
||||
return self._base.select_db(*args, **kwargs)
|
||||
|
||||
def set_server_option(self, *args, **kwargs): return self._base.set_server_option(*args, **kwargs)
|
||||
def set_server_option(self, *args, **kwargs):
|
||||
return self._base.set_server_option(*args, **kwargs)
|
||||
|
||||
def server_capabilities(self, *args, **kwargs): return self._base.server_capabilities(*args, **kwargs)
|
||||
def server_capabilities(self, *args, **kwargs):
|
||||
return self._base.server_capabilities(*args, **kwargs)
|
||||
|
||||
def shutdown(self, *args, **kwargs): return self._base.shutdown(*args, **kwargs)
|
||||
def shutdown(self, *args, **kwargs):
|
||||
return self._base.shutdown(*args, **kwargs)
|
||||
|
||||
def sqlstate(self, *args, **kwargs): return self._base.sqlstate(*args, **kwargs)
|
||||
def sqlstate(self, *args, **kwargs):
|
||||
return self._base.sqlstate(*args, **kwargs)
|
||||
|
||||
def stat(self, *args, **kwargs): return self._base.stat(*args, **kwargs)
|
||||
def stat(self, *args, **kwargs):
|
||||
return self._base.stat(*args, **kwargs)
|
||||
|
||||
def store_result(self, *args, **kwargs): return self._base.store_result(*args, **kwargs)
|
||||
def store_result(self, *args, **kwargs):
|
||||
return self._base.store_result(*args, **kwargs)
|
||||
|
||||
def string_literal(self, *args, **kwargs): return self._base.string_literal(*args, **kwargs)
|
||||
def string_literal(self, *args, **kwargs):
|
||||
return self._base.string_literal(*args, **kwargs)
|
||||
|
||||
def thread_id(self, *args, **kwargs): return self._base.thread_id(*args, **kwargs)
|
||||
def thread_id(self, *args, **kwargs):
|
||||
return self._base.thread_id(*args, **kwargs)
|
||||
|
||||
def use_result(self, *args, **kwargs): return self._base.use_result(*args, **kwargs)
|
||||
def use_result(self, *args, **kwargs):
|
||||
return self._base.use_result(*args, **kwargs)
|
||||
|
||||
|
||||
class PooledConnectionWrapper(GenericConnectionWrapper):
|
||||
@ -420,7 +454,7 @@ class PooledConnectionWrapper(GenericConnectionWrapper):
|
||||
|
||||
def __del__(self):
|
||||
return # this causes some issues if __del__ is called in the
|
||||
# main coroutine, so for now this is disabled
|
||||
# main coroutine, so for now this is disabled
|
||||
# self.close()
|
||||
|
||||
|
||||
|
@ -18,11 +18,13 @@ __all__ = dir(builtins_orig)
|
||||
__patched__ = ['file', 'open']
|
||||
|
||||
slurp_properties(builtins_orig, globals(),
|
||||
ignore=__patched__, srckeys=dir(builtins_orig))
|
||||
ignore=__patched__, srckeys=dir(builtins_orig))
|
||||
|
||||
hubs.get_hub()
|
||||
|
||||
__original_file = file
|
||||
|
||||
|
||||
class file(__original_file):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(file, self).__init__(*args, **kwargs)
|
||||
@ -30,6 +32,8 @@ class file(__original_file):
|
||||
|
||||
__original_open = open
|
||||
__opening = False
|
||||
|
||||
|
||||
def open(*args):
|
||||
global __opening
|
||||
result = __original_open(*args)
|
||||
|
@ -96,6 +96,8 @@ def waitpid(pid, options):
|
||||
greenthread.sleep(0.01)
|
||||
|
||||
__original_open__ = os_orig.open
|
||||
|
||||
|
||||
def open(file, flags, mode=0o777):
|
||||
""" Wrap os.open
|
||||
This behaves identically, but collaborates with
|
||||
|
@ -58,7 +58,7 @@ class GreenSSLSocket(_original_sslsocket):
|
||||
# nonblocking socket handshaking on connect got disabled so let's pretend it's disabled
|
||||
# even when it's on
|
||||
super(GreenSSLSocket, self).__init__(
|
||||
sock.fd, keyfile, certfile, server_side,cert_reqs, ssl_version,
|
||||
sock.fd, keyfile, certfile, server_side, cert_reqs, ssl_version,
|
||||
ca_certs, do_handshake_on_connect and six.PY2, *args, **kw)
|
||||
|
||||
# the superclass initializer trashes the methods so we remove
|
||||
@ -208,17 +208,20 @@ class GreenSSLSocket(_original_sslsocket):
|
||||
|
||||
def recv_into(self, buffer, nbytes=None, flags=0):
|
||||
if not self.act_non_blocking:
|
||||
trampoline(self, read=True, timeout=self.gettimeout(), timeout_exc=timeout_exc('timed out'))
|
||||
trampoline(self, read=True, timeout=self.gettimeout(),
|
||||
timeout_exc=timeout_exc('timed out'))
|
||||
return super(GreenSSLSocket, self).recv_into(buffer, nbytes, flags)
|
||||
|
||||
def recvfrom(self, addr, buflen=1024, flags=0):
|
||||
if not self.act_non_blocking:
|
||||
trampoline(self, read=True, timeout=self.gettimeout(), timeout_exc=timeout_exc('timed out'))
|
||||
trampoline(self, read=True, timeout=self.gettimeout(),
|
||||
timeout_exc=timeout_exc('timed out'))
|
||||
return super(GreenSSLSocket, self).recvfrom(addr, buflen, flags)
|
||||
|
||||
def recvfrom_into(self, buffer, nbytes=None, flags=0):
|
||||
if not self.act_non_blocking:
|
||||
trampoline(self, read=True, timeout=self.gettimeout(), timeout_exc=timeout_exc('timed out'))
|
||||
trampoline(self, read=True, timeout=self.gettimeout(),
|
||||
timeout_exc=timeout_exc('timed out'))
|
||||
return super(GreenSSLSocket, self).recvfrom_into(buffer, nbytes, flags)
|
||||
|
||||
def unwrap(self):
|
||||
|
@ -74,6 +74,7 @@ if hasattr(__thread, 'stack_size'):
|
||||
return __original_stack_size__(size)
|
||||
else:
|
||||
pass
|
||||
# not going to decrease stack_size, because otherwise other greenlets in this thread will suffer
|
||||
# not going to decrease stack_size, because otherwise other greenlets in
|
||||
# this thread will suffer
|
||||
|
||||
from eventlet.corolocal import local as _local
|
||||
|
@ -191,8 +191,8 @@ class GreenSocket(object):
|
||||
raise IOClosed()
|
||||
try:
|
||||
return trampoline(fd, read=read, write=write, timeout=timeout,
|
||||
timeout_exc=timeout_exc,
|
||||
mark_as_closed=self._mark_as_closed)
|
||||
timeout_exc=timeout_exc,
|
||||
mark_as_closed=self._mark_as_closed)
|
||||
except IOClosed:
|
||||
# This socket's been obsoleted. De-fang it.
|
||||
self._mark_as_closed()
|
||||
@ -209,7 +209,7 @@ class GreenSocket(object):
|
||||
set_nonblocking(client)
|
||||
return type(self)(client), addr
|
||||
self._trampoline(fd, read=True, timeout=self.gettimeout(),
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
|
||||
def _mark_as_closed(self):
|
||||
""" Mark this socket as being closed """
|
||||
@ -243,7 +243,7 @@ class GreenSocket(object):
|
||||
raise socket.timeout("timed out")
|
||||
try:
|
||||
self._trampoline(fd, write=True, timeout=end - time.time(),
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
except IOClosed:
|
||||
# ... we need some workable errno here.
|
||||
raise socket.error(errno.EBADFD)
|
||||
@ -271,7 +271,7 @@ class GreenSocket(object):
|
||||
if time.time() >= end:
|
||||
raise socket.timeout(errno.EAGAIN)
|
||||
self._trampoline(fd, write=True, timeout=end - time.time(),
|
||||
timeout_exc=socket.timeout(errno.EAGAIN))
|
||||
timeout_exc=socket.timeout(errno.EAGAIN))
|
||||
socket_checkerr(fd)
|
||||
except socket.error as ex:
|
||||
return get_errno(ex)
|
||||
@ -327,19 +327,19 @@ class GreenSocket(object):
|
||||
def recvfrom(self, *args):
|
||||
if not self.act_non_blocking:
|
||||
self._trampoline(self.fd, read=True, timeout=self.gettimeout(),
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
return self.fd.recvfrom(*args)
|
||||
|
||||
def recvfrom_into(self, *args):
|
||||
if not self.act_non_blocking:
|
||||
self._trampoline(self.fd, read=True, timeout=self.gettimeout(),
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
return self.fd.recvfrom_into(*args)
|
||||
|
||||
def recv_into(self, *args):
|
||||
if not self.act_non_blocking:
|
||||
self._trampoline(self.fd, read=True, timeout=self.gettimeout(),
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
return self.fd.recv_into(*args)
|
||||
|
||||
def send(self, data, flags=0):
|
||||
@ -362,7 +362,7 @@ class GreenSocket(object):
|
||||
|
||||
try:
|
||||
self._trampoline(self.fd, write=True, timeout=self.gettimeout(),
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
timeout_exc=socket.timeout("timed out"))
|
||||
except IOClosed:
|
||||
raise socket.error(errno.ECONNRESET, 'Connection closed by another thread')
|
||||
|
||||
@ -432,8 +432,8 @@ class _SocketDuckForFd(object):
|
||||
raise IOClosed()
|
||||
try:
|
||||
return trampoline(fd, read=read, write=write, timeout=timeout,
|
||||
timeout_exc=timeout_exc,
|
||||
mark_as_closed=self._mark_as_closed)
|
||||
timeout_exc=timeout_exc,
|
||||
mark_as_closed=self._mark_as_closed)
|
||||
except IOClosed:
|
||||
# Our fileno has been obsoleted. Defang ourselves to
|
||||
# prevent spurious closes.
|
||||
|
@ -8,7 +8,8 @@ from eventlet.hubs import timer
|
||||
from eventlet.support import greenlets as greenlet, six
|
||||
import warnings
|
||||
|
||||
__all__ = ['getcurrent', 'sleep', 'spawn', 'spawn_n', 'spawn_after', 'spawn_after_local', 'GreenThread']
|
||||
__all__ = ['getcurrent', 'sleep', 'spawn', 'spawn_n',
|
||||
'spawn_after', 'spawn_after_local', 'GreenThread']
|
||||
|
||||
getcurrent = greenlet.getcurrent
|
||||
|
||||
|
@ -120,7 +120,7 @@ from eventlet import timeout
|
||||
|
||||
def trampoline(fd, read=None, write=None, timeout=None,
|
||||
timeout_exc=timeout.Timeout,
|
||||
mark_as_closed = None):
|
||||
mark_as_closed=None):
|
||||
"""Suspend the current coroutine until the given socket object or file
|
||||
descriptor is ready to *read*, ready to *write*, or the specified
|
||||
*timeout* elapses, depending on arguments specified.
|
||||
@ -163,6 +163,7 @@ def trampoline(fd, read=None, write=None, timeout=None,
|
||||
if t is not None:
|
||||
t.cancel()
|
||||
|
||||
|
||||
def notify_close(fd):
|
||||
"""
|
||||
A particular file descriptor has been explicitly closed. Register for any
|
||||
@ -171,6 +172,7 @@ def notify_close(fd):
|
||||
hub = get_hub()
|
||||
hub.notify_close(fd)
|
||||
|
||||
|
||||
def notify_opened(fd):
|
||||
"""
|
||||
Some file descriptors may be closed 'silently' - that is, by the garbage
|
||||
|
@ -173,7 +173,7 @@ class BaseHub(object):
|
||||
"If you do know what you're doing and want to disable "
|
||||
"this error, call "
|
||||
"eventlet.debug.hub_prevent_multiple_readers(False) - MY THREAD=%s; THAT THREAD=%s" % (
|
||||
evtype, fileno, evtype, cb, bucket[fileno]))
|
||||
evtype, fileno, evtype, cb, bucket[fileno]))
|
||||
# store off the second listener in another structure
|
||||
self.secondaries[evtype].setdefault(fileno, []).append(listener)
|
||||
else:
|
||||
@ -365,7 +365,8 @@ class BaseHub(object):
|
||||
if self.running:
|
||||
self.stopping = True
|
||||
if wait:
|
||||
assert self.greenlet is not greenlet.getcurrent(), "Can't abort with wait from inside the hub's greenlet."
|
||||
assert self.greenlet is not greenlet.getcurrent(
|
||||
), "Can't abort with wait from inside the hub's greenlet."
|
||||
# schedule an immediate timer just so the hub doesn't sleep
|
||||
self.schedule_call_global(0, lambda: None)
|
||||
# switch to it; when done the hub will switch back to its parent,
|
||||
|
@ -88,7 +88,8 @@ class Hub(BaseHub):
|
||||
def abort(self, wait=True):
|
||||
self.schedule_call_global(0, self.greenlet.throw, greenlet.GreenletExit)
|
||||
if wait:
|
||||
assert self.greenlet is not greenlet.getcurrent(), "Can't abort with wait from inside the hub's greenlet."
|
||||
assert self.greenlet is not greenlet.getcurrent(
|
||||
), "Can't abort with wait from inside the hub's greenlet."
|
||||
self.switch()
|
||||
|
||||
def _getrunning(self):
|
||||
|
@ -38,7 +38,7 @@ def callLater(DelayedCallClass, reactor, _seconds, _f, *args, **kw):
|
||||
if not isinstance(_seconds, (int, long, float)):
|
||||
raise TypeError("Seconds must be int, long, or float, was " + type(_seconds))
|
||||
assert sys.maxint >= _seconds >= 0, \
|
||||
"%s is not greater than or equal to 0 seconds" % (_seconds,)
|
||||
"%s is not greater than or equal to 0 seconds" % (_seconds,)
|
||||
tple = DelayedCallClass(reactor.seconds() + _seconds, _f, args, kw,
|
||||
reactor._cancelCallLater,
|
||||
reactor._moveCallLaterSooner,
|
||||
@ -109,11 +109,11 @@ class BaseTwistedHub(object):
|
||||
|
||||
def switch(self):
|
||||
assert greenlet.getcurrent() is not self.greenlet, \
|
||||
"Cannot switch from MAINLOOP to MAINLOOP"
|
||||
"Cannot switch from MAINLOOP to MAINLOOP"
|
||||
try:
|
||||
greenlet.getcurrent().parent = self.greenlet
|
||||
greenlet.getcurrent().parent = self.greenlet
|
||||
except ValueError:
|
||||
pass
|
||||
pass
|
||||
return self.greenlet.switch()
|
||||
|
||||
def stop(self):
|
||||
@ -197,17 +197,17 @@ class TwistedHub(BaseTwistedHub):
|
||||
|
||||
def __init__(self):
|
||||
assert Hub.state == 0, ('%s hub can only be instantiated once' % type(self).__name__,
|
||||
Hub.state)
|
||||
Hub.state)
|
||||
Hub.state = 1
|
||||
make_twisted_threadpool_daemonic() # otherwise the program
|
||||
# would hang after the main
|
||||
# greenlet exited
|
||||
# would hang after the main
|
||||
# greenlet exited
|
||||
g = greenlet.greenlet(self.run)
|
||||
BaseTwistedHub.__init__(self, g)
|
||||
|
||||
def switch(self):
|
||||
assert greenlet.getcurrent() is not self.greenlet, \
|
||||
"Cannot switch from MAINLOOP to MAINLOOP"
|
||||
"Cannot switch from MAINLOOP to MAINLOOP"
|
||||
if self.greenlet.dead:
|
||||
self.greenlet = greenlet.greenlet(self.run)
|
||||
try:
|
||||
|
@ -70,7 +70,7 @@ def inject(module_name, new_globals, *additional_modules):
|
||||
_green_socket_modules() +
|
||||
_green_thread_modules() +
|
||||
_green_time_modules())
|
||||
# _green_MySQLdb()) # enable this after a short baking-in period
|
||||
# _green_MySQLdb()) # enable this after a short baking-in period
|
||||
|
||||
# after this we are gonna screw with sys.modules, so capture the
|
||||
# state of all the modules we're going to mess with, and lock
|
||||
|
@ -108,7 +108,8 @@ class Waiter(object):
|
||||
"""Wake up the greenlet that is calling wait() currently (if there is one).
|
||||
Can only be called from Hub's greenlet.
|
||||
"""
|
||||
assert getcurrent() is get_hub().greenlet, "Can only use Waiter.switch method from the mainloop"
|
||||
assert getcurrent() is get_hub(
|
||||
).greenlet, "Can only use Waiter.switch method from the mainloop"
|
||||
if self.greenlet is not None:
|
||||
try:
|
||||
self.greenlet.switch(value)
|
||||
@ -119,7 +120,8 @@ class Waiter(object):
|
||||
"""Make greenlet calling wait() wake up (if there is a wait()).
|
||||
Can only be called from Hub's greenlet.
|
||||
"""
|
||||
assert getcurrent() is get_hub().greenlet, "Can only use Waiter.switch method from the mainloop"
|
||||
assert getcurrent() is get_hub(
|
||||
).greenlet, "Can only use Waiter.switch method from the mainloop"
|
||||
if self.greenlet is not None:
|
||||
try:
|
||||
self.greenlet.throw(*throw_args)
|
||||
@ -335,7 +337,8 @@ class LightQueue(object):
|
||||
getter = self.getters.pop()
|
||||
if getter:
|
||||
item = putter.item
|
||||
putter.item = _NONE # this makes greenlet calling put() not to call _put() again
|
||||
# this makes greenlet calling put() not to call _put() again
|
||||
putter.item = _NONE
|
||||
self._put(item)
|
||||
item = self._get()
|
||||
getter.switch(item)
|
||||
|
@ -228,7 +228,7 @@ def getnameinfo(sockaddr, flags):
|
||||
except (ValueError, TypeError):
|
||||
if not isinstance(sockaddr, tuple):
|
||||
del sockaddr # to pass a stdlib test that is
|
||||
# hyper-careful about reference counts
|
||||
# hyper-careful about reference counts
|
||||
raise TypeError('getnameinfo() argument 1 must be a tuple')
|
||||
else:
|
||||
# must be ipv6 sockaddr, pretending we don't know how to resolve it
|
||||
|
@ -5,7 +5,7 @@ try:
|
||||
getcurrent = greenlet.greenlet.getcurrent
|
||||
GreenletExit = greenlet.greenlet.GreenletExit
|
||||
preserves_excinfo = (distutils.version.LooseVersion(greenlet.__version__)
|
||||
>= distutils.version.LooseVersion('0.3.2'))
|
||||
>= distutils.version.LooseVersion('0.3.2'))
|
||||
greenlet = greenlet.greenlet
|
||||
except ImportError as e:
|
||||
raise
|
||||
|
@ -262,7 +262,8 @@ del attr
|
||||
|
||||
Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes
|
||||
|
||||
sys.modules[__name__ + ".moves.urllib_parse"] = sys.modules[__name__ + ".moves.urllib.parse"] = Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse")
|
||||
sys.modules[__name__ + ".moves.urllib_parse"] = sys.modules[__name__ +
|
||||
".moves.urllib.parse"] = Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse")
|
||||
|
||||
|
||||
class Module_six_moves_urllib_error(_LazyModule):
|
||||
@ -280,7 +281,8 @@ del attr
|
||||
|
||||
Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes
|
||||
|
||||
sys.modules[__name__ + ".moves.urllib_error"] = sys.modules[__name__ + ".moves.urllib.error"] = Module_six_moves_urllib_error(__name__ + ".moves.urllib.error")
|
||||
sys.modules[__name__ + ".moves.urllib_error"] = sys.modules[__name__ +
|
||||
".moves.urllib.error"] = Module_six_moves_urllib_error(__name__ + ".moves.urllib.error")
|
||||
|
||||
|
||||
class Module_six_moves_urllib_request(_LazyModule):
|
||||
@ -328,7 +330,8 @@ del attr
|
||||
|
||||
Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes
|
||||
|
||||
sys.modules[__name__ + ".moves.urllib_request"] = sys.modules[__name__ + ".moves.urllib.request"] = Module_six_moves_urllib_request(__name__ + ".moves.urllib.request")
|
||||
sys.modules[__name__ + ".moves.urllib_request"] = sys.modules[__name__ +
|
||||
".moves.urllib.request"] = Module_six_moves_urllib_request(__name__ + ".moves.urllib.request")
|
||||
|
||||
|
||||
class Module_six_moves_urllib_response(_LazyModule):
|
||||
@ -347,7 +350,8 @@ del attr
|
||||
|
||||
Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes
|
||||
|
||||
sys.modules[__name__ + ".moves.urllib_response"] = sys.modules[__name__ + ".moves.urllib.response"] = Module_six_moves_urllib_response(__name__ + ".moves.urllib.response")
|
||||
sys.modules[__name__ + ".moves.urllib_response"] = sys.modules[__name__ +
|
||||
".moves.urllib.response"] = Module_six_moves_urllib_response(__name__ + ".moves.urllib.response")
|
||||
|
||||
|
||||
class Module_six_moves_urllib_robotparser(_LazyModule):
|
||||
@ -363,7 +367,8 @@ del attr
|
||||
|
||||
Module_six_moves_urllib_robotparser._moved_attributes = _urllib_robotparser_moved_attributes
|
||||
|
||||
sys.modules[__name__ + ".moves.urllib_robotparser"] = sys.modules[__name__ + ".moves.urllib.robotparser"] = Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser")
|
||||
sys.modules[__name__ + ".moves.urllib_robotparser"] = sys.modules[__name__ +
|
||||
".moves.urllib.robotparser"] = Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser")
|
||||
|
||||
|
||||
class Module_six_moves_urllib(types.ModuleType):
|
||||
@ -574,8 +579,8 @@ if print_ is None:
|
||||
data = str(data)
|
||||
# If the file has an encoding, encode unicode with it.
|
||||
if (isinstance(fp, file) and
|
||||
isinstance(data, unicode) and
|
||||
fp.encoding is not None):
|
||||
isinstance(data, unicode) and
|
||||
fp.encoding is not None):
|
||||
errors = getattr(fp, "errors", None)
|
||||
if errors is None:
|
||||
errors = "strict"
|
||||
|
@ -1,6 +1,7 @@
|
||||
from eventlet.hubs import get_hub
|
||||
from eventlet import spawn, getcurrent
|
||||
|
||||
|
||||
def block_on(deferred):
|
||||
cur = [getcurrent()]
|
||||
synchronous = []
|
||||
@ -28,6 +29,7 @@ def block_on(deferred):
|
||||
finally:
|
||||
del cur[0]
|
||||
|
||||
|
||||
def _putResultInDeferred(deferred, f, args, kwargs):
|
||||
try:
|
||||
result = f(*args, **kwargs)
|
||||
@ -38,17 +40,19 @@ def _putResultInDeferred(deferred, f, args, kwargs):
|
||||
else:
|
||||
deferred.callback(result)
|
||||
|
||||
|
||||
def deferToGreenThread(func, *args, **kwargs):
|
||||
from twisted.internet import defer
|
||||
d = defer.Deferred()
|
||||
spawn(_putResultInDeferred, d, func, args, kwargs)
|
||||
return d
|
||||
|
||||
|
||||
def callInGreenThread(func, *args, **kwargs):
|
||||
return spawn(func, *args, **kwargs)
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
try:
|
||||
num = int(sys.argv[1])
|
||||
@ -58,21 +62,20 @@ if __name__=='__main__':
|
||||
def test():
|
||||
print(block_on(reactor.resolver.getHostByName('www.google.com')))
|
||||
print(block_on(reactor.resolver.getHostByName('###')))
|
||||
if num==0:
|
||||
if num == 0:
|
||||
test()
|
||||
elif num==1:
|
||||
elif num == 1:
|
||||
spawn(test)
|
||||
from eventlet import sleep
|
||||
print('sleeping..')
|
||||
sleep(5)
|
||||
print('done sleeping..')
|
||||
elif num==2:
|
||||
elif num == 2:
|
||||
from eventlet.twistedutil import join_reactor
|
||||
spawn(test)
|
||||
reactor.run()
|
||||
elif num==3:
|
||||
elif num == 3:
|
||||
from eventlet.twistedutil import join_reactor
|
||||
print("fails because it's impossible to use block_on from the mainloop")
|
||||
reactor.callLater(0, test)
|
||||
reactor.run()
|
||||
|
||||
|
@ -27,7 +27,7 @@ class ValueQueue(Queue):
|
||||
Queue and it is an exception, raise it, but keep it in the Queue, so
|
||||
that future calls to wait() will raise it again.
|
||||
"""
|
||||
if self.has_error() and len(self.items)==1:
|
||||
if self.has_error() and len(self.items) == 1:
|
||||
# the last item, which is an exception, raise without emptying the Queue
|
||||
getcurrent().throw(*self.items[0][1])
|
||||
else:
|
||||
@ -49,6 +49,7 @@ class Event(BaseEvent):
|
||||
self.reset()
|
||||
return BaseEvent.send_exception(self, *throw_args)
|
||||
|
||||
|
||||
class Producer2Event(object):
|
||||
|
||||
# implements IPullProducer
|
||||
@ -117,7 +118,7 @@ class GreenTransportBase(object):
|
||||
self._disconnected_event.wait()
|
||||
|
||||
def __getattr__(self, item):
|
||||
if item=='transport':
|
||||
if item == 'transport':
|
||||
raise AttributeError(item)
|
||||
if hasattr(self, 'transport'):
|
||||
try:
|
||||
@ -131,12 +132,12 @@ class GreenTransportBase(object):
|
||||
|
||||
def resumeProducing(self):
|
||||
self.paused -= 1
|
||||
if self.paused==0:
|
||||
if self.paused == 0:
|
||||
self.transport.resumeProducing()
|
||||
|
||||
def pauseProducing(self):
|
||||
self.paused += 1
|
||||
if self.paused==1:
|
||||
if self.paused == 1:
|
||||
self.transport.pauseProducing()
|
||||
|
||||
def _init_transport_producer(self):
|
||||
@ -229,7 +230,7 @@ class GreenTransport(GreenTransportBase):
|
||||
except:
|
||||
if not self._disconnected_event.has_exception():
|
||||
raise
|
||||
if size>=0:
|
||||
if size >= 0:
|
||||
result, self._buffer = self._buffer[:size], self._buffer[size:]
|
||||
else:
|
||||
result, self._buffer = self._buffer, ''
|
||||
@ -247,7 +248,7 @@ class GreenTransport(GreenTransportBase):
|
||||
try:
|
||||
try:
|
||||
recvd = self._wait()
|
||||
#print 'received %r' % recvd
|
||||
# print 'received %r' % recvd
|
||||
self._buffer += recvd
|
||||
except ConnectionDone:
|
||||
pass
|
||||
@ -411,4 +412,3 @@ class SpawnFactory(SimpleSpawnFactory):
|
||||
for g in self.greenlets:
|
||||
results.append(g.wait())
|
||||
return results
|
||||
|
||||
|
@ -38,4 +38,3 @@ class LineOnlyReceiverTransport(GreenTransportBase):
|
||||
return self.readline()
|
||||
except ConnectionDone:
|
||||
raise StopIteration
|
||||
|
||||
|
@ -16,11 +16,11 @@ conn.loseWriteConnection()
|
||||
print(conn.read())
|
||||
|
||||
# read from SSL connection line by line
|
||||
conn = GreenClientCreator(reactor, LineOnlyReceiverTransport).connectSSL('sf.net', 443, ssl.ClientContextFactory())
|
||||
conn = GreenClientCreator(reactor, LineOnlyReceiverTransport).connectSSL(
|
||||
'sf.net', 443, ssl.ClientContextFactory())
|
||||
conn.write('GET / HTTP/1.0\r\n\r\n')
|
||||
try:
|
||||
for num, line in enumerate(conn):
|
||||
print('%3s %r' % (num, line))
|
||||
except ConnectionClosed as ex:
|
||||
print(ex)
|
||||
|
||||
|
@ -17,6 +17,7 @@ from eventlet.twistedutil import deferToGreenThread
|
||||
from eventlet.twistedutil import join_reactor
|
||||
from eventlet.green import httplib
|
||||
|
||||
|
||||
class LineOnlyReceiver(basic.LineOnlyReceiver):
|
||||
|
||||
def connectionMade(self):
|
||||
@ -31,7 +32,7 @@ class LineOnlyReceiver(basic.LineOnlyReceiver):
|
||||
|
||||
def requestReceived(self, lines):
|
||||
request = re.match('^(\w+) http://(.*?)(/.*?) HTTP/1..$', lines[0])
|
||||
#print request.groups()
|
||||
# print request.groups()
|
||||
method, host, path = request.groups()
|
||||
headers = dict(x.split(': ', 1) for x in lines[1:])
|
||||
def callback(result):
|
||||
@ -43,6 +44,7 @@ class LineOnlyReceiver(basic.LineOnlyReceiver):
|
||||
d = deferToGreenThread(http_request, method, host, path, headers=headers)
|
||||
d.addCallbacks(callback, errback)
|
||||
|
||||
|
||||
def http_request(method, host, path, headers):
|
||||
conn = httplib.HTTPConnection(host)
|
||||
conn.request(method, path, headers=headers)
|
||||
@ -51,6 +53,7 @@ def http_request(method, host, path, headers):
|
||||
print(method, host, path, response.status, response.reason, len(body))
|
||||
return format_response(response, body)
|
||||
|
||||
|
||||
def format_response(response, body):
|
||||
result = "HTTP/1.1 %s %s" % (response.status, response.reason)
|
||||
for k, v in response.getheaders():
|
||||
@ -61,6 +64,7 @@ def format_response(response, body):
|
||||
result += '\r\n'
|
||||
return result
|
||||
|
||||
|
||||
class MyFactory(Factory):
|
||||
protocol = LineOnlyReceiver
|
||||
|
||||
|
@ -6,6 +6,7 @@ from eventlet.twistedutil import join_reactor
|
||||
from eventlet.twistedutil.protocol import GreenClientCreator, SpawnFactory, UnbufferedTransport
|
||||
from eventlet import proc
|
||||
|
||||
|
||||
def forward(source, dest):
|
||||
try:
|
||||
while True:
|
||||
@ -17,6 +18,7 @@ def forward(source, dest):
|
||||
finally:
|
||||
dest.loseConnection()
|
||||
|
||||
|
||||
def handler(local):
|
||||
client = str(local.getHost())
|
||||
print('accepted connection from %s' % client)
|
||||
|
@ -9,6 +9,7 @@ from eventlet.twistedutil import join_reactor
|
||||
from eventlet.twistedutil.protocol import SpawnFactory
|
||||
from eventlet.twistedutil.protocols.basic import LineOnlyReceiverTransport
|
||||
|
||||
|
||||
class Chat:
|
||||
|
||||
def __init__(self):
|
||||
@ -39,4 +40,3 @@ chat = Chat()
|
||||
from twisted.internet import reactor
|
||||
reactor.listenTCP(8007, SpawnFactory(chat.handler, LineOnlyReceiverTransport))
|
||||
reactor.run()
|
||||
|
||||
|
@ -5,11 +5,13 @@ from gnutls.interfaces.twisted import X509Credentials
|
||||
from eventlet.twistedutil.protocol import GreenClientCreator
|
||||
from eventlet.twistedutil.protocols.basic import LineOnlyReceiverTransport
|
||||
|
||||
|
||||
class NoisySRVConnector(SRVConnector):
|
||||
|
||||
def pickServer(self):
|
||||
host, port = SRVConnector.pickServer(self)
|
||||
print('Resolved _%s._%s.%s --> %s:%s' % (self.service, self.protocol, self.domain, host, port))
|
||||
print('Resolved _%s._%s.%s --> %s:%s' %
|
||||
(self.service, self.protocol, self.domain, host, port))
|
||||
return host, port
|
||||
|
||||
cred = X509Credentials(None, None)
|
||||
|
@ -7,6 +7,7 @@ from xcaplib.green import XCAPClient
|
||||
from eventlet.twistedutil import deferToGreenThread
|
||||
from eventlet.twistedutil import join_reactor
|
||||
|
||||
|
||||
class LineOnlyReceiver(basic.LineOnlyReceiver):
|
||||
|
||||
def lineReceived(self, line):
|
||||
@ -14,8 +15,8 @@ class LineOnlyReceiver(basic.LineOnlyReceiver):
|
||||
if not line:
|
||||
return
|
||||
app, context, node = (line + ' ').split(' ', 3)
|
||||
context = {'u' : 'users', 'g': 'global'}.get(context, context)
|
||||
d = deferToGreenThread(client._get, app, node, globaltree=context=='global')
|
||||
context = {'u': 'users', 'g': 'global'}.get(context, context)
|
||||
d = deferToGreenThread(client._get, app, node, globaltree=context == 'global')
|
||||
def callback(result):
|
||||
self.transport.write(str(result))
|
||||
def errback(error):
|
||||
@ -23,6 +24,7 @@ class LineOnlyReceiver(basic.LineOnlyReceiver):
|
||||
d.addCallback(callback)
|
||||
d.addErrback(errback)
|
||||
|
||||
|
||||
class MyFactory(Factory):
|
||||
protocol = LineOnlyReceiver
|
||||
|
||||
|
@ -220,7 +220,8 @@ def verify_hub_empty():
|
||||
num_readers = len(hub.get_readers())
|
||||
num_writers = len(hub.get_writers())
|
||||
num_timers = hub.get_timers_count()
|
||||
assert num_readers == 0 and num_writers == 0, "Readers: %s Writers: %s" % (num_readers, num_writers)
|
||||
assert num_readers == 0 and num_writers == 0, "Readers: %s Writers: %s" % (
|
||||
num_readers, num_writers)
|
||||
|
||||
|
||||
def find_command(command):
|
||||
|
@ -6,15 +6,15 @@ import os
|
||||
__test__ = False
|
||||
_proc_status = '/proc/%d/status' % os.getpid()
|
||||
|
||||
_scale = {'kB': 1024.0, 'mB': 1024.0*1024.0,
|
||||
'KB': 1024.0, 'MB': 1024.0*1024.0}
|
||||
_scale = {'kB': 1024.0, 'mB': 1024.0 * 1024.0,
|
||||
'KB': 1024.0, 'MB': 1024.0 * 1024.0}
|
||||
|
||||
|
||||
def _VmB(VmKey):
|
||||
'''Private.
|
||||
'''
|
||||
global _proc_status, _scale
|
||||
# get pseudo file /proc/<pid>/status
|
||||
# get pseudo file /proc/<pid>/status
|
||||
try:
|
||||
t = open(_proc_status)
|
||||
v = t.read()
|
||||
|
@ -461,8 +461,8 @@ def _check_and_set_parent(parent, value, name, new_name):
|
||||
if not _is_instance_mock(value):
|
||||
return False
|
||||
if ((value._mock_name or value._mock_new_name) or
|
||||
(value._mock_parent is not None) or
|
||||
(value._mock_new_parent is not None)):
|
||||
(value._mock_parent is not None) or
|
||||
(value._mock_new_parent is not None)):
|
||||
return False
|
||||
|
||||
_parent = parent
|
||||
@ -502,10 +502,10 @@ class NonCallableMock(Base):
|
||||
return instance
|
||||
|
||||
def __init__(
|
||||
self, spec=None, wraps=None, name=None, spec_set=None,
|
||||
parent=None, _spec_state=None, _new_name='', _new_parent=None,
|
||||
**kwargs
|
||||
):
|
||||
self, spec=None, wraps=None, name=None, spec_set=None,
|
||||
parent=None, _spec_state=None, _new_name='', _new_parent=None,
|
||||
**kwargs
|
||||
):
|
||||
if _new_parent is None:
|
||||
_new_parent = parent
|
||||
|
||||
@ -768,8 +768,8 @@ class NonCallableMock(Base):
|
||||
# property setters go through here
|
||||
return object.__setattr__(self, name, value)
|
||||
elif (self._spec_set and self._mock_methods is not None and
|
||||
name not in self._mock_methods and
|
||||
name not in self.__dict__):
|
||||
name not in self._mock_methods and
|
||||
name not in self.__dict__):
|
||||
raise AttributeError("Mock object has no attribute '%s'" % name)
|
||||
elif name in _unsupported_magics:
|
||||
msg = 'Attempting to set unsupported magic method %r.' % name
|
||||
@ -1018,7 +1018,7 @@ class CallableMixin(Base):
|
||||
ret_val = self.return_value
|
||||
|
||||
if (self._mock_wraps is not None and
|
||||
self._mock_return_value is DEFAULT):
|
||||
self._mock_return_value is DEFAULT):
|
||||
return self._mock_wraps(*args, **kwargs)
|
||||
if ret_val is DEFAULT:
|
||||
ret_val = self.return_value
|
||||
@ -1110,9 +1110,9 @@ class _patch(object):
|
||||
_active_patches = set()
|
||||
|
||||
def __init__(
|
||||
self, getter, attribute, new, spec, create,
|
||||
spec_set, autospec, new_callable, kwargs
|
||||
):
|
||||
self, getter, attribute, new, spec, create,
|
||||
spec_set, autospec, new_callable, kwargs
|
||||
):
|
||||
if new_callable is not None:
|
||||
if new is not DEFAULT:
|
||||
raise ValueError(
|
||||
@ -1193,7 +1193,7 @@ class _patch(object):
|
||||
return func(*args, **keywargs)
|
||||
except:
|
||||
if (patching not in entered_patchers and
|
||||
_is_started(patching)):
|
||||
_is_started(patching)):
|
||||
# the patcher may have been started, but an exception
|
||||
# raised whilst entering one of its additional_patchers
|
||||
entered_patchers.append(patching)
|
||||
@ -1252,7 +1252,7 @@ class _patch(object):
|
||||
if spec is not None and autospec is not None:
|
||||
raise TypeError("Can't specify spec and autospec")
|
||||
if ((spec is not None or autospec is not None) and
|
||||
spec_set not in (True, None)):
|
||||
spec_set not in (True, None)):
|
||||
raise TypeError("Can't provide explicit spec_set *and* spec or autospec")
|
||||
|
||||
original, local = self.get_original()
|
||||
@ -1301,7 +1301,7 @@ class _patch(object):
|
||||
|
||||
# add a name to mocks
|
||||
if (isinstance(Klass, type) and
|
||||
issubclass(Klass, NonCallableMock) and self.attribute):
|
||||
issubclass(Klass, NonCallableMock) and self.attribute):
|
||||
_kwargs['name'] = self.attribute
|
||||
|
||||
_kwargs.update(kwargs)
|
||||
@ -1314,7 +1314,7 @@ class _patch(object):
|
||||
if spec_set is not None:
|
||||
this_spec = spec_set
|
||||
if (not _is_list(this_spec) and not
|
||||
_instance_callable(this_spec)):
|
||||
_instance_callable(this_spec)):
|
||||
Klass = NonCallableMagicMock
|
||||
|
||||
_kwargs.pop('name')
|
||||
@ -1402,10 +1402,10 @@ def _get_target(target):
|
||||
|
||||
|
||||
def _patch_object(
|
||||
target, attribute, new=DEFAULT, spec=None,
|
||||
create=False, spec_set=None, autospec=None,
|
||||
new_callable=None, **kwargs
|
||||
):
|
||||
target, attribute, new=DEFAULT, spec=None,
|
||||
create=False, spec_set=None, autospec=None,
|
||||
new_callable=None, **kwargs
|
||||
):
|
||||
"""
|
||||
patch.object(target, attribute, new=DEFAULT, spec=None, create=False,
|
||||
spec_set=None, autospec=None, new_callable=None, **kwargs)
|
||||
@ -1479,9 +1479,9 @@ def _patch_multiple(target, spec=None, create=False, spec_set=None,
|
||||
|
||||
|
||||
def patch(
|
||||
target, new=DEFAULT, spec=None, create=False,
|
||||
spec_set=None, autospec=None, new_callable=None, **kwargs
|
||||
):
|
||||
target, new=DEFAULT, spec=None, create=False,
|
||||
spec_set=None, autospec=None, new_callable=None, **kwargs
|
||||
):
|
||||
"""
|
||||
`patch` acts as a function decorator, class decorator or a context
|
||||
manager. Inside the body of the function or with statement, the `target`
|
||||
@ -1611,7 +1611,7 @@ class _patch_dict(object):
|
||||
for attr in dir(klass):
|
||||
attr_value = getattr(klass, attr)
|
||||
if (attr.startswith(patch.TEST_PREFIX) and
|
||||
hasattr(attr_value, "__call__")):
|
||||
hasattr(attr_value, "__call__")):
|
||||
decorator = _patch_dict(self.in_dict, self.values, self.clear)
|
||||
decorated = decorator(attr_value)
|
||||
setattr(klass, attr, decorated)
|
||||
|
@ -39,7 +39,8 @@ def parse_unittest_output(s):
|
||||
num = int(re.search('^Ran (\d+) test.*?$', s, re.M).group(1))
|
||||
ok = re.search('^OK$', s, re.M)
|
||||
error, fail, timeout = 0, 0, 0
|
||||
failed_match = re.search(r'^FAILED \((?:failures=(?P<f>\d+))?,? ?(?:errors=(?P<e>\d+))?\)$', s, re.M)
|
||||
failed_match = re.search(
|
||||
r'^FAILED \((?:failures=(?P<f>\d+))?,? ?(?:errors=(?P<e>\d+))?\)$', s, re.M)
|
||||
ok_match = re.search('^OK$', s, re.M)
|
||||
if failed_match:
|
||||
assert not ok_match, (ok_match, s)
|
||||
|
@ -218,7 +218,8 @@ class TestQueue(LimitedTestCase):
|
||||
|
||||
self.assertEqual(['waiting', 'sending hello', 'hello', 'sending world', 'world'], events)
|
||||
eventlet.sleep(0)
|
||||
self.assertEqual(['waiting', 'sending hello', 'hello', 'sending world', 'world', 'sent world'], events)
|
||||
self.assertEqual(
|
||||
['waiting', 'sending hello', 'hello', 'sending world', 'world', 'sent world'], events)
|
||||
|
||||
def test_channel_waiters(self):
|
||||
c = eventlet.Queue(0)
|
||||
|
@ -9,8 +9,10 @@ patcher.inject(
|
||||
('urllib2', urllib2))
|
||||
|
||||
HandlerTests.test_file = patcher.patch_function(HandlerTests.test_file, ('socket', socket))
|
||||
HandlerTests.test_cookie_redirect = patcher.patch_function(HandlerTests.test_cookie_redirect, ('urllib2', urllib2))
|
||||
OpenerDirectorTests.test_badly_named_methods = patcher.patch_function(OpenerDirectorTests.test_badly_named_methods, ('urllib2', urllib2))
|
||||
HandlerTests.test_cookie_redirect = patcher.patch_function(
|
||||
HandlerTests.test_cookie_redirect, ('urllib2', urllib2))
|
||||
OpenerDirectorTests.test_badly_named_methods = patcher.patch_function(
|
||||
OpenerDirectorTests.test_badly_named_methods, ('urllib2', urllib2))
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
@ -39,4 +39,3 @@ class Test(unittest.TestCase):
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user