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

Skip to content

Commit 587c2bf

Browse files
committed
Merged revisions 60053-60078 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r60054 | christian.heimes | 2008-01-18 20:12:56 +0100 (Fri, 18 Jan 2008) | 1 line Silence Coverity false alerts with CIDs #172, #183, #184 ........ r60057 | guido.van.rossum | 2008-01-18 21:56:30 +0100 (Fri, 18 Jan 2008) | 3 lines Fix an edge case whereby the __del__() method of a classic class could create a new weakref to the object. ........ r60058 | raymond.hettinger | 2008-01-18 22:14:58 +0100 (Fri, 18 Jan 2008) | 1 line Better variable name in an example. ........ r60063 | guido.van.rossum | 2008-01-19 00:05:40 +0100 (Sat, 19 Jan 2008) | 3 lines This got fixed for classic classes in r60057, and backported to 2.5.2 in 60056. ........ r60068 | jeffrey.yasskin | 2008-01-19 10:56:06 +0100 (Sat, 19 Jan 2008) | 4 lines Several tweaks: add construction from strings and .from_decimal(), change __init__ to __new__ to enforce immutability, and remove "rational." from repr and the parens from str. ........ r60069 | georg.brandl | 2008-01-19 11:11:27 +0100 (Sat, 19 Jan 2008) | 2 lines Fix markup. ........ r60070 | georg.brandl | 2008-01-19 11:16:09 +0100 (Sat, 19 Jan 2008) | 3 lines Amend curses docs by info how to write non-ascii characters. Thanks to Jeroen Ruigrok van der Werven. ........ r60071 | georg.brandl | 2008-01-19 11:18:07 +0100 (Sat, 19 Jan 2008) | 2 lines Indentation normalization. ........ r60073 | facundo.batista | 2008-01-19 13:32:27 +0100 (Sat, 19 Jan 2008) | 5 lines Fix issue #1822: MIMEMultipart.is_multipart() behaves correctly for a just-created (and empty) instance. Added tests for this. Thanks Jonathan Share. ........ r60074 | andrew.kuchling | 2008-01-19 14:33:20 +0100 (Sat, 19 Jan 2008) | 1 line Polish sentence ........ r60075 | christian.heimes | 2008-01-19 14:46:06 +0100 (Sat, 19 Jan 2008) | 1 line Added unit test to verify that threading.local doesn't cause ref leaks. It seems that the thread local storage always keeps the storage of the last stopped thread alive. Can anybody comment on it, please? ........ r60076 | christian.heimes | 2008-01-19 16:06:09 +0100 (Sat, 19 Jan 2008) | 1 line Update for threading.local test. ........ r60077 | andrew.kuchling | 2008-01-19 16:16:37 +0100 (Sat, 19 Jan 2008) | 1 line Polish sentence ........ r60078 | georg.brandl | 2008-01-19 16:22:16 +0100 (Sat, 19 Jan 2008) | 2 lines Fix typos. ........
1 parent bd84a58 commit 587c2bf

14 files changed

Lines changed: 312 additions & 139 deletions

File tree

Doc/c-api/concrete.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ These are the UTF-8 codec APIs:
12591259

12601260
.. cfunction:: PyObject* PyUnicode_AsUTF8String(PyObject *unicode)
12611261

1262-
Encode a Unicode objects using UTF-8 and return the result as Python string
1262+
Encode a Unicode object using UTF-8 and return the result as Python string
12631263
object. Error handling is "strict". Return *NULL* if an exception was raised
12641264
by the codec.
12651265

@@ -1411,7 +1411,7 @@ These are the "Unicode Escape" codec APIs:
14111411

14121412
.. cfunction:: PyObject* PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
14131413

1414-
Encode a Unicode objects using Unicode-Escape and return the result as Python
1414+
Encode a Unicode object using Unicode-Escape and return the result as Python
14151415
string object. Error handling is "strict". Return *NULL* if an exception was
14161416
raised by the codec.
14171417

@@ -1435,7 +1435,7 @@ These are the "Raw Unicode Escape" codec APIs:
14351435

14361436
.. cfunction:: PyObject* PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
14371437

1438-
Encode a Unicode objects using Raw-Unicode-Escape and return the result as
1438+
Encode a Unicode object using Raw-Unicode-Escape and return the result as
14391439
Python string object. Error handling is "strict". Return *NULL* if an exception
14401440
was raised by the codec.
14411441

@@ -1459,7 +1459,7 @@ ordinals and only these are accepted by the codecs during encoding.
14591459

