Python3: __bool__, im_code, im_func
This commit is contained in:

committed by
Sergey Shepelev

parent
49773bb12b
commit
fb6b46dea0
@@ -150,6 +150,8 @@ class Queue(object):
|
||||
def __nonzero__(self):
|
||||
return len(self.items)>0
|
||||
|
||||
__bool__ = __nonzero__
|
||||
|
||||
def __len__(self):
|
||||
return len(self.items)
|
||||
|
||||
@@ -224,6 +226,8 @@ class Channel(object):
|
||||
def __nonzero__(self):
|
||||
return len(self.items)>0
|
||||
|
||||
__bool__ = __nonzero__
|
||||
|
||||
def __len__(self):
|
||||
return len(self.items)
|
||||
|
||||
|
@@ -135,8 +135,9 @@ class BaseConnectionPool(Pool):
|
||||
def _unwrap_connection(self, conn):
|
||||
""" If the connection was wrapped by a subclass of
|
||||
BaseConnectionWrapper and is still functional (as determined
|
||||
by the __nonzero__ method), returns the unwrapped connection.
|
||||
If anything goes wrong with this process, returns None.
|
||||
by the __nonzero__, or __bool__ in python3, method), returns
|
||||
the unwrapped connection. If anything goes wrong with this
|
||||
process, returns None.
|
||||
"""
|
||||
base = None
|
||||
try:
|
||||
@@ -336,6 +337,8 @@ class PooledConnectionWrapper(GenericConnectionWrapper):
|
||||
def __nonzero__(self):
|
||||
return (hasattr(self, '_base') and bool(self._base))
|
||||
|
||||
__bool__ = __nonzero__
|
||||
|
||||
def _destroy(self):
|
||||
self._pool = None
|
||||
try:
|
||||
|
@@ -6,6 +6,7 @@ import eventlet
|
||||
from eventlet import greenio
|
||||
from eventlet import patcher
|
||||
from eventlet.green import select
|
||||
from eventlet.support import six
|
||||
|
||||
|
||||
patcher.inject('subprocess', globals(), ('select', select))
|
||||
@@ -77,19 +78,23 @@ class Popen(subprocess_orig.Popen):
|
||||
# don't want to rewrite the original _communicate() method, we
|
||||
# just want a version that uses eventlet.green.select.select()
|
||||
# instead of select.select().
|
||||
_communicate = FunctionType(subprocess_orig.Popen._communicate.im_func.func_code,
|
||||
globals())
|
||||
_communicate = FunctionType(
|
||||
six.get_function_code(six.get_unbound_function(
|
||||
subprocess_orig.Popen._communicate)),
|
||||
globals())
|
||||
try:
|
||||
_communicate_with_select = FunctionType(
|
||||
subprocess_orig.Popen._communicate_with_select.im_func.func_code,
|
||||
six.get_function_code(six.get_unbound_function(
|
||||
subprocess_orig.Popen._communicate_with_select)),
|
||||
globals())
|
||||
_communicate_with_poll = FunctionType(
|
||||
subprocess_orig.Popen._communicate_with_poll.im_func.func_code,
|
||||
six.get_function_code(six.get_unbound_function(
|
||||
subprocess_orig.Popen._communicate_with_poll)),
|
||||
globals())
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# Borrow subprocess.call() and check_call(), but patch them so they reference
|
||||
# OUR Popen class rather than subprocess.Popen.
|
||||
call = FunctionType(subprocess_orig.call.func_code, globals())
|
||||
check_call = FunctionType(subprocess_orig.check_call.func_code, globals())
|
||||
call = FunctionType(six.get_function_code(subprocess_orig.call), globals())
|
||||
check_call = FunctionType(six.get_function_code(subprocess_orig.check_call), globals())
|
||||
|
@@ -42,6 +42,8 @@ class _QueueLock(object):
|
||||
def __nonzero__(self):
|
||||
return self._count
|
||||
|
||||
__bool__ = __nonzero__
|
||||
|
||||
def __enter__(self):
|
||||
self.acquire()
|
||||
|
||||
@@ -88,6 +90,8 @@ class _BlockedThread(object):
|
||||
def __nonzero__(self):
|
||||
return self._blocked_thread is not None
|
||||
|
||||
__bool__ = __nonzero__
|
||||
|
||||
def block(self):
|
||||
if self._blocked_thread is not None:
|
||||
raise Exception("Cannot block more than one thread on one BlockedThread")
|
||||
|
@@ -547,6 +547,8 @@ class Proc(Source):
|
||||
if self.greenlet is not None:
|
||||
return bool(self.greenlet)
|
||||
|
||||
__bool__ = __nonzero__
|
||||
|
||||
@property
|
||||
def dead(self):
|
||||
return self.ready() or self.greenlet.dead
|
||||
|
@@ -98,6 +98,8 @@ class Waiter(object):
|
||||
def __nonzero__(self):
|
||||
return self.greenlet is not None
|
||||
|
||||
__bool__ = __nonzero__
|
||||
|
||||
@property
|
||||
def waiting(self):
|
||||
return self.greenlet is not None
|
||||
|
@@ -220,6 +220,7 @@ class Proxy(object):
|
||||
return len(self._obj)
|
||||
def __nonzero__(self):
|
||||
return bool(self._obj)
|
||||
__bool__ = __nonzero__
|
||||
def __iter__(self):
|
||||
it = iter(self._obj)
|
||||
if it == self._obj:
|
||||
|
Reference in New Issue
Block a user