[pypy-svn] r78776 - in pypy/branch/fast-forward/lib-python/2.7.0: . ctypes distutils distutils/tests email email/test json json/tests lib-tk lib-tk/test/test_ttk lib2to3 lib2to3/fixes lib2to3/tests lib2to3/tests/data logging multiprocessing test test/tracedmodules unittest unittest/test xml/dom xml/sax

afa at codespeak.net afa at codespeak.net
Fri Nov 5 23:51:09 CET 2010


Author: afa
Date: Fri Nov  5 23:50:59 2010
New Revision: 78776

Modified:
   pypy/branch/fast-forward/lib-python/2.7.0/CGIHTTPServer.py
   pypy/branch/fast-forward/lib-python/2.7.0/SimpleXMLRPCServer.py
   pypy/branch/fast-forward/lib-python/2.7.0/_pyio.py
   pypy/branch/fast-forward/lib-python/2.7.0/argparse.py
   pypy/branch/fast-forward/lib-python/2.7.0/asyncore.py
   pypy/branch/fast-forward/lib-python/2.7.0/base64.py
   pypy/branch/fast-forward/lib-python/2.7.0/calendar.py
   pypy/branch/fast-forward/lib-python/2.7.0/collections.py
   pypy/branch/fast-forward/lib-python/2.7.0/ctypes/util.py
   pypy/branch/fast-forward/lib-python/2.7.0/distutils/dir_util.py
   pypy/branch/fast-forward/lib-python/2.7.0/distutils/sysconfig.py
   pypy/branch/fast-forward/lib-python/2.7.0/distutils/tests/test_build_ext.py
   pypy/branch/fast-forward/lib-python/2.7.0/distutils/tests/test_dir_util.py
   pypy/branch/fast-forward/lib-python/2.7.0/doctest.py
   pypy/branch/fast-forward/lib-python/2.7.0/email/_parseaddr.py
   pypy/branch/fast-forward/lib-python/2.7.0/email/quoprimime.py
   pypy/branch/fast-forward/lib-python/2.7.0/email/test/test_email.py
   pypy/branch/fast-forward/lib-python/2.7.0/gettext.py
   pypy/branch/fast-forward/lib-python/2.7.0/gzip.py
   pypy/branch/fast-forward/lib-python/2.7.0/httplib.py
   pypy/branch/fast-forward/lib-python/2.7.0/json/__init__.py
   pypy/branch/fast-forward/lib-python/2.7.0/json/decoder.py
   pypy/branch/fast-forward/lib-python/2.7.0/json/tests/test_encode_basestring_ascii.py
   pypy/branch/fast-forward/lib-python/2.7.0/json/tests/test_unicode.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib-tk/test/test_ttk/test_widgets.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib-tk/turtle.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/Grammar.txt
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixer_base.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixer_util.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_apply.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_basestring.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_buffer.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_callable.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_dict.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_except.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_exec.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_execfile.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_exitfunc.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_filter.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_funcattrs.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_future.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_getcwdu.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_has_key.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_idioms.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_import.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_imports.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_input.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_intern.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_isinstance.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_itertools.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_itertools_imports.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_long.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_map.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_metaclass.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_methodattrs.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_next.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_nonzero.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_operator.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_paren.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_print.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_raise.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_raw_input.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_reduce.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_renames.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_repr.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_set_literal.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_standarderror.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_sys_exc.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_throw.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_tuple_params.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_types.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_unicode.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_urllib.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_xrange.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_xreadlines.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_zip.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/patcomp.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/pygram.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/pytree.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/refactor.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/data/bom.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/test_fixers.py
   pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/test_pytree.py
   pypy/branch/fast-forward/lib-python/2.7.0/logging/__init__.py
   pypy/branch/fast-forward/lib-python/2.7.0/logging/config.py
   pypy/branch/fast-forward/lib-python/2.7.0/mimetypes.py
   pypy/branch/fast-forward/lib-python/2.7.0/multiprocessing/__init__.py
   pypy/branch/fast-forward/lib-python/2.7.0/ntpath.py
   pypy/branch/fast-forward/lib-python/2.7.0/posixpath.py
   pypy/branch/fast-forward/lib-python/2.7.0/runpy.py
   pypy/branch/fast-forward/lib-python/2.7.0/site.py
   pypy/branch/fast-forward/lib-python/2.7.0/smtpd.py
   pypy/branch/fast-forward/lib-python/2.7.0/ssl.py
   pypy/branch/fast-forward/lib-python/2.7.0/sysconfig.py
   pypy/branch/fast-forward/lib-python/2.7.0/tarfile.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/regrtest.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_abc.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_argparse.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_bz2.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_class.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_collections.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_compiler.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_decimal.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_doctest.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_file2k.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_fileio.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_float.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_ftplib.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_gettext.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_gzip.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_httplib.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_httpservers.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_io.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_long.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_mailbox.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_module.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_modulefinder.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_multibytecodec.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_multibytecodec_support.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_multiprocessing.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_ntpath.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_old_mailbox.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_os.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_pipes.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_pkgimport.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_posixpath.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_quopri.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_sax.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_scope.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_shutil.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_signal.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_smtpnet.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_socket.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_ssl.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_subprocess.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_support.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_sys_setprofile.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_threading.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_timeout.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_tokenize.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_trace.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_unicode.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_urllib2net.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_uu.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_winreg.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_xml_etree.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/test_xpickle.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/tracedmodules/testmod.py
   pypy/branch/fast-forward/lib-python/2.7.0/test/win_console_handler.py
   pypy/branch/fast-forward/lib-python/2.7.0/trace.py
   pypy/branch/fast-forward/lib-python/2.7.0/unittest/result.py
   pypy/branch/fast-forward/lib-python/2.7.0/unittest/suite.py
   pypy/branch/fast-forward/lib-python/2.7.0/unittest/test/test_suite.py
   pypy/branch/fast-forward/lib-python/2.7.0/urllib.py
   pypy/branch/fast-forward/lib-python/2.7.0/urllib2.py
   pypy/branch/fast-forward/lib-python/2.7.0/uu.py
   pypy/branch/fast-forward/lib-python/2.7.0/uuid.py
   pypy/branch/fast-forward/lib-python/2.7.0/xml/dom/expatbuilder.py
   pypy/branch/fast-forward/lib-python/2.7.0/xml/sax/saxutils.py
Log:
New copy of the 2.7 std library,
with probably many fixes to cleanly close resources
without relying on the refcounting garbage collector.


Modified: pypy/branch/fast-forward/lib-python/2.7.0/CGIHTTPServer.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/CGIHTTPServer.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/CGIHTTPServer.py	Fri Nov  5 23:50:59 2010
@@ -29,6 +29,7 @@
 import BaseHTTPServer
 import SimpleHTTPServer
 import select
+import copy
 
 
 class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
@@ -154,7 +155,7 @@
 
         # Reference: http://hoohoo.ncsa.uiuc.edu/cgi/env.html
         # XXX Much of the following could be prepared ahead of time!
-        env = {}
+        env = copy.deepcopy(os.environ)
         env['SERVER_SOFTWARE'] = self.version_string()
         env['SERVER_NAME'] = self.server.server_name
         env['GATEWAY_INTERFACE'] = 'CGI/1.1'
@@ -216,7 +217,6 @@
         for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH',
                   'HTTP_USER_AGENT', 'HTTP_COOKIE', 'HTTP_REFERER'):
             env.setdefault(k, "")
-        os.environ.update(env)
 
         self.send_response(200, "Script output follows")
 
@@ -248,7 +248,7 @@
                     pass
                 os.dup2(self.rfile.fileno(), 0)
                 os.dup2(self.wfile.fileno(), 1)
-                os.execve(scriptfile, args, os.environ)
+                os.execve(scriptfile, args, env)
             except:
                 self.server.handle_error(self.request, self.client_address)
                 os._exit(127)
@@ -274,7 +274,8 @@
             p = subprocess.Popen(cmdline,
                                  stdin = subprocess.PIPE,
                                  stdout = subprocess.PIPE,
-                                 stderr = subprocess.PIPE
+                                 stderr = subprocess.PIPE,
+                                 env = env
                                 )
             if self.command.lower() == "post" and nbytes > 0:
                 data = self.rfile.read(nbytes)
@@ -288,6 +289,8 @@
             self.wfile.write(stdout)
             if stderr:
                 self.log_error('%s', stderr)
+            p.stderr.close()
+            p.stdout.close()
             status = p.returncode
             if status:
                 self.log_error("CGI script exit status %#x", status)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/SimpleXMLRPCServer.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/SimpleXMLRPCServer.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/SimpleXMLRPCServer.py	Fri Nov  5 23:50:59 2010
@@ -163,7 +163,7 @@
     This class is used to register XML-RPC method handlers
     and then to dispatch them. This class doesn't need to be
     instanced directly when used by SimpleXMLRPCServer but it
-    can be instanced when used by the MultiPathXMLRPCServer
+    can be instanced when used by the MultiPathXMLRPCServer.
     """
 
     def __init__(self, allow_none=False, encoding=None):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/_pyio.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/_pyio.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/_pyio.py	Fri Nov  5 23:50:59 2010
@@ -546,6 +546,8 @@
             return self.readall()
         b = bytearray(n.__index__())
         n = self.readinto(b)
+        if n is None:
+            return None
         del b[n:]
         return bytes(b)
 
@@ -563,7 +565,7 @@
         """Read up to len(b) bytes into b.
 
         Returns number of bytes read (0 for EOF), or None if the object
-        is set not to block as has no data to read.
+        is set not to block and has no data to read.
         """
         self._unsupported("readinto")
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/argparse.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/argparse.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/argparse.py	Fri Nov  5 23:50:59 2010
@@ -65,13 +65,20 @@
 __all__ = [
     'ArgumentParser',
     'ArgumentError',
-    'Namespace',
-    'Action',
+    'ArgumentTypeError',
     'FileType',
     'HelpFormatter',
+    'ArgumentDefaultsHelpFormatter',
     'RawDescriptionHelpFormatter',
     'RawTextHelpFormatter',
-    'ArgumentDefaultsHelpFormatter',
+    'Namespace',
+    'Action',
+    'ONE_OR_MORE',
+    'OPTIONAL',
+    'PARSER',
+    'REMAINDER',
+    'SUPPRESS',
+    'ZERO_OR_MORE',
 ]
 
 
@@ -95,6 +102,7 @@
 ONE_OR_MORE = '+'
 PARSER = 'A...'
 REMAINDER = '...'
+_UNRECOGNIZED_ARGS_ATTR = '_unrecognized_args'
 
 # =============================
 # Utility functions and classes
@@ -385,10 +393,16 @@
                     for action in group._group_actions:
                         group_actions.add(action)
                     if not group.required:
-                        inserts[start] = '['
+                        if start in inserts:
+                            inserts[start] += ' ['
+                        else:
+                            inserts[start] = '['
                         inserts[end] = ']'
                     else:
-                        inserts[start] = '('
+                        if start in inserts:
+                            inserts[start] += ' ('
+                        else:
+                            inserts[start] = '('
                         inserts[end] = ')'
                     for i in range(start + 1, end):
                         inserts[i] = '|'
@@ -1070,7 +1084,12 @@
             raise ArgumentError(self, msg)
 
         # parse all the remaining options into the namespace
-        parser.parse_args(arg_strings, namespace)
+        # store any unrecognized options on the object, so that the top
+        # level parser can decide what to do with them
+        namespace, arg_strings = parser.parse_known_args(arg_strings, namespace)
+        if arg_strings:
+            vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
+            getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings)
 
 
 # ==============
@@ -1688,7 +1707,11 @@
 
         # parse the arguments and exit if there are any errors
         try:
-            return self._parse_known_args(args, namespace)
+            namespace, args = self._parse_known_args(args, namespace)
+            if hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR):
+                args.extend(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR))
+                delattr(namespace, _UNRECOGNIZED_ARGS_ATTR)
+            return namespace, args
         except ArgumentError:
             err = _sys.exc_info()[1]
             self.error(str(err))
@@ -1789,13 +1812,13 @@
                     chars = self.prefix_chars
                     if arg_count == 0 and option_string[1] not in chars:
                         action_tuples.append((action, [], option_string))
-                        for char in self.prefix_chars:
-                            option_string = char + explicit_arg[0]
-                            explicit_arg = explicit_arg[1:] or None
-                            optionals_map = self._option_string_actions
-                            if option_string in optionals_map:
-                                action = optionals_map[option_string]
-                                break
+                        char = option_string[0]
+                        option_string = char + explicit_arg[0]
+                        new_explicit_arg = explicit_arg[1:] or None
+                        optionals_map = self._option_string_actions
+                        if option_string in optionals_map:
+                            action = optionals_map[option_string]
+                            explicit_arg = new_explicit_arg
                         else:
                             msg = _('ignored explicit argument %r')
                             raise ArgumentError(action, msg % explicit_arg)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/asyncore.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/asyncore.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/asyncore.py	Fri Nov  5 23:50:59 2010
@@ -350,12 +350,15 @@
         # XXX can return either an address pair or None
         try:
             conn, addr = self.socket.accept()
-            return conn, addr
-        except socket.error, why:
-            if why.args[0] == EWOULDBLOCK:
-                pass
+        except TypeError:
+            return None
+        except socket.error as why:
+            if why.args[0] in (EWOULDBLOCK, ECONNABORTED):
+                return None
             else:
                 raise
+        else:
+            return conn, addr
 
     def send(self, data):
         try:

Modified: pypy/branch/fast-forward/lib-python/2.7.0/base64.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/base64.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/base64.py	Fri Nov  5 23:50:59 2010
@@ -343,7 +343,8 @@
         if o == '-u': func = decode
         if o == '-t': test1(); return
     if args and args[0] != '-':
-        func(open(args[0], 'rb'), sys.stdout)
+        with open(args[0], 'rb') as f:
+            func(f, sys.stdout)
     else:
         func(sys.stdin, sys.stdout)
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/calendar.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/calendar.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/calendar.py	Fri Nov  5 23:50:59 2010
@@ -95,7 +95,7 @@
 
 
 def isleap(year):
-    """Return 1 for leap years, 0 for non-leap years."""
+    """Return True for leap years, False for non-leap years."""
     return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
 
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/collections.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/collections.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/collections.py	Fri Nov  5 23:50:59 2010
@@ -12,6 +12,32 @@
 import heapq as _heapq
 from itertools import repeat as _repeat, chain as _chain, starmap as _starmap, \
                       ifilter as _ifilter, imap as _imap
+try:
+    from thread import get_ident
+except AttributeError:
+    from dummy_thread import get_ident
+
+def _recursive_repr(user_function):
+    'Decorator to make a repr function return "..." for a recursive call'
+    repr_running = set()
+
+    def wrapper(self):
+        key = id(self), get_ident()
+        if key in repr_running:
+            return '...'
+        repr_running.add(key)
+        try:
+            result = user_function(self)
+        finally:
+            repr_running.discard(key)
+        return result
+
+    # Can't use functools.wraps() here because of bootstrap issues
+    wrapper.__module__ = getattr(user_function, '__module__')
+    wrapper.__doc__ = getattr(user_function, '__doc__')
+    wrapper.__name__ = getattr(user_function, '__name__')
+    return wrapper
+
 
 ################################################################################
 ### OrderedDict
@@ -142,6 +168,7 @@
         value = self.pop(key)
         return key, value
 
+    @_recursive_repr
     def __repr__(self):
         'od.__repr__() <==> repr(od)'
         if not self:

Modified: pypy/branch/fast-forward/lib-python/2.7.0/ctypes/util.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/ctypes/util.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/ctypes/util.py	Fri Nov  5 23:50:59 2010
@@ -185,7 +185,7 @@
         def _findLib_ldconfig(name):
             # XXX assuming GLIBC's ldconfig (with option -p)
             expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
-            f = os.popen('LANG=C /sbin/ldconfig -p 2>/dev/null')
+            f = os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null')
             try:
                 data = f.read()
             finally:

Modified: pypy/branch/fast-forward/lib-python/2.7.0/distutils/dir_util.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/distutils/dir_util.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/distutils/dir_util.py	Fri Nov  5 23:50:59 2010
@@ -2,7 +2,7 @@
 
 Utility functions for manipulating directories and directory trees."""
 
-__revision__ = "$Id: dir_util.py 76956 2009-12-21 01:22:46Z tarek.ziade $"
+__revision__ = "$Id: dir_util.py 84862 2010-09-17 16:40:01Z senthil.kumaran $"
 
 import os
 from distutils.errors import DistutilsFileError, DistutilsInternalError
@@ -68,7 +68,7 @@
 
         if not dry_run:
             try:
-                os.mkdir(head)
+                os.mkdir(head, mode)
                 created_dirs.append(head)
             except OSError, exc:
                 raise DistutilsFileError, \

Modified: pypy/branch/fast-forward/lib-python/2.7.0/distutils/sysconfig.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/distutils/sysconfig.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/distutils/sysconfig.py	Fri Nov  5 23:50:59 2010
@@ -9,7 +9,7 @@
 Email:        <fdrake at acm.org>
 """
 
-__revision__ = "$Id: sysconfig.py 80804 2010-05-05 19:09:31Z ronald.oussoren $"
+__revision__ = "$Id: sysconfig.py 85358 2010-10-10 09:54:59Z antoine.pitrou $"
 
 import os
 import re
@@ -318,6 +318,11 @@
 
     fp.close()
 
+    # strip spurious spaces
+    for k, v in done.items():
+        if isinstance(v, str):
+            done[k] = v.strip()
+
     # save the results in the global dictionary
     g.update(done)
     return g

Modified: pypy/branch/fast-forward/lib-python/2.7.0/distutils/tests/test_build_ext.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/distutils/tests/test_build_ext.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/distutils/tests/test_build_ext.py	Fri Nov  5 23:50:59 2010
@@ -49,6 +49,25 @@
                                     sys.platform == 'cygwin')
         super(BuildExtTestCase, self).tearDown()
 
+    def _fixup_command(self, cmd):
+        # When Python was build with --enable-shared, -L. is not good enough
+        # to find the libpython<blah>.so.  This is because regrtest runs it
+        # under a tempdir, not in the top level where the .so lives.  By the
+        # time we've gotten here, Python's already been chdir'd to the
+        # tempdir.
+        #
+        # To further add to the fun, we can't just add library_dirs to the
+        # Extension() instance because that doesn't get plumbed through to the
+        # final compiler command.
+        if (sysconfig.get_config_var('Py_ENABLE_SHARED') and
+            not sys.platform.startswith('win')):
+            runshared = sysconfig.get_config_var('RUNSHARED')
+            if runshared is None:
+                cmd.library_dirs = ['.']
+            else:
+                name, equals, value = runshared.partition('=')
+                cmd.library_dirs = value.split(os.pathsep)
+
     @unittest.skipIf(not os.path.exists(_XX_MODULE_PATH),
                      'xxmodule.c not found')
     def test_build_ext(self):
@@ -58,6 +77,7 @@
         dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]})
         dist.package_dir = self.tmp_dir
         cmd = build_ext(dist)
+        self._fixup_command(cmd)
         if os.name == "nt":
             # On Windows, we must build a debug version iff running
             # a debug build of Python
@@ -250,6 +270,7 @@
         dist = Distribution({'name': 'xx',
                              'ext_modules': [ext]})
         cmd = build_ext(dist)
+        self._fixup_command(cmd)
         cmd.ensure_finalized()
         self.assertEquals(len(cmd.get_outputs()), 1)
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/distutils/tests/test_dir_util.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/distutils/tests/test_dir_util.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/distutils/tests/test_dir_util.py	Fri Nov  5 23:50:59 2010
@@ -1,7 +1,9 @@
 """Tests for distutils.dir_util."""
 import unittest
 import os
+import stat
 import shutil
+import sys
 
 from distutils.dir_util import (mkpath, remove_tree, create_tree, copy_tree,
                                 ensure_relative)
@@ -48,6 +50,19 @@
         wanted = ["removing '%s' (and everything under it)" % self.root_target]
         self.assertEquals(self._logs, wanted)
 
+    @unittest.skipIf(sys.platform.startswith('win'),
+                        "This test is only appropriate for POSIX-like systems.")
+    def test_mkpath_with_custom_mode(self):
+        # Get and set the current umask value for testing mode bits.
+        umask = os.umask(0o002)
+        os.umask(umask)
+        mkpath(self.target, 0o700)
+        self.assertEqual(
+            stat.S_IMODE(os.stat(self.target).st_mode), 0o700 & ~umask)
+        mkpath(self.target2, 0o555)
+        self.assertEqual(
+            stat.S_IMODE(os.stat(self.target2).st_mode), 0o555 & ~umask)
+
     def test_create_tree_verbosity(self):
 
         create_tree(self.root_target, ['one', 'two', 'three'], verbose=0)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/doctest.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/doctest.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/doctest.py	Fri Nov  5 23:50:59 2010
@@ -216,7 +216,8 @@
                 # get_data() opens files as 'rb', so one must do the equivalent
                 # conversion as universal newlines would do.
                 return file_contents.replace(os.linesep, '\n'), filename
-    return open(filename).read(), filename
+    with open(filename) as f:
+        return f.read(), filename
 
 # Use sys.stdout encoding for ouput.
 _encoding = getattr(sys.__stdout__, 'encoding', None) or 'utf-8'
@@ -1327,13 +1328,15 @@
         self.tries += t
 
     __LINECACHE_FILENAME_RE = re.compile(r'<doctest '
-                                         r'(?P<name>[\w\.]+)'
+                                         r'(?P<name>.+)'
                                          r'\[(?P<examplenum>\d+)\]>$')
     def __patched_linecache_getlines(self, filename, module_globals=None):
         m = self.__LINECACHE_FILENAME_RE.match(filename)
         if m and m.group('name') == self.test.name:
             example = self.test.examples[int(m.group('examplenum'))]
-            source = example.source.encode('ascii', 'backslashreplace')
+            source = example.source
+            if isinstance(source, unicode):
+                source = source.encode('ascii', 'backslashreplace')
             return source.splitlines(True)
         else:
             return self.save_linecache_getlines(filename, module_globals)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/email/_parseaddr.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/email/_parseaddr.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/email/_parseaddr.py	Fri Nov  5 23:50:59 2010
@@ -160,7 +160,12 @@
 
 
 def quote(str):
-    """Add quotes around a string."""
+    """Prepare string to be used in a quoted string.
+
+    Turns backslash and double quote characters into quoted pairs.  These
+    are the only characters that need to be quoted inside a quoted string.
+    Does not add the surrounding double quotes.
+    """
     return str.replace('\\', '\\\\').replace('"', '\\"')
 
 
@@ -318,7 +323,7 @@
                 aslist.append('.')
                 self.pos += 1
             elif self.field[self.pos] == '"':
-                aslist.append('"%s"' % self.getquote())
+                aslist.append('"%s"' % quote(self.getquote()))
             elif self.field[self.pos] in self.atomends:
                 break
             else:

Modified: pypy/branch/fast-forward/lib-python/2.7.0/email/quoprimime.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/email/quoprimime.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/email/quoprimime.py	Fri Nov  5 23:50:59 2010
@@ -333,4 +333,4 @@
     the high level email.header class for that functionality.
     """
     s = s.replace('_', ' ')
-    return re.sub(r'=\w{2}', _unquote_match, s)
+    return re.sub(r'=[a-fA-F0-9]{2}', _unquote_match, s)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/email/test/test_email.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/email/test/test_email.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/email/test/test_email.py	Fri Nov  5 23:50:59 2010
@@ -1621,6 +1621,12 @@
             dh = decode_header(s % q)
             self.assertEqual(dh, [(a, 'iso-8859-1')])
 
+    def test_rfc2047_Q_invalid_digits(self):
+        # issue 10004.
+        s = '=?iso-8659-1?Q?andr=e9=zz?='
+        self.assertEqual(decode_header(s),
+                        [(b'andr\xe9=zz', 'iso-8659-1')])
+
 
 # Test the MIMEMessage class
 class TestMIMEMessage(TestEmailBase):
@@ -2281,6 +2287,24 @@
         # formataddr() quotes the name if there's a dot in it
         self.assertEqual(Utils.formataddr((a, b)), y)
 
+    def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
+        # issue 10005.  Note that in the third test the second pair of
+        # backslashes is not actually a quoted pair because it is not inside a
+        # comment or quoted string: the address being parsed has a quoted
+        # string containing a quoted backslash, followed by 'example' and two
+        # backslashes, followed by another quoted string containing a space and
+        # the word 'example'.  parseaddr copies those two backslashes
+        # literally.  Per rfc5322 this is not technically correct since a \ may
+        # not appear in an address outside of a quoted string.  It is probably
+        # a sensible Postel interpretation, though.
+        eq = self.assertEqual
+        eq(Utils.parseaddr('""example" example"@example.com'),
+          ('', '""example" example"@example.com'))
+        eq(Utils.parseaddr('"\\"example\\" example"@example.com'),
+          ('', '"\\"example\\" example"@example.com'))
+        eq(Utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
+          ('', '"\\\\"example\\\\" example"@example.com'))
+
     def test_multiline_from_comment(self):
         x = """\
 Foo

Modified: pypy/branch/fast-forward/lib-python/2.7.0/gettext.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/gettext.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/gettext.py	Fri Nov  5 23:50:59 2010
@@ -471,7 +471,7 @@
     # once.
     result = None
     for mofile in mofiles:
-        key = os.path.abspath(mofile)
+        key = (class_, os.path.abspath(mofile))
         t = _translations.get(key)
         if t is None:
             with open(mofile, 'rb') as fp:

Modified: pypy/branch/fast-forward/lib-python/2.7.0/gzip.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/gzip.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/gzip.py	Fri Nov  5 23:50:59 2010
@@ -138,6 +138,13 @@
         s = repr(self.fileobj)
         return '<gzip ' + s[1:-1] + ' ' + hex(id(self)) + '>'
 
+    def _check_closed(self):
+        """Raises a ValueError if the underlying file object has been closed.
+
+        """
+        if self.closed:
+            raise ValueError('I/O operation on closed file.')
+
     def _init_write(self, filename):
         self.name = filename
         self.crc = zlib.crc32("") & 0xffffffffL
@@ -202,6 +209,7 @@
             self.fileobj.read(2)     # Read & discard the 16-bit header CRC
 
     def write(self,data):
+        self._check_closed()
         if self.mode != WRITE:
             import errno
             raise IOError(errno.EBADF, "write() on read-only GzipFile object")
@@ -222,6 +230,7 @@
         return len(data)
 
     def read(self, size=-1):
+        self._check_closed()
         if self.mode != READ:
             import errno
             raise IOError(errno.EBADF, "read() on write-only GzipFile object")
@@ -359,6 +368,7 @@
             self.myfileobj = None
 
     def flush(self,zlib_mode=zlib.Z_SYNC_FLUSH):
+        self._check_closed()
         if self.mode == WRITE:
             # Ensure the compressor's buffer is flushed
             self.fileobj.write(self.compress.flush(zlib_mode))

Modified: pypy/branch/fast-forward/lib-python/2.7.0/httplib.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/httplib.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/httplib.py	Fri Nov  5 23:50:59 2010
@@ -639,6 +639,9 @@
             amt -= len(chunk)
         return ''.join(s)
 
+    def fileno(self):
+        return self.fp.fileno()
+
     def getheader(self, name, default=None):
         if self.msg is None:
             raise ResponseNotReady()
@@ -749,8 +752,8 @@
             self.__response = None
         self.__state = _CS_IDLE
 
-    def send(self, str):
-        """Send `str' to the server."""
+    def send(self, data):
+        """Send `data' to the server."""
         if self.sock is None:
             if self.auto_open:
                 self.connect()
@@ -758,16 +761,16 @@
                 raise NotConnected()
 
         if self.debuglevel > 0:
-            print "send:", repr(str)
+            print "send:", repr(data)
         blocksize = 8192
-        if hasattr(str,'read') and not isinstance(str, array):
+        if hasattr(data,'read') and not isinstance(data, array):
             if self.debuglevel > 0: print "sendIng a read()able"
-            data = str.read(blocksize)
-            while data:
-                self.sock.sendall(data)
-                data = str.read(blocksize)
+            datablock = data.read(blocksize)
+            while datablock:
+                self.sock.sendall(datablock)
+                datablock = data.read(blocksize)
         else:
-            self.sock.sendall(str)
+            self.sock.sendall(data)
 
     def _output(self, s):
         """Add a line of output to the current request buffer.
@@ -839,9 +842,9 @@
         self._method = method
         if not url:
             url = '/'
-        str = '%s %s %s' % (method, url, self._http_vsn_str)
+        hdr = '%s %s %s' % (method, url, self._http_vsn_str)
 
-        self._output(str)
+        self._output(hdr)
 
         if self._http_vsn == 11:
             # Issue some standard headers for better HTTP/1.1 compliance
@@ -912,8 +915,8 @@
         if self.__state != _CS_REQ_STARTED:
             raise CannotSendHeader()
 
-        str = '%s: %s' % (header, '\r\n\t'.join(values))
-        self._output(str)
+        hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values]))
+        self._output(hdr)
 
     def endheaders(self, message_body=None):
         """Indicate that the last header line has been sent to the server.

Modified: pypy/branch/fast-forward/lib-python/2.7.0/json/__init__.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/json/__init__.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/json/__init__.py	Fri Nov  5 23:50:59 2010
@@ -160,7 +160,7 @@
 
     To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
     ``.default()`` method to serialize additional types), specify it with
-    the ``cls`` kwarg.
+    the ``cls`` kwarg; otherwise ``JSONEncoder`` is used.
 
     """
     # cached encoder
@@ -220,7 +220,7 @@
 
     To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
     ``.default()`` method to serialize additional types), specify it with
-    the ``cls`` kwarg.
+    the ``cls`` kwarg; otherwise ``JSONEncoder`` is used.
 
     """
     # cached encoder
@@ -259,8 +259,16 @@
     ``object_hook`` will be used instead of the ``dict``. This feature
     can be used to implement custom decoders (e.g. JSON-RPC class hinting).
 
+    ``object_pairs_hook`` is an optional function that will be called with the
+    result of any object literal decoded with an ordered list of pairs.  The
+    return value of ``object_pairs_hook`` will be used instead of the ``dict``.
+    This feature can be used to implement custom decoders that rely on the
+    order that the key and value pairs are decoded (for example,
+    collections.OrderedDict will remember the order of insertion). If
+    ``object_hook`` is also defined, the ``object_pairs_hook`` takes priority.
+
     To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
