Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8569e58

Browse files
committed
Merged revisions 80030,80067,80069,80080-80081,80084,80432-80433,80465-80470,81059,81065-81067 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r80030 | georg.brandl | 2010-04-13 08:43:54 +0200 (Di, 13 Apr 2010) | 1 line Get rid of multi-row cells. ........ r80067 | georg.brandl | 2010-04-14 10:53:38 +0200 (Mi, 14 Apr 2010) | 1 line #5341: typo. ........ r80069 | georg.brandl | 2010-04-14 15:50:31 +0200 (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 21:16:38 +0200 (Mi, 14 Apr 2010) | 1 line #8399: add note about Windows and O_BINARY. ........ r80081 | georg.brandl | 2010-04-14 23:34:44 +0200 (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 23:46:45 +0200 (Mi, 14 Apr 2010) | 1 line Fix missing. ........ r80432 | georg.brandl | 2010-04-24 10:56:58 +0200 (Sa, 24 Apr 2010) | 1 line Markup fixes. ........ r80433 | georg.brandl | 2010-04-24 11:08:10 +0200 (Sa, 24 Apr 2010) | 1 line #7507: quote "!" in pipes.quote(); it is a special character for some shells. ........ r80465 | georg.brandl | 2010-04-25 12:29:17 +0200 (So, 25 Apr 2010) | 1 line Remove LaTeXy index entry syntax. ........ r80466 | georg.brandl | 2010-04-25 12:54:42 +0200 (So, 25 Apr 2010) | 1 line Patch from Tim Hatch: Better cross-referencing in socket and winreg docs. ........ r80467 | georg.brandl | 2010-04-25 12:55:16 +0200 (So, 25 Apr 2010) | 1 line Patch from Tim Hatch: Remove reference to winreg being the fabled high-level registry interface. ........ r80468 | georg.brandl | 2010-04-25 12:55:58 +0200 (So, 25 Apr 2010) | 1 line Patch from Tim Hatch: Minor spelling changes to _winreg docs. ........ r80469 | georg.brandl | 2010-04-25 12:56:41 +0200 (So, 25 Apr 2010) | 1 line Fix code example to have valid syntax so that it can be highlighted. ........ r80470 | georg.brandl | 2010-04-25 12:57:15 +0200 (So, 25 Apr 2010) | 1 line Patch from Tim Hatch: Make socket setblocking <-> settimeout examples symmetric. ........ r81059 | georg.brandl | 2010-05-10 23:02:51 +0200 (Mo, 10 Mai 2010) | 1 line #8642: fix wrong function name. ........ r81065 | georg.brandl | 2010-05-10 23:46:50 +0200 (Mo, 10 Mai 2010) | 1 line Fix reference direction. ........ r81066 | georg.brandl | 2010-05-10 23:50:57 +0200 (Mo, 10 Mai 2010) | 1 line Consolidate deprecation messages. ........ r81067 | georg.brandl | 2010-05-10 23:51:33 +0200 (Mo, 10 Mai 2010) | 1 line Fix typo. ........
1 parent 7d79b8b commit 8569e58

12 files changed

Lines changed: 138 additions & 95 deletions

File tree

Doc/library/fcntl.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
.. index::
11-
pair: UNIX@Unix; file control
12-
pair: UNIX@Unix; I/O control
11+
pair: UNIX; file control
12+
pair: UNIX; I/O control
1313

1414
This module performs file control and I/O control on file descriptors. It is an
1515
interface to the :cfunc:`fcntl` and :cfunc:`ioctl` Unix routines.

Doc/library/ftplib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The module defines the following items:
122122
The set of all exceptions (as a tuple) that methods of :class:`FTP`
123123
instances may raise as a result of problems with the FTP connection (as
124124
opposed to programming errors made by the caller). This set includes the
125-
four exceptions listed below as well as :exc:`socket.error` and
125+
four exceptions listed above as well as :exc:`socket.error` and
126126
:exc:`IOError`.
127127

128128
.. seealso::

Doc/library/io.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ I/O Base Classes
240240

241241
Flush and close this stream. This method has no effect if the file is
242242
already closed. Once the file is closed, any operation on the file
243-
(e.g. reading or writing) will raise an :exc:`ValueError`.
243+
(e.g. reading or writing) will raise a :exc:`ValueError`.
244244

