[Python-checkins] r64654 - in python/branches/tlee-ast-optimize: Doc/glossary.rst Doc/library/abc.rst Doc/library/msilib.rst Doc/library/stdtypes.rst Doc/library/subprocess.rst Doc/library/urllib.rst Doc/reference/expressions.rst Doc/whatsnew/2.6.rst Lib/test/test_file.py Lib/test/test_syntax.py Lib/test/test_urllib.py Lib/test/test_urllibnet.py Lib/urllib.py Misc/NEWS Python/ast.c Python/ceval.c

thomas.lee python-checkins at python.org
Wed Jul 2 09:11:20 CEST 2008


Author: thomas.lee
Date: Wed Jul 2 09:11:19 2008
New Revision: 64654
Log:
Merged revisions 64612-64653 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk
........
 r64622 | benjamin.peterson | 2008年07月02日 05:34:52 +1000 (2008年7月02日) | 1 line
 
 #3219 repeated keyword arguments aren't allowed in function calls anymore
........
 r64623 | benjamin.peterson | 2008年07月02日 05:51:54 +1000 (2008年7月02日) | 1 line
 
 write a short little section for multiprocessing; it still needs help
........
 r64625 | georg.brandl | 2008年07月02日 05:59:00 +1000 (2008年7月02日) | 2 lines
 
 Add a link to PEP 324.
........
 r64630 | georg.brandl | 2008年07月02日 06:18:10 +1000 (2008年7月02日) | 2 lines
 
 #3216: fix Execute's parameter description.
........
 r64633 | amaury.forgeotdarc | 2008年07月02日 06:38:04 +1000 (2008年7月02日) | 5 lines
 
 #3242: fix a crash in "print", if sys.stdout is set to a custom object,
 whose write() method installs another sys.stdout.
 
 Will backport.
........
 r64635 | georg.brandl | 2008年07月02日 06:45:09 +1000 (2008年7月02日) | 2 lines
 
 #1523853: add note about fread().
........
 r64638 | georg.brandl | 2008年07月02日 06:50:02 +1000 (2008年7月02日) | 2 lines
 
 #1410739: add a footnote about "is" and "unusual" behavior.
........
 r64640 | georg.brandl | 2008年07月02日 06:56:03 +1000 (2008年7月02日) | 2 lines
 
 Add a comment about incref'ing w.
........
 r64647 | benjamin.peterson | 2008年07月02日 09:33:06 +1000 (2008年7月02日) | 1 line
 
 add ABC to the glossary
........
 r64649 | brett.cannon | 2008年07月02日 11:57:08 +1000 (2008年7月02日) | 8 lines
 
 Handle urllib's renaming for Python 3.0:
 
 * Deprecate urllib.urlopen() in favor of urllib2.urlopen() for 3.0.
 * Update docs to mention split/rename of the module and deprecation of
 urlopen().
 
 Changes to lib2to3 are in a separate commit. Work is for issue #2885.
........
Modified:
 python/branches/tlee-ast-optimize/ (props changed)
 python/branches/tlee-ast-optimize/Doc/glossary.rst
 python/branches/tlee-ast-optimize/Doc/library/abc.rst
 python/branches/tlee-ast-optimize/Doc/library/msilib.rst
 python/branches/tlee-ast-optimize/Doc/library/stdtypes.rst
 python/branches/tlee-ast-optimize/Doc/library/subprocess.rst
 python/branches/tlee-ast-optimize/Doc/library/urllib.rst
 python/branches/tlee-ast-optimize/Doc/reference/expressions.rst
 python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst
 python/branches/tlee-ast-optimize/Lib/test/test_file.py
 python/branches/tlee-ast-optimize/Lib/test/test_syntax.py
 python/branches/tlee-ast-optimize/Lib/test/test_urllib.py
 python/branches/tlee-ast-optimize/Lib/test/test_urllibnet.py
 python/branches/tlee-ast-optimize/Lib/urllib.py
 python/branches/tlee-ast-optimize/Misc/NEWS
 python/branches/tlee-ast-optimize/Python/ast.c
 python/branches/tlee-ast-optimize/Python/ceval.c