14601460
.. cfunction:: PyObject* PyUnicode_AsLatin1String(PyObject *unicode)
14611461

1462-
Encode a Unicode objects using Latin-1 and return the result as Python string
1462+
Encode a Unicode object using Latin-1 and return the result as Python string
14631463
object. Error handling is "strict". Return *NULL* if an exception was raised
14641464
by the codec.
14651465

@@ -1483,7 +1483,7 @@ codes generate errors.
14831483

14841484
.. cfunction:: PyObject* PyUnicode_AsASCIIString(PyObject *unicode)
14851485

1486-
Encode a Unicode objects using ASCII and return the result as Python string
1486+
Encode a Unicode object using ASCII and return the result as Python string
14871487
object. Error handling is "strict". Return *NULL* if an exception was raised
14881488
by the codec.
14891489

@@ -1532,7 +1532,7 @@ characters to different code points.
15321532

15331533
.. cfunction:: PyObject* PyUnicode_AsCharmapString(PyObject *unicode, PyObject *mapping)
15341534

1535-
Encode a Unicode objects using the given *mapping* object and return the result
1535+
Encode a Unicode object using the given *mapping* object and return the result
15361536
as Python string object. Error handling is "strict". Return *NULL* if an
15371537
exception was raised by the codec.
15381538

@@ -1582,7 +1582,7 @@ the user settings on the machine running the codec.
15821582

15831583
.. cfunction:: PyObject* PyUnicode_AsMBCSString(PyObject *unicode)
15841584

1585-
Encode a Unicode objects using MBCS and return the result as Python string
1585+
Encode a Unicode object using MBCS and return the result as Python string
15861586
object. Error handling is "strict". Return *NULL* if an exception was raised
15871587
by the codec.
15881588

Doc/c-api/utilities.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ Importing Modules
201201
.. cfunction:: PyObject* PyImport_ImportModuleNoBlock(const char *name)
202202

203203
This version of :cfunc:`PyImport_ImportModule` does not block. It's intended
204-
to be used in C function which import other modules to execute a function.
204+
to be used in C functions that import other modules to execute a function.
205205
The import may block if another thread holds the import lock. The function
206-
:cfunc:`PyImport_ImportModuleNoBlock` doesn't block. It first tries to fetch
206+
:cfunc:`PyImport_ImportModuleNoBlock` never blocks. It first tries to fetch
207207
the module from sys.modules and falls back to :cfunc:`PyImport_ImportModule`
208-
unless the the lock is hold. In the latter case the function raises an
209-
ImportError.
208+
unless the lock is held, in which case the function will raise an
209+
:exc:`ImportError`.
210210

211211

212212
.. cfunction:: PyObject* PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist)

Doc/library/collections.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,8 @@ Default values can be implemented by using :meth:`_replace` to
579579
customize a prototype instance::
580580

581581
>>> Account = namedtuple('Account', 'owner balance transaction_count')
582-
>>> model_account = Account('<owner name>', 0.0, 0)
583-
>>> johns_account = model_account._replace(owner='John')
582+
>>> default_account = Account('<owner name>', 0.0, 0)
583+
>>> johns_account = default_account._replace(owner='John')
584584

585585
.. rubric:: Footnotes
586586

Doc/library/curses.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ for DOS, OS/2, and possibly other systems as well. This extension module is
1616
designed to match the API of ncurses, an open-source curses library hosted on
1717
Linux and the BSD variants of Unix.
1818

19+
.. note::
20+
21+
Since version 5.4, the ncurses library decides how to interpret non-ASCII data
22+
using the ``nl_langinfo`` function. That means that you have to call
23+
:func:`locale.setlocale` in the application and encode Unicode strings
24+
using one of the system's available encodings. This example uses the
25+
system's default encoding::
26+
27+
import locale
28+
locale.setlocale(locale.LC_ALL, '')
29+
code = locale.getpreferredencoding()
30+
31+
Then use *code* as the encoding for :meth:`str.encode` calls.
1932

2033
.. seealso::
2134

Doc/library/logging.rst

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,65 +1179,65 @@ to do what you need. Here's an example script which uses this class, which
11791179
also illustrates what dict-like behaviour is needed from an arbitrary
11801180
"dict-like" object for use in the constructor::
11811181