245245
As a convenience, it is allowed to call this method more than once;
246246
only the first call, however, will have an effect.

Doc/library/json.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Basic Usage
209209
specified. Encodings that are not ASCII based (such as UCS-2) are not
210210
allowed and should be decoded to :class:`str` first.
211211

212-
The other arguments have the same meaning as in :func:`dump`.
212+
The other arguments have the same meaning as in :func:`load`.
213213

214214

215215
Encoders and decoders

Doc/library/os.rst

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,14 @@ as internal buffering of data.
697697
Availability: Unix, Windows.
698698

699699

700+
.. data:: SEEK_SET
701+
SEEK_CUR
702+
SEEK_END
703+
704+
Parameters to the :func:`lseek` function. Their values are 0, 1, and 2,
705+
respectively. Availability: Windows, Unix.
706+
707+
700708
.. function:: open(file, flags[, mode])
701709

702710
Open the file *file* and set various flags according to *flags* and possibly
@@ -706,7 +714,8 @@ as internal buffering of data.
706714

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

711720
Availability: Unix, Windows.
712721

@@ -794,6 +803,12 @@ as internal buffering of data.
794803
:func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its
795804
:meth:`~file.write` method.
796805

806+
807+
.. _open-constants:
808+
809+
``open()`` flag constants
810+
~~~~~~~~~~~~~~~~~~~~~~~~~
811+
797812
The following constants are options for the *flags* parameter to the
798813
:func:`~os.open` function. They can be combined using the bitwise OR operator
799814
``|``. Some of them are not available on all platforms. For descriptions of
@@ -845,14 +860,6 @@ or `the MSDN <http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Window
845860
the C library.
846861

847862

848-
.. data:: SEEK_SET
849-
SEEK_CUR
850-
SEEK_END
851-
852-
Parameters to the :func:`lseek` function. Their values are 0, 1, and 2,
853-
respectively. Availability: Windows, Unix.
854-
855-
856863
.. _os-file-dir:
857864

858865
Files and Directories

Doc/library/socket.rst

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ All errors raise exceptions. The normal exceptions for invalid argument types
8989
and out-of-memory conditions can be raised; errors related to socket or address
9090
semantics raise the error :exc:`socket.error`.
9191

92-
Non-blocking mode is supported through :meth:`setblocking`. A generalization of
93-
this based on timeouts is supported through :meth:`settimeout`.
92+
Non-blocking mode is supported through :meth:`~socket.setblocking`. A
93+
generalization of this based on timeouts is supported through
94+
:meth:`~socket.settimeout`.
9495

9596
The module :mod:`socket` exports the following constants and functions:
9697

@@ -559,7 +560,9 @@ correspond to Unix system calls applicable to sockets.
559560
:platform: Windows
560561

561562
The :meth:`ioctl` method is a limited interface to the WSAIoctl system
562-
interface. Please refer to the MSDN documentation for more information.
563+
interface. Please refer to the `Win32 documentation
564+
<http://msdn.microsoft.com/en-us/library/ms741621%28VS.85%29.aspx>`_ for more
565+
information.
563566

564567
On other platforms, the generic :func:`fcntl.fcntl` and :func:`fcntl.ioctl`
565568
functions may be used; they accept a socket object as their first argument.
@@ -662,7 +665,7 @@ correspond to Unix system calls applicable to sockets.
662665
blocking mode. In non-blocking mode, if a :meth:`recv` call doesn't find any
663666
data, or if a :meth:`send` call can't immediately dispose of the data, a
664667
:exc:`error` exception is raised; in blocking mode, the calls block until they
665-
can proceed. ``s.setblocking(0)`` is equivalent to ``s.settimeout(0)``;
668+
can proceed. ``s.setblocking(0)`` is equivalent to ``s.settimeout(0.0)``;
666669
``s.setblocking(1)`` is equivalent to ``s.settimeout(None)``.
667670

668671

