PEP8 whitespace

This commit is contained in:
Sergey Shepelev
2014-04-02 15:38:46 +04:00
parent cbd404d56e
commit c6a6731ded
4 changed files with 29 additions and 8 deletions

View File

@@ -21,15 +21,20 @@ __all__ = [
warnings.warn("eventlet.api is deprecated! Nearly everything in it has moved " warnings.warn("eventlet.api is deprecated! Nearly everything in it has moved "
"to the eventlet module.", DeprecationWarning, stacklevel=2) "to the eventlet module.", DeprecationWarning, stacklevel=2)
def get_hub(*a, **kw): def get_hub(*a, **kw):
warnings.warn("eventlet.api.get_hub has moved to eventlet.hubs.get_hub", warnings.warn("eventlet.api.get_hub has moved to eventlet.hubs.get_hub",
DeprecationWarning, stacklevel=2) DeprecationWarning, stacklevel=2)
return hubs.get_hub(*a, **kw) return hubs.get_hub(*a, **kw)
def get_default_hub(*a, **kw): def get_default_hub(*a, **kw):
warnings.warn("eventlet.api.get_default_hub has moved to" warnings.warn("eventlet.api.get_default_hub has moved to"
" eventlet.hubs.get_default_hub", " eventlet.hubs.get_default_hub",
DeprecationWarning, stacklevel=2) DeprecationWarning, stacklevel=2)
return hubs.get_default_hub(*a, **kw) return hubs.get_default_hub(*a, **kw)
def use_hub(*a, **kw): def use_hub(*a, **kw):
warnings.warn("eventlet.api.use_hub has moved to eventlet.hubs.use_hub", warnings.warn("eventlet.api.use_hub has moved to eventlet.hubs.use_hub",
DeprecationWarning, stacklevel=2) DeprecationWarning, stacklevel=2)
@@ -58,6 +63,7 @@ def tcp_listener(address, backlog=50):
util.socket_bind_and_listen(socket, address, backlog=backlog) util.socket_bind_and_listen(socket, address, backlog=backlog)
return socket return socket
def ssl_listener(address, certificate, private_key): def ssl_listener(address, certificate, private_key):
"""Listen on the given (ip, port) *address* with a TCP socket that """Listen on the given (ip, port) *address* with a TCP socket that
can do SSL. Primarily useful for unit tests, don't use in production. can do SSL. Primarily useful for unit tests, don't use in production.
@@ -78,6 +84,7 @@ def ssl_listener(address, certificate, private_key):
socket.listen(50) socket.listen(50)
return socket return socket
def connect_tcp(address, localaddr=None): def connect_tcp(address, localaddr=None):
""" """
Create a TCP connection to address ``(host, port)`` and return the socket. Create a TCP connection to address ``(host, port)`` and return the socket.

View File

@@ -4,22 +4,26 @@ from eventlet.support import greenlets as greenlet
from eventlet import greenthread from eventlet import greenthread
from eventlet.semaphore import Semaphore as LockType from eventlet.semaphore import Semaphore as LockType
__patched__ = ['get_ident', 'start_new_thread', 'start_new', 'allocate_lock', __patched__ = ['get_ident', 'start_new_thread', 'start_new', 'allocate_lock',
'allocate', 'exit', 'interrupt_main', 'stack_size', '_local', 'allocate', 'exit', 'interrupt_main', 'stack_size', '_local',
'LockType', '_count'] 'LockType', '_count']
error = __thread.error error = __thread.error
__threadcount = 0 __threadcount = 0
def _count(): def _count():
return __threadcount return __threadcount
def get_ident(gr=None): def get_ident(gr=None):
if gr is None: if gr is None:
return id(greenlet.getcurrent()) return id(greenlet.getcurrent())
else: else:
return id(gr) return id(gr)
def __thread_body(func, args, kwargs): def __thread_body(func, args, kwargs):
global __threadcount global __threadcount
__threadcount += 1 __threadcount += 1
@@ -28,22 +32,30 @@ def __thread_body(func, args, kwargs):
finally: finally:
__threadcount -= 1 __threadcount -= 1
def start_new_thread(function, args=(), kwargs={}):
def start_new_thread(function, args=(), kwargs=None):
kwargs = kwargs or {}
g = greenthread.spawn_n(__thread_body, function, args, kwargs) g = greenthread.spawn_n(__thread_body, function, args, kwargs)
return get_ident(g) return get_ident(g)
start_new = start_new_thread start_new = start_new_thread
def allocate_lock(*a): def allocate_lock(*a):
return LockType(1) return LockType(1)
allocate = allocate_lock allocate = allocate_lock
def exit(): def exit():
raise greenlet.GreenletExit raise greenlet.GreenletExit
exit_thread = __thread.exit_thread exit_thread = __thread.exit_thread
def interrupt_main(): def interrupt_main():
curr = greenlet.getcurrent() curr = greenlet.getcurrent()
if curr.parent and not curr.parent.dead: if curr.parent and not curr.parent.dead:
@@ -51,6 +63,7 @@ def interrupt_main():
else: else:
raise KeyboardInterrupt() raise KeyboardInterrupt()
if hasattr(__thread, 'stack_size'): if hasattr(__thread, 'stack_size'):
__original_stack_size__ = __thread.stack_size __original_stack_size__ = __thread.stack_size
def stack_size(size=None): def stack_size(size=None):

View File

@@ -13,6 +13,7 @@ EXC_MASK = select.POLLERR | select.POLLHUP
READ_MASK = select.POLLIN | select.POLLPRI READ_MASK = select.POLLIN | select.POLLPRI
WRITE_MASK = select.POLLOUT WRITE_MASK = select.POLLOUT
class Hub(BaseHub): class Hub(BaseHub):
def __init__(self, clock=time.time): def __init__(self, clock=time.time):
super(Hub, self).__init__(clock) super(Hub, self).__init__(clock)
@@ -27,7 +28,7 @@ class Hub(BaseHub):
listener = super(Hub, self).add(evtype, fileno, cb) listener = super(Hub, self).add(evtype, fileno, cb)
self.register(fileno, new=True) self.register(fileno, new=True)
return listener return listener
def remove(self, listener): def remove(self, listener):
super(Hub, self).remove(listener) super(Hub, self).remove(listener)
self.register(listener.fileno) self.register(listener.fileno)
@@ -47,7 +48,7 @@ class Hub(BaseHub):
self.modify(fileno, mask) self.modify(fileno, mask)
except (IOError, OSError): except (IOError, OSError):
self.poll.register(fileno, mask) self.poll.register(fileno, mask)
else: else:
try: try:
self.poll.unregister(fileno) self.poll.unregister(fileno)
except (KeyError, IOError, OSError): except (KeyError, IOError, OSError):
@@ -108,7 +109,6 @@ class Hub(BaseHub):
except: except:
self.squelch_exception(fileno, sys.exc_info()) self.squelch_exception(fileno, sys.exc_info())
clear_sys_exc_info() clear_sys_exc_info()
if self.debug_blocking: if self.debug_blocking:
self.block_detect_post() self.block_detect_post()

View File

@@ -44,6 +44,7 @@ def _signal_t2e():
_wfile.write(_bytetosend) _wfile.write(_bytetosend)
_wfile.flush() _wfile.flush()
_reqq = None _reqq = None
_rspq = None _rspq = None