Ticket #5129: compat3k.execfile.diff
| File compat3k.execfile.diff, 5.7 KB (added by allenap, 19 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.compat3k import execfile 24 23 25 extensions = [] 24 26 25 27 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 -
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 __all__ = [ 181 "frozenset", 182 "reduce", 183 "set", 184 ] -
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 -
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.compat3k import execfile 17 18 from twisted.web import http, server, static, resource, html 18 19 19 20
