Ticket #6395: 6395-2.patch

File 6395-2.patch, 4.4 KB (added by moijes12, 5 years ago)

Building on thijs' comments. Attaching a tested patch.

  • docs/words/examples/msn_example.py

     
    1 #!/usr/bin/env python
    2 
    3 # Copyright (c) Twisted Matrix Laboratories.
    4 # See LICENSE for details.
    5 
    6 # Twisted Imports
    7 from twisted.internet import reactor
    8 from twisted.internet.protocol import ClientFactory
    9 from twisted.words.protocols import msn
    10 from twisted.python import log
    11 
    12 # System Imports
    13 import sys, getpass
    14 
    15 """
    16 This simple example connects to the MSN chat service and
    17 prints out information about all the users on your
    18 contact list (both online and offline).
    19 
    20 The main aim of this example is to demonstrate
    21 the connection process.
    22 
    23 @author Samuel Jordan
    24 
    25 To run the script::
    26 
    27     $ python msn_example.py
    28 """
    29 
    30 
    31 def _createNotificationFac():
    32     fac = msn.NotificationFactory.forProtocol(Notification)
    33     fac.userHandle = USER_HANDLE
    34     fac.password = PASSWORD
    35     return fac
    36 
    37 class Dispatch(msn.DispatchClient):
    38 
    39     def __init__(self):
    40         msn.DispatchClient.__init__(self)
    41         self.userHandle = USER_HANDLE
    42 
    43     def gotNotificationReferral(self, host, port):
    44         self.transport.loseConnection()
    45         reactor.connectTCP(host, port, _createNotificationFac())
    46 
    47 class Notification(msn.NotificationClient):
    48 
    49     def loginFailure(self, message):
    50         print 'Login failure:', message
    51 
    52     def listSynchronized(self, *args):
    53         contactList = self.factory.contacts
    54         print 'Contact list has been synchronized, number of contacts = %s' % len(contactList.getContacts())
    55         for contact in contactList.getContacts().values():
    56             print 'Contact: %s' % (contact.screenName,)
    57             print '    email: %s' % (contact.userHandle,)
    58             print '   groups:'
    59             for group in contact.groups:
    60                 print '      - %s' % contactList.groups[group]
    61             print
    62 
    63 if __name__ == '__main__':
    64     USER_HANDLE = raw_input("Email (passport): ")
    65     PASSWORD = getpass.getpass()
    66     log.startLogging(sys.stdout)
    67     _dummy_fac = ClientFactory()
    68     _dummy_fac.protocol = Dispatch
    69     reactor.connectTCP('messenger.hotmail.com', 1863, _dummy_fac)
    70     reactor.run()
  • twisted/words/protocols/__init__.py

     
    55"""
    66Chat protocols.
    77"""
     8
     9from twisted.python import deprecate, versions
     10
     11deprecate.deprecatedModuleAttribute(
     12    versions.Version("Twisted", 14, 1, 0), "MSN has shutdown.", __name__,
     13    "msn")
     14 No newline at end of file
  • twisted/words/test/test_msn.py

     
    513513        d.addCallback(check)
    514514        return d
    515515
     516
     517
     518class DeprecationTests(unittest.TestCase):
     519    """
     520    Test deprecation of L{twisted.words.protocols.msn}
     521    """
     522   
     523    def test_deprecation(self):
     524        """
     525        Accessing L{twisted.words.protocols.msn} emits a deprecation warning
     526        """
     527        from twisted.words.protocols import msn
     528        warningsShown = self.flushWarnings([self.test_deprecation])
     529        self.assertEqual(len(warningsShown), 1)
     530        self.assertIdentical(warningsShown[0]['category'], DeprecationWarning)
     531        self.assertEqual(
     532            warningsShown[0]['message'],
     533            'twisted.words.protocols.msn was deprecated in Twisted 14.1.0: ' +
     534            'MSN has shutdown.')
     535
    516536if msn is None:
    517537    for testClass in [DispatchTests, PassportTests, NotificationTests,
    518                       MessageHandlingTests, FileTransferTestCase]:
     538                      MessageHandlingTests, FileTransferTestCase,
     539                      DeprecationTests]:
    519540        testClass.skip = (
    520541            "MSN requires an HTTP client but none is available, "
    521542            "skipping tests.")
  • twisted/words/topfiles/6395.misc

     
     1twisted.words.protocols.msn is now deprecated
     2 No newline at end of file