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

Skip to content

Commit 4ac9ce4

Browse files
committed
Merged revisions 74779-74786,74793,74795,74811,74860-74861,74863,74876,74886,74896,74901,74903,74908,74912,74930,74933,74943,74946,74952-74955,75015,75019,75032,75068,75076,75095,75098,75102,75129,75139,75230 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r74779 | michael.foord | 2009-09-13 11:13:36 -0500 (Sun, 13 Sep 2009) | 1 line Change to tutorial wording for reading text / binary files on Windows. Issue #6301. ........ r74780 | michael.foord | 2009-09-13 11:40:02 -0500 (Sun, 13 Sep 2009) | 1 line Objects that compare equal automatically pass or fail assertAlmostEqual and assertNotAlmostEqual tests on unittest.TestCase. Issue 6567. ........ r74781 | michael.foord | 2009-09-13 11:46:19 -0500 (Sun, 13 Sep 2009) | 1 line Note that sys._getframe is not guaranteed to exist in all implementations of Python, and a corresponding note in inspect.currentframe. Issue 6712. ........ r74782 | michael.foord | 2009-09-13 12:07:46 -0500 (Sun, 13 Sep 2009) | 1 line Tutorial tweaks. Issue 6849. ........ r74783 | michael.foord | 2009-09-13 12:28:35 -0500 (Sun, 13 Sep 2009) | 1 line unittest.TestLoader.loadTestsFromName honors the loader suiteClass attribute. Issue 6866. ........ r74784 | georg.brandl | 2009-09-13 13:15:07 -0500 (Sun, 13 Sep 2009) | 1 line Typo fix. ........ r74785 | michael.foord | 2009-09-13 14:07:03 -0500 (Sun, 13 Sep 2009) | 1 line Test discovery in unittest will only attempt to import modules that are importable; i.e. their names are valid Python identifiers. If an import fails during discovery this will be recorded as an error and test discovery will continue. Issue 6568. ........ r74786 | michael.foord | 2009-09-13 14:08:18 -0500 (Sun, 13 Sep 2009) | 1 line Remove an extraneous space in unittest documentation. ........ r74793 | georg.brandl | 2009-09-14 09:50:47 -0500 (Mon, 14 Sep 2009) | 1 line #6908: fix association of hashlib hash attributes. ........ r74795 | benjamin.peterson | 2009-09-14 22:36:26 -0500 (Mon, 14 Sep 2009) | 1 line Py_SetPythonHome uses static storage #6913 ........ r74811 | georg.brandl | 2009-09-15 15:26:59 -0500 (Tue, 15 Sep 2009) | 1 line Add Armin Ronacher. ........ r74860 | benjamin.peterson | 2009-09-16 21:46:54 -0500 (Wed, 16 Sep 2009) | 1 line kill bare except ........ r74861 | benjamin.peterson | 2009-09-16 22:18:28 -0500 (Wed, 16 Sep 2009) | 1 line pep 8 defaults ........ r74863 | benjamin.peterson | 2009-09-16 22:27:33 -0500 (Wed, 16 Sep 2009) | 1 line rationalize a bit ........ r74876 | georg.brandl | 2009-09-17 11:15:53 -0500 (Thu, 17 Sep 2009) | 1 line #6932: remove paragraph that advises relying on __del__ being called. ........ r74886 | benjamin.peterson | 2009-09-17 16:33:46 -0500 (Thu, 17 Sep 2009) | 1 line use macros ........ r74896 | georg.brandl | 2009-09-18 02:22:41 -0500 (Fri, 18 Sep 2009) | 1 line #6936: for interactive use, quit() is just fine. ........ r74901 | georg.brandl | 2009-09-18 04:14:52 -0500 (Fri, 18 Sep 2009) | 1 line #6905: use better exception messages in inspect when the argument is of the wrong type. ........ r74903 | georg.brandl | 2009-09-18 04:18:27 -0500 (Fri, 18 Sep 2009) | 1 line #6938: "ident" is always a string, so use a format code which works. ........ r74908 | georg.brandl | 2009-09-18 08:57:11 -0500 (Fri, 18 Sep 2009) | 1 line Use str.format() to fix beginner's mistake with %-style string formatting. ........ r74912 | georg.brandl | 2009-09-18 11:19:56 -0500 (Fri, 18 Sep 2009) | 1 line Optimize optimization and fix method name in docstring. ........ r74930 | georg.brandl | 2009-09-18 16:21:41 -0500 (Fri, 18 Sep 2009) | 1 line #6925: rewrite docs for locals() and vars() a bit. ........ r74933 | georg.brandl | 2009-09-18 16:35:59 -0500 (Fri, 18 Sep 2009) | 1 line #6930: clarify description about byteorder handling in UTF decoder routines. ........ r74943 | georg.brandl | 2009-09-19 02:35:07 -0500 (Sat, 19 Sep 2009) | 1 line #6944: the argument to PyArg_ParseTuple should be a tuple, otherwise a SystemError is set. Also clean up another usage of PyArg_ParseTuple. ........ r74946 | georg.brandl | 2009-09-19 03:43:16 -0500 (Sat, 19 Sep 2009) | 1 line Update bug tracker reference. ........ r74952 | georg.brandl | 2009-09-19 05:42:34 -0500 (Sat, 19 Sep 2009) | 1 line #6946: fix duplicate index entries for datetime classes. ........ r74953 | georg.brandl | 2009-09-19 07:04:16 -0500 (Sat, 19 Sep 2009) | 1 line Fix references to threading.enumerate(). ........ r74954 | georg.brandl | 2009-09-19 08:13:56 -0500 (Sat, 19 Sep 2009) | 1 line Add Doug. ........ r74955 | georg.brandl | 2009-09-19 08:20:49 -0500 (Sat, 19 Sep 2009) | 1 line Add Mark Summerfield. ........ r75015 | georg.brandl | 2009-09-22 05:55:08 -0500 (Tue, 22 Sep 2009) | 1 line Fix encoding name. ........ r75019 | vinay.sajip | 2009-09-22 12:23:41 -0500 (Tue, 22 Sep 2009) | 1 line Fixed a typo, and added sections on optimization and using arbitrary objects as messages. ........ r75032 | benjamin.peterson | 2009-09-22 17:15:28 -0500 (Tue, 22 Sep 2009) | 1 line fix typos/rephrase ........ r75068 | benjamin.peterson | 2009-09-25 21:57:59 -0500 (Fri, 25 Sep 2009) | 1 line comment out ugly xxx ........ r75076 | vinay.sajip | 2009-09-26 09:53:32 -0500 (Sat, 26 Sep 2009) | 1 line Tidied up name of parameter in StreamHandler ........ r75095 | michael.foord | 2009-09-27 14:15:41 -0500 (Sun, 27 Sep 2009) | 1 line Test creation moved from TestProgram.parseArgs to TestProgram.createTests exclusively. Issue 6956. ........ r75098 | michael.foord | 2009-09-27 15:08:23 -0500 (Sun, 27 Sep 2009) | 1 line Documentation improvement for load_tests protocol in unittest. Issue 6515. ........ r75102 | skip.montanaro | 2009-09-27 21:12:27 -0500 (Sun, 27 Sep 2009) | 3 lines Patch from Thomas Barr so that csv.Sniffer will set doublequote property. Closes issue 6606. ........ r75129 | vinay.sajip | 2009-09-29 02:08:54 -0500 (Tue, 29 Sep 2009) | 1 line Issue #7014: logging: Improved IronPython 2.6 compatibility. ........ r75139 | raymond.hettinger | 2009-09-29 13:53:24 -0500 (Tue, 29 Sep 2009) | 3 lines Issue 7008: Better document str.title and show how to work around the apostrophe problem. ........ r75230 | benjamin.peterson | 2009-10-04 08:38:38 -0500 (Sun, 04 Oct 2009) | 1 line test logging ........
1 parent bd27aef commit 4ac9ce4

