[Twisted-Python] Twisted Names Deprecation Warning Fixes

In the Twisted pseudo-sprint yesterday, I made some changes to the doc/names/examples/testdns.py and twisted/names/dns.py to clean up the deprecation warnings. Attached are two svn diffs of the changes made. I've run the trials for twisted names and everything passes with the exception of testIPv6. That was skipped since I'm not using IPv6 on my laptop. Would someone please review them and commit the changes to SVN?
There's also a deprecation warning in twisted/names/client.py that I'll try to get to while at the pycon...
Thanks.
- Peter
peter@think:/space/src/twisted/Twisted> svn diff doc/names/examples/testdns.py Index: doc/names/examples/testdns.py =================================================================== --- doc/names/examples/testdns.py (revision 13290) +++ doc/names/examples/testdns.py (working copy) @@ -1,9 +1,8 @@ #!/usr/bin/env python
import sys -from twisted.names import client +from twisted.names import client, dns from twisted.internet import reactor -from twisted.protocols import dns
r = client.Resolver('/etc/resolv.conf')
@@ -27,6 +26,10 @@ if __name__ == '__main__': import sys
+ if len( sys.argv ) < 2: + print 'usage: testdns.py domain_name' + sys.exit( 1 ) + r.lookupAddress(sys.argv[1]).addCallback(gotAddress).addErrback(gotError) r.lookupMailExchange(sys.argv[1]).addCallback(gotMails).addErrback(gotError) r.lookupNameservers(sys.argv[1]).addCallback(gotNameservers).addErrback(gotError)
peter@think:/space/src/twisted/Twisted> svn diff twisted/names/dns.py Index: twisted/names/dns.py =================================================================== --- twisted/names/dns.py (revision 13294) +++ twisted/names/dns.py (working copy) @@ -1086,7 +1086,8 @@ m = Message() m.fromStr(data) if self.liveMessages.has_key(m.id): - d = self.liveMessages[m.id] + d, timeout_call = self.liveMessages[m.id] + timeout_call.cancel( ) del self.liveMessages[m.id] # XXX we shouldn't need this hack of catching exceptioon on callback() try: @@ -1123,8 +1124,13 @@ self.resends[id] = 1 m = Message(id, recDes=1) m.queries = queries - d = self.liveMessages[id] = defer.Deferred() - d.setTimeout(timeout, self._clearFailed, id) + + from twisted.internet import reactor + d = defer.Deferred() + timeoutCall = reactor.callLater( + timeout, + lambda: d.called or self._clearFailed( d, id ) ) + self.liveMessages[id] = ( d, timeoutCall ) self.writeMessage(m, address) return d

On Wed, Mar 23, 2005 at 05:49:47AM -0800, Peter Kropf wrote: [...]
@@ -1123,8 +1124,13 @@ self.resends[id] = 1 m = Message(id, recDes=1) m.queries = queries
d = self.liveMessages[id] = defer.Deferred()
d.setTimeout(timeout, self._clearFailed, id)
from twisted.internet import reactor
d = defer.Deferred()
timeoutCall = reactor.callLater(
timeout,
lambda: d.called or self._clearFailed( d, id ) )
self.liveMessages[id] = ( d, timeoutCall ) self.writeMessage(m, address) return d
I think this would be better as:
from twisted.internet import reactor d = defer.Deferred() timeoutCall = reactor.callLater(timeout, self._clearFailed, d, id) def cancelTimeout(result, timeoutCall=timeoutCall): timeoutCall.cancel() return result d.addBoth(cancelTimeout) self.liveMessages[id] = ( d, timeoutCall )
'called' is not part of Deferred's public API.
-Andrew.

Ok.
Out of curiousity, how would I find out the public API?
- Peter
Andrew Bennetts wrote:
On Wed, Mar 23, 2005 at 05:49:47AM -0800, Peter Kropf wrote: [...]
@@ -1123,8 +1124,13 @@ self.resends[id] = 1 m = Message(id, recDes=1) m.queries = queries
d = self.liveMessages[id] = defer.Deferred()
d.setTimeout(timeout, self._clearFailed, id)
from twisted.internet import reactor
d = defer.Deferred()
timeoutCall = reactor.callLater(
timeout,
lambda: d.called or self._clearFailed( d, id ) )
self.liveMessages[id] = ( d, timeoutCall ) self.writeMessage(m, address) return d
I think this would be better as:
from twisted.internet import reactor d = defer.Deferred() timeoutCall = reactor.callLater(timeout, self._clearFailed, d, id) def cancelTimeout(result, timeoutCall=timeoutCall): timeoutCall.cancel() return result d.addBoth(cancelTimeout) self.liveMessages[id] = ( d, timeoutCall )
'called' is not part of Deferred's public API.
-Andrew.
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

(I forgot to say so, but patches are best uploaded to the issue tracker, rather than the mailing list where things can easily be forgotten.)
On Wed, Mar 23, 2005 at 12:21:32PM -0800, Peter Kropf wrote:
Ok.
Out of curiousity, how would I find out the public API?
The docstrings will mention it. If the docstrings don't mention an attribute, consider it an implementation detail.
Also, I made a small mistake in my hurry this morning:
from twisted.internet import reactor d = defer.Deferred() timeoutCall = reactor.callLater(timeout, self._clearFailed, d, id) def cancelTimeout(result, timeoutCall=timeoutCall): timeoutCall.cancel()
That bit needs to be: if timeoutCall.active(): timeoutCall.cancel()
-Andrew.
participants (2)
-
Andrew Bennetts
-
Peter Kropf