[Python-checkins] r80395 - in python/branches/py3k-cdecimal: Doc/about.rst Doc/bugs.rst Doc/documenting/index.rst Doc/library/urllib.parse.rst Doc/library/urllib.request.rst Doc/library/winreg.rst Doc/tools/sphinxext/indexsidebar.html Doc/tools/sphinxext/layout.html Doc/whatsnew/3.2.rst Include/unicodeobject.h Lib/email/test/test_email.py Lib/mailcap.py Lib/shutil.py Lib/sqlite3/test/regression.py Lib/test/gdb_sample.py Lib/test/sha256.pem Lib/test/support.py Lib/test/test_bytes.py Lib/test/test_codecs.py Lib/test/test_ftplib.py Lib/test/test_gdb.py Lib/test/test_genericpath.py Lib/test/test_os.py Lib/test/test_ssl.py Lib/test/test_urlparse.py Lib/test/test_winreg.py Lib/unittest/test/test_break.py Lib/urllib/parse.py Mac/BuildScript/build-installer.py Misc/ACKS Misc/NEWS Misc/maintainers.rst Modules/Setup.dist Modules/_posixsubprocess.c Modules/_sqlite/connection.c Modules/_ssl.c Modules/posixmodule.c Objects/unicodeobject.c PC/winreg.c Python/marshal.c Tools/gdb/libpython.py setup.py

stefan.krah python-checkins at python.org
Fri Apr 23 10:13:31 CEST 2010


Author: stefan.krah
Date: Fri Apr 23 10:13:30 2010
New Revision: 80395

Log:
Merged revisions 80309,80311-80312,80317,80321,80323-80324,80326-80329,80331,80333-80335,80337,80342-80343,80346,80349,80353,80359,80361,80364,80366,80368-80370,80379,80382,80384,80390,80394 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r80309 | tarek.ziade | 2010-04-21 15:35:21 +0200 (Wed, 21 Apr 2010) | 9 lines
  
  Merged revisions 80306 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80306 | tarek.ziade | 2010-04-21 15:32:26 +0200 (Wed, 21 Apr 2010) | 1 line
    
    shutil: removed unused import and fixed attributes names in _call_external_zip
  ........
................
  r80311 | victor.stinner | 2010-04-21 15:53:05 +0200 (Wed, 21 Apr 2010) | 5 lines
  
  Adapt libpython.py and test_gdb.py to Python3
  
   * Rename PyStringObjectPtr to PyBytesObjectPtr
   * Replace PyObject_Print by textiowrapper_write
................
  r80312 | victor.stinner | 2010-04-21 15:55:23 +0200 (Wed, 21 Apr 2010) | 4 lines
  
  Update NEWS file accoding to my last patch (r80311 about gdb)
  
  Move test_gdb issues to the Tests section.
................
  r80317 | antoine.pitrou | 2010-04-21 21:46:23 +0200 (Wed, 21 Apr 2010) | 15 lines
  
  Merged revisions 80314-80315 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80314 | antoine.pitrou | 2010-04-21 21:28:03 +0200 (mer., 21 avril 2010) | 5 lines
    
    Issue #8484: Load all ciphers and digest algorithms when initializing
    the _ssl extension, such that verification of some SSL certificates
    doesn't fail because of an "unknown algorithm".
  ........
    r80315 | antoine.pitrou | 2010-04-21 21:36:23 +0200 (mer., 21 avril 2010) | 3 lines
    
    Forgot to add the sample certificate (followup to r80314)
  ........
................
  r80321 | matthias.klose | 2010-04-21 23:47:45 +0200 (Wed, 21 Apr 2010) | 9 lines
  
  Merged revisions 80320 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80320 | matthias.klose | 2010-04-21 23:45:30 +0200 (Mi, 21 Apr 2010) | 2 lines
    
    setup.py: search ffi.h in include dirs, if LIBFFI_INCLUDEDIR is empty.
  ........
................
  r80323 | matthias.klose | 2010-04-22 00:21:03 +0200 (Thu, 22 Apr 2010) | 9 lines
  
  Merged revisions 80322 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80322 | matthias.klose | 2010-04-22 00:18:52 +0200 (Do, 22 Apr 2010) | 2 lines
    
    - Build the ossaudio extension on GNU/kFreeBSD.
  ........
................
  r80324 | martin.v.loewis | 2010-04-22 00:38:42 +0200 (Thu, 22 Apr 2010) | 2 lines
  
  Issue #8380: Port gdb/libpython to 3.x.
................
  r80326 | antoine.pitrou | 2010-04-22 00:56:22 +0200 (Thu, 22 Apr 2010) | 12 lines
  
  Merged revisions 80325 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80325 | antoine.pitrou | 2010-04-22 00:53:29 +0200 (jeu., 22 avril 2010) | 6 lines
    
    Issue #7332: Remove the 16KB stack-based buffer in
    PyMarshal_ReadLastObjectFromFile, which doesn't bring any noticeable
    benefit compared to the dynamic memory allocation fallback.  Patch by
    Charles-François Natali.
  ........
................
  r80327 | antoine.pitrou | 2010-04-22 00:59:01 +0200 (Thu, 22 Apr 2010) | 3 lines
  
  Add myself to ssl, although I'm not a de facto maintainer or expert
................
  r80328 | r.david.murray | 2010-04-22 01:05:10 +0200 (Thu, 22 Apr 2010) | 3 lines
  
  Add myself to email, move 'windows' to Platforms where it
  belongs, and finish alphabetizing the Platforms list.
................
  r80329 | brian.curtin | 2010-04-22 01:56:21 +0200 (Thu, 22 Apr 2010) | 4 lines
  
  Port #7347 to py3k.
  
  Add CreateKeyEx and DeleteKeyEx, along with test improvements.
................
  r80331 | r.david.murray | 2010-04-22 02:53:47 +0200 (Thu, 22 Apr 2010) | 12 lines
  
  Merged revisions 80155 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80155 | r.david.murray | 2010-04-17 17:59:26 -0400 (Sat, 17 Apr 2010) | 5 lines
    
    Issue #8263: On freebsd6 the unittest 'break' test stops regrtest; skip it.
    
    This is presumably related to issue 3864, and appears to be due
    to a platform bug on freebsd6.
  ........
................
  r80333 | brian.curtin | 2010-04-22 03:07:36 +0200 (Thu, 22 Apr 2010) | 2 lines
  
  Add a note about #7347.
................
  r80334 | r.david.murray | 2010-04-22 03:49:37 +0200 (Thu, 22 Apr 2010) | 2 lines
  
  Fix verb tense in skip message.
................
  r80335 | brian.curtin | 2010-04-22 03:52:50 +0200 (Thu, 22 Apr 2010) | 2 lines
  
  #7347 entry got entered in the wrong spot.
................
  r80337 | senthil.kumaran | 2010-04-22 07:53:18 +0200 (Thu, 22 Apr 2010) | 9 lines
  
  Merged revisions 80336 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80336 | senthil.kumaran | 2010-04-22 11:18:35 +0530 (Thu, 22 Apr 2010) | 3 lines
    
    Updated the RFCs list in the See Also section of urlparse.rst
  ........
................
  r80342 | georg.brandl | 2010-04-22 09:00:42 +0200 (Thu, 22 Apr 2010) | 1 line
  
  Fix indentation.
................
  r80343 | georg.brandl | 2010-04-22 09:02:51 +0200 (Thu, 22 Apr 2010) | 1 line
  
  Typo fixes.
................
  r80346 | senthil.kumaran | 2010-04-22 12:53:30 +0200 (Thu, 22 Apr 2010) | 4 lines
  
  Fixing a note on encoding declaration, its usage in urlopen based on review
  comments from RDM and Ezio.
................
  r80349 | victor.stinner | 2010-04-22 13:23:23 +0200 (Thu, 22 Apr 2010) | 3 lines
  
  Issue #8195: Fix a crash in sqlite Connection.create_collation() if the
  collation name contains a surrogate character.
................
  r80353 | ezio.melotti | 2010-04-22 13:29:27 +0200 (Thu, 22 Apr 2010) | 9 lines
  
  Merged revisions 80350 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80350 | ezio.melotti | 2010-04-22 14:23:31 +0300 (Thu, 22 Apr 2010) | 1 line
    
    #8474: fix duplicate test in test_email.
  ........
................
  r80359 | ezio.melotti | 2010-04-22 13:57:12 +0200 (Thu, 22 Apr 2010) | 9 lines
  
  Merged revisions 80357 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80357 | ezio.melotti | 2010-04-22 14:53:21 +0300 (Thu, 22 Apr 2010) | 1 line
    
    Rephrase comment.
  ........
................
  r80361 | victor.stinner | 2010-04-22 14:08:36 +0200 (Thu, 22 Apr 2010) | 3 lines
  
  Issue #8485: PyUnicode_FSConverter() doesn't accept bytearray object anymore,
  you have to convert your bytearray filenames to bytes
................
  r80364 | senthil.kumaran | 2010-04-22 14:19:46 +0200 (Thu, 22 Apr 2010) | 10 lines
  
  Merged revisions 80362 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80362 | senthil.kumaran | 2010-04-22 17:40:13 +0530 (Thu, 22 Apr 2010) | 4 lines
    
    Changed tests to only urlparse one, which was enough, addressed Ezio's comment
    on Invalid url check statement and versionchanged string in docs.
  ........
................
  r80366 | martin.v.loewis | 2010-04-22 15:16:44 +0200 (Thu, 22 Apr 2010) | 10 lines
  
  Merged revisions 80355 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80355 | martin.v.loewis | 2010-04-22 13:34:36 +0200 (Do, 22 Apr 2010) | 3 lines
    
    Issue #8475: Pass absolute interpreter path to
    "make html".
  ........
................
  r80368 | antoine.pitrou | 2010-04-22 15:19:31 +0200 (Thu, 22 Apr 2010) | 3 lines
  
  Fix mailcap.py built-in test.
................
  r80369 | antoine.pitrou | 2010-04-22 15:30:10 +0200 (Thu, 22 Apr 2010) | 5 lines
  
  Issue #8496: make mailcap.lookup() always return a list, rather than an iterator.
  Patch by Gregory Nofi.
................
  r80370 | matthias.klose | 2010-04-22 15:38:12 +0200 (Thu, 22 Apr 2010) | 2 lines
  
  - Mention _posixsubprocess.c in Modules/Setup.dist
................
  r80379 | antoine.pitrou | 2010-04-22 20:43:31 +0200 (Thu, 22 Apr 2010) | 9 lines
  
  Merged revisions 80375 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80375 | antoine.pitrou | 2010-04-22 20:00:41 +0200 (jeu., 22 avril 2010) | 3 lines
    
    Skip test on old versions of OpenSSL
  ........
................
  r80382 | victor.stinner | 2010-04-22 21:38:16 +0200 (Thu, 22 Apr 2010) | 3 lines
  
  Issue #8092: Fix PyUnicode_EncodeUTF8() to support error handler producing
  unicode string (eg. backslashreplace)
................
  r80384 | victor.stinner | 2010-04-22 22:01:57 +0200 (Thu, 22 Apr 2010) | 2 lines
  
  Fix my previous commit (r80382) for wide build (unicodeobject.c)
................
  r80390 | georg.brandl | 2010-04-23 01:20:19 +0200 (Fri, 23 Apr 2010) | 9 lines
  
  Merged revisions 80388 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80388 | georg.brandl | 2010-04-23 00:15:33 +0200 (Fr, 23 Apr 2010) | 1 line
    
    Add "report a bug" links in some prominent places.  Make it clear that doc bugs can be mailed to docs at python.org.  Clarify tracker usage.
  ........
................
  r80394 | antoine.pitrou | 2010-04-23 02:16:21 +0200 (Fri, 23 Apr 2010) | 15 lines
  
  Merged revisions 80392 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r80392 | antoine.pitrou | 2010-04-23 01:33:02 +0200 (ven., 23 avril 2010) | 9 lines
    
    Issue #8108: Fix the unwrap() method of SSL objects when the socket has
    a non-infinite timeout.  Also make that method friendlier with applications
    wanting to continue using the socket in clear-text mode, by disabling
    OpenSSL's internal readahead.  Thanks to Darryl Miles for guidance.
    
    Issue #8108: test_ftplib's non-blocking SSL server now has proper handling
    of SSL shutdowns.
  ........
................


Added:
   python/branches/py3k-cdecimal/Lib/test/sha256.pem
      - copied unchanged from r80394, /python/branches/py3k/Lib/test/sha256.pem
Modified:
   python/branches/py3k-cdecimal/   (props changed)
   python/branches/py3k-cdecimal/Doc/about.rst
   python/branches/py3k-cdecimal/Doc/bugs.rst
   python/branches/py3k-cdecimal/Doc/documenting/index.rst
   python/branches/py3k-cdecimal/Doc/library/urllib.parse.rst
   python/branches/py3k-cdecimal/Doc/library/urllib.request.rst
   python/branches/py3k-cdecimal/Doc/library/winreg.rst
   python/branches/py3k-cdecimal/Doc/tools/sphinxext/indexsidebar.html
   python/branches/py3k-cdecimal/Doc/tools/sphinxext/layout.html
   python/branches/py3k-cdecimal/Doc/whatsnew/3.2.rst
   python/branches/py3k-cdecimal/Include/unicodeobject.h
   python/branches/py3k-cdecimal/Lib/email/test/test_email.py
   python/branches/py3k-cdecimal/Lib/mailcap.py
   python/branches/py3k-cdecimal/Lib/shutil.py
   python/branches/py3k-cdecimal/Lib/sqlite3/test/regression.py
   python/branches/py3k-cdecimal/Lib/test/gdb_sample.py
   python/branches/py3k-cdecimal/Lib/test/support.py
   python/branches/py3k-cdecimal/Lib/test/test_bytes.py
   python/branches/py3k-cdecimal/Lib/test/test_codecs.py
   python/branches/py3k-cdecimal/Lib/test/test_ftplib.py
   python/branches/py3k-cdecimal/Lib/test/test_gdb.py
   python/branches/py3k-cdecimal/Lib/test/test_genericpath.py
   python/branches/py3k-cdecimal/Lib/test/test_os.py
   python/branches/py3k-cdecimal/Lib/test/test_ssl.py
   python/branches/py3k-cdecimal/Lib/test/test_urlparse.py
   python/branches/py3k-cdecimal/Lib/test/test_winreg.py
   python/branches/py3k-cdecimal/Lib/unittest/test/test_break.py
   python/branches/py3k-cdecimal/Lib/urllib/parse.py
   python/branches/py3k-cdecimal/Mac/BuildScript/build-installer.py
   python/branches/py3k-cdecimal/Misc/ACKS
   python/branches/py3k-cdecimal/Misc/NEWS
   python/branches/py3k-cdecimal/Misc/maintainers.rst
   python/branches/py3k-cdecimal/Modules/Setup.dist
   python/branches/py3k-cdecimal/Modules/_posixsubprocess.c
   python/branches/py3k-cdecimal/Modules/_sqlite/connection.c
   python/branches/py3k-cdecimal/Modules/_ssl.c
   python/branches/py3k-cdecimal/Modules/posixmodule.c
   python/branches/py3k-cdecimal/Objects/unicodeobject.c
   python/branches/py3k-cdecimal/PC/winreg.c
   python/branches/py3k-cdecimal/Python/marshal.c
   python/branches/py3k-cdecimal/Tools/gdb/libpython.py
   python/branches/py3k-cdecimal/setup.py

Modified: python/branches/py3k-cdecimal/Doc/about.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/about.rst	(original)
+++ python/branches/py3k-cdecimal/Doc/about.rst	Fri Apr 23 10:13:30 2010
@@ -3,9 +3,11 @@
 =====================
 
 
-These documents are generated from `reStructuredText
-<http://docutils.sf.net/rst.html>`_ sources by *Sphinx*, a document processor
-specifically written for the Python documentation.
+These documents are generated from `reStructuredText`_ sources by `Sphinx`_, a
+document processor specifically written for the Python documentation.
+
+.. _reStructuredText: http://docutils.sf.net/rst.html
+.. _Sphinx: http://sphinx.pocoo.org/
 
 .. In the online version of these documents, you can submit comments and suggest
    changes directly on the documentation pages.

Modified: python/branches/py3k-cdecimal/Doc/bugs.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/bugs.rst	(original)
+++ python/branches/py3k-cdecimal/Doc/bugs.rst	Fri Apr 23 10:13:30 2010
@@ -1,14 +1,32 @@
 .. _reporting-bugs:
 
-************************
-Reporting Bugs in Python
-************************
+**************
+Reporting Bugs
+**************
 
 Python is a mature programming language which has established a reputation for
 stability.  In order to maintain this reputation, the developers would like to
 know of any deficiencies you find in Python.
 