-    kwarg.
+    kwarg; otherwise ``JSONDecoder`` is used.
 
     """
     return loads(fp.read(),
@@ -285,6 +293,14 @@
     ``object_hook`` will be used instead of the ``dict``. This feature
     can be used to implement custom decoders (e.g. JSON-RPC class hinting).
 
+    ``object_pairs_hook`` is an optional function that will be called with the
+    result of any object literal decoded with an ordered list of pairs.  The
+    return value of ``object_pairs_hook`` will be used instead of the ``dict``.
+    This feature can be used to implement custom decoders that rely on the
+    order that the key and value pairs are decoded (for example,
+    collections.OrderedDict will remember the order of insertion). If
+    ``object_hook`` is also defined, the ``object_pairs_hook`` takes priority.
+
     ``parse_float``, if specified, will be called with the string
     of every JSON float to be decoded. By default this is equivalent to
     float(num_str). This can be used to use another datatype or parser
@@ -301,7 +317,7 @@
     are encountered.
 
     To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
-    kwarg.
+    kwarg; otherwise ``JSONDecoder`` is used.
 
     """
     if (cls is None and encoding is None and object_hook is None and

Modified: pypy/branch/fast-forward/lib-python/2.7.0/json/decoder.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/json/decoder.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/json/decoder.py	Fri Nov  5 23:50:59 2010
@@ -310,6 +310,15 @@
         place of the given ``dict``.  This can be used to provide custom
         deserializations (e.g. to support JSON-RPC class hinting).
 
+        ``object_pairs_hook``, if specified will be called with the result of
+        every JSON object decoded with an ordered list of pairs.  The return
+        value of ``object_pairs_hook`` will be used instead of the ``dict``.
+        This feature can be used to implement custom decoders that rely on the
+        order that the key and value pairs are decoded (for example,
+        collections.OrderedDict will remember the order of insertion). If
+        ``object_hook`` is also defined, the ``object_pairs_hook`` takes
+        priority.
+
         ``parse_float``, if specified, will be called with the string
         of every JSON float to be decoded. By default this is equivalent to
         float(num_str). This can be used to use another datatype or parser
@@ -325,6 +334,11 @@
         This can be used to raise an exception if invalid JSON numbers
         are encountered.
 
+        If ``strict`` is false (true is the default), then control
+        characters will be allowed inside strings.  Control characters in
+        this context are those with character codes in the 0-31 range,
+        including ``'\\t'`` (tab), ``'\\n'``, ``'\\r'`` and ``'\\0'``.
+
         """
         self.encoding = encoding
         self.object_hook = object_hook

Modified: pypy/branch/fast-forward/lib-python/2.7.0/json/tests/test_encode_basestring_ascii.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/json/tests/test_encode_basestring_ascii.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/json/tests/test_encode_basestring_ascii.py	Fri Nov  5 23:50:59 2010
@@ -1,6 +1,8 @@
 from unittest import TestCase
 
 import json.encoder
+from json import dumps
+from collections import OrderedDict
 
 CASES = [
     (u'/\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\x08\x0c\n\r\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?', '"/\\\\\\"\\ucafe\\ubabe\\uab98\\ufcde\\ubcda\\uef4a\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?"'),
@@ -37,3 +39,9 @@
             self.assertEquals(result, expect,
                 '{0!r} != {1!r} for {2}({3!r})'.format(
                     result, expect, fname, input_string))
+
+    def test_ordered_dict(self):
+        # See issue 6105
+        items = [('one', 1), ('two', 2), ('three', 3), ('four', 4), ('five', 5)]
+        s = json.dumps(OrderedDict(items))
+        self.assertEqual(s, '{"one": 1, "two": 2, "three": 3, "four": 4, "five": 5}')

Modified: pypy/branch/fast-forward/lib-python/2.7.0/json/tests/test_unicode.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/json/tests/test_unicode.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/json/tests/test_unicode.py	Fri Nov  5 23:50:59 2010
@@ -78,3 +78,5 @@
         self.assertEquals(type(json.loads(u'""')), unicode)
         self.assertEquals(type(json.loads(u'"a"')), unicode)
         self.assertEquals(type(json.loads(u'["a"]')[0]), unicode)
+        # Issue 10038.
+        self.assertEquals(type(json.loads('"foo"')), unicode)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib-tk/test/test_ttk/test_widgets.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib-tk/test/test_ttk/test_widgets.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib-tk/test/test_ttk/test_widgets.py	Fri Nov  5 23:50:59 2010
@@ -13,7 +13,7 @@
 
     def setUp(self):
         support.root_deiconify()
-        self.widget = ttk.Button()
+        self.widget = ttk.Button(width=0, text="Text")
         self.widget.pack()
         self.widget.wait_visibility()
 
@@ -24,7 +24,10 @@
 
     def test_identify(self):
         self.widget.update_idletasks()
-        self.assertEqual(self.widget.identify(5, 5), "label")
+        self.assertEqual(self.widget.identify(
+            int(self.widget.winfo_width() / 2),
+            int(self.widget.winfo_height() / 2)
+            ), "label")
         self.assertEqual(self.widget.identify(-1, -1), "")
 
         self.assertRaises(Tkinter.TclError, self.widget.identify, None, 5)
@@ -530,7 +533,7 @@
 
     def setUp(self):
         support.root_deiconify()
-        self.nb = ttk.Notebook()
+        self.nb = ttk.Notebook(padding=0)
         self.child1 = ttk.Label()
         self.child2 = ttk.Label()
         self.nb.add(self.child1, text='a')
@@ -717,6 +720,7 @@
         self.nb.tab(self.child1, text='a', underline=0)
         self.nb.enable_traversal()
         self.nb.focus_force()
+        support.simulate_mouse_click(self.nb, 5, 5)
         self.nb.event_generate('<Alt-a>')
         self.assertEqual(self.nb.select(), str(self.child1))
 
@@ -725,7 +729,7 @@
 
     def setUp(self):
         support.root_deiconify()
-        self.tv = ttk.Treeview()
+        self.tv = ttk.Treeview(padding=0)
 
     def tearDown(self):
         self.tv.destroy()

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib-tk/turtle.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib-tk/turtle.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib-tk/turtle.py	Fri Nov  5 23:50:59 2010
@@ -1495,7 +1495,10 @@
         >>> turtle.left(90)
         >>> turtle.heading()
         90
-        >>> turtle.degrees(400.0)  # angle measurement in gon
+
+        Change angle measurement unit to grad (also known as gon,
+        grade, or gradian and equals 1/100-th of the right angle.)
+        >>> turtle.degrees(400.0)
         >>> turtle.heading()
         100
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/Grammar.txt
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/Grammar.txt	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/Grammar.txt	Fri Nov  5 23:50:59 2010
@@ -128,7 +128,7 @@
        '`' testlist1 '`' |
        NAME | NUMBER | STRING+ | '.' '.' '.')
 listmaker: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
-testlist_gexp: test ( comp_for | (',' (test|star_expr))* [','] )
+testlist_gexp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
 lambdef: 'lambda' [varargslist] ':' test
 trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
 subscriptlist: subscript (',' subscript)* [',']

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixer_base.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixer_base.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixer_base.py	Fri Nov  5 23:50:59 2010
@@ -24,6 +24,7 @@
 
     PATTERN = None  # Most subclasses should override with a string literal
     pattern = None  # Compiled pattern, set by compile_pattern()
+    pattern_tree = None # Tree representation of the pattern
     options = None  # Options object passed to initializer
     filename = None # The filename (set by set_filename)
     logger = None   # A logger (set by set_filename)
@@ -36,6 +37,12 @@
     _accept_type = None # [Advanced and not public] This tells RefactoringTool
                         # which node type to accept when there's not a pattern.
 
+    keep_line_order = False # For the bottom matcher: match with the
+                            # original line order
+    BM_compatible = False # Compatibility with the bottom matching
+                          # module; every fixer should set this
+                          # manually
+
     # Shortcut for access to Python grammar symbols
     syms = pygram.python_symbols
 
@@ -58,7 +65,9 @@
         self.{pattern,PATTERN} in .match().
         """
         if self.PATTERN is not None:
-            self.pattern = PatternCompiler().compile_pattern(self.PATTERN)
+            PC = PatternCompiler()
+            self.pattern, self.pattern_tree = PC.compile_pattern(self.PATTERN,
+                                                                 with_tree=True)
 
     def set_filename(self, filename):
         """Set the filename, and a logger derived from it.

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixer_util.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixer_util.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixer_util.py	Fri Nov  5 23:50:59 2010
@@ -295,8 +295,8 @@
     """ Works like `does_tree_import` but adds an import statement
         if it was not imported. """
     def is_import_stmt(node):
-        return node.type == syms.simple_stmt and node.children and \
-               is_import(node.children[0])
+        return (node.type == syms.simple_stmt and node.children and
+                is_import(node.children[0]))
 
     root = find_root(node)
 
@@ -319,8 +319,8 @@
     # if that also fails, we stick to the beginning of the file
     if insert_pos == 0:
         for idx, node in enumerate(root.children):
-            if node.type == syms.simple_stmt and node.children and \
-               node.children[0].type == token.STRING:
+            if (node.type == syms.simple_stmt and node.children and
+               node.children[0].type == token.STRING):
                 insert_pos = idx + 1
                 break
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_apply.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_apply.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_apply.py	Fri Nov  5 23:50:59 2010
@@ -12,6 +12,7 @@
 from ..fixer_util import Call, Comma, parenthesize
 
 class FixApply(fixer_base.BaseFix):
+    BM_compatible = True
 
     PATTERN = """
     power< 'apply'

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_basestring.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_basestring.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_basestring.py	Fri Nov  5 23:50:59 2010
@@ -6,6 +6,7 @@
 from ..fixer_util import Name
 
 class FixBasestring(fixer_base.BaseFix):
+    BM_compatible = True
 
     PATTERN = "'basestring'"
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_buffer.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_buffer.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_buffer.py	Fri Nov  5 23:50:59 2010
@@ -9,6 +9,7 @@
 
 
 class FixBuffer(fixer_base.BaseFix):
+    BM_compatible = True
 
     explicit = True # The user must ask for this fixer
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_callable.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_callable.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_callable.py	Fri Nov  5 23:50:59 2010
@@ -11,6 +11,9 @@
 from lib2to3.fixer_util import Call, Name, String, Attr, touch_import
 
 class FixCallable(fixer_base.BaseFix):
+    BM_compatible = True
+
+    order = "pre"
 
     # Ignore callable(*args) or use of keywords.
     # Either could be a hint that the builtin callable() is not being used.

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_dict.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_dict.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_dict.py	Fri Nov  5 23:50:59 2010
@@ -40,6 +40,8 @@
 
 
 class FixDict(fixer_base.BaseFix):
+    BM_compatible = True
+
     PATTERN = """
     power< head=any+
          trailer< '.' method=('keys'|'items'|'values'|

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_except.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_except.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_except.py	Fri Nov  5 23:50:59 2010
@@ -34,6 +34,7 @@
                 yield (n, nodes[i+2])
 
 class FixExcept(fixer_base.BaseFix):
+    BM_compatible = True
 
     PATTERN = """
     try_stmt< 'try' ':' (simple_stmt | suite)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_exec.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_exec.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_exec.py	Fri Nov  5 23:50:59 2010
@@ -16,6 +16,7 @@
 
 
 class FixExec(fixer_base.BaseFix):
+    BM_compatible = True
 
     PATTERN = """
     exec_stmt< 'exec' a=any 'in' b=any [',' c=any] >

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_execfile.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_execfile.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_execfile.py	Fri Nov  5 23:50:59 2010
@@ -13,6 +13,7 @@
 
 
 class FixExecfile(fixer_base.BaseFix):
+    BM_compatible = True
 
     PATTERN = """
     power< 'execfile' trailer< '(' arglist< filename=any [',' globals=any [',' locals=any ] ] > ')' > >

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_exitfunc.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_exitfunc.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_exitfunc.py	Fri Nov  5 23:50:59 2010
@@ -9,6 +9,8 @@
 
 
 class FixExitfunc(fixer_base.BaseFix):
+    keep_line_order = True
+    BM_compatible = True
 
     PATTERN = """
               (

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_filter.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_filter.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_filter.py	Fri Nov  5 23:50:59 2010
@@ -19,6 +19,7 @@
 from ..fixer_util import Name, Call, ListComp, in_special_context
 
 class FixFilter(fixer_base.ConditionalFix):
+    BM_compatible = True
 
     PATTERN = """
     filter_lambda=power<

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_funcattrs.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_funcattrs.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_funcattrs.py	Fri Nov  5 23:50:59 2010
@@ -7,6 +7,8 @@
 
 
 class FixFuncattrs(fixer_base.BaseFix):
+    BM_compatible = True
+
     PATTERN = """
     power< any+ trailer< '.' attr=('func_closure' | 'func_doc' | 'func_globals'
                                   | 'func_name' | 'func_defaults' | 'func_code'

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_future.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_future.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_future.py	Fri Nov  5 23:50:59 2010
@@ -9,6 +9,8 @@
 from ..fixer_util import BlankLine
 
 class FixFuture(fixer_base.BaseFix):
+    BM_compatible = True
+
     PATTERN = """import_from< 'from' module_name="__future__" 'import' any >"""
 
     # This should be run last -- some things check for the import

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_getcwdu.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_getcwdu.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_getcwdu.py	Fri Nov  5 23:50:59 2010
@@ -8,6 +8,7 @@
 from ..fixer_util import Name
 
 class FixGetcwdu(fixer_base.BaseFix):
+    BM_compatible = True
 
     PATTERN = """
               power< 'os' trailer< dot='.' name='getcwdu' > any* >

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_has_key.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_has_key.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_has_key.py	Fri Nov  5 23:50:59 2010
@@ -37,6 +37,7 @@
 
 
 class FixHasKey(fixer_base.BaseFix):
+    BM_compatible = True
 
     PATTERN = """
     anchor=power<

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_idioms.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_idioms.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_idioms.py	Fri Nov  5 23:50:59 2010
@@ -35,7 +35,6 @@
 TYPE = "power< 'type' trailer< '(' x=any ')' > >"
 
 class FixIdioms(fixer_base.BaseFix):
-
     explicit = True # The user must ask for this fixer
 
     PATTERN = r"""

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_import.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_import.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_import.py	Fri Nov  5 23:50:59 2010
@@ -36,6 +36,7 @@
 
 
 class FixImport(fixer_base.BaseFix):
+    BM_compatible = True
 
     PATTERN = """
     import_from< 'from' imp=any 'import' ['('] any [')'] >

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_imports.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_imports.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_imports.py	Fri Nov  5 23:50:59 2010
@@ -84,6 +84,8 @@
 
 class FixImports(fixer_base.BaseFix):
 
+    BM_compatible = True
+    keep_line_order = True
     # This is overridden in fix_imports2.
     mapping = MAPPING
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_input.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_input.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_input.py	Fri Nov  5 23:50:59 2010
@@ -11,7 +11,7 @@
 
 
 class FixInput(fixer_base.BaseFix):
-
+    BM_compatible = True
     PATTERN = """
               power< 'input' args=trailer< '(' [any] ')' > >
               """

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_intern.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_intern.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_intern.py	Fri Nov  5 23:50:59 2010
@@ -12,6 +12,8 @@
 
 
 class FixIntern(fixer_base.BaseFix):
+    BM_compatible = True
+    order = "pre"
 
     PATTERN = """
     power< 'intern'

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_isinstance.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_isinstance.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_isinstance.py	Fri Nov  5 23:50:59 2010
@@ -14,7 +14,7 @@
 
 
 class FixIsinstance(fixer_base.BaseFix):
-
+    BM_compatible = True
     PATTERN = """
     power<
         'isinstance'

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_itertools.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_itertools.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_itertools.py	Fri Nov  5 23:50:59 2010
@@ -12,6 +12,7 @@
 from ..fixer_util import Name
 
 class FixItertools(fixer_base.BaseFix):
+    BM_compatible = True
     it_funcs = "('imap'|'ifilter'|'izip'|'ifilterfalse')"
     PATTERN = """
               power< it='itertools'

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_itertools_imports.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_itertools_imports.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_itertools_imports.py	Fri Nov  5 23:50:59 2010
@@ -6,6 +6,7 @@
 
 
 class FixItertoolsImports(fixer_base.BaseFix):
+    BM_compatible = True
     PATTERN = """
               import_from< 'from' 'itertools' 'import' imports=any >
               """ %(locals())

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_long.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_long.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_long.py	Fri Nov  5 23:50:59 2010
@@ -10,7 +10,7 @@
 
 
 class FixLong(fixer_base.BaseFix):
-
+    BM_compatible = True
     PATTERN = "'long'"
 
     def transform(self, node, results):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_map.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_map.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_map.py	Fri Nov  5 23:50:59 2010
@@ -26,6 +26,7 @@
 from ..pygram import python_symbols as syms
 
 class FixMap(fixer_base.ConditionalFix):
+    BM_compatible = True
 
     PATTERN = """
     map_none=power<

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_metaclass.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_metaclass.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_metaclass.py	Fri Nov  5 23:50:59 2010
@@ -143,6 +143,7 @@
 
 
 class FixMetaclass(fixer_base.BaseFix):
+    BM_compatible = True
 
     PATTERN = """
     classdef<any*>

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_methodattrs.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_methodattrs.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_methodattrs.py	Fri Nov  5 23:50:59 2010
@@ -13,6 +13,7 @@
     }
 
 class FixMethodattrs(fixer_base.BaseFix):
+    BM_compatible = True
     PATTERN = """
     power< any+ trailer< '.' attr=('im_func' | 'im_self' | 'im_class') > any* >
     """

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_next.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_next.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_next.py	Fri Nov  5 23:50:59 2010
@@ -15,6 +15,7 @@
 
 
 class FixNext(fixer_base.BaseFix):
+    BM_compatible = True
     PATTERN = """
     power< base=any+ trailer< '.' attr='next' > trailer< '(' ')' > >
     |

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_nonzero.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_nonzero.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_nonzero.py	Fri Nov  5 23:50:59 2010
@@ -6,6 +6,7 @@
 from ..fixer_util import Name, syms
 
 class FixNonzero(fixer_base.BaseFix):
+    BM_compatible = True
     PATTERN = """
     classdef< 'class' any+ ':'
               suite< any*

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_operator.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_operator.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_operator.py	Fri Nov  5 23:50:59 2010
@@ -14,7 +14,16 @@
 from lib2to3.fixer_util import Call, Name, String, touch_import
 
 
+def invocation(s):
+    def dec(f):
+        f.invocation = s
+        return f
+    return dec
+
+
 class FixOperator(fixer_base.BaseFix):
+    BM_compatible = True
+    order = "pre"
 
     methods = """
               method=('isCallable'|'sequenceIncludes'
@@ -34,34 +43,34 @@
         if method is not None:
             return method(node, results)
 
+    @invocation("operator.contains(%s)")
     def _sequenceIncludes(self, node, results):
-        """operator.contains(%s)"""
         return self._handle_rename(node, results, u"contains")
 
+    @invocation("hasattr(%s, '__call__')")
     def _isCallable(self, node, results):
-        """hasattr(%s, '__call__')"""
         obj = results["obj"]
         args = [obj.clone(), String(u", "), String(u"'__call__'")]
         return Call(Name(u"hasattr"), args, prefix=node.prefix)
 
+    @invocation("operator.mul(%s)")
     def _repeat(self, node, results):
-        """operator.mul(%s)"""
         return self._handle_rename(node, results, u"mul")
 
+    @invocation("operator.imul(%s)")
     def _irepeat(self, node, results):
-        """operator.imul(%s)"""
         return self._handle_rename(node, results, u"imul")
 
+    @invocation("isinstance(%s, collections.Sequence)")
     def _isSequenceType(self, node, results):
-        """isinstance(%s, collections.Sequence)"""
         return self._handle_type2abc(node, results, u"collections", u"Sequence")
 
+    @invocation("isinstance(%s, collections.Mapping)")
     def _isMappingType(self, node, results):
-        """isinstance(%s, collections.Mapping)"""
         return self._handle_type2abc(node, results, u"collections", u"Mapping")
 
+    @invocation("isinstance(%s, numbers.Number)")
     def _isNumberType(self, node, results):
-        """isinstance(%s, numbers.Number)"""
         return self._handle_type2abc(node, results, u"numbers", u"Number")
 
     def _handle_rename(self, node, results, name):
@@ -82,6 +91,6 @@
                 return method
             else:
                 sub = (unicode(results["obj"]),)
-                invocation_str = unicode(method.__doc__) % sub
+                invocation_str = unicode(method.invocation) % sub
                 self.warning(node, u"You should use '%s' here." % invocation_str)
         return None

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_paren.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_paren.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_paren.py	Fri Nov  5 23:50:59 2010
@@ -10,6 +10,8 @@
 
 # XXX This doesn't support nested for loops like [x for x in 1, 2 for x in 1, 2]
 class FixParen(fixer_base.BaseFix):
+    BM_compatible = True
+
     PATTERN = """
         atom< ('[' | '(')
             (listmaker< any

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_print.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_print.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_print.py	Fri Nov  5 23:50:59 2010
@@ -28,6 +28,8 @@
 
 class FixPrint(fixer_base.BaseFix):
 
+    BM_compatible = True
+
     PATTERN = """
               simple_stmt< any* bare='print' any* > | print_stmt
               """

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_raise.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_raise.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_raise.py	Fri Nov  5 23:50:59 2010
@@ -4,6 +4,7 @@
 raise E       -> raise E
 raise E, V    -> raise E(V)
 raise E, V, T -> raise E(V).with_traceback(T)
+raise E, None, T -> raise E.with_traceback(T)
 
 raise (((E, E'), E''), E'''), V -> raise E(V)
 raise "foo", V, T               -> warns about string exceptions
@@ -29,6 +30,7 @@
 
 class FixRaise(fixer_base.BaseFix):
 
+    BM_compatible = True
     PATTERN = """
     raise_stmt< 'raise' exc=any [',' val=any [',' tb=any]] >
     """
@@ -37,8 +39,9 @@
         syms = self.syms
 
         exc = results["exc"].clone()
-        if exc.type is token.STRING:
-            self.cannot_convert(node, "Python 3 does not support string exceptions")
+        if exc.type == token.STRING:
+            msg = "Python 3 does not support string exceptions"
+            self.cannot_convert(node, msg)
             return
 
         # Python 2 supports
@@ -52,7 +55,7 @@
                 # exc.children[1:-1] is the unparenthesized tuple
                 # exc.children[1].children[0] is the first element of the tuple
                 exc = exc.children[1].children[0].clone()
-            exc.prefix = " "
+            exc.prefix = u" "
 
         if "val" not in results:
             # One-argument raise
@@ -71,7 +74,12 @@
             tb = results["tb"].clone()
             tb.prefix = u""
 
-            e = Call(exc, args)
+            e = exc
+            # If there's a traceback and None is passed as the value, then don't
+            # add a call, since the user probably just wants to add a
+            # traceback. See issue #9661.
+            if val.type != token.NAME or val.value != u"None":
+                e = Call(exc, args)
             with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])]
             new = pytree.Node(syms.simple_stmt, [Name(u"raise")] + with_tb)
             new.prefix = node.prefix

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_raw_input.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_raw_input.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_raw_input.py	Fri Nov  5 23:50:59 2010
@@ -7,6 +7,7 @@
 
 class FixRawInput(fixer_base.BaseFix):
 
+    BM_compatible = True
     PATTERN = """
               power< name='raw_input' trailer< '(' [any] ')' > any* >
               """

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_reduce.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_reduce.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_reduce.py	Fri Nov  5 23:50:59 2010
@@ -14,6 +14,9 @@
 
 class FixReduce(fixer_base.BaseFix):
 
+    BM_compatible = True
+    order = "pre"
+
     PATTERN = """
     power< 'reduce'
         trailer< '('

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_renames.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_renames.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_renames.py	Fri Nov  5 23:50:59 2010
@@ -40,6 +40,7 @@
 
 
 class FixRenames(fixer_base.BaseFix):
+    BM_compatible = True
     PATTERN = "|".join(build_pattern())
 
     order = "pre" # Pre-order tree traversal

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_repr.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_repr.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_repr.py	Fri Nov  5 23:50:59 2010
@@ -10,6 +10,7 @@
 
 class FixRepr(fixer_base.BaseFix):
 
+    BM_compatible = True
     PATTERN = """
               atom < '`' expr=any '`' >
               """

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_set_literal.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_set_literal.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_set_literal.py	Fri Nov  5 23:50:59 2010
@@ -11,6 +11,7 @@
 
 class FixSetLiteral(fixer_base.BaseFix):
 
+    BM_compatible = True
     explicit = True
 
     PATTERN = """power< 'set' trailer< '('

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_standarderror.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_standarderror.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_standarderror.py	Fri Nov  5 23:50:59 2010
@@ -9,7 +9,7 @@
 
 
 class FixStandarderror(fixer_base.BaseFix):
-
+    BM_compatible = True
     PATTERN = """
               'StandardError'
               """

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_sys_exc.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_sys_exc.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_sys_exc.py	Fri Nov  5 23:50:59 2010
@@ -14,6 +14,7 @@
 class FixSysExc(fixer_base.BaseFix):
     # This order matches the ordering of sys.exc_info().
     exc_info = [u"exc_type", u"exc_value", u"exc_traceback"]
+    BM_compatible = True
     PATTERN = """
               power< 'sys' trailer< dot='.' attribute=(%s) > >
               """ % '|'.join("'%s'" % e for e in exc_info)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_throw.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_throw.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_throw.py	Fri Nov  5 23:50:59 2010
@@ -14,7 +14,7 @@
 from ..fixer_util import Name, Call, ArgList, Attr, is_tuple
 
 class FixThrow(fixer_base.BaseFix):
-
+    BM_compatible = True
     PATTERN = """
     power< any trailer< '.' 'throw' >
            trailer< '(' args=arglist< exc=any ',' val=any [',' tb=any] > ')' >

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_tuple_params.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_tuple_params.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_tuple_params.py	Fri Nov  5 23:50:59 2010
@@ -29,6 +29,10 @@
            stmt.children[0].type == token.STRING
 
 class FixTupleParams(fixer_base.BaseFix):
+    run_order = 4 #use a lower order since lambda is part of other
+                  #patterns
+    BM_compatible = True
+
     PATTERN = """
               funcdef< 'def' any parameters< '(' args=any ')' >
                        ['->' any] ':' suite=any+ >

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_types.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_types.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_types.py	Fri Nov  5 23:50:59 2010
@@ -52,7 +52,7 @@
 _pats = ["power< 'types' trailer< '.' name='%s' > >" % t for t in _TYPE_MAPPING]
 
 class FixTypes(fixer_base.BaseFix):
-
+    BM_compatible = True
     PATTERN = '|'.join(_pats)
 
     def transform(self, node, results):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_unicode.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_unicode.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_unicode.py	Fri Nov  5 23:50:59 2010
@@ -10,7 +10,7 @@
 _literal_re = re.compile(ur"[uU][rR]?[\'\"]")
 
 class FixUnicode(fixer_base.BaseFix):
-
+    BM_compatible = True
     PATTERN = "STRING | 'unicode' | 'unichr'"
 
     def transform(self, node, results):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_urllib.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_urllib.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_urllib.py	Fri Nov  5 23:50:59 2010
@@ -8,7 +8,7 @@
 from lib2to3.fixes.fix_imports import alternates, FixImports
 from lib2to3 import fixer_base
 from lib2to3.fixer_util import (Name, Comma, FromImport, Newline,
-                                find_indentation)
+                                find_indentation, Node, syms)
 
 MAPPING = {"urllib":  [
                 ("urllib.request",
@@ -121,26 +121,37 @@
             mod_dict = {}
             members = results["members"]
             for member in members:
-                member = member.value
                 # we only care about the actual members
-                if member != u",":
+                if member.type == syms.import_as_name:
+                    as_name = member.children[2].value
+                    member_name = member.children[0].value
+                else:
+                    member_name = member.value
+                    as_name = None
+                if member_name != u",":
                     for change in MAPPING[mod_member.value]:
-                        if member in change[1]:
-                            if change[0] in mod_dict:
-                                mod_dict[change[0]].append(member)
-                            else:
-                                mod_dict[change[0]] = [member]
+                        if member_name in change[1]:
+                            if change[0] not in mod_dict:
                                 modules.append(change[0])
+                            mod_dict.setdefault(change[0], []).append(member)
 
             new_nodes = []
             indentation = find_indentation(node)
             first = True
+            def handle_name(name, prefix):
+                if name.type == syms.import_as_name:
+                    kids = [Name(name.children[0].value, prefix=prefix),
+                            name.children[1].clone(),
+                            name.children[2].clone()]
+                    return [Node(syms.import_as_name, kids)]
+                return [Name(name.value, prefix=prefix)]
             for module in modules:
                 elts = mod_dict[module]
                 names = []
                 for elt in elts[:-1]:
-                    names.extend([Name(elt, prefix=pref), Comma()])
-                names.append(Name(elts[-1], prefix=pref))
+                    names.extend(handle_name(elt, pref))
+                    names.append(Comma())
+                names.extend(handle_name(elts[-1], pref))
                 new = FromImport(module, names)
                 if not first or node.parent.prefix.endswith(indentation):
                     new.prefix = indentation

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_xrange.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_xrange.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_xrange.py	Fri Nov  5 23:50:59 2010
@@ -10,7 +10,7 @@
 
 
 class FixXrange(fixer_base.BaseFix):
-
+    BM_compatible = True
     PATTERN = """
               power<
                  (name='range'|name='xrange') trailer< '(' args=any ')' >

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_xreadlines.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_xreadlines.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_xreadlines.py	Fri Nov  5 23:50:59 2010
@@ -9,6 +9,7 @@
 
 
 class FixXreadlines(fixer_base.BaseFix):
+    BM_compatible = True
     PATTERN = """
     power< call=any+ trailer< '.' 'xreadlines' > trailer< '(' ')' > >
     |

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_zip.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_zip.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/fixes/fix_zip.py	Fri Nov  5 23:50:59 2010
@@ -13,6 +13,7 @@
 
 class FixZip(fixer_base.ConditionalFix):
 
+    BM_compatible = True
     PATTERN = """
     power< 'zip' args=trailer< '(' [any] ')' >
     >

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/patcomp.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/patcomp.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/patcomp.py	Fri Nov  5 23:50:59 2010
@@ -52,14 +52,17 @@
         self.pysyms = pygram.python_symbols
         self.driver = driver.Driver(self.grammar, convert=pattern_convert)
 
-    def compile_pattern(self, input, debug=False):
+    def compile_pattern(self, input, debug=False, with_tree=False):
         """Compiles a pattern string to a nested pytree.*Pattern object."""
         tokens = tokenize_wrapper(input)
         try:
             root = self.driver.parse_tokens(tokens, debug=debug)
-        except parse.ParseError, e:
+        except parse.ParseError as e:
             raise PatternSyntaxError(str(e))
-        return self.compile_node(root)
+        if with_tree:
+            return self.compile_node(root), root
+        else:
+            return self.compile_node(root)
 
     def compile_node(self, node):
         """Compiles a node, recursively.

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/pygram.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/pygram.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/pygram.py	Fri Nov  5 23:50:59 2010
@@ -13,6 +13,8 @@
 
 # The grammar file
 _GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "Grammar.txt")
+_PATTERN_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__),
+                                     "PatternGrammar.txt")
 
 
 class Symbols(object):
