Ticket #5209: 5209.patch

File 5209.patch, 1.8 KB (added by retenodus, 5 years ago)

Module deprecated

  • ../google.py

     
    77import urllib
    88from twisted.internet import protocol, reactor, defer
    99from twisted.web import http
     10from twisted.python.deprecate import deprecatedModuleAttribute
     11from twisted.python.versions import Version
    1012
    1113class GoogleChecker(http.HTTPClient):
    1214
     15    deprecatedModuleAttribute(
     16        Version('Twisted',11,1,0),
     17        "Google module is deprecated. Use Google's API instead",
     18        __name__, "GoogleChecker")
     19
    1320    def connectionMade(self):
    1421        self.sendCommand('GET', self.factory.url)
    1522        self.sendHeader('Host', self.factory.host)
     
    4047
    4148class GoogleCheckerFactory(protocol.ClientFactory):
    4249
     50    deprecatedModuleAttribute(
     51        Version('Twisted',11,1,0),
     52        "Google module is deprecated. Use Google's API instead",
     53        __name__, "GoogleCheckerFactory")
     54
    4355    protocol = GoogleChecker
    4456
    4557    def __init__(self, words):
  • test_web.py

     
    552552        d.addCallback(self.assertEqual, 'http://twistedmatrix.com/')
    553553        return d
    554554
     555    def test_deprecatedModule(self):
     556        google.GoogleChecker
     557        google.GoogleCheckerFactory
     558        warnings = self.flushWarnings([self.test_deprecatedModule])
     559        self.assertEqual(len(warnings),2)
     560        self.assertEqual(warnings[0]['category'],DeprecationWarning)
     561        self.assertIn("Google module is deprecated. Use Google's API instead",warnings[0]['message'])
    555562
    556563
    557564
    558565
     566
    559567class RequestTests(unittest.TestCase):
    560568    """
    561569    Tests for the HTTP request class, L{server.Request}.