@@ -691,21 +694,21 @@ the system returns an error (such as connection timed out). In
691694
non-blocking mode, operations fail (with an error that is unfortunately
692695
system-dependent) if they cannot be completed immediately. In timeout mode,
693696
operations fail if they cannot be completed within the timeout specified for the
694-
socket or if the system returns an error. The :meth:`setblocking` method is simply
695-
a shorthand for certain :meth:`settimeout` calls.
697+
socket or if the system returns an error. The :meth:`~socket.setblocking`
698+
method is simply a shorthand for certain :meth:`~socket.settimeout` calls.
696699

697700
Timeout mode internally sets the socket in non-blocking mode. The blocking and
698701
timeout modes are shared between file descriptors and socket objects that refer
699702
to the same network endpoint. A consequence of this is that file objects
700-
returned by the :meth:`makefile` method must only be used when the socket is in
701-
blocking mode; in timeout or non-blocking mode file operations that cannot be
702-
completed immediately will fail.
703+
returned by the :meth:`~socket.makefile` method must only be used when the
704+
socket is in blocking mode; in timeout or non-blocking mode file operations
705+
that cannot be completed immediately will fail.
703706

704-
Note that the :meth:`connect` operation is subject to the timeout setting, and
705-
in general it is recommended to call :meth:`settimeout` before calling
706-
:meth:`connect` or pass a timeout parameter to :meth:`create_connection`.
707-
The system network stack may return a connection timeout error
708-
of its own regardless of any Python socket timeout setting.
707+
Note that the :meth:`~socket.connect` operation is subject to the timeout
708+
setting, and in general it is recommended to call :meth:`~socket.settimeout`
709+
before calling :meth:`~socket.connect` or pass a timeout parameter to
710+
:meth:`create_connection`. The system network stack may return a connection
711+
timeout error of its own regardless of any Python socket timeout setting.
709712

710713

711714
.. method:: socket.setsockopt(level, optname, value)
@@ -727,8 +730,8 @@ of its own regardless of any Python socket timeout setting.
727730
are disallowed. If *how* is :const:`SHUT_RDWR`, further sends and receives are
728731
disallowed.
729732

730-
Note that there are no methods :meth:`read` or :meth:`write`; use :meth:`recv`
731-
and :meth:`send` without *flags* argument instead.
733+
Note that there are no methods :meth:`read` or :meth:`write`; use
734+
:meth:`~socket.recv` and :meth:`~socket.send` without *flags* argument instead.
732735

733736
Socket objects also have these (read-only) attributes that correspond to the
734737
values given to the :class:`socket` constructor.
@@ -757,11 +760,12 @@ Example
757760
Here are four minimal example programs using the TCP/IP protocol: a server that
758761
echoes all data that it receives back (servicing only one client), and a client
759762
using it. Note that a server must perform the sequence :func:`socket`,
760-
:meth:`bind`, :meth:`listen`, :meth:`accept` (possibly repeating the
761-
:meth:`accept` to service more than one client), while a client only needs the
762-
sequence :func:`socket`, :meth:`connect`. Also note that the server does not
763-
:meth:`send`/:meth:`recv` on the socket it is listening on but on the new
764-
socket returned by :meth:`accept`.
763+
:meth:`~socket.bind`, :meth:`~socket.listen`, :meth:`~socket.accept` (possibly
764+
repeating the :meth:`~socket.accept` to service more than one client), while a
765+
client only needs the sequence :func:`socket`, :meth:`~socket.connect`. Also
766+
note that the server does not :meth:`~socket.send`/:meth:`~socket.recv` on the
767+
socket it is listening on but on the new socket returned by
768+
:meth:`~socket.accept`.
765769

766770
The first two examples support IPv4 only. ::
767771

Doc/library/syslog.rst

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,66 +10,63 @@ This module provides an interface to the Unix ``syslog`` library routines.
1010
Refer to the Unix manual pages for a detailed description of the ``syslog``
1111
facility.
1212

13-
This module wraps the system ``syslog`` module. A pure Python
14-
library that can speak to a syslog server is available in
15-
the :mod:`logging.handlers` module as :class:`SysLogHandler`.
13+
This module wraps the system ``syslog`` family of routines. A pure Python
14+
library that can speak to a syslog server is available in the
15+
:mod:`logging.handlers` module as :class:`SysLogHandler`.
1616

1717
The module defines the following functions:
1818

1919

2020
.. function:: syslog([priority,] message)
2121

