Skip to content

Commit eb41214

Browse files
committed
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 python#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 python#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 python#8399: add note about Windows and O_BINARY. ........ r80081 | georg.brandl | 2010-04-14 21:34:44 +0000 (Mi, 14 Apr 2010) | 1 line python#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 python#7507: quote "!" in pipes.quote(); it is a special character for some shells. ........
1 parent 324086f commit eb41214

7 files changed

Lines changed: 82 additions & 32 deletions

File tree

Doc/library/os.rst

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,16 @@ as internal buffering of data.
677677
Availability: Unix, Windows.
678678

679679

680+
.. data:: SEEK_SET
681+
SEEK_CUR
682+
SEEK_END
683+
684+
Parameters to the :func:`lseek` function. Their values are 0, 1, and 2,
685+
respectively. Availability: Windows, Unix.
686+
687+
.. versionadded:: 2.5
688+
689+
680690
.. function:: open(file, flags[, mode])
681691

682692
Open the file *file* and set various flags according to *flags* and possibly its
@@ -686,7 +696,8 @@ as internal buffering of data.
686696

687697
For a description of the flag and mode values, see the C run-time documentation;
688698
flag constants (like :const:`O_RDONLY` and :const:`O_WRONLY`) are defined in
689-
this module too (see below).
699+
this module too (see :ref:`open-constants`). In particular, on Windows adding
700+
:const:`O_BINARY` is needed to open files in binary mode.
690701

691702
Availability: Unix, Windows.
692703

@@ -774,6 +785,12 @@ as internal buffering of data.
774785
:func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its
775786
:meth:`~file.write` method.
776787

788+
789+
.. _open-constants:
790+
791+
``open()`` flag constants
792+
~~~~~~~~~~~~~~~~~~~~~~~~~
793+
777794
The following constants are options for the *flags* parameter to the
778795
:func:`~os.open` function. They can be combined using the bitwise OR operator
779796
``|``. Some of them are not available on all platforms. For descriptions of
@@ -825,16 +842,6 @@ or `the MSDN <http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Window
825842
the C library.
826843

827844

828-
.. data:: SEEK_SET
829-
SEEK_CUR
830-
SEEK_END
831-
832-
Parameters to the :func:`lseek` function. Their values are 0, 1, and 2,
833-
respectively. Availability: Windows, Unix.
834-
835-
.. versionadded:: 2.5
836-
837-
838845
.. _os-file-dir:
839846

840847
Files and Directories

Doc/library/socket.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,10 +664,10 @@ correspond to Unix system calls applicable to sockets.
664664
.. method:: socket.recv_into(buffer[, nbytes[, flags]])
665665

666666
Receive up to *nbytes* bytes from the socket, storing the data into a buffer
667-
rather than creating a new string. If *nbytes* is not specified (or 0),
668-
receive up to the size available in the given buffer. See the Unix manual page
669-
:manpage:`recv(2)` for the meaning of the optional argument *flags*; it defaults
670-
to zero.
667+
rather than creating a new string. If *nbytes* is not specified (or 0),
668+
receive up to the size available in the given buffer. Returns the number of
669+
bytes received. See the Unix manual page :manpage:`recv(2)` for the meaning
670+
of the optional argument *flags*; it defaults to zero.
671671

672672
.. versionadded:: 2.5
673673

Doc/reference/datamodel.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,48 @@ property creation, proxies, frameworks, and automatic resource
17571757
locking/synchronization.
17581758

17591759

1760+
Customizing instance and subclass checks
1761+
----------------------------------------
1762+
1763+
.. versionadded:: 2.6
1764+
1765+
The following methods are used to override the default behavior of the
1766+
:func:`isinstance` and :func:`issubclass` built-in functions.
1767+
1768+
In particular, the metaclass :class:`abc.ABCMeta` implements these methods in
1769+
order to allow the addition of Abstract Base Classes (ABCs) as "virtual base
1770+
classes" to any class or type (including built-in types), and including to other
1771+
ABCs.
1772+
1773+
.. method:: class.__instancecheck__(self, instance)
1774+
1775+
Return true if *instance* should be considered a (direct or indirect)
1776+
instance of *class*. If defined, called to implement ``isinstance(instance,
1777+
class)``.
1778+
1779+
1780+
.. method:: class.__subclasscheck__(self, subclass)
1781+
1782+
Return true if *subclass* should be considered a (direct or indirect)
1783+
subclass of *class*. If defined, called to implement ``issubclass(subclass,
1784+
class)``.
1785+
1786+
1787+
Note that these methods are looked up on the type (metaclass) of a class. They
1788+
cannot be defined as class methods in the actual class. This is consistent with
1789+
the lookup of special methods that are called on instances, only that in this
1790+
case the instance is itself a class.
1791+
1792+
.. seealso::
1793+
1794+
:pep:`3119` - Introducing Abstract Base Classes
1795+
Includes the specification for customizing :func:`isinstance` and
1796+
:func:`issubclass` behavior through :meth:`__instancecheck__` and
1797+
:meth:`__subclasscheck__`, with motivation for this functionality in the
1798+
context of adding Abstract Base Classes (see the :mod:`abc` module) to the
1799+
language.
1800+
1801+
17601802
.. _callable-types:
17611803

17621804
Emulating callable objects

Lib/pipes.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,23 +263,18 @@ def makepipeline(infile, steps, outfile):
263263

264264
# Reliably quote a string as a single argument for /bin/sh
265265

266-
_safechars = string.ascii_letters + string.digits + '!@%_-+=:,./' # Safe unquoted
267-
_funnychars = '"`$\\' # Unsafe inside "double quotes"
266+
# Safe unquoted
267+
_safechars = frozenset(string.ascii_letters + string.digits + '@%_-+=:,./')
268268