1182-
import logging
1183-
1184-
class ConnInfo:
1185-
"""
1186-
An example class which shows how an arbitrary class can be used as
1187-
the 'extra' context information repository passed to a LoggerAdapter.
1188-
"""
1189-
1190-
def __getitem__(self, name):
1191-
"""
1192-
To allow this instance to look like a dict.
1193-
"""
1194-
from random import choice
1195-
if name == "ip":
1196-
result = choice(["127.0.0.1", "192.168.0.1"])
1197-
elif name == "user":
1198-
result = choice(["jim", "fred", "sheila"])
1199-
else:
1200-
result = self.__dict__.get(name, "?")
1201-
return result
1202-
1203-
def __iter__(self):
1204-
"""
1205-
To allow iteration over keys, which will be merged into
1206-
the LogRecord dict before formatting and output.
1207-
"""
1208-
keys = ["ip", "user"]
1209-
keys.extend(self.__dict__.keys())
1210-
return keys.__iter__()
1211-
1212-
if __name__ == "__main__":
1213-
from random import choice
1214-
levels = (logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL)
1215-
a1 = logging.LoggerAdapter(logging.getLogger("a.b.c"),
1216-
{ "ip" : "123.231.231.123", "user" : "sheila" })
1217-
logging.basicConfig(level=logging.DEBUG,
1218-
format="%(asctime)-15s %(name)-5s %(levelname)-8s IP: %(ip)-15s User: %(user)-8s %(message)s")
1219-
a1.debug("A debug message")
1220-
a1.info("An info message with %s", "some parameters")
1221-
a2 = logging.LoggerAdapter(logging.getLogger("d.e.f"), ConnInfo())
1222-
for x in range(10):
1223-
lvl = choice(levels)
1224-
lvlname = logging.getLevelName(lvl)
1225-
a2.log(lvl, "A message at %s level with %d %s", lvlname, 2, "parameters")
1182+
import logging
1183+
1184+
class ConnInfo:
1185+
"""
1186+
An example class which shows how an arbitrary class can be used as
1187+
the 'extra' context information repository passed to a LoggerAdapter.
1188+
"""
1189+
1190+
def __getitem__(self, name):
1191+
"""
1192+
To allow this instance to look like a dict.
1193+
"""
1194+
from random import choice
1195+
if name == "ip":
1196+
result = choice(["127.0.0.1", "192.168.0.1"])
1197+
elif name == "user":
1198+
result = choice(["jim", "fred", "sheila"])
1199+
else:
1200+
result = self.__dict__.get(name, "?")
1201+
return result
1202+
1203+
def __iter__(self):
1204+
"""
1205+
To allow iteration over keys, which will be merged into
1206+
the LogRecord dict before formatting and output.
1207+
"""
1208+
keys = ["ip", "user"]
1209+
keys.extend(self.__dict__.keys())
1210+
return keys.__iter__()
1211+
1212+
if __name__ == "__main__":
1213+
from random import choice
1214+
levels = (logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL)
1215+
a1 = logging.LoggerAdapter(logging.getLogger("a.b.c"),
1216+
{ "ip" : "123.231.231.123", "user" : "sheila" })
1217+
logging.basicConfig(level=logging.DEBUG,
1218+
format="%(asctime)-15s %(name)-5s %(levelname)-8s IP: %(ip)-15s User: %(user)-8s %(message)s")
1219+
a1.debug("A debug message")
1220+
a1.info("An info message with %s", "some parameters")
1221+
a2 = logging.LoggerAdapter(logging.getLogger("d.e.f"), ConnInfo())
1222+
for x in range(10):
1223+
lvl = choice(levels)
1224+
lvlname = logging.getLevelName(lvl)
1225+
a2.log(lvl, "A message at %s level with %d %s", lvlname, 2, "parameters")
12261226

12271227
When this script is run, the output should look something like this::
12281228

