Ticket #5129: compat3k.execfile.2.diff
| File compat3k.execfile.2.diff, 7.1 KB (added by allenap, 18 months ago) |
|---|
-
setup.py
=== modified file 'setup.py'
10 10 try: 11 11 # Load setuptools, to build a specific source package 12 12 import setuptools 13 setuptools # Silence lint. 13 14 except ImportError: 14 15 pass 15 16 … … 20 21 """ 21 22 Get all extensions from core and all subprojects. 22 23 """ 24 from twisted.python.compat3k import execfile 25 23 26 extensions = [] 24 27 25 28 if not sys.platform.startswith('java'): -
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.compat3k 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.compat3k 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 … … 945 946 946 947 This knows how to build tarballs for Twisted and all of its subprojects. 947 948 """ 948 from twisted.python.dist import twisted_subprojects as subprojects949 949 950 950 def __init__(self, rootDirectory, outputDirectory, apiBaseURL=None): 951 951 """ -
twisted/python/compat.py
=== modified file 'twisted/python/compat.py'
68 68 raise ValueError("address length incorrect") 69 69 parts = struct.unpack('!8H', addr) 70 70 curBase = bestBase = None 71 bestLen = 0 71 72 for i in range(8): 72 73 if not parts[i]: 73 74 if curBase is None: … … 139 140 'set_connect_state', 'set_accept_state', 140 141 'connect_ex', 'sendall'): 141 142 142 exec """def %s(self, *args):143 exec("""def %s(self, *args): 143 144 self._lock.acquire() 144 145 try: 145 146 return apply(self._ssl_conn.%s, args) 146 147 finally: 147 self._lock.release()\n""" % (f, f) 148 self._lock.release()\n""" % (f, f)) 148 149 sys.modules['OpenSSL.tsafe'] = tsafe 149 150 150 151 import operator … … 175 176 from functools import reduce 176 177 except ImportError: 177 178 reduce = reduce 179 180 181 __all__ = [ 182 "frozenset", 183 "reduce", 184 "set", 185 ] -
twisted/python/compat3k.py
=== added file 'twisted/python/compat3k.py'
1 # -*- test-case-name: twisted.python.test.test_compat3k -*- 2 # 3 # Copyright (c) Twisted Matrix Laboratories. 4 # See LICENSE for details. 5 6 7 """ 8 Python 3.x compatibility module to provide backwards compatibility for useful 9 Python 2.x features, chiefly to aid porting. 10 11 This is mainly for use of internal Twisted code. We encourage you to use 12 the latest version of Python directly from your code, if possible. 13 """ 14 15 try: 16 _execfile = execfile 17 except NameError: 18 _execfile = None 19 20 21 def execfile(filename, globals, locals=None): 22 """Execute a Python script in the given namespaces. 23 24 Similar to the execfile builtin, but a namespace is mandatory, partly 25 because that's a sensible thing to require, and because otherwise we'd 26 have to do some frame hacking. 27 28 This is a compatibility wrapper for Python 3 porting. 29 """ 30 if locals is None: 31 locals = globals 32 if _execfile is None: 33 fin = open(filename, "rb") 34 try: 35 source = fin.read() 36 finally: 37 fin.close() 38 code = compile(source, filename, "exec") 39 exec(code, globals, locals) 40 else: 41 _execfile(filename, globals, locals) 42 43 44 __all__ = [ 45 "execfile", 46 ] -
twisted/python/dist.py
=== modified file 'twisted/python/dist.py'
15 15 import platform 16 16 import sys 17 17 18 from twisted.python.compat3k import execfile 19 18 20 19 21 twisted_subprojects = ["conch", "lore", "mail", "names", 20 22 "news", "pair", "runner", "web", -
twisted/python/test/test_compat3k.py
=== added file 'twisted/python/test/test_compat3k.py'
1 # Copyright (c) Twisted Matrix Laboratories. 2 # See LICENSE for details. 3 4 5 """ 6 Tests for L{twisted.python.py3compat}. 7 """ 8 9 import os, tempfile, unittest 10 11 from twisted.python.compat3k import execfile 12 13 14 class ExecfileCompatTestCase(unittest.TestCase): 15 16 def setUp(self): 17 super(ExecfileCompatTestCase, self).setUp() 18 fd, self.script = tempfile.mkstemp(".py") 19 fout = os.fdopen(fd, "wb") 20 try: 21 fout.write("foo += 1\n".encode("ascii")) 22 finally: 23 fout.close() 24 25 def tearDown(self): 26 super(ExecfileCompatTestCase, self).tearDown() 27 os.unlink(self.script) 28 29 def test_execfile_globals(self): 30 ns_global = {"foo": 1} 31 execfile(self.script, ns_global) 32 self.assertEqual(2, ns_global["foo"]) 33 34 def test_execfile_globals_and_locals(self): 35 ns_global, ns_local = {"foo": 10}, {"foo": 20} 36 execfile(self.script, ns_global, ns_local) 37 self.assertEqual(10, ns_global["foo"]) 38 self.assertEqual(21, ns_local["foo"]) -
twisted/python/test/test_release.py
=== modified file 'twisted/python/test/test_release.py'
21 21 from twisted.trial.unittest import TestCase 22 22 23 23 from twisted.python.compat import set 24 from twisted.python.compat3k import execfile 24 25 from twisted.python.procutils import which 25 26 from twisted.python import release 26 27 from twisted.python.filepath import FilePath … … 50 51 # Check a bunch of dependencies to skip tests if necessary. 51 52 try: 52 53 from twisted.lore.scripts import lore 54 lore # Silence lint. 53 55 except ImportError: 54 56 loreSkip = "Lore is not present." 55 57 else: -
twisted/topfiles/5129.misc
=== added file 'twisted/topfiles/5129.misc'
1 Replace usage of execfile() with t.p.compat3k.execfile(), a new 2 function 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'
9 9 import os, traceback 10 10 11 11 try: 12 import cStringIO as StringIO 12 import cStringIO 13 StringIO = cStringIO # Silence lint. 13 14 except ImportError: 14 15 import StringIO 15 16 16 17 from twisted import copyright 18 from twisted.python.compat3k import execfile 17 19 from twisted.web import http, server, static, resource, html 18 20 19 21
