Merged revisions 66766-66767,66771-66772,66774,66776,66783-66787,66790,66793,66797 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

................
  r66766 | benjamin.peterson | 2008-10-03 06:52:06 -0500 (Fri, 03 Oct 2008) | 1 line

  update the mac installer script
................
  r66767 | andrew.kuchling | 2008-10-03 07:26:42 -0500 (Fri, 03 Oct 2008) | 1 line

  Docstring typo.
................
  r66771 | hirokazu.yamamoto | 2008-10-03 11:18:42 -0500 (Fri, 03 Oct 2008) | 2 lines

  Fixed following error when DocXMLRPCServer failed.
    UnboundLocalError: local variable 'serv' referenced before assignment
................
  r66772 | andrew.kuchling | 2008-10-03 11:29:19 -0500 (Fri, 03 Oct 2008) | 1 line

  Mention exception in docstring
................
  r66774 | andrew.kuchling | 2008-10-03 11:42:52 -0500 (Fri, 03 Oct 2008) | 1 line

  Typo fix
................
  r66776 | hirokazu.yamamoto | 2008-10-03 12:34:49 -0500 (Fri, 03 Oct 2008) | 2 lines

  Issue #1706863: Fixed "'NoneType' object has no attribute 'rfind'" error when sqlite libfile not found.
................
  r66783 | andrew.kuchling | 2008-10-03 20:02:29 -0500 (Fri, 03 Oct 2008) | 1 line

  Use correct capitalization of NaN
................
  r66784 | andrew.kuchling | 2008-10-03 20:03:42 -0500 (Fri, 03 Oct 2008) | 1 line

  Docstring change: Specify exception raised
................
  r66785 | andrew.kuchling | 2008-10-03 20:04:24 -0500 (Fri, 03 Oct 2008) | 1 line

  Docstring changes: Specify exceptions raised
................
  r66786 | andrew.kuchling | 2008-10-03 20:05:56 -0500 (Fri, 03 Oct 2008) | 3 lines

  Docstring change for *partition: use same tense as other docstrings.
  Hyphenate left- and right-justified.
  Fix 'registerd' typo
................
  r66787 | andrew.kuchling | 2008-10-03 22:08:56 -0500 (Fri, 03 Oct 2008) | 1 line

  two corrections
................
  r66790 | andrew.kuchling | 2008-10-04 11:52:01 -0500 (Sat, 04 Oct 2008) | 1 line

  Set svn:keywords
................
  r66793 | georg.brandl | 2008-10-04 13:26:01 -0500 (Sat, 04 Oct 2008) | 2 lines

  #4041: don't refer to removed and outdated modules.
................
  r66797 | benjamin.peterson | 2008-10-04 15:55:50 -0500 (Sat, 04 Oct 2008) | 19 lines

  Merged revisions 66707,66775,66782 via svnmerge from
  svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3

  ........
    r66707 | benjamin.peterson | 2008-09-30 18:27:10 -0500 (Tue, 30 Sep 2008) | 1 line

    fix #4001: fix_imports didn't check for __init__.py before converting to relative imports
  ........
    r66775 | collin.winter | 2008-10-03 12:08:26 -0500 (Fri, 03 Oct 2008) | 4 lines

    Add an alternative iterative pattern matching system that, while slower, correctly parses files that cause the faster recursive pattern matcher to fail with a recursion error. lib2to3 falls back to the iterative matcher if the recursive one fails.

    Fixes http://bugs.python.org/issue2532. Thanks to Nick Edds.
  ........
    r66782 | benjamin.peterson | 2008-10-03 17:51:36 -0500 (Fri, 03 Oct 2008) | 1 line

    add Victor Stinner's fixer for os.getcwdu -> os.getcwd #4023
  ........
................
diff --git a/Lib/lib2to3/pytree.py b/Lib/lib2to3/pytree.py
index cd988ac..08198fd 100644
--- a/Lib/lib2to3/pytree.py
+++ b/Lib/lib2to3/pytree.py
@@ -655,10 +655,47 @@
         elif self.name == "bare_name":
             yield self._bare_name_matches(nodes)
         else:
-            for count, r in self._recursive_matches(nodes, 0):
-                if self.name:
-                    r[self.name] = nodes[:count]
-                yield count, r
+            try:
+                for count, r in self._recursive_matches(nodes, 0):
+                    if self.name:
+                        r[self.name] = nodes[:count]
+                    yield count, r
+            except RuntimeError:
+                # We fall back to the iterative pattern matching scheme if the recursive
+                # scheme hits the recursion limit.
+                for count, r in self._iterative_matches(nodes):
+                    if self.name:
+                        r[self.name] = nodes[:count]
+                    yield count, r
+
+    def _iterative_matches(self, nodes):
+        """Helper to iteratively yield the matches."""
+        nodelen = len(nodes)
+        if 0 >= self.min:
+            yield 0, {}
+
+        results = []
+        # generate matches that use just one alt from self.content
+        for alt in self.content:
+            for c, r in generate_matches(alt, nodes):
+                yield c, r
+                results.append((c, r))
+
+        # for each match, iterate down the nodes
+        while results:
+            new_results = []
+            for c0, r0 in results:
+                # stop if the entire set of nodes has been matched
+                if c0 < nodelen and c0 <= self.max:
+                    for alt in self.content:
+                        for c1, r1 in generate_matches(alt, nodes[c0:]):
+                            if c1 > 0:
+                                r = {}
+                                r.update(r0)
+                                r.update(r1)
+                                yield c0 + c1, r
+                                new_results.append((c0 + c1, r))
+            results = new_results
 
     def _bare_name_matches(self, nodes):
         """Special optimized matcher for bare_name."""