-Bug reports should be submitted via the Python Bug Tracker
+
+Documentation bugs
+==================
+
+If you find a bug in this documentation or would like to propose an improvement,
+please send an e-mail to docs at python.org describing the bug and where you found
+it.  If you have a suggestion how to fix it, include that as well.
+
+docs at python.org is a mailing list run by volunteers; your request will be
+noticed, even if it takes a while to be processed.
+
+Of course, if you want a more persistent record of your issue, you can use the
+issue tracker for documentation bugs as well.
+
+
+Using the Python issue tracker
+==============================
+
+Bug reports for Python itself should be submitted via the Python Bug Tracker
 (http://bugs.python.org/).  The bug tracker offers a Web form which allows
 pertinent information to be entered and submitted to the developers.
 
@@ -19,9 +37,6 @@
 information is needed (in which case you are welcome to provide it if you can!).
 To do this, search the bug database using the search box on the top of the page.
 
-In the case of documentation bugs, look at the most recent development docs at
-http://docs.python.org/dev to see if the bug has been fixed.
-
 If the problem you're reporting is not already in the bug tracker, go back to
 the Python Bug Tracker and log in.  If you don't already have a tracker account,
 select the "Register" link or, if you use OpenID, one of the OpenID provider

Modified: python/branches/py3k-cdecimal/Doc/documenting/index.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/documenting/index.rst	(original)
+++ python/branches/py3k-cdecimal/Doc/documenting/index.rst	Fri Apr 23 10:13:30 2010
@@ -18,12 +18,17 @@
 .. _docutils: http://docutils.sf.net/
 .. _Sphinx: http://sphinx.pocoo.org/
 
-If you're interested in contributing to Python's documentation, there's no need
-to write reStructuredText if you're not so inclined; plain text contributions
-are more than welcome as well.
+.. note::
+
+   If you're interested in contributing to Python's documentation, there's no
+   need to write reStructuredText if you're not so inclined; plain text
+   contributions are more than welcome as well.  Send an e-mail to
+   docs at python.org or open an issue on the :ref:`tracker <reporting-bugs>`.
+
 
 .. toctree::
    :numbered:
+   :maxdepth: 1
 
    intro.rst
    style.rst

Modified: python/branches/py3k-cdecimal/Doc/library/urllib.parse.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/urllib.parse.rst	(original)
+++ python/branches/py3k-cdecimal/Doc/library/urllib.parse.rst	Fri Apr 23 10:13:30 2010
@@ -88,6 +88,9 @@
    See section :ref:`urlparse-result-object` for more information on the result
    object.
 
+   .. versionchanged:: 3.2
+      Added IPv6 URL parsing capabilities.
+
 
 .. function:: parse_qs(qs, keep_blank_values=False, strict_parsing=False)
 
@@ -326,17 +329,29 @@
 
 .. seealso::
 
-   :rfc:`1738` - Uniform Resource Locators (URL)
-      This specifies the formal syntax and semantics of absolute URLs.
+   :rfc:`3986` - Uniform Resource Identifiers
+      This is the current standard (STD66). Any changes to urlparse module
+      should conform to this. Certain deviations could be observed, which are
+      mostly due backward compatiblity purposes and for certain de-facto
+      parsing requirements as commonly observed in major browsers.
+
+   :rfc:`2732` - Format for Literal IPv6 Addresses in URL's.
+      This specifies the parsing requirements of IPv6 URLs.
+
+   :rfc:`2396` - Uniform Resource Identifiers (URI): Generic Syntax
+      Document describing the generic syntactic requirements for both Uniform Resource
+      Names (URNs) and Uniform Resource Locators (URLs).
+
+   :rfc:`2368` - The mailto URL scheme.
+      Parsing requirements for mailto url schemes.
 
    :rfc:`1808` - Relative Uniform Resource Locators
       This Request For Comments includes the rules for joining an absolute and a
       relative URL, including a fair number of "Abnormal Examples" which govern the
       treatment of border cases.
 
-   :rfc:`2396` - Uniform Resource Identifiers (URI): Generic Syntax
-      Document describing the generic syntactic requirements for both Uniform Resource
-      Names (URNs) and Uniform Resource Locators (URLs).
+   :rfc:`1738` - Uniform Resource Locators (URL)
+      This specifies the formal syntax and semantics of absolute URLs.
 
 
 .. _urlparse-result-object:

Modified: python/branches/py3k-cdecimal/Doc/library/urllib.request.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/urllib.request.rst	(original)
+++ python/branches/py3k-cdecimal/Doc/library/urllib.request.rst	Fri Apr 23 10:13:30 2010
@@ -1072,30 +1072,37 @@
 Examples
 --------
 
-This example gets the python.org main page and displays the first 100 bytes of
+This example gets the python.org main page and displays the first 300 bytes of
 it. ::
 
    >>> import urllib.request
    >>> f = urllib.request.urlopen('http://www.python.org/')
-   >>> print(f.read(100))
-   b'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-   <?xml-stylesheet href="./css/ht2html'
-
-Note that in Python 3, urlopen returns a bytes object by default. In many
-circumstances, you might expect the output of urlopen to be a string. This
-might be a carried over expectation from Python 2, where urlopen returned
-string or it might even the common usecase. In those cases, you should
-explicitly decode the bytes to string.
-
-In the examples below, we have chosen *utf-8* encoding for demonstration, you
-might choose the encoding which is suitable for the webpage you are
-requesting::
+   >>> print(f.read(300))
+   b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\n\n<html
+   xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\n<head>\n
+   <meta http-equiv="content-type" content="text/html; charset=utf-8" />\n
+   <title>Python Programming '
+
+Note that urlopen returns a bytes object.  This is because there is no way
+for urlopen to automatically determine the encoding of the byte stream
+it receives from the http server. In general, a program will decode
+the returned bytes object to string once it determines or guesses
+the appropriate encoding.
+
+The following W3C document, http://www.w3.org/International/O-charset  , lists
+the various ways in which a (X)HTML or a XML document could have specified its
+encoding information.
+
+As python.org website uses *utf-8* encoding as specified in it's meta tag, we
+will use same for decoding the bytes object. ::
 
    >>> import urllib.request
    >>> f = urllib.request.urlopen('http://www.python.org/')
-   >>> print(f.read(100).decode('utf-8')
-   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-   <?xml-stylesheet href="./css/ht2html
+   >>> print(fp.read(100).decode('utf-8'))
+   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+   "http://www.w3.org/TR/xhtml1/DTD/xhtm
+
 
 In the following example, we are sending a data-stream to the stdin of a CGI
 and reading the data it returns to us. Note that this example will only work

Modified: python/branches/py3k-cdecimal/Doc/library/winreg.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/winreg.rst	(original)
+++ python/branches/py3k-cdecimal/Doc/library/winreg.rst	Fri Apr 23 10:13:30 2010
@@ -61,15 +61,40 @@
    :exc:`WindowsError` exception is  raised.
 
 
+.. function:: CreateKeyEx(key, sub_key, res=0, sam=KEY_ALL_ACCESS)
+
+   Creates or opens the specified key, returning a :dfn:`handle object`
+
+   *key* is an already open key, or one of the predefined :const:`HKEY_\*`
+   constants.
+
+   *sub_key* is a string that names the key this method opens or creates.
+
+   *res* is a reserved integer, and must be zero. The default is zero.
+
+   *sam* is an integer that specifies an access mask that describes the desired
+   security access for the key. Default is :const:`KEY_ALL_ACCESS`
+
+   If *key* is one of the predefined keys, *sub_key* may  be ``None``. In that
+   case, the handle returned is the same key handle  passed in to the function.
+
+   If the key already exists, this function opens the existing key.
+
+   The return value is the handle of the opened key. If the function fails, a
+   :exc:`WindowsError` exception is raised.
+
+   .. versionadded:: 3.2
+
+
 .. function:: DeleteKey(key, sub_key)
 
    Deletes the specified key.
 
-   *key* is an already open key, or any one of the predefined  :const:`HKEY_\*`
+   *key* is an already open key, or any one of the predefined :const:`HKEY_\*`
    constants.
 
-   *sub_key* is a string that must be a subkey of the key  identified by the *key*
-   parameter.  This value must not be  ``None``, and the key may not have subkeys.
+   *sub_key* is a string that must be a subkey of the key identified by the *key*
+   parameter.  This value must not be ``None``, and the key may not have subkeys.
 
    *This method can not delete keys with subkeys.*
 
@@ -77,6 +102,37 @@
    If the method fails, a :exc:`WindowsError`  exception is raised.
 
 
+.. function:: DeleteKeyEx(key, sub_key, sam=KEY_WOW64_64KEY, res=0)
+
+   Deletes the specified key.
+
+   .. note::
+      The :func:`DeleteKeyEx` function is implemented with the RegDeleteKeyEx
+      Windows API function, which is specific to 64-bit versions of Windows.
+      See http://msdn.microsoft.com/en-us/library/ms724847%28VS.85%29.aspx
+
+   *key* is an already open key, or any one of the predefined :const:`HKEY_\*`
+   constants.
+
+   *sub_key* is a string that must be a subkey of the key identified by the
+   *key* parameter. This value must not be ``None``, and the key may not have
+   subkeys.
+
+   *res* is a reserved integer, and must be zero. The default is zero.
+
+   *sam* is an integer that specifies an access mask that describes the
+   desired security access for the key. Default is :const:`KEY_WOW64_64KEY`
+
+   *This method can not delete keys with subkeys.*
+
+   If the method succeeds, the entire key, including all of its values, is
+   removed. If the method fails, a :exc:`WindowsError` exception is raised.
+
+   On unsupported Windows versions, :exc:`NotImplementedError` is raised.
+
+   .. versionadded:: 3.2
+
+
 .. function:: DeleteValue(key, value)
 
    Removes a named value from a registry key.
@@ -374,6 +430,48 @@
    registry.  This helps the registry perform efficiently.
 
 
+.. function:: DisableReflectionKey(key)
+
+   Disables registry reflection for 32-bit processes running on a 64-bit
+   Operating System.
+
+   *key* is an already open key, or one of the predefined :const:`HKEY_\*`
+   constants.
+
+   Will generally raise :exc:`NotImplemented` if executed on a 32-bit
+   Operating System.
+
+   If the key is not on the reflection list, the function succeeds but has no
+   effect. Disabling reflection for a key does not affect reflection of any
+   subkeys.
+
+
+.. function:: EnableReflectionKey(key)
+
+   Restores registry reflection for the specified disabled key.
+
+   *key* is an already open key, or one of the predefined :const:`HKEY_\*`
+   constants.
+
+   Will generally raise :exc:`NotImplemented` if executed on a 32-bit
+   Operating System.
+
+   Restoring reflection for a key does not affect reflection of any subkeys.
+
+
+.. function:: QueryReflectionKey(key)
+
+   Determines the reflection state for the specified key.
+
+   *key* is an already open key, or one of the predefined :const:`HKEY_\*`
+   constants.
+
+   Returns ``True`` if reflection is disabled.
+
+   Will generally raise :exc:`NotImplemented` if executed on a 32-bit
+   Operating System.
+
+
 .. _handle-object:
 
 Registry Handle Objects

Modified: python/branches/py3k-cdecimal/Doc/tools/sphinxext/indexsidebar.html
==============================================================================
--- python/branches/py3k-cdecimal/Doc/tools/sphinxext/indexsidebar.html	(original)
+++ python/branches/py3k-cdecimal/Doc/tools/sphinxext/indexsidebar.html	Fri Apr 23 10:13:30 2010
@@ -19,4 +19,5 @@
               <li><a href="http://wiki.python.org/moin/PythonBooks">Book List</a></li>
               <li><a href="http://www.python.org/doc/av/">Audio/Visual Talks</a></li>
               <li><a href="http://www.python.org/doc/other/">Other Doc Collections</a></li>
+              <li><a href="{{ pathto('bugs') }}">Report a Bug</a></li>
             </ul>

Modified: python/branches/py3k-cdecimal/Doc/tools/sphinxext/layout.html
==============================================================================
--- python/branches/py3k-cdecimal/Doc/tools/sphinxext/layout.html	(original)
+++ python/branches/py3k-cdecimal/Doc/tools/sphinxext/layout.html	Fri Apr 23 10:13:30 2010
@@ -16,6 +16,18 @@
     <a href="http://www.python.org/psf/donations/">Please donate.</a>
     <br />
     Last updated on {{ last_updated|e }}.
+    <a href="{{ pathto('bugs') }}">Found a bug</a>?
+    <br />
     Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> {{ sphinx_version|e }}.
     </div>
 {% endblock %}
+{% block sidebarsourcelink %}
+{%- if show_source and has_source and sourcename %}
+<h3>{{ _('This Page') }}</h3>
+<ul class="this-page-menu">
+  <li><a href="{{ pathto('bugs') }}">Report a Bug</a></li>
+  <li><a href="{{ pathto('_sources/' + sourcename, true)|e }}"
+         rel="nofollow">Show Source</a></li>
+</ul>
+{%- endif %}
+{% endblock %}

Modified: python/branches/py3k-cdecimal/Doc/whatsnew/3.2.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/whatsnew/3.2.rst	(original)
+++ python/branches/py3k-cdecimal/Doc/whatsnew/3.2.rst	Fri Apr 23 10:13:30 2010
@@ -85,16 +85,17 @@
   (Contributed by Georg Brandl and Mattias Brändström;
   `appspot issue 53094 <http://codereview.appspot.com/53094>`_.)
 
-* The :func:`shutil.copytree` function has two new options
+* The :func:`shutil.copytree` function has two new options:
 
-  * ignore_dangling_symlinks: when symlinks=false (meaning that the function
-    copy the file pointed by the symlink, not the symlink itself)
-    this option will silence the error thrown if the file doesn't exists.
+  * *ignore_dangling_symlinks*: when ``symlinks=False`` (meaning that the
+    function copies the file pointed to by the symlink, not the symlink
+    itself) this option will silence the error thrown if the file doesn't
+    exist.
 
-  * copy_function: a callable that will be used to copy files.
+  * *copy_function*: a callable that will be used to copy files.
     :func:`shutil.copy2` is used by default.
 
-  (Contributed by Tarek Ziade)
+  (Contributed by Tarek Ziade.)
 
 Multi-threading
 ===============
@@ -114,7 +115,7 @@
   (however, "priority requests" as exposed in this message have not been
   kept for inclusion).
 
-  (Contributed by Antoine Pitrou)
+  (Contributed by Antoine Pitrou.)
 
 * Recursive locks (created with the :func:`threading.RLock` API) now benefit
   from a C implementation which makes them as fast as regular locks, and
@@ -150,4 +151,6 @@
 This section lists previously described changes and other bugfixes
 that may require changes to your code:
 
+* bytearray objects cannot be used anymore as filenames: convert them to bytes
+
 * Stub

Modified: python/branches/py3k-cdecimal/Include/unicodeobject.h
==============================================================================
--- python/branches/py3k-cdecimal/Include/unicodeobject.h	(original)
+++ python/branches/py3k-cdecimal/Include/unicodeobject.h	Fri Apr 23 10:13:30 2010
@@ -1238,8 +1238,8 @@
 /* --- File system encoding ---------------------------------------------- */
 
 /* ParseTuple converter which converts a Unicode object into the file
-   system encoding, using the PEP 383 error handler; bytes objects are
-   output as-is. */
+   system encoding as a bytes object, using the PEP 383 error handler; bytes
+   objects are output as-is. */
 
 PyAPI_FUNC(int) PyUnicode_FSConverter(PyObject*, void*);
 

Modified: python/branches/py3k-cdecimal/Lib/email/test/test_email.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/email/test/test_email.py	(original)
+++ python/branches/py3k-cdecimal/Lib/email/test/test_email.py	Fri Apr 23 10:13:30 2010
@@ -520,15 +520,10 @@
 
     def test_default_cte(self):
         eq = self.assertEqual
+        # 7bit data and the default us-ascii _charset
         msg = MIMEText('hello world')
         eq(msg['content-transfer-encoding'], '7bit')
-
-    def test_default_cte(self):
-        eq = self.assertEqual
-        # With no explicit _charset its us-ascii, and all are 7-bit
-        msg = MIMEText('hello world')
-        eq(msg['content-transfer-encoding'], '7bit')
-        # Similar, but with 8-bit data
+        # Similar, but with 8bit data
         msg = MIMEText('hello \xf8 world')
         eq(msg['content-transfer-encoding'], '8bit')
         # And now with a different charset

Modified: python/branches/py3k-cdecimal/Lib/mailcap.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/mailcap.py	(original)
+++ python/branches/py3k-cdecimal/Lib/mailcap.py	Fri Apr 23 10:13:30 2010
@@ -164,7 +164,7 @@
     if MIMEtype in caps:
         entries = entries + caps[MIMEtype]
     if key is not None:
-        entries = filter(lambda e, key=key: key in e, entries)
+        entries = [e for e in entries if key in e]
     return entries
 
 def subst(field, MIMEtype, filename, plist=[]):
@@ -239,14 +239,12 @@
     if not caps: caps = getcaps()
     print("Mailcap entries:")
     print()
-    ckeys = caps.keys()
-    ckeys.sort()
+    ckeys = sorted(caps)
     for type in ckeys:
         print(type)
         entries = caps[type]
         for e in entries:
-            keys = e.keys()
-            keys.sort()
+            keys = sorted(e)
             for k in keys:
                 print("  %-15s" % k, e[k])
             print()

Modified: python/branches/py3k-cdecimal/Lib/shutil.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/shutil.py	(original)
+++ python/branches/py3k-cdecimal/Lib/shutil.py	Fri Apr 23 10:13:30 2010
@@ -9,7 +9,6 @@
 import stat
 from os.path import abspath
 import fnmatch
-from warnings import warn
 import collections
 import errno
 
@@ -410,7 +409,7 @@
 
     return archive_name
 
-def _call_external_zip(directory, verbose=False):
+def _call_external_zip(base_dir, zip_filename, verbose=False, dry_run=False):
     # XXX see if we want to keep an external call here
     if verbose:
         zipoptions = "-r"
@@ -453,7 +452,7 @@
         zipfile = None
 
     if zipfile is None:
-        _call_external_zip(base_dir, verbose)
+        _call_external_zip(base_dir, zip_filename, verbose, dry_run)
     else:
         if logger is not None:
             logger.info("creating '%s' and adding '%s' to it",

Modified: python/branches/py3k-cdecimal/Lib/sqlite3/test/regression.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/sqlite3/test/regression.py	(original)
+++ python/branches/py3k-cdecimal/Lib/sqlite3/test/regression.py	Fri Apr 23 10:13:30 2010
@@ -274,6 +274,13 @@
         """
         self.assertRaises(sqlite.Warning, self.con, 1)
 
+    def CheckCollation(self):
+        def collation_cb(a, b):
+            return 1
+        self.assertRaises(sqlite.ProgrammingError, self.con.create_collation,
+            # Lone surrogate cannot be encoded to the default encoding (utf8)
+            "\uDC80", collation_cb)
+
 def suite():
     regression_suite = unittest.makeSuite(RegressionTests, "Check")
     return unittest.TestSuite((regression_suite,))

Modified: python/branches/py3k-cdecimal/Lib/test/gdb_sample.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/gdb_sample.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/gdb_sample.py	Fri Apr 23 10:13:30 2010
@@ -7,6 +7,6 @@
     baz(a, b, c)
 
 def baz(*args):
-    print(42)
+    id(42)
 
 foo(1, 2, 3)

Modified: python/branches/py3k-cdecimal/Lib/test/support.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/support.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/support.py	Fri Apr 23 10:13:30 2010
@@ -755,6 +755,17 @@
 
 
 @contextlib.contextmanager
+def transient_internet():
+    """Return a context manager that raises ResourceDenied when various issues
+    with the Internet connection manifest themselves as exceptions."""
+    time_out = TransientResource(IOError, errno=errno.ETIMEDOUT)
+    socket_peer_reset = TransientResource(socket.error, errno=errno.ECONNRESET)
+    ioerror_peer_reset = TransientResource(IOError, errno=errno.ECONNRESET)
+    with time_out, socket_peer_reset, ioerror_peer_reset:
+        yield
+
+
+ at contextlib.contextmanager
 def captured_output(stream_name):
     """Run the 'with' statement body using a StringIO object in place of a
     specific attribute on the sys module.

Modified: python/branches/py3k-cdecimal/Lib/test/test_bytes.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_bytes.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/test_bytes.py	Fri Apr 23 10:13:30 2010
@@ -815,13 +815,6 @@
         self.assertRaises(BufferError, delslice)
         self.assertEquals(b, orig)
 
-    def test_empty_bytearray(self):
-        # Issue #7561: operations on empty bytearrays could crash in many
-        # situations, due to a fragile implementation of the
-        # PyByteArray_AS_STRING() C macro.
-        self.assertRaises(ValueError, int, bytearray(b''))
-        self.assertRaises((ValueError, OSError), os.mkdir, bytearray(b''))
-
 
 class AssortedBytesTest(unittest.TestCase):
     #

Modified: python/branches/py3k-cdecimal/Lib/test/test_codecs.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_codecs.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/test_codecs.py	Fri Apr 23 10:13:30 2010
@@ -571,6 +571,16 @@
     def test_lone_surrogates(self):
         self.assertRaises(UnicodeEncodeError, "\ud800".encode, "utf-8")
         self.assertRaises(UnicodeDecodeError, b"\xed\xa0\x80".decode, "utf-8")
+        self.assertEqual("[\uDC80]".encode("utf-8", "backslashreplace"),
+                         b'[\\udc80]')
+        self.assertEqual("[\uDC80]".encode("utf-8", "xmlcharrefreplace"),
+                         b'[&#56448;]')
+        self.assertEqual("[\uDC80]".encode("utf-8", "surrogateescape"),
+                         b'[\x80]')
+        self.assertEqual("[\uDC80]".encode("utf-8", "ignore"),
+                         b'[]')
+        self.assertEqual("[\uDC80]".encode("utf-8", "replace"),
+                         b'[?]')
 
     def test_surrogatepass_handler(self):
         self.assertEquals("abc\ud800def".encode("utf-8", "surrogatepass"),

Modified: python/branches/py3k-cdecimal/Lib/test/test_ftplib.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_ftplib.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/test_ftplib.py	Fri Apr 23 10:13:30 2010
@@ -28,6 +28,7 @@
 
 
 class DummyDTPHandler(asynchat.async_chat):
+    dtp_conn_closed = False
 
     def __init__(self, conn, baseclass):
         asynchat.async_chat.__init__(self, conn)
@@ -38,8 +39,13 @@
         self.baseclass.last_received_data += self.recv(1024).decode('ascii')
 
     def handle_close(self):
-        self.baseclass.push('226 transfer complete')
-        self.close()
+        # XXX: this method can be called many times in a row for a single
+        # connection, including in clear-text (non-TLS) mode.
+        # (behaviour witnessed with test_data_connection)
+        if not self.dtp_conn_closed:
+            self.baseclass.push('226 transfer complete')
+            self.close()
+            self.dtp_conn_closed = True
 
     def push(self, what):
         super(DummyDTPHandler, self).push(what.encode('ascii'))
@@ -254,6 +260,7 @@
         """An asyncore.dispatcher subclass supporting TLS/SSL."""
 
         _ssl_accepting = False
+        _ssl_closing = False
 
         def secure_connection(self):
             self.del_channel()
@@ -280,15 +287,36 @@
             else:
                 self._ssl_accepting = False
 
+        def _do_ssl_shutdown(self):
+            self._ssl_closing = True
+            try:
+                self.socket = self.socket.unwrap()
+            except ssl.SSLError as err:
+                if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
+                                   ssl.SSL_ERROR_WANT_WRITE):
+                    return
+            except socket.error as err:
+                # Any "socket error" corresponds to a SSL_ERROR_SYSCALL return
+                # from OpenSSL's SSL_shutdown(), corresponding to a
+                # closed socket condition. See also:
+                # http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html
+                pass
+            self._ssl_closing = False
+            super(SSLConnection, self).close()
+
         def handle_read_event(self):
             if self._ssl_accepting:
                 self._do_ssl_handshake()
+            elif self._ssl_closing:
+                self._do_ssl_shutdown()
             else:
                 super(SSLConnection, self).handle_read_event()
 
         def handle_write_event(self):
             if self._ssl_accepting:
                 self._do_ssl_handshake()
+            elif self._ssl_closing:
+                self._do_ssl_shutdown()
             else:
                 super(SSLConnection, self).handle_write_event()
 
@@ -308,7 +336,7 @@
             except ssl.SSLError as err:
                 if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
                                    ssl.SSL_ERROR_WANT_WRITE):
-                    return ''
+                    return b''
                 if err.args[0] in (ssl.SSL_ERROR_EOF, ssl.SSL_ERROR_ZERO_RETURN):
                     self.handle_close()
                     return b''
@@ -318,12 +346,9 @@
             raise
 
         def close(self):
-            try:
-                if isinstance(self.socket, ssl.SSLSocket):
-                    if self.socket._sslobj is not None:
-                        self.socket.unwrap()
-            finally:
-                super(SSLConnection, self).close()
+            if (isinstance(self.socket, ssl.SSLSocket) and
+                self.socket._sslobj is not None):
+                self._do_ssl_shutdown()
 
 
     class DummyTLS_DTPHandler(SSLConnection, DummyDTPHandler):
@@ -606,21 +631,21 @@
         sock = self.client.transfercmd('list')
         self.assertNotIsInstance(sock, ssl.SSLSocket)
         sock.close()
-        self.client.voidresp()
+        self.assertEqual(self.client.voidresp(), "226 transfer complete")
 
         # secured, after PROT P
         self.client.prot_p()
         sock = self.client.transfercmd('list')
         self.assertIsInstance(sock, ssl.SSLSocket)
         sock.close()
-        self.client.voidresp()
+        self.assertEqual(self.client.voidresp(), "226 transfer complete")
 
         # PROT C is issued, the connection must be in cleartext again
         self.client.prot_c()
         sock = self.client.transfercmd('list')
         self.assertNotIsInstance(sock, ssl.SSLSocket)
         sock.close()
-        self.client.voidresp()
+        self.assertEqual(self.client.voidresp(), "226 transfer complete")
 
     def test_login(self):
         # login() is supposed to implicitly secure the control connection

Modified: python/branches/py3k-cdecimal/Lib/test/test_gdb.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_gdb.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/test_gdb.py	Fri Apr 23 10:13:30 2010
@@ -45,6 +45,8 @@
 
 HAS_PYUP_PYDOWN = gdb_has_frame_select()
 
+BREAKPOINT_FN='builtin_id'
+
 class DebuggerTests(unittest.TestCase):
 
     """Test that the debugger can debug Python."""
@@ -57,10 +59,10 @@
         out, err = subprocess.Popen(
             args, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
             ).communicate()
-        return out.decode('iso-8859-1'), err.decode('iso-8859-1')
+        return out.decode('utf-8'), err.decode('utf-8')
 
     def get_stack_trace(self, source=None, script=None,
-                        breakpoint='PyObject_Print',
+                        breakpoint=BREAKPOINT_FN,
                         cmds_after_breakpoint=None,
                         import_site=False):
         '''
@@ -78,7 +80,7 @@
         # error, which typically happens python is dynamically linked (the
         # breakpoints of interest are to be found in the shared library)
         # When this happens, we still get:
-        #   Function "PyObject_Print" not defined.
+        #   Function "textiowrapper_write" not defined.
         # emitted to stderr each time, alas.
 
         # Initially I had "--eval-command=continue" here, but removed it to
@@ -129,19 +131,21 @@
                      cmds_after_breakpoint=None,
                      import_site=False):
         # Given an input python source representation of data,
-        # run "python -c'print DATA'" under gdb with a breakpoint on
-        # PyObject_Print and scrape out gdb's representation of the "op"
+        # run "python -c'id(DATA)'" under gdb with a breakpoint on
+        # builtin_id and scrape out gdb's representation of the "op"
         # parameter, and verify that the gdb displays the same string
         #
+        # Verify that the gdb displays the expected string
+        #
         # For a nested structure, the first time we hit the breakpoint will
         # give us the top-level structure
-        gdb_output = self.get_stack_trace(source, breakpoint='PyObject_Print',
+        gdb_output = self.get_stack_trace(source, breakpoint=BREAKPOINT_FN,
                                           cmds_after_breakpoint=cmds_after_breakpoint,
                                           import_site=import_site)
         # gdb can insert additional '\n' and space characters in various places
         # in its output, depending on the width of the terminal it's connected
         # to (using its "wrap_here" function)
-        m = re.match('.*#0\s+PyObject_Print\s+\(\s*op\=\s*(.*?),\s+fp=.*\).*',
+        m = re.match('.*#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)\)\s+at\s+Python/bltinmodule.c.*',
                      gdb_output, re.DOTALL)
         if not m:
             self.fail('Unexpected gdb output: %r\n%s' % (gdb_output, gdb_output))
@@ -154,37 +158,34 @@
 
     def assertMultilineMatches(self, actual, pattern):
         m = re.match(pattern, actual, re.DOTALL)
-        self.assert_(m,
-                     msg='%r did not match %r' % (actual, pattern))
+        if not m:
+            self.fail(msg='%r did not match %r' % (actual, pattern))
 
     def get_sample_script(self):
         return findfile('gdb_sample.py')
 
 class PrettyPrintTests(DebuggerTests):
     def test_getting_backtrace(self):
-        gdb_output = self.get_stack_trace('print(42)')
-        self.assertTrue('PyObject_Print' in gdb_output)
+        gdb_output = self.get_stack_trace('id(42)')
+        self.assertTrue(BREAKPOINT_FN in gdb_output)
 
-    def assertGdbRepr(self, val, cmds_after_breakpoint=None):
+    def assertGdbRepr(self, val, exp_repr=None, cmds_after_breakpoint=None):
         # Ensure that gdb's rendering of the value in a debugged process
         # matches repr(value) in this process:
-        gdb_repr, gdb_output = self.get_gdb_repr('print(' + repr(val) + ')',
+        gdb_repr, gdb_output = self.get_gdb_repr('id(' + repr(val) + ')',
                                                  cmds_after_breakpoint)
-        self.assertEquals(gdb_repr, repr(val), gdb_output)
+        if not exp_repr:
+            exp_repr = repr(val)
+        self.assertEquals(gdb_repr, exp_repr,
+                          ('%r did not equal expected %r; full output was:\n%s'
+                           % (gdb_repr, exp_repr, gdb_output)))
 
     def test_int(self):
-        'Verify the pretty-printing of various "int" values'
+        'Verify the pretty-printing of various "int"/long values'
         self.assertGdbRepr(42)
         self.assertGdbRepr(0)
         self.assertGdbRepr(-7)
-        self.assertGdbRepr(sys.maxint)
-        self.assertGdbRepr(-sys.maxint)
-
-    def test_long(self):
-        'Verify the pretty-printing of various "long" values'
-        self.assertGdbRepr(0)
         self.assertGdbRepr(1000000000000)
-        self.assertGdbRepr(-1)
         self.assertGdbRepr(-1000000000000000)
 
     def test_singletons(self):
@@ -202,27 +203,27 @@
     def test_lists(self):
         'Verify the pretty-printing of lists'
         self.assertGdbRepr([])
-        self.assertGdbRepr(range(5))
+        self.assertGdbRepr(list(range(5)))
+
+    def test_bytes(self):
+        'Verify the pretty-printing of bytes'
+        self.assertGdbRepr(b'')
+        self.assertGdbRepr(b'And now for something hopefully the same')
+        self.assertGdbRepr(b'string with embedded NUL here \0 and then some more text')
+        self.assertGdbRepr(b'this is a tab:\t'
+                           b' this is a slash-N:\n'
+                           b' this is a slash-R:\r'
+                           )
+
+        self.assertGdbRepr(b'this is byte 255:\xff and byte 128:\x80')
+
+        self.assertGdbRepr(bytes([b for b in range(255)]))
 
     def test_strings(self):
-        'Verify the pretty-printing of strings'
+        'Verify the pretty-printing of unicode strings'
         self.assertGdbRepr('')
         self.assertGdbRepr('And now for something hopefully the same')
         self.assertGdbRepr('string with embedded NUL here \0 and then some more text')
-        self.assertGdbRepr('this is byte 255:\xff and byte 128:\x80')
-
-    def test_tuples(self):
-        'Verify the pretty-printing of tuples'
-        self.assertGdbRepr(tuple())
-        self.assertGdbRepr((1,))
-        self.assertGdbRepr(('foo', 'bar', 'baz'))
-
-    def test_unicode(self):
-        'Verify the pretty-printing of unicode values'
-        # Test the empty unicode string:
-        self.assertGdbRepr('')
-
-        self.assertGdbRepr('hello world')
 
         # Test printing a single character:
         #    U+2620 SKULL AND CROSSBONES
@@ -238,14 +239,19 @@
         # This is:
         # UTF-8: 0xF0 0x9D 0x84 0xA1
         # UTF-16: 0xD834 0xDD21
-        try:
-            # This will only work on wide-unicode builds:
-            self.assertGdbRepr(unichr(0x1D121))
-        except ValueError as e:
-            # We're probably on a narrow-unicode build; if we're seeing a
-            # different problem, then re-raise it:
-            if e.args != ('unichr() arg not in range(0x10000) (narrow Python build)',):
-                raise e
+        if sys.maxunicode == 0x10FFFF:
+            # wide unicode:
+            self.assertGdbRepr(chr(0x1D121))
+        else:
+            # narrow unicode:
+            self.assertGdbRepr(chr(0x1D121),
+                               "'\\U0000d834\\U0000dd21'")
+
+    def test_tuples(self):
+        'Verify the pretty-printing of tuples'
+        self.assertGdbRepr(tuple())
+        self.assertGdbRepr((1,), '(1,)')
+        self.assertGdbRepr(('foo', 'bar', 'baz'))
 
     def test_sets(self):
         'Verify the pretty-printing of sets'
@@ -253,12 +259,12 @@
         self.assertGdbRepr(set(['a', 'b']))
         self.assertGdbRepr(set([4, 5, 6]))
 
-        # Ensure that we handled sets containing the "dummy" key value,
+        # Ensure that we handle sets containing the "dummy" key value,
         # which happens on deletion:
         gdb_repr, gdb_output = self.get_gdb_repr('''s = set(['a','b'])
 s.pop()
-print(s)''')
-        self.assertEquals(gdb_repr, "set(['b'])")
+id(s)''')
+        self.assertEquals(gdb_repr, "{'b'}")
 
     def test_frozensets(self):
         'Verify the pretty-printing of frozensets'
@@ -271,43 +277,31 @@
         gdb_repr, gdb_output = self.get_gdb_repr('''
 try:
     raise RuntimeError("I am an error")
-except RuntimeError, e:
-    print(e)
+except RuntimeError as e:
+    id(e)
 ''')
         self.assertEquals(gdb_repr,
-                          "exceptions.RuntimeError('I am an error',)")
+                          "RuntimeError('I am an error',)")
 
 
         # Test division by zero:
         gdb_repr, gdb_output = self.get_gdb_repr('''
 try:
     a = 1 / 0
-except ZeroDivisionError, e:
-    print(e)
+except ZeroDivisionError as e:
+    id(e)
 ''')
         self.assertEquals(gdb_repr,
-                          "exceptions.ZeroDivisionError('integer division or modulo by zero',)")
-
-    def test_classic_class(self):
-        'Verify the pretty-printing of classic class instances'
-        gdb_repr, gdb_output = self.get_gdb_repr('''
-class Foo:
-    pass
-foo = Foo()
-foo.an_int = 42
-print(foo)''')
-        m = re.match(r'<Foo\(an_int=42\) at remote 0x[0-9a-f]+>', gdb_repr)
-        self.assertTrue(m,
-                        msg='Unexpected classic-class rendering %r' % gdb_repr)
+                          "ZeroDivisionError('division by zero',)")
 
     def test_modern_class(self):
         'Verify the pretty-printing of new-style class instances'
         gdb_repr, gdb_output = self.get_gdb_repr('''
-class Foo(object):
+class Foo:
     pass
 foo = Foo()
 foo.an_int = 42
-print(foo)''')
+id(foo)''')
         m = re.match(r'<Foo\(an_int=42\) at remote 0x[0-9a-f]+>', gdb_repr)
         self.assertTrue(m,
                         msg='Unexpected new-style class rendering %r' % gdb_repr)
@@ -320,8 +314,9 @@
 foo = Foo()
 foo += [1, 2, 3]
 foo.an_int = 42
-print(foo)''')
+id(foo)''')
         m = re.match(r'<Foo\(an_int=42\) at remote 0x[0-9a-f]+>', gdb_repr)
+
         self.assertTrue(m,
                         msg='Unexpected new-style class rendering %r' % gdb_repr)
 
@@ -334,12 +329,13 @@
     pass
 foo = Foo((1, 2, 3))
 foo.an_int = 42
-print(foo)''')
+id(foo)''')
         m = re.match(r'<Foo\(an_int=42\) at remote 0x[0-9a-f]+>', gdb_repr)
+
         self.assertTrue(m,
                         msg='Unexpected new-style class rendering %r' % gdb_repr)
 
-    def assertSane(self, source, corruption, expvalue=None, exptype=None):
+    def assertSane(self, source, corruption, exprepr=None):
         '''Run Python under gdb, corrupting variables in the inferior process
         immediately before taking a backtrace.
 
