Ticket #5387: 5387.2.patch

File 5387.2.patch, 12.5 KB (added by bartekci, 4 years ago)

Updated patch with newsfile typo fixes and additional doc changes as requested.

  • 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
  • python/filepath.py

     
    5353    return False
    5454
    5555
    56 def _stub_urandom(n):
    57     """
    58     Provide random data in versions of Python prior to 2.4.  This is an
    59     effectively compatible replacement for 'os.urandom'.
    60 
    61     @type n: L{int}
    62     @param n: the number of bytes of data to return
    63     @return: C{n} bytes of random data.
    64     @rtype: str
    65     """
    66     randomData = [random.randrange(256) for n in xrange(n)]
    67     return ''.join(map(chr, randomData))
    68 
    69 
    7056def _stub_armor(s):
    7157    """
    7258    ASCII-armor for random data.  This uses a hex encoding, although we will
     
    7662    return s.encode('hex')
    7763
    7864islink = getattr(os.path, 'islink', _stub_islink)
    79 randomBytes = getattr(os, 'urandom', _stub_urandom)
     65randomBytes = os.urandom # Retained for historic usage.
    8066armor = getattr(base64, 'urlsafe_b64encode', _stub_armor)
    8167
    8268class InsecurePath(Exception):
     
    132118    """
    133119    Create a pseudorandom, 16-character string for use in secure filenames.
    134120    """
    135     return armor(sha1(randomBytes(64)).digest())[:16]
     121    return armor(sha1(os.urandom(64)).digest())[:16]
    136122
    137123
    138124
  • python/dist.py

     
    359359    Checks if this implementation is CPython.
    360360
    361361    On recent versions of Python, will use C{platform.python_implementation}.
    362     On 2.5, it will try to extract the implementation from sys.subversion. On
    363     older versions (currently the only supported older version is 2.4), checks
    364     if C{__pypy__} is in C{sys.modules}, since PyPy is the implementation we
    365     really care about. If it isn't, assumes CPython.
     362    On 2.5, it will try to extract the implementation from sys.subversion.
    366363
    367364    This takes C{sys} and C{platform} kwargs that by default use the real
    368365    modules. You shouldn't care about these -- they are for testing purposes
  • topfiles/5387.doc

     
     1twisted.internet.defer.inlineCallbacks, removed Python 2.4 warnings and examples, as no longer supported.
     2twisted.python.dist._checkCPython, removed Python 2.4 as only supported older version.
     3twisted.trial.test.mockdoctest, Removed Python 2.4 reference.
  • topfiles/5387.removal

     
     1twisted.python.filepath.randomBytes, no longer falls back to _stub_urandom. Uses os.urandom at all times
     2twisted.test.test_defgen, removed hack for preventing yield syntax from breaking test runner.
     3twisted.trial.runner.DocTestCase, removed as deprecated since Twisted 8.0
     4twisted.trial.unittest.TestSuite, removed over-rides to __call__ and run. No longer needed due to Python 2.4 support drop.
     5twisted.trial.util.profiled, removed Python 2.4 hotshot hack. No longer required.
  • internet/defer.py

     
    11241124
    11251125def inlineCallbacks(f):
    11261126    """
    1127     WARNING: this function will not work in Python 2.4 and earlier!
    1128 
    11291127    inlineCallbacks helps you write Deferred-using code that looks like a
    1130     regular sequential function. This function uses features of Python 2.5
    1131     generators.  If you need to be compatible with Python 2.4 or before, use
    1132     the L{deferredGenerator} function instead, which accomplishes the same
    1133     thing, but with somewhat more boilerplate.  For example::
    1134 
    1135         @inlineCallBacks
    1136         def thingummy():
    1137             thing = yield makeSomeRequestResultingInDeferred()
    1138             print thing #the result! hoorj!
    1139 
     1128    regular sequential function.
     1129   
    11401130    When you call anything that results in a L{Deferred}, you can simply yield it;
    11411131    your generator will automatically be resumed when the Deferred's result is
    11421132    available. The generator will be sent the result of the L{Deferred} with the
  • trial/test/mockdoctest.py

     
    11# Copyright (c) Twisted Matrix Laboratories.
    22# See LICENSE for details.
    33
    4 # this module is a trivial class with doctests and a __test__ attribute
    5 # to test trial's doctest support with python2.4
     4# This module is a trivial class with doctests to test trial's doctest support.
    65
    76
    87class Counter(object):
  • 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
  • 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
  • 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")):
  • 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    """
  • web/topfiles/5387.removal

     
     1twisted.web.client.FileBodyProducer, removed hard-code default for _SEEK_SET, _SEEK_END. Both available in os in >= 2.5
     2twisted.web.xmlrpclib, removed Datetime.decode hack for Python versions < 2.5
     3twisted.web.test.text_xmlrpc.XMLRPCDisableUseDateTimeTestCase, removed test specific to Python 2.4 support
  • 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
  • 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