Skip to content

Commit

Permalink
Tub.listenOn: tolerate non-qualified strings like "12345"
Browse files Browse the repository at this point in the history
Tahoe still uses these, so convert them into "tcp:12345" (which is a
valid endpoint specification) and emit a DeprecationWarning.
  • Loading branch information
warner committed Apr 8, 2016
1 parent 98c28e0 commit ef38c82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/foolscap/pb.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/foolscap/test/test_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit ef38c82

Please sign in to comment.