@@ -33,3 +35,6 @@
 
 python_grammar_no_print_statement = python_grammar.copy()
 del python_grammar_no_print_statement.keywords["print"]
+
+pattern_grammar = driver.load_grammar(_PATTERN_GRAMMAR_FILE)
+pattern_symbols = Symbols(pattern_grammar)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/pytree.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/pytree.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/pytree.py	Fri Nov  5 23:50:59 2010
@@ -16,7 +16,6 @@
 import warnings
 from StringIO import StringIO
 
-
 HUGE = 0x7FFFFFFF  # maximum repeat count, default max
 
 _type_reprs = {}
@@ -30,7 +29,6 @@
             if type(val) == int: _type_reprs[val] = name
     return _type_reprs.setdefault(type_num, type_num)
 
-
 class Base(object):
 
     """
@@ -47,6 +45,7 @@
     parent = None  # Parent node pointer, or None
     children = ()  # Tuple of subnodes
     was_changed = False
+    was_checked = False
 
     def __new__(cls, *args, **kwds):
         """Constructor that prevents Base from being instantiated."""
@@ -213,6 +212,16 @@
                     return None
                 return self.parent.children[i-1]
 
+    def leaves(self):
+        for child in self.children:
+            for x in child.leaves():
+                yield x
+
+    def depth(self):
+        if self.parent is None:
+            return 0
+        return 1 + self.parent.depth()
+
     def get_suffix(self):
         """
         Return the string immediately following the invocant node. This is
@@ -227,12 +236,14 @@
         def __str__(self):
             return unicode(self).encode("ascii")
 
-
 class Node(Base):
 
     """Concrete implementation for interior nodes."""
 
-    def __init__(self, type, children, context=None, prefix=None):
+    def __init__(self,type, children,
+                 context=None,
+                 prefix=None,
+                 fixers_applied=None):
         """
         Initializer.
 
@@ -249,6 +260,10 @@
             ch.parent = self
         if prefix is not None:
             self.prefix = prefix
+        if fixers_applied:
+            self.fixers_applied = fixers_applied[:]
+        else:
+            self.fixers_applied = None
 
     def __repr__(self):
         """Return a canonical string representation."""
@@ -273,7 +288,8 @@
 
     def clone(self):
         """Return a cloned (deep) copy of self."""
-        return Node(self.type, [ch.clone() for ch in self.children])
+        return Node(self.type, [ch.clone() for ch in self.children],
+                    fixers_applied=self.fixers_applied)
 
     def post_order(self):
         """Return a post-order iterator for the tree."""
@@ -341,7 +357,10 @@
     lineno = 0    # Line where this token starts in the input
     column = 0    # Column where this token tarts in the input
 
-    def __init__(self, type, value, context=None, prefix=None):
+    def __init__(self, type, value,
+                 context=None,
+                 prefix=None,
+                 fixers_applied=[]):
         """
         Initializer.
 
@@ -355,6 +374,7 @@
         self.value = value
         if prefix is not None:
             self._prefix = prefix
+        self.fixers_applied = fixers_applied[:]
 
     def __repr__(self):
         """Return a canonical string representation."""
@@ -380,7 +400,11 @@
     def clone(self):
         """Return a cloned (deep) copy of self."""
         return Leaf(self.type, self.value,
-                    (self.prefix, (self.lineno, self.column)))
+                    (self.prefix, (self.lineno, self.column)),
+                    fixers_applied=self.fixers_applied)
+
+    def leaves(self):
+        yield self
 
     def post_order(self):
         """Return a post-order iterator for the tree."""

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/refactor.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/refactor.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/refactor.py	Fri Nov  5 23:50:59 2010
@@ -24,7 +24,10 @@
 
 # Local imports
 from .pgen2 import driver, tokenize, token
+from .fixer_util import find_root
 from . import pytree, pygram
+from . import btm_utils as bu
+from . import btm_matcher as bm
 
 
 def get_all_fix_names(fixer_pkg, remove_prefix=True):
@@ -201,11 +204,28 @@
                                     logger=self.logger)
         self.pre_order, self.post_order = self.get_fixers()
 
-        self.pre_order_heads = _get_headnode_dict(self.pre_order)
-        self.post_order_heads = _get_headnode_dict(self.post_order)
 
         self.files = []  # List of files that were or should be modified
 
+        self.BM = bm.BottomMatcher()
+        self.bmi_pre_order = [] # Bottom Matcher incompatible fixers
+        self.bmi_post_order = []
+
+        for fixer in chain(self.post_order, self.pre_order):
+            if fixer.BM_compatible:
+                self.BM.add_fixer(fixer)
+                # remove fixers that will be handled by the bottom-up
+                # matcher
+            elif fixer in self.pre_order:
+                self.bmi_pre_order.append(fixer)
+            elif fixer in self.post_order:
+                self.bmi_post_order.append(fixer)
+
+        self.bmi_pre_order_heads = _get_headnode_dict(self.bmi_pre_order)
+        self.bmi_post_order_heads = _get_headnode_dict(self.bmi_post_order)
+
+
+
     def get_fixers(self):
         """Inspects the options to load the requested patterns and handlers.
 
@@ -268,6 +288,7 @@
 
     def refactor(self, items, write=False, doctests_only=False):
         """Refactor a list of files and directories."""
+
         for dir_or_file in items:
             if os.path.isdir(dir_or_file):
                 self.refactor_dir(dir_or_file, write, doctests_only)
@@ -299,7 +320,7 @@
         """
         try:
             f = open(filename, "rb")
-        except IOError, err:
+        except IOError as err:
             self.log_error("Can't open %s: %s", filename, err)
             return None, None
         try:
@@ -348,7 +369,7 @@
             self.driver.grammar = pygram.python_grammar_no_print_statement
         try:
             tree = self.driver.parse_string(data)
-        except Exception, err:
+        except Exception as err:
             self.log_error("Can't parse %s: %s: %s",
                            name, err.__class__.__name__, err)
             return
@@ -378,6 +399,10 @@
     def refactor_tree(self, tree, name):
         """Refactors a parse tree (modifying the tree in place).
 
+        For compatible patterns the bottom matcher module is
+        used. Otherwise the tree is traversed node-to-node for
+        matches.
+
         Args:
             tree: a pytree.Node instance representing the root of the tree
                   to be refactored.
@@ -386,11 +411,65 @@
         Returns:
             True if the tree was modified, False otherwise.
         """
+
         for fixer in chain(self.pre_order, self.post_order):
             fixer.start_tree(tree, name)
 
-        self.traverse_by(self.pre_order_heads, tree.pre_order())
-        self.traverse_by(self.post_order_heads, tree.post_order())
+        #use traditional matching for the incompatible fixers
+        self.traverse_by(self.bmi_pre_order_heads, tree.pre_order())
+        self.traverse_by(self.bmi_post_order_heads, tree.post_order())
+
+        # obtain a set of candidate nodes
+        match_set = self.BM.run(tree.leaves())
+
+        while any(match_set.values()):
+            for fixer in self.BM.fixers:
+                if fixer in match_set and match_set[fixer]:
+                    #sort by depth; apply fixers from bottom(of the AST) to top
+                    match_set[fixer].sort(key=pytree.Base.depth, reverse=True)
+
+                    if fixer.keep_line_order:
+                        #some fixers(eg fix_imports) must be applied
+                        #with the original file's line order
+                        match_set[fixer].sort(key=pytree.Base.get_lineno)
+
+                    for node in list(match_set[fixer]):
+                        if node in match_set[fixer]:
+                            match_set[fixer].remove(node)
+
+                        try:
+                            find_root(node)
+                        except AssertionError:
+                            # this node has been cut off from a
+                            # previous transformation ; skip
+                            continue
+
+                        if node.fixers_applied and fixer in node.fixers_applied:
+                            # do not apply the same fixer again
+                            continue
+
+                        results = fixer.match(node)
+
+                        if results:
+                            new = fixer.transform(node, results)
+                            if new is not None:
+                                node.replace(new)
+                                #new.fixers_applied.append(fixer)
+                                for node in new.post_order():
+                                    # do not apply the fixer again to
+                                    # this or any subnode
+                                    if not node.fixers_applied:
+                                        node.fixers_applied = []
+                                    node.fixers_applied.append(fixer)
+
+                                # update the original match set for
+                                # the added code
+                                new_matches = self.BM.run(new.leaves())
+                                for fxr in new_matches:
+                                    if not fxr in match_set:
+                                        match_set[fxr]=[]
+
+                                    match_set[fxr].extend(new_matches[fxr])
 
         for fixer in chain(self.pre_order, self.post_order):
             fixer.finish_tree(tree, name)
@@ -448,12 +527,12 @@
         """
         try:
             f = _open_with_encoding(filename, "w", encoding=encoding)
-        except os.error, err:
+        except os.error as err:
             self.log_error("Can't create %s: %s", filename, err)
             return
         try:
             f.write(_to_system_newlines(new_text))
-        except os.error, err:
+        except os.error as err:
             self.log_error("Can't write %s: %s", filename, err)
         finally:
             f.close()
@@ -516,7 +595,7 @@
         """
         try:
             tree = self.parse_block(block, lineno, indent)
-        except Exception, err:
+        except Exception as err:
             if self.logger.isEnabledFor(logging.DEBUG):
                 for line in block:
                     self.log_debug("Source: %s", line.rstrip(u"\n"))

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/data/bom.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/data/bom.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/data/bom.py	Fri Nov  5 23:50:59 2010
@@ -1,3 +1,2 @@
 # coding: utf-8
 print "BOM BOOM!"
-

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/test_fixers.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/test_fixers.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/test_fixers.py	Fri Nov  5 23:50:59 2010
@@ -868,6 +868,11 @@
                     raise Exception(5).with_traceback(6) # foo"""
         self.check(b, a)
 
+    def test_None_value(self):
+        b = """raise Exception(5), None, tb"""
+        a = """raise Exception(5).with_traceback(tb)"""
+        self.check(b, a)
+
     def test_tuple_value(self):
         b = """raise Exception, (5, 6, 7)"""
         a = """raise Exception(5, 6, 7)"""
@@ -1812,6 +1817,9 @@
                     b = "from %s import %s as foo_bar" % (old, member)
                     a = "from %s import %s as foo_bar" % (new, member)
                     self.check(b, a)
+                    b = "from %s import %s as blah, %s" % (old, member, member)
+                    a = "from %s import %s as blah, %s" % (new, member, member)
+                    self.check(b, a)
 
     def test_star(self):
         for old in self.modules:

Modified: pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/test_pytree.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/test_pytree.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/lib2to3/tests/test_pytree.py	Fri Nov  5 23:50:59 2010
@@ -178,6 +178,27 @@
         self.assertEqual(str(n1), "foo**bar")
         self.assertTrue(isinstance(n1.children, list))
 
+    def test_leaves(self):
+        l1 = pytree.Leaf(100, "foo")
+        l2 = pytree.Leaf(100, "bar")
+        l3 = pytree.Leaf(100, "fooey")
+        n2 = pytree.Node(1000, [l1, l2])
+        n3 = pytree.Node(1000, [l3])
+        n1 = pytree.Node(1000, [n2, n3])
+
+        self.assertEqual(list(n1.leaves()), [l1, l2, l3])
+
+    def test_depth(self):
+        l1 = pytree.Leaf(100, "foo")
+        l2 = pytree.Leaf(100, "bar")
+        n2 = pytree.Node(1000, [l1, l2])
+        n3 = pytree.Node(1000, [])
+        n1 = pytree.Node(1000, [n2, n3])
+
+        self.assertEqual(l1.depth(), 2)
+        self.assertEqual(n3.depth(), 1)
+        self.assertEqual(n1.depth(), 0)
+
     def test_post_order(self):
         l1 = pytree.Leaf(100, "foo")
         l2 = pytree.Leaf(100, "bar")

Modified: pypy/branch/fast-forward/lib-python/2.7.0/logging/__init__.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/logging/__init__.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/logging/__init__.py	Fri Nov  5 23:50:59 2010
@@ -1211,7 +1211,7 @@
             if filename == _srcfile:
                 f = f.f_back
                 continue
-            rv = (filename, f.f_lineno, co.co_name)
+            rv = (co.co_filename, f.f_lineno, co.co_name)
             break
         return rv
 
@@ -1263,20 +1263,23 @@
         """
         Add the specified handler to this logger.
         """
-        if not (hdlr in self.handlers):
-            self.handlers.append(hdlr)
+        _acquireLock()
+        try:
+            if not (hdlr in self.handlers):
+                self.handlers.append(hdlr)
+        finally:
+            _releaseLock()
 
     def removeHandler(self, hdlr):
         """
         Remove the specified handler from this logger.
         """
-        if hdlr in self.handlers:
-            #hdlr.close()
-            hdlr.acquire()
-            try:
+        _acquireLock()
+        try:
+            if hdlr in self.handlers:
                 self.handlers.remove(hdlr)
-            finally:
-                hdlr.release()
+        finally:
+            _releaseLock()
 
     def callHandlers(self, record):
         """
@@ -1653,9 +1656,15 @@
     a NullHandler and add it to the top-level logger of the library module or
     package.
     """
+    def handle(self, record):
+        pass
+
     def emit(self, record):
         pass
 
+    def createLock(self):
+        self.lock = None
+
 # Warnings integration
 
 _warnings_showwarning = None

Modified: pypy/branch/fast-forward/lib-python/2.7.0/logging/config.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/logging/config.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/logging/config.py	Fri Nov  5 23:50:59 2010
@@ -866,6 +866,7 @@
                 logging._acquireLock()
                 abort = self.abort
                 logging._releaseLock()
+            self.socket.close()
 
     class Server(threading.Thread):
 
@@ -895,8 +896,10 @@
     Stop the listening server which was created with a call to listen().
     """
     global _listener
-    if _listener:
-        logging._acquireLock()
-        _listener.abort = 1
-        _listener = None
+    logging._acquireLock()
+    try:
+        if _listener:
+            _listener.abort = 1
+            _listener = None
+    finally:
         logging._releaseLock()

Modified: pypy/branch/fast-forward/lib-python/2.7.0/mimetypes.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/mimetypes.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/mimetypes.py	Fri Nov  5 23:50:59 2010
@@ -199,9 +199,8 @@
         list of standard types, else to the list of non-standard
         types.
         """
-        fp = open(filename)
-        self.readfp(fp, strict)
-        fp.close()
+        with open(filename) as fp:
+            self.readfp(fp, strict)
 
     def readfp(self, fp, strict=True):
         """
@@ -258,18 +257,19 @@
         with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT,
                              r'MIME\Database\Content Type') as mimedb:
             for ctype in enum_types(mimedb):
-                with _winreg.OpenKey(mimedb, ctype) as key:
-                    try:
-                        suffix, datatype = _winreg.QueryValueEx(key, 'Extension')
-                    except EnvironmentError:
-                        continue
-                    if datatype != _winreg.REG_SZ:
-                        continue
-                    try:
-                        suffix = suffix.encode(default_encoding) # omit in 3.x!
-                    except UnicodeEncodeError:
-                        continue
-                    self.add_type(ctype, suffix, strict)
+                try:
+                    with _winreg.OpenKey(mimedb, ctype) as key:
+                        suffix, datatype = _winreg.QueryValueEx(key,
+                                                                'Extension')
+                except EnvironmentError:
+                    continue
+                if datatype != _winreg.REG_SZ:
+                    continue
+                try:
+                    suffix = suffix.encode(default_encoding) # omit in 3.x!
+                except UnicodeEncodeError:
+                    continue
+                self.add_type(ctype, suffix, strict)
 
 
 def guess_type(url, strict=True):
@@ -356,7 +356,7 @@
         files = knownfiles
     for file in files:
         if os.path.isfile(file):
-            db.readfp(open(file))
+            db.read(file)
     encodings_map = db.encodings_map
     suffix_map = db.suffix_map
     types_map = db.types_map[True]

Modified: pypy/branch/fast-forward/lib-python/2.7.0/multiprocessing/__init__.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/multiprocessing/__init__.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/multiprocessing/__init__.py	Fri Nov  5 23:50:59 2010
@@ -116,7 +116,8 @@
             num = 0
     elif 'bsd' in sys.platform or sys.platform == 'darwin':
         try:
-            num = int(os.popen('sysctl -n hw.ncpu').read())
+            with os.popen('sysctl -n hw.ncpu') as p:
+                num = int(p.read())
         except ValueError:
             num = 0
     else:

Modified: pypy/branch/fast-forward/lib-python/2.7.0/ntpath.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/ntpath.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/ntpath.py	Fri Nov  5 23:50:59 2010
@@ -483,27 +483,38 @@
 supports_unicode_filenames = (hasattr(sys, "getwindowsversion") and
                               sys.getwindowsversion()[3] >= 2)
 
+def _abspath_split(path):
+    abs = abspath(normpath(path))
+    prefix, rest = splitunc(abs)
+    is_unc = bool(prefix)
+    if not is_unc:
+        prefix, rest = splitdrive(abs)
+    return is_unc, prefix, [x for x in rest.split(sep) if x]
+
 def relpath(path, start=curdir):
     """Return a relative version of a path"""
 
     if not path:
         raise ValueError("no path specified")
-    start_list = abspath(start).split(sep)
-    path_list = abspath(path).split(sep)
-    if start_list[0].lower() != path_list[0].lower():
-        unc_path, rest = splitunc(path)
-        unc_start, rest = splitunc(start)
-        if bool(unc_path) ^ bool(unc_start):
-            raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
-                                                                % (path, start))
+
+    start_is_unc, start_prefix, start_list = _abspath_split(start)
+    path_is_unc, path_prefix, path_list = _abspath_split(path)
+
+    if path_is_unc ^ start_is_unc:
+        raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
+                                                            % (path, start))
+    if path_prefix.lower() != start_prefix.lower():
+        if path_is_unc:
+            raise ValueError("path is on UNC root %s, start on UNC root %s"
+                                                % (path_prefix, start_prefix))
         else:
             raise ValueError("path is on drive %s, start on drive %s"
-                                                % (path_list[0], start_list[0]))
+                                                % (path_prefix, start_prefix))
     # Work out how much of the filepath is shared by start and path.
-    for i in range(min(len(start_list), len(path_list))):
-        if start_list[i].lower() != path_list[i].lower():
+    i = 0
+    for e1, e2 in zip(start_list, path_list):
+        if e1.lower() != e2.lower():
             break
-    else:
         i += 1
 
     rel_list = [pardir] * (len(start_list)-i) + path_list[i:]

Modified: pypy/branch/fast-forward/lib-python/2.7.0/posixpath.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/posixpath.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/posixpath.py	Fri Nov  5 23:50:59 2010
@@ -11,6 +11,7 @@
 """
 
 import os
+import sys
 import stat
 import genericpath
 import warnings
@@ -394,7 +395,7 @@
             path = normpath(resolved)
     return path
 
-supports_unicode_filenames = False
+supports_unicode_filenames = (sys.platform == 'darwin')
 
 def relpath(path, start=curdir):
     """Return a relative version of a path"""
@@ -402,8 +403,8 @@
     if not path:
         raise ValueError("no path specified")
 
-    start_list = abspath(start).split(sep)
-    path_list = abspath(path).split(sep)
+    start_list = [x for x in abspath(start).split(sep) if x]
+    path_list = [x for x in abspath(path).split(sep) if x]
 
     # Work out how much of the filepath is shared by start and path.
     i = len(commonprefix([start_list, path_list]))

Modified: pypy/branch/fast-forward/lib-python/2.7.0/runpy.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/runpy.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/runpy.py	Fri Nov  5 23:50:59 2010
@@ -261,7 +261,7 @@
                  _ModifiedArgv0(path_name):
                 mod_globals = temp_module.module.__dict__
                 return _run_code(code, mod_globals, init_globals,
-                                    run_name, fname, loader, pkg_name)
+                                    run_name, fname, loader, pkg_name).copy()
         finally:
             try:
                 sys.path.remove(path_name)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/site.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/site.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/site.py	Fri Nov  5 23:50:59 2010
@@ -76,7 +76,11 @@
 
 
 def makepath(*paths):
-    dir = os.path.abspath(os.path.join(*paths))
+    dir = os.path.join(*paths)
+    try:
+        dir = os.path.abspath(dir)
+    except OSError:
+        pass
     return dir, os.path.normcase(dir)
 
 
@@ -87,8 +91,8 @@
             continue   # don't mess with a PEP 302-supplied __file__
         try:
             m.__file__ = os.path.abspath(m.__file__)
-        except AttributeError:
-            continue
+        except (AttributeError, OSError):
+            pass
 
 
 def removeduppaths():