Modified: python/branches/tlee-ast-optimize/Doc/glossary.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/glossary.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/glossary.rst	Wed Jul 2 09:11:19 2008
@@ -24,6 +24,14 @@
 2to3 is available in the standard library as :mod:`lib2to3`; a standalone
 entry point is provided as :file:`Tools/scripts/2to3`.
 
+ Abstract Base Class
+ Abstract Base Classes (abbreviated ABCs) complement :term:`duck-typing` by
+ providing a way to define interfaces when other techniques like :func:`hasattr`
+ would be clumsy. Python comes with many builtin ABCs for data structures
+ (in the :mod:`collections` module), numbers (in the :mod:`numbers`
+ module), and streams (in the :mod:`io` module). You can create your own
+ ABC with the :mod:`abc` module.
+
 argument
 A value passed to a function or method, assigned to a name local to
 the body. A function or method may have both positional arguments and
@@ -116,15 +124,16 @@
 be any object with a :meth:`__hash__` function, not just integers starting
 from zero. Called a hash in Perl.
 
- duck-typing
+ duck-typing 
 Pythonic programming style that determines an object's type by inspection
 of its method or attribute signature rather than by explicit relationship
 to some type object ("If it looks like a duck and quacks like a duck, it
 must be a duck.") By emphasizing interfaces rather than specific types,
 well-designed code improves its flexibility by allowing polymorphic
 substitution. Duck-typing avoids tests using :func:`type` or
- :func:`isinstance`. Instead, it typically employs :func:`hasattr` tests or
- :term:`EAFP` programming.
+ :func:`isinstance`. (Note, however, that duck-typing can be complemented
+ with abstract base classes.) Instead, it typically employs :func:`hasattr`
+ tests or :term:`EAFP` programming.
 
 EAFP
 Easier to ask for forgiveness than permission. This common Python coding
Modified: python/branches/tlee-ast-optimize/Doc/library/abc.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/abc.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/abc.rst	Wed Jul 2 09:11:19 2008
@@ -9,10 +9,10 @@
 
 .. versionadded:: 2.6
 
-This module provides the infrastructure for defining abstract base classes
-(ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this was added
-to Python. (See also :pep:`3141` and the :mod:`numbers` module regarding a type
-hierarchy for numbers based on ABCs.)
+This module provides the infrastructure for defining :term:`abstract base
+classes` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this
+was added to Python. (See also :pep:`3141` and the :mod:`numbers` module
+regarding a type hierarchy for numbers based on ABCs.)
 
 The :mod:`collections` module has some concrete classes that derive from
 ABCs; these can, of course, be further derived. In addition the
Modified: python/branches/tlee-ast-optimize/Doc/library/msilib.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/msilib.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/msilib.rst	Wed Jul 2 09:11:19 2008
@@ -1,4 +1,3 @@
-
 :mod:`msilib` --- Read and write Microsoft Installer files
 ==========================================================
 
@@ -165,11 +164,11 @@
 ------------
 
 
-.. method:: View.Execute([params=None])
+.. method:: View.Execute(params)
 
- Execute the SQL query of the view, through :cfunc:`MSIViewExecute`. *params* is
- an optional record describing actual values of the parameter tokens in the
- query.
+ Execute the SQL query of the view, through :cfunc:`MSIViewExecute`. If
+ *params* is not ``None``, it is a record describing actual values of the
+ parameter tokens in the query.
 
 
 .. method:: View.GetColumnInfo(kind)
Modified: python/branches/tlee-ast-optimize/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/stdtypes.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/stdtypes.rst	Wed Jul 2 09:11:19 2008
@@ -2058,6 +2058,10 @@
 that when in non-blocking mode, less data than what was requested may be
 returned, even if no *size* parameter was given.
 
+ .. note::
+ As this function depends of the underlying C function :cfunc:`fread`,
+ it resembles its behaviour in details like caching EOF and others.
+
 
 .. method:: file.readline([size])
 
Modified: python/branches/tlee-ast-optimize/Doc/library/subprocess.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/subprocess.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/subprocess.rst	Wed Jul 2 09:11:19 2008
@@ -23,6 +23,10 @@
 Information about how the :mod:`subprocess` module can be used to replace these
 modules and functions can be found in the following sections.
 
+.. seealso::
+
+ :pep:`324` -- PEP proposing the subprocess module
+
 
 Using the subprocess Module
 ---------------------------
Modified: python/branches/tlee-ast-optimize/Doc/library/urllib.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/urllib.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/urllib.rst	Wed Jul 2 09:11:19 2008
@@ -4,6 +4,13 @@
 .. module:: urllib
 :synopsis: Open an arbitrary network resource by URL (requires sockets).
 
+.. note::
+ The :mod:`urllib` module has been split into parts and renamed in
+ Python 3.0 to :mod:`urllib.request`, :mod:`urllib.parse`,
+ and :mod:`urllib.error`. The :term:`2to3` tool will automatically adapt
+ imports when converting your sources to 3.0.
+ Also note that the :func:`urllib.urlopen` function has been removed in
+ Python 3.0 in favor of :func:`urllib2.urlopen`.
 
 .. index::
 single: WWW
@@ -116,6 +123,10 @@
 .. versionchanged:: 2.6
 Added :meth:`getcode` to returned object and support for the
 :envvar:`no_proxy` environment variable.
+ 
+ .. deprecated:: 2.6
+ The :func:`urlopen` function has been removed in Python 3.0 in favor
+ of :func:`urllib2.urlopen`.
 
 
 .. function:: urlretrieve(url[, filename[, reporthook[, data]]])
Modified: python/branches/tlee-ast-optimize/Doc/reference/expressions.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/reference/expressions.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/reference/expressions.rst	Wed Jul 2 09:11:19 2008
@@ -1113,7 +1113,7 @@
 
 The operators :keyword:`is` and :keyword:`is not` test for object identity: ``x
 is y`` is true if and only if *x* and *y* are the same object. ``x is not y``
-yields the inverse truth value.
+yields the inverse truth value. [#]_
 
 
 .. _booleans:
@@ -1352,3 +1352,7 @@
 only, but this caused surprises because people expected to be able to test a
 dictionary for emptiness by comparing it to ``{}``.
 
+.. [#] Due to automatic garbage-collection, free lists, and the dynamic nature of 
+ descriptors, you may notice seemingly unusual behaviour in certain uses of
+ the :keyword:`is` operator, like those involving comparisons between instance
+ methods, or constants. Check their documentation for more info.
Modified: python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/whatsnew/2.6.rst	Wed Jul 2 09:11:19 2008
@@ -526,7 +526,21 @@
 PEP 371: The ``multiprocessing`` Package
 =====================================================
 
-XXX write this.
+.. XXX I think this still needs help
+
+:mod:`multiprocessing` makes it easy to distribute work over multiple processes.
+Its API is similiar to that of :mod:`threading`. For example::
+
+ from multiprocessing import Process
+
+ def long_hard_task(n):
+ print n * 43
+
+ for i in range(10):
+ Process(target=long_hard_task, args=(i)).start()
+
+will multiply the numbers between 0 and 10 times 43 and print out the result
+concurrently.
 
 .. seealso::
 
Modified: python/branches/tlee-ast-optimize/Lib/test/test_file.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_file.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_file.py	Wed Jul 2 09:11:19 2008
@@ -503,13 +503,31 @@
 self._test_close_open_io(io_func)
 
 
+class StdoutTests(unittest.TestCase):
+
+ def test_move_stdout_on_write(self):
+ # Issue 3242: sys.stdout can be replaced (and freed) during a
+ # print statement; prevent a segfault in this case
+ save_stdout = sys.stdout
+
+ class File:
+ def write(self, data):
+ if '\n' in data:
+ sys.stdout = save_stdout
+
+ try:
+ sys.stdout = File()
+ print "some text"
+ finally:
+ sys.stdout = save_stdout
+
 
 def test_main():
 # Historically, these tests have been sloppy about removing TESTFN.
 # So get rid of it no matter what.
 try:
 run_unittest(AutoFileTests, OtherFileTests, FileSubclassTests,
- FileThreadingTests)
+ FileThreadingTests, StdoutTests)
 finally:
 if os.path.exists(TESTFN):
 os.unlink(TESTFN)
Modified: python/branches/tlee-ast-optimize/Lib/test/test_syntax.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_syntax.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_syntax.py	Wed Jul 2 09:11:19 2008
@@ -417,6 +417,11 @@
 ...
 SyntaxError: can't assign to function call (<doctest test.test_syntax[48]>, line 6)
 
+>>> f(a=23, a=234)
+Traceback (most recent call last):
+ ...
+SyntaxError: keyword argument repeated (<doctest test.test_syntax[49]>, line 1)
+
 """
 
 import re
Modified: python/branches/tlee-ast-optimize/Lib/test/test_urllib.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_urllib.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_urllib.py	Wed Jul 2 09:11:19 2008
@@ -640,16 +640,20 @@
 
 
 def test_main():
- test_support.run_unittest(
- urlopen_FileTests,
- urlopen_HttpTests,
- urlretrieve_FileTests,
- QuotingTests,
- UnquotingTests,
- urlencode_Tests,
- Pathname_Tests,
- #FTPWrapperTests,
- )
+ import warnings
+ with test_support.catch_warning(record=False):
+ warnings.filterwarnings('ignore', ".*urllib\.urlopen.*Python 3.0",
+ DeprecationWarning)
+ test_support.run_unittest(
+ urlopen_FileTests,
+ urlopen_HttpTests,
+ urlretrieve_FileTests,
+ QuotingTests,
+ UnquotingTests,
+ urlencode_Tests,
+ Pathname_Tests,
+ #FTPWrapperTests,
+ )
 
 
 
Modified: python/branches/tlee-ast-optimize/Lib/test/test_urllibnet.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_urllibnet.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_urllibnet.py	Wed Jul 2 09:11:19 2008
@@ -182,9 +182,13 @@
 
 def test_main():
 test_support.requires('network')
- test_support.run_unittest(URLTimeoutTest,
- urlopenNetworkTests,
- urlretrieveNetworkTests)
+ from warnings import filterwarnings
+ with test_support.catch_warning(record=False):
+ filterwarnings('ignore', '.*urllib\.urlopen.*Python 3.0',
+ DeprecationWarning)
+ test_support.run_unittest(URLTimeoutTest,
+ urlopenNetworkTests,
+ urlretrieveNetworkTests)
 
 if __name__ == "__main__":
 test_main()
Modified: python/branches/tlee-ast-optimize/Lib/urllib.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/urllib.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/urllib.py	Wed Jul 2 09:11:19 2008
@@ -28,6 +28,7 @@
 import time
 import sys
 from urlparse import urljoin as basejoin
+import warnings
 
 __all__ = ["urlopen", "URLopener", "FancyURLopener", "urlretrieve",
 "urlcleanup", "quote", "quote_plus", "unquote", "unquote_plus",
@@ -69,7 +70,11 @@
 # Shortcut for basic usage
 _urlopener = None
 def urlopen(url, data=None, proxies=None):
- """urlopen(url [, data]) -> open file-like object"""
+ """Create a file-like object for the specified URL to read from."""
+ from warnings import warnpy3k
+ warnings.warnpy3k("urllib.urlopen() has been removed in Python 3.0 in "
+ "favor of urllib2.urlopen()", stacklevel=2)
+
 global _urlopener
 if proxies is not None:
 opener = FancyURLopener(proxies=proxies)
Modified: python/branches/tlee-ast-optimize/Misc/NEWS
==============================================================================
--- python/branches/tlee-ast-optimize/Misc/NEWS	(original)
+++ python/branches/tlee-ast-optimize/Misc/NEWS	Wed Jul 2 09:11:19 2008
@@ -10,6 +10,10 @@
 Core and Builtins
 -----------------
 
+- Issue #3242: Fix a crash inside the print statement, if sys.stdout is
+ set to a custom object whose write() method happens to install
+ another file in sys.stdout.
+
 - Issue #3088: Corrected a race condition in classes derived from
 threading.local: the first member set by a thread could be saved in
 another thread's dictionary.
@@ -21,11 +25,28 @@
 slice(None, 10, -1).indices(10) returns (9, 9, -1) instead of (9,
 10, -1).
 
+- Issue #3219: Calling a function with repeated keyword arguments, f(a=2, a=23),
+ would not cause a syntax error. This was regression from 2.4 caused by the
+ switch to the new compiler.
+
+
+Library
+-------
+
+- Issue #2885 (partial): The urllib.urlopen() function has been deprecated for
+ removal in Python 3.0 in favor of urllib2.urlopen().
+
+- Issue #2885 (partial): lib2to3 has been updated to handle the renaming of the
+ urllib module in Python 3.0 to urllib.request, urllib.parse, and
+ urllib.error.
+
+
 Build
 -----
 
 - Issue #3215: Build sqlite3 as sqlite3.dll, not sqlite3.pyd.
 
+
 What's New in Python 2.6 beta 1?
 ================================
 
Modified: python/branches/tlee-ast-optimize/Python/ast.c
==============================================================================
--- python/branches/tlee-ast-optimize/Python/ast.c	(original)
+++ python/branches/tlee-ast-optimize/Python/ast.c	Wed Jul 2 09:11:19 2008
@@ -1912,6 +1912,8 @@
 else {
 keyword_ty kw;
 identifier key;
+ int k;
+ char *tmp;
 
 /* CHILD(ch, 0) is test, but must be an identifier? */ 
 e = ast_for_expr(c, CHILD(ch, 0));
@@ -1933,6 +1935,14 @@
 key = e->v.Name.id;
 if (!forbidden_check(c, CHILD(ch, 0), PyBytes_AS_STRING(key)))
 return NULL;
+ for (k = 0; k < nkeywords; k++) {
+ tmp = PyString_AS_STRING(
+ ((keyword_ty)asdl_seq_GET(keywords, k))->arg);
+ if (!strcmp(tmp, PyString_AS_STRING(key))) {
+ ast_error(CHILD(ch, 0), "keyword argument repeated");
+ return NULL;
+ }
+ }
 e = ast_for_expr(c, CHILD(ch, 2));
 if (!e)
 return NULL;
Modified: python/branches/tlee-ast-optimize/Python/ceval.c
==============================================================================
--- python/branches/tlee-ast-optimize/Python/ceval.c	(original)
+++ python/branches/tlee-ast-optimize/Python/ceval.c	Wed Jul 2 09:11:19 2008
@@ -1617,9 +1617,13 @@
 							"lost sys.stdout");
 			}
 			if (w != NULL) {
+				/* w.write() may replace sys.stdout, so we
+				 * have to keep our reference to it */
+				Py_INCREF(w);
 				err = PyFile_WriteString("\n", w);
 				if (err == 0)
 					PyFile_SoftSpace(w, 0);
+				Py_DECREF(w);
 			}
 			Py_XDECREF(stream);
 			stream = NULL;


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /