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
- Add support for PyPy.
- Drop support for Python 2.5. Python 2.5 users can continue to use
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.
- 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
buffered to unbuffered. PR #542 by Romuald Brunet.
- Upgraded c-ares to 1.10.0. PR #579 by Omer Katz.
......@@ -34,6 +34,8 @@ Unreleased
should assist things like Sentry to track the original problem. PRs
#450 and #528 by Rodolfo and Eddi Linder.
- 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
-------------
......
......@@ -208,9 +208,9 @@ class BaseServer(object):
result += str(ex) or '<error>'
handle = self.__dict__.get('handle')
try:
if handle is not None:
fself = getattr(handle, '__self__')
fself = getattr(handle, '__self__', None)
try:
if fself is self:
# Checks the __self__ of the handle in case it is a bound
# method of self to prevent recursivly defined reprs.
......@@ -222,8 +222,8 @@ class BaseServer(object):
handle_repr = repr(handle)
result += ' handle=' + handle_repr
except AttributeError:
pass
except Exception as ex:
result += str(ex) or '<error>'
return result
......
......@@ -82,7 +82,12 @@ class TestCase(greentest.TestCase):
def makefile(self, timeout=0.1, bufsize=1):
sock = socket.socket()
try:
sock.connect((self.server.server_host, self.server.server_port))
except:
# avoid ResourceWarning under Py3
sock.close()
raise
if PY3:
# Under Python3, you can't read and write to the same
......@@ -107,7 +112,10 @@ class TestCase(greentest.TestCase):
def assertConnectionRefused(self):
try:
conn = self.makefile()
try:
raise AssertionError('Connection was not refused: %r' % (conn._sock, ))
finally:
conn.close()
except socket.error as ex:
if ex.args[0] not in (errno.ECONNREFUSED, errno.EADDRNOTAVAIL):
raise
......@@ -181,9 +189,6 @@ class TestCase(greentest.TestCase):
self.assert_error(TypeError)
finally:
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):
kwargs.setdefault('spawn', self.get_spawn())
......@@ -314,6 +319,26 @@ class TestDefaultSpawn(TestCase):
gevent.sleep(0.1)
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):
......
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