Modified: pypy/branch/fast-forward/lib-python/2.7.0/smtpd.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/smtpd.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/smtpd.py	Fri Nov  5 23:50:59 2010
@@ -35,7 +35,6 @@
 and if remoteport is not given, then 25 is used.
 """
 
-
 # Overview:
 #
 # This file implements the minimal SMTP protocol as defined in RFC 821.  It
@@ -96,7 +95,6 @@
 COMMASPACE = ', '
 
 
-
 def usage(code, msg=''):
     print >> sys.stderr, __doc__ % globals()
     if msg:
@@ -104,7 +102,6 @@
     sys.exit(code)
 
 
-
 class SMTPChannel(asynchat.async_chat):
     COMMAND = 0
     DATA = 1
@@ -276,7 +273,6 @@
         self.push('354 End data with <CR><LF>.<CR><LF>')
 
 
-
 class SMTPServer(asyncore.dispatcher):
     def __init__(self, localaddr, remoteaddr):
         self._localaddr = localaddr
@@ -299,22 +295,11 @@
                 localaddr, remoteaddr)
 
     def handle_accept(self):
-        try:
-            conn, addr = self.accept()
-        except TypeError:
-            # sometimes accept() might return None
-            return
-        except socket.error, err:
-            # ECONNABORTED might be thrown
-            if err[0] != errno.ECONNABORTED:
-                raise
-            return
-        else:
-            # sometimes addr == None instead of (ip, port)
-            if addr == None:
-                return
-        print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
-        channel = SMTPChannel(self, conn, addr)
+        pair = self.accept()
+        if pair is not None:
+            conn, addr = pair
+            print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
+            channel = SMTPChannel(self, conn, addr)
 
     # API for "doing something useful with the message"
     def process_message(self, peer, mailfrom, rcpttos, data):
@@ -342,7 +327,6 @@
         raise NotImplementedError
 
 
-
 class DebuggingServer(SMTPServer):
     # Do something with the gathered message
     def process_message(self, peer, mailfrom, rcpttos, data):
@@ -358,7 +342,6 @@
         print '------------ END MESSAGE ------------'
 
 
-
 class PureProxy(SMTPServer):
     def process_message(self, peer, mailfrom, rcpttos, data):
         lines = data.split('\n')
@@ -399,7 +382,6 @@
         return refused
 
 
-
 class MailmanProxy(PureProxy):
     def process_message(self, peer, mailfrom, rcpttos, data):
         from cStringIO import StringIO
@@ -478,13 +460,11 @@
                 msg.Enqueue(mlist, torequest=1)
 
 
-
 class Options:
     setuid = 1
     classname = 'PureProxy'
 
 
-
 def parseargs():
     global DEBUGSTREAM
     try:
@@ -541,7 +521,6 @@
     return options
 
 
-
 if __name__ == '__main__':
     options = parseargs()
     # Become nobody

Modified: pypy/branch/fast-forward/lib-python/2.7.0/ssl.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/ssl.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/ssl.py	Fri Nov  5 23:50:59 2010
@@ -184,14 +184,16 @@
                 else:
                     return v
         else:
-            return socket.send(self, data, flags)
+            return self._sock.send(data, flags)
 
-    def sendto(self, data, addr, flags=0):
+    def sendto(self, data, flags_or_addr, addr=None):
         if self._sslobj:
             raise ValueError("sendto not allowed on instances of %s" %
                              self.__class__)
+        elif addr is None:
+            return self._sock.sendto(data, flags_or_addr)
         else:
-            return socket.sendto(self, data, addr, flags)
+            return self._sock.sendto(data, flags_or_addr, addr)
 
     def sendall(self, data, flags=0):
         if self._sslobj:
@@ -216,7 +218,7 @@
                     self.__class__)
             return self.read(buflen)
         else:
-            return socket.recv(self, buflen, flags)
+            return self._sock.recv(buflen, flags)
 
     def recv_into(self, buffer, nbytes=None, flags=0):
         if buffer and (nbytes is None):
@@ -233,21 +235,21 @@
             buffer[:v] = tmp_buffer
             return v
         else:
-            return socket.recv_into(self, buffer, nbytes, flags)
+            return self._sock.recv_into(buffer, nbytes, flags)
 
-    def recvfrom(self, addr, buflen=1024, flags=0):
+    def recvfrom(self, buflen=1024, flags=0):
         if self._sslobj:
             raise ValueError("recvfrom not allowed on instances of %s" %
                              self.__class__)
         else:
-            return socket.recvfrom(self, addr, buflen, flags)
+            return self._sock.recvfrom(buflen, flags)
 
     def recvfrom_into(self, buffer, nbytes=None, flags=0):
         if self._sslobj:
             raise ValueError("recvfrom_into not allowed on instances of %s" %
                              self.__class__)
         else:
-            return socket.recvfrom_into(self, buffer, nbytes, flags)
+            return self._sock.recvfrom_into(buffer, nbytes, flags)
 
     def pending(self):
         if self._sslobj:

Modified: pypy/branch/fast-forward/lib-python/2.7.0/sysconfig.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/sysconfig.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/sysconfig.py	Fri Nov  5 23:50:59 2010
@@ -93,21 +93,28 @@
 _EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
 _CONFIG_VARS = None
 _USER_BASE = None
+
+def _safe_realpath(path):
+    try:
+        return realpath(path)
+    except OSError:
+        return path
+
 if sys.executable:
-    _PROJECT_BASE = os.path.dirname(realpath(sys.executable))
+    _PROJECT_BASE = os.path.dirname(_safe_realpath(sys.executable))
 else:
     # sys.executable can be empty if argv[0] has been changed and Python is
     # unable to retrieve the real program name
-    _PROJECT_BASE = realpath(os.getcwd())
+    _PROJECT_BASE = _safe_realpath(os.getcwd())
 
 if os.name == "nt" and "pcbuild" in _PROJECT_BASE[-8:].lower():
-    _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir))
+    _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir))
 # PC/VS7.1
 if os.name == "nt" and "\\pc\\v" in _PROJECT_BASE[-10:].lower():
-    _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
+    _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
 # PC/AMD64
 if os.name == "nt" and "\\pcbuild\\amd64" in _PROJECT_BASE[-14:].lower():
-    _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
+    _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
 
 def is_python_build():
     for fn in ("Setup.dist", "Setup.local"):
@@ -251,6 +258,11 @@
             else:
                 # bogus variable reference; just drop it since we can't deal
                 del notdone[name]
+    # strip spurious spaces
+    for k, v in done.items():
+        if isinstance(v, str):
+            done[k] = v.strip()
+
     # save the results in the global dictionary
     vars.update(done)
     return vars
@@ -277,7 +289,8 @@
     # load the installed pyconfig.h:
     config_h = get_config_h_filename()
     try:
-        parse_config_h(open(config_h), vars)
+        with open(config_h) as f:
+            parse_config_h(f, vars)
     except IOError, e:
         msg = "invalid Python installation: unable to open %s" % config_h
         if hasattr(e, "strerror"):
@@ -314,7 +327,7 @@
     vars['SO'] = '.pyd'
     vars['EXE'] = '.exe'
     vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT
-    vars['BINDIR'] = os.path.dirname(realpath(sys.executable))
+    vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable))
 
 #
 # public APIs
@@ -434,8 +447,12 @@
         # from a different directory.
         if _PYTHON_BUILD and os.name == "posix":
             base = _PROJECT_BASE
+            try:
+                cwd = os.getcwd()
+            except OSError:
+                cwd = None
             if (not os.path.isabs(_CONFIG_VARS['srcdir']) and
-                base != os.getcwd()):
+                base != cwd):
                 # srcdir is relative and we are not in the same directory
                 # as the executable. Assume executable is in the build
                 # directory and make srcdir absolute.

Modified: pypy/branch/fast-forward/lib-python/2.7.0/tarfile.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/tarfile.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/tarfile.py	Fri Nov  5 23:50:59 2010
@@ -30,13 +30,13 @@
 """Read from and write to tar format archives.
 """
 
-__version__ = "$Revision: 81667 $"
+__version__ = "$Revision: 85213 $"
 # $Source$
 
 version     = "0.9.0"
 __author__  = "Lars Gustäbel (lars at gustaebel.de)"
-__date__    = "$Date: 2010-06-03 14:34:14 +0200 (Thu, 03 Jun 2010) $"
-__cvsid__   = "$Id: tarfile.py 81667 2010-06-03 12:34:14Z lars.gustaebel $"
+__date__    = "$Date: 2010-10-04 17:37:53 +0200 (Mon, 04 Oct 2010) $"
+__cvsid__   = "$Id: tarfile.py 85213 2010-10-04 15:37:53Z lars.gustaebel $"
 __credits__ = "Gustavo Niemeyer, Niels Gustäbel, Richard Townsend."
 
 #---------
@@ -928,8 +928,8 @@
         self.chksum = 0         # header checksum
         self.type = REGTYPE     # member type
         self.linkname = ""      # link name
-        self.uname = "root"     # user name
-        self.gname = "root"     # group name
+        self.uname = ""         # user name
+        self.gname = ""         # group name
         self.devmajor = 0       # device major number
         self.devminor = 0       # device minor number
 
@@ -1112,8 +1112,8 @@
             info.get("type", REGTYPE),
             stn(info.get("linkname", ""), 100),
             stn(info.get("magic", POSIX_MAGIC), 8),
-            stn(info.get("uname", "root"), 32),
-            stn(info.get("gname", "root"), 32),
+            stn(info.get("uname", ""), 32),
+            stn(info.get("gname", ""), 32),
             itn(info.get("devmajor", 0), 8, format),
             itn(info.get("devminor", 0), 8, format),
             stn(info.get("prefix", ""), 155)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/regrtest.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/regrtest.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/regrtest.py	Fri Nov  5 23:50:59 2010
@@ -133,11 +133,7 @@
     decimal -   Test the decimal module against a large suite that
                 verifies compliance with standards.
 
-    compiler -  Test the compiler package by compiling all the source
-                in the standard library and test suite.  This takes
-                a long time.  Enabling this resource also allows
-                test_tokenize to verify round-trip lexing on every
-                file in the test library.
+    cpu -       Used for certain CPU-heavy tests.
 
     subprocess  Run all tests for the subprocess module.
 
@@ -215,7 +211,7 @@
 from test import test_support
 
 RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb',
-                  'decimal', 'compiler', 'subprocess', 'urlfetch', 'gui',
+                  'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui',
                   'xpickle')
 
 TEMPDIR = os.path.abspath(tempfile.gettempdir())
@@ -365,9 +361,6 @@
         usage(2, "-T and -j don't go together!")
     if use_mp and findleaks:
         usage(2, "-l and -j don't go together!")
-    if use_mp and max(sys.flags):
-        # TODO: inherit the environment and the flags
-        print "Warning: flags and environment variables are ignored with -j option"
 
     good = []
     bad = []
@@ -496,6 +489,8 @@
                 )
                 yield (test, args_tuple)
         pending = tests_and_args()
+        opt_args = test_support.args_from_interpreter_flags()
+        base_cmd = [sys.executable] + opt_args + ['-m', 'test.regrtest']
         def work():
             # A worker thread.
             try:
@@ -506,8 +501,7 @@
                         output.put((None, None, None, None))
                         return
                     # -E is needed by some tests, e.g. test_import
-                    popen = Popen([sys.executable, '-E', '-m', 'test.regrtest',
-                                   '--slaveargs', json.dumps(args_tuple)],
+                    popen = Popen(base_cmd + ['--slaveargs', json.dumps(args_tuple)],
                                    stdout=PIPE, stderr=PIPE,
                                    universal_newlines=True,
                                    close_fds=(os.name != 'nt'))
@@ -805,11 +799,12 @@
 
     def get_asyncore_socket_map(self):
         asyncore = sys.modules.get('asyncore')
-        return asyncore and asyncore.socket_map or {}
+        # XXX Making a copy keeps objects alive until __exit__ gets called.
+        return asyncore and asyncore.socket_map.copy() or {}
     def restore_asyncore_socket_map(self, saved_map):
         asyncore = sys.modules.get('asyncore')
         if asyncore is not None:
-            asyncore.socket_map.clear()
+            asyncore.close_all(ignore_all=True)
             asyncore.socket_map.update(saved_map)
 
     def resource_info(self):
@@ -825,9 +820,11 @@
         return self
 
     def __exit__(self, exc_type, exc_val, exc_tb):
+        saved_values = self.saved_values
+        del self.saved_values
         for name, get, restore in self.resource_info():
             current = get()
-            original = self.saved_values[name]
+            original = saved_values.pop(name)
             # Check for changes to the resource's value
             if current != original:
                 self.changed = True
@@ -929,6 +926,10 @@
 def cleanup_test_droppings(testname, verbose):
     import shutil
     import stat
+    import gc
+
+    # First kill any dangling references to open files etc.
+    gc.collect()
 
     # Try to clean up junk commonly left behind.  While tests shouldn't leave
     # any files or directories behind, when a test fails that can be tedious
@@ -1258,6 +1259,7 @@
         test_bsddb3
         test_curses
         test_epoll
+        test_gdb
         test_gdbm
         test_largefile
         test_locale

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_abc.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_abc.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_abc.py	Fri Nov  5 23:50:59 2010
@@ -70,6 +70,13 @@
         self.assertFalse(issubclass(OldstyleClass, A))
         self.assertFalse(issubclass(A, OldstyleClass))
 
+    def test_type_has_no_abstractmethods(self):
+        # type pretends not to have __abstractmethods__.
+        self.assertRaises(AttributeError, getattr, type, "__abstractmethods__")
+        class meta(type):
+            pass
+        self.assertRaises(AttributeError, getattr, meta, "__abstractmethods__")
+
     def test_isinstance_class(self):
         class A:
             __metaclass__ = abc.ABCMeta

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_argparse.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_argparse.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_argparse.py	Fri Nov  5 23:50:59 2010
@@ -1,6 +1,7 @@
 # Author: Steven J. Bethard <steven.bethard at gmail.com>.
 
 import codecs
+import inspect
 import os
 import shutil
 import sys
@@ -27,6 +28,13 @@
             print(obj2)
         super(TestCase, self).assertEqual(obj1, obj2)
 
+    def setUp(self):
+        # The tests assume that line wrapping occurs at 80 columns, but this
+        # behaviour can be overridden by setting the COLUMNS environment
+        # variable.  To ensure that this assumption is true, unset COLUMNS.
+        env = test_support.EnvironmentVarGuard()
+        env.unset("COLUMNS")
+        self.addCleanup(env.__exit__)
 
 
 class TempDirMixin(object):
@@ -460,6 +468,30 @@
         ('/ba +f', NS(f=True, bar=None, baz=42))
     ]
 
+
+class TestOptionalsAlternatePrefixCharsMultipleShortArgs(ParserTestCase):
+    """Verify that Optionals must be called with their defined prefixes"""
+
+    parser_signature = Sig(prefix_chars='+-', add_help=False)
+    argument_signatures = [
+        Sig('-x', action='store_true'),
+        Sig('+y', action='store_true'),
+        Sig('+z', action='store_true'),
+    ]
+    failures = ['-w',
+                '-xyz',
+                '+x',
+                '-y',
+                '+xyz',
+    ]
+    successes = [
+        ('', NS(x=False, y=False, z=False)),
+        ('-x', NS(x=True, y=False, z=False)),
+        ('+y -x', NS(x=True, y=True, z=False)),
+        ('+yz -x', NS(x=True, y=True, z=True)),
+    ]
+
+
 class TestOptionalsShortLong(ParserTestCase):
     """Test a combination of single- and double-dash option strings"""
 
@@ -1726,6 +1758,7 @@
         return parser
 
     def setUp(self):
+        super(TestAddSubparsers, self).setUp()
         self.parser = self._get_parser()
         self.command_help_parser = self._get_parser(subparser_help=True)
 
@@ -1751,6 +1784,28 @@
             NS(foo=True, bar=0.125, w=None, x='c'),
         )
 
+    def test_parse_known_args(self):
+        self.assertEqual(
+            self.parser.parse_known_args('0.5 1 b -w 7'.split()),
+            (NS(foo=False, bar=0.5, w=7, x='b'), []),
+        )
+        self.assertEqual(
+            self.parser.parse_known_args('0.5 -p 1 b -w 7'.split()),
+            (NS(foo=False, bar=0.5, w=7, x='b'), ['-p']),
+        )
+        self.assertEqual(
+            self.parser.parse_known_args('0.5 1 b -w 7 -p'.split()),
+            (NS(foo=False, bar=0.5, w=7, x='b'), ['-p']),
+        )
+        self.assertEqual(
+            self.parser.parse_known_args('0.5 1 b -q -rs -w 7'.split()),
+            (NS(foo=False, bar=0.5, w=7, x='b'), ['-q', '-rs']),
+        )
+        self.assertEqual(
+            self.parser.parse_known_args('0.5 -W 1 b -X Y -w 7 Z'.split()),
+            (NS(foo=False, bar=0.5, w=7, x='b'), ['-W', '-X', 'Y', 'Z']),
+        )
+
     def test_dest(self):
         parser = ErrorRaisingArgumentParser()
         parser.add_argument('--foo', action='store_true')
@@ -1953,6 +2008,7 @@
         self.assertRaises(ArgumentParserError, *args, **kwargs)
 
     def setUp(self):
+        super(TestParentParsers, self).setUp()
         self.wxyz_parent = ErrorRaisingArgumentParser(add_help=False)
         self.wxyz_parent.add_argument('--w')
         x_group = self.wxyz_parent.add_argument_group('x')
@@ -2140,6 +2196,25 @@
         raises(ValueError, add_argument, 'bar', nargs=1)
         raises(ValueError, add_argument, 'bar', nargs=argparse.PARSER)
 
+    def test_help(self):
+        parser = ErrorRaisingArgumentParser(prog='PROG')
+        group1 = parser.add_mutually_exclusive_group()
+        group1.add_argument('--foo', action='store_true')
+        group1.add_argument('--bar', action='store_false')
+        group2 = parser.add_mutually_exclusive_group()
+        group2.add_argument('--soup', action='store_true')
+        group2.add_argument('--nuts', action='store_false')
+        expected = '''\
+            usage: PROG [-h] [--foo | --bar] [--soup | --nuts]
+
+            optional arguments:
+              -h, --help  show this help message and exit
+              --foo
+              --bar
+              --soup
+              --nuts
+              '''
+        self.assertEqual(parser.format_help(), textwrap.dedent(expected))
 
 class MEMixin(object):
 
@@ -4171,7 +4246,8 @@
     def _test_module_encoding(self, path):
         path, _ = os.path.splitext(path)
         path += ".py"
-        codecs.open(path, 'r', 'utf8').read()
+        with codecs.open(path, 'r', 'utf8') as f:
+            f.read()
 
     def test_argparse_module_encoding(self):
         self._test_module_encoding(argparse.__file__)
@@ -4246,6 +4322,15 @@
         for name in argparse.__all__:
             self.assertTrue(hasattr(argparse, name))
 
+    def test_all_exports_everything_but_modules(self):
+        items = [
+            name
+            for name, value in vars(argparse).items()
+            if not name.startswith("_")
+            if not inspect.ismodule(value)
+        ]
+        self.assertEqual(sorted(items), sorted(argparse.__all__))
+
 def test_main():
     # silence warnings about version argument - these are expected
     with test_support.check_warnings(

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_bz2.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_bz2.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_bz2.py	Fri Nov  5 23:50:59 2010
@@ -54,68 +54,68 @@
             os.unlink(self.filename)
 
     def createTempFile(self, crlf=0):
-        f = open(self.filename, "wb")
-        if crlf:
-            data = self.DATA_CRLF
-        else:
-            data = self.DATA
-        f.write(data)
-        f.close()
+        with open(self.filename, "wb") as f:
+            if crlf:
+                data = self.DATA_CRLF
+            else:
+                data = self.DATA
+            f.write(data)
 
     def testRead(self):
         # "Test BZ2File.read()"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        self.assertRaises(TypeError, bz2f.read, None)
-        self.assertEqual(bz2f.read(), self.TEXT)
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            self.assertRaises(TypeError, bz2f.read, None)
+            self.assertEqual(bz2f.read(), self.TEXT)
+
+    def testRead0(self):
+        # Test BBZ2File.read(0)"
+        self.createTempFile()
+        with BZ2File(self.filename) as bz2f:
+            self.assertRaises(TypeError, bz2f.read, None)
+            self.assertEqual(bz2f.read(0), "")
 
     def testReadChunk10(self):
         # "Test BZ2File.read() in chunks of 10 bytes"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        text = ''
-        while 1:
-            str = bz2f.read(10)
-            if not str:
-                break
-            text += str
-        self.assertEqual(text, text)
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            text = ''
+            while 1:
+                str = bz2f.read(10)
+                if not str:
+                    break
+                text += str
+            self.assertEqual(text, text)
 
     def testRead100(self):
         # "Test BZ2File.read(100)"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        self.assertEqual(bz2f.read(100), self.TEXT[:100])
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            self.assertEqual(bz2f.read(100), self.TEXT[:100])
 
     def testReadLine(self):
         # "Test BZ2File.readline()"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        self.assertRaises(TypeError, bz2f.readline, None)
-        sio = StringIO(self.TEXT)
-        for line in sio.readlines():
-            self.assertEqual(bz2f.readline(), line)
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            self.assertRaises(TypeError, bz2f.readline, None)
+            sio = StringIO(self.TEXT)
+            for line in sio.readlines():
+                self.assertEqual(bz2f.readline(), line)
 
     def testReadLines(self):
         # "Test BZ2File.readlines()"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        self.assertRaises(TypeError, bz2f.readlines, None)
-        sio = StringIO(self.TEXT)
-        self.assertEqual(bz2f.readlines(), sio.readlines())
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            self.assertRaises(TypeError, bz2f.readlines, None)
+            sio = StringIO(self.TEXT)
+            self.assertEqual(bz2f.readlines(), sio.readlines())
 
     def testIterator(self):
         # "Test iter(BZ2File)"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        sio = StringIO(self.TEXT)
-        self.assertEqual(list(iter(bz2f)), sio.readlines())
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            sio = StringIO(self.TEXT)
+            self.assertEqual(list(iter(bz2f)), sio.readlines())
 
     def testClosedIteratorDeadlock(self):
         # "Test that iteration on a closed bz2file releases the lock."
@@ -154,104 +154,91 @@
 
     def testWrite(self):
         # "Test BZ2File.write()"
-        bz2f = BZ2File(self.filename, "w")
-        self.assertRaises(TypeError, bz2f.write)
-        bz2f.write(self.TEXT)
-        bz2f.close()
-        f = open(self.filename, 'rb')
-        self.assertEqual(self.decompress(f.read()), self.TEXT)
-        f.close()
+        with BZ2File(self.filename, "w") as bz2f:
+            self.assertRaises(TypeError, bz2f.write)
+            bz2f.write(self.TEXT)
+        with open(self.filename, 'rb') as f:
+            self.assertEqual(self.decompress(f.read()), self.TEXT)
 
     def testWriteChunks10(self):
         # "Test BZ2File.write() with chunks of 10 bytes"
-        bz2f = BZ2File(self.filename, "w")
-        n = 0
-        while 1:
-            str = self.TEXT[n*10:(n+1)*10]
-            if not str:
-                break
-            bz2f.write(str)
-            n += 1
-        bz2f.close()
-        f = open(self.filename, 'rb')
-        self.assertEqual(self.decompress(f.read()), self.TEXT)
-        f.close()
+        with BZ2File(self.filename, "w") as bz2f:
+            n = 0
+            while 1:
+                str = self.TEXT[n*10:(n+1)*10]
+                if not str:
+                    break
+                bz2f.write(str)
+                n += 1
+        with open(self.filename, 'rb') as f:
+            self.assertEqual(self.decompress(f.read()), self.TEXT)
 
     def testWriteLines(self):
         # "Test BZ2File.writelines()"
-        bz2f = BZ2File(self.filename, "w")
-        self.assertRaises(TypeError, bz2f.writelines)
-        sio = StringIO(self.TEXT)
-        bz2f.writelines(sio.readlines())
-        bz2f.close()
+        with BZ2File(self.filename, "w") as bz2f:
+            self.assertRaises(TypeError, bz2f.writelines)
+            sio = StringIO(self.TEXT)
+            bz2f.writelines(sio.readlines())
         # patch #1535500
         self.assertRaises(ValueError, bz2f.writelines, ["a"])
-        f = open(self.filename, 'rb')
-        self.assertEqual(self.decompress(f.read()), self.TEXT)
-        f.close()
+        with open(self.filename, 'rb') as f:
+            self.assertEqual(self.decompress(f.read()), self.TEXT)
 
     def testWriteMethodsOnReadOnlyFile(self):
-        bz2f = BZ2File(self.filename, "w")
-        bz2f.write("abc")
-        bz2f.close()
+        with BZ2File(self.filename, "w") as bz2f:
+            bz2f.write("abc")
 
-        bz2f = BZ2File(self.filename, "r")
-        self.assertRaises(IOError, bz2f.write, "a")
-        self.assertRaises(IOError, bz2f.writelines, ["a"])
+        with BZ2File(self.filename, "r") as bz2f:
+            self.assertRaises(IOError, bz2f.write, "a")
+            self.assertRaises(IOError, bz2f.writelines, ["a"])
 
     def testSeekForward(self):
         # "Test BZ2File.seek(150, 0)"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        self.assertRaises(TypeError, bz2f.seek)
-        bz2f.seek(150)
-        self.assertEqual(bz2f.read(), self.TEXT[150:])
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            self.assertRaises(TypeError, bz2f.seek)
+            bz2f.seek(150)
+            self.assertEqual(bz2f.read(), self.TEXT[150:])
 
     def testSeekBackwards(self):
         # "Test BZ2File.seek(-150, 1)"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        bz2f.read(500)
-        bz2f.seek(-150, 1)
-        self.assertEqual(bz2f.read(), self.TEXT[500-150:])
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            bz2f.read(500)
+            bz2f.seek(-150, 1)
+            self.assertEqual(bz2f.read(), self.TEXT[500-150:])
 
     def testSeekBackwardsFromEnd(self):
         # "Test BZ2File.seek(-150, 2)"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        bz2f.seek(-150, 2)
-        self.assertEqual(bz2f.read(), self.TEXT[len(self.TEXT)-150:])
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            bz2f.seek(-150, 2)
+            self.assertEqual(bz2f.read(), self.TEXT[len(self.TEXT)-150:])
 
     def testSeekPostEnd(self):
         # "Test BZ2File.seek(150000)"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        bz2f.seek(150000)
-        self.assertEqual(bz2f.tell(), len(self.TEXT))
-        self.assertEqual(bz2f.read(), "")
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            bz2f.seek(150000)
+            self.assertEqual(bz2f.tell(), len(self.TEXT))
+            self.assertEqual(bz2f.read(), "")
 
     def testSeekPostEndTwice(self):
         # "Test BZ2File.seek(150000) twice"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        bz2f.seek(150000)
-        bz2f.seek(150000)
-        self.assertEqual(bz2f.tell(), len(self.TEXT))
-        self.assertEqual(bz2f.read(), "")
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            bz2f.seek(150000)
+            bz2f.seek(150000)
+            self.assertEqual(bz2f.tell(), len(self.TEXT))
+            self.assertEqual(bz2f.read(), "")
 
     def testSeekPreStart(self):
         # "Test BZ2File.seek(-150, 0)"
         self.createTempFile()
-        bz2f = BZ2File(self.filename)
-        bz2f.seek(-150)
-        self.assertEqual(bz2f.tell(), 0)
-        self.assertEqual(bz2f.read(), self.TEXT)
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            bz2f.seek(-150)
+            self.assertEqual(bz2f.tell(), 0)
+            self.assertEqual(bz2f.read(), self.TEXT)
 
     def testOpenDel(self):
         # "Test opening and deleting a file many times"
@@ -277,16 +264,13 @@
     def testBug1191043(self):
         # readlines() for files containing no newline
         data = 'BZh91AY&SY\xd9b\x89]\x00\x00\x00\x03\x80\x04\x00\x02\x00\x0c\x00 \x00!\x9ah3M\x13<]\xc9\x14\xe1BCe\x8a%t'
-        f = open(self.filename, "wb")
-        f.write(data)
-        f.close()
-        bz2f = BZ2File(self.filename)
-        lines = bz2f.readlines()
-        bz2f.close()
+        with open(self.filename, "wb") as f:
+            f.write(data)
+        with BZ2File(self.filename) as bz2f:
+            lines = bz2f.readlines()
         self.assertEqual(lines, ['Test'])
-        bz2f = BZ2File(self.filename)
-        xlines = list(bz2f.xreadlines())
-        bz2f.close()
+        with BZ2File(self.filename) as bz2f:
+            xlines = list(bz2f.readlines())
         self.assertEqual(xlines, ['Test'])
 
     def testContextProtocol(self):
@@ -316,8 +300,7 @@
         # Using a BZ2File from several threads doesn't deadlock (issue #7205).
         data = "1" * 2**20
         nthreads = 10
-        f = bz2.BZ2File(self.filename, 'wb')
-        try:
+        with bz2.BZ2File(self.filename, 'wb') as f:
             def comp():
                 for i in range(5):
                     f.write(data)
@@ -326,27 +309,19 @@
                 t.start()
             for t in threads:
                 t.join()
-        finally:
-            f.close()
 
     def testMixedIterationReads(self):
         # Issue #8397: mixed iteration and reads should be forbidden.
-        f = bz2.BZ2File(self.filename, 'wb')
-        try:
+        with bz2.BZ2File(self.filename, 'wb') as f:
             # The internal buffer size is hard-wired to 8192 bytes, we must
             # write out more than that for the test to stop half through
             # the buffer.
             f.write(self.TEXT * 100)
-        finally:
-            f.close()
-        f = bz2.BZ2File(self.filename, 'rb')
-        try:
+        with bz2.BZ2File(self.filename, 'rb') as f:
             next(f)
             self.assertRaises(ValueError, f.read)
             self.assertRaises(ValueError, f.readline)
             self.assertRaises(ValueError, f.readlines)
-        finally:
-            f.close()
 
 class BZ2CompressorTest(BaseTest):
     def testCompress(self):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_class.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_class.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_class.py	Fri Nov  5 23:50:59 2010
@@ -513,7 +513,7 @@
 
         callLst[:] = []
         as_long = long(mixIntAndLong)
-        self.assertEquals(type(as_long), int)
+        self.assertEquals(type(as_long), long)
         self.assertEquals(as_long, 64)
         self.assertCallStack([('__long__', (mixIntAndLong,))])
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_collections.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_collections.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_collections.py	Fri Nov  5 23:50:59 2010
@@ -926,6 +926,13 @@
         self.assertEqual(eval(repr(od)), od)
         self.assertEqual(repr(OrderedDict()), "OrderedDict()")
 
+    def test_repr_recursive(self):
+        # See issue #9826
+        od = OrderedDict.fromkeys('abc')
+        od['x'] = od
+        self.assertEqual(repr(od),
+            "OrderedDict([('a', None), ('b', None), ('c', None), ('x', ...)])")
+
     def test_setdefault(self):
         pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
         shuffle(pairs)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_compiler.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_compiler.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_compiler.py	Fri Nov  5 23:50:59 2010
@@ -310,7 +310,7 @@
 
 def test_main():
     global TEST_ALL
-    TEST_ALL = test.test_support.is_resource_enabled("compiler")
+    TEST_ALL = test.test_support.is_resource_enabled("cpu")
     test.test_support.run_unittest(CompilerTest)
 
 if __name__ == "__main__":

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_decimal.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_decimal.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_decimal.py	Fri Nov  5 23:50:59 2010
@@ -224,14 +224,15 @@
         if skip_expected:
             raise unittest.SkipTest
             return
-        for line in open(file):
-            line = line.replace('\r\n', '').replace('\n', '')
-            #print line
-            try:
-                t = self.eval_line(line)
-            except DecimalException, exception:
-                #Exception raised where there shoudn't have been one.
-                self.fail('Exception "'+exception.__class__.__name__ + '" raised on line '+line)
+        with open(file) as f:
+            for line in f:
+                line = line.replace('\r\n', '').replace('\n', '')
+                #print line
+                try:
+                    t = self.eval_line(line)
+                except DecimalException as exception:
+                    #Exception raised where there shoudn't have been one.
+                    self.fail('Exception "'+exception.__class__.__name__ + '" raised on line '+line)
 
         return
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_doctest.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_doctest.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_doctest.py	Fri Nov  5 23:50:59 2010
@@ -1721,10 +1721,13 @@
 
       >>> doc = '''
       ... >>> x = 42
+      ... >>> raise Exception('clé')
+      ... Traceback (most recent call last):
+      ... Exception: clé
       ... >>> import pdb; pdb.set_trace()
       ... '''
       >>> parser = doctest.DocTestParser()
-      >>> test = parser.get_doctest(doc, {}, "foo", "foo.py", 0)
+      >>> test = parser.get_doctest(doc, {}, "foo-bär at baz", "foo-bär at baz.py", 0)
       >>> runner = doctest.DocTestRunner(verbose=False)
 
     To demonstrate this, we'll create a fake standard input that
@@ -1740,12 +1743,12 @@
       >>> try: runner.run(test)
       ... finally: sys.stdin = real_stdin
       --Return--
-      > <doctest foo[1]>(1)<module>()->None
+      > <doctest foo-bär at baz[2]>(1)<module>()->None
       -> import pdb; pdb.set_trace()
       (Pdb) print x
       42
       (Pdb) continue
-      TestResults(failed=0, attempted=2)
+      TestResults(failed=0, attempted=3)
 
       You can also put pdb.set_trace in a function called from a test:
 
@@ -1757,7 +1760,7 @@
       ... >>> x=1
       ... >>> calls_set_trace()
       ... '''
-      >>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0)
+      >>> test = parser.get_doctest(doc, globals(), "foo-bär at baz", "foo-bär at baz.py", 0)
       >>> real_stdin = sys.stdin
       >>> sys.stdin = _FakeInput([
       ...    'print y',  # print data defined in the function
@@ -1776,7 +1779,7 @@
       (Pdb) print y
       2
       (Pdb) up
-      > <doctest foo[1]>(1)<module>()
+      > <doctest foo-bär at baz[1]>(1)<module>()
       -> calls_set_trace()
       (Pdb) print x
       1
@@ -1794,7 +1797,7 @@
       ... ...     import pdb; pdb.set_trace()
       ... >>> f(3)
       ... '''
-      >>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0)
+      >>> test = parser.get_doctest(doc, globals(), "foo-bär at baz", "foo-bär at baz.py", 0)
       >>> real_stdin = sys.stdin
       >>> sys.stdin = _FakeInput([
       ...    'list',     # list source from example 2
@@ -1808,7 +1811,7 @@
       ... finally: sys.stdin = real_stdin
       ... # doctest: +NORMALIZE_WHITESPACE
       --Return--
-      > <doctest foo[1]>(3)g()->None
+      > <doctest foo-bär at baz[1]>(3)g()->None
       -> import pdb; pdb.set_trace()
       (Pdb) list
         1     def g(x):
@@ -1817,7 +1820,7 @@
       [EOF]
       (Pdb) next
       --Return--
-      > <doctest foo[0]>(2)f()->None
+      > <doctest foo-bär at baz[0]>(2)f()->None
       -> g(x*2)
       (Pdb) list
         1     def f(x):
@@ -1825,14 +1828,14 @@
       [EOF]
       (Pdb) next
       --Return--
-      > <doctest foo[2]>(1)<module>()->None
+      > <doctest foo-bär at baz[2]>(1)<module>()->None
       -> f(3)
       (Pdb) list
         1  -> f(3)
       [EOF]
       (Pdb) continue
       **********************************************************************
-      File "foo.py", line 7, in foo
+      File "foo-bär at baz.py", line 7, in foo-bär at baz
       Failed example:
           f(3)
       Expected nothing
@@ -1866,7 +1869,7 @@
     ... '''
     >>> parser = doctest.DocTestParser()
     >>> runner = doctest.DocTestRunner(verbose=False)
-    >>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0)
+    >>> test = parser.get_doctest(doc, globals(), "foo-bär at baz", "foo-bär at baz.py", 0)
     >>> real_stdin = sys.stdin
     >>> sys.stdin = _FakeInput([
     ...    'print y',  # print data defined in the function
@@ -1918,7 +1921,7 @@
     (Pdb) print y
     1
     (Pdb) up
-    > <doctest foo[1]>(1)<module>()
+    > <doctest foo-bär at baz[1]>(1)<module>()
     -> calls_set_trace()
     (Pdb) print foo
     *** NameError: name 'foo' is not defined

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_file2k.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_file2k.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_file2k.py	Fri Nov  5 23:50:59 2010
@@ -135,6 +135,14 @@
     def testReadWhenWriting(self):
         self.assertRaises(IOError, self.f.read)
 
+    def testNastyWritelinesGenerator(self):
+        def nasty():
+            for i in range(5):
+                if i == 3:
+                    self.f.close()
+                yield str(i)
+        self.assertRaises(ValueError, self.f.writelines, nasty())
+
     def testIssue5677(self):
         # Remark: Do not perform more than one test per open file,
         # since that does NOT catch the readline error on Windows.
@@ -172,7 +180,7 @@
 class OtherFileTests(unittest.TestCase):
 
     def testOpenDir(self):
-        this_dir = os.path.dirname(__file__)
+        this_dir = os.path.dirname(__file__) or os.curdir
         for mode in (None, "w"):
             try:
                 if mode:

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_fileio.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_fileio.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_fileio.py	Fri Nov  5 23:50:59 2010
@@ -263,7 +263,6 @@
                     # OS'es that don't support /dev/tty.
                     pass
                 else:
-                    f = _FileIO("/dev/tty", "a")
                     self.assertEquals(f.readable(), False)
                     self.assertEquals(f.writable(), True)
                     if sys.platform != "darwin" and \
@@ -342,6 +341,7 @@
         f.truncate(15)
         self.assertEqual(f.tell(), 5)
         self.assertEqual(f.seek(0, os.SEEK_END), 15)
+        f.close()
 
     def testTruncateOnWindows(self):
         def bug801631():

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_float.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_float.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_float.py	Fri Nov  5 23:50:59 2010
@@ -540,19 +540,20 @@
 
     @requires_IEEE_754
     def test_format_testfile(self):
-        for line in open(format_testfile):
-            if line.startswith('--'):
-                continue
-            line = line.strip()
-            if not line:
-                continue
-
-            lhs, rhs = map(str.strip, line.split('->'))
-            fmt, arg = lhs.split()
-            arg = float(arg)
-            self.assertEqual(fmt % arg, rhs)
-            if not math.isnan(arg) and copysign(1.0, arg) > 0.0:
-                self.assertEqual(fmt % -arg, '-' + rhs)
+        with open(format_testfile) as testfile:
+            for line in open(format_testfile):
+                if line.startswith('--'):
+                    continue
+                line = line.strip()
+                if not line:
+                    continue
+
+                lhs, rhs = map(str.strip, line.split('->'))
+                fmt, arg = lhs.split()
+                arg = float(arg)
+                self.assertEqual(fmt % arg, rhs)
+                if not math.isnan(arg) and copysign(1.0, arg) > 0.0:
+                    self.assertEqual(fmt % -arg, '-' + rhs)
 
     def test_issue5864(self):
         self.assertEquals(format(123.456, '.4'), '123.5')

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_ftplib.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_ftplib.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_ftplib.py	Fri Nov  5 23:50:59 2010
@@ -99,7 +99,7 @@
         addr = map(int, arg.split(','))
         ip = '%d.%d.%d.%d' %tuple(addr[:4])
         port = (addr[4] * 256) + addr[5]
-        s = socket.create_connection((ip, port), timeout=2)
+        s = socket.create_connection((ip, port), timeout=10)
         self.dtp = self.dtp_handler(s, baseclass=self)
         self.push('200 active data connection established')
 
@@ -107,7 +107,7 @@
         sock = socket.socket()
         sock.bind((self.socket.getsockname()[0], 0))
         sock.listen(5)
-        sock.settimeout(2)
+        sock.settimeout(10)
         ip, port = sock.getsockname()[:2]
         ip = ip.replace('.', ',')
         p1, p2 = divmod(port, 256)
@@ -118,7 +118,7 @@
     def cmd_eprt(self, arg):
         af, ip, port = arg.split(arg[0])[1:-1]
         port = int(port)
-        s = socket.create_connection((ip, port), timeout=2)
+        s = socket.create_connection((ip, port), timeout=10)
         self.dtp = self.dtp_handler(s, baseclass=self)
         self.push('200 active data connection established')
 
@@ -126,7 +126,7 @@
         sock = socket.socket(socket.AF_INET6)
         sock.bind((self.socket.getsockname()[0], 0))
         sock.listen(5)
-        sock.settimeout(2)
+        sock.settimeout(10)
         port = sock.getsockname()[1]
         self.push('229 entering extended passive mode (|||%d|)' %port)
         conn, addr = sock.accept()
@@ -403,7 +403,7 @@
     def setUp(self):
         self.server = DummyFTPServer((HOST, 0))
         self.server.start()
-        self.client = ftplib.FTP(timeout=2)
+        self.client = ftplib.FTP(timeout=10)
         self.client.connect(self.server.host, self.server.port)
 
     def tearDown(self):
@@ -545,7 +545,7 @@
 
     def test_makepasv(self):
         host, port = self.client.makepasv()
-        conn = socket.create_connection((host, port), 2)
+        conn = socket.create_connection((host, port), 10)
         conn.close()
         # IPv4 is in use, just make sure send_epsv has not been used
         self.assertEqual(self.server.handler.last_received_cmd, 'pasv')
@@ -572,7 +572,7 @@
 
     def test_makepasv(self):
         host, port = self.client.makepasv()
-        conn = socket.create_connection((host, port), 2)
+        conn = socket.create_connection((host, port), 10)
         conn.close()
         self.assertEqual(self.server.handler.last_received_cmd, 'epsv')
 
@@ -595,7 +595,7 @@
     def setUp(self):
         self.server = DummyTLS_FTPServer((HOST, 0))
         self.server.start()
-        self.client = ftplib.FTP_TLS(timeout=2)
+        self.client = ftplib.FTP_TLS(timeout=10)
         self.client.connect(self.server.host, self.server.port)
         # enable TLS
         self.client.auth()
@@ -608,7 +608,7 @@
     def setUp(self):
         self.server = DummyTLS_FTPServer((HOST, 0))
         self.server.start()
-        self.client = ftplib.FTP_TLS(timeout=2)
+        self.client = ftplib.FTP_TLS(timeout=10)
         self.client.connect(self.server.host, self.server.port)
 
     def tearDown(self):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_gettext.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_gettext.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_gettext.py	Fri Nov  5 23:50:59 2010
@@ -334,6 +334,37 @@
            'John Doe <jdoe at example.com>\nJane Foobar <jfoobar at example.com>')
 
 
+class DummyGNUTranslations(gettext.GNUTranslations):
+    def foo(self):
+        return 'foo'
+
+
+class GettextCacheTestCase(GettextBaseTest):
+    def test_cache(self):
+        self.localedir = os.curdir
+        self.mofile = MOFILE
+
+        self.assertEqual(len(gettext._translations), 0)
+
+        t = gettext.translation('gettext', self.localedir)
+
+        self.assertEqual(len(gettext._translations), 1)
+
+        t = gettext.translation('gettext', self.localedir,
+                                class_=DummyGNUTranslations)
+
+        self.assertEqual(len(gettext._translations), 2)
+        self.assertEqual(t.__class__, DummyGNUTranslations)
+
+        # Calling it again doesn't add to the cache
+
+        t = gettext.translation('gettext', self.localedir,
+                                class_=DummyGNUTranslations)
+
+        self.assertEqual(len(gettext._translations), 2)
+        self.assertEqual(t.__class__, DummyGNUTranslations)
+
+
 def test_main():
     test_support.run_unittest(__name__)
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_gzip.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_gzip.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_gzip.py	Fri Nov  5 23:50:59 2010
@@ -33,14 +33,15 @@
 
 
     def test_write(self):
-        f = gzip.GzipFile(self.filename, 'wb') ; f.write(data1 * 50)
+        with gzip.GzipFile(self.filename, 'wb') as f:
+            f.write(data1 * 50)
 
-        # Try flush and fileno.
-        f.flush()
-        f.fileno()
-        if hasattr(os, 'fsync'):
-            os.fsync(f.fileno())
-        f.close()
+            # Try flush and fileno.
+            f.flush()
+            f.fileno()
+            if hasattr(os, 'fsync'):
+                os.fsync(f.fileno())
+            f.close()
 
         # Test multiple close() calls.
         f.close()
@@ -48,37 +49,59 @@
     def test_read(self):
         self.test_write()
         # Try reading.
-        f = gzip.GzipFile(self.filename, 'r') ; d = f.read() ; f.close()
+        with gzip.GzipFile(self.filename, 'r') as f:
+            d = f.read()
         self.assertEqual(d, data1*50)
 
+    def test_io_on_closed_object(self):
+        # Test that I/O operations on closed GzipFile objects raise a
+        # ValueError, just like the corresponding functions on file objects.
+
+        # Write to a file, open it for reading, then close it.
+        self.test_write()
+        f = gzip.GzipFile(self.filename, 'r')
+        f.close()
+        with self.assertRaises(ValueError):
+            f.read(1)
+        with self.assertRaises(ValueError):
+            f.seek(0)
+        with self.assertRaises(ValueError):
+            f.tell()
+        # Open the file for writing, then close it.
+        f = gzip.GzipFile(self.filename, 'w')
+        f.close()
+        with self.assertRaises(ValueError):
+            f.write('')
+        with self.assertRaises(ValueError):
+            f.flush()
+
     def test_append(self):
         self.test_write()
         # Append to the previous file
-        f = gzip.GzipFile(self.filename, 'ab') ; f.write(data2 * 15) ; f.close()
+        with gzip.GzipFile(self.filename, 'ab') as f:
+            f.write(data2 * 15)
 
-        f = gzip.GzipFile(self.filename, 'rb') ; d = f.read() ; f.close()
+        with gzip.GzipFile(self.filename, 'rb') as f:
+            d = f.read()
         self.assertEqual(d, (data1*50) + (data2*15))
 
     def test_many_append(self):
         # Bug #1074261 was triggered when reading a file that contained
         # many, many members.  Create such a file and verify that reading it
         # works.
-        f = gzip.open(self.filename, 'wb', 9)
-        f.write('a')
-        f.close()
-        for i in range(0,200):
-            f = gzip.open(self.filename, "ab", 9) # append
+        with gzip.open(self.filename, 'wb', 9) as f:
             f.write('a')
-            f.close()
+        for i in range(0, 200):
+            with gzip.open(self.filename, "ab", 9) as f: # append
+                f.write('a')
 
         # Try reading the file
-        zgfile = gzip.open(self.filename, "rb")
-        contents = ""
-        while 1:
-            ztxt = zgfile.read(8192)
-            contents += ztxt
-            if not ztxt: break
-        zgfile.close()
+        with gzip.open(self.filename, "rb") as zgfile:
+            contents = ""
+            while 1:
+                ztxt = zgfile.read(8192)
+                contents += ztxt
+                if not ztxt: break
         self.assertEquals(contents, 'a'*201)
 
     def test_buffered_reader(self):
@@ -86,9 +109,9 @@
         # performance.
         self.test_write()
 
-        f = gzip.GzipFile(self.filename, 'rb')
-        with io.BufferedReader(f) as r:
-            lines = [line for line in r]
+        with gzip.GzipFile(self.filename, 'rb') as f:
+            with io.BufferedReader(f) as r:
+                lines = [line for line in r]
 
         self.assertEqual(lines, 50 * data1.splitlines(True))
 
@@ -96,140 +119,127 @@
         self.test_write()
         # Try .readline() with varying line lengths
 
-        f = gzip.GzipFile(self.filename, 'rb')
-        line_length = 0
-        while 1:
-            L = f.readline(line_length)
-            if L == "" and line_length != 0: break
-            self.assertTrue(len(L) <= line_length)
-            line_length = (line_length + 1) % 50
-        f.close()
+        with gzip.GzipFile(self.filename, 'rb') as f:
+            line_length = 0
+            while 1:
+                L = f.readline(line_length)
+                if not L and line_length != 0: break
+                self.assertTrue(len(L) <= line_length)
+                line_length = (line_length + 1) % 50
 
     def test_readlines(self):
         self.test_write()
         # Try .readlines()
 
-        f = gzip.GzipFile(self.filename, 'rb')
-        L = f.readlines()
-        f.close()
+        with gzip.GzipFile(self.filename, 'rb') as f:
+            L = f.readlines()
 
-        f = gzip.GzipFile(self.filename, 'rb')
-        while 1:
-            L = f.readlines(150)
-            if L == []: break
-        f.close()
+        with gzip.GzipFile(self.filename, 'rb') as f:
+            while 1:
+                L = f.readlines(150)
+                if L == []: break
 
     def test_seek_read(self):
         self.test_write()
         # Try seek, read test
 
-        f = gzip.GzipFile(self.filename)
-        while 1:
-            oldpos = f.tell()
-            line1 = f.readline()
-            if not line1: break
-            newpos = f.tell()
-            f.seek(oldpos)  # negative seek
-            if len(line1)>10:
-                amount = 10
-            else:
-                amount = len(line1)
-            line2 = f.read(amount)
-            self.assertEqual(line1[:amount], line2)
-            f.seek(newpos)  # positive seek
-        f.close()
+        with gzip.GzipFile(self.filename) as f:
+            while 1:
+                oldpos = f.tell()
+                line1 = f.readline()
+                if not line1: break
+                newpos = f.tell()
+                f.seek(oldpos)  # negative seek
+                if len(line1)>10:
+                    amount = 10
+                else:
+                    amount = len(line1)
+                line2 = f.read(amount)
+                self.assertEqual(line1[:amount], line2)
+                f.seek(newpos)  # positive seek
 
     def test_seek_whence(self):
         self.test_write()
         # Try seek(whence=1), read test
 
-        f = gzip.GzipFile(self.filename)
-        f.read(10)
-        f.seek(10, whence=1)
-        y = f.read(10)
-        f.close()
+        with gzip.GzipFile(self.filename) as f:
+            f.read(10)
+            f.seek(10, whence=1)
+            y = f.read(10)
         self.assertEquals(y, data1[20:30])
 
     def test_seek_write(self):
         # Try seek, write test
-        f = gzip.GzipFile(self.filename, 'w')
-        for pos in range(0, 256, 16):
-            f.seek(pos)
-            f.write('GZ\n')
-        f.close()
+        with gzip.GzipFile(self.filename, 'w') as f:
+            for pos in range(0, 256, 16):
+                f.seek(pos)
+                f.write('GZ\n')
 
     def test_mode(self):
         self.test_write()
-        f = gzip.GzipFile(self.filename, 'r')
-        self.assertEqual(f.myfileobj.mode, 'rb')
-        f.close()
+        with gzip.GzipFile(self.filename, 'r') as f:
+            self.assertEqual(f.myfileobj.mode, 'rb')
 
     def test_1647484(self):
         for mode in ('wb', 'rb'):
-            f = gzip.GzipFile(self.filename, mode)
-            self.assertTrue(hasattr(f, "name"))
-            self.assertEqual(f.name, self.filename)
-            f.close()
+            with gzip.GzipFile(self.filename, mode) as f:
+                self.assertTrue(hasattr(f, "name"))
+                self.assertEqual(f.name, self.filename)
 
     def test_mtime(self):
         mtime = 123456789
-        fWrite = gzip.GzipFile(self.filename, 'w', mtime = mtime)
-        fWrite.write(data1)
-        fWrite.close()
-        fRead = gzip.GzipFile(self.filename)
-        dataRead = fRead.read()
-        self.assertEqual(dataRead, data1)
-        self.assertTrue(hasattr(fRead, 'mtime'))
-        self.assertEqual(fRead.mtime, mtime)
-        fRead.close()
+        with gzip.GzipFile(self.filename, 'w', mtime = mtime) as fWrite:
+            fWrite.write(data1)
+        with gzip.GzipFile(self.filename) as fRead:
+            dataRead = fRead.read()
+            self.assertEqual(dataRead, data1)
+            self.assertTrue(hasattr(fRead, 'mtime'))
+            self.assertEqual(fRead.mtime, mtime)
 
     def test_metadata(self):
         mtime = 123456789
 
-        fWrite = gzip.GzipFile(self.filename, 'w', mtime = mtime)
-        fWrite.write(data1)
-        fWrite.close()
-
-        fRead = open(self.filename, 'rb')
-
-        # see RFC 1952: http://www.faqs.org/rfcs/rfc1952.html
+        with gzip.GzipFile(self.filename, 'w', mtime = mtime) as fWrite:
+            fWrite.write(data1)
 
-        idBytes = fRead.read(2)
-        self.assertEqual(idBytes, '\x1f\x8b') # gzip ID
+        with open(self.filename, 'rb') as fRead:
+            # see RFC 1952: http://www.faqs.org/rfcs/rfc1952.html
 
-        cmByte = fRead.read(1)
-        self.assertEqual(cmByte, '\x08') # deflate
+            idBytes = fRead.read(2)
+            self.assertEqual(idBytes, '\x1f\x8b') # gzip ID
 
-        flagsByte = fRead.read(1)
-        self.assertEqual(flagsByte, '\x08') # only the FNAME flag is set
+            cmByte = fRead.read(1)
+            self.assertEqual(cmByte, '\x08') # deflate
 
-        mtimeBytes = fRead.read(4)
-        self.assertEqual(mtimeBytes, struct.pack('<i', mtime)) # little-endian
+            flagsByte = fRead.read(1)
+            self.assertEqual(flagsByte, '\x08') # only the FNAME flag is set
 
-        xflByte = fRead.read(1)
-        self.assertEqual(xflByte, '\x02') # maximum compression
+            mtimeBytes = fRead.read(4)
+            self.assertEqual(mtimeBytes, struct.pack('<i', mtime)) # little-endian
 
-        osByte = fRead.read(1)
-        self.assertEqual(osByte, '\xff') # OS "unknown" (OS-independent)
+            xflByte = fRead.read(1)
+            self.assertEqual(xflByte, '\x02') # maximum compression
 
-        # Since the FNAME flag is set, the zero-terminated filename follows.
-        # RFC 1952 specifies that this is the name of the input file, if any.
-        # However, the gzip module defaults to storing the name of the output
-        # file in this field.
-        nameBytes = fRead.read(len(self.filename) + 1)
-        self.assertEqual(nameBytes, self.filename + '\x00')
+            osByte = fRead.read(1)
+            self.assertEqual(osByte, '\xff') # OS "unknown" (OS-independent)
 
-        # Since no other flags were set, the header ends here.
-        # Rather than process the compressed data, let's seek to the trailer.
-        fRead.seek(os.stat(self.filename).st_size - 8)
+            # Since the FNAME flag is set, the zero-terminated filename follows.
+            # RFC 1952 specifies that this is the name of the input file, if any.
+            # However, the gzip module defaults to storing the name of the output
+            # file in this field.
+            expected = self.filename.encode('Latin-1') + '\x00'
+            nameBytes = fRead.read(len(expected))
+            self.assertEqual(nameBytes, expected)
 
-        crc32Bytes = fRead.read(4) # CRC32 of uncompressed data [data1]
-        self.assertEqual(crc32Bytes, '\xaf\xd7d\x83')
+            # Since no other flags were set, the header ends here.
+            # Rather than process the compressed data, let's seek to the trailer.
+            fRead.seek(os.stat(self.filename).st_size - 8)
 
-        isizeBytes = fRead.read(4)
-        self.assertEqual(isizeBytes, struct.pack('<i', len(data1)))
+            crc32Bytes = fRead.read(4) # CRC32 of uncompressed data [data1]
+            self.assertEqual(crc32Bytes, '\xaf\xd7d\x83')
 
-        fRead.close()
+            isizeBytes = fRead.read(4)
+            self.assertEqual(isizeBytes, struct.pack('<i', len(data1)))
 
     def test_with_open(self):
         # GzipFile supports the context management protocol

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_httplib.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_httplib.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_httplib.py	Fri Nov  5 23:50:59 2010
@@ -1,3 +1,4 @@
+import httplib
 import array
 import httplib
 import StringIO
@@ -64,8 +65,6 @@
         # Some headers are added automatically, but should not be added by
         # .request() if they are explicitly set.
 
-        import httplib
-
         class HeaderCountingBuffer(list):
             def __init__(self):
                 self.count = {}
@@ -91,6 +90,13 @@
                 conn.request('POST', '/', body, headers)
                 self.assertEqual(conn._buffer.count[header.lower()], 1)
 
+    def test_putheader(self):
+        conn = httplib.HTTPConnection('example.com')
+        conn.sock = FakeSocket(None)
+        conn.putrequest('GET','/')
+        conn.putheader('Content-length',42)
+        self.assertTrue('Content-length: 42' in conn._buffer)
+
 class BasicTest(TestCase):
     def test_status_lines(self):
         # Test HTTP status lines
@@ -285,6 +291,13 @@
         self.assertEqual("Basic realm=\"example\"",
                          resp.getheader("www-authenticate"))
 
+    def test_filenoattr(self):
+        # Just test the fileno attribute in the HTTPResponse Object.
+        body = "HTTP/1.1 200 Ok\r\n\r\nText"
+        sock = FakeSocket(body)
+        resp = httplib.HTTPResponse(sock)
+        self.assertTrue(hasattr(resp,'fileno'),
+                'HTTPResponse should expose a fileno attribute')
 
 class OfflineTest(TestCase):
     def test_responses(self):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_httpservers.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_httpservers.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_httpservers.py	Fri Nov  5 23:50:59 2010
@@ -11,6 +11,7 @@
 
 import os
 import sys
+import re
 import base64
 import shutil
 import urllib
@@ -18,6 +19,9 @@
 import tempfile
 
 import unittest
+
+from StringIO import StringIO
+
 from test import test_support
 threading = test_support.import_module('threading')
 
@@ -27,6 +31,22 @@
         # don't write log messages to stderr
         pass
 
+class SocketlessRequestHandler(BaseHTTPRequestHandler):
+    def __init__(self):
+        self.get_called = False
+        self.protocol_version = "HTTP/1.1"
+
+    def do_GET(self):
+        self.get_called = True
+        self.send_response(200)
+        self.send_header('Content-Type', 'text/html')
+        self.end_headers()
+        self.wfile.write('<html><body>Data</body></html>\r\n')
+
+    def log_message(self, format, *args):
+        pass
+
+
 
 class TestServerThread(threading.Thread):
     def __init__(self, test_object, request_handler):
@@ -67,6 +87,63 @@
         self.connection.request(method, uri, body, headers)
         return self.connection.getresponse()
 
+class BaseHTTPRequestHandlerTestCase(unittest.TestCase):
+    """Test the functionaility of the BaseHTTPServer focussing on
+    BaseHTTPRequestHandler.
+    """
+
+    HTTPResponseMatch = re.compile('HTTP/1.[0-9]+ 200 OK')
+
+    def setUp (self):
+        self.handler = SocketlessRequestHandler()
+
+    def send_typical_request(self, message):
+        input = StringIO(message)
+        output = StringIO()
+        self.handler.rfile = input
+        self.handler.wfile = output
+        self.handler.handle_one_request()
+        output.seek(0)
+        return output.readlines()
+
+    def verify_get_called(self):
+        self.assertTrue(self.handler.get_called)
+
+    def verify_expected_headers(self, headers):
+        for fieldName in 'Server: ', 'Date: ', 'Content-Type: ':
+            self.assertEqual(sum(h.startswith(fieldName) for h in headers), 1)
+
+    def verify_http_server_response(self, response):
+        match = self.HTTPResponseMatch.search(response)
+        self.assertTrue(match is not None)
+
+    def test_http_1_1(self):
+        result = self.send_typical_request('GET / HTTP/1.1\r\n\r\n')
+        self.verify_http_server_response(result[0])
+        self.verify_expected_headers(result[1:-1])
+        self.verify_get_called()
+        self.assertEqual(result[-1], '<html><body>Data</body></html>\r\n')
+
+    def test_http_1_0(self):
+        result = self.send_typical_request('GET / HTTP/1.0\r\n\r\n')
+        self.verify_http_server_response(result[0])
+        self.verify_expected_headers(result[1:-1])
+        self.verify_get_called()
+        self.assertEqual(result[-1], '<html><body>Data</body></html>\r\n')
+
+    def test_http_0_9(self):
+        result = self.send_typical_request('GET / HTTP/0.9\r\n\r\n')
+        self.assertEqual(len(result), 1)
+        self.assertEqual(result[0], '<html><body>Data</body></html>\r\n')
+        self.verify_get_called()
+
+    def test_with_continue_1_0(self):
+        result = self.send_typical_request('GET / HTTP/1.0\r\nExpect: 100-continue\r\n\r\n')
+        self.verify_http_server_response(result[0])
+        self.verify_expected_headers(result[1:-1])
+        self.verify_get_called()
+        self.assertEqual(result[-1], '<html><body>Data</body></html>\r\n')
+
 
 class BaseHTTPServerTestCase(BaseTestCase):
     class request_handler(NoLogRequestHandler, BaseHTTPRequestHandler):
@@ -179,6 +256,7 @@
         res = self.con.getresponse()
         self.assertEqual(res.getheader('Connection'), 'keep-alive')
         self.con.request('TEST', '/')
+        self.addCleanup(self.con.close)
 
     def test_internal_key_error(self):
         self.con.request('KEYERROR', '/')
@@ -398,14 +476,22 @@
         self.assertEqual(('Hello World\n', 'text/html', 200),
              (res.read(), res.getheader('Content-type'), res.status))
 
+    def test_os_environ_is_not_altered(self):
+        signature = "Test CGI Server"
+        os.environ['SERVER_SOFTWARE'] = signature
+        res = self.request('/cgi-bin/file1.py')
+        self.assertEqual((b'Hello World\n', 'text/html', 200),
+                (res.read(), res.getheader('Content-type'), res.status))
+        self.assertEqual(os.environ['SERVER_SOFTWARE'], signature)
 
 def test_main(verbose=None):
     try:
         cwd = os.getcwd()
-        test_support.run_unittest(BaseHTTPServerTestCase,
-                                SimpleHTTPServerTestCase,
-                                CGIHTTPServerTestCase
-                                )
+        test_support.run_unittest(BaseHTTPRequestHandlerTestCase,
+                                  BaseHTTPServerTestCase,
+                                  SimpleHTTPServerTestCase,
+                                  CGIHTTPServerTestCase
+                                 )
     finally:
         os.chdir(cwd)
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_io.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_io.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_io.py	Fri Nov  5 23:50:59 2010
@@ -53,7 +53,9 @@
         return f._CHUNK_SIZE
 
 
-class MockRawIO:
+class MockRawIOWithoutRead:
+    """A RawIO implementation without read(), so as to exercise the default
+    RawIO.read() which calls readinto()."""
 
     def __init__(self, read_stack=()):
         self._read_stack = list(read_stack)
@@ -61,14 +63,6 @@
         self._reads = 0
         self._extraneous_reads = 0
 
-    def read(self, n=None):
-        self._reads += 1
-        try:
-            return self._read_stack.pop(0)
-        except:
-            self._extraneous_reads += 1
-            return b""
-
     def write(self, b):
         self._write_stack.append(bytes(b))
         return len(b)
@@ -115,6 +109,23 @@
     def truncate(self, pos=None):
         return pos
 
+class CMockRawIOWithoutRead(MockRawIOWithoutRead, io.RawIOBase):
+    pass
+
+class PyMockRawIOWithoutRead(MockRawIOWithoutRead, pyio.RawIOBase):
+    pass
+
+
+class MockRawIO(MockRawIOWithoutRead):
+
+    def read(self, n=None):
+        self._reads += 1
+        try:
+            return self._read_stack.pop(0)
+        except:
+            self._extraneous_reads += 1
+            return b""
+
 class CMockRawIO(MockRawIO, io.RawIOBase):
     pass
 
@@ -560,6 +571,19 @@
         f.close()
         self.assertRaises(ValueError, f.flush)
 
+    def test_RawIOBase_read(self):
+        # Exercise the default RawIOBase.read() implementation (which calls
+        # readinto() internally).
+        rawio = self.MockRawIOWithoutRead((b"abc", b"d", None, b"efg", None))
+        self.assertEqual(rawio.read(2), b"ab")
+        self.assertEqual(rawio.read(2), b"c")
+        self.assertEqual(rawio.read(2), b"d")
+        self.assertEqual(rawio.read(2), None)
+        self.assertEqual(rawio.read(2), b"ef")
+        self.assertEqual(rawio.read(2), b"g")
+        self.assertEqual(rawio.read(2), None)
+        self.assertEqual(rawio.read(2), b"")
+
 class CIOTest(IOTest):
     pass
 
@@ -788,6 +812,7 @@
         self.assertEquals(b"abcdefg", bufio.read())
 
     @unittest.skipUnless(threading, 'Threading required for this test.')
+    @support.requires_resource('cpu')
     def test_threads(self):
         try:
             # Write out many bytes with exactly the same number of 0's,
@@ -1057,6 +1082,7 @@
             self.assertEqual(f.read(), b"abc")
 
     @unittest.skipUnless(threading, 'Threading required for this test.')
+    @support.requires_resource('cpu')
     def test_threads(self):
         try:
             # Write out many bytes from many threads and test they were
@@ -2558,7 +2584,7 @@
     # Put the namespaces of the IO module we are testing and some useful mock
     # classes in the __dict__ of each test.
     mocks = (MockRawIO, MisbehavedRawIO, MockFileIO, CloseFailureIO,
-             MockNonBlockWriterIO)
+             MockNonBlockWriterIO, MockRawIOWithoutRead)
     all_members = io.__all__ + ["IncrementalNewlineDecoder"]
     c_io_ns = dict((name, getattr(io, name)) for name in all_members)
     py_io_ns = dict((name, getattr(pyio, name)) for name in all_members)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_long.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_long.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_long.py	Fri Nov  5 23:50:59 2010
@@ -601,6 +601,22 @@
             slicemin, slicemax = X()[-2L**100:2L**100]
             self.assertEqual(X()[slicemin:slicemax], (slicemin, slicemax))
 
+    def test_issue9869(self):
+        # Issue 9869: Interpreter crash when initializing an instance
+        # of a long subclass from an object whose __long__ method returns
+        # a plain int.
+        class BadLong(object):
+            def __long__(self):
+                return 1000000
+
+        class MyLong(long):
+            pass
+
+        x = MyLong(BadLong())
+        self.assertIsInstance(x, long)
+        self.assertEqual(x, 1000000)
+
+
 # ----------------------------------- tests of auto int->long conversion
 
     def test_auto_overflow(self):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_mailbox.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_mailbox.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_mailbox.py	Fri Nov  5 23:50:59 2010
@@ -598,12 +598,10 @@
         # Remove old files from 'tmp'
         foo_path = os.path.join(self._path, 'tmp', 'foo')
         bar_path = os.path.join(self._path, 'tmp', 'bar')
-        f = open(foo_path, 'w')
-        f.write("@")
-        f.close()
-        f = open(bar_path, 'w')
-        f.write("@")
-        f.close()
+        with open(foo_path, 'w') as f:
+            f.write("@")
+        with open(bar_path, 'w') as f:
+            f.write("@")
         self._box.clean()
         self.assertTrue(os.path.exists(foo_path))
         self.assertTrue(os.path.exists(bar_path))
@@ -1088,13 +1086,12 @@
 
     def test_initialize_with_file(self):
         # Initialize based on contents of file
-        f = open(self._path, 'w+')
-        f.write(_sample_message)
-        f.seek(0)
-        msg = self._factory(f)
-        self._post_initialize_hook(msg)
-        self._check_sample(msg)
-        f.close()
+        with open(self._path, 'w+') as f:
+            f.write(_sample_message)
+            f.seek(0)
+            msg = self._factory(f)
+            self._post_initialize_hook(msg)
+            self._check_sample(msg)
 
     def test_initialize_with_nothing(self):
         # Initialize without arguments
@@ -1812,18 +1809,16 @@
         filename = os.extsep.join((str(t), str(pid), "myhostname", "mydomain"))
         tmpname = os.path.join(self._dir, "tmp", filename)
         newname = os.path.join(self._dir, dir, filename)
-        fp = open(tmpname, "w")
-        self._msgfiles.append(tmpname)
-        if mbox:
-            fp.write(FROM_)
-        fp.write(DUMMY_MESSAGE)
-        fp.close()
+        with open(tmpname, "w") as fp:
+            self._msgfiles.append(tmpname)
+            if mbox:
+                fp.write(FROM_)
+            fp.write(DUMMY_MESSAGE)
         if hasattr(os, "link"):
             os.link(tmpname, newname)
         else:
-            fp = open(newname, "w")
-            fp.write(DUMMY_MESSAGE)
-            fp.close()
+            with open(newname, "w") as fp:
+                fp.write(DUMMY_MESSAGE)
         self._msgfiles.append(newname)
         return tmpname
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_module.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_module.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_module.py	Fri Nov  5 23:50:59 2010
@@ -1,6 +1,6 @@
 # Test the module type
 import unittest
-from test.test_support import run_unittest
+from test.test_support import run_unittest, gc_collect
 
 import sys
 ModuleType = type(sys)
@@ -55,14 +55,29 @@
               {"__name__": "foo", "__doc__": "foodoc", "bar": 42})
         self.assertTrue(foo.__dict__ is d)
 
+    @unittest.expectedFailure
     def test_dont_clear_dict(self):
         # See issue 7140.
         def f():
             foo = ModuleType("foo")
             foo.bar = 4
             return foo
+        gc_collect()
         self.assertEqual(f().__dict__["bar"], 4)
 
+    def test_clear_dict_in_ref_cycle(self):
+        destroyed = []
+        m = ModuleType("foo")
+        m.destroyed = destroyed
+        s = """class A:
+    def __del__(self):
+        destroyed.append(1)
+a = A()"""
+        exec(s, m.__dict__)
+        del m
+        gc_collect()
+        self.assertEqual(destroyed, [1])
+
 def test_main():
     run_unittest(ModuleTests)
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_modulefinder.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_modulefinder.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_modulefinder.py	Fri Nov  5 23:50:59 2010
@@ -211,11 +211,17 @@
 
 def create_package(source):
     ofi = None
-    for line in source.splitlines():
-        if line.startswith(" ") or line.startswith("\t"):
-            ofi.write(line.strip() + "\n")
-        else:
-            ofi = open_file(os.path.join(TEST_DIR, line.strip()))
+    try:
+        for line in source.splitlines():
+            if line.startswith(" ") or line.startswith("\t"):
+                ofi.write(line.strip() + "\n")
+            else:
+                if ofi:
+                    ofi.close()
+                ofi = open_file(os.path.join(TEST_DIR, line.strip()))
+    finally:
+        if ofi:
+            ofi.close()
 
 class ModuleFinderTest(unittest.TestCase):
     def _do_test(self, info, report=False):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_multibytecodec.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_multibytecodec.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_multibytecodec.py	Fri Nov  5 23:50:59 2010
@@ -46,12 +46,9 @@
                           'apple\x92ham\x93spam', 'test.cjktest')
 
     def test_codingspec(self):
-        try:
-            for enc in ALL_CJKENCODINGS:
-                print >> open(TESTFN, 'w'), '# coding:', enc
-                exec open(TESTFN)
-        finally:
-            os.unlink(TESTFN)
+        for enc in ALL_CJKENCODINGS:
+            code = '# coding: {}\n'.format(enc)
+            exec code
 
     def test_init_segfault(self):
         # bug #3305: this used to segfault

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_multibytecodec_support.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_multibytecodec_support.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_multibytecodec_support.py	Fri Nov  5 23:50:59 2010
@@ -252,7 +252,7 @@
     def __init__(self, *args, **kw):
         unittest.TestCase.__init__(self, *args, **kw)
         try:
-            self.open_mapping_file() # test it to report the error early
+            self.open_mapping_file().close() # test it to report the error early
         except (IOError, HTTPException):
             self.skipTest("Could not retrieve "+self.mapfileurl)
 
@@ -270,36 +270,38 @@
         unichrs = lambda s: u''.join(_unichr(c) for c in s.split('+'))
         urt_wa = {}
 
-        for line in self.open_mapping_file():
-            if not line:
-                break
-            data = line.split('#')[0].strip().split()
-            if len(data) != 2:
-                continue
-
-            csetval = eval(data[0])
-            if csetval <= 0x7F:
-                csetch = chr(csetval & 0xff)
-            elif csetval >= 0x1000000:
-                csetch = chr(csetval >> 24) + chr((csetval >> 16) & 0xff) + \
-                         chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
-            elif csetval >= 0x10000:
-                csetch = chr(csetval >> 16) + \
-                         chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
-            elif csetval >= 0x100:
-                csetch = chr(csetval >> 8) + chr(csetval & 0xff)
-            else:
-                continue
-
-            unich = unichrs(data[1])
-            if unich == u'\ufffd' or unich in urt_wa:
-                continue
-            urt_wa[unich] = csetch
+        with self.open_mapping_file() as f:
+            for line in f:
+                if not line:
+                    break
+                data = line.split('#')[0].strip().split()
+                if len(data) != 2:
+                    continue
+
+                csetval = eval(data[0])
+                if csetval <= 0x7F:
+                    csetch = chr(csetval & 0xff)
+                elif csetval >= 0x1000000:
+                    csetch = chr(csetval >> 24) + chr((csetval >> 16) & 0xff) + \
+                             chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
+                elif csetval >= 0x10000:
+                    csetch = chr(csetval >> 16) + \
+                             chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
+                elif csetval >= 0x100:
+                    csetch = chr(csetval >> 8) + chr(csetval & 0xff)
+                else:
+                    continue
+
+                unich = unichrs(data[1])
+                if unich == u'\ufffd' or unich in urt_wa:
+                    continue
+                urt_wa[unich] = csetch
 
-            self._testpoint(csetch, unich)
+                self._testpoint(csetch, unich)
 
     def _test_mapping_file_ucm(self):
-        ucmdata = self.open_mapping_file().read()
+        with self.open_mapping_file() as f:
+            ucmdata = f.read()
         uc = re.findall('<a u="([A-F0-9]{4})" b="([0-9A-F ]+)"/>', ucmdata)
         for uni, coded in uc:
             unich = unichr(int(uni, 16))

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_multiprocessing.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_multiprocessing.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_multiprocessing.py	Fri Nov  5 23:50:59 2010
@@ -34,6 +34,12 @@
 
 from multiprocessing import util
 
+try:
+    from multiprocessing.sharedctypes import Value, copy
+    HAS_SHAREDCTYPES = True
+except ImportError:
+    HAS_SHAREDCTYPES = False
+
 #
 #
 #
@@ -72,16 +78,6 @@
     Structure = object
     c_int = c_double = None
 
-try:
-    from ctypes import Value
-except ImportError:
-    Value = None
-
-try:
-    from ctypes import copy as ctypes_copy
-except ImportError:
-    ctypes_copy = None
-
 #
 # Creates a wrapper for a function which records the time it takes to finish
 #
@@ -119,6 +115,13 @@
         else:
             return self.assertEqual(value, res)
 
+    # For the sanity of Windows users, rather than crashing or freezing in
+    # multiple ways.
+    def __reduce__(self, *args):
+        raise NotImplementedError("shouldn't try to pickle a test case")
+
+    __reduce_ex__ = __reduce__
+
 #
 # Return the value of a semaphore
 #
@@ -157,12 +160,13 @@
         self.assertEqual(current.ident, os.getpid())
         self.assertEqual(current.exitcode, None)
 
-    def _test(self, q, *args, **kwds):
-        current = self.current_process()
+    @classmethod
+    def _test(cls, q, *args, **kwds):
+        current = cls.current_process()
         q.put(args)
         q.put(kwds)
         q.put(current.name)
-        if self.TYPE != 'threads':
+        if cls.TYPE != 'threads':
             q.put(bytes(current.authkey))
             q.put(current.pid)
 
@@ -205,7 +209,8 @@
         self.assertEquals(p.is_alive(), False)
         self.assertNotIn(p, self.active_children())
 
-    def _test_terminate(self):
+    @classmethod
+    def _test_terminate(cls):
         time.sleep(1000)
 
     def test_terminate(self):
@@ -254,13 +259,14 @@
         p.join()
         self.assertNotIn(p, self.active_children())
 
-    def _test_recursion(self, wconn, id):
+    @classmethod
+    def _test_recursion(cls, wconn, id):
         from multiprocessing import forking
         wconn.send(id)
         if len(id) < 2:
             for i in range(2):
-                p = self.Process(
-                    target=self._test_recursion, args=(wconn, id+[i])
+                p = cls.Process(
+                    target=cls._test_recursion, args=(wconn, id+[i])
                     )
                 p.start()
                 p.join()
@@ -343,7 +349,8 @@
 class _TestQueue(BaseTestCase):
 
 
-    def _test_put(self, queue, child_can_start, parent_can_continue):
+    @classmethod
+    def _test_put(cls, queue, child_can_start, parent_can_continue):
         child_can_start.wait()
         for i in range(6):
             queue.get()
@@ -407,7 +414,8 @@
 
         proc.join()
 
-    def _test_get(self, queue, child_can_start, parent_can_continue):
+    @classmethod
+    def _test_get(cls, queue, child_can_start, parent_can_continue):
         child_can_start.wait()
         #queue.put(1)
         queue.put(2)
@@ -468,7 +476,8 @@
 
         proc.join()
 
-    def _test_fork(self, queue):
+    @classmethod
+    def _test_fork(cls, queue):
         for i in range(10, 20):
             queue.put(i)
         # note that at this point the items may only be buffered, so the
@@ -516,7 +525,8 @@
         q.get()
         self.assertEqual(q.qsize(), 0)
 
-    def _test_task_done(self, q):
+    @classmethod
+    def _test_task_done(cls, q):
         for obj in iter(q.get, None):
             time.sleep(DELTA)
             q.task_done()
@@ -628,7 +638,8 @@
 
 class _TestCondition(BaseTestCase):
 
-    def f(self, cond, sleeping, woken, timeout=None):
+    @classmethod
+    def f(cls, cond, sleeping, woken, timeout=None):
         cond.acquire()
         sleeping.release()
         cond.wait(timeout)
@@ -760,7 +771,8 @@
 
 class _TestEvent(BaseTestCase):
 
-    def _test_event(self, event):
+    @classmethod
+    def _test_event(cls, event):
         time.sleep(TIMEOUT2)
         event.set()
 
@@ -800,6 +812,8 @@
 #
 #
 
+ at unittest.skipUnless(HAS_SHAREDCTYPES,
+                     "requires multiprocessing.sharedctypes")
 class _TestValue(BaseTestCase):
 
     ALLOWED_TYPES = ('processes',)
@@ -811,12 +825,12 @@
         ('c', latin('x'), latin('y'))
         ]
 
-    def _test(self, values):
-        for sv, cv in zip(values, self.codes_values):
+    @classmethod
+    def _test(cls, values):
+        for sv, cv in zip(values, cls.codes_values):
             sv.value = cv[2]
 
 
-    @unittest.skipIf(c_int is None, "requires _ctypes")
     def test_value(self, raw=False):
         if raw:
             values = [self.RawValue(code, value)
@@ -835,11 +849,9 @@
         for sv, cv in zip(values, self.codes_values):
             self.assertEqual(sv.value, cv[2])
 
-    @unittest.skipIf(c_int is None, "requires _ctypes")
     def test_rawvalue(self):
         self.test_value(raw=True)
 
-    @unittest.skipIf(c_int is None, "requires _ctypes")
     def test_getobj_getlock(self):
         val1 = self.Value('i', 5)
         lock1 = val1.get_lock()
@@ -870,7 +882,8 @@
 
     ALLOWED_TYPES = ('processes',)
 
-    def f(self, seq):
+    @classmethod
+    def f(cls, seq):
         for i in range(1, len(seq)):
             seq[i] += seq[i-1]
 
@@ -1215,7 +1228,8 @@
 
     ALLOWED_TYPES = ('manager',)
 
-    def _putter(self, address, authkey):
+    @classmethod
+    def _putter(cls, address, authkey):
         manager = QueueManager2(
             address=address, authkey=authkey, serializer=SERIALIZER
             )
@@ -1253,7 +1267,8 @@
 
 class _TestManagerRestart(BaseTestCase):
 
-    def _putter(self, address, authkey):
+    @classmethod
+    def _putter(cls, address, authkey):
         manager = QueueManager(
             address=address, authkey=authkey, serializer=SERIALIZER)
         manager.connect()
@@ -1264,7 +1279,11 @@
         authkey = os.urandom(32)
         manager = QueueManager(
             address=('localhost', 0), authkey=authkey, serializer=SERIALIZER)
-        addr = manager.get_server().address
+        srvr = manager.get_server()
+        addr = srvr.address
+        # Close the connection.Listener socket which gets opened as a part
+        # of manager.get_server(). It's not needed for the test.
+        srvr.listener.close()
         manager.start()
 
         p = self.Process(target=self._putter, args=(manager.address, authkey))
@@ -1288,7 +1307,8 @@
 
     ALLOWED_TYPES = ('processes', 'threads')
 
-    def _echo(self, conn):
+    @classmethod
+    def _echo(cls, conn):
         for msg in iter(conn.recv_bytes, SENTINEL):
             conn.send_bytes(msg)
         conn.close()
@@ -1437,8 +1457,9 @@
 
     ALLOWED_TYPES = ('processes', 'threads')
 
-    def _test(self, address):
-        conn = self.connection.Client(address)
+    @classmethod
+    def _test(cls, address):
+        conn = cls.connection.Client(address)
         conn.send('hello')
         conn.close()
 
@@ -1593,11 +1614,14 @@
         ('y', c_double)
         ]
 
+ at unittest.skipUnless(HAS_SHAREDCTYPES,
+                     "requires multiprocessing.sharedctypes")
 class _TestSharedCTypes(BaseTestCase):
 
     ALLOWED_TYPES = ('processes',)
 
-    def _double(self, x, y, foo, arr, string):
+    @classmethod
+    def _double(cls, x, y, foo, arr, string):
         x.value *= 2
         y.value *= 2
         foo.x *= 2
@@ -1606,14 +1630,13 @@
         for i in range(len(arr)):
             arr[i] *= 2
 
-    @unittest.skipIf(Value is None, "requires ctypes.Value")
     def test_sharedctypes(self, lock=False):
         x = Value('i', 7, lock=lock)
         y = Value(c_double, 1.0/3.0, lock=lock)
         foo = Value(_Foo, 3, 2, lock=lock)
         arr = self.Array('d', range(10), lock=lock)
         string = self.Array('c', 20, lock=lock)
-        string.value = 'hello'
+        string.value = latin('hello')
 
         p = self.Process(target=self._double, args=(x, y, foo, arr, string))
         p.start()
@@ -1627,14 +1650,12 @@
             self.assertAlmostEqual(arr[i], i*2)
         self.assertEqual(string.value, latin('hellohello'))
 
-    @unittest.skipIf(Value is None, "requires ctypes.Value")
     def test_synchronize(self):
         self.test_sharedctypes(lock=True)
 
-    @unittest.skipIf(ctypes_copy is None, "requires ctypes.copy")
     def test_copy(self):
         foo = _Foo(2, 5.0)
-        bar = ctypes_copy(foo)
+        bar = copy(foo)
         foo.x = 0
         foo.y = 0
         self.assertEqual(bar.x, 2)
@@ -1648,7 +1669,8 @@
 
     ALLOWED_TYPES = ('processes',)
 
-    def _test_finalize(self, conn):
+    @classmethod
+    def _test_finalize(cls, conn):
         class Foo(object):
             pass
 
@@ -1742,7 +1764,8 @@
         logger.info('nor will this')
         logger.setLevel(LOG_LEVEL)
 
-    def _test_level(self, conn):
+    @classmethod
+    def _test_level(cls, conn):
         logger = multiprocessing.get_logger()
         conn.send(logger.getEffectiveLevel())
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_ntpath.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_ntpath.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_ntpath.py	Fri Nov  5 23:50:59 2010
@@ -178,6 +178,16 @@
         tester('ntpath.relpath("a", "b/c")', '..\\..\\a')
         tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a')
         tester('ntpath.relpath("a", "a")', '.')
+        tester('ntpath.relpath("/foo/bar/bat", "/x/y/z")', '..\\..\\..\\foo\\bar\\bat')
+        tester('ntpath.relpath("/foo/bar/bat", "/foo/bar")', 'bat')
+        tester('ntpath.relpath("/foo/bar/bat", "/")', 'foo\\bar\\bat')
+        tester('ntpath.relpath("/", "/foo/bar/bat")', '..\\..\\..')
+        tester('ntpath.relpath("/foo/bar/bat", "/x")', '..\\foo\\bar\\bat')
+        tester('ntpath.relpath("/x", "/foo/bar/bat")', '..\\..\\..\\x')
+        tester('ntpath.relpath("/", "/")', '.')
+        tester('ntpath.relpath("/a", "/a")', '.')
+        tester('ntpath.relpath("/a/b", "/a/b")', '.')
+        tester('ntpath.relpath("c:/foo", "C:/FOO")', '.')
 
 
 class NtCommonTest(test_genericpath.CommonTest):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_old_mailbox.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_old_mailbox.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_old_mailbox.py	Fri Nov  5 23:50:59 2010
@@ -48,18 +48,16 @@
         filename = os.extsep.join((str(t), str(pid), "myhostname", "mydomain"))
         tmpname = os.path.join(self._dir, "tmp", filename)
         newname = os.path.join(self._dir, dir, filename)
-        fp = open(tmpname, "w")
-        self._msgfiles.append(tmpname)
-        if mbox:
-            fp.write(FROM_)
-        fp.write(DUMMY_MESSAGE)
-        fp.close()
+        with open(tmpname, "w") as fp:
+            self._msgfiles.append(tmpname)
+            if mbox:
+                fp.write(FROM_)
+            fp.write(DUMMY_MESSAGE)
         if hasattr(os, "link"):
             os.link(tmpname, newname)
         else:
-            fp = open(newname, "w")
-            fp.write(DUMMY_MESSAGE)
-            fp.close()
+            with open(newname, "w") as fp:
+                fp.write(DUMMY_MESSAGE)
         self._msgfiles.append(newname)
         return tmpname
 
@@ -102,11 +100,12 @@
         import email.parser
         fname = self.createMessage("cur", True)
         n = 0
-        for msg in mailbox.PortableUnixMailbox(open(fname),
+        with open(fname) as f:
+            for msg in mailbox.PortableUnixMailbox(f,
                                                email.parser.Parser().parse):
-            n += 1
-            self.assertEqual(msg["subject"], "Simple Test")
-            self.assertEqual(len(str(msg)), len(FROM_)+len(DUMMY_MESSAGE))
+                n += 1
+                self.assertEqual(msg["subject"], "Simple Test")
+                self.assertEqual(len(str(msg)), len(FROM_)+len(DUMMY_MESSAGE))
         self.assertEqual(n, 1)
 
 class MboxTestCase(unittest.TestCase):
@@ -119,8 +118,8 @@
 
     def test_from_regex (self):
         # Testing new regex from bug #1633678
-        f = open(self._path, 'w')
-        f.write("""From fred at example.com Mon May 31 13:24:50 2004 +0200
+        with open(self._path, 'w') as f:
+            f.write("""From fred at example.com Mon May 31 13:24:50 2004 +0200
 Subject: message 1
 
 body1
@@ -137,9 +136,9 @@
 
 body4
 """)
-        f.close()
-        box = mailbox.UnixMailbox(open(self._path, 'r'))
-        self.assertTrue(len(list(iter(box))) == 4)
+        with open(self._path, 'r') as f:
+            box = mailbox.UnixMailbox(f)
+            self.assertTrue(len(list(iter(box))) == 4)
 
 
     # XXX We still need more tests!

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_os.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_os.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_os.py	Fri Nov  5 23:50:59 2010
@@ -11,6 +11,8 @@
 import subprocess
 import time
 from test import test_support
+import mmap
+import uuid
 
 warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__)
 warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__)
@@ -342,8 +344,9 @@
     def test_update2(self):
         if os.path.exists("/bin/sh"):
             os.environ.update(HELLO="World")
-            value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip()
-            self.assertEquals(value, "World")
+            with os.popen("/bin/sh -c 'echo $HELLO'") as popen:
+                value = popen.read().strip()
+                self.assertEquals(value, "World")
 
 class WalkTests(unittest.TestCase):
     """Tests for os.walk()."""
@@ -706,6 +709,9 @@
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 stdin=subprocess.PIPE)
+        self.addCleanup(proc.stdout.close)
+        self.addCleanup(proc.stderr.close)
+        self.addCleanup(proc.stdin.close)
 
         count, max = 0, 100
         while count < max and proc.poll() is None:
