From ef38c820b3e6831352c8fcc5a056ef7b1aadb109 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 7 Apr 2016 20:47:29 -1000 Subject: [PATCH] Tub.listenOn: tolerate non-qualified strings like "12345" Tahoe still uses these, so convert them into "tcp:12345" (which is a valid endpoint specification) and emit a DeprecationWarning. --- src/foolscap/pb.py | 9 ++++++++- src/foolscap/test/test_listener.py | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/foolscap/pb.py b/src/foolscap/pb.py index e703e233..85752e8e 100644 --- a/src/foolscap/pb.py +++ b/src/foolscap/pb.py @@ -1,6 +1,6 @@ # -*- test-case-name: foolscap.test.test_pb -*- -import os.path, weakref, binascii +import os.path, weakref, binascii, re from warnings import warn from zope.interface import implements from twisted.internet import (reactor, defer, protocol, error, interfaces, @@ -500,6 +500,13 @@ def listenOn(self, what, _test_options={}): "port numbers instead") warn(warningString, DeprecationWarning, stacklevel=2) + if isinstance(what, str) and re.search(r"^\d+$", what): + warn("Tub.listenOn('12345') was deprecated " + "in Foolscap 0.12.0; please use qualified endpoint " + "descriptions like 'tcp:12345'", + DeprecationWarning, stacklevel=2) + what = "tcp:%s" % what + l = Listener(self, what, _test_options, self.negotiationClass) self.listeners.append(l) l.setServiceParent(self) diff --git a/src/foolscap/test/test_listener.py b/src/foolscap/test/test_listener.py index 7e594f5b..f03ed5e4 100644 --- a/src/foolscap/test/test_listener.py +++ b/src/foolscap/test/test_listener.py @@ -53,6 +53,15 @@ def test_parsed_endpoint(self): furl = tubA.registerReference(Target()) yield tubB.getReference(furl) + @inlineCallbacks + def test_nonqualified_port(self): + tubA, tubB = self.makeTubs() + portnum = util.allocate_tcp_port() + tubA.listenOn("%d" % portnum) # this is deprecated + tubA.setLocation("tcp:127.0.0.1:%d" % portnum) + furl = tubA.registerReference(Target()) + yield tubB.getReference(furl) + def test_invalid(self): tubA, tubB = self.makeTubs() self.assertRaises(TypeError, tubA.listenOn, 42)