22-
Send the string *message* to the system logger. A trailing newline is
23-
added if necessary. Each message is tagged with a priority composed
24-
of a *facility* and a *level*. The optional *priority* argument, which
25-
defaults to :const:`LOG_INFO`, determines the message priority. If the
26-
facility is not encoded in *priority* using logical-or (``LOG_INFO |
27-
LOG_USER``), the value given in the :func:`openlog` call is used.
22+
Send the string *message* to the system logger. A trailing newline is added
23+
if necessary. Each message is tagged with a priority composed of a
24+
*facility* and a *level*. The optional *priority* argument, which defaults
25+
to :const:`LOG_INFO`, determines the message priority. If the facility is
26+
not encoded in *priority* using logical-or (``LOG_INFO | LOG_USER``), the
27+
value given in the :func:`openlog` call is used.
2828

29-
If :func:`openlog` has not been called prior to the call to
30-
:func:'syslog', ``openlog()`` will be called with no arguments.
29+
If :func:`openlog` has not been called prior to the call to :func:`syslog`,
30+
``openlog()`` will be called with no arguments.
3131

3232

3333
.. function:: openlog([ident[, logopt[, facility]]])
3434

35-
Logging options of subsequent :func:`syslog` calls can be set by
36-
calling :func:`openlog`. :func:`syslog` will call :func:`openlog`
37-
with no arguments if the log is not currently open.
35+
Logging options of subsequent :func:`syslog` calls can be set by calling
36+
:func:`openlog`. :func:`syslog` will call :func:`openlog` with no arguments
37+
if the log is not currently open.
3838

39-
The optional *ident* keyword argument is a string which is prepended
40-
to every message, and defaults to ''sys.argv[0]'' with leading
41-
path components stripped. The optional *logopt* keyword argument
42-
(default=0) is a bit field - see below for possible values to combine.
43-
The optional *facility* keyword argument (default=:const:`LOG_USER`)
44-
sets the default facility for messages which do not have a facility
45-
explicitly encoded.
39+
The optional *ident* keyword argument is a string which is prepended to every
40+
message, and defaults to ``sys.argv[0]`` with leading path components
41+
stripped. The optional *logopt* keyword argument (default is 0) is a bit
42+
field -- see below for possible values to combine. The optional *facility*
43+
keyword argument (default is :const:`LOG_USER`) sets the default facility for
44+
messages which do not have a facility explicitly encoded.
4645

47-
.. versionchanged::3.2
48-
In previous versions, keyword arguments were not allowed, and *ident*
49-
was required. The default for *ident* was dependent on the system
50-
libraries, and often was ''python'' instead of the name of the
51-
python program file.
46+
.. versionchanged:: 3.2
47+
In previous versions, keyword arguments were not allowed, and *ident* was
48+
required. The default for *ident* was dependent on the system libraries,
49+
and often was ``python`` instead of the name of the python program file.
5250

5351

5452
.. function:: closelog()
5553

56-
Reset the syslog module values and call the system library
57-
''closelog()''.
54+
Reset the syslog module values and call the system library ``closelog()``.
5855