35 files changed

Lines changed: 391 additions & 164 deletions

Doc/c-api/init.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ Initialization, Finalization, and Threads
371371
Set the default "home" directory, that is, the location of the standard
372372
Python libraries. The libraries are searched in
373373
:file:`{home}/lib/python{version}` and :file:`{home}/lib/python{version}`.
374+
The argument should point to a zero-terminated character string in static
375+
storage whose contents will not change for the duration of the program's
376+
execution. No code in the Python interpreter will change the contents of
377+
this storage.
374378

375379

376380
.. cfunction:: w_char* Py_GetPythonHome()

Doc/c-api/unicode.rst

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,13 @@ These are the UTF-32 codec APIs:
476476
*byteorder == 0: native order
477477
*byteorder == 1: big endian
478478

479-
and then switches if the first four bytes of the input data are a byte order mark
480-
(BOM) and the specified byte order is native order. This BOM is not copied into
481-
the resulting Unicode string. After completion, *\*byteorder* is set to the
482-
current byte order at the end of input data.
479+
If ``*byteorder`` is zero, and the first four bytes of the input data are a
480+
byte order mark (BOM), the decoder switches to this byte order and the BOM is
481+
not copied into the resulting Unicode string. If ``*byteorder`` is ``-1`` or
482+
``1``, any byte order mark is copied to the output.
483+
484+
After completion, *\*byteorder* is set to the current byte order at the end
485+
of input data.
483486

