Commit 5b3fd014 authored by Jason Madden's avatar Jason Madden

Make the BaseServer's repr again show a handle if it's *not* an instancemethod...

Make the BaseServer's repr again show a handle if it's *not* an instancemethod and add a test case for the various possibilities. Update the changelog.
parent fc72362e
...@@ -13,9 +13,9 @@ Unreleased ...@@ -13,9 +13,9 @@ Unreleased
- Add support for PyPy. - Add support for PyPy.
- Drop support for Python 2.5. Python 2.5 users can continue to use - Drop support for Python 2.5. Python 2.5 users can continue to use
gevent 1.0.x. gevent 1.0.x.
- Fix gevent.greenlet.joinall to not ignore ``count`` when - Fix ``gevent.greenlet.joinall`` to not ignore ``count`` when
``raise_error`` is False. PR #512 by Ivan Diao. ``raise_error`` is False. PR #512 by Ivan Diao.
- Fix subprocess.Popen to not ignore the ``bufsize`` argument. Note - Fix ``subprocess.Popen`` to not ignore the ``bufsize`` argument. Note
that this changes the (platform dependent) default, typically from that this changes the (platform dependent) default, typically from
buffered to unbuffered. PR #542 by Romuald Brunet. buffered to unbuffered. PR #542 by Romuald Brunet.
- Upgraded c-ares to 1.10.0. PR #579 by Omer Katz. - Upgraded c-ares to 1.10.0. PR #579 by Omer Katz.
...@@ -34,6 +34,8 @@ Unreleased ...@@ -34,6 +34,8 @@ Unreleased
should assist things like Sentry to track the original problem. PRs should assist things like Sentry to track the original problem. PRs
#450 and #528 by Rodolfo and Eddi Linder. #450 and #528 by Rodolfo and Eddi Linder.
- Upgrade to libev 4.20. PR #590 by Peter Renström. - Upgrade to libev 4.20. PR #590 by Peter Renström.
- Fix ``gevent.baseserver.BaseServer`` to be printable when its
``handle`` function is an instancemethod of itself. PR #501 by Joe Jevnik.
Release 1.0.2 Release 1.0.2
------------- -------------
......
...@@ -208,9 +208,9 @@ class BaseServer(object): ...@@ -208,9 +208,9 @@ class BaseServer(object):
result += str(ex) or '<error>' result += str(ex) or '<error>'
handle = self.__dict__.get('handle') handle = self.__dict__.get('handle')
try: if handle is not None:
if handle is not None: fself = getattr(handle, '__self__', None)
fself = getattr(handle, '__self__') try:
if fself is self: if fself is self:
# Checks the __self__ of the handle in case it is a bound # Checks the __self__ of the handle in case it is a bound
# method of self to prevent recursivly defined reprs. # method of self to prevent recursivly defined reprs.
...@@ -222,8 +222,8 @@ class BaseServer(object): ...@@ -222,8 +222,8 @@ class BaseServer(object):
handle_repr = repr(handle) handle_repr = repr(handle)
result += ' handle=' + handle_repr result += ' handle=' + handle_repr
except AttributeError: except Exception as ex:
pass result += str(ex) or '<error>'
return result return result
......
...@@ -82,7 +82,12 @@ class TestCase(greentest.TestCase): ...@@ -82,7 +82,12 @@ class TestCase(greentest.TestCase):
def makefile(self, timeout=0.1, bufsize=1): def makefile(self, timeout=0.1, bufsize=1):
sock = socket.socket() sock = socket.socket()
sock.connect((self.server.server_host, self.server.server_port)) try:
sock.connect((self.server.server_host, self.server.server_port))
except:
# avoid ResourceWarning under Py3
sock.close()
raise
if PY3: if PY3:
# Under Python3, you can't read and write to the same # Under Python3, you can't read and write to the same
...@@ -107,7 +112,10 @@ class TestCase(greentest.TestCase): ...@@ -107,7 +112,10 @@ class TestCase(greentest.TestCase):
def assertConnectionRefused(self): def assertConnectionRefused(self):
try: try:
conn = self.makefile() conn = self.makefile()
raise AssertionError('Connection was not refused: %r' % (conn._sock, )) try:
raise AssertionError('Connection was not refused: %r' % (conn._sock, ))
finally:
conn.close()
except socket.error as ex: except socket.error as ex:
if ex.args[0] not in (errno.ECONNREFUSED, errno.EADDRNOTAVAIL): if ex.args[0] not in (errno.ECONNREFUSED, errno.EADDRNOTAVAIL):
raise raise
...@@ -181,9 +189,6 @@ class TestCase(greentest.TestCase): ...@@ -181,9 +189,6 @@ class TestCase(greentest.TestCase):
self.assert_error(TypeError) self.assert_error(TypeError)
finally: finally:
self.server.stop() self.server.stop()
# XXX: There's an unreachable greenlet that has a traceback.
# We need to clear it to make the leak checks work
import gc; gc.collect()
def ServerClass(self, *args, **kwargs): def ServerClass(self, *args, **kwargs):
kwargs.setdefault('spawn', self.get_spawn()) kwargs.setdefault('spawn', self.get_spawn())
...@@ -314,6 +319,26 @@ class TestDefaultSpawn(TestCase): ...@@ -314,6 +319,26 @@ class TestDefaultSpawn(TestCase):
gevent.sleep(0.1) gevent.sleep(0.1)
assert self.server.started assert self.server.started
def test_server_repr_when_handle_is_instancemethod(self):
# PR 501
self.init_server()
self.start_server()
self.assertTrue('<SimpleStreamServer' in repr(self.server))
self.server.set_handle(self.server.handle)
self.assertTrue('handle=<bound method SimpleStreamServer.handle of self>' in repr(self.server),
repr(self.server))
self.server.set_handle(self.test_server_repr_when_handle_is_instancemethod)
self.assertTrue('test_server_repr_when_handle_is_instancemethod' in repr(self.server),
repr(self.server))
def handle():
pass
self.server.set_handle(handle)
self.assertTrue('handle=<function' in repr(self.server),
repr(self.server))
class TestRawSpawn(TestDefaultSpawn): class TestRawSpawn(TestDefaultSpawn):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment