=== modified file 'setup.py'
--- setup.py	2011-07-04 23:21:42 +0000
+++ setup.py	2011-12-08 11:57:10 +0000
@@ -10,6 +10,7 @@
 try:
     # Load setuptools, to build a specific source package
     import setuptools
+    setuptools  # Silence lint.
 except ImportError:
     pass
 
@@ -20,6 +21,8 @@
     """
     Get all extensions from core and all subprojects.
     """
+    from twisted.python.compat3k import execfile
+
     extensions = []
 
     if not sys.platform.startswith('java'):

=== modified file 'twisted/names/authority.py'
--- twisted/names/authority.py	2011-02-14 04:45:15 +0000
+++ twisted/names/authority.py	2011-12-07 21:50:29 +0000
@@ -12,6 +12,7 @@
 from twisted.names import dns
 from twisted.internet import defer
 from twisted.python import failure
+from twisted.python.compat3k import execfile
 
 import common
 

=== modified file 'twisted/python/_release.py'
--- twisted/python/_release.py	2011-11-20 15:23:17 +0000
+++ twisted/python/_release.py	2011-12-08 11:50:21 +0000
@@ -25,6 +25,7 @@
 from twisted.python.versions import Version
 from twisted.python.filepath import FilePath
 from twisted.python.dist import twisted_subprojects
+from twisted.python.compat3k import execfile
 
 # This import is an example of why you shouldn't use this module unless you're
 # radix
@@ -945,7 +946,6 @@
 
     This knows how to build tarballs for Twisted and all of its subprojects.
     """
-    from twisted.python.dist import twisted_subprojects as subprojects
 
     def __init__(self, rootDirectory, outputDirectory, apiBaseURL=None):
         """

=== modified file 'twisted/python/compat.py'
--- twisted/python/compat.py	2011-06-03 21:55:35 +0000
+++ twisted/python/compat.py	2011-12-08 11:52:24 +0000
@@ -68,6 +68,7 @@
             raise ValueError("address length incorrect")
         parts = struct.unpack('!8H', addr)
         curBase = bestBase = None
+        bestLen = 0
         for i in range(8):
             if not parts[i]:
                 if curBase is None:
@@ -139,12 +140,12 @@
                   'set_connect_state', 'set_accept_state',
                   'connect_ex', 'sendall'):
 
-            exec """def %s(self, *args):
+            exec("""def %s(self, *args):
                 self._lock.acquire()
                 try:
                     return apply(self._ssl_conn.%s, args)
                 finally:
-                    self._lock.release()\n""" % (f, f)
+                    self._lock.release()\n""" % (f, f))
 sys.modules['OpenSSL.tsafe'] = tsafe
 
 import operator
@@ -175,3 +176,10 @@
     from functools import reduce
 except ImportError:
     reduce = reduce
+
+
+__all__ = [
+    "frozenset",
+    "reduce",
+    "set",
+    ]

=== added file 'twisted/python/compat3k.py'
--- twisted/python/compat3k.py	1970-01-01 00:00:00 +0000
+++ twisted/python/compat3k.py	2011-12-03 22:07:06 +0000
@@ -0,0 +1,46 @@
+# -*- test-case-name: twisted.python.test.test_compat3k -*-
+#
+# Copyright (c) Twisted Matrix Laboratories.
+# See LICENSE for details.
+
+
+"""
+Python 3.x compatibility module to provide backwards compatibility for useful
+Python 2.x features, chiefly to aid porting.
+
+This is mainly for use of internal Twisted code. We encourage you to use
+the latest version of Python directly from your code, if possible.
+"""
+
+try:
+    _execfile = execfile
+except NameError:
+    _execfile = None
+
+
+def execfile(filename, globals, locals=None):
+    """Execute a Python script in the given namespaces.
+
+    Similar to the execfile builtin, but a namespace is mandatory, partly
+    because that's a sensible thing to require, and because otherwise we'd
+    have to do some frame hacking.
+
+    This is a compatibility wrapper for Python 3 porting.
+    """
+    if locals is None:
+        locals = globals
+    if _execfile is None:
+        fin = open(filename, "rb")
+        try:
+            source = fin.read()
+        finally:
+            fin.close()
+        code = compile(source, filename, "exec")
+        exec(code, globals, locals)
+    else:
+        _execfile(filename, globals, locals)
+
+
+__all__ = [
+    "execfile",
+    ]