@@ -736,13 +742,23 @@
         self._kill(100)
 
     def _kill_with_event(self, event, name):
+        tagname = "test_os_%s" % uuid.uuid1()
+        m = mmap.mmap(-1, 1, tagname)
+        m[0] = '0'
         # Run a script which has console control handling enabled.
         proc = subprocess.Popen([sys.executable,
                    os.path.join(os.path.dirname(__file__),
-                                "win_console_handler.py")],
+                                "win_console_handler.py"), tagname],
                    creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
         # Let the interpreter startup before we send signals. See #3137.
-        time.sleep(0.5)
+        count, max = 0, 20
+        while count < max and proc.poll() is None:
+            if m[0] == '1':
+                break
+            time.sleep(0.5)
+            count += 1
+        else:
+            self.fail("Subprocess didn't finish initialization")
         os.kill(proc.pid, event)
         # proc.send_signal(event) could also be done here.
         # Allow time for the signal to be passed and the process to exit.

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_pipes.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_pipes.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_pipes.py	Fri Nov  5 23:50:59 2010
@@ -23,17 +23,21 @@
         f = t.open(TESTFN, 'w')
         f.write('hello world #1')
         f.close()
-        self.assertEqual(open(TESTFN).read(), 'HELLO WORLD #1')
+        with open(TESTFN) as f:
+            self.assertEqual(f.read(), 'HELLO WORLD #1')
 
     def testSimplePipe2(self):
-        file(TESTFN, 'w').write('hello world #2')
+        with open(TESTFN, 'w') as f:
+            f.write('hello world #2')
         t = pipes.Template()
         t.append(s_command + ' < $IN > $OUT', pipes.FILEIN_FILEOUT)
         t.copy(TESTFN, TESTFN2)
-        self.assertEqual(open(TESTFN2).read(), 'HELLO WORLD #2')
+        with open(TESTFN2) as f:
+            self.assertEqual(f.read(), 'HELLO WORLD #2')
 
     def testSimplePipe3(self):
-        file(TESTFN, 'w').write('hello world #2')
+        with open(TESTFN, 'w') as f:
+            f.write('hello world #2')
         t = pipes.Template()
         t.append(s_command + ' < $IN', pipes.FILEIN_STDOUT)
         with t.open(TESTFN, 'r') as f:
@@ -42,16 +46,20 @@
     def testEmptyPipeline1(self):
         # copy through empty pipe
         d = 'empty pipeline test COPY'
-        file(TESTFN, 'w').write(d)
-        file(TESTFN2, 'w').write('')
+        with open(TESTFN, 'w') as f:
+            f.write(d)
+        with open(TESTFN2, 'w') as f:
+            f.write('')
         t=pipes.Template()
         t.copy(TESTFN, TESTFN2)
-        self.assertEqual(open(TESTFN2).read(), d)
+        with open(TESTFN2) as f:
+            self.assertEqual(f.read(), d)
 
     def testEmptyPipeline2(self):
         # read through empty pipe
         d = 'empty pipeline test READ'
-        file(TESTFN, 'w').write(d)
+        with open(TESTFN, 'w') as f:
+            f.write(d)
         t=pipes.Template()
         with t.open(TESTFN, 'r') as f:
             self.assertEqual(f.read(), d)
@@ -60,8 +68,10 @@
         # write through empty pipe
         d = 'empty pipeline test WRITE'
         t = pipes.Template()
-        t.open(TESTFN, 'w').write(d)
-        self.assertEqual(open(TESTFN).read(), d)
+        with t.open(TESTFN, 'w') as f:
+            f.write(d)
+        with open(TESTFN) as f:
+            self.assertEqual(f.read(), d)
 
     def testQuoting(self):
         safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./'

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_pkgimport.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_pkgimport.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_pkgimport.py	Fri Nov  5 23:50:59 2010
@@ -22,7 +22,8 @@
         self.package_dir = os.path.join(self.test_dir,
                                         self.package_name)
         os.mkdir(self.package_dir)
-        open(os.path.join(self.package_dir, '__init__'+os.extsep+'py'), 'w')
+        open(os.path.join(
+                self.package_dir, '__init__'+os.extsep+'py'), 'w').close()
         self.module_path = os.path.join(self.package_dir, 'foo'+os.extsep+'py')
 
     def tearDown(self):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_posixpath.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_posixpath.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_posixpath.py	Fri Nov  5 23:50:59 2010
@@ -322,6 +322,15 @@
             self.assertEqual(posixpath.relpath("a/b", "../c"), "../"+curdir+"/a/b")
             self.assertEqual(posixpath.relpath("a", "b/c"), "../../a")
             self.assertEqual(posixpath.relpath("a", "a"), ".")
