Ticket #5768: google-5678.patch
| File google-5678.patch, 5.5 KB (added by thijs, 10 months ago) |
|---|
-
twisted/web/test/test_web.py
587 587 588 588 589 589 590 591 from twisted.web import google592 class GoogleTestCase(unittest.TestCase):593 def testCheckGoogle(self):594 raise unittest.SkipTest("no violation of google ToS")595 d = google.checkGoogle('site:www.twistedmatrix.com twisted')596 d.addCallback(self.assertEqual, 'http://twistedmatrix.com/')597 return d598 599 600 def test_deprecated(self):601 """602 Google module is deprecated since Twisted 11.1.0603 """604 from twisted.web import google605 warnings = self.flushWarnings(offendingFunctions=[self.test_deprecated])606 self.assertEqual(len(warnings), 1)607 self.assertEqual(warnings[0]['category'], DeprecationWarning)608 609 610 611 590 class RequestTests(unittest.TestCase): 612 591 """ 613 592 Tests for the HTTP request class, L{server.Request}. -
twisted/web/topfiles/5678.removal
1 twisted.web.google, deprecated since Twisted 11.1, is removed now. -
twisted/web/__init__.py
10 10 """ 11 11 12 12 from twisted.web._version import version 13 from twisted.python.versions import Version14 from twisted.python.deprecate import deprecatedModuleAttribute15 13 16 14 __version__ = version.short() 17 15 18 deprecatedModuleAttribute(19 Version('Twisted', 11, 1, 0),20 "Google module is deprecated. Use Google's API instead",21 __name__, "google") -
twisted/web/google.py
1 # Copyright (c) Twisted Matrix Laboratories.2 # See LICENSE for details.3 4 #5 """\"I'm Feeling Lucky\" with U{Google<http://google.com>}.6 """7 import urllib8 from twisted.internet import protocol, reactor, defer9 from twisted.web import http10 11 class GoogleChecker(http.HTTPClient):12 13 def connectionMade(self):14 self.sendCommand('GET', self.factory.url)15 self.sendHeader('Host', self.factory.host)16 self.sendHeader('User-Agent', self.factory.agent)17 self.endHeaders()18 19 def handleHeader(self, key, value):20 key = key.lower()21 if key == 'location':22 self.factory.gotLocation(value)23 24 def handleStatus(self, version, status, message):25 if status != '302':26 self.factory.noLocation(ValueError("bad status"))27 28 def handleEndHeaders(self):29 self.factory.noLocation(ValueError("no location"))30 31 def handleResponsePart(self, part):32 pass33 34 def handleResponseEnd(self):35 pass36 37 def connectionLost(self, reason):38 self.factory.noLocation(reason)39 40 41 class GoogleCheckerFactory(protocol.ClientFactory):42 43 protocol = GoogleChecker44 45 def __init__(self, words):46 self.url = ('/search?q=%s&btnI=%s' %47 (urllib.quote_plus(' '.join(words)),48 urllib.quote_plus("I'm Feeling Lucky")))49 self.agent="Twisted/GoogleChecker"50 self.host = "www.google.com"51 self.deferred = defer.Deferred()52 53 def clientConnectionFailed(self, _, reason):54 self.noLocation(reason)55 56 def gotLocation(self, location):57 if self.deferred:58 self.deferred.callback(location)59 self.deferred = None60 61 def noLocation(self, error):62 if self.deferred:63 self.deferred.errback(error)64 self.deferred = None65 66 67 def checkGoogle(words):68 """Check google for a match.69 70 @returns: a Deferred which will callback with a URL or errback with a71 Failure.72 """73 factory = GoogleCheckerFactory(words)74 reactor.connectTCP('www.google.com', 80, factory)75 return factory.deferred -
doc/web/examples/index.xhtml
85 85 distributed web setup with a master and slave using 86 86 <code>twisted.web.distrib</code> and 87 87 <code>twisted.spread.pb</code></li> 88 <li><a href="google.py">google.py</a> - use89 <code>twisted.web.google</code> to get the I'm Feeling Lucky90 page for a search term</li>91 88 <li><a href="soap.py">soap.py</a> - use 92 89 <code>twisted.web.soap</code> to publish SOAP methods</li> 93 90 </ul> -
doc/web/examples/google.py
1 # Copyright (c) Twisted Matrix Laboratories2 # See LICENSE for details.3 4 """5 This program will print out the URL corresponding to the first webpage given by6 a Google search.7 8 Usage:9 $ python google.py <keyword(s)>10 """11 12 import sys13 14 from twisted.web.google import checkGoogle15 from twisted.python.util import println16 from twisted.internet import reactor17 18 checkGoogle(sys.argv[1:]).addCallbacks(19 lambda l:(println(l),reactor.stop()),20 lambda e:(println('error:',e),reactor.stop()))21 reactor.run()