=== modified file 'twisted/python/dist.py'
--- twisted/python/dist.py	2011-11-20 15:19:42 +0000
+++ twisted/python/dist.py	2011-12-07 21:39:45 +0000
@@ -15,6 +15,8 @@
 import platform
 import sys
 
+from twisted.python.compat3k import execfile
+
 
 twisted_subprojects = ["conch", "lore", "mail", "names",
                        "news", "pair", "runner", "web",

=== added file 'twisted/python/test/test_compat3k.py'
--- twisted/python/test/test_compat3k.py	1970-01-01 00:00:00 +0000
+++ twisted/python/test/test_compat3k.py	2011-12-03 22:08:23 +0000
@@ -0,0 +1,38 @@
+# Copyright (c) Twisted Matrix Laboratories.
+# See LICENSE for details.
+
+
+"""
+Tests for L{twisted.python.py3compat}.
+"""
+
+import os, tempfile, unittest
+
+from twisted.python.compat3k import execfile
+
+
+class ExecfileCompatTestCase(unittest.TestCase):
+
+    def setUp(self):
+        super(ExecfileCompatTestCase, self).setUp()
+        fd, self.script = tempfile.mkstemp(".py")
+        fout = os.fdopen(fd, "wb")
+        try:
+            fout.write("foo += 1\n".encode("ascii"))
+        finally:
+            fout.close()
+
+    def tearDown(self):
+        super(ExecfileCompatTestCase, self).tearDown()
+        os.unlink(self.script)
+
+    def test_execfile_globals(self):
+        ns_global = {"foo": 1}
+        execfile(self.script, ns_global)
+        self.assertEqual(2, ns_global["foo"])
+
+    def test_execfile_globals_and_locals(self):
+        ns_global, ns_local = {"foo": 10}, {"foo": 20}
+        execfile(self.script, ns_global, ns_local)
+        self.assertEqual(10, ns_global["foo"])
+        self.assertEqual(21, ns_local["foo"])

=== modified file 'twisted/python/test/test_release.py'
--- twisted/python/test/test_release.py	2011-07-14 18:05:14 +0000
+++ twisted/python/test/test_release.py	2011-12-08 11:57:42 +0000
@@ -21,6 +21,7 @@
 from twisted.trial.unittest import TestCase
 
 from twisted.python.compat import set
+from twisted.python.compat3k import execfile
 from twisted.python.procutils import which
 from twisted.python import release
 from twisted.python.filepath import FilePath
@@ -50,6 +51,7 @@
 # Check a bunch of dependencies to skip tests if necessary.
 try:
     from twisted.lore.scripts import lore
+    lore  # Silence lint.
 except ImportError:
     loreSkip = "Lore is not present."
 else:

=== added file 'twisted/topfiles/5129.misc'
--- twisted/topfiles/5129.misc	1970-01-01 00:00:00 +0000
+++ twisted/topfiles/5129.misc	2011-12-08 11:41:40 +0000
@@ -0,0 +1,3 @@
+Replace usage of execfile() with t.p.compat3k.execfile(), a new
+function that wraps execfile() on Python 2.x and provides equivalent
+functionality on Python 3.x.

=== modified file 'twisted/web/script.py'
--- twisted/web/script.py	2011-02-14 04:45:15 +0000
+++ twisted/web/script.py	2011-12-08 11:59:49 +0000
@@ -9,11 +9,13 @@
 import os, traceback
 
 try:
-    import cStringIO as StringIO
+    import cStringIO
+    StringIO = cStringIO  # Silence lint.
 except ImportError:
     import StringIO
 
 from twisted import copyright
+from twisted.python.compat3k import execfile
 from twisted.web import http, server, static, resource, html
 
 