269269
def quote(file):
270-
''' return a shell-escaped version of the file string '''
270+
"""Return a shell-escaped version of the file string."""
271271
for c in file:
272272
if c not in _safechars:
273273
break
274274
else:
275275
if not file:
276276
return "''"
277277
return file
278-
if '\'' not in file:
279-
return '\'' + file + '\''
280-
res = ''
281-
for c in file:
282-
if c in _funnychars:
283-
c = '\\' + c
284-
res = res + c
285-
return '"' + res + '"'
278+
# use single quotes, and put single quotes into double quotes
279+
# the string $'b is then quoted as '$'"'"'b'
280+
return "'" + file.replace("'", "'\"'\"'") + "'"

Lib/test/test_pipes.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,18 @@ def testEmptyPipeline3(self):
6262
self.assertEqual(open(TESTFN).read(), d)
6363

6464
def testQuoting(self):
65-
safeunquoted = string.ascii_letters + string.digits + '!@%_-+=:,./'
66-
unsafe = '"`$\\'
65+
safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./'
66+
unsafe = '"`$\\!'
6767

68+
self.assertEqual(pipes.quote(''), "''")
6869
self.assertEqual(pipes.quote(safeunquoted), safeunquoted)
6970
self.assertEqual(pipes.quote('test file name'), "'test file name'")
7071
for u in unsafe:
7172
self.assertEqual(pipes.quote('test%sname' % u),
7273
"'test%sname'" % u)
7374
for u in unsafe:
7475
self.assertEqual(pipes.quote("test%s'name'" % u),
75-
'"test\\%s\'name\'"' % u)
76-
77-
self.assertEqual(pipes.quote(''), "''")
76+
"'test%s'\"'\"'name'\"'\"''" % u)
7877

7978
def testRepr(self):
8079
t = pipes.Template()

Misc/NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ Core and Builtins
2929

3030
- Raise a TypeError when trying to delete a T_STRING_INPLACE struct member.
3131

32-
- Issue #1583863: An unicode subclass can now override the __unicode__ method
32+
- Issue #1583863: An unicode subclass can now override the __unicode__ method.
33+
34+
- Issue #7507: Quote "!" in pipes.quote(); it is special to some shells.
3335

3436
- Issue #7544: Preallocate thread memory before creating the thread to avoid
3537
a fatal error in low memory condition.

Misc/developers.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ the format to accommodate documentation needs as they arise.
1717
Permissions History
1818
-------------------
1919

20+
- Jean-Paul Calderone was given commit access on April 6 2010 by
21+
GFB, at suggestion of Michael Foord and others.
22+
23+
- Brian Curtin was given commit access on March 24 2010 by MvL.
24+
2025
- Florent Xicluna was given commit access on February 25 2010 by
2126
MvL, based on Antoine Pitrou's recommendation.
2227

0 commit comments

Comments
 (0)