Ticket #5129: compat3k.execfile.3.diff
| File compat3k.execfile.3.diff, 6.5 KB (added by allenap, 17 months ago) |
|---|
-
setup.py
=== modified file 'setup.py'
20 20 """ 21 21 Get all extensions from core and all subprojects. 22 22 """ 23 from twisted.python.compat import execfile 24 23 25 extensions = [] 24 26 25 27 if not sys.platform.startswith('java'): -
twisted/lore/htmlbook.py
=== modified file 'twisted/lore/htmlbook.py'
1 1 # Copyright (c) Twisted Matrix Laboratories. 2 2 # See LICENSE for details. 3 3 4 from twisted.python.compat import execfile 5 4 6 5 7 def getNumber(filename): 6 8 return None … … 24 26 Index = self.Index 25 27 26 28 if filename: 27 execfile(filename )29 execfile(filename, globals()) 28 30 29 31 def getFiles(self): 30 32 return [c[0] for c in self.chapters] -
twisted/names/authority.py
=== modified file 'twisted/names/authority.py'
12 12 from twisted.names import dns 13 13 from twisted.internet import defer 14 14 from twisted.python import failure 15 from twisted.python.compat import execfile 15 16 16 17 import common 17 18 -
twisted/python/_release.py
=== modified file 'twisted/python/_release.py'
25 25 from twisted.python.versions import Version 26 26 from twisted.python.filepath import FilePath 27 27 from twisted.python.dist import twisted_subprojects 28 from twisted.python.compat import execfile 28 29 29 30 # This import is an example of why you shouldn't use this module unless you're 30 31 # radix -
twisted/python/compat.py
=== modified file 'twisted/python/compat.py'
139 139 'set_connect_state', 'set_accept_state', 140 140 'connect_ex', 'sendall'): 141 141 142 exec """def %s(self, *args):142 exec("""def %s(self, *args): 143 143 self._lock.acquire() 144 144 try: 145 145 return apply(self._ssl_conn.%s, args) 146 146 finally: 147 self._lock.release()\n""" % (f, f) 147 self._lock.release()\n""" % (f, f)) 148 148 sys.modules['OpenSSL.tsafe'] = tsafe 149 149 150 150 import operator … … 175 175 from functools import reduce 176 176 except ImportError: 177 177 reduce = reduce 178 179 180 try: 181 _execfile = execfile 182 except NameError: 183 _execfile = None 184 185 186 def execfile(filename, globals, locals=None): 187 """Execute a Python script in the given namespaces. 188 189 Similar to the execfile builtin, but a namespace is mandatory, partly 190 because that's a sensible thing to require, and because otherwise we'd 191 have to do some frame hacking. 192 193 This is a compatibility wrapper for Python 3 porting. 194 """ 195 if locals is None: 196 locals = globals 197 if _execfile is None: 198 fin = open(filename, "rb") 199 try: 200 source = fin.read() 201 finally: 202 fin.close() 203 code = compile(source, filename, "exec") 204 exec(code, globals, locals) 205 else: 206 _execfile(filename, globals, locals) 207 208 209 __all__ = [ 210 "execfile", 211 "frozenset", 212 "reduce", 213 "set", 214 ] -
twisted/python/dist.py
=== modified file 'twisted/python/dist.py'
15 15 import platform 16 16 import sys 17 17 18 from twisted.python.compat import execfile 19 18 20 19 21 twisted_subprojects = ["conch", "lore", "mail", "names", 20 22 "news", "pair", "runner", "web", -
twisted/python/test/test_release.py
=== modified file 'twisted/python/test/test_release.py'
20 20 21 21 from twisted.trial.unittest import TestCase 22 22 23 from twisted.python.compat import set23 from twisted.python.compat import execfile, set 24 24 from twisted.python.procutils import which 25 25 from twisted.python import release 26 26 from twisted.python.filepath import FilePath -
twisted/test/test_compat.py
=== modified file 'twisted/test/test_compat.py'
6 6 Tests for L{twisted.python.compat}. 7 7 """ 8 8 9 import types, socket9 import os, tempfile, types, socket 10 10 11 11 from twisted.trial import unittest 12 12 13 from twisted.python.compat import set, frozenset, reduce 13 from twisted.python.compat import set, frozenset, reduce, execfile 14 14 15 15 16 16 … … 197 197 """ 198 198 self.assertEqual(15, reduce(lambda x, y: x + y, [1, 2, 3, 4, 5])) 199 199 self.assertEqual(16, reduce(lambda x, y: x + y, [1, 2, 3, 4, 5], 1)) 200 201 202 class ExecfileCompatTestCase(unittest.TestCase): 203 """Tests for the L{execfile} compatibility wrapper.""" 204 205 def setUp(self): 206 super(ExecfileCompatTestCase, self).setUp() 207 fd, self.script = tempfile.mkstemp(".py") 208 fout = os.fdopen(fd, "wb") 209 try: 210 fout.write("foo += 1\n".encode("ascii")) 211 finally: 212 fout.close() 213 214 def tearDown(self): 215 super(ExecfileCompatTestCase, self).tearDown() 216 os.unlink(self.script) 217 218 def test_execfileGlobals(self): 219 """ 220 L{execfile} executes the specified file in the given global namespace. 221 """ 222 ns_global = {"foo": 1} 223 execfile(self.script, ns_global) 224 self.assertEqual(2, ns_global["foo"]) 225 226 def test_execfileGlobalsAndLocals(self): 227 """ 228 L{execfile} executes the specified file in the given global and local 229 namespaces. 230 """ 231 ns_global, ns_local = {"foo": 10}, {"foo": 20} 232 execfile(self.script, ns_global, ns_local) 233 self.assertEqual(10, ns_global["foo"]) 234 self.assertEqual(21, ns_local["foo"]) -
twisted/topfiles/5129.misc
=== added file 'twisted/topfiles/5129.misc'
1 Replace usage of execfile() with t.p.compat.execfile(), a new function 2 that wraps execfile() on Python 2.x and provides equivalent 3 functionality on Python 3.x. -
twisted/web/script.py
=== modified file 'twisted/web/script.py'
14 14 import StringIO 15 15 16 16 from twisted import copyright 17 from twisted.python.compat import execfile 17 18 from twisted.web import http, server, static, resource, html 18 19 19 20