484487
In a narrow build codepoints outside the BMP will be decoded as surrogate pairs.
485488

@@ -500,8 +503,7 @@ These are the UTF-32 codec APIs:
500503
.. cfunction:: PyObject* PyUnicode_EncodeUTF32(const Py_UNICODE *s, Py_ssize_t size, const char *errors, int byteorder)
501504

502505
Return a Python bytes object holding the UTF-32 encoded value of the Unicode
503-
data in *s*. If *byteorder* is not ``0``, output is written according to the
504-
following byte order::
506+
data in *s*. Output is written according to the following byte order::
505507

506508
byteorder == -1: little endian
507509
byteorder == 0: native byte order (writes a BOM mark)
@@ -541,10 +543,14 @@ These are the UTF-16 codec APIs:
541543
*byteorder == 0: native order
542544
*byteorder == 1: big endian
543545

544-
and then switches if the first two bytes of the input data are a byte order mark
545-
(BOM) and the specified byte order is native order. This BOM is not copied into
546-
the resulting Unicode string. After completion, *\*byteorder* is set to the
547-
current byte order at the end of input data.
546+
If ``*byteorder`` is zero, and the first two bytes of the input data are a
547+
byte order mark (BOM), the decoder switches to this byte order and the BOM is
548+
not copied into the resulting Unicode string. If ``*byteorder`` is ``-1`` or
549+
``1``, any byte order mark is copied to the output (where it will result in
550+
either a ``\ufeff`` or a ``\ufffe`` character).
551+
552+
After completion, *\*byteorder* is set to the current byte order at the end
553+
of input data.
548554

549555
If *byteorder* is *NULL*, the codec starts in native order mode.
550556

@@ -563,8 +569,7 @@ These are the UTF-16 codec APIs:
563569
.. cfunction:: PyObject* PyUnicode_EncodeUTF16(const Py_UNICODE *s, Py_ssize_t size, const char *errors, int byteorder)
564570

565571
Return a Python bytes object holding the UTF-16 encoded value of the Unicode
566-
data in *s*. If *byteorder* is not ``0``, output is written according to the
567-
following byte order::
572+
data in *s*. Output is written according to the following byte order::
568573

569574
byteorder == -1: little endian
570575
byteorder == 0: native byte order (writes a BOM mark)

Doc/documenting/markup.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,10 @@ units as well as normal text:
597597
An important bit of information about an API that a user should be aware of
598598
when using whatever bit of API the warning pertains to. The content of the
599599
directive should be written in complete sentences and include all appropriate
600-
punctuation. This should only be chosen over ``note`` for information
601-
regarding the possibility of crashes, data loss, or security implications.
600+
punctuation. In the interest of not scaring users away from pages filled
601+
with warnings, this directive should only be chosen over ``note`` for
602+
information regarding the possibility of crashes, data loss, or security
603+
implications.
602604

603605
.. describe:: versionadded
604606

Doc/library/codecs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ particular, the following variants typically exist:
988988
+-----------------+--------------------------------+--------------------------------+
989989
| cp1255 | windows-1255 | Hebrew |
990990
+-----------------+--------------------------------+--------------------------------+
991-
| cp1256 | windows1256 | Arabic |
991+
| cp1256 | windows-1256 | Arabic |
992992
+-----------------+--------------------------------+--------------------------------+
993993
| cp1257 | windows-1257 | Baltic languages |
994994
+-----------------+--------------------------------+--------------------------------+

Doc/library/datetime.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ Available Types
6363

6464

6565
.. class:: date
66+
:noindex:
6667

6768
An idealized naive date, assuming the current Gregorian calendar always was, and
6869
always will be, in effect. Attributes: :attr:`year`, :attr:`month`, and
6970
:attr:`day`.
7071

7172

7273
.. class:: time
74+
:noindex:
7375

7476
An idealized time, independent of any particular day, assuming that every day
7577
has exactly 24\*60\*60 seconds (there is no notion of "leap seconds" here).
@@ -78,13 +80,15 @@ Available Types
7880

7981

8082
.. class:: datetime
83+
:noindex:
8184

8285
A combination of a date and a time. Attributes: :attr:`year`, :attr:`month`,
8386
:attr:`day`, :attr:`hour`, :attr:`minute`, :attr:`second`, :attr:`microsecond`,
8487
and :attr:`tzinfo`.
8588

8689

