Ticket #6166: ticket6166_2.patch

File ticket6166_2.patch, 9.3 KB (added by Can Ibanoglu, 8 years ago)

Removed # from the filename

  • twisted/test/test_sslverify.py

     
    88
    99from __future__ import division, absolute_import
    1010
    11 import itertools
     11import itertools, warnings
    1212
    1313try:
    1414    from OpenSSL import SSL
     
    1818except ImportError:
    1919    pass
    2020
     21from twisted.python.versions import Version
     22
    2123from twisted.python.compat import nativeString
    2224from twisted.trial import unittest
    2325from twisted.internet import protocol, defer, reactor
     
    2628from twisted.internet import interfaces
    2729
    2830
     31
    2932# A couple of static PEM-format certificates to be used by various tests.
    3033A_HOST_CERTIFICATE_PEM = """
    3134-----BEGIN CERTIFICATE-----
     
    355358        context = firstOpts.getContext()
    356359        self.assertIdentical(context, firstOpts._context)
    357360        self.assertNotIdentical(context, None)
    358         state = firstOpts.__getstate__()
     361        with warnings.catch_warnings():
     362            warnings.filterwarnings(action="ignore", category=DeprecationWarning,
     363                message="twisted.internet._sslverify.OpenSSLCertificateOptions"
     364                ".__getstate__ was deprecated in Twisted 13.1.0: Pickling is no longer supported.")
     365            state = firstOpts.__getstate__()
    359366        self.assertNotIn("_context", state)
    360367
    361368        opts = sslverify.OpenSSLCertificateOptions()
    362         opts.__setstate__(state)
     369        with warnings.catch_warnings():
     370            warnings.filterwarnings(action="ignore", category=DeprecationWarning,
     371                message="twisted.internet._sslverify.OpenSSLCertificateOptions"
     372                ".__setstate__ was deprecated in Twisted 13.1.0: Pickling is no longer supported.")
     373            opts.__setstate__(state)
    363374        self.assertEqual(opts.privateKey, self.sKey)
    364375        self.assertEqual(opts.certificate, self.sCert)
    365376        self.assertEqual(opts.method, SSL.SSLv3_METHOD)
     
    648659
    649660if interfaces.IReactorSSL(reactor, None) is None:
    650661    Constructors.skip = "Reactor does not support SSL, cannot run SSL tests"
     662
     663class DeprecationTestCase(unittest.TestCase):
     664    """
     665    Test deprecations in twisted.internet._sslverify
     666    """
     667
     668    def lookForDeprecationWarning(self, testMethod, className, methodName, warningMsg):
     669        """
     670        Test deprecation of class method '_sslverify.className.methodName' by calling
     671        '_sslverify.testMethod' and verifying the warning message
     672        '_sslverify.warningMsg'
     673
     674        @param testMethod: Name of the offending function to be used with
     675            flushWarnings
     676        @type testmethod: C{str}
     677
     678        @param className: Name of class containing the deprecated method
     679        @type className: C{str}
     680
     681        @param methodName: Name of method to be checked for deprecation
     682        @type methodName: C{str}
     683
     684        @param warningMsg: Deprecation warning message
     685        @type warningMsg: C{str}
     686        """
     687        warningsShown = self.flushWarnings([testMethod])
     688        self.assertEqual(len(warningsShown), 1)
     689        self.assertIdentical(warningsShown[0]['category'], DeprecationWarning)
     690        self.assertEqual(
     691            warningsShown[0]['message'],
     692            "twisted.internet._sslverify." + className + "." + methodName +
     693            " was deprecated in Twisted 13.1.0: " + warningMsg)
     694
     695    def test_getstateDeprecationInOpenSSLCertificationOptions(self):
     696        """
     697        Test deprecation of L{_sslverify.OpenSSLCertificateOptions.__getstate__}
     698        """
     699        sslverify.OpenSSLCertificateOptions().__getstate__()
     700        self.lookForDeprecationWarning(
     701            self.test_getstateDeprecationInOpenSSLCertificationOptions, "OpenSSLCertificateOptions",
     702            "__getstate__",
     703            "Pickling is no longer supported.")
     704
     705    def test_setstateDeprecationInOpenSSLCertificationOptions(self):
     706        """
     707        Test deprecation of L{_sslverify.OpenSSLCertificateOptions.__setstate__}
     708        """
     709        with warnings.catch_warnings():
     710            warnings.filterwarnings(action="ignore", category=DeprecationWarning,
     711                message="twisted.internet._sslverify.OpenSSLCertificateOptions"
     712                ".__getstate__ was deprecated in Twisted 13.1.0: Pickling is no longer supported.")
     713            state = sslverify.OpenSSLCertificateOptions().__getstate__()
     714       
     715        sslverify.OpenSSLCertificateOptions().__setstate__(state)
     716        self.lookForDeprecationWarning(
     717            self.test_setstateDeprecationInOpenSSLCertificationOptions, "OpenSSLCertificateOptions",
     718            "__setstate__",
     719            "Pickling is no longer supported.")
     720
     721    def test_getstateDeprecationInKeyPair(self):
     722        """
     723        Test deprecation of L{_sslverify.KeyPair.__getstate__}
     724        """
     725        sKey = makeCertificate(
     726            O=b"Server Test Certificate",
     727            CN=b"server")[0]
     728        sslverify.KeyPair(sKey).__getstate__()
     729        self.lookForDeprecationWarning(
     730            self.test_getstateDeprecationInKeyPair, "KeyPair", "__getstate__",
     731            "Pickling is no longer supported.")
     732
     733    def test_setstateDeprecationInKeyPair(self):
     734        """
     735        Test deprecation of L{_sslverify.KeyPair.__setstate__}
     736        """
     737        sKey = makeCertificate(
     738            O=b"Server Test Certificate",
     739            CN=b"server")[0]
     740        with warnings.catch_warnings():
     741            warnings.filterwarnings(action="ignore", category=DeprecationWarning,
     742                message="twisted.internet._sslverify.KeyPair"
     743                ".__getstate__ was deprecated in Twisted 13.1.0: Pickling is no longer supported.")
     744            state = sslverify.KeyPair(sKey).__getstate__()
     745        sslverify.KeyPair(sKey).__setstate__(state)
     746        self.lookForDeprecationWarning(
     747            self.test_setstateDeprecationInKeyPair, "KeyPair", "__setstate__",
     748            "Pickling is no longer supported.")
  • twisted/topfiles/6166.removal

     
     1twisted.internet._sslverify.OpenSSLCertificateOptions.__getstate__ is now deprecated due to pickling not being supported anymore.
     2twisted.internet._sslverify.OpenSSLCertificateOptions.__setstate__ is now deprecated due to pickling not being supported anymore.
     3twisted.internet._sslverify.KeyPair.__getstate__ is now deprecated due to pickling not being supported anymore.
     4twisted.internet._sslverify.KeyPair.__setstate__ is now deprecated due to pickling not being supported anymore.
  • twisted/internet/_sslverify.py

     
    1414from twisted.python import _reflectpy3 as reflect, util
    1515from twisted.internet.defer import Deferred
    1616from twisted.internet.error import VerifyError, CertificateError
     17from twisted.python.deprecate import deprecated, getDeprecationWarningString
     18from twisted.python.versions import Version
    1719
     20import warnings
     21
    1822def _sessionCounter(counter=itertools.count()):
    1923    """
    2024    Private - shared between all OpenSSLCertificateOptions, counts up to
     
    508512    def dump(self, format=crypto.FILETYPE_ASN1):
    509513        return crypto.dump_privatekey(format, self.original)
    510514
    511 
    512515    def __getstate__(self):
     516        """
     517        Deprecated due to pickling not being supported anymore. See ticket #6166 for more information.
     518        """
     519        msg = getDeprecationWarningString(
     520            self.__getstate__, Version("Twisted", 13, 1, 0)) + ": Pickling is no longer supported."
     521        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
    513522        return self.dump()
    514523
    515 
    516524    def __setstate__(self, state):
     525        """
     526        Deprecated due to pickling not being supported anymore. See ticket #6166 for more information.
     527        """
     528        msg = getDeprecationWarningString(
     529            self.__setstate__, Version("Twisted", 13, 1, 0)) + ": Pickling is no longer supported."
     530        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
    517531        self.__init__(crypto.load_privatekey(crypto.FILETYPE_ASN1, state))
    518532
    519533
     
    717731        self.enableSessions = enableSessions
    718732        self.fixBrokenPeers = fixBrokenPeers
    719733        self.enableSessionTickets = enableSessionTickets
    720 
    721 
     734 
    722735    def __getstate__(self):
     736        """
     737        Deprecated due to pickling not being supported anymore. See ticket #6166 for more information.
     738        """
     739        msg = getDeprecationWarningString(
     740            self.__getstate__, Version("Twisted", 13, 1, 0)) + ": Pickling is no longer supported."
     741        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
    723742        d = self.__dict__.copy()
    724743        try:
    725744            del d['_context']
     
    727746            pass
    728747        return d
    729748
    730 
    731749    def __setstate__(self, state):
     750        """
     751        Deprecated due to pickling not being supported anymore. See ticket #6166 for more information.
     752        """
     753        msg = getDeprecationWarningString(
     754            self.__setstate__, Version("Twisted", 13, 1, 0)) + ": Pickling is no longer supported."
     755        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
    732756        self.__dict__ = state
    733757
    734758