@@ -353,19 +349,15 @@
         gdb_repr, gdb_output = \
             self.get_gdb_repr(source,
                               cmds_after_breakpoint=cmds_after_breakpoint)
-
-        if expvalue:
-            if gdb_repr == repr(expvalue):
+        if exprepr:
+            if gdb_repr == exprepr:
                 # gdb managed to print the value in spite of the corruption;
                 # this is good (see http://bugs.python.org/issue8330)
                 return
 
-        if exptype:
-            pattern = '<' + exptype + ' at remote 0x[0-9a-f]+>'
-        else:
-            # Match anything for the type name; 0xDEADBEEF could point to
-            # something arbitrary (see  http://bugs.python.org/issue8330)
-            pattern = '<.* at remote 0x[0-9a-f]+>'
+        # Match anything for the type name; 0xDEADBEEF could point to
+        # something arbitrary (see  http://bugs.python.org/issue8330)
+        pattern = '<.* at remote 0x[0-9a-f]+>'
 
         m = re.match(pattern, gdb_repr)
         if not m:
@@ -375,8 +367,8 @@
     def test_NULL_ptr(self):
         'Ensure that a NULL PyObject* is handled gracefully'
         gdb_repr, gdb_output = (
-            self.get_gdb_repr('print(42)',
-                              cmds_after_breakpoint=['set variable op=0',
+            self.get_gdb_repr('id(42)',
+                              cmds_after_breakpoint=['set variable v=0',
                                                      'backtrace'])
             )
 
@@ -384,44 +376,33 @@
 
     def test_NULL_ob_type(self):
         'Ensure that a PyObject* with NULL ob_type is handled gracefully'
-        self.assertSane('print(42)',
-                        'set op->ob_type=0')
+        self.assertSane('id(42)',
+                        'set v->ob_type=0')
 
     def test_corrupt_ob_type(self):
         'Ensure that a PyObject* with a corrupt ob_type is handled gracefully'
-        self.assertSane('print(42)',
-                        'set op->ob_type=0xDEADBEEF',
-                        expvalue=42)
+        self.assertSane('id(42)',
+                        'set v->ob_type=0xDEADBEEF',
+                        exprepr='42')
 
     def test_corrupt_tp_flags(self):
         'Ensure that a PyObject* with a type with corrupt tp_flags is handled'
-        self.assertSane('print(42)',
-                        'set op->ob_type->tp_flags=0x0',
-                        expvalue=42)
+        self.assertSane('id(42)',
+                        'set v->ob_type->tp_flags=0x0',
+                        exprepr='42')
 
     def test_corrupt_tp_name(self):
         'Ensure that a PyObject* with a type with corrupt tp_name is handled'
-        self.assertSane('print(42)',
-                        'set op->ob_type->tp_name=0xDEADBEEF',
-                        expvalue=42)
-
-    def test_NULL_instance_dict(self):
-        'Ensure that a PyInstanceObject with with a NULL in_dict is handled'
-        self.assertSane('''
-class Foo:
-    pass
-foo = Foo()
-foo.an_int = 42
-print(foo)''',
-                        'set ((PyInstanceObject*)op)->in_dict = 0',
-                        exptype='Foo')
+        self.assertSane('id(42)',
+                        'set v->ob_type->tp_name=0xDEADBEEF',
+                        exprepr='42')
 
     def test_builtins_help(self):
         'Ensure that the new-style class _Helper in site.py can be handled'
         # (this was the issue causing tracebacks in
         #  http://bugs.python.org/issue8032#msg100537 )
+        gdb_repr, gdb_output = self.get_gdb_repr('id(__builtins__.help)', import_site=True)
 
-        gdb_repr, gdb_output = self.get_gdb_repr('print(__builtins__.help)', import_site=True)
         m = re.match(r'<_Helper at remote 0x[0-9a-f]+>', gdb_repr)
         self.assertTrue(m,
                         msg='Unexpected rendering %r' % gdb_repr)
@@ -430,20 +411,18 @@
         '''Ensure that a reference loop involving a list doesn't lead proxyval
         into an infinite loop:'''
         gdb_repr, gdb_output = \
-            self.get_gdb_repr("a = [3, 4, 5] ; a.append(a) ; print(a)")
-
+            self.get_gdb_repr("a = [3, 4, 5] ; a.append(a) ; id(a)")
         self.assertEquals(gdb_repr, '[3, 4, 5, [...]]')
 
         gdb_repr, gdb_output = \
-            self.get_gdb_repr("a = [3, 4, 5] ; b = [a] ; a.append(b) ; print(a)")
-
+            self.get_gdb_repr("a = [3, 4, 5] ; b = [a] ; a.append(b) ; id(a)")
         self.assertEquals(gdb_repr, '[3, 4, 5, [[...]]]')
 
     def test_selfreferential_dict(self):
         '''Ensure that a reference loop involving a dict doesn't lead proxyval
         into an infinite loop:'''
         gdb_repr, gdb_output = \
-            self.get_gdb_repr("a = {} ; b = {'bar':a} ; a['foo'] = b ; print(a)")
+            self.get_gdb_repr("a = {} ; b = {'bar':a} ; a['foo'] = b ; id(a)")
 
         self.assertEquals(gdb_repr, "{'foo': {'bar': {...}}}")
 
@@ -454,7 +433,7 @@
     pass
 foo = Foo()
 foo.an_attr = foo
-print(foo)''')
+id(foo)''')
         self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x[0-9a-f]+>',
                                  gdb_repr),
                         'Unexpected gdb representation: %r\n%s' % \
