[Python-checkins] r65752 - in python/branches/tlee-ast-optimize: Doc/c-api/arg.rst Doc/library/language.rst Doc/library/os.rst Doc/library/symtable.rst Doc/reference/expressions.rst Include/symtable.h Lib/BaseHTTPServer.py Lib/cgi.py Lib/distutils/command/build_ext.py Lib/distutils/command/build_py.py Lib/distutils/core.py Lib/email/message.py Lib/httplib.py Lib/imghdr.py Lib/lib2to3 Lib/lib2to3/fixes/fix_imports.py Lib/test/test_ossaudiodev.py Lib/test/test_syntax.py Lib/test/test_urllib2.py Lib/urllib2.py Misc/NEWS Modules/posixmodule.c Python/symtable.c

thomas.lee python-checkins at python.org
Sun Aug 17 12:35:44 CEST 2008


Author: thomas.lee
Date: Sun Aug 17 12:35:43 2008
New Revision: 65752

Log:
Merged revisions 65691-65751 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

................
  r65693 | georg.brandl | 2008-08-16 04:35:09 +1000 (Sat, 16 Aug 2008) | 2 lines
  
  #3558: Attribute reference binds more tightly than subscription and call.
................
  r65700 | antoine.pitrou | 2008-08-16 07:03:21 +1000 (Sat, 16 Aug 2008) | 3 lines
  
  #2676: email/message.py [Message.get_content_type]: Trivial regex hangs on pathological input
................
  r65702 | gregory.p.smith | 2008-08-16 09:14:00 +1000 (Sat, 16 Aug 2008) | 2 lines
  
  document that waitpid raises OSError
................
  r65703 | benjamin.peterson | 2008-08-16 09:51:24 +1000 (Sat, 16 Aug 2008) | 11 lines
  
  Merged revisions 65397 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
  
  ........
    r65397 | collin.winter | 2008-08-01 22:39:06 -0500 (Fri, 01 Aug 2008) | 5 lines
    
    Patch #3480 by Nick Edds.
    
    Dramatically simplifies the fix_imports pattern, resulting in a reduction of the test_all_fixers runtime from 122+ secs to 59 secs (a good predictor of 2to3 performance).
  ........
................
  r65706 | benjamin.peterson | 2008-08-16 13:02:41 +1000 (Sat, 16 Aug 2008) | 1 line
  
  fix markup
................
  r65707 | benjamin.peterson | 2008-08-16 13:13:07 +1000 (Sat, 16 Aug 2008) | 1 line
  
  note how os.utime should be used for emulating touch
................
  r65710 | facundo.batista | 2008-08-17 00:44:07 +1000 (Sun, 17 Aug 2008) | 4 lines
  
  
  Issue #2776: fixed small issue when handling an URL with double slash
  after a 302 response in the case of not going through a proxy.
................
  r65713 | benjamin.peterson | 2008-08-17 02:29:02 +1000 (Sun, 17 Aug 2008) | 1 line
  
  #3424 rearrange the order of tests in imghdr to place more common types first
................
  r65715 | benjamin.peterson | 2008-08-17 07:04:16 +1000 (Sun, 17 Aug 2008) | 1 line
  
  add some documentation for symtable
................
  r65716 | brett.cannon | 2008-08-17 07:47:07 +1000 (Sun, 17 Aug 2008) | 5 lines
  
  Silence the DeprecationWarning raised by importing mimetools in BaseHTTPServer.
  This does have an unfortunate side-effect of silencing the warning for all
  subsequent code that imports mimetools as well since the warning is only
  executed upon the first import of mimetools.
................
  r65719 | brett.cannon | 2008-08-17 07:56:03 +1000 (Sun, 17 Aug 2008) | 2 lines
  
  Silence the DeprecationWarning raised in httplib when mimetools is imported.
................
  r65721 | brett.cannon | 2008-08-17 08:00:27 +1000 (Sun, 17 Aug 2008) | 2 lines
  
  Silence DeprecationWarning raised by mimetools and rfc822 in cgi.
................
  r65724 | benjamin.peterson | 2008-08-17 08:11:33 +1000 (Sun, 17 Aug 2008) | 2 lines
  
  include filename and line number in SyntaxError
................
  r65726 | georg.brandl | 2008-08-17 08:37:05 +1000 (Sun, 17 Aug 2008) | 2 lines
  
  Review symtable docs.
................
  r65732 | benjamin.peterson | 2008-08-17 09:29:40 +1000 (Sun, 17 Aug 2008) | 1 line
  
  PySTEntry's constructor is static; there's no point in a fancy API name
