Ticket #5387: 5387.patch
| File 5387.patch, 13.0 KB (added by bartekci, 15 months ago) |
|---|
-
test/test_defgen.py
175 175 176 176 177 177 178 ## This has to be in a string so the new yield syntax doesn't cause a179 ## syntax error in Python 2.4 and before.180 inlineCallbacksTestsSource = '''181 178 from twisted.internet.defer import inlineCallbacks, returnValue 182 179 183 180 class InlineCallbacksTests(BaseDefgenTests, unittest.TestCase): … … 295 292 296 293 self.assertIn("inlineCallbacks", 297 294 str(self.assertRaises(TypeError, _noYield))) 298 299 '''300 301 if sys.version_info > (2, 5):302 # Load tests303 exec inlineCallbacksTestsSource304 else:305 # Make a placeholder test case306 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
53 53 return False 54 54 55 55 56 def _stub_urandom(n):57 """58 Provide random data in versions of Python prior to 2.4. This is an59 effectively compatible replacement for 'os.urandom'.60 61 @type n: L{int}62 @param n: the number of bytes of data to return63 @return: C{n} bytes of random data.64 @rtype: str65 """66 randomData = [random.randrange(256) for n in xrange(n)]67 return ''.join(map(chr, randomData))68 69 70 56 def _stub_armor(s): 71 57 """ 72 58 ASCII-armor for random data. This uses a hex encoding, although we will … … 76 62 return s.encode('hex') 77 63 78 64 islink = getattr(os.path, 'islink', _stub_islink) 79 randomBytes = getattr(os, 'urandom', _stub_urandom)65 randomBytes = os.urandom # Retained for historic usage. 80 66 armor = getattr(base64, 'urlsafe_b64encode', _stub_armor) 81 67 82 68 class InsecurePath(Exception): … … 132 118 """ 133 119 Create a pseudorandom, 16-character string for use in secure filenames. 134 120 """ 135 return armor(sha1( randomBytes(64)).digest())[:16]121 return armor(sha1(os.urandom(64)).digest())[:16] 136 122 137 123 138 124 -
python/util.py
790 790 Return the id of an object as an unsigned number so that its hex 791 791 representation makes sense. 792 792 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 795 795 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 797 797 2.5's implementation of L{id} always returns positive values. 798 798 """ 799 799 rval = _idFunction(obj) -
python/dist.py
360 360 361 361 On recent versions of Python, will use C{platform.python_implementation}. 362 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), checks363 older versions, checks 364 364 if C{__pypy__} is in C{sys.modules}, since PyPy is the implementation we 365 365 really care about. If it isn't, assumes CPython. 366 366 -
topfiles/5387.doc
1 twisted.internet.defer.inlineCallbacks, removed Python 2.4 warnings and examples, as no longer supported. 2 twisted.python.dist._checkCPython, removed Python 2.4 as only supported older version. 3 twisted.trial.test.mockdoctest, Removed Python 2.4 reference. -
topfiles/5387.removal
1 twisted.python.filepath.randomByres, no longer falls back to _stub_urandom. Uses os.urandom at all times 2 twisted.test.test_defgen, removed hack for preventing yield syntax from breaking test runner. 3 twisted.trial.runner.DocTestCase, removed as deprecated since Tornadio 8.0 4 twisted.trial.unittest.TestSuite, removed over-rides to __call__ and run. No longer needed due to Python 2.4 support drop. 5 twisted.trial.util.profiled, removed Python 2.4 hotshot hack. No longer required. -
internet/defer.py
1124 1124 1125 1125 def inlineCallbacks(f): 1126 1126 """ 1127 WARNING: this function will not work in Python 2.4 and earlier!1128 1129 1127 inlineCallbacks helps you write Deferred-using code that looks like a 1130 1128 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 1129 generators. 1130 1140 1131 When you call anything that results in a L{Deferred}, you can simply yield it; 1141 1132 your generator will automatically be resumed when the Deferred's result is 1142 1133 available. The generator will be sent the result of the L{Deferred} with the -
trial/test/mockdoctest.py
2 2 # See LICENSE for details. 3 3 4 4 # this module is a trivial class with doctests and a __test__ attribute 5 # to test trial's doctest support with python2.45 # to test trial's doctest support. 6 6 7 7 8 8 class Counter(object): -
trial/runner.py
11 11 __all__ = [ 12 12 'suiteVisit', 'TestSuite', 13 13 14 'DestructiveTestSuite', 'D ocTestCase', 'DryRunVisitor',14 'DestructiveTestSuite', 'DryRunVisitor', 15 15 'ErrorHolder', 'LoggedSuite', 'PyUnitTestCase', 16 16 'TestHolder', 'TestLoader', 'TrialRunner', 'TrialSuite', 17 17 … … 239 239 240 240 241 241 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 the253 fully qualified Python name of the doctest.254 """255 return self._test.shortDescription()256 257 258 242 class TrialSuite(TestSuite): 259 243 """ 260 244 Suite to wrap around every single test in a C{trial} run. Used internally -
trial/util.py
208 208 209 209 def profiled(f, outputFile): 210 210 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 231 220 return _ 232 221 233 222 -
trial/unittest.py
1392 1392 class TestSuite(pyunit.TestSuite): 1393 1393 """ 1394 1394 Extend the standard library's C{TestSuite} with support for the visitor 1395 pattern and a consistently overrideable C{run} method.1395 pattern. 1396 1396 """ 1397 1397 1398 1398 visit = suiteVisit 1399 1399 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 code1409 # in __call__, whereas 2.4 defines the code in run.1410 for test in self._tests:1411 if result.shouldStop:1412 break1413 test(result)1414 return result1415 1416 1417 1400 1418 1401 class TestDecorator(components.proxyForInterface(itrial.ITestCase, 1419 1402 "_originalTest")): -
web/test/test_xmlrpc.py
575 575 value = None 576 576 577 577 578 try:579 xmlrpclib.loads(xmlrpclib.dumps(({}, {})), use_datetime=True)580 except TypeError:581 _datetimeSupported = False582 else:583 _datetimeSupported = True584 585 586 587 578 class XMLRPCUseDateTimeTestCase(SerializationConfigMixin, unittest.TestCase): 588 579 """ 589 580 Tests for passing a C{datetime.datetime} instance when the C{useDateTime} … … 592 583 flagName = "useDateTime" 593 584 value = datetime.datetime(2000, 12, 28, 3, 45, 59) 594 585 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 raises622 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 630 586 631 587 class XMLRPCTestAuthenticated(XMLRPCTestCase): 632 588 """ -
web/topfiles/5387.removal
1 twisted.web.client.FileBodyProducer, removed hard-code default for _SEEK_SET, _SEEK_END. Both available in os in >= 2.5 2 twisted.web.xmlrpclib, removed Datetime.decode hack for Python versions < 2.5 3 twisted.web.test.text_xmlrpc.XMLRPCDisableUseDateTimeTestCase, removed test specific to Python 2.4 support -
web/xmlrpc.py
28 28 Boolean = xmlrpclib.Boolean 29 29 DateTime = xmlrpclib.DateTime 30 30 31 # On Python 2.4 and earlier, DateTime.decode returns unicode.32 if sys.version_info[:2] < (2, 5):33 _decode = DateTime.decode34 DateTime.decode = lambda self, value: _decode(self, value.encode('ascii'))35 36 31 37 32 def withRequest(f): 38 33 """ … … 128 123 129 124 130 125 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.")133 126 self.__dict__[name] = value 134 127 135 128 -
web/client.py
720 720 """ 721 721 implements(IBodyProducer) 722 722 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 726 725 727 726 def __init__(self, inputFile, cooperator=task, readSize=2 ** 16): 728 727 self._inputFile = inputFile
