Merged revisions 79822,79828,79862,80067,80069,80080-80081,80084,80432-80433 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79822 | georg.brandl | 2010-04-06 08:18:15 +0000 (Di, 06 Apr 2010) | 1 line
#8320: document return value of recv_into().
........
r79828 | georg.brandl | 2010-04-06 14:33:44 +0000 (Di, 06 Apr 2010) | 1 line
Add JP.
........
r79862 | georg.brandl | 2010-04-06 20:27:59 +0000 (Di, 06 Apr 2010) | 1 line
Fix syntax.
........
r80067 | georg.brandl | 2010-04-14 08:53:38 +0000 (Mi, 14 Apr 2010) | 1 line
#5341: typo.
........
r80069 | georg.brandl | 2010-04-14 13:50:31 +0000 (Mi, 14 Apr 2010) | 1 line
Add an x-ref to where the O_ constants are documented and move the SEEK_ constants after lseek().
........
r80080 | georg.brandl | 2010-04-14 19:16:38 +0000 (Mi, 14 Apr 2010) | 1 line
#8399: add note about Windows and O_BINARY.
........
r80081 | georg.brandl | 2010-04-14 21:34:44 +0000 (Mi, 14 Apr 2010) | 1 line
#5250: document __instancecheck__ and __subclasscheck__. I hope the part about the class/metaclass distinction is understandable.
........
r80084 | georg.brandl | 2010-04-14 21:46:45 +0000 (Mi, 14 Apr 2010) | 1 line
Fix missing.
........
r80432 | georg.brandl | 2010-04-24 08:56:58 +0000 (Sa, 24 Apr 2010) | 1 line
Markup fixes.
........
r80433 | georg.brandl | 2010-04-24 09:08:10 +0000 (Sa, 24 Apr 2010) | 1 line
#7507: quote "!" in pipes.quote(); it is a special character for some shells.
........
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 1bc9126..eb9cb19 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -677,6 +677,16 @@
Availability: Unix, Windows.
+.. data:: SEEK_SET
+ SEEK_CUR
+ SEEK_END
+
+ Parameters to the :func:`lseek` function. Their values are 0, 1, and 2,
+ respectively. Availability: Windows, Unix.
+
+ .. versionadded:: 2.5
+
+
.. function:: open(file, flags[, mode])
Open the file *file* and set various flags according to *flags* and possibly its
@@ -686,7 +696,8 @@
For a description of the flag and mode values, see the C run-time documentation;
flag constants (like :const:`O_RDONLY` and :const:`O_WRONLY`) are defined in
- this module too (see below).
+ this module too (see :ref:`open-constants`). In particular, on Windows adding
+ :const:`O_BINARY` is needed to open files in binary mode.
Availability: Unix, Windows.
@@ -774,6 +785,12 @@
:func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its
:meth:`~file.write` method.
+
+.. _open-constants:
+
+``open()`` flag constants
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
The following constants are options for the *flags* parameter to the
:func:`~os.open` function. They can be combined using the bitwise OR operator
``|``. Some of them are not available on all platforms. For descriptions of
@@ -825,16 +842,6 @@
the C library.
-.. data:: SEEK_SET
- SEEK_CUR
- SEEK_END
-
- Parameters to the :func:`lseek` function. Their values are 0, 1, and 2,
- respectively. Availability: Windows, Unix.
-
- .. versionadded:: 2.5
-
-
.. _os-file-dir:
Files and Directories
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index 51f3b82..22579ae 100644
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -664,10 +664,10 @@
.. method:: socket.recv_into(buffer[, nbytes[, flags]])
Receive up to *nbytes* bytes from the socket, storing the data into a buffer
- rather than creating a new string. If *nbytes* is not specified (or 0),
- receive up to the size available in the given buffer. See the Unix manual page
- :manpage:`recv(2)` for the meaning of the optional argument *flags*; it defaults
- to zero.
+ rather than creating a new string. If *nbytes* is not specified (or 0),
+ receive up to the size available in the given buffer. Returns the number of
+ bytes received. See the Unix manual page :manpage:`recv(2)` for the meaning
+ of the optional argument *flags*; it defaults to zero.
.. versionadded:: 2.5
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index 5189f1f..8c16d4e 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -1757,6 +1757,48 @@
locking/synchronization.
+Customizing instance and subclass checks
+----------------------------------------
+
+.. versionadded:: 2.6
+
+The following methods are used to override the default behavior of the
+:func:`isinstance` and :func:`issubclass` built-in functions.
+
+In particular, the metaclass :class:`abc.ABCMeta` implements these methods in
+order to allow the addition of Abstract Base Classes (ABCs) as "virtual base
+classes" to any class or type (including built-in types), and including to other
+ABCs.
+
+.. method:: class.__instancecheck__(self, instance)
+
+ Return true if *instance* should be considered a (direct or indirect)
+ instance of *class*. If defined, called to implement ``isinstance(instance,
+ class)``.
+
+
+.. method:: class.__subclasscheck__(self, subclass)
+
+ Return true if *subclass* should be considered a (direct or indirect)
+ subclass of *class*. If defined, called to implement ``issubclass(subclass,
+ class)``.
+
+
+Note that these methods are looked up on the type (metaclass) of a class. They
+cannot be defined as class methods in the actual class. This is consistent with
+the lookup of special methods that are called on instances, only that in this
+case the instance is itself a class.
+
+.. seealso::
+
+ :pep:`3119` - Introducing Abstract Base Classes
+ Includes the specification for customizing :func:`isinstance` and
+ :func:`issubclass` behavior through :meth:`__instancecheck__` and
+ :meth:`__subclasscheck__`, with motivation for this functionality in the
+ context of adding Abstract Base Classes (see the :mod:`abc` module) to the
+ language.
+
+
.. _callable-types:
Emulating callable objects
diff --git a/Lib/pipes.py b/Lib/pipes.py
index 25e9915..02e1257 100644
--- a/Lib/pipes.py
+++ b/Lib/pipes.py
@@ -263,11 +263,11 @@
# Reliably quote a string as a single argument for /bin/sh
-_safechars = string.ascii_letters + string.digits + '!@%_-+=:,./' # Safe unquoted
-_funnychars = '"`$\\' # Unsafe inside "double quotes"
+# Safe unquoted
+_safechars = frozenset(string.ascii_letters + string.digits + '@%_-+=:,./')
def quote(file):
- ''' return a shell-escaped version of the file string '''
+ """Return a shell-escaped version of the file string."""
for c in file:
if c not in _safechars:
break
@@ -275,11 +275,6 @@
if not file:
return "''"
return file
- if '\'' not in file:
- return '\'' + file + '\''
- res = ''
- for c in file:
- if c in _funnychars:
- c = '\\' + c
- res = res + c
- return '"' + res + '"'
+ # use single quotes, and put single quotes into double quotes
+ # the string $'b is then quoted as '$'"'"'b'
+ return "'" + file.replace("'", "'\"'\"'") + "'"
diff --git a/Lib/test/test_pipes.py b/Lib/test/test_pipes.py
index dd1cc9e..072d023 100644
--- a/Lib/test/test_pipes.py
+++ b/Lib/test/test_pipes.py
@@ -62,9 +62,10 @@
self.assertEqual(open(TESTFN).read(), d)
def testQuoting(self):
- safeunquoted = string.ascii_letters + string.digits + '!@%_-+=:,./'
- unsafe = '"`$\\'
+ safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./'
+ unsafe = '"`$\\!'
+ self.assertEqual(pipes.quote(''), "''")
self.assertEqual(pipes.quote(safeunquoted), safeunquoted)
self.assertEqual(pipes.quote('test file name'), "'test file name'")
for u in unsafe:
@@ -72,9 +73,7 @@
"'test%sname'" % u)
for u in unsafe:
self.assertEqual(pipes.quote("test%s'name'" % u),
- '"test\\%s\'name\'"' % u)
-
- self.assertEqual(pipes.quote(''), "''")
+ "'test%s'\"'\"'name'\"'\"''" % u)
def testRepr(self):
t = pipes.Template()
diff --git a/Misc/NEWS b/Misc/NEWS
index 43d4c4b..09ab65e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,7 +29,9 @@
- Raise a TypeError when trying to delete a T_STRING_INPLACE struct member.
-- Issue #1583863: An unicode subclass can now override the __unicode__ method
+- Issue #1583863: An unicode subclass can now override the __unicode__ method.
+
+- Issue #7507: Quote "!" in pipes.quote(); it is special to some shells.
- Issue #7544: Preallocate thread memory before creating the thread to avoid
a fatal error in low memory condition.
diff --git a/Misc/developers.txt b/Misc/developers.txt
index 6d91a70..006bd31 100644
--- a/Misc/developers.txt
+++ b/Misc/developers.txt
@@ -17,6 +17,11 @@
Permissions History
-------------------
+- Jean-Paul Calderone was given commit access on April 6 2010 by
+ GFB, at suggestion of Michael Foord and others.
+
+- Brian Curtin was given commit access on March 24 2010 by MvL.
+
- Florent Xicluna was given commit access on February 25 2010 by
MvL, based on Antoine Pitrou's recommendation.