................
  r65733 | antoine.pitrou | 2008-08-17 10:36:03 +1000 (Sun, 17 Aug 2008) | 3 lines
  
  Make test_ossaudiodev work.
................
  r65736 | benjamin.peterson | 2008-08-17 11:09:17 +1000 (Sun, 17 Aug 2008) | 1 line
  
  expose PySTEntry.nested so the symtable module will work
................
  r65737 | benjamin.peterson | 2008-08-17 11:17:15 +1000 (Sun, 17 Aug 2008) | 1 line
  
  a few improvements
................
  r65738 | benjamin.peterson | 2008-08-17 11:27:30 +1000 (Sun, 17 Aug 2008) | 1 line
  
  fix compile errors
................
  r65739 | benjamin.peterson | 2008-08-17 12:23:43 +1000 (Sun, 17 Aug 2008) | 1 line
  
  uhh PySTEntry->ste_unoptimized has to be exposed too
................
  r65741 | facundo.batista | 2008-08-17 13:38:39 +1000 (Sun, 17 Aug 2008) | 4 lines
  
  
  Issue 2464. Supports a malformation in the URL received
  in a redirect.
................
  r65742 | brett.cannon | 2008-08-17 14:16:04 +1000 (Sun, 17 Aug 2008) | 2 lines
  
  Update distutils so that it triggers no warnings when run under -3.
................
  r65745 | hirokazu.yamamoto | 2008-08-17 19:19:52 +1000 (Sun, 17 Aug 2008) | 2 lines
  
  Issue #2222: Fixed reference leak when occured os.rename()
  fails unicode conversion on 2nd parameter. (windows only)
................
  r65748 | hirokazu.yamamoto | 2008-08-17 19:46:56 +1000 (Sun, 17 Aug 2008) | 1 line
  
  I forgot to update NEWS.
................


Added:
   python/branches/tlee-ast-optimize/Doc/library/symtable.rst
      - copied unchanged from r65748, /python/trunk/Doc/library/symtable.rst
Modified:
   python/branches/tlee-ast-optimize/   (props changed)
   python/branches/tlee-ast-optimize/Doc/c-api/arg.rst
   python/branches/tlee-ast-optimize/Doc/library/language.rst
   python/branches/tlee-ast-optimize/Doc/library/os.rst
   python/branches/tlee-ast-optimize/Doc/reference/expressions.rst
   python/branches/tlee-ast-optimize/Include/symtable.h
   python/branches/tlee-ast-optimize/Lib/BaseHTTPServer.py
   python/branches/tlee-ast-optimize/Lib/cgi.py
   python/branches/tlee-ast-optimize/Lib/distutils/command/build_ext.py
   python/branches/tlee-ast-optimize/Lib/distutils/command/build_py.py
   python/branches/tlee-ast-optimize/Lib/distutils/core.py
   python/branches/tlee-ast-optimize/Lib/email/message.py
   python/branches/tlee-ast-optimize/Lib/httplib.py
   python/branches/tlee-ast-optimize/Lib/imghdr.py
   python/branches/tlee-ast-optimize/Lib/lib2to3/   (props changed)
   python/branches/tlee-ast-optimize/Lib/lib2to3/fixes/fix_imports.py
   python/branches/tlee-ast-optimize/Lib/test/test_ossaudiodev.py
   python/branches/tlee-ast-optimize/Lib/test/test_syntax.py
   python/branches/tlee-ast-optimize/Lib/test/test_urllib2.py
   python/branches/tlee-ast-optimize/Lib/urllib2.py
   python/branches/tlee-ast-optimize/Misc/NEWS
   python/branches/tlee-ast-optimize/Modules/posixmodule.c
   python/branches/tlee-ast-optimize/Python/symtable.c

Modified: python/branches/tlee-ast-optimize/Doc/c-api/arg.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/c-api/arg.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/c-api/arg.rst	Sun Aug 17 12:35:43 2008
@@ -57,6 +57,7 @@
 
 ``z*`` (string or ``None`` or any buffer compatible object) [Py_buffer*]
    This is to ``s*`` as ``z`` is to ``s``.
+
   .. versionadded:: 2.6
 
 ``u`` (Unicode object) [Py_UNICODE \*]

Modified: python/branches/tlee-ast-optimize/Doc/library/language.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/language.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/language.rst	Sun Aug 17 12:35:43 2008
@@ -16,6 +16,7 @@
 
    parser.rst
    ast.rst
+   symtable.rst
    symbol.rst
    token.rst
    keyword.rst

Modified: python/branches/tlee-ast-optimize/Doc/library/os.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/os.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/os.rst	Sun Aug 17 12:35:43 2008
@@ -1303,15 +1303,16 @@
 
 .. function:: utime(path, times)
 
-   Set the access and modified times of the file specified by *path*. If *times* is
-   ``None``, then the file's access and modified times are set to the current time.
-   Otherwise, *times* must be a 2-tuple of numbers, of the form ``(atime, mtime)``
-   which is used to set the access and modified times, respectively. Whether a
-   directory can be given for *path* depends on whether the operating system
-   implements directories as files (for example, Windows does not).  Note that the
-   exact times you set here may not be returned by a subsequent :func:`stat` call,
-   depending on the resolution with which your operating system records access and
-   modification times; see :func:`stat`.
+   Set the access and modified times of the file specified by *path*. If *times*
+   is ``None``, then the file's access and modified times are set to the current
+   time. (The effect is similar to running the Unix program :program:`touch` on
+   the path.)  Otherwise, *times* must be a 2-tuple of numbers, of the form
+   ``(atime, mtime)`` which is used to set the access and modified times,
+   respectively. Whether a directory can be given for *path* depends on whether
+   the operating system implements directories as files (for example, Windows
+   does not).  Note that the exact times you set here may not be returned by a
+   subsequent :func:`stat` call, depending on the resolution with which your
+   operating system records access and modification times; see :func:`stat`.
 
    .. versionchanged:: 2.0
       Added support for ``None`` for *times*.
@@ -1883,6 +1884,9 @@
    ``-1``, status is requested for any process in the process group ``-pid`` (the
    absolute value of *pid*).
 
+   An :exc:`OSError` is raised with the value of errno when the syscall
+   returns -1.
+
    On Windows: Wait for completion of a process given by process handle *pid*, and
    return a tuple containing *pid*, and its exit status shifted left by 8 bits
    (shifting makes cross-platform use of the function easier). A *pid* less than or

Modified: python/branches/tlee-ast-optimize/Doc/reference/expressions.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/reference/expressions.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/reference/expressions.rst	Sun Aug 17 12:35:43 2008
@@ -1299,13 +1299,13 @@
 +-----------------------------------------------+-------------------------------------+
 | ``**``                                        | Exponentiation                      |
 +-----------------------------------------------+-------------------------------------+
-| ``x.attribute``                               | Attribute reference                 |
-+-----------------------------------------------+-------------------------------------+
 | ``x[index]``                                  | Subscription                        |
 +-----------------------------------------------+-------------------------------------+
 | ``x[index:index]``                            | Slicing                             |
 +-----------------------------------------------+-------------------------------------+
-| ``f(arguments...)``                           | Function call                       |
+| ``x(arguments...)``                           | Call                                |
++-----------------------------------------------+-------------------------------------+
+| ``x.attribute``                               | Attribute reference                 |
 +-----------------------------------------------+-------------------------------------+
 | ``(expressions...)``                          | Binding or tuple display            |
 +-----------------------------------------------+-------------------------------------+

Modified: python/branches/tlee-ast-optimize/Include/symtable.h
==============================================================================
--- python/branches/tlee-ast-optimize/Include/symtable.h	(original)
+++ python/branches/tlee-ast-optimize/Include/symtable.h	Sun Aug 17 12:35:43 2008
@@ -32,7 +32,7 @@
 	PyObject *ste_children;  /* list of child ids */
 	_Py_block_ty ste_type;   /* module, class, or function */
 	int ste_unoptimized;     /* false if namespace is optimized */
-	unsigned ste_nested : 1;      /* true if block is nested */
+	int ste_nested;      /* true if block is nested */
 	unsigned ste_free : 1;        /* true if block has free variables */
 	unsigned ste_child_free : 1;  /* true if a child block has free vars,
 				         including free refs to globals */

Modified: python/branches/tlee-ast-optimize/Lib/BaseHTTPServer.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/BaseHTTPServer.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/BaseHTTPServer.py	Sun Aug 17 12:35:43 2008
@@ -73,7 +73,12 @@
 import sys
 import time
 import socket # For gethostbyaddr()
-import mimetools
+from test.test_support import catch_warning
+from warnings import filterwarnings
+with catch_warning(record=False):
+    filterwarnings("ignore", ".*mimetools has been removed",
+                    DeprecationWarning)
+    import mimetools
 import SocketServer
 
 # Default error message template

Modified: python/branches/tlee-ast-optimize/Lib/cgi.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/cgi.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/cgi.py	Sun Aug 17 12:35:43 2008
@@ -38,9 +38,16 @@
 import sys
 import os
 import urllib
-import mimetools
-import rfc822
 import UserDict
+from test.test_support import catch_warning
+from warnings import filterwarnings
+with catch_warning(record=False):
+    filterwarnings("ignore", ".*mimetools has been removed",
+                    DeprecationWarning)
+    import mimetools
+    filterwarnings("ignore", ".*rfc822 has been removed", DeprecationWarning)
+    import rfc822
+
 try:
     from cStringIO import StringIO
 except ImportError:

Modified: python/branches/tlee-ast-optimize/Lib/distutils/command/build_ext.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/distutils/command/build_ext.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/distutils/command/build_ext.py	Sun Aug 17 12:35:43 2008
@@ -679,7 +679,7 @@
         so_ext = get_config_var('SO')
         if os.name == 'nt' and self.debug:
             return apply(os.path.join, ext_path) + '_d' + so_ext
-        return apply(os.path.join, ext_path) + so_ext
+        return os.path.join(*ext_path) + so_ext
 
     def get_export_symbols (self, ext):
         """Return the list of symbols that a shared extension has to

Modified: python/branches/tlee-ast-optimize/Lib/distutils/command/build_py.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/distutils/command/build_py.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/distutils/command/build_py.py	Sun Aug 17 12:35:43 2008
@@ -169,7 +169,7 @@
                     del path[-1]
                 else:
                     tail.insert(0, pdir)
-                    return apply(os.path.join, tail)
+                    return os.path.join(*tail)
             else:
                 # Oops, got all the way through 'path' without finding a
                 # match in package_dir.  If package_dir defines a directory
@@ -337,7 +337,7 @@
 
     def get_module_outfile (self, build_dir, package, module):
         outfile_path = [build_dir] + list(package) + [module + ".py"]
-        return apply(os.path.join, outfile_path)
+        return os.path.join(*outfile_path)
 
 
     def get_outputs (self, include_bytecode=1):

Modified: python/branches/tlee-ast-optimize/Lib/distutils/core.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/distutils/core.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/distutils/core.py	Sun Aug 17 12:35:43 2008
@@ -218,7 +218,8 @@
             sys.argv[0] = script_name
             if script_args is not None:
                 sys.argv[1:] = script_args
-            execfile(script_name, g, l)
+            with open(script_name, 'r') as file:
+                exec file.read() in g, l
         finally:
             sys.argv = save_argv
             _setup_stop_after = None

Modified: python/branches/tlee-ast-optimize/Lib/email/message.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/email/message.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/email/message.py	Sun Aug 17 12:35:43 2008
@@ -19,18 +19,22 @@
 
 SEMISPACE = '; '
 
-# Regular expression used to split header parameters.  BAW: this may be too
-# simple.  It isn't strictly RFC 2045 (section 5.1) compliant, but it catches
-# most headers found in the wild.  We may eventually need a full fledged
-# parser eventually.
-paramre = re.compile(r'\s*;\s*')
 # Regular expression that matches `special' characters in parameters, the
 # existance of which force quoting of the parameter value.
 tspecials = re.compile(r'[ \(\)<>@,;:\\"/\[\]\?=]')
 
 
-
 # Helper functions
+def _splitparam(param):
+    # Split header parameters.  BAW: this may be too simple.  It isn't
+    # strictly RFC 2045 (section 5.1) compliant, but it catches most headers
+    # found in the wild.  We may eventually need a full fledged parser
+    # eventually.
+    a, sep, b = param.partition(';')
+    if not sep:
+        return a.strip(), None
+    return a.strip(), b.strip()
+
 def _formatparam(param, value=None, quote=True):
     """Convenience function to format and return a key=value pair.
 
@@ -436,7 +440,7 @@
         if value is missing:
             # This should have no parameters
             return self.get_default_type()
-        ctype = paramre.split(value)[0].lower().strip()
+        ctype = _splitparam(value)[0].lower()
         # RFC 2045, section 5.2 says if its invalid, use text/plain
         if ctype.count('/') != 1:
             return 'text/plain'