+            self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x/y/z"), '../../../foo/bar/bat')
+            self.assertEqual(posixpath.relpath("/foo/bar/bat", "/foo/bar"), 'bat')
+            self.assertEqual(posixpath.relpath("/foo/bar/bat", "/"), 'foo/bar/bat')
+            self.assertEqual(posixpath.relpath("/", "/foo/bar/bat"), '../../..')
+            self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x"), '../foo/bar/bat')
+            self.assertEqual(posixpath.relpath("/x", "/foo/bar/bat"), '../../../x')
+            self.assertEqual(posixpath.relpath("/", "/"), '.')
+            self.assertEqual(posixpath.relpath("/a", "/a"), '.')
+            self.assertEqual(posixpath.relpath("/a/b", "/a/b"), '.')
         finally:
             os.getcwd = real_getcwd
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_quopri.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_quopri.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_quopri.py	Fri Nov  5 23:50:59 2010
@@ -178,6 +178,7 @@
         (p, e) = self.STRINGS[-1]
         process = subprocess.Popen([sys.executable, "-mquopri"],
                                    stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+        self.addCleanup(process.stdout.close)
         cout, cerr = process.communicate(p)
         # On Windows, Python will output the result to stdout using
         # CRLF, as the mode of stdout is text mode. To compare this
@@ -188,6 +189,7 @@
         (p, e) = self.STRINGS[-1]
         process = subprocess.Popen([sys.executable, "-mquopri", "-d"],
                                    stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+        self.addCleanup(process.stdout.close)
         cout, cerr = process.communicate(e)
         self.assertEqual(cout.splitlines(), p.splitlines())
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_sax.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_sax.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_sax.py	Fri Nov  5 23:50:59 2010
@@ -1,5 +1,5 @@
-# regression test for SAX 2.0            -*- coding: iso-8859-1 -*-
-# $Id: test_sax.py 78919 2010-03-13 12:41:48Z florent.xicluna $
+# regression test for SAX 2.0            -*- coding: utf-8 -*-
+# $Id: test_sax.py 85863 2010-10-27 18:58:04Z antoine.pitrou $
 
 from xml.sax import make_parser, ContentHandler, \
                     SAXException, SAXReaderNotAvailable, SAXParseException
@@ -11,6 +11,7 @@
 from xml.sax.saxutils import XMLGenerator, escape, unescape, quoteattr, \
                              XMLFilterBase
 from xml.sax.expatreader import create_parser
+from xml.sax.handler import feature_namespaces
 from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
 from cStringIO import StringIO
 from test.test_support import findfile, run_unittest
@@ -108,7 +109,7 @@
                           "&lt;Donald Duck &amp; Co&gt;")
 
     def test_escape_extra(self):
-        self.assertEquals(escape("Hei på deg", {"å" : "&aring;"}),
+        self.assertEquals(escape("Hei på deg", {"å" : "&aring;"}),
                           "Hei p&aring; deg")
 
     # ===== unescape
@@ -120,7 +121,7 @@
                           "<Donald Duck & Co>")
 
     def test_unescape_extra(self):
-        self.assertEquals(unescape("Hei på deg", {"å" : "&aring;"}),
+        self.assertEquals(unescape("Hei på deg", {"å" : "&aring;"}),
                           "Hei p&aring; deg")
 
     def test_unescape_amp_extra(self):
@@ -290,6 +291,60 @@
         self.assertEquals(result.getvalue(),
             start+'<my:a xmlns:my="qux" b="c"></my:a>')
 
+    def test_5027_1(self):
+        # The xml prefix (as in xml:lang below) is reserved and bound by
+        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
+        # a bug whereby a KeyError is thrown because this namespace is missing
+        # from a dictionary.
+        #
+        # This test demonstrates the bug by parsing a document.
+        test_xml = StringIO(
+            '<?xml version="1.0"?>'
+            '<a:g1 xmlns:a="http://example.com/ns">'
+             '<a:g2 xml:lang="en">Hello</a:g2>'
+            '</a:g1>')
+
+        parser = make_parser()
+        parser.setFeature(feature_namespaces, True)
+        result = StringIO()
+        gen = XMLGenerator(result)
+        parser.setContentHandler(gen)
+        parser.parse(test_xml)
+
+        self.assertEquals(result.getvalue(),
+                          start + (
+                          '<a:g1 xmlns:a="http://example.com/ns">'
+                           '<a:g2 xml:lang="en">Hello</a:g2>'
+                          '</a:g1>'))
+
+    def test_5027_2(self):
+        # The xml prefix (as in xml:lang below) is reserved and bound by
+        # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
+        # a bug whereby a KeyError is thrown because this namespace is missing
+        # from a dictionary.
+        #
+        # This test demonstrates the bug by direct manipulation of the
+        # XMLGenerator.
+        result = StringIO()
+        gen = XMLGenerator(result)
+
+        gen.startDocument()
+        gen.startPrefixMapping('a', 'http://example.com/ns')
+        gen.startElementNS(('http://example.com/ns', 'g1'), 'g1', {})
+        lang_attr = {('http://www.w3.org/XML/1998/namespace', 'lang'): 'en'}
+        gen.startElementNS(('http://example.com/ns', 'g2'), 'g2', lang_attr)
+        gen.characters('Hello')
+        gen.endElementNS(('http://example.com/ns', 'g2'), 'g2')
+        gen.endElementNS(('http://example.com/ns', 'g1'), 'g1')
+        gen.endPrefixMapping('a')
+        gen.endDocument()
+
+        self.assertEquals(result.getvalue(),
+                          start + (
+                          '<a:g1 xmlns:a="http://example.com/ns">'
+                           '<a:g2 xml:lang="en">Hello</a:g2>'
+                          '</a:g1>'))
+
 
 class XMLFilterBaseTest(unittest.TestCase):
     def test_filter_basic(self):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_scope.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_scope.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_scope.py	Fri Nov  5 23:50:59 2010
@@ -647,6 +647,13 @@
         self.assertEqual(2, global_ns["result2"])
         self.assertEqual(9, global_ns["result9"])
 
+    def testTopIsNotSignificant(self):
+        # See #9997.
+        def top(a):
+            pass
+        def b():
+            global a
+
 
 def test_main():
     with check_warnings(("import \* only allowed at module level",

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_shutil.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_shutil.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_shutil.py	Fri Nov  5 23:50:59 2010
@@ -277,7 +277,8 @@
 
                 os.link(src, dst)
                 self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
-                self.assertEqual(open(src,'r').read(), 'cheddar')
+                with open(src, 'r') as f:
+                    self.assertEqual(f.read(), 'cheddar')
                 os.remove(dst)
 
                 # Using `src` here would mean we end up with a symlink pointing
@@ -285,7 +286,8 @@
                 # TESTFN/cheese.
                 os.symlink('cheese', dst)
                 self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
-                self.assertEqual(open(src,'r').read(), 'cheddar')
+                with open(src, 'r') as f:
+                    self.assertEqual(f.read(), 'cheddar')
                 os.remove(dst)
             finally:
                 try:
@@ -588,9 +590,11 @@
                 pass
 
     def _check_move_file(self, src, dst, real_dst):
-        contents = open(src, "rb").read()
+        with open(src, "rb") as f:
+            contents = f.read()
         shutil.move(src, dst)
-        self.assertEqual(contents, open(real_dst, "rb").read())
+        with open(real_dst, "rb") as f:
+            self.assertEqual(contents, f.read())
         self.assertFalse(os.path.exists(src))
 
     def _check_move_dir(self, src, dst, real_dst):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_signal.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_signal.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_signal.py	Fri Nov  5 23:50:59 2010
@@ -212,13 +212,13 @@
 @unittest.skipUnless(sys.platform == "win32", "Windows specific")
 class WindowsSignalTests(unittest.TestCase):
     def test_issue9324(self):
+        # Updated for issue #10003, adding SIGBREAK
         handler = lambda x, y: None
-        signal.signal(signal.SIGABRT, handler)
-        signal.signal(signal.SIGFPE, handler)
-        signal.signal(signal.SIGILL, handler)
-        signal.signal(signal.SIGINT, handler)
-        signal.signal(signal.SIGSEGV, handler)
-        signal.signal(signal.SIGTERM, handler)
+        for sig in (signal.SIGABRT, signal.SIGBREAK, signal.SIGFPE,
+                    signal.SIGILL, signal.SIGINT, signal.SIGSEGV,
+                    signal.SIGTERM):
+            # Set and then reset a handler for signals that work on windows
+            signal.signal(sig, signal.signal(sig, handler))
 
         with self.assertRaises(ValueError):
             signal.signal(-1, handler)
@@ -438,8 +438,8 @@
         self.assertEqual(self.hndl_called, True)
 
     # Issue 3864. Unknown if this affects earlier versions of freebsd also.
-    @unittest.skipIf(sys.platform=='freebsd6',
-        'itimer not reliable (does not mix well with threading) on freebsd6')
+    @unittest.skipIf(sys.platform in ('freebsd6', 'netbsd5'),
+        'itimer not reliable (does not mix well with threading) on some BSDs.')
     def test_itimer_virtual(self):
         self.itimer = signal.ITIMER_VIRTUAL
         signal.signal(signal.SIGVTALRM, self.sig_vtalrm)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_smtpnet.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_smtpnet.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_smtpnet.py	Fri Nov  5 23:50:59 2010
@@ -12,7 +12,8 @@
 
     def test_connect(self):
         test_support.get_attribute(smtplib, 'SMTP_SSL')
-        server = smtplib.SMTP_SSL(self.testServer, self.remotePort)
+        with test_support.transient_internet(self.testServer):
+            server = smtplib.SMTP_SSL(self.testServer, self.remotePort)
         server.ehlo()
         server.quit()
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_socket.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_socket.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_socket.py	Fri Nov  5 23:50:59 2010
@@ -15,6 +15,7 @@
 import contextlib
 from weakref import proxy
 import signal
+import math
 
 def try_address(host, port=0, family=socket.AF_INET):
     """Try to bind a socket on the given host:port and return True
@@ -185,6 +186,11 @@
     def clientSetUp(self):
         self.cli = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 
+    def clientTearDown(self):
+        self.cli.close()
+        self.cli = None
+        ThreadableTest.clientTearDown(self)
+
 class SocketConnectedTest(ThreadedTCPSocketTest):
 
     def __init__(self, methodName='runTest'):
@@ -350,8 +356,10 @@
         # Find one service that exists, then check all the related interfaces.
         # I've ordered this by protocols that have both a tcp and udp
         # protocol, at least for modern Linuxes.
-        if sys.platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
-                            'freebsd7', 'freebsd8', 'darwin'):
+        if (sys.platform.startswith('linux') or
+            sys.platform.startswith('freebsd') or
+            sys.platform.startswith('netbsd') or
+            sys.platform == 'darwin'):
             # avoid the 'echo' service on this platform, as there is an
             # assumption breaking non-standard port/protocol entry
             services = ('daytime', 'qotd', 'domain')
@@ -509,6 +517,7 @@
         # Testing getsockname()
         port = self._get_unused_port()
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        self.addCleanup(sock.close)
         sock.bind(("0.0.0.0", port))
         name = sock.getsockname()
         # XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate
@@ -522,12 +531,14 @@
         # Testing getsockopt()
         # We know a socket should start without reuse==0
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        self.addCleanup(sock.close)
         reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
         self.assertFalse(reuse != 0, "initial mode is reuse")
 
     def testSetSockOpt(self):
         # Testing setsockopt()
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        self.addCleanup(sock.close)
         sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
         self.assertFalse(reuse == 0, "failed to set reuse mode")
@@ -560,15 +571,15 @@
         finally:
             sock.close()
 
+    @unittest.skipUnless(os.name == "nt", "Windows specific")
     def test_sock_ioctl(self):
-        if os.name != "nt":
-            return
         self.assertTrue(hasattr(socket.socket, 'ioctl'))
         self.assertTrue(hasattr(socket, 'SIO_RCVALL'))
         self.assertTrue(hasattr(socket, 'RCVALL_ON'))
         self.assertTrue(hasattr(socket, 'RCVALL_OFF'))
         self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS'))
         s = socket.socket()
+        self.addCleanup(s.close)
         self.assertRaises(ValueError, s.ioctl, -1, None)
         s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100))
 
@@ -611,6 +622,42 @@
                            socket.AI_PASSIVE)
 
 
+    def check_sendall_interrupted(self, with_timeout):
+        # socketpair() is not stricly required, but it makes things easier.
+        if not hasattr(signal, 'alarm') or not hasattr(socket, 'socketpair'):
+            self.skipTest("signal.alarm and socket.socketpair required for this test")
+        # Our signal handlers clobber the C errno by calling a math function
+        # with an invalid domain value.
+        def ok_handler(*args):
+            self.assertRaises(ValueError, math.acosh, 0)
+        def raising_handler(*args):
+            self.assertRaises(ValueError, math.acosh, 0)
+            1 // 0
+        c, s = socket.socketpair()
+        old_alarm = signal.signal(signal.SIGALRM, raising_handler)
+        try:
+            if with_timeout:
+                # Just above the one second minimum for signal.alarm
+                c.settimeout(1.5)
+            with self.assertRaises(ZeroDivisionError):
+                signal.alarm(1)
+                c.sendall(b"x" * (1024**2))
+            if with_timeout:
+                signal.signal(signal.SIGALRM, ok_handler)
+                signal.alarm(1)
+                self.assertRaises(socket.timeout, c.sendall, b"x" * (1024**2))
+        finally:
+            signal.signal(signal.SIGALRM, old_alarm)
+            c.close()
+            s.close()
+
+    def test_sendall_interrupted(self):
+        self.check_sendall_interrupted(False)
+
+    def test_sendall_interrupted_with_timeout(self):
+        self.check_sendall_interrupted(True)
+
+
 @unittest.skipUnless(thread, 'Threading required for this test.')
 class BasicTCPTest(SocketConnectedTest):
 
@@ -673,12 +720,23 @@
             return # On Windows, this doesn't exist
         fd = self.cli_conn.fileno()
         sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)
+        self.addCleanup(sock.close)
         msg = sock.recv(1024)
         self.assertEqual(msg, MSG)
 
     def _testFromFd(self):
         self.serv_conn.send(MSG)
 
+    def testDup(self):
+        # Testing dup()
+        sock = self.cli_conn.dup()
+        self.addCleanup(sock.close)
+        msg = sock.recv(1024)
+        self.assertEqual(msg, MSG)
+
+    def _testDup(self):
+        self.serv_conn.send(MSG)
+
     def testShutdown(self):
         # Testing shutdown()
         msg = self.cli_conn.recv(1024)
@@ -789,6 +847,7 @@
         read, write, err = select.select([self.serv], [], [])
         if self.serv in read:
             conn, addr = self.serv.accept()
+            conn.close()
         else:
             self.fail("Error trying to do accept after select.")
 
@@ -799,6 +858,7 @@
     def testConnect(self):
         # Testing non-blocking connect
         conn, addr = self.serv.accept()
+        conn.close()
 
     def _testConnect(self):
         self.cli.settimeout(10)
@@ -817,6 +877,7 @@
         read, write, err = select.select([conn], [], [])
         if conn in read:
             msg = conn.recv(len(MSG))
+            conn.close()
             self.assertEqual(msg, MSG)
         else:
             self.fail("Error during select call to non-blocking socket.")
@@ -1066,6 +1127,7 @@
     def test_connect(self):
         port = test_support.find_unused_port()
         cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        self.addCleanup(cli.close)
         with self.assertRaises(socket.error) as cm:
             cli.connect((HOST, port))
         self.assertEqual(cm.exception.errno, errno.ECONNREFUSED)
@@ -1103,16 +1165,19 @@
 
     def _justAccept(self):
         conn, addr = self.serv.accept()
+        conn.close()
 
     testFamily = _justAccept
     def _testFamily(self):
         self.cli = socket.create_connection((HOST, self.port), timeout=30)
+        self.addCleanup(self.cli.close)
         self.assertEqual(self.cli.family, 2)
 
     testSourceAddress = _justAccept
     def _testSourceAddress(self):
         self.cli = socket.create_connection((HOST, self.port), timeout=30,
                 source_address=('', self.source_port))
+        self.addCleanup(self.cli.close)
         self.assertEqual(self.cli.getsockname()[1], self.source_port)
         # The port number being used is sufficient to show that the bind()
         # call happened.
@@ -1124,6 +1189,7 @@
         socket.setdefaulttimeout(42)
         try:
             self.cli = socket.create_connection((HOST, self.port))
+            self.addCleanup(self.cli.close)
         finally:
             socket.setdefaulttimeout(None)
         self.assertEquals(self.cli.gettimeout(), 42)
@@ -1135,6 +1201,7 @@
         socket.setdefaulttimeout(30)
         try:
             self.cli = socket.create_connection((HOST, self.port), timeout=None)
+            self.addCleanup(self.cli.close)
         finally:
             socket.setdefaulttimeout(None)
         self.assertEqual(self.cli.gettimeout(), None)
@@ -1147,6 +1214,7 @@
     testTimeoutValueNonamed = _justAccept
     def _testTimeoutValueNonamed(self):
         self.cli = socket.create_connection((HOST, self.port), 30)
+        self.addCleanup(self.cli.close)
         self.assertEqual(self.cli.gettimeout(), 30)
 
 @unittest.skipUnless(thread, 'Threading required for this test.')
@@ -1166,6 +1234,7 @@
 
     def testInsideTimeout(self):
         conn, addr = self.serv.accept()
+        self.addCleanup(conn.close)
         time.sleep(3)
         conn.send("done!")
     testOutsideTimeout = testInsideTimeout

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_ssl.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_ssl.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_ssl.py	Fri Nov  5 23:50:59 2010
@@ -156,18 +156,19 @@
         if not test_support.is_resource_enabled('network'):
             return
         remote = ("svn.python.org", 443)
-        s = ssl.wrap_socket(socket.socket(socket.AF_INET),
-                            cert_reqs=ssl.CERT_NONE, ciphers="ALL")
-        s.connect(remote)
-        s = ssl.wrap_socket(socket.socket(socket.AF_INET),
-                            cert_reqs=ssl.CERT_NONE, ciphers="DEFAULT")
-        s.connect(remote)
-        # Error checking occurs when connecting, because the SSL context
-        # isn't created before.
-        s = ssl.wrap_socket(socket.socket(socket.AF_INET),
-                            cert_reqs=ssl.CERT_NONE, ciphers="^$:,;?*'dorothyx")
-        with self.assertRaisesRegexp(ssl.SSLError, "No cipher can be selected"):
+        with test_support.transient_internet(remote[0]):
+            s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+                                cert_reqs=ssl.CERT_NONE, ciphers="ALL")
+            s.connect(remote)
+            s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+                                cert_reqs=ssl.CERT_NONE, ciphers="DEFAULT")
             s.connect(remote)
+            # Error checking occurs when connecting, because the SSL context
+            # isn't created before.
+            s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+                                cert_reqs=ssl.CERT_NONE, ciphers="^$:,;?*'dorothyx")
+            with self.assertRaisesRegexp(ssl.SSLError, "No cipher can be selected"):
+                s.connect(remote)
 
     @test_support.cpython_only
     def test_refcycle(self):
@@ -179,6 +180,19 @@
         del ss
         self.assertEqual(wr(), None)
 
+    def test_wrapped_unconnected(self):
+        # The _delegate_methods in socket.py are correctly delegated to by an
+        # unconnected SSLSocket, so they will raise a socket.error rather than
+        # something unexpected like TypeError.
+        s = socket.socket(socket.AF_INET)
+        ss = ssl.wrap_socket(s)
+        self.assertRaises(socket.error, ss.recv, 1)
+        self.assertRaises(socket.error, ss.recv_into, bytearray(b'x'))
+        self.assertRaises(socket.error, ss.recvfrom, 1)
+        self.assertRaises(socket.error, ss.recvfrom_into, bytearray(b'x'), 1)
+        self.assertRaises(socket.error, ss.send, b'x')
+        self.assertRaises(socket.error, ss.sendto, b'x', ('0.0.0.0', 0))
+
 
 class NetworkedTests(unittest.TestCase):
 
@@ -1285,7 +1299,7 @@
         not os.path.exists(SVN_PYTHON_ORG_ROOT_CERT)):
         raise test_support.TestFailed("Can't read certificate files!")
 
-    tests = [BasicTests]
+    tests = [BasicTests, BasicSocketTests]
 
     if test_support.is_resource_enabled('network'):
         tests.append(NetworkedTests)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_subprocess.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_subprocess.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_subprocess.py	Fri Nov  5 23:50:59 2010
@@ -117,6 +117,8 @@
         # .stdin is None when not redirected
         p = subprocess.Popen([sys.executable, "-c", 'print "banana"'],
                          stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        self.addCleanup(p.stdout.close)
+        self.addCleanup(p.stderr.close)
         p.wait()
         self.assertEqual(p.stdin, None)
 
@@ -127,6 +129,8 @@
                              'test of stdout in a different '
                              'process ..."'],
                              stdin=subprocess.PIPE, stderr=subprocess.PIPE)
+        self.addCleanup(p.stdin.close)
+        self.addCleanup(p.stderr.close)
         p.wait()
         self.assertEqual(p.stdout, None)
 
@@ -134,6 +138,8 @@
         # .stderr is None when not redirected
         p = subprocess.Popen([sys.executable, "-c", 'print "banana"'],
                          stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+        self.addCleanup(p.stdout.close)
+        self.addCleanup(p.stdin.close)
         p.wait()
         self.assertEqual(p.stderr, None)
 
@@ -194,6 +200,7 @@
         p = subprocess.Popen([sys.executable, "-c",
                           'import sys; sys.stdout.write("orange")'],
                          stdout=subprocess.PIPE)
+        self.addCleanup(p.stdout.close)
         self.assertEqual(p.stdout.read(), "orange")
 
     def test_stdout_filedes(self):
@@ -222,6 +229,7 @@
         p = subprocess.Popen([sys.executable, "-c",
                           'import sys; sys.stderr.write("strawberry")'],
                          stderr=subprocess.PIPE)
+        self.addCleanup(p.stderr.close)
         self.assertStderrEqual(p.stderr.read(), "strawberry")
 
     def test_stderr_filedes(self):
@@ -254,6 +262,7 @@
                           'sys.stderr.write("orange")'],
                          stdout=subprocess.PIPE,
                          stderr=subprocess.STDOUT)
+        self.addCleanup(p.stdout.close)
         self.assertStderrEqual(p.stdout.read(), "appleorange")
 
     def test_stdout_stderr_file(self):
@@ -289,6 +298,7 @@
                           'sys.stdout.write(os.getcwd())'],
                          stdout=subprocess.PIPE,
                          cwd=tmpdir)
+        self.addCleanup(p.stdout.close)
         normcase = os.path.normcase
         self.assertEqual(normcase(p.stdout.read()), normcase(tmpdir))
 
@@ -300,6 +310,7 @@
                           'sys.stdout.write(os.getenv("FRUIT"))'],
                          stdout=subprocess.PIPE,
                          env=newenv)
+        self.addCleanup(p.stdout.close)
         self.assertEqual(p.stdout.read(), "orange")
 
     def test_communicate_stdin(self):
@@ -334,6 +345,9 @@
                          stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
+        self.addCleanup(p.stdout.close)
+        self.addCleanup(p.stderr.close)
+        self.addCleanup(p.stdin.close)
         (stdout, stderr) = p.communicate("banana")
         self.assertEqual(stdout, "banana")
         self.assertStderrEqual(stderr, "pineapple")
@@ -382,6 +396,9 @@
                          stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
+        self.addCleanup(p.stdout.close)
+        self.addCleanup(p.stderr.close)
+        self.addCleanup(p.stdin.close)
         string_to_write = "abc"*pipe_buf
         (stdout, stderr) = p.communicate(string_to_write)
         self.assertEqual(stdout, string_to_write)
@@ -394,6 +411,9 @@
                          stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
+        self.addCleanup(p.stdout.close)
+        self.addCleanup(p.stderr.close)
+        self.addCleanup(p.stdin.close)
         p.stdin.write("banana")
         (stdout, stderr) = p.communicate("split")
         self.assertEqual(stdout, "bananasplit")
@@ -415,6 +435,7 @@
                           'sys.stdout.write("\\nline6");'],
                          stdout=subprocess.PIPE,
                          universal_newlines=1)
+        self.addCleanup(p.stdout.close)
         stdout = p.stdout.read()
         if hasattr(file, 'newlines'):
             # Interpreter with universal newline support
@@ -442,6 +463,8 @@
                           'sys.stdout.write("\\nline6");'],
                          stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                          universal_newlines=1)
+        self.addCleanup(p.stdout.close)
+        self.addCleanup(p.stderr.close)
         (stdout, stderr) = p.communicate()
         if hasattr(file, 'newlines'):
             # Interpreter with universal newline support
@@ -454,20 +477,40 @@
 
     def test_no_leaking(self):
         # Make sure we leak no resources
-        if not hasattr(test_support, "is_resource_enabled") \
-               or test_support.is_resource_enabled("subprocess") and not mswindows:
+        if not mswindows:
             max_handles = 1026 # too much for most UNIX systems
         else:
-            max_handles = 65
-        for i in range(max_handles):
-            p = subprocess.Popen([sys.executable, "-c",
-                    "import sys;sys.stdout.write(sys.stdin.read())"],
-                    stdin=subprocess.PIPE,
-                    stdout=subprocess.PIPE,
-                    stderr=subprocess.PIPE)
-            data = p.communicate("lime")[0]
-            self.assertEqual(data, "lime")
-
+            max_handles = 2050 # too much for (at least some) Windows setups
+        handles = []
+        try:
+            for i in range(max_handles):
+                try:
+                    handles.append(os.open(test_support.TESTFN,
+                                           os.O_WRONLY | os.O_CREAT))
+                except OSError as e:
+                    if e.errno != errno.EMFILE:
+                        raise
+                    break
+            else:
+                self.skipTest("failed to reach the file descriptor limit "
+                    "(tried %d)" % max_handles)
+            # Close a couple of them (should be enough for a subprocess)
+            for i in range(10):
+                os.close(handles.pop())
+            # Loop creating some subprocesses. If one of them leaks some fds,
+            # the next loop iteration will fail by reaching the max fd limit.
+            for i in range(15):
+                p = subprocess.Popen([sys.executable, "-c",
+                                      "import sys;"
+                                      "sys.stdout.write(sys.stdin.read())"],
+                                     stdin=subprocess.PIPE,
+                                     stdout=subprocess.PIPE,
+                                     stderr=subprocess.PIPE)
+                data = p.communicate(b"lime")[0]
+                self.assertEqual(data, b"lime")
+        finally:
+            for h in handles:
+                os.close(h)
 
     def test_list2cmdline(self):
         self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']),
@@ -530,7 +573,7 @@
                 subprocess.Popen(['nonexisting_i_hope'],
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
-            if c.exception.errno != 2:  # ignore "no such file"
+            if c.exception.errno != errno.ENOENT:  # ignore "no such file"
                 raise c.exception
 
     def test_handles_closed_on_exception(self):
@@ -619,6 +662,7 @@
                               "sys.stdout.write(os.getenv('FRUIT'))"],
                              stdout=subprocess.PIPE,
                              preexec_fn=lambda: os.putenv("FRUIT", "apple"))
+        self.addCleanup(p.stdout.close)
         self.assertEqual(p.stdout.read(), "apple")
 
     def test_args_string(self):
@@ -652,6 +696,7 @@
         p = subprocess.Popen(["echo $FRUIT"], shell=1,
                              stdout=subprocess.PIPE,
                              env=newenv)
+        self.addCleanup(p.stdout.close)
         self.assertEqual(p.stdout.read().strip(), "apple")
 
     def test_shell_string(self):
@@ -661,6 +706,7 @@
         p = subprocess.Popen("echo $FRUIT", shell=1,
                              stdout=subprocess.PIPE,
                              env=newenv)
+        self.addCleanup(p.stdout.close)
         self.assertEqual(p.stdout.read().strip(), "apple")
 
     def test_call_string(self):
@@ -692,29 +738,26 @@
         for sh in shells:
             p = subprocess.Popen("echo $0", executable=sh, shell=True,
                                  stdout=subprocess.PIPE)
+            self.addCleanup(p.stdout.close)
             self.assertEqual(p.stdout.read().strip(), sh)
 
     def _kill_process(self, method, *args):
         # Do not inherit file handles from the parent.
         # It should fix failures on some platforms.
-        p = subprocess.Popen([sys.executable, "-c", "input()"], close_fds=True,
-                             stdin=subprocess.PIPE, stderr=subprocess.PIPE)
-
-        # Let the process initialize (Issue #3137)
-        time.sleep(0.1)
-        # The process should not terminate prematurely
-        self.assertIsNone(p.poll())
-        # Retry if the process do not receive the signal.
-        count, maxcount = 0, 3
-        while count < maxcount and p.poll() is None:
-            getattr(p, method)(*args)
-            time.sleep(0.1)
-            count += 1
-
-        self.assertIsNotNone(p.poll(), "the subprocess did not terminate")
-        if count > 1:
-            print >>sys.stderr, ("p.{}{} succeeded after "
-                                 "{} attempts".format(method, args, count))
+        p = subprocess.Popen([sys.executable, "-c", """if 1:
+                             import sys, time
+                             sys.stdout.write('x\\n')
+                             sys.stdout.flush()
+                             time.sleep(30)
+                             """],
+                             close_fds=True,
+                             stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE)
+        # Wait for the interpreter to be completely initialized before
+        # sending any signal.
+        p.stdout.read(1)
+        getattr(p, method)(*args)
         return p
 
     def test_send_signal(self):
@@ -788,6 +831,7 @@
         p = subprocess.Popen(["set"], shell=1,
                              stdout=subprocess.PIPE,
                              env=newenv)
+        self.addCleanup(p.stdout.close)
         self.assertIn("physalis", p.stdout.read())
 
     def test_shell_string(self):
@@ -797,6 +841,7 @@
         p = subprocess.Popen("set", shell=1,
                              stdout=subprocess.PIPE,
                              env=newenv)
+        self.addCleanup(p.stdout.close)
         self.assertIn("physalis", p.stdout.read())
 
     def test_call_string(self):
@@ -807,28 +852,25 @@
 
     def _kill_process(self, method, *args):
         # Some win32 buildbot raises EOFError if stdin is inherited
-        p = subprocess.Popen([sys.executable, "-c", "input()"],
-                             stdin=subprocess.PIPE, stderr=subprocess.PIPE)
-
-        # Let the process initialize (Issue #3137)
-        time.sleep(0.1)
-        # The process should not terminate prematurely
-        self.assertIsNone(p.poll())
-        # Retry if the process do not receive the signal.
-        count, maxcount = 0, 3
-        while count < maxcount and p.poll() is None:
-            getattr(p, method)(*args)
-            time.sleep(0.1)
-            count += 1
-
-        returncode = p.poll()
-        self.assertIsNotNone(returncode, "the subprocess did not terminate")
-        if count > 1:
-            print >>sys.stderr, ("p.{}{} succeeded after "
-                                 "{} attempts".format(method, args, count))
+        p = subprocess.Popen([sys.executable, "-c", """if 1:
+                             import sys, time
+                             sys.stdout.write('x\\n')
+                             sys.stdout.flush()
+                             time.sleep(30)
+                             """],
+                             stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE)
+        self.addCleanup(p.stdout.close)
+        self.addCleanup(p.stderr.close)
+        self.addCleanup(p.stdin.close)
+        # Wait for the interpreter to be completely initialized before
+        # sending any signal.
+        p.stdout.read(1)
+        getattr(p, method)(*args)
         _, stderr = p.communicate()
         self.assertStderrEqual(stderr, '')
-        self.assertEqual(p.wait(), returncode)
+        returncode = p.wait()
         self.assertNotEqual(returncode, 0)
 
     def test_send_signal(self):
@@ -891,6 +933,7 @@
     def with_spaces(self, *args, **kwargs):
         kwargs['stdout'] = subprocess.PIPE
         p = subprocess.Popen(*args, **kwargs)
+        self.addCleanup(p.stdout.close)
         self.assertEqual(
           p.stdout.read ().decode("mbcs"),
           "2 [%r, 'ab cd']" % self.fname

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_support.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_support.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_support.py	Fri Nov  5 23:50:59 2010
@@ -1004,7 +1004,7 @@
     return obj
 
 def requires_resource(resource):
-    if resource_is_enabled(resource):
+    if is_resource_enabled(resource):
         return _id
     else:
         return unittest.skip("resource {0!r} is not enabled".format(resource))
@@ -1199,3 +1199,23 @@
             return b"".join(chr(x) for x in b)
         except TypeError:
             return bytes(b)
+
+def args_from_interpreter_flags():
+    """Return a list of command-line arguments reproducing the current
+    settings in sys.flags."""
+    flag_opt_map = {
+        'bytes_warning': 'b',
+        'dont_write_bytecode': 'B',
+        'ignore_environment': 'E',
+        'no_user_site': 's',
+        'no_site': 'S',
+        'optimize': 'O',
+        'py3k_warning': '3',
+        'verbose': 'v',
+    }
+    args = []
+    for flag, opt in flag_opt_map.items():
+        v = getattr(sys.flags, flag)
+        if v > 0:
+            args.append('-' + opt * v)
+    return args

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_sys_setprofile.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_sys_setprofile.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_sys_setprofile.py	Fri Nov  5 23:50:59 2010
@@ -1,3 +1,4 @@
+import gc
 import pprint
 import sys
 import unittest
@@ -12,14 +13,14 @@
         sys.setprofile(None)
 
     def test_empty(self):
-        assert sys.getprofile() is None
+        self.assertIsNone(sys.getprofile())
 
     def test_setget(self):
         def fn(*args):
             pass
 
         sys.setprofile(fn)
-        assert sys.getprofile() == fn
+        self.assertIs(sys.getprofile(), fn)
 
 class HookWatcher:
     def __init__(self):
@@ -352,19 +353,19 @@
 
 
 def capture_events(callable, p=None):
-    try:
-        sys.setprofile()
-    except TypeError:
-        pass
-    else:
-        raise test_support.TestFailed(
-            'sys.setprofile() did not raise TypeError')
-
     if p is None:
         p = HookWatcher()
-    sys.setprofile(p.callback)
-    protect(callable, p)
-    sys.setprofile(None)
+    # Disable the garbage collector. This prevents __del__s from showing up in
+    # traces.
+    old_gc = gc.isenabled()
+    gc.disable()
+    try:
+        sys.setprofile(p.callback)
+        protect(callable, p)
+        sys.setprofile(None)
+    finally:
+        if old_gc:
+            gc.enable()
     return p.get_events()[1:-1]
 
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_threading.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_threading.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_threading.py	Fri Nov  5 23:50:59 2010
@@ -307,7 +307,7 @@
         # Issue1733757
         # Avoid a deadlock when sys.settrace steps into threading._shutdown
         import subprocess
-        rc = subprocess.call([sys.executable, "-c", """if 1:
+        p = subprocess.Popen([sys.executable, "-c", """if 1:
             import sys, threading
 
             # A deadlock-killer, to prevent the
@@ -327,9 +327,16 @@
                 return func
 
             sys.settrace(func)
-            """])
+            """],
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE)
+        self.addCleanup(p.stdout.close)
+        self.addCleanup(p.stderr.close)
+        stdout, stderr = p.communicate()
+        rc = p.returncode
         self.assertFalse(rc == 2, "interpreted was blocked")
-        self.assertTrue(rc == 0, "Unexpected error")
+        self.assertTrue(rc == 0,
+                        "Unexpected error: " + repr(stderr))
 
     def test_join_nondaemon_on_shutdown(self):
         # Issue 1722344
@@ -350,6 +357,8 @@
             """],
             stdout=subprocess.PIPE,
             stderr=subprocess.PIPE)
+        self.addCleanup(p.stdout.close)
+        self.addCleanup(p.stderr.close)
         stdout, stderr = p.communicate()
         self.assertEqual(stdout.strip(),
             "Woke up, sleep function is: <built-in function sleep>")
@@ -423,6 +432,7 @@
         p = subprocess.Popen([sys.executable, "-c", script], stdout=subprocess.PIPE)
         rc = p.wait()
         data = p.stdout.read().replace('\r', '')
+        p.stdout.close()
         self.assertEqual(data, "end of main\nend of thread\n")
         self.assertFalse(rc == 2, "interpreter was blocked")
         self.assertTrue(rc == 0, "Unexpected error")
@@ -466,7 +476,8 @@
             return
         # Skip platforms with known problems forking from a worker thread.
         # See http://bugs.python.org/issue3863.
-        if sys.platform in ('freebsd4', 'freebsd5', 'freebsd6', 'os2emx'):
+        if sys.platform in ('freebsd4', 'freebsd5', 'freebsd6', 'netbsd5',
+                           'os2emx'):
             print >>sys.stderr, ('Skipping test_3_join_in_forked_from_thread'
                                  ' due to known OS bugs on'), sys.platform
             return

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_timeout.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_timeout.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_timeout.py	Fri Nov  5 23:50:59 2010
@@ -130,17 +130,19 @@
     def testRecvTimeout(self):
         # Test recv() timeout
         _timeout = 0.02
-        self.sock.connect(self.addr_remote)
-        self.sock.settimeout(_timeout)
-
-        _t1 = time.time()
-        self.assertRaises(socket.error, self.sock.recv, 1024)
-        _t2 = time.time()
 
-        _delta = abs(_t1 - _t2)
-        self.assertTrue(_delta < _timeout + self.fuzz,
-                     "timeout (%g) is %g seconds more than expected (%g)"
-                     %(_delta, self.fuzz, _timeout))
+        with test_support.transient_internet(self.addr_remote[0]):
+            self.sock.connect(self.addr_remote)
+            self.sock.settimeout(_timeout)
+
+            _t1 = time.time()
+            self.assertRaises(socket.timeout, self.sock.recv, 1024)
+            _t2 = time.time()
+
+            _delta = abs(_t1 - _t2)
+            self.assertTrue(_delta < _timeout + self.fuzz,
+                         "timeout (%g) is %g seconds more than expected (%g)"
+                         %(_delta, self.fuzz, _timeout))
 
     def testAcceptTimeout(self):
         # Test accept() timeout

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_tokenize.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_tokenize.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_tokenize.py	Fri Nov  5 23:50:59 2010
@@ -493,13 +493,13 @@
     True
 
 Test roundtrip on random python modules.
-pass the '-ucompiler' option to process the full directory.
+pass the '-ucpu' option to process the full directory.
 
     >>>
     >>> tempdir = os.path.dirname(f) or os.curdir
     >>> testfiles = glob.glob(os.path.join(tempdir, "test*.py"))
 
-    >>> if not test_support.is_resource_enabled("compiler"):
+    >>> if not test_support.is_resource_enabled("cpu"):
     ...     testfiles = random.sample(testfiles, 10)
     ...
     >>> for testfile in testfiles:

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_trace.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_trace.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_trace.py	Fri Nov  5 23:50:59 2010
@@ -186,7 +186,6 @@
             }
             self.assertEqual(tracer.results().counts, expected)
 
-
 class TestRunExecCounts(unittest.TestCase):
     """A simple sanity test of line-counting, via runctx (exec)"""
     def setUp(self):
@@ -283,8 +282,9 @@
         rmtree(TESTFN)
         unlink(TESTFN)
 
-    def _coverage(self, tracer):
-        tracer.run('from test import test_pprint; test_pprint.test_main()')
+    def _coverage(self, tracer,
+                  cmd='from test import test_pprint; test_pprint.test_main()'):
+        tracer.run(cmd)
         r = tracer.results()
         r.write_results(show_missing=True, summary=True, coverdir=TESTFN)
 
@@ -311,6 +311,27 @@
             files = os.listdir(TESTFN)
             self.assertEquals(files, [])
 
+    def test_issue9936(self):
+        tracer = trace.Trace(trace=0, count=1)
+        modname = 'test.tracedmodules.testmod'
+        # Ensure that the module is executed in import
+        if modname in sys.modules:
+            del sys.modules[modname]
+        cmd = ("import test.tracedmodules.testmod as t;"
+               "t.func(0); t.func2();")
+        with captured_stdout() as stdout:
+            self._coverage(tracer, cmd)
+        stdout.seek(0)
+        stdout.readline()
+        coverage = {}
+        for line in stdout:
+            lines, cov, module = line.split()[:3]
+            coverage[module] = (int(lines), int(cov[:-1]))
+        # XXX This is needed to run regrtest.py as a script
+        modname = trace.fullmodname(sys.modules[modname].__file__)
+        self.assertIn(modname, coverage)
+        self.assertEqual(coverage[modname], (5, 100))
+
 
 def test_main():
     run_unittest(__name__)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_unicode.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_unicode.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_unicode.py	Fri Nov  5 23:50:59 2010
@@ -1,4 +1,3 @@
-# -*- coding: iso-8859-1 -*-
 """ Test script for the Unicode implementation.
 
 Written by Marc-Andre Lemburg (mal at lemburg.com).

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_urllib2net.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_urllib2net.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_urllib2net.py	Fri Nov  5 23:50:59 2010
@@ -156,10 +156,35 @@
 
     def test_urlwithfrag(self):
         urlwith_frag = "http://docs.python.org/glossary.html#glossary"
-        req = urllib2.Request(urlwith_frag)
-        res = urllib2.urlopen(req)
-        self.assertEqual(res.geturl(),
-                "http://docs.python.org/glossary.html")
+        with test_support.transient_internet(urlwith_frag):
+            req = urllib2.Request(urlwith_frag)
+            res = urllib2.urlopen(req)
+            self.assertEqual(res.geturl(),
+                    "http://docs.python.org/glossary.html")
+
+    def test_fileno(self):
+        req = urllib2.Request("http://www.python.org")
+        opener = urllib2.build_opener()
+        res = opener.open(req)
+        try:
+            res.fileno()
+        except AttributeError:
+            self.fail("HTTPResponse object should return a valid fileno")
+        finally:
+            res.close()
+
+    def test_custom_headers(self):
+        url = "http://www.example.com"
+        with test_support.transient_internet(url):
+            opener = urllib2.build_opener()
+            request = urllib2.Request(url)
+            self.assertFalse(request.header_items())
+            opener.open(request)
+            self.assertTrue(request.header_items())
+            self.assertTrue(request.has_header('User-agent'))
+            request.add_header('User-Agent','Test-Agent')
+            opener.open(request)
+            self.assertEqual(request.get_header('User-agent'),'Test-Agent')
 
     def _test_urls(self, urls, handlers, retry=True):
         import time
@@ -175,29 +200,30 @@
                 url, req, expected_err = url
             else:
                 req = expected_err = None
-            debug(url)
-            try:
-                f = urlopen(url, req, TIMEOUT)
-            except EnvironmentError, err:
-                debug(err)
-                if expected_err:
-                    msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" %
-                           (expected_err, url, req, type(err), err))
-                    self.assertIsInstance(err, expected_err, msg)
-            except urllib2.URLError as err:
-                if isinstance(err[0], socket.timeout):
-                    print >>sys.stderr, "<timeout: %s>" % url
-                    continue
-                else:
-                    raise
-            else:
+            with test_support.transient_internet(url):
+                debug(url)
                 try:
-                    with test_support.transient_internet(url):
-                        buf = f.read()
-                        debug("read %d bytes" % len(buf))
-                except socket.timeout:
-                    print >>sys.stderr, "<timeout: %s>" % url
-                f.close()
+                    f = urlopen(url, req, TIMEOUT)
+                except EnvironmentError as err:
+                    debug(err)
+                    if expected_err:
+                        msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" %
+                               (expected_err, url, req, type(err), err))
+                        self.assertIsInstance(err, expected_err, msg)
+                except urllib2.URLError as err:
+                    if isinstance(err[0], socket.timeout):
+                        print >>sys.stderr, "<timeout: %s>" % url
+                        continue
+                    else:
+                        raise
+                else:
+                    try:
+                        with test_support.transient_internet(url):
+                            buf = f.read()
+                            debug("read %d bytes" % len(buf))
+                    except socket.timeout:
+                        print >>sys.stderr, "<timeout: %s>" % url
+                    f.close()
             debug("******** next url coming up...")
             time.sleep(0.1)
 
@@ -214,59 +240,71 @@
 class TimeoutTest(unittest.TestCase):
     def test_http_basic(self):
         self.assertTrue(socket.getdefaulttimeout() is None)
-        u = _urlopen_with_retry("http://www.python.org")
-        self.assertTrue(u.fp._sock.fp._sock.gettimeout() is None)
+        url = "http://www.python.org"
+        with test_support.transient_internet(url, timeout=None):
+            u = _urlopen_with_retry(url)
+            self.assertTrue(u.fp._sock.fp._sock.gettimeout() is None)
 
     def test_http_default_timeout(self):
         self.assertTrue(socket.getdefaulttimeout() is None)
-        socket.setdefaulttimeout(60)
-        try:
-            u = _urlopen_with_retry("http://www.python.org")
-        finally:
-            socket.setdefaulttimeout(None)
-        self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 60)
+        url = "http://www.python.org"
+        with test_support.transient_internet(url):
+            socket.setdefaulttimeout(60)
+            try:
+                u = _urlopen_with_retry(url)
+            finally:
+                socket.setdefaulttimeout(None)
+            self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 60)
 
     def test_http_no_timeout(self):
         self.assertTrue(socket.getdefaulttimeout() is None)
-        socket.setdefaulttimeout(60)
-        try:
-            u = _urlopen_with_retry("http://www.python.org", timeout=None)
-        finally:
-            socket.setdefaulttimeout(None)
-        self.assertTrue(u.fp._sock.fp._sock.gettimeout() is None)
+        url = "http://www.python.org"
+        with test_support.transient_internet(url):
+            socket.setdefaulttimeout(60)
+            try:
+                u = _urlopen_with_retry(url, timeout=None)
+            finally:
+                socket.setdefaulttimeout(None)
+            self.assertTrue(u.fp._sock.fp._sock.gettimeout() is None)
 
     def test_http_timeout(self):
-        u = _urlopen_with_retry("http://www.python.org", timeout=120)
-        self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 120)
+        url = "http://www.python.org"
+        with test_support.transient_internet(url):
+            u = _urlopen_with_retry(url, timeout=120)
+            self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 120)
 
     FTP_HOST = "ftp://ftp.mirror.nl/pub/gnu/"
 
     def test_ftp_basic(self):
         self.assertTrue(socket.getdefaulttimeout() is None)
-        u = _urlopen_with_retry(self.FTP_HOST)
-        self.assertTrue(u.fp.fp._sock.gettimeout() is None)
+        with test_support.transient_internet(self.FTP_HOST, timeout=None):
+            u = _urlopen_with_retry(self.FTP_HOST)
+            self.assertTrue(u.fp.fp._sock.gettimeout() is None)
 
     def test_ftp_default_timeout(self):
         self.assertTrue(socket.getdefaulttimeout() is None)
-        socket.setdefaulttimeout(60)
-        try:
-            u = _urlopen_with_retry(self.FTP_HOST)
-        finally:
-            socket.setdefaulttimeout(None)
-        self.assertEqual(u.fp.fp._sock.gettimeout(), 60)
+        with test_support.transient_internet(self.FTP_HOST):
+            socket.setdefaulttimeout(60)
+            try:
+                u = _urlopen_with_retry(self.FTP_HOST)
+            finally:
+                socket.setdefaulttimeout(None)
+            self.assertEqual(u.fp.fp._sock.gettimeout(), 60)
 
     def test_ftp_no_timeout(self):
         self.assertTrue(socket.getdefaulttimeout() is None)
-        socket.setdefaulttimeout(60)
-        try:
-            u = _urlopen_with_retry(self.FTP_HOST, timeout=None)
-        finally:
-            socket.setdefaulttimeout(None)
-        self.assertTrue(u.fp.fp._sock.gettimeout() is None)
+        with test_support.transient_internet(self.FTP_HOST):
+            socket.setdefaulttimeout(60)
+            try:
+                u = _urlopen_with_retry(self.FTP_HOST, timeout=None)
+            finally:
+                socket.setdefaulttimeout(None)
+            self.assertTrue(u.fp.fp._sock.gettimeout() is None)
 
     def test_ftp_timeout(self):
-        u = _urlopen_with_retry(self.FTP_HOST, timeout=60)
-        self.assertEqual(u.fp.fp._sock.gettimeout(), 60)
+        with test_support.transient_internet(self.FTP_HOST):
+            u = _urlopen_with_retry(self.FTP_HOST, timeout=60)
+            self.assertEqual(u.fp.fp._sock.gettimeout(), 60)
 
 
 def test_main():

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_uu.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_uu.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_uu.py	Fri Nov  5 23:50:59 2010
@@ -161,6 +161,23 @@
         finally:
             self._kill(f)
 
+    def test_decode_filename(self):
+        f = None
+        try:
+            test_support.unlink(self.tmpin)
+            f = open(self.tmpin, 'w')
+            f.write(encodedtextwrapped % (0644, self.tmpout))
+            f.close()
+
+            uu.decode(self.tmpin)
+
+            f = open(self.tmpout, 'r')
+            s = f.read()
+            f.close()
+            self.assertEqual(s, plaintext)
+        finally:
+            self._kill(f)
+
     def test_decodetwice(self):
         # Verify that decode() will refuse to overwrite an existing file
         f = None

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_winreg.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_winreg.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_winreg.py	Fri Nov  5 23:50:59 2010
@@ -261,7 +261,8 @@
         finally:
             done = True
             thread.join()
-            DeleteKey(HKEY_CURRENT_USER, test_key_name+'\\changing_value')
+            with OpenKey(HKEY_CURRENT_USER, test_key_name, 0, KEY_ALL_ACCESS) as key:
+                DeleteKey(key, 'changing_value')
             DeleteKey(HKEY_CURRENT_USER, test_key_name)
 
     def test_long_key(self):
@@ -275,7 +276,8 @@
                 num_subkeys, num_values, t = QueryInfoKey(key)
                 EnumKey(key, 0)
         finally:
-            DeleteKey(HKEY_CURRENT_USER, '\\'.join((test_key_name, name)))
+            with OpenKey(HKEY_CURRENT_USER, test_key_name, 0, KEY_ALL_ACCESS) as key:
+                DeleteKey(key, name)
             DeleteKey(HKEY_CURRENT_USER, test_key_name)
 
     def test_dynamic_key(self):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_xml_etree.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_xml_etree.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_xml_etree.py	Fri Nov  5 23:50:59 2010
@@ -586,10 +586,13 @@
        <ns0:empty-element />
     </ns0:root>
 
+    >>> with open(SIMPLE_XMLFILE) as f:
+    ...     data = f.read()
+
     >>> parser = ET.XMLParser()
     >>> parser.version  # doctest: +ELLIPSIS
     'Expat ...'
-    >>> parser.feed(open(SIMPLE_XMLFILE).read())
+    >>> parser.feed(data)
     >>> print serialize(parser.close())
     <root>
        <element key="value">text</element>
@@ -598,7 +601,7 @@
     </root>
 
     >>> parser = ET.XMLTreeBuilder() # 1.2 compatibility
-    >>> parser.feed(open(SIMPLE_XMLFILE).read())
+    >>> parser.feed(data)
     >>> print serialize(parser.close())
     <root>
        <element key="value">text</element>
@@ -608,7 +611,7 @@
 
     >>> target = ET.TreeBuilder()
     >>> parser = ET.XMLParser(target=target)
-    >>> parser.feed(open(SIMPLE_XMLFILE).read())
+    >>> parser.feed(data)
     >>> print serialize(parser.close())
     <root>
        <element key="value">text</element>
@@ -711,7 +714,8 @@
     end-ns None
 
     >>> events = ("start", "end", "bogus")
-    >>> context = iterparse(SIMPLE_XMLFILE, events)
+    >>> with open(SIMPLE_XMLFILE, "rb") as f:
+    ...     iterparse(f, events)
     Traceback (most recent call last):
     ValueError: unknown event 'bogus'
 
@@ -763,6 +767,8 @@
     """
     Test parser w. custom builder.
 
+    >>> with open(SIMPLE_XMLFILE) as f:
+    ...     data = f.read()
     >>> class Builder:
     ...     def start(self, tag, attrib):
     ...         print "start", tag
@@ -772,7 +778,7 @@
     ...         pass
     >>> builder = Builder()
     >>> parser = ET.XMLParser(target=builder)
-    >>> parser.feed(open(SIMPLE_XMLFILE, "r").read())
+    >>> parser.feed(data)
     start root
     start element
     end element
@@ -782,6 +788,8 @@
     end empty-element
     end root
 
+    >>> with open(SIMPLE_NS_XMLFILE) as f:
+    ...     data = f.read()
     >>> class Builder:
     ...     def start(self, tag, attrib):
     ...         print "start", tag
@@ -795,7 +803,7 @@
     ...         print "comment", repr(data)
     >>> builder = Builder()
     >>> parser = ET.XMLParser(target=builder)
-    >>> parser.feed(open(SIMPLE_NS_XMLFILE, "r").read())
+    >>> parser.feed(data)
     pi pi 'data'
     comment ' comment '
     start {namespace}root
@@ -813,7 +821,8 @@
     """
     Test Element.getchildren()
 
-    >>> tree = ET.parse(open(SIMPLE_XMLFILE, "r"))
+    >>> with open(SIMPLE_XMLFILE, "r") as f:
+    ...     tree = ET.parse(f)
     >>> for elem in tree.getroot().iter():
     ...     summarize_list(elem.getchildren())
     ['element', 'element', 'empty-element']

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/test_xpickle.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/test_xpickle.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/test_xpickle.py	Fri Nov  5 23:50:59 2010
@@ -57,7 +57,8 @@
         return cPickle.loads(buf)
 
 def have_python_version(name):
-    """Check whether the given name is a valid Python binary.
+    """Check whether the given name is a valid Python binary and has
+    test.test_support.
 
     This respects your PATH.
 
@@ -67,7 +68,7 @@
     Returns:
         True if the name is valid, False otherwise.
     """
-    return os.system(name + " -c 'import sys; sys.exit()'") == 0
+    return os.system(name + " -c 'import test.test_support'") == 0
 
 
 class AbstractCompatTests(AbstractPickleTests):

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/tracedmodules/testmod.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/tracedmodules/testmod.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/tracedmodules/testmod.py	Fri Nov  5 23:50:59 2010
@@ -1,3 +1,9 @@
 def func(x):
     b = x + 1
     return b + 2
+
+def func2():
+    """Test function for issue 9936 """
+    return (1,
+            2,
+            3)

Modified: pypy/branch/fast-forward/lib-python/2.7.0/test/win_console_handler.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/test/win_console_handler.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/test/win_console_handler.py	Fri Nov  5 23:50:59 2010
@@ -8,12 +8,14 @@
 similar example in C.
 """
 
-from ctypes import wintypes
+from ctypes import wintypes, WINFUNCTYPE
 import signal
 import ctypes
+import mmap
+import sys
 
 # Function prototype for the handler function. Returns BOOL, takes a DWORD.
-HandlerRoutine = wintypes.WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD)
+HandlerRoutine = WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD)
 
 def _ctrl_handler(sig):
     """Handle a sig event and return 0 to terminate the process"""
@@ -38,6 +40,10 @@
         print("Unable to add SetConsoleCtrlHandler")
         exit(-1)
 
+    # Awaken mail process
+    m = mmap.mmap(-1, 1, sys.argv[1])
+    m[0] = '1'
+
     # Do nothing but wait for the signal
     while True:
         pass

Modified: pypy/branch/fast-forward/lib-python/2.7.0/trace.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/trace.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/trace.py	Fri Nov  5 23:50:59 2010
@@ -58,7 +58,7 @@
 import tokenize
 import inspect
 import gc
-
+import dis
 try:
     import cPickle
     pickle = cPickle
@@ -379,13 +379,7 @@
     """Return dict where keys are lines in the line number table."""
     linenos = {}
 
-    line_increments = [ord(c) for c in code.co_lnotab[1::2]]
-    table_length = len(line_increments)
-    docstring = False
-
-    lineno = code.co_firstlineno
-    for li in line_increments:
-        lineno += li
+    for _, lineno in dis.findlinestarts(code):
         if lineno not in strs:
             linenos[lineno] = 1
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/unittest/result.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/unittest/result.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/unittest/result.py	Fri Nov  5 23:50:59 2010
@@ -35,6 +35,7 @@
     formatted traceback of the error that occurred.
     """
     _previousTestClass = None
+    _testRunEntered = False
     _moduleSetUpFailed = False
     def __init__(self, stream=None, descriptions=None, verbosity=None):
         self.failfast = False

Modified: pypy/branch/fast-forward/lib-python/2.7.0/unittest/suite.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/unittest/suite.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/unittest/suite.py	Fri Nov  5 23:50:59 2010
@@ -80,23 +80,11 @@
     subclassing, do not forget to call the base class constructor.
     """
 
+    def run(self, result, debug=False):
+        topLevel = False
+        if getattr(result, '_testRunEntered', False) is False:
+            result._testRunEntered = topLevel = True
 
-    def run(self, result):
-        self._wrapped_run(result)
-        self._tearDownPreviousClass(None, result)
-        self._handleModuleTearDown(result)
-        return result
-
-    def debug(self):
-        """Run the tests without collecting errors in a TestResult"""
-        debug = _DebugResult()
-        self._wrapped_run(debug, True)
-        self._tearDownPreviousClass(None, debug)
-        self._handleModuleTearDown(debug)
-
-    ################################
-    # private methods
-    def _wrapped_run(self, result, debug=False):
         for test in self:
             if result.shouldStop:
                 break
@@ -111,13 +99,23 @@
                     getattr(result, '_moduleSetUpFailed', False)):
                     continue
 
-            if hasattr(test, '_wrapped_run'):
-                test._wrapped_run(result, debug)
-            elif not debug:
+            if not debug:
                 test(result)
             else:
                 test.debug()
 
+        if topLevel:
+            self._tearDownPreviousClass(None, result)
+            self._handleModuleTearDown(result)
+        return result
+
+    def debug(self):
+        """Run the tests without collecting errors in a TestResult"""
+        debug = _DebugResult()
+        self.run(debug, True)
+
+    ################################
+
     def _handleClassSetUp(self, test, result):
         previousClass = getattr(result, '_previousTestClass', None)
         currentClass = test.__class__

Modified: pypy/branch/fast-forward/lib-python/2.7.0/unittest/test/test_suite.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/unittest/test/test_suite.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/unittest/test/test_suite.py	Fri Nov  5 23:50:59 2010
@@ -345,5 +345,19 @@
         self.assertEqual(result.testsRun, 2)
 
 
+    def test_overriding_call(self):
+        class MySuite(unittest.TestSuite):
+            called = False
+            def __call__(self, *args, **kw):
+                self.called = True
+                unittest.TestSuite.__call__(self, *args, **kw)
+
+        suite = MySuite()
+        wrapper = unittest.TestSuite()
+        wrapper.addTest(suite)
+        wrapper(unittest.TestResult())
+        self.assertTrue(suite.called)
+
+
 if __name__ == '__main__':
     unittest.main()

Modified: pypy/branch/fast-forward/lib-python/2.7.0/urllib.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/urllib.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/urllib.py	Fri Nov  5 23:50:59 2010
@@ -1189,8 +1189,7 @@
                'abcdefghijklmnopqrstuvwxyz'
                '0123456789' '_.-')
 _safe_map = {}
-for i in xrange(256):
-    c = chr(i)
+for i, c in zip(xrange(256), str(bytearray(xrange(256)))):
     _safe_map[c] = c if (i < 128 and c in always_safe) else '%{:02X}'.format(i)
 _safe_quoters = {}
 

Modified: pypy/branch/fast-forward/lib-python/2.7.0/urllib2.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/urllib2.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/urllib2.py	Fri Nov  5 23:50:59 2010
@@ -1127,8 +1127,10 @@
         h = http_class(host, timeout=req.timeout) # will parse host:port
         h.set_debuglevel(self._debuglevel)
 
-        headers = dict(req.headers)
-        headers.update(req.unredirected_hdrs)
+        headers = dict(req.unredirected_hdrs)
+        headers.update(dict((k, v) for k, v in req.headers.items()
+                            if k not in headers))
+
         # We want to make an HTTP/1.1 request, but the addinfourl
         # class isn't prepared to deal with a persistent connection.
         # It will try to read all remaining data from the socket,

Modified: pypy/branch/fast-forward/lib-python/2.7.0/uu.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/uu.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/uu.py	Fri Nov  5 23:50:59 2010
@@ -44,40 +44,47 @@
     #
     # If in_file is a pathname open it and change defaults
     #
-    if in_file == '-':
-        in_file = sys.stdin
-    elif isinstance(in_file, basestring):
+    opened_files = []
+    try:
+        if in_file == '-':
+            in_file = sys.stdin
+        elif isinstance(in_file, basestring):
+            if name is None:
+                name = os.path.basename(in_file)
+            if mode is None:
+                try:
+                    mode = os.stat(in_file).st_mode
+                except AttributeError:
+                    pass
+            in_file = open(in_file, 'rb')
+            opened_files.append(in_file)
+        #
+        # Open out_file if it is a pathname
+        #
+        if out_file == '-':
+            out_file = sys.stdout
+        elif isinstance(out_file, basestring):
+            out_file = open(out_file, 'wb')
+            opened_files.append(out_file)
+        #
+        # Set defaults for name and mode
+        #
         if name is None:
-            name = os.path.basename(in_file)
+            name = '-'
         if mode is None:
-            try:
-                mode = os.stat(in_file).st_mode
-            except AttributeError:
-                pass
-        in_file = open(in_file, 'rb')
-    #
-    # Open out_file if it is a pathname
-    #
-    if out_file == '-':
-        out_file = sys.stdout
-    elif isinstance(out_file, basestring):
-        out_file = open(out_file, 'w')
-    #
-    # Set defaults for name and mode
-    #
-    if name is None:
-        name = '-'
-    if mode is None:
-        mode = 0666
-    #
-    # Write the data
-    #
-    out_file.write('begin %o %s\n' % ((mode&0777),name))
-    data = in_file.read(45)
-    while len(data) > 0:
-        out_file.write(binascii.b2a_uu(data))
+            mode = 0666
+        #
+        # Write the data
+        #
+        out_file.write('begin %o %s\n' % ((mode&0777),name))
         data = in_file.read(45)
-    out_file.write(' \nend\n')
+        while len(data) > 0:
+            out_file.write(binascii.b2a_uu(data))
+            data = in_file.read(45)
+        out_file.write(' \nend\n')
+    finally:
+        for f in opened_files:
+            f.close()
 
 
 def decode(in_file, out_file=None, mode=None, quiet=0):
@@ -85,65 +92,68 @@
     #
     # Open the input file, if needed.
     #
+    opened_files = []
     if in_file == '-':
         in_file = sys.stdin
     elif isinstance(in_file, basestring):
         in_file = open(in_file)
-    #
-    # Read until a begin is encountered or we've exhausted the file
-    #
-    while True:
-        hdr = in_file.readline()
-        if not hdr:
-            raise Error('No valid begin line found in input file')
-        if not hdr.startswith('begin'):
-            continue
-        hdrfields = hdr.split(' ', 2)
-        if len(hdrfields) == 3 and hdrfields[0] == 'begin':
+        opened_files.append(in_file)
+    try:
+        #
+        # Read until a begin is encountered or we've exhausted the file
+        #
+        while True:
+            hdr = in_file.readline()
+            if not hdr:
+                raise Error('No valid begin line found in input file')
+            if not hdr.startswith('begin'):
+                continue
+            hdrfields = hdr.split(' ', 2)
+            if len(hdrfields) == 3 and hdrfields[0] == 'begin':
+                try:
+                    int(hdrfields[1], 8)
+                    break
+                except ValueError:
+                    pass
+        if out_file is None:
+            out_file = hdrfields[2].rstrip()
+            if os.path.exists(out_file):
+                raise Error('Cannot overwrite existing file: %s' % out_file)
+        if mode is None:
+            mode = int(hdrfields[1], 8)
+        #
+        # Open the output file
+        #
+        if out_file == '-':
+            out_file = sys.stdout
+        elif isinstance(out_file, basestring):
+            fp = open(out_file, 'wb')
             try:
-                int(hdrfields[1], 8)
-                break
-            except ValueError:
+                os.path.chmod(out_file, mode)
+            except AttributeError:
                 pass
-    if out_file is None:
-        out_file = hdrfields[2].rstrip()
-        if os.path.exists(out_file):
-            raise Error('Cannot overwrite existing file: %s' % out_file)
-    if mode is None:
-        mode = int(hdrfields[1], 8)
-    #
-    # Open the output file
-    #
-    opened = False
-    if out_file == '-':
-        out_file = sys.stdout
-    elif isinstance(out_file, basestring):
-        fp = open(out_file, 'wb')
-        try:
-            os.path.chmod(out_file, mode)
-        except AttributeError:
-            pass
-        out_file = fp
-        opened = True
-    #
-    # Main decoding loop
-    #
-    s = in_file.readline()
-    while s and s.strip() != 'end':
-        try:
-            data = binascii.a2b_uu(s)
-        except binascii.Error, v:
-            # Workaround for broken uuencoders by /Fredrik Lundh
-            nbytes = (((ord(s[0])-32) & 63) * 4 + 5) // 3
-            data = binascii.a2b_uu(s[:nbytes])
-            if not quiet:
-                sys.stderr.write("Warning: %s\n" % v)
-        out_file.write(data)
+            out_file = fp
+            opened_files.append(out_file)
+        #
+        # Main decoding loop
+        #
         s = in_file.readline()
-    if not s:
-        raise Error('Truncated input file')
-    if opened:
-        out_file.close()
+        while s and s.strip() != 'end':
+            try:
+                data = binascii.a2b_uu(s)
+            except binascii.Error, v:
+                # Workaround for broken uuencoders by /Fredrik Lundh
+                nbytes = (((ord(s[0])-32) & 63) * 4 + 5) // 3
+                data = binascii.a2b_uu(s[:nbytes])
+                if not quiet:
+                    sys.stderr.write("Warning: %s\n" % v)
+            out_file.write(data)
+            s = in_file.readline()
+        if not s:
+            raise Error('Truncated input file')
+    finally:
+        for f in opened_files:
+            f.close()
 
 def test():
     """uuencode/uudecode main program"""

Modified: pypy/branch/fast-forward/lib-python/2.7.0/uuid.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/uuid.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/uuid.py	Fri Nov  5 23:50:59 2010
@@ -302,15 +302,15 @@
             # LC_ALL to get English output, 2>/dev/null to
             # prevent output on stderr
             cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
-            pipe = os.popen(cmd)
+            with os.popen(cmd) as pipe:
+                for line in pipe:
+                    words = line.lower().split()
+                    for i in range(len(words)):
+                        if words[i] in hw_identifiers:
+                            return int(
+                                words[get_index(i)].replace(':', ''), 16)
         except IOError:
             continue
-
-        for line in pipe:
-            words = line.lower().split()
-            for i in range(len(words)):
-                if words[i] in hw_identifiers:
-                    return int(words[get_index(i)].replace(':', ''), 16)
     return None
 
 def _ifconfig_getnode():
@@ -353,10 +353,13 @@
             pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all')
         except IOError:
             continue
-        for line in pipe:
-            value = line.split(':')[-1].strip().lower()
-            if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value):
-                return int(value.replace('-', ''), 16)
+        else:
+            for line in pipe:
+                value = line.split(':')[-1].strip().lower()
+                if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value):
+                    return int(value.replace('-', ''), 16)
+        finally:
+            pipe.close()
 
 def _netbios_getnode():
     """Get the hardware address on Windows using NetBIOS calls.

Modified: pypy/branch/fast-forward/lib-python/2.7.0/xml/dom/expatbuilder.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/xml/dom/expatbuilder.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/xml/dom/expatbuilder.py	Fri Nov  5 23:50:59 2010
@@ -242,7 +242,7 @@
         doctype = self.document.implementation.createDocumentType(
             doctypeName, publicId, systemId)
         doctype.ownerDocument = self.document
-        self.document.childNodes.append(doctype)
+        _append_child(self.document, doctype)
         self.document.doctype = doctype
         if self._filter and self._filter.acceptNode(doctype) == FILTER_REJECT:
             self.document.doctype = None

Modified: pypy/branch/fast-forward/lib-python/2.7.0/xml/sax/saxutils.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/2.7.0/xml/sax/saxutils.py	(original)
+++ pypy/branch/fast-forward/lib-python/2.7.0/xml/sax/saxutils.py	Fri Nov  5 23:50:59 2010
@@ -103,6 +103,12 @@
     def _qname(self, name):
         """Builds a qualified name from a (ns_url, localname) pair"""
         if name[0]:
+            # Per http://www.w3.org/XML/1998/namespace, The 'xml' prefix is
+            # bound by definition to http://www.w3.org/XML/1998/namespace.  It
+            # does not need to be declared and will not usually be found in
+            # self._current_context.
+            if 'http://www.w3.org/XML/1998/namespace' == name[0]:
+                return 'xml:' + name[1]
             # The name is in a non-empty namespace
             prefix = self._current_context[name[0]]
             if prefix:



More information about the Pypy-commit mailing list