[Checkins] SVN: zc.monitor/trunk/src/zc/monitor/ ``start`` now returns the address being listened on, which is useful
Jim Fulton
jim at zope.com
Sat Dec 10 17:37:27 UTC 2011
Log message for revision 123667:
``start`` now returns the address being listened on, which is useful
when binding to port 0.
Changed:
U zc.monitor/trunk/src/zc/monitor/CHANGES.txt
U zc.monitor/trunk/src/zc/monitor/README.txt
U zc.monitor/trunk/src/zc/monitor/__init__.py
-=-
Modified: zc.monitor/trunk/src/zc/monitor/CHANGES.txt
===================================================================
--- zc.monitor/trunk/src/zc/monitor/CHANGES.txt 2011-12-10 17:27:23 UTC (rev 123666)
+++ zc.monitor/trunk/src/zc/monitor/CHANGES.txt 2011-12-10 17:37:27 UTC (rev 123667)
@@ -2,12 +2,15 @@
Change History
==============
-0.2.1 (unreleased)
+0.2.1 (2011-12-10)
------------------
- Added an ``address`` option to ``start`` to be able to specify an adapter
to bind to.
+- ``start`` now returns the address being listened on, which is useful
+ when binding to port 0.
+
- Using Python's ``doctest`` module instead of depreacted
``zope.testing.doctest``.
Modified: zc.monitor/trunk/src/zc/monitor/README.txt
===================================================================
--- zc.monitor/trunk/src/zc/monitor/README.txt 2011-12-10 17:27:23 UTC (rev 123666)
+++ zc.monitor/trunk/src/zc/monitor/README.txt 2011-12-10 17:37:27 UTC (rev 123667)
@@ -219,7 +219,7 @@
>>> zc.monitor.start(9644)
- True
+ ('', 9644)
>>> print loghandler
zc.ngi.async.server INFO
@@ -229,12 +229,10 @@
>>> zc.monitor.last_listener = None
>>> time.sleep(0.1)
-
-
>>> loghandler.clear()
>>> zc.monitor.start(('127.0.0.1', 9644))
- True
+ ('127.0.0.1', 9644)
>>> print loghandler
zc.ngi.async.server INFO
@@ -244,12 +242,22 @@
>>> zc.monitor.last_listener = None
>>> time.sleep(0.1)
+Bind to port 0:
+
+ >>> addr = zc.monitor.start(0)
+ >>> addr == zc.monitor.last_listener.address
+ True
+
+ >>> zc.monitor.last_listener.close()
+ >>> zc.monitor.last_listener = None
+ >>> time.sleep(0.1)
+
Trying to rebind to a port in use:
>>> loghandler.clear()
>>> zc.monitor.start(('127.0.0.1', 9644))
- True
+ ('127.0.0.1', 9644)
>>> zc.monitor.start(('127.0.0.1', 9644))
False
@@ -266,4 +274,4 @@
>>> zc.monitor.last_listener = None
>>> time.sleep(0.1)
- >>> loghandler.uninstall()
\ No newline at end of file
+ >>> loghandler.uninstall()
Modified: zc.monitor/trunk/src/zc/monitor/__init__.py
===================================================================
--- zc.monitor/trunk/src/zc/monitor/__init__.py 2011-12-10 17:27:23 UTC (rev 123666)
+++ zc.monitor/trunk/src/zc/monitor/__init__.py 2011-12-10 17:37:27 UTC (rev 123667)
@@ -75,8 +75,9 @@
def start(address):
"""start monitor server.
- Returns True if monitor server started; returns False if the port is
- already in use; and raises an exception otherwise.
+ Returns the listener address (which may be different from the
+ given address) if monitor server started; returns False if the
+ port is already in use; and raises an exception otherwise.
"""
import zc.ngi.async
@@ -105,7 +106,7 @@
return False
else:
raise
- return True
+ return last_listener.address
# default commands
More information about the checkins
mailing list