Modified: python/branches/tlee-ast-optimize/Lib/httplib.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/httplib.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/httplib.py	Sun Aug 17 12:35:43 2008
@@ -66,10 +66,14 @@
 Req-sent-unread-response       _CS_REQ_SENT       <response_class>
 """
 
-import mimetools
 import socket
 from urlparse import urlsplit
 import warnings
+from test.test_support import catch_warning
+with catch_warning(record=False):
+    warnings.filterwarnings("ignore", ".*mimetools has been removed",
+                            DeprecationWarning)
+    import mimetools
 
 try:
     from cStringIO import StringIO

Modified: python/branches/tlee-ast-optimize/Lib/imghdr.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/imghdr.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/imghdr.py	Sun Aug 17 12:35:43 2008
@@ -34,12 +34,25 @@
 
 tests = []
 
-def test_rgb(h, f):
-    """SGI image library"""
-    if h[:2] == '\001\332':
-        return 'rgb'
+def test_jpeg(h, f):
+    """JPEG data in JFIF format"""
+    if h[6:10] == 'JFIF':
+        return 'jpeg'
 
-tests.append(test_rgb)
+tests.append(test_jpeg)
+
+def test_exif(h, f):
+    """JPEG data in Exif format"""
+    if h[6:10] == 'Exif':
+        return 'jpeg'
+
+tests.append(test_exif)
+
+def test_png(h, f):
+    if h[:8] == "\211PNG\r\n\032\n":
+        return 'png'
+
+tests.append(test_png)
 
 def test_gif(h, f):
     """GIF ('87 and '89 variants)"""
@@ -48,6 +61,20 @@
 
 tests.append(test_gif)
 
+def test_tiff(h, f):
+    """TIFF (can be in Motorola or Intel byte order)"""
+    if h[:2] in ('MM', 'II'):
+        return 'tiff'
+
+tests.append(test_tiff)
+
+def test_rgb(h, f):
+    """SGI image library"""
+    if h[:2] == '\001\332':
+        return 'rgb'
+
+tests.append(test_rgb)
+
 def test_pbm(h, f):
     """PBM (portable bitmap)"""
     if len(h) >= 3 and \
@@ -72,13 +99,6 @@
 
 tests.append(test_ppm)
 
-def test_tiff(h, f):
-    """TIFF (can be in Motorola or Intel byte order)"""
-    if h[:2] in ('MM', 'II'):
-        return 'tiff'
-
-tests.append(test_tiff)
-
 def test_rast(h, f):
     """Sun raster file"""
     if h[:4] == '\x59\xA6\x6A\x95':
@@ -94,32 +114,12 @@
 
 tests.append(test_xbm)
 
-def test_jpeg(h, f):
-    """JPEG data in JFIF format"""
-    if h[6:10] == 'JFIF':
-        return 'jpeg'
-
-tests.append(test_jpeg)
-
-def test_exif(h, f):
-    """JPEG data in Exif format"""
-    if h[6:10] == 'Exif':
-        return 'jpeg'
-
-tests.append(test_exif)
-
 def test_bmp(h, f):
     if h[:2] == 'BM':
         return 'bmp'
 
 tests.append(test_bmp)
 
-def test_png(h, f):
-    if h[:8] == "\211PNG\r\n\032\n":
-        return 'png'
-
-tests.append(test_png)
-
 #--------------------#
 # Small test program #
 #--------------------#

Modified: python/branches/tlee-ast-optimize/Lib/lib2to3/fixes/fix_imports.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/lib2to3/fixes/fix_imports.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/lib2to3/fixes/fix_imports.py	Sun Aug 17 12:35:43 2008
@@ -61,24 +61,23 @@
 
 
 def build_pattern(mapping=MAPPING):
-    bare = set()
-    for old_module, new_module in mapping.items():
-        bare.add(old_module)
-        yield """import_name< 'import' (module=%r
-                              | dotted_as_names< any* module=%r any* >) >
-              """ % (old_module, old_module)
-        yield """import_from< 'from' module_name=%r 'import'
-                  ( any | import_as_name< any 'as' any > |
-                    import_as_names< any* >) >
-              """ % old_module
-        yield """import_name< 'import'
-                              dotted_as_name< module_name=%r 'as' any > >
-              """ % old_module
-        # Find usages of module members in code e.g. urllib.foo(bar)
-        yield """power< module_name=%r
-                 trailer<'.' any > any* >
-              """ % old_module
-    yield """bare_name=%s""" % alternates(bare)
+    mod_list = ' | '.join(["module='" + key + "'" for key in mapping.keys()])
+    mod_name_list = ' | '.join(["module_name='" + key + "'" for key in mapping.keys()])
+    yield """import_name< 'import' ((%s)
+                          | dotted_as_names< any* (%s) any* >) >
+          """ % (mod_list, mod_list)
+    yield """import_from< 'from' (%s) 'import'
+              ( any | import_as_name< any 'as' any > |
+                import_as_names< any* >) >
+          """ % mod_name_list
+    yield """import_name< 'import'
+                          dotted_as_name< (%s) 'as' any > >
+          """ % mod_name_list
+    # Find usages of module members in code e.g. urllib.foo(bar)
+    yield """power< (%s)
+             trailer<'.' any > any* >
+          """ % mod_name_list
+    yield """bare_name=%s""" % alternates(mapping.keys())
 
 class FixImports(fixer_base.BaseFix):
     PATTERN = "|".join(build_pattern())

Modified: python/branches/tlee-ast-optimize/Lib/test/test_ossaudiodev.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_ossaudiodev.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_ossaudiodev.py	Sun Aug 17 12:35:43 2008
@@ -56,7 +56,7 @@
         dsp.fileno()
 
         # Make sure the read-only attributes work.
-        self.failUnless(dsp.close)
+        self.failIf(dsp.closed)
         self.assertEqual(dsp.name, "/dev/dsp")
         self.assertEqual(dsp.mode, "w", "bad dsp.mode: %r" % dsp.mode)
 
@@ -74,7 +74,7 @@
 
         # set parameters based on .au file headers
         dsp.setparameters(AFMT_S16_NE, nchannels, rate)
-        self.assertEquals("%.2f" % expected_time, "2.93")
+        self.assertTrue(abs(expected_time - 2.94) < 1e-2, expected_time)
         t1 = time.time()
         dsp.write(data)
         dsp.close()

Modified: python/branches/tlee-ast-optimize/Lib/test/test_syntax.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_syntax.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_syntax.py	Sun Aug 17 12:35:43 2008
@@ -5,7 +5,7 @@
 >>> def f(x):
 ...     global x
 Traceback (most recent call last):
-SyntaxError: name 'x' is local and global
+SyntaxError: name 'x' is local and global (<doctest test.test_syntax[0]>, line 1)
 
 The tests are all raise SyntaxErrors.  They were created by checking
 each C call that raises SyntaxError.  There are several modules that

Modified: python/branches/tlee-ast-optimize/Lib/test/test_urllib2.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_urllib2.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_urllib2.py	Sun Aug 17 12:35:43 2008
@@ -772,6 +772,32 @@
             self.assertEqual(req.unredirected_hdrs["Host"], "baz")
             self.assertEqual(req.unredirected_hdrs["Spam"], "foo")
 
+    def test_http_doubleslash(self):
+        # Checks that the presence of an unnecessary double slash in a url doesn't break anything
+        # Previously, a double slash directly after the host could cause incorrect parsing of the url
+        h = urllib2.AbstractHTTPHandler()
+        o = h.parent = MockOpener()
+
+        data = ""
+        ds_urls = [
+            "http://example.com/foo/bar/baz.html",
+            "http://example.com//foo/bar/baz.html",
+            "http://example.com/foo//bar/baz.html",
+            "http://example.com/foo/bar//baz.html",
+        ]
+
+        for ds_url in ds_urls:
+            ds_req = Request(ds_url, data)
+
+            # Check whether host is determined correctly if there is no proxy
+            np_ds_req = h.do_request_(ds_req)
+            self.assertEqual(np_ds_req.unredirected_hdrs["Host"],"example.com")
+
+            # Check whether host is determined correctly if there is a proxy
+            ds_req.set_proxy("someproxy:3128",None)
+            p_ds_req = h.do_request_(ds_req)
+            self.assertEqual(p_ds_req.unredirected_hdrs["Host"],"example.com")
+
     def test_errors(self):
         h = urllib2.HTTPErrorProcessor()
         o = h.parent = MockOpener()

Modified: python/branches/tlee-ast-optimize/Lib/urllib2.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/urllib2.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/urllib2.py	Sun Aug 17 12:35:43 2008
@@ -255,6 +255,9 @@
         self.host, self.type = host, type
         self.__r_host = self.__original
 
+    def has_proxy(self):
+        return self.__r_host == self.__original
+
     def get_origin_req_host(self):
         return self.origin_req_host
 
@@ -557,6 +560,14 @@
             newurl = headers.getheaders('uri')[0]
         else:
             return
+
+        # fix a possible malformed URL
+        urlparts = urlparse.urlparse(newurl)
+        if not urlparts.path:
+            urlparts = list(urlparts)
+            urlparts[2] = "/"
+        newurl = urlparse.urlunparse(urlparts)
+
         newurl = urlparse.urljoin(req.get_full_url(), newurl)
 
         # XXX Probably want to forget about the state of the current
@@ -1045,10 +1056,13 @@
                 request.add_unredirected_header(
                     'Content-length', '%d' % len(data))
 
-        scheme, sel = splittype(request.get_selector())
-        sel_host, sel_path = splithost(sel)
+        sel_host = host
+        if request.has_proxy():
+            scheme, sel = splittype(request.get_selector())
+            sel_host, sel_path = splithost(sel)
+
         if not request.has_header('Host'):
-            request.add_unredirected_header('Host', sel_host or host)
+            request.add_unredirected_header('Host', sel_host)
         for name, value in self.parent.addheaders:
             name = name.capitalize()
             if not request.has_header(name):

Modified: python/branches/tlee-ast-optimize/Misc/NEWS
==============================================================================
--- python/branches/tlee-ast-optimize/Misc/NEWS	(original)
+++ python/branches/tlee-ast-optimize/Misc/NEWS	Sun Aug 17 12:35:43 2008
@@ -48,6 +48,22 @@
 Library
 -------
 
+- Issue #2222: Fixed reference leak when occured os.rename()
+  fails unicode conversion on 2nd parameter. (windows only)
+
+- Issue 2464. urllib2 now supports a malformation in the URL received
+  in a redirect.
+
+- Silence the DeprecationWarning raised when importing mimetools in
+  BaseHTTPServer, cgi (and rfc822), httplib.
+
+- Issue #2776: fixed small issue when handling an URL with double slash
+  after a 302 response in the case of not going through a proxy.
+
+- Issue #2676: in the email package, content-type parsing was hanging on
+  pathological input because of quadratic or exponential behaviour of a
+  regular expression.
+
 - Issue #3476: binary buffered reading through the new "io" library is now
   thread-safe.
 
@@ -79,11 +95,11 @@
 
 - Changed code in the following modules/packages to remove warnings raised
   while running under the ``-3`` flag: aifc, asynchat, asyncore, bdb, bsddb,
-  ConfigParser, cookielib, csv, difflib, DocXMLRPCServer, email, filecmp,
-  fileinput, inspect, logging, modulefinder, pdb, pickle, profile, pstats,
-  pydoc, re, rlcompleter, SimpleXMLRPCServer, shelve, socket, subprocess,
-  sqlite3, tarfile, Tkinter, test.test_support, textwrap, threading, tokenize,
-  traceback, urlparse, wsgiref, xml, xmlrpclib.
+  ConfigParser, cookielib, csv, difflib, distutils, DocXMLRPCServer, email,
+  filecmp, fileinput, inspect, logging, modulefinder, pdb, pickle, profile,
+  pstats, pydoc, re, rlcompleter, SimpleXMLRPCServer, shelve, socket,
+  subprocess, sqlite3, tarfile, Tkinter, test.test_support, textwrap,
+  threading, tokenize, traceback, urlparse, wsgiref, xml, xmlrpclib.
 
 - Issue #3039: Fix tarfile.TarFileCompat.writestr() which always
   raised an AttributeError.

Modified: python/branches/tlee-ast-optimize/Modules/posixmodule.c
==============================================================================
--- python/branches/tlee-ast-optimize/Modules/posixmodule.c	(original)
+++ python/branches/tlee-ast-optimize/Modules/posixmodule.c	Sun Aug 17 12:35:43 2008
@@ -478,24 +478,18 @@
 {
 }
 
-/* Function suitable for O& conversion */
 static int
-convert_to_unicode(PyObject *arg, void* _param)
+convert_to_unicode(PyObject **param)
 {
-	PyObject **param = (PyObject**)_param;
-	if (PyUnicode_CheckExact(arg)) {
-		Py_INCREF(arg);
-		*param = arg;
-	} 
-	else if (PyUnicode_Check(arg)) {
+	if (PyUnicode_CheckExact(*param))
+		Py_INCREF(*param);
+	else if (PyUnicode_Check(*param))
 		/* For a Unicode subtype that's not a Unicode object,
 		   return a true Unicode object with the same data. */
-		*param = PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(arg),
-					       PyUnicode_GET_SIZE(arg));
-		return *param != NULL;
-	}
+		*param = PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(*param),
+					       PyUnicode_GET_SIZE(*param));
 	else
-		*param = PyUnicode_FromEncodedObject(arg,
+		*param = PyUnicode_FromEncodedObject(*param,
 				                     Py_FileSystemDefaultEncoding,
 					             "strict");
 	return (*param) != NULL;
@@ -2542,22 +2536,26 @@
 	char *p1, *p2;
 	BOOL result;
 	if (unicode_file_names()) {
-	    if (!PyArg_ParseTuple(args, "O&O&:rename", 
-		convert_to_unicode, &o1,
-		convert_to_unicode, &o2))
-		    PyErr_Clear();
-	    else {
-		    Py_BEGIN_ALLOW_THREADS
-		    result = MoveFileW(PyUnicode_AsUnicode(o1),
-				       PyUnicode_AsUnicode(o2));
-		    Py_END_ALLOW_THREADS
-		    Py_DECREF(o1);
-		    Py_DECREF(o2);
-		    if (!result)
-			    return win32_error("rename", NULL);
-		    Py_INCREF(Py_None);
-		    return Py_None;
+	    if (!PyArg_ParseTuple(args, "OO:rename", &o1, &o2))
+		goto error;
+	    if (!convert_to_unicode(&o1))
+		goto error;
+	    if (!convert_to_unicode(&o2)) {
+		Py_DECREF(o1);
+		goto error;
 	    }
+	    Py_BEGIN_ALLOW_THREADS
+	    result = MoveFileW(PyUnicode_AsUnicode(o1),
+			       PyUnicode_AsUnicode(o2));
+	    Py_END_ALLOW_THREADS
+	    Py_DECREF(o1);
+	    Py_DECREF(o2);
+	    if (!result)
+		    return win32_error("rename", NULL);
+	    Py_INCREF(Py_None);
+	    return Py_None;
+error:
+	    PyErr_Clear();
 	}
 	if (!PyArg_ParseTuple(args, "ss:rename", &p1, &p2))
 		return NULL;

Modified: python/branches/tlee-ast-optimize/Python/symtable.c
==============================================================================
--- python/branches/tlee-ast-optimize/Python/symtable.c	(original)
+++ python/branches/tlee-ast-optimize/Python/symtable.c	Sun Aug 17 12:35:43 2008
@@ -16,9 +16,9 @@
 #define RETURN_VAL_IN_GENERATOR \
     "'return' with argument inside generator"
 
-/* XXX(nnorwitz): change name since static? */
+
 static PySTEntryObject *
-PySTEntry_New(struct symtable *st, identifier name, _Py_block_ty block,
+ste_new(struct symtable *st, identifier name, _Py_block_ty block,
 	      void *key, int lineno)
 {
 	PySTEntryObject *ste = NULL;
@@ -112,6 +112,8 @@
 	{"symbols",  T_OBJECT, OFF(ste_symbols), READONLY},
 	{"varnames", T_OBJECT, OFF(ste_varnames), READONLY},
 	{"children", T_OBJECT, OFF(ste_children), READONLY},
+        {"optimized",T_INT,    OFF(ste_unoptimized), READONLY},
+	{"nested",   T_INT,    OFF(ste_nested), READONLY},
 	{"type",     T_INT,    OFF(ste_type), READONLY},
 	{"lineno",   T_INT,    OFF(ste_lineno), READONLY},
 	{NULL}
@@ -373,6 +375,9 @@
 			PyErr_Format(PyExc_SyntaxError,
 				     "name '%s' is local and global",
 				     PyString_AS_STRING(name));
+			PyErr_SyntaxLocation(ste->ste_table->st_filename,
+					     ste->ste_lineno);
+			
 			return 0;
 		}
 		SET_SCOPE(dict, name, GLOBAL_EXPLICIT);
@@ -719,7 +724,7 @@
 	return 1;
 }
 
-/* symtable_enter_block() gets a reference via PySTEntry_New().
+/* symtable_enter_block() gets a reference via ste_new.
    This reference is released when the block is exited, via the DECREF
    in symtable_exit_block().
 */
@@ -756,7 +761,7 @@
 		}
 		Py_DECREF(st->st_cur);
 	}
-	st->st_cur = PySTEntry_New(st, name, block, ast, lineno);
+	st->st_cur = ste_new(st, name, block, ast, lineno);
 	if (st->st_cur == NULL)
 		return 0;
 	if (name == GET_IDENTIFIER(top))


More information about the Python-checkins mailing list