8790
.. class:: timedelta
91+
:noindex:
8892

8993
A duration expressing the difference between two :class:`date`, :class:`time`,
9094
or :class:`datetime` instances to microsecond resolution.

Doc/library/functions.rst

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -600,16 +600,12 @@ are always available. They are listed here in alphabetical order.
600600
.. function:: locals()
601601

602602
Update and return a dictionary representing the current local symbol table.
603+
Free variables are returned by :func:`locals` when it is called in function
604+
blocks, but not in class blocks.
603605

604606
.. note::
605-
606607
The contents of this dictionary should not be modified; changes may not
607-
affect the values of local variables used by the interpreter.
608-
609-
Free variables are returned by :func:`locals` when it is called in a function
610-
block. Modifications of free variables may not affect the values used by the
611-
interpreter. Free variables are not returned in class blocks.
612-
608+
affect the values of local and free variables used by the interpreter.
613609

614610
.. function:: map(function, iterable, ...)
615611

@@ -1176,10 +1172,10 @@ are always available. They are listed here in alphabetical order.
11761172

11771173
.. function:: vars([object])
11781174

1179-
Without arguments, return a dictionary corresponding to the current local symbol
1180-
table. With a module, class or class instance object as argument (or anything
1181-
else that has a :attr:`__dict__` attribute), returns a dictionary corresponding
1182-
to the object's symbol table.
1175+
Without an argument, act like :func:`locals`.
1176+
1177+
With a module, class or class instance object as argument (or anything else that
1178+
has a :attr:`__dict__` attribute), return that attribute.
11831179

11841180
.. note::
11851181
The returned dictionary should not be modified:

Doc/library/hashlib.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ The following values are provided as constant attributes of the hash objects
8686
returned by the constructors:
8787

8888

89-
.. data:: digest_size
89+
.. data:: hash.digest_size
9090

9191
The size of the resulting hash in bytes.
9292

93-
.. data:: block_size
93+
.. data:: hash.block_size
9494

9595
The internal block size of the hash algorithm in bytes.
9696

Doc/library/inspect.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,11 @@ line.
508508

509509
Return the frame object for the caller's stack frame.
510510

511+
This function relies on Python stack frame support in the interpreter, which
512+
isn't guaranteed to exist in all implementations of Python. If running in
513+
an implementation without Python stack frame support this function returns
514+
``None``.
515+
511516

512517
.. function:: stack(context=1)
513518

Doc/library/logging.rst

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ default handler so that debug messages are written to a file::
5757

5858
import logging
5959
LOG_FILENAME = '/tmp/logging_example.out'
60-
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,)
60+
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
6161

6262
logging.debug('This message should go to the log file')
6363

@@ -1493,6 +1493,55 @@ printed on the console; on the server side, you should see something like::
14931493
69 myapp.area2 WARNING Jail zesty vixen who grabbed pay from quack.
14941494
69 myapp.area2 ERROR The five boxing wizards jump quickly.
14951495

1496+
Using arbitrary objects as messages
1497+
-----------------------------------
1498+
1499+
In the preceding sections and examples, it has been assumed that the message
1500+
passed when logging the event is a string. However, this is not the only
1501+
possibility. You can pass an arbitrary object as a message, and its
1502+
:meth:`__str__` method will be called when the logging system needs to convert
1503+
it to a string representation. In fact, if you want to, you can avoid
1504+
computing a string representation altogether - for example, the
1505+
:class:`SocketHandler` emits an event by pickling it and sending it over the
1506+
wire.
1507+
1508+
Optimization
1509+
------------
1510+
1511+
Formatting of message arguments is deferred until it cannot be avoided.
1512+
However, computing the arguments passed to the logging method can also be
1513+
expensive, and you may want to avoid doing it if the logger will just throw
1514+
away your event. To decide what to do, you can call the :meth:`isEnabledFor`
1515+
method which takes a level argument and returns true if the event would be
1516+
created by the Logger for that level of call. You can write code like this::
1517+
1518+
if logger.isEnabledFor(logging.DEBUG):
1519+
logger.debug("Message with %s, %s", expensive_func1(),
1520+
expensive_func2())
1521+
1522+
so that if the logger's threshold is set above ``DEBUG``, the calls to
1523+
:func:`expensive_func1` and :func:`expensive_func2` are never made.
1524+
1525+
There are other optimizations which can be made for specific applications which
1526+
need more precise control over what logging information is collected. Here's a
1527+
list of things you can do to avoid processing during logging which you don't
1528+
need:
1529+
1530+
+-----------------------------------------------+----------------------------------------+
1531+
| What you don't want to collect | How to avoid collecting it |
1532+
+===============================================+========================================+
1533+
| Information about where calls were made from. | Set ``logging._srcfile`` to ``None``. |
1534+
+-----------------------------------------------+----------------------------------------+
1535+
| Threading information. | Set ``logging.logThreads`` to ``0``. |
1536+
+-----------------------------------------------+----------------------------------------+
1537+
| Process information. | Set ``logging.logProcesses`` to ``0``. |
1538+
+-----------------------------------------------+----------------------------------------+
1539+
1540+
Also note that the core logging module only includes the basic handlers. If
1541+
you don't import :mod:`logging.handlers` and :mod:`logging.config`, they won't
1542+
take up any memory.
1543+
1544+
.. _handler:
14961545