59-
This causes the module to behave as it does when initially imported.
60-
For example, :func:'openlog' will be called on the first :func:'syslog'
61-
call (if :func:'openlog' hasn't already been called), and *ident*
62-
and other :func:'openlog' parameters are reset to defaults.
56+
This causes the module to behave as it does when initially imported. For
57+
example, :func:`openlog` will be called on the first :func:`syslog` call (if
58+
:func:`openlog` hasn't already been called), and *ident* and other
59+
:func:`openlog` parameters are reset to defaults.
6360

6461

6562
.. function:: setlogmask(maskpri)
6663

67-
Set the priority mask to *maskpri* and return the previous mask value.
68-
Calls to :func:`syslog` with a priority level not set in *maskpri*
69-
are ignored. The default is to log all priorities. The function
70-
``LOG_MASK(pri)`` calculates the mask for the individual priority
71-
*pri*. The function ``LOG_UPTO(pri)`` calculates the mask for all
72-
priorities up to and including *pri*.
64+
Set the priority mask to *maskpri* and return the previous mask value. Calls
65+
to :func:`syslog` with a priority level not set in *maskpri* are ignored.
66+
The default is to log all priorities. The function ``LOG_MASK(pri)``
67+
calculates the mask for the individual priority *pri*. The function
68+
``LOG_UPTO(pri)`` calculates the mask for all priorities up to and including
69+
*pri*.
7370

7471
The module defines the following constants:
7572

@@ -100,11 +97,11 @@ A simple set of examples::
10097

10198
syslog.syslog('Processing started')
10299
if error:
103-
syslog.syslog(syslog.LOG_ERR, 'Processing started')
100+
syslog.syslog(syslog.LOG_ERR, 'Processing started')
104101

105-
An example of setting some log options, these would include the process ID
106-
in logged messages, and write the messages to the destination facility
107-
used for mail logging::
102+
An example of setting some log options, these would include the process ID in
103+
logged messages, and write the messages to the destination facility used for
104+
mail logging::
108105

109106
syslog.openlog(logopt=syslog.LOG_PID, facility=syslog.LOG_MAIL)
110107
syslog.syslog('E-mail processing initiated...')

Doc/library/unittest.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,7 @@ Test cases
773773
will be *msg* if given, otherwise it will be :const:`None`.
774774

775775
.. deprecated:: 3.1
776-
:meth:`failUnless`; use one of the ``assert`` variants.
777-
:meth:`assert_`; use :meth:`assertTrue`.
776+
:meth:`failUnless` and :meth:`assert_`; use :meth:`assertTrue`.
778777

779778

780779
.. method:: assertEqual(first, second, msg=None)

Doc/reference/datamodel.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,46 @@ the new type and it saves the ordered dictionary keys in an attribute
15871587
called *members*.
15881588

15891589

1590+
Customizing instance and subclass checks
1591+
----------------------------------------
1592+
1593+
The following methods are used to override the default behavior of the
1594+
:func:`isinstance` and :func:`issubclass` built-in functions.
1595+
1596+
In particular, the metaclass :class:`abc.ABCMeta` implements these methods in
1597+
order to allow the addition of Abstract Base Classes (ABCs) as "virtual base
1598+
classes" to any class or type (including built-in types), and including to other
1599+
ABCs.
1600+
1601+
.. method:: class.__instancecheck__(self, instance)
1602+
1603+
Return true if *instance* should be considered a (direct or indirect)
1604+
instance of *class*. If defined, called to implement ``isinstance(instance,
1605+
class)``.
1606+
1607+
1608+
.. method:: class.__subclasscheck__(self, subclass)
1609+
1610+
Return true if *subclass* should be considered a (direct or indirect)
1611+
subclass of *class*. If defined, called to implement ``issubclass(subclass,
1612+
class)``.
1613+
1614+
1615+
Note that these methods are looked up on the type (metaclass) of a class. They
1616+
cannot be defined as class methods in the actual class. This is consistent with
1617+
the lookup of special methods that are called on instances, only that in this
1618+
case the instance is itself a class.
1619+
1620+
.. seealso::
1621+
1622+
:pep:`3119` - Introducing Abstract Base Classes
1623+
Includes the specification for customizing :func:`isinstance` and
1624+
:func:`issubclass` behavior through :meth:`__instancecheck__` and
1625+
:meth:`__subclasscheck__`, with motivation for this functionality in the
1626+
context of adding Abstract Base Classes (see the :mod:`abc` module) to the
1627+
language.
1628+
1629+
15901630
.. _callable-types:
15911631

15921632
Emulating callable objects

Lib/pipes.py

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

250250
# Reliably quote a string as a single argument for /bin/sh
251251

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

255255
def quote(file):
256-
''' return a shell-escaped version of the file string '''
256+
"""Return a shell-escaped version of the file string."""
257257
for c in file:
258258
if c not in _safechars:
259259
break
260260
else:
261261
if not file:
262262
return "''"
263263
return file
264-
if '\'' not in file:
265-
return '\'' + file + '\''
266-
res = ''
267-
for c in file:
268-
if c in _funnychars:
269-
c = '\\' + c
270-
res = res + c
271-
return '"' + res + '"'
264+
# use single quotes, and put single quotes into double quotes
265+
# the string $'b is then quoted as '$'"'"'b'
266+
return "'" + file.replace("'", "'\"'\"'") + "'"

0 commit comments

Comments
 (0)