Ticket #5387: ticket-5387.diff

File ticket-5387.diff, 8.8 KB (added by bartekci, 3 years ago)

Initial work for review. Partially done deprecation

  • twisted/test/test_defgen.py

     
    175175 
    176176 
    177177 
    178 ## This has to be in a string so the new yield syntax doesn't cause a 
    179 ## syntax error in Python 2.4 and before. 
    180 inlineCallbacksTestsSource = ''' 
    181178from twisted.internet.defer import inlineCallbacks, returnValue 
    182179 
    183180class InlineCallbacksTests(BaseDefgenTests, unittest.TestCase): 
     
    295292 
    296293        self.assertIn("inlineCallbacks", 
    297294            str(self.assertRaises(TypeError, _noYield))) 
    298  
    299 ''' 
    300  
    301 if sys.version_info > (2, 5): 
    302     # Load tests 
    303     exec inlineCallbacksTestsSource 
    304 else: 
    305     # Make a placeholder test case 
    306     class InlineCallbacksTests(unittest.TestCase): 
    307         skip = "defer.defgen doesn't run on python < 2.5." 
    308         def test_everything(self): 
    309             pass 
  • twisted/python/util.py

     
    790790    Return the id of an object as an unsigned number so that its hex 
    791791    representation makes sense. 
    792792 
    793     This is mostly necessary in Python 2.4 which implements L{id} to sometimes 
    794     return a negative value.  Python 2.3 shares this behavior, but also 
     793    This is mostly necessary in Python 2.4 which implements L{id} to sometimes  
     794    return a negative value.  Python 2.3 shares this behavior, but also  
    795795    implements hex and the %x format specifier to represent negative values as 
    796     though they were positive ones, obscuring the behavior of L{id}.  Python 
     796    though they were positive ones, obscuring the behavior of L{id}.  Python  
    797797    2.5's implementation of L{id} always returns positive values. 
    798798    """ 
    799799    rval = _idFunction(obj) 
  • twisted/trial/test/mockdoctest.py

     
    22# See LICENSE for details. 
    33 
    44# this module is a trivial class with doctests and a __test__ attribute 
    5 # to test trial's doctest support with python2.4 
     5# to test trial's doctest support. 
    66 
    77 
    88class Counter(object): 
  • twisted/trial/runner.py

     
    1111__all__ = [ 
    1212    'suiteVisit', 'TestSuite', 
    1313 
    14     'DestructiveTestSuite', 'DocTestCase', 'DryRunVisitor', 
     14    'DestructiveTestSuite', 'DryRunVisitor', 
    1515    'ErrorHolder', 'LoggedSuite', 'PyUnitTestCase', 
    1616    'TestHolder', 'TestLoader', 'TrialRunner', 'TrialSuite', 
    1717 
     
    239239 
    240240 
    241241 
    242 class DocTestCase(PyUnitTestCase): 
    243     """ 
    244     DEPRECATED in Twisted 8.0. 
    245     """ 
    246  
    247     def id(self): 
    248         """ 
    249         In Python 2.4, doctests have correct id() behaviour. In Python 2.3, 
    250         id() returns 'runit'. 
    251  
    252         Here we override id() so that at least it will always contain the 
    253         fully qualified Python name of the doctest. 
    254         """ 
    255         return self._test.shortDescription() 
    256  
    257  
    258242class TrialSuite(TestSuite): 
    259243    """ 
    260244    Suite to wrap around every single test in a C{trial} run. Used internally 
  • twisted/trial/util.py

     
    208208 
    209209def profiled(f, outputFile): 
    210210    def _(*args, **kwargs): 
    211         if sys.version_info[0:2] != (2, 4): 
    212             import profile 
    213             prof = profile.Profile() 
    214             try: 
    215                 result = prof.runcall(f, *args, **kwargs) 
    216                 prof.dump_stats(outputFile) 
    217             except SystemExit: 
    218                 pass 
    219             prof.print_stats() 
    220             return result 
    221         else: # use hotshot, profile is broken in 2.4 
    222             import hotshot.stats 
    223             prof = hotshot.Profile(outputFile) 
    224             try: 
    225                 return prof.runcall(f, *args, **kwargs) 
    226             finally: 
    227                 stats = hotshot.stats.load(outputFile) 
    228                 stats.strip_dirs() 
    229                 stats.sort_stats('cum')   # 'time' 
    230                 stats.print_stats(100) 
     211        import profile 
     212        prof = profile.Profile() 
     213        try: 
     214            result = prof.runcall(f, *args, **kwargs) 
     215            prof.dump_stats(outputFile) 
     216        except SystemExit: 
     217            pass 
     218        prof.print_stats() 
     219        return result 
    231220    return _ 
    232221 
    233222 
  • twisted/trial/unittest.py

     
    13921392class TestSuite(pyunit.TestSuite): 
    13931393    """ 
    13941394    Extend the standard library's C{TestSuite} with support for the visitor 
    1395     pattern and a consistently overrideable C{run} method. 
     1395    pattern. 
    13961396    """ 
    13971397 
    13981398    visit = suiteVisit 
    13991399 
    1400     def __call__(self, result): 
    1401         return self.run(result) 
    1402  
    1403  
    1404     def run(self, result): 
    1405         """ 
    1406         Call C{run} on every member of the suite. 
    1407         """ 
    1408         # we implement this because Python 2.3 unittest defines this code 
    1409         # in __call__, whereas 2.4 defines the code in run. 
    1410         for test in self._tests: 
    1411             if result.shouldStop: 
    1412                 break 
    1413             test(result) 
    1414         return result 
    1415  
    1416  
    14171400 
    14181401class TestDecorator(components.proxyForInterface(itrial.ITestCase, 
    14191402                                                 "_originalTest")): 
  • twisted/web/test/test_xmlrpc.py

     
    575575    value = None 
    576576 
    577577 
    578 try: 
    579     xmlrpclib.loads(xmlrpclib.dumps(({}, {})), use_datetime=True) 
    580 except TypeError: 
    581     _datetimeSupported = False 
    582 else: 
    583     _datetimeSupported = True 
    584  
    585  
    586  
    587578class XMLRPCUseDateTimeTestCase(SerializationConfigMixin, unittest.TestCase): 
    588579    """ 
    589580    Tests for passing a C{datetime.datetime} instance when the C{useDateTime} 
     
    592583    flagName = "useDateTime" 
    593584    value = datetime.datetime(2000, 12, 28, 3, 45, 59) 
    594585 
    595     if not _datetimeSupported: 
    596         skip = ( 
    597             "Available version of xmlrpclib does not support datetime " 
    598             "objects.") 
    599  
    600  
    601  
    602 class XMLRPCDisableUseDateTimeTestCase(unittest.TestCase): 
    603     """ 
    604     Tests for the C{useDateTime} flag on Python 2.4. 
    605     """ 
    606     if _datetimeSupported: 
    607         skip = ( 
    608             "Available version of xmlrpclib supports datetime objects.") 
    609  
    610     def test_cannotInitializeWithDateTime(self): 
    611         """ 
    612         L{XMLRPC} raises L{RuntimeError} if passed C{True} for C{useDateTime}. 
    613         """ 
    614         self.assertRaises(RuntimeError, XMLRPC, useDateTime=True) 
    615         self.assertRaises( 
    616             RuntimeError, Proxy, "http://localhost/", useDateTime=True) 
    617  
    618  
    619     def test_cannotSetDateTime(self): 
    620         """ 
    621         Setting L{XMLRPC.useDateTime} to C{True} after initialization raises 
    622         L{RuntimeError}. 
    623         """ 
    624         xmlrpc = XMLRPC(useDateTime=False) 
    625         self.assertRaises(RuntimeError, setattr, xmlrpc, "useDateTime", True) 
    626         proxy = Proxy("http://localhost/", useDateTime=False) 
    627         self.assertRaises(RuntimeError, setattr, proxy, "useDateTime", True) 
    628  
    629  
    630586 
    631587class XMLRPCTestAuthenticated(XMLRPCTestCase): 
    632588    """ 
  • twisted/web/xmlrpc.py

     
    2828Boolean = xmlrpclib.Boolean 
    2929DateTime = xmlrpclib.DateTime 
    3030 
    31 # On Python 2.4 and earlier, DateTime.decode returns unicode. 
    32 if sys.version_info[:2] < (2, 5): 
    33     _decode = DateTime.decode 
    34     DateTime.decode = lambda self, value: _decode(self, value.encode('ascii')) 
    35  
    3631 
    3732def withRequest(f): 
    3833    """ 
     
    128123 
    129124 
    130125    def __setattr__(self, name, value): 
    131         if name == "useDateTime" and value and sys.version_info[:2] < (2, 5): 
    132             raise RuntimeError("useDateTime requires Python 2.5 or later.") 
    133126        self.__dict__[name] = value 
    134127 
    135128 
  • twisted/web/client.py

     
    720720    """ 
    721721    implements(IBodyProducer) 
    722722 
    723     # Python 2.4 doesn't have these symbolic constants 
    724     _SEEK_SET = getattr(os, 'SEEK_SET', 0) 
    725     _SEEK_END = getattr(os, 'SEEK_END', 2) 
     723    _SEEK_SET = os.SEEK_SET 
     724    _SEEK_END = os.SEEK_END 
    726725 
    727726    def __init__(self, inputFile, cooperator=task, readSize=2 ** 16): 
    728727        self._inputFile = inputFile