1229-
2008-01-18 14:49:54,023 a.b.c DEBUG IP: 123.231.231.123 User: sheila A debug message
1230-
2008-01-18 14:49:54,023 a.b.c INFO IP: 123.231.231.123 User: sheila An info message with some parameters
1231-
2008-01-18 14:49:54,023 d.e.f CRITICAL IP: 192.168.0.1 User: jim A message at CRITICAL level with 2 parameters
1232-
2008-01-18 14:49:54,033 d.e.f INFO IP: 192.168.0.1 User: jim A message at INFO level with 2 parameters
1233-
2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: sheila A message at WARNING level with 2 parameters
1234-
2008-01-18 14:49:54,033 d.e.f ERROR IP: 127.0.0.1 User: fred A message at ERROR level with 2 parameters
1235-
2008-01-18 14:49:54,033 d.e.f ERROR IP: 127.0.0.1 User: sheila A message at ERROR level with 2 parameters
1236-
2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: sheila A message at WARNING level with 2 parameters
1237-
2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: jim A message at WARNING level with 2 parameters
1238-
2008-01-18 14:49:54,033 d.e.f INFO IP: 192.168.0.1 User: fred A message at INFO level with 2 parameters
1239-
2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: sheila A message at WARNING level with 2 parameters
1240-
2008-01-18 14:49:54,033 d.e.f WARNING IP: 127.0.0.1 User: jim A message at WARNING level with 2 parameters
1229+
2008-01-18 14:49:54,023 a.b.c DEBUG IP: 123.231.231.123 User: sheila A debug message
1230+
2008-01-18 14:49:54,023 a.b.c INFO IP: 123.231.231.123 User: sheila An info message with some parameters
1231+
2008-01-18 14:49:54,023 d.e.f CRITICAL IP: 192.168.0.1 User: jim A message at CRITICAL level with 2 parameters
1232+
2008-01-18 14:49:54,033 d.e.f INFO IP: 192.168.0.1 User: jim A message at INFO level with 2 parameters
1233+
2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: sheila A message at WARNING level with 2 parameters
1234+
2008-01-18 14:49:54,033 d.e.f ERROR IP: 127.0.0.1 User: fred A message at ERROR level with 2 parameters
1235+
2008-01-18 14:49:54,033 d.e.f ERROR IP: 127.0.0.1 User: sheila A message at ERROR level with 2 parameters
1236+
2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: sheila A message at WARNING level with 2 parameters
1237+
2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: jim A message at WARNING level with 2 parameters
1238+
2008-01-18 14:49:54,033 d.e.f INFO IP: 192.168.0.1 User: fred A message at INFO level with 2 parameters
1239+
2008-01-18 14:49:54,033 d.e.f WARNING IP: 192.168.0.1 User: sheila A message at WARNING level with 2 parameters
1240+
2008-01-18 14:49:54,033 d.e.f WARNING IP: 127.0.0.1 User: jim A message at WARNING level with 2 parameters
12411241

12421242
.. versionadded:: 2.6
12431243

Doc/library/rational.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ Rational number class.
1515

1616
.. class:: Rational(numerator=0, denominator=1)
1717
Rational(other_rational)
18+
Rational(string)
1819

1920
The first version requires that *numerator* and *denominator* are
2021
instances of :class:`numbers.Integral` and returns a new
2122
``Rational`` representing ``numerator/denominator``. If
2223
*denominator* is :const:`0`, raises a :exc:`ZeroDivisionError`. The
2324
second version requires that *other_rational* is an instance of
2425
:class:`numbers.Rational` and returns an instance of
25-
:class:`Rational` with the same value.
26+
:class:`Rational` with the same value. The third version expects a
27+
string of the form ``[-+]?[0-9]+(/[0-9]+)?``, optionally surrounded
28+
by spaces.
2629

2730
Implements all of the methods and operations from
28-
:class:`numbers.Rational` and is hashable.
31+
:class:`numbers.Rational` and is immutable and hashable.
2932

3033

3134
.. method:: Rational.from_float(flt)
@@ -36,6 +39,13 @@ Rational number class.
3639
10)``
3740

3841

42+
.. method:: Rational.from_decimal(dec)
43+
44+
This classmethod constructs a :class:`Rational` representing the
45+
exact value of *dec*, which must be a
46+
:class:`decimal.Decimal`.
47+
48+
3949
.. method:: Rational.__floor__()
4050

4151
Returns the greatest :class:`int` ``<= self``. Will be accessible

Lib/email/mime/multipart.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ def __init__(self, _subtype='mixed', boundary=None, _subparts=None,
3434
keyword arguments (or passed into the _params argument).
3535
"""
3636
MIMEBase.__init__(self, 'multipart', _subtype, **_params)
37+
38+
# Initialise _payload to an empty list as the Message superclass's
39+
# implementation of is_multipart assumes that _payload is a list for
40+
# multipart messages.
41+
self._payload = []
42+
3743
if _subparts:
3844
for p in _subparts:
3945
self.attach(p)

Lib/email/test/test_email.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,9 @@ def test_mime_attachments_in_constructor(self):
18921892
eq(msg.get_payload(0), text1)
18931893
eq(msg.get_payload(1), text2)
18941894

1895+
def test_default_multipart_constructor(self):
1896+
msg = MIMEMultipart()
1897+
self.assertTrue(msg.is_multipart())
18951898

18961899

18971900
# A general test of parser->model->generator idempotency. IOW, read a message

0 commit comments

Comments
 (0)