@@ -467,7 +446,7 @@
     pass
 foo = Foo()
 foo.an_attr = foo
-print(foo)''')
+id(foo)''')
         self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x[0-9a-f]+>',
                                  gdb_repr),
                         'Unexpected gdb representation: %r\n%s' % \
@@ -481,7 +460,7 @@
 b = Foo()
 a.an_attr = b
 b.an_attr = a
-print(a)''')
+id(a)''')
         self.assertTrue(re.match('<Foo\(an_attr=<Foo\(an_attr=<\.\.\.>\) at remote 0x[0-9a-f]+>\) at remote 0x[0-9a-f]+>',
                                  gdb_repr),
                         'Unexpected gdb representation: %r\n%s' % \
@@ -489,7 +468,7 @@
 
     def test_truncation(self):
         'Verify that very long output is truncated'
-        gdb_repr, gdb_output = self.get_gdb_repr('print(range(1000))')
+        gdb_repr, gdb_output = self.get_gdb_repr('id(list(range(1000)))')
         self.assertEquals(gdb_repr,
                           "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, "
                           "14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, "
@@ -515,13 +494,9 @@
         self.assertEquals(len(gdb_repr),
                           1024 + len('...(truncated)'))
 
-    def test_builtin_function(self):
-        gdb_repr, gdb_output = self.get_gdb_repr('print(len)')
-        self.assertEquals(gdb_repr, '<built-in function len>')
-
     def test_builtin_method(self):
-        gdb_repr, gdb_output = self.get_gdb_repr('import sys; print(sys.stdout.readlines)')
-        self.assertTrue(re.match('<built-in method readlines of file object at remote 0x[0-9a-f]+>',
+        gdb_repr, gdb_output = self.get_gdb_repr('import sys; id(sys.stdout.readlines)')
+        self.assertTrue(re.match('<built-in method readlines of _io.TextIOWrapper object at remote 0x[0-9a-f]+>',
                                  gdb_repr),
                         'Unexpected gdb representation: %r\n%s' % \
                             (gdb_repr, gdb_output))
@@ -532,11 +507,11 @@
     pass
 
 foo(3, 4, 5)
-print foo.__code__''',
-                                          breakpoint='PyObject_Print',
-                                          cmds_after_breakpoint=['print (PyFrameObject*)(((PyCodeObject*)op)->co_zombieframe)']
+id(foo.__code__)''',
+                                          breakpoint='builtin_id',
+                                          cmds_after_breakpoint=['print (PyFrameObject*)(((PyCodeObject*)v)->co_zombieframe)']
                                           )
-        self.assertTrue(re.match(r'.*\s+\$1 =\s+Frame 0x[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*',
+        self.assertTrue(re.match('.*\s+\$1 =\s+Frame 0x[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*',
                                  gdb_output,
                                  re.DOTALL),
                         'Unexpected gdb representation: %r\n%s' % (gdb_output, gdb_output))
@@ -555,7 +530,7 @@
                            '   7        baz(a, b, c)\n'
                            '   8    \n'
                            '   9    def baz(*args):\n'
-                           ' >10        print(42)\n'
+                           ' >10        id(42)\n'
                            '  11    \n'
                            '  12    foo(1, 2, 3)\n',
                            bt)
@@ -566,7 +541,7 @@
                                   cmds_after_breakpoint=['py-list 9'])
 
         self.assertListing('   9    def baz(*args):\n'
-                           ' >10        print(42)\n'
+                           ' >10        id(42)\n'
                            '  11    \n'
                            '  12    foo(1, 2, 3)\n',
                            bt)
@@ -619,7 +594,7 @@
 #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
     baz\(a, b, c\)
 #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 10, in baz \(args=\(1, 2, 3\)\)
-    print\(42\)
+    id\(42\)
 $''')
 
 class PyBtTests(DebuggerTests):
@@ -662,7 +637,7 @@
         bt = self.get_stack_trace(script=self.get_sample_script(),
                                   cmds_after_breakpoint=['py-print len'])
         self.assertMultilineMatches(bt,
-                                    r".*\nbuiltin 'len' = <built-in function len>\n.*")
+                                    r".*\nbuiltin 'len' = <built-in method len of module object at remote 0x[0-9a-f]+>\n.*")
 
 class PyLocalsTests(DebuggerTests):
     def test_basic_command(self):

Modified: python/branches/py3k-cdecimal/Lib/test/test_genericpath.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_genericpath.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/test_genericpath.py	Fri Apr 23 10:13:30 2010
@@ -286,7 +286,7 @@
                     self.assertIsInstance(abspath(path), str)
 
     @unittest.skipIf(sys.platform == 'darwin',
-        "Mac OS X deny the creation of a directory with an invalid utf8 name")
+        "Mac OS X denies the creation of a directory with an invalid utf8 name")
     def test_nonascii_abspath(self):
         # Test non-ASCII, non-UTF8 bytes in the path.
         with support.temp_cwd(b'\xe7w\xf0'):

Modified: python/branches/py3k-cdecimal/Lib/test/test_os.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_os.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/test_os.py	Fri Apr 23 10:13:30 2010
@@ -607,14 +607,6 @@
     def test_execvpe_with_bad_arglist(self):
         self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
 
-class ArgTests(unittest.TestCase):
-    def test_bytearray(self):
-        # Issue #7561: posix module didn't release bytearray exports properly.
-        b = bytearray(os.sep.encode('ascii'))
-        self.assertRaises(OSError, os.mkdir, b)
-        # Check object is still resizable.
-        b[:] = b''
-
 class Win32ErrorTests(unittest.TestCase):
     def test_rename(self):
         self.assertRaises(WindowsError, os.rename, support.TESTFN, support.TESTFN+".bak")
@@ -872,7 +864,6 @@
 
 def test_main():
     support.run_unittest(
-        ArgTests,
         FileTests,
         StatAttributeTests,
         EnvironTests,

Modified: python/branches/py3k-cdecimal/Lib/test/test_ssl.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_ssl.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/test_ssl.py	Fri Apr 23 10:13:30 2010
@@ -218,6 +218,29 @@
         if support.verbose:
             sys.stdout.write("\nVerified certificate for svn.python.org:443 is\n%s\n" % pem)
 
+    def test_algorithms(self):
+        # Issue #8484: all algorithms should be available when verifying a
+        # certificate.
+        # SHA256 was added in OpenSSL 0.9.8
+        if ssl.OPENSSL_VERSION_INFO < (0, 9, 8, 0, 15):
+            self.skipTest("SHA256 not available on %r" % ssl.OPENSSL_VERSION)
+        # NOTE: https://sha256.tbs-internet.com is another possible test host
+        remote = ("sha2.hboeck.de", 443)
+        sha256_cert = os.path.join(os.path.dirname(__file__), "sha256.pem")
+        s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+                            cert_reqs=ssl.CERT_REQUIRED,
+                            ca_certs=sha256_cert,)
+        with support.transient_internet():
+            try:
+                s.connect(remote)
+                if support.verbose:
+                    sys.stdout.write("\nCipher with %r is %r\n" %
+                                     (remote, s.cipher()))
+                    sys.stdout.write("Certificate is:\n%s\n" %
+                                     pprint.pformat(s.getpeercert()))
+            finally:
+                s.close()
+
 
 try:
     import threading

Modified: python/branches/py3k-cdecimal/Lib/test/test_urlparse.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_urlparse.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/test_urlparse.py	Fri Apr 23 10:13:30 2010
@@ -273,10 +273,10 @@
         for invalid_url in [
                 'http://::12.34.56.78]/',
                 'http://[::1/foo/',
+                'ftp://[::1/foo/bad]/bad',
                 'http://[::1/foo/bad]/bad',
                 'http://[::ffff:12.34.56.78']:
-            self.assertRaises(ValueError, lambda : urllib.parse.urlparse(invalid_url).hostname)
-            self.assertRaises(ValueError, lambda : urllib.parse.urlparse(invalid_url))
+            self.assertRaises(ValueError, urllib.parse.urlparse, invalid_url)
 
     def test_urldefrag(self):
         for url, defrag, frag in [

Modified: python/branches/py3k-cdecimal/Lib/test/test_winreg.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_winreg.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/test_winreg.py	Fri Apr 23 10:13:30 2010
@@ -5,13 +5,32 @@
 import os, sys
 import unittest
 from test import support
+from platform import machine
 
 # Do this first so test will be skipped if module doesn't exist
 support.import_module('winreg')
 # Now import everything
 from winreg import *
 
+try:
+    REMOTE_NAME = sys.argv[sys.argv.index("--remote")+1]
+except (IndexError, ValueError):
+    REMOTE_NAME = None
+
+# tuple of (major, minor)
+WIN_VER = sys.getwindowsversion()[:2]
+# Some tests should only run on 64-bit architectures where WOW64 will be.
+WIN64_MACHINE = True if machine() == "AMD64" else False
+
+# Starting with Windows 7 and Windows Server 2008 R2, WOW64 no longer uses
+# registry reflection and formerly reflected keys are shared instead.
+# Windows 7 and Windows Server 2008 R2 are version 6.1. Due to this, some
+# tests are only valid up until 6.1
+HAS_REFLECTION = True if WIN_VER < (6, 1) else False
+
 test_key_name = "SOFTWARE\\Python Registry Test Key - Delete Me"
+# On OS'es that support reflection we should test with a reflected key
+test_reflect_key_name = "SOFTWARE\\Classes\\Python Test Key - Delete Me"
 
 test_data = [
     ("Int Value",     45,                                      REG_DWORD),
@@ -25,8 +44,7 @@
     ("Japanese 日本", "日本語", REG_SZ),
 ]
 
-class WinregTests(unittest.TestCase):
-    remote_name = None
+class BaseWinregTests(unittest.TestCase):
 
     def setUp(self):
         # Make sure that the test key is absent when the test
@@ -49,7 +67,8 @@
         CloseKey(hkey)
         DeleteKey(root, subkey)
 
-    def WriteTestData(self, root_key, subkeystr="sub_key"):
+    def _write_test_data(self, root_key, subkeystr="sub_key",
+                         CreateKey=CreateKey):
         # Set the default value for this key.
         SetValue(root_key, test_key_name, REG_SZ, "Default value")
         key = CreateKey(root_key, test_key_name)
@@ -90,7 +109,7 @@
         except EnvironmentError:
             pass
 
-    def ReadTestData(self, root_key, subkeystr="sub_key"):
+    def _read_test_data(self, root_key, subkeystr="sub_key", OpenKey=OpenKey):
         # Check we can get default value for this key.
         val = QueryValue(root_key, test_key_name)
         self.assertEquals(val, "Default value",
@@ -130,7 +149,7 @@
 
         key.Close()
 
-    def DeleteTestData(self, root_key, subkeystr="sub_key"):
+    def _delete_test_data(self, root_key, subkeystr="sub_key"):
         key = OpenKey(root_key, test_key_name, 0, KEY_ALL_ACCESS)
         sub_key = OpenKey(key, subkeystr, 0, KEY_ALL_ACCESS)
         # It is not necessary to delete the values before deleting
@@ -160,39 +179,179 @@
         except WindowsError: # Use this error name this time
             pass
 
-    def TestAll(self, root_key, subkeystr="sub_key"):
-        self.WriteTestData(root_key, subkeystr)
-        self.ReadTestData(root_key, subkeystr)
-        self.DeleteTestData(root_key, subkeystr)
-
-    def testLocalMachineRegistryWorks(self):
-        self.TestAll(HKEY_CURRENT_USER)
-        self.TestAll(HKEY_CURRENT_USER, "日本-subkey")
+    def _test_all(self, root_key, subkeystr="sub_key"):
+        self._write_test_data(root_key, subkeystr)
+        self._read_test_data(root_key, subkeystr)
+        self._delete_test_data(root_key, subkeystr)
+
+class LocalWinregTests(BaseWinregTests):
+
+    def test_registry_works(self):
+        self._test_all(HKEY_CURRENT_USER)
+        self._test_all(HKEY_CURRENT_USER, "日本-subkey")
+
+    def test_registry_works_extended_functions(self):
+        # Substitute the regular CreateKey and OpenKey calls with their
+        # extended counterparts.
+        # Note: DeleteKeyEx is not used here because it is platform dependent
+        cke = lambda key, sub_key: CreateKeyEx(key, sub_key, 0, KEY_ALL_ACCESS)
+        self._write_test_data(HKEY_CURRENT_USER, CreateKey=cke)
+
+        oke = lambda key, sub_key: OpenKeyEx(key, sub_key, 0, KEY_READ)
+        self._read_test_data(HKEY_CURRENT_USER, OpenKey=oke)
 
-    def testConnectRegistryToLocalMachineWorks(self):
+        self._delete_test_data(HKEY_CURRENT_USER)
+
+    def test_connect_registry_to_local_machine_works(self):
         # perform minimal ConnectRegistry test which just invokes it
         h = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
+        self.assertNotEqual(h.handle, 0)
         h.Close()
+        self.assertEqual(h.handle, 0)
 
-    def testRemoteMachineRegistryWorks(self):
-        if not self.remote_name:
-            return # remote machine name not specified
-        remote_key = ConnectRegistry(self.remote_name, HKEY_CURRENT_USER)
-        self.TestAll(remote_key)
+    def test_inexistant_remote_registry(self):
+        connect = lambda: ConnectRegistry("abcdefghijkl", HKEY_CURRENT_USER)
+        self.assertRaises(WindowsError, connect)
 
     def testExpandEnvironmentStrings(self):
         r = ExpandEnvironmentStrings("%windir%\\test")
         self.assertEqual(type(r), str)
         self.assertEqual(r, os.environ["windir"] + "\\test")
 
+    def test_context_manager(self):
+        # ensure that the handle is closed if an exception occurs
+        try:
+            with ConnectRegistry(None, HKEY_LOCAL_MACHINE) as h:
+                self.assertNotEqual(h.handle, 0)
+                raise WindowsError
+        except WindowsError:
+            self.assertEqual(h.handle, 0)
+
+    # Reflection requires XP x64/Vista at a minimum. XP doesn't have this stuff
+    # or DeleteKeyEx so make sure their use raises NotImplementedError
+    @unittest.skipUnless(WIN_VER < (5, 2), "Requires Windows XP")
+    def test_reflection_unsupported(self):
+        try:
+            with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
+                self.assertNotEqual(ck.handle, 0)
+
+            key = OpenKey(HKEY_CURRENT_USER, test_key_name)
+            self.assertNotEqual(key.handle, 0)
+
+            with self.assertRaises(NotImplementedError):
+                DisableReflectionKey(key)
+            with self.assertRaises(NotImplementedError):
+                EnableReflectionKey(key)
+            with self.assertRaises(NotImplementedError):
+                QueryReflectionKey(key)
+            with self.assertRaises(NotImplementedError):
+                DeleteKeyEx(HKEY_CURRENT_USER, test_key_name)
+        finally:
+            DeleteKey(HKEY_CURRENT_USER, test_key_name)
+
+
+ at unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests")
+class RemoteWinregTests(BaseWinregTests):
+
+    def test_remote_registry_works(self):
+        remote_key = ConnectRegistry(REMOTE_NAME, HKEY_CURRENT_USER)
+        self._test_all(remote_key)
+
+
+ at unittest.skipUnless(WIN64_MACHINE, "x64 specific registry tests")
+class Win64WinregTests(BaseWinregTests):
+
+    def test_reflection_functions(self):
+        # Test that we can call the query, enable, and disable functions
+        # on a key which isn't on the reflection list with no consequences.
+        with OpenKey(HKEY_LOCAL_MACHINE, "Software") as key:
+            # HKLM\Software is redirected but not reflected in all OSes
+            self.assertTrue(QueryReflectionKey(key))
+            self.assertEquals(None, EnableReflectionKey(key))
+            self.assertEquals(None, DisableReflectionKey(key))
+            self.assertTrue(QueryReflectionKey(key))
+
+    @unittest.skipUnless(HAS_REFLECTION, "OS doesn't support reflection")
+    def test_reflection(self):
+        # Test that we can create, open, and delete keys in the 32-bit
+        # area. Because we are doing this in a key which gets reflected,
+        # test the differences of 32 and 64-bit keys before and after the
+        # reflection occurs (ie. when the created key is closed).
+        try:
+            with CreateKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 0,
+                             KEY_ALL_ACCESS | KEY_WOW64_32KEY) as created_key:
+                self.assertNotEqual(created_key.handle, 0)
+
+                # The key should now be available in the 32-bit area
+                with OpenKey(HKEY_CURRENT_USER, test_reflect_key_name, 0,
+                             KEY_ALL_ACCESS | KEY_WOW64_32KEY) as key:
+                    self.assertNotEqual(key.handle, 0)
+
+                # Write a value to what currently is only in the 32-bit area
+                SetValueEx(created_key, "", 0, REG_SZ, "32KEY")
+
+                # The key is not reflected until created_key is closed.
+                # The 64-bit version of the key should not be available yet.
+                open_fail = lambda: OpenKey(HKEY_CURRENT_USER,
+                                            test_reflect_key_name, 0,
+                                            KEY_READ | KEY_WOW64_64KEY)
+                self.assertRaises(WindowsError, open_fail)
+
+            # Now explicitly open the 64-bit version of the key
+            with OpenKey(HKEY_CURRENT_USER, test_reflect_key_name, 0,
+                         KEY_ALL_ACCESS | KEY_WOW64_64KEY) as key:
+                self.assertNotEqual(key.handle, 0)
+                # Make sure the original value we set is there
+                self.assertEqual("32KEY", QueryValue(key, ""))
+                # Set a new value, which will get reflected to 32-bit
+                SetValueEx(key, "", 0, REG_SZ, "64KEY")
+
+            # Reflection uses a "last-writer wins policy, so the value we set
+            # on the 64-bit key should be the same on 32-bit
+            with OpenKey(HKEY_CURRENT_USER, test_reflect_key_name, 0,
+                         KEY_READ | KEY_WOW64_32KEY) as key:
+                self.assertEqual("64KEY", QueryValue(key, ""))
+        finally:
+            DeleteKeyEx(HKEY_CURRENT_USER, test_reflect_key_name,
+                        KEY_WOW64_32KEY, 0)
+
+    @unittest.skipUnless(HAS_REFLECTION, "OS doesn't support reflection")
+    def test_disable_reflection(self):
+        # Make use of a key which gets redirected and reflected
+        try:
+            with CreateKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 0,
+                             KEY_ALL_ACCESS | KEY_WOW64_32KEY) as created_key:
+                # QueryReflectionKey returns whether or not the key is disabled
+                disabled = QueryReflectionKey(created_key)
+                self.assertEqual(type(disabled), bool)
+                # HKCU\Software\Classes is reflected by default
+                self.assertFalse(disabled)
+
+                DisableReflectionKey(created_key)
+                self.assertTrue(QueryReflectionKey(created_key))
+
+            # The key is now closed and would normally be reflected to the
+            # 64-bit area, but let's make sure that didn't happen.
+            open_fail = lambda: OpenKeyEx(HKEY_CURRENT_USER,
+                                          test_reflect_key_name, 0,
+                                          KEY_READ | KEY_WOW64_64KEY)
+            self.assertRaises(WindowsError, open_fail)
+
+            # Make sure the 32-bit key is actually there
+            with OpenKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 0,
+                           KEY_READ | KEY_WOW64_32KEY) as key:
+                self.assertNotEqual(key.handle, 0)
+        finally:
+            DeleteKeyEx(HKEY_CURRENT_USER, test_reflect_key_name,
+                        KEY_WOW64_32KEY, 0)
+
+
 def test_main():
-    support.run_unittest(WinregTests)
+    support.run_unittest(LocalWinregTests, RemoteWinregTests,
+                         Win64WinregTests)
 
 if __name__ == "__main__":
-    try:
-        WinregTests.remote_name = sys.argv[sys.argv.index("--remote")+1]
-    except (IndexError, ValueError):
+    if not REMOTE_NAME:
         print("Remote registry calls can be tested using",
               "'test_winreg.py --remote \\\\machine_name'")
-        WinregTests.remote_name = None
     test_main()

Modified: python/branches/py3k-cdecimal/Lib/unittest/test/test_break.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/unittest/test/test_break.py	(original)
+++ python/branches/py3k-cdecimal/Lib/unittest/test/test_break.py	Fri Apr 23 10:13:30 2010
@@ -10,6 +10,8 @@
 
 @unittest.skipUnless(hasattr(os, 'kill'), "Test requires os.kill")
 @unittest.skipIf(sys.platform =="win32", "Test cannot run on Windows")
+ at unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 "
+    "if threads have been used")
 class TestBreak(unittest.TestCase):
 
     def setUp(self):

Modified: python/branches/py3k-cdecimal/Lib/urllib/parse.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/urllib/parse.py	(original)
+++ python/branches/py3k-cdecimal/Lib/urllib/parse.py	Fri Apr 23 10:13:30 2010
@@ -181,10 +181,9 @@
             url = url[i+1:]
             if url[:2] == '//':
                 netloc, url = _splitnetloc(url, 2)
-                if '[' in netloc :
-                    if not ']' in netloc: raise ValueError("Invalid IPv6 URL")
-                if ']' in netloc:
-                    if not '[' in netloc: raise ValueError("Invalid IPv6 URL")
+                if (('[' in netloc and ']' not in netloc) or
+                        (']' in netloc and '[' not in netloc)):
+                    raise ValueError("Invalid IPv6 URL")
             if allow_fragments and '#' in url:
                 url, fragment = url.split('#', 1)
             if '?' in url:
@@ -199,10 +198,9 @@
             scheme, url = url[:i].lower(), url[i+1:]
     if url[:2] == '//':
         netloc, url = _splitnetloc(url, 2)
-        if '[' in netloc:
-            if not ']' in netloc: raise ValueError("Invalid IPv6 URL")
-        if ']' in netloc:
-            if not '[' in netloc: raise ValueError("Invalid IPv6 URL")
+        if (('[' in netloc and ']' not in netloc) or
+                (']' in netloc and '[' not in netloc)):
+            raise ValueError("Invalid IPv6 URL")
     if allow_fragments and scheme in uses_fragment and '#' in url:
         url, fragment = url.split('#', 1)
     if scheme in uses_query and '?' in url:

Modified: python/branches/py3k-cdecimal/Mac/BuildScript/build-installer.py
==============================================================================
--- python/branches/py3k-cdecimal/Mac/BuildScript/build-installer.py	(original)
+++ python/branches/py3k-cdecimal/Mac/BuildScript/build-installer.py	Fri Apr 23 10:13:30 2010
@@ -734,7 +734,7 @@
     curDir = os.getcwd()
     os.chdir(buildDir)
     runCommand('make update')
-    runCommand('make html')
+    runCommand("make html PYTHON='%s'" % os.path.abspath(sys.executable))
     os.chdir(curDir)
     if not os.path.exists(docdir):
         os.mkdir(docdir)

Modified: python/branches/py3k-cdecimal/Misc/ACKS
==============================================================================
--- python/branches/py3k-cdecimal/Misc/ACKS	(original)
+++ python/branches/py3k-cdecimal/Misc/ACKS	Fri Apr 23 10:13:30 2010
@@ -540,6 +540,7 @@
 John Nagle
 Takahiro Nakayama
 Travers Naran
+Charles-François Natali
 Fredrik Nehr
 Trent Nelson
 Tony Nelson

Modified: python/branches/py3k-cdecimal/Misc/NEWS
==============================================================================
--- python/branches/py3k-cdecimal/Misc/NEWS	(original)
+++ python/branches/py3k-cdecimal/Misc/NEWS	Fri Apr 23 10:13:30 2010
@@ -12,6 +12,17 @@
 Core and Builtins
 -----------------
 
+- Issue #8092: Fix PyUnicode_EncodeUTF8() to support error handler producing
+  unicode string (eg. backslashreplace)
+
+- Issue #8485: PyUnicode_FSConverter() doesn't accept bytearray object anymore,
+  you have to convert your bytearray filenames to bytes
+
+- Issue #7332: Remove the 16KB stack-based buffer in
+  PyMarshal_ReadLastObjectFromFile, which doesn't bring any noticeable
+  benefit compared to the dynamic memory allocation fallback.  Patch by
+  Charles-François Natali.
+
 - Issue #8417: Raise an OverflowError when an integer larger than sys.maxsize is
   passed to bytes or bytearray.
 
@@ -318,7 +329,20 @@
 Library
 -------
 
-- Issues #8279, #8330, #8437: Fix test_gdb failures, patch written by Dave Malcolm
+- Issue #8108: Fix the unwrap() method of SSL objects when the socket has
+  a non-infinite timeout.  Also make that method friendlier with applications
+  wanting to continue using the socket in clear-text mode, by disabling
+  OpenSSL's internal readahead.  Thanks to Darryl Miles for guidance.
+
+- Issue #8496: make mailcap.lookup() always return a list, rather than an
+  iterator.  Patch by Gregory Nofi.
+
+- Issue #8195: Fix a crash in sqlite Connection.create_collation() if the
+  collation name contains a surrogate character.
+
+- Issue #8484: Load all ciphers and digest algorithms when initializing
+  the _ssl extension, such that verification of some SSL certificates
+  doesn't fail because of an "unknown algorithm".
 
 - Issue #6547: Added the ignore_dangling_symlinks option to shutil.copytree.
 
@@ -1020,6 +1044,11 @@
 - Issue #7999: os.setreuid() and os.setregid() would refuse to accept a -1
   parameter on some platforms such as OS X.
 
+- Build the ossaudio extension on GNU/kFreeBSD.
+
+- Issue #7347: winreg: Add CreateKeyEx and DeleteKeyEx, as well as fix a
+  bug in the return value of QueryReflectionKey.
+
 Build
 -----
 
@@ -1096,6 +1125,12 @@
 Tests
 -----
 
+- Issue #8108: test_ftplib's non-blocking SSL server now has proper handling
+  of SSL shutdowns.
+
+- Issues #8279, #8330, #8437, #8480: Fix test_gdb failures, patch written by
+  Dave Malcolm
+
 - Issue #3864: Skip three test_signal tests on freebsd6 because they fail
   if any thread was previously started, most likely due to a platform bug.
 

Modified: python/branches/py3k-cdecimal/Misc/maintainers.rst
==============================================================================
--- python/branches/py3k-cdecimal/Misc/maintainers.rst	(original)
+++ python/branches/py3k-cdecimal/Misc/maintainers.rst	Fri Apr 23 10:13:30 2010
@@ -88,7 +88,7 @@
 distutils           tarek
 doctest             tim_one (inactive)
 dummy_threading     brett.cannon
-email               barry
+email               barry, r.david.murray
 encodings           lemburg, loewis
 errno
 exceptions
@@ -187,7 +187,7 @@
 socketserver
 spwd
 sqlite3             ghaering
-ssl                 janssen
+ssl                 janssen, pitrou
 stat
 string
 stringprep
@@ -251,12 +251,13 @@
 AIX
 Cygwin              jlt63
 FreeBSD
+HP-UX
 Linux
 Mac                 ronaldoussoren
 NetBSD1
 OS2/EMX             aimacintyre
 Solaris
-HP-UX
+Windows
 ==================  ===========
 
 
@@ -291,5 +292,4 @@
 tracker
 unicode             lemburg, ezio.melotti, haypo
 version control
-windows
 ==================  ===========

Modified: python/branches/py3k-cdecimal/Modules/Setup.dist
==============================================================================
--- python/branches/py3k-cdecimal/Modules/Setup.dist	(original)
+++ python/branches/py3k-cdecimal/Modules/Setup.dist	Fri Apr 23 10:13:30 2010
@@ -217,6 +217,7 @@
 #termios termios.c	# Steen Lumholt's termios module
 #resource resource.c	# Jeremy Hylton's rlimit interface
 
+#_posixsubprocess _posixsubprocess.c  # POSIX subprocess module helper
 
 # Multimedia modules -- off by default.
 # These don't work for 64-bit platforms!!!

Modified: python/branches/py3k-cdecimal/Modules/_posixsubprocess.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/_posixsubprocess.c	(original)
+++ python/branches/py3k-cdecimal/Modules/_posixsubprocess.c	Fri Apr 23 10:13:30 2010
@@ -271,10 +271,7 @@
     if (cwd_obj != Py_None) {
         if (PyUnicode_FSConverter(cwd_obj, &cwd_obj2) == 0)
             goto cleanup;
-        if (PyBytes_Check(cwd_obj2))
-            cwd = PyBytes_AS_STRING(cwd_obj2);
-        else
-            cwd = PyByteArray_AS_STRING(cwd_obj2);
+        cwd = PyBytes_AsString(cwd_obj2);
     } else {
         cwd = NULL;
         cwd_obj2 = NULL;

Modified: python/branches/py3k-cdecimal/Modules/_sqlite/connection.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/_sqlite/connection.c	(original)
+++ python/branches/py3k-cdecimal/Modules/_sqlite/connection.c	Fri Apr 23 10:13:30 2010
@@ -1374,7 +1374,9 @@
     PyObject* uppercase_name = 0;
     PyObject* name;
     PyObject* retval;
-    char* chk;
+    Py_UNICODE* chk;
+    Py_ssize_t i, len;
+    char *uppercase_name_str;
     int rc;
 
     if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
@@ -1390,19 +1392,24 @@
         goto finally;
     }
 
-    chk = _PyUnicode_AsString(uppercase_name);
-    while (*chk) {
+    len = PyUnicode_GET_SIZE(uppercase_name);
+    chk = PyUnicode_AS_UNICODE(uppercase_name);
+    for (i=0; i<len; i++, chk++) {
         if ((*chk >= '0' && *chk <= '9')
          || (*chk >= 'A' && *chk <= 'Z')
          || (*chk == '_'))
         {
-            chk++;
+            continue;
         } else {
             PyErr_SetString(pysqlite_ProgrammingError, "invalid character in collation name");
             goto finally;
         }
     }
 
+    uppercase_name_str = _PyUnicode_AsString(uppercase_name);
+    if (!uppercase_name_str)
+        goto finally;
+
     if (callable != Py_None && !PyCallable_Check(callable)) {
         PyErr_SetString(PyExc_TypeError, "parameter must be callable");
         goto finally;
@@ -1417,7 +1424,7 @@
     }
 
     rc = sqlite3_create_collation(self->db,
-                                  _PyUnicode_AsString(uppercase_name),
+                                  uppercase_name_str,
                                   SQLITE_UTF8,
                                   (callable != Py_None) ? callable : NULL,
                                   (callable != Py_None) ? pysqlite_collation_callback : NULL);

Modified: python/branches/py3k-cdecimal/Modules/_ssl.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/_ssl.c	(original)
+++ python/branches/py3k-cdecimal/Modules/_ssl.c	Fri Apr 23 10:13:30 2010
@@ -9,6 +9,9 @@
    directly.
 
    XXX should partial writes be enabled, SSL_MODE_ENABLE_PARTIAL_WRITE?
+
+   XXX integrate several "shutdown modes" as suggested in
+       http://bugs.python.org/issue8108#msg102867 ?
 */
 
 #include "Python.h"
@@ -116,6 +119,7 @@
 	SSL_CTX*	ctx;
 	SSL*		ssl;
 	X509*		peer_cert;
+	int		shutdown_seen_zero;
 
 } PySSLObject;
 
@@ -1392,7 +1396,8 @@
 
 static PyObject *PySSL_SSLshutdown(PySSLObject *self)
 {
-	int err;
+	int err, ssl_err, sockstate, nonblocking;
+	int zeros = 0;
         PySocketSockObject *sock
           = (PySocketSockObject *) PyWeakref_GetObject(self->Socket);
 
@@ -1403,13 +1408,65 @@
                 return NULL;
         }
 
-	PySSL_BEGIN_ALLOW_THREADS
-	err = SSL_shutdown(self->ssl);
-	if (err == 0) {
-		/* we need to call it again to finish the shutdown */
+        /* Just in case the blocking state of the socket has been changed */
+	nonblocking = (sock->sock_timeout >= 0.0);
+	BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
+	BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking);
+
+	while (1) {
+		PySSL_BEGIN_ALLOW_THREADS
+		/* Disable read-ahead so that unwrap can work correctly.
+		 * Otherwise OpenSSL might read in too much data,
+		 * eating clear text data that happens to be
+		 * transmitted after the SSL shutdown.
+		 * Should be safe to call repeatedly everytime this
+		 * function is used and the shutdown_seen_zero != 0
+		 * condition is met.
+		 */
+		if (self->shutdown_seen_zero)
+			SSL_set_read_ahead(self->ssl, 0);
 		err = SSL_shutdown(self->ssl);
+		PySSL_END_ALLOW_THREADS
+		/* If err == 1, a secure shutdown with SSL_shutdown() is complete */
+		if (err > 0)
+			break;
+		if (err == 0) {
+			/* Don't loop endlessly; instead preserve legacy
+			   behaviour of trying SSL_shutdown() only twice.
+			   This looks necessary for OpenSSL < 0.9.8m */
+			if (++zeros > 1)
+				break;
+			/* Shutdown was sent, now try receiving */
+			self->shutdown_seen_zero = 1;
+			continue;
+		}
+
+		/* Possibly retry shutdown until timeout or failure */
+		ssl_err = SSL_get_error(self->ssl, err);
+		if (ssl_err == SSL_ERROR_WANT_READ)
+			sockstate = check_socket_and_wait_for_timeout(sock, 0);
+		else if (ssl_err == SSL_ERROR_WANT_WRITE)
+			sockstate = check_socket_and_wait_for_timeout(sock, 1);
+		else
+			break;
+		if (sockstate == SOCKET_HAS_TIMED_OUT) {
+			if (ssl_err == SSL_ERROR_WANT_READ)
+				PyErr_SetString(PySSLErrorObject,
+		                                "The read operation timed out");
+			else
+				PyErr_SetString(PySSLErrorObject,
+		                                "The write operation timed out");
+			return NULL;
+		}
+		else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
+			PyErr_SetString(PySSLErrorObject,
+	                                "Underlying socket too large for select().");
+			return NULL;
+		}
+		else if (sockstate != SOCKET_OPERATION_OK)
+			/* Retain the SSL error code */
+			break;
 	}
-	PySSL_END_ALLOW_THREADS
 
 	if (err < 0)
 		return PySSL_SetError(self, err, __FILE__, __LINE__);
@@ -1669,13 +1726,14 @@
 
 	/* Init OpenSSL */
 	SSL_load_error_strings();
+	SSL_library_init();
 #ifdef WITH_THREAD
 	/* note that this will start threading if not already started */
 	if (!_setup_ssl_threads()) {
 		return NULL;
 	}
 #endif
-	SSLeay_add_ssl_algorithms();
+	OpenSSL_add_all_algorithms();
 
 	/* Add symbols to module dict */
 	PySSLErrorObject = PyErr_NewException("ssl.SSLError",

Modified: python/branches/py3k-cdecimal/Modules/posixmodule.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/posixmodule.c	(original)
+++ python/branches/py3k-cdecimal/Modules/posixmodule.c	Fri Apr 23 10:13:30 2010
@@ -536,38 +536,6 @@
 	return d;
 }
 
-/* Convert a bytes object to a char*. Optionally lock the buffer if it is a
-   bytes array. */
-
-static char*
-bytes2str(PyObject* o, int lock)
-{
-	if(PyBytes_Check(o))
-		return PyBytes_AsString(o);
-	else if(PyByteArray_Check(o)) {
-		if (lock && PyObject_GetBuffer(o, NULL, 0) < 0)
-			/* On a bytearray, this should not fail. */
-			PyErr_BadInternalCall();
-		return PyByteArray_AsString(o);
-	} else {
-		/* The FS converter should have verified that this
-		   is either bytes or bytearray. */
-		Py_FatalError("bad object passed to bytes2str");
-		/* not reached. */
-		return "";
-	}
-}
-
-/* Release the lock, decref the object. */
-static void
-release_bytes(PyObject* o)
-{
-	if (PyByteArray_Check(o))
-		o->ob_type->tp_as_buffer->bf_releasebuffer(o, 0);
-	Py_DECREF(o);
-}
-
-
 /* Set a POSIX-specific error from errno, and return NULL */
 
 static PyObject *
@@ -594,8 +562,8 @@
 posix_error_with_allocated_filename(PyObject* name)
 {
 	PyObject *rc = PyErr_SetFromErrnoWithFilename(PyExc_OSError, 
-						      bytes2str(name, 0));
-	release_bytes(name);
+						      PyBytes_AsString(name));
+	Py_DECREF(name);
 	return rc;
 }
 
@@ -751,13 +719,13 @@
 	if (!PyArg_ParseTuple(args, format,
 	                      PyUnicode_FSConverter, &opath1))
 		return NULL;
-	path1 = bytes2str(opath1, 1);
+	path1 = PyBytes_AsString(opath1);
 	Py_BEGIN_ALLOW_THREADS
 	res = (*func)(path1);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath1);
-	release_bytes(opath1);
+	Py_DECREF(opath1);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -775,13 +743,13 @@
 	                      PyUnicode_FSConverter, &opath2)) {
 		return NULL;
 	}
-	path1 = bytes2str(opath1, 1);
-	path2 = bytes2str(opath2, 1);
+	path1 = PyBytes_AsString(opath1);
+	path2 = PyBytes_AsString(opath2);
 	Py_BEGIN_ALLOW_THREADS
 	res = (*func)(path1, path2);
 	Py_END_ALLOW_THREADS
-	release_bytes(opath1);
-	release_bytes(opath2);
+	Py_DECREF(opath1);
+	Py_DECREF(opath2);
 	if (res != 0)
 		/* XXX how to report both path1 and path2??? */
 		return posix_error();
@@ -1530,7 +1498,7 @@
 	if (!PyArg_ParseTuple(args, format,
 	                      PyUnicode_FSConverter, &opath))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = (*statfunc)(path, &st);
 	Py_END_ALLOW_THREADS
@@ -1545,7 +1513,7 @@
 	else
 		result = _pystat_fromstructstat(&st);
 
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return result;
 }
 
@@ -1583,11 +1551,11 @@
 	if (!PyArg_ParseTuple(args, "O&i:access",
 			      PyUnicode_FSConverter, &opath, &mode))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	attr = GetFileAttributesA(path);
 	Py_END_ALLOW_THREADS
-	release_bytes(opath);
+	Py_DECREF(opath);
 finish:
 	if (attr == 0xFFFFFFFF)
 		/* File does not exist, or cannot read attributes */
@@ -1603,11 +1571,11 @@
 	if (!PyArg_ParseTuple(args, "O&i:access", 
 			      PyUnicode_FSConverter, &opath, &mode))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = access(path, mode);
 	Py_END_ALLOW_THREADS
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return PyBool_FromLong(res == 0);
 #endif
 }
@@ -1750,7 +1718,7 @@
 	if (!PyArg_ParseTuple(args, "O&i:chmod", PyUnicode_FSConverter,
 	                      &opath, &i))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	attr = GetFileAttributesA(path);
 	if (attr != 0xFFFFFFFF) {
@@ -1765,23 +1733,23 @@
 	Py_END_ALLOW_THREADS
 	if (!res) {
 		win32_error("chmod", path);
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 #else /* MS_WINDOWS */
 	if (!PyArg_ParseTuple(args, "O&i:chmod", PyUnicode_FSConverter,
 	                      &opath, &i))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = chmod(path, i);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 #endif
@@ -1824,13 +1792,13 @@
 	if (!PyArg_ParseTuple(args, "O&i:lchmod", PyUnicode_FSConverter,
 	                      &opath, &i))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = lchmod(path, i);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_RETURN_NONE;
 }
 #endif /* HAVE_LCHMOD */
@@ -1851,13 +1819,13 @@
 	if (!PyArg_ParseTuple(args, "O&k:chflags",
 			      PyUnicode_FSConverter, &opath, &flags))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = chflags(path, flags);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -1879,13 +1847,13 @@
 	if (!PyArg_ParseTuple(args, "O&k:lchflags",
 			      PyUnicode_FSConverter, &opath, &flags))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = lchflags(path, flags);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -1950,13 +1918,13 @@
 	                      PyUnicode_FSConverter, &opath,
 	                      &uid, &gid))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = chown(path, (uid_t) uid, (gid_t) gid);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -2002,13 +1970,13 @@
 	                      PyUnicode_FSConverter, &opath,
 	                      &uid, &gid))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = lchown(path, (uid_t) uid, (gid_t) gid);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -2209,12 +2177,12 @@
 	if (!PyArg_ParseTuple(args, "O&:listdir",
 	                      PyUnicode_FSConverter, &opath))
 		return NULL;
-	if (PyObject_Size(opath)+1 > MAX_PATH) {
+	if (PyBytes_GET_SIZE(opath)+1 > MAX_PATH) {
 		PyErr_SetString(PyExc_ValueError, "path too long");
 		Py_DECREF(opath);
 		return NULL;
 	}
-	strcpy(namebuf, bytes2str(opath, 0));
+	strcpy(namebuf, PyBytes_AsString(opath));
 	len = PyObject_Size(opath);
 	if (len > 0) {
 		char ch = namebuf[len-1];
@@ -2290,10 +2258,10 @@
     if (!PyArg_ParseTuple(args, "O&:listdir", 
                           PyUnicode_FSConverter, &oname))
         return NULL;
-    name = bytes2str(oname);
-    len = PyObject_Size(oname);
+    name = PyBytes_AsString(oname);
+    len = PyBytes_GET_SIZE(oname);
     if (len >= MAX_PATH) {
-        release_bytes(oname);
+        Py_DECREF(oname);
         PyErr_SetString(PyExc_ValueError, "path too long");
         return NULL;
     }
@@ -2306,7 +2274,7 @@
     strcpy(namebuf + len, "*.*");
 
     if ((d = PyList_New(0)) == NULL) {
-        release_bytes(oname);
+        Py_DECREF(oname);
         return NULL;
     }
 
@@ -2349,7 +2317,7 @@
         } while (DosFindNext(hdir, &ep, sizeof(ep), &srchcnt) == NO_ERROR && srchcnt > 0);
     }
 
-    release_bytes(oname);
+    Py_DECREF(oname);
     return d;
 #else
 	PyObject *oname;
@@ -2366,13 +2334,13 @@
 	}
 	if (!PyArg_ParseTuple(args, "O&:listdir", PyUnicode_FSConverter, &oname))
 		return NULL;
-	name = bytes2str(oname, 1);
+	name = PyBytes_AsString(oname);
 	if ((dirp = opendir(name)) == NULL) {
 		return posix_error_with_allocated_filename(oname);
 	}
 	if ((d = PyList_New(0)) == NULL) {
 		closedir(dirp);
-		release_bytes(oname);
+		Py_DECREF(oname);
 		return NULL;
 	}
 	for (;;) {
@@ -2425,7 +2393,7 @@
 		Py_DECREF(v);
 	}
 	closedir(dirp);
-	release_bytes(oname);
+	Py_DECREF(oname);
 
 	return d;
 
@@ -2474,14 +2442,14 @@
 	if (!PyArg_ParseTuple (args, "O&:_getfullpathname",
 	                       PyUnicode_FSConverter, &opath))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (!GetFullPathName(path, sizeof(outbuf)/sizeof(outbuf[0]),
 	                     outbuf, &temp)) {
 		win32_error("GetFullPathName", path);
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
-	release_bytes(opath);
+	Py_DECREF(opath);
 	if (PyUnicode_Check(PyTuple_GetItem(args, 0))) {
 		return PyUnicode_Decode(outbuf, strlen(outbuf),
 			Py_FileSystemDefaultEncoding, NULL);
@@ -2521,7 +2489,7 @@
 	if (!PyArg_ParseTuple(args, "O&|i:mkdir",
 	                      PyUnicode_FSConverter, &opath, &mode))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	/* PyUnicode_AS_UNICODE OK without thread lock as
 	   it is a simple dereference. */
@@ -2529,10 +2497,10 @@
 	Py_END_ALLOW_THREADS
 	if (!res) {
 		win32_error("mkdir", path);
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 #else
@@ -2540,7 +2508,7 @@
 	if (!PyArg_ParseTuple(args, "O&|i:mkdir",
 	                      PyUnicode_FSConverter, &opath, &mode))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 #if ( defined(__WATCOMC__) || defined(PYCC_VACPP) ) && !defined(__QNX__)
 	res = mkdir(path);
@@ -2550,7 +2518,7 @@
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 #endif
@@ -2699,11 +2667,11 @@
 	                      PyUnicode_FSConverter, &command_obj))
 		return NULL;
 
-	command = bytes2str(command_obj, 1);
+	command = PyBytes_AsString(command_obj);
 	Py_BEGIN_ALLOW_THREADS
 	sts = system(command);
 	Py_END_ALLOW_THREADS
-	release_bytes(command_obj);
+	Py_DECREF(command_obj);
 #endif
 	return PyLong_FromLong(sts);
 }
@@ -2838,7 +2806,7 @@
 		if (!PyArg_ParseTuple(args, "O&O:utime",
 				PyUnicode_FSConverter, &oapath, &arg))
 			return NULL;
-		apath = bytes2str(oapath, 1);
+		apath = PyBytes_AsString(oapath);
 		Py_BEGIN_ALLOW_THREADS
 		hFile = CreateFileA(apath, FILE_WRITE_ATTRIBUTES, 0,
 				    NULL, OPEN_EXISTING,
@@ -2846,10 +2814,10 @@
 		Py_END_ALLOW_THREADS
 		if (hFile == INVALID_HANDLE_VALUE) {
 			win32_error("utime", apath);
-			release_bytes(oapath);
+			Py_DECREF(oapath);
 			return NULL;
 		}
-		release_bytes(oapath);
+		Py_DECREF(oapath);
 	}
 	
 	if (arg == Py_None) {
@@ -2917,7 +2885,7 @@
 	if (!PyArg_ParseTuple(args, "O&O:utime",
 				  PyUnicode_FSConverter, &opath, &arg))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (arg == Py_None) {
 		/* optional time values not given */
 		Py_BEGIN_ALLOW_THREADS
@@ -2927,18 +2895,18 @@
 	else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) {
 		PyErr_SetString(PyExc_TypeError,
 				"utime() arg 2 must be a tuple (atime, mtime)");
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
 	else {
 		if (extract_time(PyTuple_GET_ITEM(arg, 0),
 				 &atime, &ausec) == -1) {
-			release_bytes(opath);
+			Py_DECREF(opath);
 			return NULL;
 		}
 		if (extract_time(PyTuple_GET_ITEM(arg, 1),
 				 &mtime, &musec) == -1) {
-			release_bytes(opath);
+			Py_DECREF(opath);
 			return NULL;
 		}
 		ATIME = atime;
@@ -2958,7 +2926,7 @@
 	if (res < 0) {
 		return posix_error_with_allocated_filename(opath);
 	}
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 #undef UTIME_ARG
@@ -3001,12 +2969,11 @@
 	Py_ssize_t size;
 	if (!PyUnicode_FSConverter(o, &bytes))
 		return 0;
-	size = PyObject_Size(bytes);
+	size = PyBytes_GET_SIZE(bytes);
 	*out = PyMem_Malloc(size+1);
 	if (!*out)
 		return 0;
-	/* Don't lock bytes, as we hold the GIL */
-	memcpy(*out, bytes2str(bytes, 0), size+1);
+	memcpy(*out, PyBytes_AsString(bytes), size+1);
 	Py_DECREF(bytes);
 	return 1;
 }
@@ -3038,7 +3005,7 @@
                               PyUnicode_FSConverter,
                               &opath, &argv))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3049,18 +3016,18 @@
 	}
 	else {
 		PyErr_SetString(PyExc_TypeError, "execv() arg 2 must be a tuple or list");
-                release_bytes(opath);
+                Py_DECREF(opath);
 		return NULL;
 	}
 	if (argc < 1) {
 		PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty");
-                release_bytes(opath);
+                Py_DECREF(opath);
 		return NULL;
 	}
 
 	argvlist = PyMem_NEW(char *, argc+1);
 	if (argvlist == NULL) {
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return PyErr_NoMemory();
 	}
 	for (i = 0; i < argc; i++) {
@@ -3069,7 +3036,7 @@
 			free_string_array(argvlist, i);
 			PyErr_SetString(PyExc_TypeError,
 					"execv() arg 2 must contain only strings");
-			release_bytes(opath);
+			Py_DECREF(opath);
 			return NULL;
 
 		}
@@ -3081,7 +3048,7 @@
 	/* If we get here it's definitely an error */
 
 	free_string_array(argvlist, argc);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return posix_error();
 }
 
@@ -3115,7 +3082,7 @@
 			      PyUnicode_FSConverter,
 			      &opath, &argv, &env))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3224,7 +3191,7 @@
 	Py_XDECREF(vals);
 	Py_XDECREF(keys);
   fail_0:
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return NULL;
 }
 #endif /* HAVE_EXECV */
@@ -3258,7 +3225,7 @@
 			      PyUnicode_FSConverter,
 			      &opath, &argv))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3270,13 +3237,13 @@
 	else {
 		PyErr_SetString(PyExc_TypeError,
 				"spawnv() arg 2 must be a tuple or list");
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
 
 	argvlist = PyMem_NEW(char *, argc+1);
 	if (argvlist == NULL) {
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return PyErr_NoMemory();
 	}
 	for (i = 0; i < argc; i++) {
@@ -3286,7 +3253,7 @@
 			PyErr_SetString(
 				PyExc_TypeError,
 				"spawnv() arg 2 must contain only strings");
-			release_bytes(opath);
+			Py_DECREF(opath);
 			return NULL;
 		}
 	}
@@ -3306,7 +3273,7 @@
 #endif
 
 	free_string_array(argvlist, argc);
-	release_bytes(opath);
+	Py_DECREF(opath);
 
 	if (spawnval == -1)
 		return posix_error();
@@ -3351,7 +3318,7 @@
 			      PyUnicode_FSConverter,
 			      &opath, &argv, &env))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3468,7 +3435,7 @@
 	Py_XDECREF(vals);
 	Py_XDECREF(keys);
   fail_0:
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return res;
 }
 
@@ -3501,7 +3468,7 @@
 			      PyUnicode_FSConverter,
 			      &opath, &argv))
 		return NULL;
-	path = bytes2str(opath);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3513,13 +3480,13 @@
 	else {
 		PyErr_SetString(PyExc_TypeError,
 				"spawnvp() arg 2 must be a tuple or list");
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
 
 	argvlist = PyMem_NEW(char *, argc+1);
 	if (argvlist == NULL) {
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return PyErr_NoMemory();
 	}
 	for (i = 0; i < argc; i++) {
@@ -3529,7 +3496,7 @@
 			PyErr_SetString(
 				PyExc_TypeError,
 				"spawnvp() arg 2 must contain only strings");
-			release_bytes(opath);
+			Py_DECREF(opath);
 			return NULL;
 		}
 	}
@@ -3544,7 +3511,7 @@
 	Py_END_ALLOW_THREADS
 
 	free_string_array(argvlist, argc);
-	release_bytes(opath);
+	Py_DECREF(opath);
 
 	if (spawnval == -1)
 		return posix_error();
@@ -3585,7 +3552,7 @@
 			      PyUnicode_FSConverter,
 			      &opath, &argv, &env))
 		return NULL;
-	path = bytes2str(opath);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3693,7 +3660,7 @@
 	Py_XDECREF(vals);
 	Py_XDECREF(keys);
   fail_0:
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return res;
 }
 #endif /* PYOS_OS2 */
@@ -4692,10 +4659,10 @@
 	if (!PyArg_ParseTuple(args, "O&:readlink", 
 				PyUnicode_FSConverter, &opath))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	v = PySequence_GetItem(args, 0);
 	if (v == NULL) {
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
 
@@ -4710,7 +4677,7 @@
 	if (n < 0)
 		return posix_error_with_allocated_filename(opath);
 
-	release_bytes(opath);
+	Py_DECREF(opath);
 	v = PyBytes_FromStringAndSize(buf, n);
 	if (arg_is_unicode) {
 		PyObject *w;
@@ -4955,13 +4922,13 @@
 	                      PyUnicode_FSConverter, &ofile,
 	                      &flag, &mode))
 		return NULL;
-	file = bytes2str(ofile, 1);
+	file = PyBytes_AsString(ofile);
 	Py_BEGIN_ALLOW_THREADS
 	fd = open(file, flag, mode);
 	Py_END_ALLOW_THREADS
 	if (fd < 0)
 		return posix_error_with_allocated_filename(ofile);
-	release_bytes(ofile);
+	Py_DECREF(ofile);
 	return PyLong_FromLong((long)fd);
 }
 
@@ -5423,8 +5390,8 @@
 			      PyUnicode_FSConverter, &os1, 
 			      PyUnicode_FSConverter, &os2))
 		return NULL;
-	s1 = bytes2str(os1, 1);
-	s2 = bytes2str(os2, 1);
+	s1 = PyBytes_AsString(os1);
+	s2 = PyBytes_AsString(os2);
 #endif
 
 #if defined(PYOS_OS2)
@@ -5468,8 +5435,8 @@
 	PyOS_snprintf(newenv, len, "%s=%s", s1, s2);
 	if (putenv(newenv)) {
                 Py_DECREF(newstr);
-		release_bytes(os1);
-		release_bytes(os2);
+		Py_DECREF(os1);
+		Py_DECREF(os2);
                 posix_error();
                 return NULL;
 	}
@@ -5491,8 +5458,8 @@
     }
 #endif
 #ifndef MS_WINDOWS
-	release_bytes(os1);
-	release_bytes(os2);
+	Py_DECREF(os1);
+	Py_DECREF(os2);
 #endif
 	Py_INCREF(Py_None);
         return Py_None;
@@ -6865,17 +6832,17 @@
 			      PyUnicode_FSConverter, &ofilepath, 
 			      &operation))
 		return NULL;
-	filepath = bytes2str(ofilepath, 1);
+	filepath = PyBytes_AsString(ofilepath);
 	Py_BEGIN_ALLOW_THREADS
 	rc = ShellExecute((HWND)0, operation, filepath, 
 			  NULL, NULL, SW_SHOWNORMAL);
 	Py_END_ALLOW_THREADS
 	if (rc <= (HINSTANCE)32) {
 		PyObject *errval = win32_error("startfile", filepath);
-		release_bytes(ofilepath);
+		Py_DECREF(ofilepath);
 		return errval;
 	}
-	release_bytes(ofilepath);
+	Py_DECREF(ofilepath);
 	Py_INCREF(Py_None);
 	return Py_None;
 }

Modified: python/branches/py3k-cdecimal/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-cdecimal/Objects/unicodeobject.c	(original)
+++ python/branches/py3k-cdecimal/Objects/unicodeobject.c	Fri Apr 23 10:13:30 2010
@@ -159,6 +159,12 @@
        const Py_UNICODE *unicode, Py_ssize_t size, PyObject **exceptionObject,
        Py_ssize_t startpos, Py_ssize_t endpos, Py_ssize_t *newpos);
 
+static void raise_encode_exception(PyObject **exceptionObject,
+                                   const char *encoding,
+                                   const Py_UNICODE *unicode, Py_ssize_t size,
+                                   Py_ssize_t startpos, Py_ssize_t endpos,
+                                   const char *reason);
+
 /* Same for linebreaks */
 static unsigned char ascii_linebreak[] = {
     0, 0, 0, 0, 0, 0, 0, 0,
@@ -1624,7 +1630,7 @@
         Py_DECREF(*(PyObject**)addr);
         return 1;
     }
-    if (PyBytes_Check(arg) || PyByteArray_Check(arg)) {
+    if (PyBytes_Check(arg)) {
         output = arg;
         Py_INCREF(output);
     }
@@ -2542,61 +2548,89 @@
             /* Encode Latin-1 */
             *p++ = (char)(0xc0 | (ch >> 6));
             *p++ = (char)(0x80 | (ch & 0x3f));
-        }
-        else {
-            /* Encode UCS2 Unicode ordinals */
-            if (ch < 0x10000) {
+        } else if (0xD800 <= ch && ch <= 0xDFFF) {
 #ifndef Py_UNICODE_WIDE
-                /* Special case: check for high surrogate */
-                if (0xD800 <= ch && ch <= 0xDBFF && i != size) {
-                    Py_UCS4 ch2 = s[i];
-                    /* Check for low surrogate and combine the two to
-                       form a UCS4 value */
-                    if (0xDC00 <= ch2 && ch2 <= 0xDFFF) {
-                        ch = ((ch - 0xD800) << 10 | (ch2 - 0xDC00)) + 0x10000;
-                        i++;
-                        goto encodeUCS4;
-                    }
-                    /* Fall through: handles isolated high surrogates */
-                }
+            /* Special case: check for high and low surrogate */
+            if (ch <= 0xDBFF && i != size && 0xDC00 <= s[i] && s[i] <= 0xDFFF) {
+                Py_UCS4 ch2 = s[i];
+                /* Combine the two surrogates to form a UCS4 value */
+                ch = ((ch - 0xD800) << 10 | (ch2 - 0xDC00)) + 0x10000;
+                i++;
+
+                /* Encode UCS4 Unicode ordinals */
+                *p++ = (char)(0xf0 | (ch >> 18));
+                *p++ = (char)(0x80 | ((ch >> 12) & 0x3f));
+                *p++ = (char)(0x80 | ((ch >> 6) & 0x3f));
+                *p++ = (char)(0x80 | (ch & 0x3f));
+            } else {
 #endif
-                if (ch >= 0xd800 && ch <= 0xdfff) {
-                    Py_ssize_t newpos;
-                    PyObject *rep;
-                    char *prep;
-                    int k;
-                    rep = unicode_encode_call_errorhandler
-                        (errors, &errorHandler, "utf-8", "surrogates not allowed", 
-                         s, size, &exc, i-1, i, &newpos);
-                    if (!rep)
-                        goto error;
-                    /* Implementation limitations: only support error handler that return
-                       bytes, and only support up to four replacement bytes. */
-                    if (!PyBytes_Check(rep)) {
-                        PyErr_SetString(PyExc_TypeError, "error handler should have returned bytes");
-                        Py_DECREF(rep);
+                Py_ssize_t newpos;
+                PyObject *rep;
+                Py_ssize_t repsize, k;
+                rep = unicode_encode_call_errorhandler
+                    (errors, &errorHandler, "utf-8", "surrogates not allowed",
+                     s, size, &exc, i-1, i, &newpos);
+                if (!rep)
+                    goto error;
+
+                if (PyBytes_Check(rep))
+                    repsize = PyBytes_GET_SIZE(rep);
+                else
+                    repsize = PyUnicode_GET_SIZE(rep);
+
+                if (repsize > 4) {
+                    Py_ssize_t offset;
+
+                    if (result == NULL)
+                        offset = p - stackbuf;
+                    else
+                        offset = p - PyBytes_AS_STRING(result);
+
+                    if (nallocated > PY_SSIZE_T_MAX - repsize + 4) {
+                        /* integer overflow */
+                        PyErr_NoMemory();
                         goto error;
                     }
-                    if (PyBytes_Size(rep) > 4) {
-                        PyErr_SetString(PyExc_TypeError, "error handler returned too many bytes");
-                        Py_DECREF(rep);
-                        goto error;
+                    nallocated += repsize - 4;
+                    if (result != NULL) {
+                        if (_PyBytes_Resize(&result, nallocated) < 0)
+                            goto error;
+                    } else {
+                        result = PyBytes_FromStringAndSize(NULL, nallocated);
+                        if (result == NULL)
+                            goto error;
+                        Py_MEMCPY(PyBytes_AS_STRING(result), stackbuf, offset);
                     }
-                    prep = PyBytes_AsString(rep);
-                    for(k = PyBytes_Size(rep); k > 0; k--)
+                    p = PyBytes_AS_STRING(result) + offset;
+                }
+
+                if (PyBytes_Check(rep)) {
+                    char *prep = PyBytes_AS_STRING(rep);
+                    for(k = repsize; k > 0; k--)
                         *p++ = *prep++;
-                    Py_DECREF(rep);
-                    continue;
-                    
+                } else /* rep is unicode */ {
+                    Py_UNICODE *prep = PyUnicode_AS_UNICODE(rep);
+                    Py_UNICODE c;
+
+                    for(k=0; k<repsize; k++) {
+                        c = prep[k];
+                        if (0x80 <= c) {
+                            raise_encode_exception(&exc, "utf-8", s, size,
+                                                   i-1, i, "surrogates not allowed");
+                            goto error;
+                        }
+                        *p++ = (char)prep[k];
+                    }
                 }
-                *p++ = (char)(0xe0 | (ch >> 12));
-                *p++ = (char)(0x80 | ((ch >> 6) & 0x3f));
-                *p++ = (char)(0x80 | (ch & 0x3f));
-                continue;
-            }
+                Py_DECREF(rep);
 #ifndef Py_UNICODE_WIDE
-          encodeUCS4:
+            }
 #endif
+        } else if (ch < 0x10000) {
+            *p++ = (char)(0xe0 | (ch >> 12));
+            *p++ = (char)(0x80 | ((ch >> 6) & 0x3f));
+            *p++ = (char)(0x80 | (ch & 0x3f));
+        } else /* ch >= 0x10000 */ {
             /* Encode UCS4 Unicode ordinals */
             *p++ = (char)(0xf0 | (ch >> 18));
             *p++ = (char)(0x80 | ((ch >> 12) & 0x3f));

Modified: python/branches/py3k-cdecimal/PC/winreg.c
==============================================================================
--- python/branches/py3k-cdecimal/PC/winreg.c	(original)
+++ python/branches/py3k-cdecimal/PC/winreg.c	Fri Apr 23 10:13:30 2010
@@ -88,7 +88,7 @@
 "key is the predefined handle to connect to.\n"
 "\n"
 "The return value is the handle of the opened key.\n"
-"If the function fails, an EnvironmentError exception is raised.");
+"If the function fails, a WindowsError exception is raised.");
 
 PyDoc_STRVAR(CreateKey_doc,
 "key = CreateKey(key, sub_key) - Creates or opens the specified key.\n"
@@ -103,6 +103,21 @@
 "The return value is the handle of the opened key.\n"
 "If the function fails, an exception is raised.");
 
+PyDoc_STRVAR(CreateKeyEx_doc,
+"key = CreateKeyEx(key, sub_key, res, sam) - Creates or opens the specified key.\n"
+"\n"
+"key is an already open key, or one of the predefined HKEY_* constants\n"
+"sub_key is a string that names the key this method opens or creates.\n"
+"res is a reserved integer, and must be zero.  Default is zero.\n"
+"sam is an integer that specifies an access mask that describes the desired\n"
+" If key is one of the predefined keys, sub_key may be None. In that case,\n"
+" the handle returned is the same key handle passed in to the function.\n"
+"\n"
+"If the key already exists, this function opens the existing key\n"
+"\n"
+"The return value is the handle of the opened key.\n"
+"If the function fails, an exception is raised.");
+
 PyDoc_STRVAR(DeleteKey_doc,
 "DeleteKey(key, sub_key) - Deletes the specified key.\n"
 "\n"
@@ -113,7 +128,22 @@
 "This method can not delete keys with subkeys.\n"
 "\n"
 "If the method succeeds, the entire key, including all of its values,\n"
-"is removed.  If the method fails, an EnvironmentError exception is raised.");
+"is removed.  If the method fails, a WindowsError exception is raised.");
+
+PyDoc_STRVAR(DeleteKeyEx_doc,
+"DeleteKeyEx(key, sub_key, sam, res) - Deletes the specified key.\n"
+"\n"
+"key is an already open key, or any one of the predefined HKEY_* constants.\n"
+"sub_key is a string that must be a subkey of the key identified by the key parameter.\n"
+"res is a reserved integer, and must be zero.  Default is zero.\n"
+"sam is an integer that specifies an access mask that describes the desired\n"
+" This value must not be None, and the key may not have subkeys.\n"
+"\n"
+"This method can not delete keys with subkeys.\n"
+"\n"
+"If the method succeeds, the entire key, including all of its values,\n"
+"is removed.  If the method fails, a WindowsError exception is raised.\n"
+"On unsupported Windows versions, NotImplementedError is raised.");
 
 PyDoc_STRVAR(DeleteValue_doc,
 "DeleteValue(key, value) - Removes a named value from a registry key.\n"
@@ -128,7 +158,7 @@
 "index is an integer that identifies the index of the key to retrieve.\n"
 "\n"
 "The function retrieves the name of one subkey each time it is called.\n"
-"It is typically called repeatedly until an EnvironmentError exception is\n"
+"It is typically called repeatedly until a WindowsError exception is\n"
 "raised, indicating no more values are available.");
 
 PyDoc_STRVAR(EnumValue_doc,
@@ -137,7 +167,7 @@
 "index is an integer that identifies the index of the value to retrieve.\n"
 "\n"
 "The function retrieves the name of one subkey each time it is called.\n"
-"It is typically called repeatedly, until an EnvironmentError exception\n"
+"It is typically called repeatedly, until a WindowsError exception\n"
 "is raised, indicating no more values.\n"
 "\n"
 "The result is a tuple of 3 items:\n"
@@ -191,7 +221,7 @@
 " security access for the key.  Default is KEY_READ\n"
 "\n"
 "The result is a new handle to the specified key\n"
-"If the function fails, an EnvironmentError exception is raised.");
+"If the function fails, a WindowsError exception is raised.");
 
 PyDoc_STRVAR(OpenKeyEx_doc, "See OpenKey()");
 
@@ -957,6 +987,29 @@
 }
 
 static PyObject *
+PyCreateKeyEx(PyObject *self, PyObject *args)
+{
+	HKEY hKey;
+	PyObject *obKey;
+	wchar_t *subKey;
+	HKEY retKey;
+	int res = 0;
+	REGSAM sam = KEY_WRITE;
+	long rc;
+	if (!PyArg_ParseTuple(args, "OZ|ii:CreateKeyEx", &obKey, &subKey,
+						  &res, &sam))
+		return NULL;
+	if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
+		return NULL;
+
+	rc = RegCreateKeyExW(hKey, subKey, res, NULL, (DWORD)NULL, 
+						sam, NULL, &retKey, NULL);
+	if (rc != ERROR_SUCCESS)
+		return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx");
+	return PyHKEY_FromHKEY(retKey);
+}
+
+static PyObject *
 PyDeleteKey(PyObject *self, PyObject *args)
 {
 	HKEY hKey;
@@ -975,6 +1028,46 @@
 }
 
 static PyObject *
+PyDeleteKeyEx(PyObject *self, PyObject *args)
+{
+	HKEY hKey;
+	PyObject *obKey;
+	HMODULE hMod;
+	typedef LONG (WINAPI *RDKEFunc)(HKEY, const wchar_t*, REGSAM, int);
+	RDKEFunc pfn = NULL;
+	wchar_t *subKey;
+	long rc;
+	int res = 0;
+	REGSAM sam = KEY_WOW64_64KEY;
+
+	if (!PyArg_ParseTuple(args, "Ou|ii:DeleteKeyEx",
+						  &obKey, &subKey, &sam, &res))
+		return NULL;
+	if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
+		return NULL;
+
+	/* Only available on 64bit platforms, so we must load it
+	   dynamically. */
+	hMod = GetModuleHandle("advapi32.dll");
+	if (hMod)
+		pfn = (RDKEFunc)GetProcAddress(hMod,
+									   "RegDeleteKeyExW");
+	if (!pfn) {
+		PyErr_SetString(PyExc_NotImplementedError,
+						"not implemented on this platform");
+		return NULL;
+	}
+	Py_BEGIN_ALLOW_THREADS
+	rc = (*pfn)(hKey, subKey, sam, res);
+	Py_END_ALLOW_THREADS
+
+	if (rc != ERROR_SUCCESS)
+		return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKeyEx");
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+static PyObject *
 PyDeleteValue(PyObject *self, PyObject *args)
 {
 	HKEY hKey;
@@ -1412,8 +1505,8 @@
 	if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
 		return NULL;
 
-	// Only available on 64bit platforms, so we must load it
-	// dynamically.
+	/* Only available on 64bit platforms, so we must load it
+	   dynamically.*/
 	hMod = GetModuleHandle("advapi32.dll");
 	if (hMod)
 		pfn = (RDRKFunc)GetProcAddress(hMod,
@@ -1448,8 +1541,8 @@
 	if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
 		return NULL;
 
-	// Only available on 64bit platforms, so we must load it
-	// dynamically.
+	/* Only available on 64bit platforms, so we must load it
+	   dynamically.*/
 	hMod = GetModuleHandle("advapi32.dll");
 	if (hMod)
 		pfn = (RERKFunc)GetProcAddress(hMod,
@@ -1485,8 +1578,8 @@
 	if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
 		return NULL;
 
-	// Only available on 64bit platforms, so we must load it
-	// dynamically.
+	/* Only available on 64bit platforms, so we must load it
+	   dynamically.*/
 	hMod = GetModuleHandle("advapi32.dll");
 	if (hMod)
 		pfn = (RQRKFunc)GetProcAddress(hMod,
@@ -1502,14 +1595,16 @@
 	if (rc != ERROR_SUCCESS)
 		return PyErr_SetFromWindowsErrWithFunction(rc,
 		                                           "RegQueryReflectionKey");
-	return PyBool_FromLong(rc);
+	return PyBool_FromLong(result);
 }
 
 static struct PyMethodDef winreg_methods[] = {
 	{"CloseKey",         PyCloseKey,        METH_VARARGS, CloseKey_doc},
 	{"ConnectRegistry",  PyConnectRegistry, METH_VARARGS, ConnectRegistry_doc},
 	{"CreateKey",        PyCreateKey,       METH_VARARGS, CreateKey_doc},
+	{"CreateKeyEx",      PyCreateKeyEx,     METH_VARARGS, CreateKeyEx_doc},
 	{"DeleteKey",        PyDeleteKey,       METH_VARARGS, DeleteKey_doc},
+	{"DeleteKeyEx",      PyDeleteKeyEx,     METH_VARARGS, DeleteKeyEx_doc},
 	{"DeleteValue",      PyDeleteValue,     METH_VARARGS, DeleteValue_doc},
 	{"DisableReflectionKey", PyDisableReflectionKey, METH_VARARGS, DisableReflectionKey_doc},
 	{"EnableReflectionKey",  PyEnableReflectionKey,  METH_VARARGS, EnableReflectionKey_doc},

Modified: python/branches/py3k-cdecimal/Python/marshal.c
==============================================================================
--- python/branches/py3k-cdecimal/Python/marshal.c	(original)
+++ python/branches/py3k-cdecimal/Python/marshal.c	Fri Apr 23 10:13:30 2010
@@ -1078,23 +1078,13 @@
 PyObject *
 PyMarshal_ReadLastObjectFromFile(FILE *fp)
 {
-/* 75% of 2.1's .pyc files can exploit SMALL_FILE_LIMIT.
- * REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc.
- */
-#define SMALL_FILE_LIMIT (1L << 14)
+/* REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc. */
 #define REASONABLE_FILE_LIMIT (1L << 18)
 #ifdef HAVE_FSTAT
 	off_t filesize;
-#endif
-#ifdef HAVE_FSTAT
 	filesize = getfilesize(fp);
-	if (filesize > 0) {
-		char buf[SMALL_FILE_LIMIT];
-		char* pBuf = NULL;
-		if (filesize <= SMALL_FILE_LIMIT)
-			pBuf = buf;
-		else if (filesize <= REASONABLE_FILE_LIMIT)
-			pBuf = (char *)PyMem_MALLOC(filesize);
+	if (filesize > 0 && filesize <= REASONABLE_FILE_LIMIT) {
+		char* pBuf = (char *)PyMem_MALLOC(filesize);
 		if (pBuf != NULL) {
 			PyObject* v;
 			size_t n;
@@ -1102,8 +1092,7 @@
 			   is smaller than REASONABLE_FILE_LIMIT */
 			n = fread(pBuf, 1, (int)filesize, fp);
 			v = PyMarshal_ReadObjectFromString(pBuf, n);
-			if (pBuf != buf)
-				PyMem_FREE(pBuf);
+			PyMem_FREE(pBuf);
 			return v;
 		}
 
@@ -1114,7 +1103,6 @@
 	 */
 	return PyMarshal_ReadObjectFromFile(fp);
 
-#undef SMALL_FILE_LIMIT
 #undef REASONABLE_FILE_LIMIT
 }
 

Modified: python/branches/py3k-cdecimal/Tools/gdb/libpython.py
==============================================================================
--- python/branches/py3k-cdecimal/Tools/gdb/libpython.py	(original)
+++ python/branches/py3k-cdecimal/Tools/gdb/libpython.py	Fri Apr 23 10:13:30 2010
@@ -19,9 +19,10 @@
 In particular, given a gdb.Value corresponding to a PyObject* in the inferior
 process, we can generate a "proxy value" within the gdb process.  For example,
 given a PyObject* in the inferior process that is in fact a PyListObject*
-holding three PyObject* that turn out to be PyStringObject* instances, we can
-generate a proxy value within the gdb process that is a list of strings:
-  ["foo", "bar", "baz"]
+holding three PyObject* that turn out to be PyBytesObject* instances, we can
+generate a proxy value within the gdb process that is a list of bytes
+instances:
+  [b"foo", b"bar", b"baz"]
 
 Doing so can be expensive for complicated graphs of objects, and could take
 some time, so we also have a "write_repr" method that writes a representation
@@ -57,7 +58,7 @@
 Py_TPFLAGS_LONG_SUBCLASS     = (1L << 24)
 Py_TPFLAGS_LIST_SUBCLASS     = (1L << 25)
 Py_TPFLAGS_TUPLE_SUBCLASS    = (1L << 26)
-Py_TPFLAGS_STRING_SUBCLASS   = (1L << 27)
+Py_TPFLAGS_BYTES_SUBCLASS    = (1L << 27)
 Py_TPFLAGS_UNICODE_SUBCLASS  = (1L << 28)
 Py_TPFLAGS_DICT_SUBCLASS     = (1L << 29)
 Py_TPFLAGS_BASE_EXC_SUBCLASS = (1L << 30)
@@ -66,6 +67,9 @@
 
 MAX_OUTPUT_LEN=1024
 
+hexdigits = "0123456789abcdef"
+
+
 class NullPyObjectPtr(RuntimeError):
     pass
 
@@ -108,7 +112,7 @@
 class PyObjectPtr(object):
     """
     Class wrapping a gdb.Value that's a either a (PyObject*) within the
-    inferior process, or some subclass pointer e.g. (PyStringObject*)
+    inferior process, or some subclass pointer e.g. (PyBytesObject*)
 
     There will be a subclass for every refined PyObject type that we care
     about.
@@ -148,12 +152,8 @@
             return pyo_ptr.dereference()[name]
 
         if name == 'ob_size':
-            try:
-            # Python 2:
-                return self._gdbval.dereference()[name]
-            except RuntimeError:
-                # Python 3:
-                return self._gdbval.dereference()['ob_base'][name]
+            pyo_ptr = self._gdbval.cast(PyVarObjectPtr.get_gdb_type())
+            return pyo_ptr.dereference()[name]
 
         # General case: look it up inside the object:
         return self._gdbval.dereference()[name]
@@ -318,8 +318,8 @@
             return PyListObjectPtr
         if tp_flags & Py_TPFLAGS_TUPLE_SUBCLASS:
             return PyTupleObjectPtr
-        if tp_flags & Py_TPFLAGS_STRING_SUBCLASS:
-            return PyStringObjectPtr
+        if tp_flags & Py_TPFLAGS_BYTES_SUBCLASS:
+            return PyBytesObjectPtr
         if tp_flags & Py_TPFLAGS_UNICODE_SUBCLASS:
             return PyUnicodeObjectPtr
         if tp_flags & Py_TPFLAGS_DICT_SUBCLASS:
@@ -355,6 +355,8 @@
     def as_address(self):
         return long(self._gdbval)
 
+class PyVarObjectPtr(PyObjectPtr):
+    _typename = 'PyVarObject'
 
 class ProxyAlreadyVisited(object):
     '''
@@ -515,20 +517,6 @@
         out.write(self.safe_tp_name())
         self.write_field_repr('args', out, visited)
 
-class PyBoolObjectPtr(PyObjectPtr):
-    """
-    Class wrapping a gdb.Value that's a PyBoolObject* i.e. one of the two
-    <bool> instances (Py_True/Py_False) within the process being debugged.
-    """
-    _typename = 'PyBoolObject'
-
-    def proxyval(self, visited):
-        if int_from_int(self.field('ob_ival')):
-            return True
-        else:
-            return False
-
-
 class PyClassObjectPtr(PyObjectPtr):
     """
     Class wrapping a gdb.Value that's a PyClassObject* i.e. a <classobj>
@@ -691,13 +679,6 @@
         _write_instance_repr(out, visited,
                              cl_name, pyop_in_dict, self.as_address())
 
-class PyIntObjectPtr(PyObjectPtr):
-    _typename = 'PyIntObject'
-
-    def proxyval(self, visited):
-        result = int_from_int(self.field('ob_ival'))
-        return result
-
 class PyListObjectPtr(PyObjectPtr):
     _typename = 'PyListObject'
 
@@ -770,6 +751,22 @@
             result = -result
         return result
 
+    def write_repr(self, out, visited):
+        # Write this out as a Python 3 int literal, i.e. without the "L" suffix
+        proxy = self.proxyval(visited)
+        out.write("%s" % proxy)
+
+
+class PyBoolObjectPtr(PyLongObjectPtr):
+    """
+    Class wrapping a gdb.Value that's a PyBoolObject* i.e. one of the two
+    <bool> instances (Py_True/Py_False) within the process being debugged.
+    """
+    def proxyval(self, visited):
+        if PyLongObjectPtr.proxyval(self, visited):
+            return True
+        else:
+            return False
 
 class PyNoneStructPtr(PyObjectPtr):
     """
@@ -894,9 +891,9 @@
             return
         out.write('Frame 0x%x, for file %s, line %i, in %s ('
                   % (self.as_address(),
-                     self.co_filename,
+                     self.co_filename.proxyval(visited),
                      self.current_line_num(),
-                     self.co_name))
+                     self.co_name.proxyval(visited)))
         first = True
         for pyop_name, pyop_value in self.iter_locals():
             if not first:
@@ -933,7 +930,8 @@
             return set(members)
 
     def write_repr(self, out, visited):
-        out.write(self.safe_tp_name())
+        # Emulate Python 3's set_repr
+        tp_name = self.safe_tp_name()
 
         # Guard against infinite loops:
         if self.as_address() in visited:
@@ -941,7 +939,18 @@
             return
         visited.add(self.as_address())
 
-        out.write('([')
+        # Python 3's set_repr special-cases the empty set:
+        if not self.field('used'):
+            out.write(tp_name)
+            out.write('()')
+            return
+
+        # Python 3 uses {} for set literals:
+        if tp_name != 'set':
+            out.write(tp_name)
+            out.write('(')
+
+        out.write('{')
         first = True
         table = self.field('table')
         for i in safe_range(self.field('mask')+1):
@@ -955,11 +964,14 @@
                         out.write(', ')
                     first = False
                     pyop_key.write_repr(out, visited)
-        out.write('])')
+        out.write('}')
+
+        if tp_name != 'set':
+            out.write(')')
 
 
-class PyStringObjectPtr(PyObjectPtr):
-    _typename = 'PyStringObject'
+class PyBytesObjectPtr(PyObjectPtr):
+    _typename = 'PyBytesObject'
 
     def __str__(self):
         field_ob_size = self.field('ob_size')
@@ -970,6 +982,37 @@
     def proxyval(self, visited):
         return str(self)
 
+    def write_repr(self, out, visited):
+        # Write this out as a Python 3 bytes literal, i.e. with a "b" prefix
+
+        # Get a PyStringObject* within the Python 2 gdb process:
+        proxy = self.proxyval(visited)
+
+        # Transliteration of Python 3's Objects/bytesobject.c:PyBytes_Repr
+        # to Python 2 code:
+        quote = "'"
+        if "'" in proxy and not '"' in proxy:
+            quote = '"'
+        out.write('b')
+        out.write(quote)
+        for byte in proxy:
+            if byte == quote or byte == '\\':
+                out.write('\\')
+                out.write(byte)
+            elif byte == '\t':
+                out.write('\\t')
+            elif byte == '\n':
+                out.write('\\n')
+            elif byte == '\r':
+                out.write('\\r')
+            elif byte < ' ' or ord(byte) >= 0x7f:
+                out.write('\\x')
+                out.write(hexdigits[(ord(byte) & 0xf0) >> 4])
+                out.write(hexdigits[ord(byte) & 0xf])
+            else:
+                out.write(byte)
+        out.write(quote)
+
 class PyTupleObjectPtr(PyObjectPtr):
     _typename = 'PyTupleObject'
 
@@ -1010,9 +1053,21 @@
     _typename = 'PyTypeObject'
 
 
+def _unichr_is_printable(char):
+    # Logic adapted from Python 3's Tools/unicode/makeunicodedata.py
+    if char == u" ":
+        return True
+    import unicodedata
+    return unicodedata.category(char)[0] not in ("C", "Z")
+
+
 class PyUnicodeObjectPtr(PyObjectPtr):
     _typename = 'PyUnicodeObject'
 
+    def char_width(self):
+        _type_Py_UNICODE = gdb.lookup_type('Py_UNICODE')
+        return _type_Py_UNICODE.sizeof
+
     def proxyval(self, visited):
         # From unicodeobject.h:
         #     Py_ssize_t length;  /* Length of raw Unicode data in buffer */
@@ -1029,6 +1084,102 @@
         result = u''.join([unichr(ucs) for ucs in Py_UNICODEs])
         return result
 
+    def write_repr(self, out, visited):
+        # Write this out as a Python 3 str literal, i.e. without a "u" prefix
+
+        # Get a PyUnicodeObject* within the Python 2 gdb process:
+        proxy = self.proxyval(visited)
+
+        # Transliteration of Python 3's Object/unicodeobject.c:unicode_repr
+        # to Python 2:
+        if "'" in proxy and '"' not in proxy:
+            quote = '"'
+        else:
+            quote = "'"
+        out.write(quote)
+
+        i = 0
+        while i < len(proxy):
+            ch = proxy[i]
+            i += 1
+
+            # Escape quotes and backslashes
+            if ch == quote or ch == '\\':
+                out.write('\\')
+                out.write(ch)
+
+            #  Map special whitespace to '\t', \n', '\r'
+            elif ch == '\t':
+                out.write('\\t')
+            elif ch == '\n':
+                out.write('\\n')
+            elif ch == '\r':
+                out.write('\\r')
+
+            # Map non-printable US ASCII to '\xhh' */
+            elif ch < ' ' or ch == 0x7F:
+                out.write('\\x')
+                out.write(hexdigits[(ord(ch) >> 4) & 0x000F])
+                out.write(hexdigits[ord(ch) & 0x000F])
+
+            # Copy ASCII characters as-is
+            elif ord(ch) < 0x7F:
+                out.write(ch)
+
+            # Non-ASCII characters
+            else:
+                ucs = ch;
+
+                if self.char_width == 2:
+                    ch2 = 0
+                    # Get code point from surrogate pair
+                    if i < len(proxy):
+                        ch2 = proxy[i]
+                        if (ord(ch) >= 0xD800 and ord(ch) < 0xDC00
+                            and ord(ch2) >= 0xDC00 and ord(ch2) <= 0xDFFF):
+                            ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000;
+                            i += 1
+
+                # Map Unicode whitespace and control characters
+                # (categories Z* and C* except ASCII space)
+                if not _unichr_is_printable(ucs):
+                    # Unfortuately, Python 2's unicode type doesn't seem
+                    # to expose the "isprintable" method
+
+                    # Map 8-bit characters to '\\xhh'
+                    if ucs <= 0xff:
+                        out.write('\\x')
+                        out.write(hexdigits[(ord(ucs) >> 4) & 0x000F])
+                        out.write(hexdigits[ord(ucs) & 0x000F])
+                    # Map 21-bit characters to '\U00xxxxxx'
+                    elif ucs >= 0x10000:
+                        out.write('\\U')
+                        out.write(hexdigits[(ord(ucs) >> 28) & 0x0000000F])
+                        out.write(hexdigits[(ord(ucs) >> 24) & 0x0000000F])
+                        out.write(hexdigits[(ord(ucs) >> 20) & 0x0000000F])
+                        out.write(hexdigits[(ord(ucs) >> 16) & 0x0000000F])
+                        out.write(hexdigits[(ord(ucs) >> 12) & 0x0000000F])
+                        out.write(hexdigits[(ord(ucs) >> 8) & 0x0000000F])
+                        out.write(hexdigits[(ord(ucs) >> 4) & 0x0000000F])
+                        out.write(hexdigits[ord(ucs) & 0x0000000F])
+                    # Map 16-bit characters to '\uxxxx'
+                    else:
+                        out.write('\\u')
+                        out.write(hexdigits[(ord(ucs) >> 12) & 0x000F])
+                        out.write(hexdigits[(ord(ucs) >> 8) & 0x000F])
+                        out.write(hexdigits[(ord(ucs) >> 4) & 0x000F])
+                        out.write(hexdigits[ord(ucs) & 0x000F])
+                else:
+                    # Copy characters as-is
+                    out.write(ch)
+                    if self.char_width == 2:
+                        if ord(ucs) >= 0x10000:
+                            out.write(ch2)
+
+        out.write(quote)
+
+
+
 
 def int_from_int(gdbval):
     return int(str(gdbval))
@@ -1065,7 +1216,7 @@
     if type.code == gdb.TYPE_CODE_PTR:
         type = type.target().unqualified()
         t = str(type)
-        if t in ("PyObject", "PyFrameObject"):
+        if t in ("PyObject", "PyFrameObject", "PyUnicodeObject"):
             return PyObjectPtrPrinter(gdbval)
 
 """

Modified: python/branches/py3k-cdecimal/setup.py
==============================================================================
--- python/branches/py3k-cdecimal/setup.py	(original)
+++ python/branches/py3k-cdecimal/setup.py	Fri Apr 23 10:13:30 2010
@@ -1250,8 +1250,9 @@
         # End multiprocessing
 
         # Platform-specific libraries
-        if platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
-                        'freebsd7', 'freebsd8'):
+        if (platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
+                        'freebsd7', 'freebsd8')
+            or platform.startswith("gnukfreebsd")):
             exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) )
         else:
             missing.append('ossaudiodev')
@@ -1606,7 +1607,7 @@
             inc_dirs.append('/usr/include/ffi')
 
         ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
-        if not ffi_inc:
+        if not ffi_inc or ffi_inc[0] == '':
             ffi_inc = find_file('ffi.h', [], inc_dirs)
         if ffi_inc is not None:
             ffi_h = ffi_inc[0] + '/ffi.h'


More information about the Python-checkins mailing list