14971546
Handler Objects
14981547
---------------
@@ -1608,9 +1657,9 @@ file-like object (or, more precisely, any object which supports :meth:`write`
16081657
and :meth:`flush` methods).
16091658

16101659

1611-
.. class:: StreamHandler(strm=None)
1660+
.. class:: StreamHandler(stream=None)
16121661

1613-
Returns a new instance of the :class:`StreamHandler` class. If *strm* is
1662+
Returns a new instance of the :class:`StreamHandler` class. If *stream* is
16141663
specified, the instance will use it for logging output; otherwise, *sys.stderr*
16151664
will be used.
16161665

Doc/library/shelve.rst

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,39 @@ lots of shared sub-objects. The keys are ordinary strings.
2727

2828
Because of Python semantics, a shelf cannot know when a mutable
2929
persistent-dictionary entry is modified. By default modified objects are
30-
written only when assigned to the shelf (see :ref:`shelve-example`). If
31-
the optional *writeback* parameter is set to *True*, all entries accessed
32-
are cached in memory, and written back at close time; this can make it
33-
handier to mutate mutable entries in the persistent dictionary, but, if
34-
many entries are accessed, it can consume vast amounts of memory for the
35-
cache, and it can make the close operation very slow since all accessed
36-
entries are written back (there is no way to determine which accessed
37-
entries are mutable, nor which ones were actually mutated).
30+
written only when assigned to the shelf (see :ref:`shelve-example`). If the
31+
optional *writeback* parameter is set to *True*, all entries accessed are
32+
cached in memory, and written back on :meth:`sync` and :meth:`close`; this
33+
can make it handier to mutate mutable entries in the persistent dictionary,
34+
but, if many entries are accessed, it can consume vast amounts of memory for
35+
the cache, and it can make the close operation very slow since all accessed
36+
entries are written back (there is no way to determine which accessed entries
37+
are mutable, nor which ones were actually mutated).
38+
39+
.. note::
40+
41+
Do not rely on the shelf being closed automatically; always call
42+
:meth:`close` explicitly when you don't need it any more, or use a
43+
:keyword:`with` statement with :func:`contextlib.closing`.
44+
3845

3946
Shelf objects support all methods supported by dictionaries. This eases the
4047
transition from dictionary based scripts to those requiring persistent storage.
4148

42-
One additional method is supported:
43-
49+
Two additional methods are supported:
4450

4551
.. method:: Shelf.sync()
4652

47-
Write back all entries in the cache if the shelf was opened with *writeback* set
48-
to *True*. Also empty the cache and synchronize the persistent dictionary on
49-
disk, if feasible. This is called automatically when the shelf is closed with
50-
:meth:`close`.
53+
Write back all entries in the cache if the shelf was opened with *writeback*
54+
set to :const:`True`. Also empty the cache and synchronize the persistent
55+
dictionary on disk, if feasible. This is called automatically when the shelf
56+
is closed with :meth:`close`.
57+
58+
.. method:: Shelf.close()
59+
60+
Synchronize and close the persistent *dict* object. Operations on a closed
61+
shelf will fail with a :exc:`ValueError`.
62+
5163

5264
.. seealso::
5365

@@ -71,11 +83,6 @@ Restrictions
7183
database should be fairly small, and in rare cases key collisions may cause
7284
the database to refuse updates.
7385

74-
* Depending on the implementation, closing a persistent dictionary may or may
75-
not be necessary to flush changes to disk. The :meth:`__del__` method of the
76-
:class:`Shelf` class calls the :meth:`close` method, so the programmer generally
77-
need not do this explicitly.
78-
7986
* The :mod:`shelve` module does not support *concurrent* read/write access to
8087
shelved objects. (Multiple simultaneous read accesses are safe.) When a
8188
program has a shelf open for writing, no other program should have it open for

0 commit comments

Comments
 (0)