Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Chapter3-Deferreds/ex4.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# Errata note: when TNPE 2ed was first printed, Twisted 12.0.0 was the latest
# version of Twisted. Since then, passing bare strings to the errback method
# was deprecated in Twisted 12.3.0. A failure or Exception must now be
# passed instead.

from twisted.internet import reactor, defer


class HeadlineRetriever(object):

def processHeadline(self, headline):
if len(headline) > 50:
self.d.errback(
"The headline ``%s'' is too long!" % (headline,))
ValueError("The headline ``%s'' is too long!" % (headline,)))
else:
self.d.callback(headline)

Expand All @@ -17,10 +24,12 @@ def getHeadline(self, input):
self.d.addCallback(self._toHTML)
return self.d


def printData(result):
print result
reactor.stop()


def printError(failure):
print failure
reactor.stop()
Expand Down
2 changes: 1 addition & 1 deletion Chapter4-Web-Servers/ex2-requesthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MyRequestHandler(http.Request):

def process(self):
self.setHeader('Content-Type', 'text/html')
if self.resources.has_key(self.path):
if self.path in self.resources:
self.write(self.resources[self.path])
else:
self.setResponseCode(http.NOT_FOUND)
Expand Down
2 changes: 1 addition & 1 deletion Chapter5-Web-Clients/ex1-print_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def stop(result):
reactor.stop()

if len(sys.argv) != 2:
print >>sys.stderr, "Usage: python print_resource.py <URL>"
printError("Usage: python print_resource.py <URL>")
exit(1)

d = getPage(sys.argv[1])
Expand Down
2 changes: 1 addition & 1 deletion Chapter5-Web-Clients/ex2-download_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def stop(result):
reactor.stop()

if len(sys.argv) != 3:
print >>sys.stderr, "Usage: python download_resource.py <URL> <output file>"
printError("Usage: python download_resource.py <URL> <output file>")
exit(1)

d = downloadPage(sys.argv[1], sys.argv[2])
Expand Down
2 changes: 1 addition & 1 deletion Chapter5-Web-Clients/ex3-agent_print_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def stop(result):
reactor.stop()

if len(sys.argv) != 2:
print >>sys.stderr, "Usage: python agent_print_resource.py URL"
printError("Usage: python agent_print_resource.py URL")
exit(1)

agent = Agent(reactor)
Expand Down
2 changes: 1 addition & 1 deletion Chapter5-Web-Clients/ex4-print_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def stop(result):
reactor.stop()

if len(sys.argv) != 2:
print >>sys.stderr, "Usage: python print_metadata.py URL"
printError("Usage: python print_metadata.py URL")
exit(1)

agent = Agent(reactor)
Expand Down
2 changes: 1 addition & 1 deletion Chapter5-Web-Clients/ex5-post_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def stop(result):
reactor.stop()

if len(sys.argv) != 3:
print >>sys.stderr, "Usage: python post_resource.py URL 'POST DATA'"
printError("Usage: python post_resource.py URL 'POST DATA'")
exit(1)

agent = Agent(reactor)
Expand Down