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

Skip to content

Commit a62da1d

Browse files
committed
Merged revisions 59921-59932 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r59923 | raymond.hettinger | 2008-01-11 19:04:55 +0100 (Fri, 11 Jan 2008) | 1 line Speed-up and simplify code urlparse's result objects. ........ r59924 | andrew.kuchling | 2008-01-11 20:33:24 +0100 (Fri, 11 Jan 2008) | 1 line Bug python#1790: update link; remove outdated paragraph ........ r59925 | thomas.heller | 2008-01-11 20:34:06 +0100 (Fri, 11 Jan 2008) | 5 lines Raise an error instead of crashing with a segfault when a NULL function pointer is called. Will backport to release25-maint. ........ r59927 | thomas.heller | 2008-01-11 21:29:19 +0100 (Fri, 11 Jan 2008) | 4 lines Fix a potential 'SystemError: NULL result without error'. NULL may be a valid return value from PyLong_AsVoidPtr. Will backport to release25-maint. ........ r59928 | raymond.hettinger | 2008-01-12 00:25:18 +0100 (Sat, 12 Jan 2008) | 1 line Update the opcode docs for STORE_MAP and BUILD_MAP ........ r59929 | mark.dickinson | 2008-01-12 02:56:00 +0100 (Sat, 12 Jan 2008) | 4 lines Issue 1780: Allow leading and trailing whitespace in Decimal constructor, when constructing from a string. Disallow trailing newlines in Context.create_decimal. ........ r59930 | georg.brandl | 2008-01-12 11:53:29 +0100 (Sat, 12 Jan 2008) | 3 lines Move OSError docs to exceptions doc, remove obsolete descriptions from os docs, rework posix docs. ........ r59931 | georg.brandl | 2008-01-12 14:47:57 +0100 (Sat, 12 Jan 2008) | 3 lines Patch #1700288: Method cache optimization, by Armin Rigo, ported to 2.6 by Kevin Jacobs. ........ r59932 | georg.brandl | 2008-01-12 17:11:09 +0100 (Sat, 12 Jan 2008) | 2 lines Fix editing glitch. ........
1 parent 25bb783 commit a62da1d

14 files changed

Lines changed: 318 additions & 142 deletions

File tree

Doc/library/decimal.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,10 @@ Decimal objects
276276

277277
Construct a new :class:`Decimal` object based from *value*.
278278

279-
*value* can be an integer, string, tuple, or another :class:`Decimal` object. If
280-
no *value* is given, returns ``Decimal("0")``. If *value* is a string, it
281-
should conform to the decimal numeric string syntax::
279+
*value* can be an integer, string, tuple, or another :class:`Decimal`
280+
object. If no *value* is given, returns ``Decimal("0")``. If *value* is a
281+
string, it should conform to the decimal numeric string syntax after leading
282+
and trailing whitespace characters are removed::
282283

283284
sign ::= '+' | '-'
284285
digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
@@ -308,6 +309,10 @@ Decimal objects
308309

309310
Once constructed, :class:`Decimal` objects are immutable.
310311

312+
.. versionchanged:: 2.6
313+
leading and trailing whitespace characters are permitted when
314+
creating a Decimal instance from a string.
315+
311316
Decimal floating point objects share many properties with the other built-in
312317
numeric types such as :class:`float` and :class:`int`. All of the usual math
313318
operations and special methods apply. Likewise, decimal objects can be copied,
@@ -925,6 +930,9 @@ method. For example, ``C.exp(x)`` is equivalent to
925930
>>> Decimal("3.4445") + Decimal(0) + Decimal("1.0023")
926931
Decimal("4.44")
927932

933+
This method implements the to-number operation of the IBM
934+
specification. If the argument is a string, no leading or trailing
935+
whitespace is permitted.
928936

929937
.. method:: Context.Etiny()
930938

Doc/library/dis.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,10 @@ the more significant byte last.
506506
Works as ``BUILD_TUPLE``, but creates a set.
507507

508508

509-
.. opcode:: BUILD_MAP (zero)
509+
.. opcode:: BUILD_MAP (count)
510510

511-
Pushes a new empty dictionary object onto the stack. The argument is ignored
512-
and set to zero by the compiler.
511+
Pushes a new dictionary object onto the stack. The dictionary is pre-sized
512+
to hold *count* entries.
513513

514514

515515
.. opcode:: LOAD_ATTR (namei)
@@ -589,6 +589,10 @@ the more significant byte last.
589589
Pushes a try block from a try-except clause onto the block stack. *delta* points
590590
to the finally block.
591591

592+
.. opcode:: STORE_MAP ()
593+
594+
Store a key and value pair in a dictionary. Pops the key and value while leaving
595+
the dictionary on the stack.
592596

593597
.. opcode:: LOAD_FAST (var_num)
594598

Doc/library/exceptions.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,19 @@ The following exceptions are the exceptions that are actually raised.
207207

208208
.. exception:: OSError
209209

210-
This class is derived from :exc:`EnvironmentError` and is used primarily as the
211-
:mod:`os` module's ``os.error`` exception. See :exc:`EnvironmentError` above for
212-
a description of the possible associated values.
210+
.. index:: module: errno
211+
212+
This exception is derived from :exc:`EnvironmentError`. It is raised when a
213+
function returns a system-related error (not for illegal argument types or
214+
other incidental errors). The :attr:`errno` attribute is a numeric error
215+
code from :cdata:`errno`, and the :attr:`strerror` attribute is the
216+
corresponding string, as would be printed by the C function :cfunc:`perror`.
217+
See the module :mod:`errno`, which contains names for the error codes defined
218+
by the underlying operating system.
219+
220+
For exceptions that involve a file system path (such as :func:`chdir` or
221+
:func:`unlink`), the exception instance will contain a third attribute,
222+
:attr:`filename`, which is the file name passed to the function.
213223

214224

215225
.. exception:: OverflowError

Doc/library/os.rst

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,36 @@
1-
21
:mod:`os` --- Miscellaneous operating system interfaces
32
=======================================================
43

54
.. module:: os
65
:synopsis: Miscellaneous operating system interfaces.
76

87

9-
This module provides a more portable way of using operating system dependent
10-
functionality than importing an operating system dependent built-in module like
11-
:mod:`posix` or :mod:`nt`. If you just want to read or write a file see
12-
:func:`open`, if you want to manipulate paths, see the :mod:`os.path`
13-
module, and if you want to read all the lines in all the files on the
14-
command line see the :mod:`fileinput` module. For creating temporary
15-
files and directories see the :mod:`tempfile` module, and for high-level
16-
file and directory handling see the :mod:`shutil` module.
17-
18-
This module searches for an operating system dependent built-in module like
19-
:mod:`mac` or :mod:`posix` and exports the same functions and data as found
20-
there. The design of all built-in operating system dependent modules of Python
21-
is such that as long as the same functionality is available, it uses the same
22-
interface; for example, the function ``os.stat(path)`` returns stat information
23-
about *path* in the same format (which happens to have originated with the POSIX
8+
This module provides a portable way of using operating system dependent
9+
functionality. If you just want to read or write a file see :func:`open`, if
10+
you want to manipulate paths, see the :mod:`os.path` module, and if you want to
11+
read all the lines in all the files on the command line see the :mod:`fileinput`
12+
module. For creating temporary files and directories see the :mod:`tempfile`
13+
module, and for high-level file and directory handling see the :mod:`shutil`
14+
module.
15+
16+
The design of all built-in operating system dependent modules of Python is such
17+
that as long as the same functionality is available, it uses the same interface;
18+
for example, the function ``os.stat(path)`` returns stat information about
19+
*path* in the same format (which happens to have originated with the POSIX
2420
interface).
2521

2622
Extensions peculiar to a particular operating system are also available through
2723
the :mod:`os` module, but using them is of course a threat to portability!
2824

29-
Note that after the first time :mod:`os` is imported, there is *no* performance
30-
penalty in using functions from :mod:`os` instead of directly from the operating
31-
system dependent built-in module, so there should be *no* reason not to use
32-
:mod:`os`!
25+
.. note::
3326

34-
The :mod:`os` module contains many functions and data values. The items below
35-
and in the following sub-sections are all available directly from the :mod:`os`
36-
module.
27+
All functions in this module raise :exc:`OSError` in the case of invalid or
28+
inaccessible file names and paths, or other arguments that have the correct
29+
type, but are not accepted by the operating system.
3730

3831
.. exception:: error
3932

40-
.. index:: module: errno
41-
42-
This exception is raised when a function returns a system-related error (not for
43-
illegal argument types or other incidental errors). This is also known as the
44-
built-in exception :exc:`OSError`. The accompanying value is a pair containing
45-
the numeric error code from :cdata:`errno` and the corresponding string, as
46-
would be printed by the C function :cfunc:`perror`. See the module
47-
:mod:`errno`, which contains names for the error codes defined by the underlying
48-
operating system.
49-
50-
When exceptions are classes, this exception carries two attributes,
51-
:attr:`errno` and :attr:`strerror`. The first holds the value of the C
52-
:cdata:`errno` variable, and the latter holds the corresponding error message
53-
from :cfunc:`strerror`. For exceptions that involve a file system path (such as
54-
:func:`chdir` or :func:`unlink`), the exception instance will contain a third
55-
attribute, :attr:`filename`, which is the file name passed to the function.
33+
An alias for the built-in :exc:`OSError` exception.
5634

5735

5836
.. data:: name
@@ -645,7 +623,6 @@ platforms. For descriptions of their availability and use, consult
645623
Files and Directories
646624
---------------------
647625

648-
649626
.. function:: access(path, mode)
650627

651628
Use the real uid/gid to test for access to *path*. Note that most operations
@@ -1760,8 +1737,8 @@ Miscellaneous System Information
17601737

17611738
.. function:: getloadavg()
17621739

1763-
Return the number of processes in the system run queue averaged over the last 1,
1764-
5, and 15 minutes or raises :exc:`OSError` if the load average was
1740+
Return the number of processes in the system run queue averaged over the last
1741+
1, 5, and 15 minutes or raises :exc:`OSError` if the load average was
17651742
unobtainable.
17661743

17671744

Doc/library/posix.rst

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
:mod:`posix` --- The most common POSIX system calls
32
===================================================
43

@@ -22,13 +21,8 @@ available through the :mod:`os` interface. Once :mod:`os` is imported, there is
2221
:mod:`os` provides some additional functionality, such as automatically calling
2322
:func:`putenv` when an entry in ``os.environ`` is changed.
2423

25-
The descriptions below are very terse; refer to the corresponding Unix manual
26-
(or POSIX documentation) entry for more information. Arguments called *path*
27-
refer to a pathname given as a string.
28-
2924
Errors are reported as exceptions; the usual exceptions are given for type
30-
errors, while errors reported by the system calls raise :exc:`error` (a synonym
31-
for the standard exception :exc:`OSError`), described below.
25+
errors, while errors reported by the system calls raise :exc:`OSError`.
3226

3327

3428
.. _posix-large-files:
@@ -42,9 +36,8 @@ Large File Support
4236

4337
.. sectionauthor:: Steve Clift <[email protected]>
4438

45-
46-
Several operating systems (including AIX, HPUX, Irix and Solaris) provide
47-
support for files that are larger than 2 Gb from a C programming model where
39+
Several operating systems (including AIX, HP-UX, Irix and Solaris) provide
40+
support for files that are larger than 2 GB from a C programming model where
4841
:ctype:`int` and :ctype:`long` are 32-bit values. This is typically accomplished
4942
by defining the relevant size and offset types as 64-bit values. Such files are
5043
sometimes referred to as :dfn:`large files`.
@@ -67,16 +60,16 @@ On large-file-capable Linux systems, this might work::
6760

6861
.. _posix-contents:
6962

70-
Module Contents
71-
---------------
72-
73-
Module :mod:`posix` defines the following data item:
63+
Notable Module Contents
64+
-----------------------
7465

66+
In addition to many functions described in the :mod:`os` module documentation,
67+
:mod:`posix` defines the following data item:
7568

7669
.. data:: environ
7770

78-
A dictionary representing the string environment at the time the interpreter was
79-
started. For example, ``environ['HOME']`` is the pathname of your home
71+
A dictionary representing the string environment at the time the interpreter
72+
was started. For example, ``environ['HOME']`` is the pathname of your home
8073
directory, equivalent to ``getenv("HOME")`` in C.
8174

8275
Modifying this dictionary does not affect the string environment passed on by
@@ -90,7 +83,3 @@ Module :mod:`posix` defines the following data item:
9083
updates the environment on modification. Note also that updating ``os.environ``
9184
will render this dictionary obsolete. Use of the :mod:`os` module version of
9285
this is recommended over direct access to the :mod:`posix` module.
93-
94-
Additional contents of this module should only be accessed via the :mod:`os`
95-
module; refer to the documentation for that module for further information.
96-

Doc/library/xmlrpclib.rst

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,11 @@ between conformable Python objects and XML on the wire.
110110
.. seealso::
111111

112112
`XML-RPC HOWTO <http://www.tldp.org/HOWTO/XML-RPC-HOWTO/index.html>`_
113-
A good description of XML operation and client software in several languages.
113+
A good description of XML-RPC operation and client software in several languages.
114114
Contains pretty much everything an XML-RPC client developer needs to know.
115115

116-
`XML-RPC Hacks page <http://xmlrpc-c.sourceforge.net/hacks.php>`_
117-
Extensions for various open-source libraries to support introspection and
118-
multicall.
116+
`XML-RPC Introspection <http://xmlrpc-c.sourceforge.net/introspection.html>`_
117+
Describes the XML-RPC protocol extension for introspection.
119118

120119

121120
.. _serverproxy-objects:
@@ -167,11 +166,6 @@ grouped under the reserved :attr:`system` member:
167166
no such string is available, an empty string is returned. The documentation
168167
string may contain HTML markup.
169168

170-
Introspection methods are currently supported by servers written in PHP, C and
171-
Microsoft .NET. Partial introspection support is included in recent updates to
172-
UserLand Frontier. Introspection support for Perl, Python and Java is available
173-
at the `XML-RPC Hacks <http://xmlrpc-c.sourceforge.net/hacks.php>`_ page.
174-
175169

176170
.. _boolean-objects:
177171

Include/object.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ typedef struct _typeobject {
374374
PyObject *tp_weaklist;
375375
destructor tp_del;
376376

377+
/* Type attribute cache version tag. Added in version 2.6 */
378+
unsigned int tp_version_tag;
379+
377380
#ifdef COUNT_ALLOCS
378381
/* these must be last and never explicitly initialized */
379382
Py_ssize_t tp_allocs;
@@ -525,6 +528,10 @@ given type object has a specified feature.
525528
#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
526529
#endif
527530

531+
/* Objects support type attribute cache */
532+
#define Py_TPFLAGS_HAVE_VERSION_TAG (1L<<18)
533+
#define Py_TPFLAGS_VALID_VERSION_TAG (1L<<19)
534+
528535
/* These flags are used to determine if a type is a subclass. */
529536
#define Py_TPFLAGS_INT_SUBCLASS (1L<<23)
530537
#define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
@@ -538,6 +545,7 @@ given type object has a specified feature.
538545

539546
#define Py_TPFLAGS_DEFAULT ( \
540547
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
548+
Py_TPFLAGS_HAVE_VERSION_TAG | \
541549
0)
542550

543551
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)

Lib/ctypes/test/test_funcptr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,11 @@ def c_string(init):
123123
self.failUnlessEqual(strtok(None, b"\n"), "c")
124124
self.failUnlessEqual(strtok(None, b"\n"), None)
125125

126+
def test_NULL_funcptr(self):
127+
tp = CFUNCTYPE(c_int)
128+
func = tp() # NULL function pointer
129+
# raise a ValueError when we try to call it
130+
self.assertRaises(ValueError, func)
131+
126132
if __name__ == '__main__':
127133
unittest.main()

Lib/decimal.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ def __new__(cls, value="0", context=None):
524524
Decimal("314")
525525
>>> Decimal(Decimal(314)) # another decimal instance
526526
Decimal("314")
527+
>>> Decimal(' 3.14 \\n') # leading and trailing whitespace okay
528+
Decimal("3.14")
527529
"""
528530

529531
# Note that the coefficient, self._int, is actually stored as
@@ -539,7 +541,7 @@ def __new__(cls, value="0", context=None):
539541
# From a string
540542
# REs insist on real strings, so we can too.
541543
if isinstance(value, str):
542-
m = _parser(value)
544+
m = _parser(value.strip())
543545
if m is None:
544546
if context is None:
545547
context = getcontext()
@@ -3542,7 +3544,16 @@ def _set_rounding(self, type):
35423544
return rounding
35433545

35443546
def create_decimal(self, num='0'):
3545-
"""Creates a new Decimal instance but using self as context."""
3547+
"""Creates a new Decimal instance but using self as context.
3548+
3549+
This method implements the to-number operation of the
3550+
IBM Decimal specification."""
3551+
3552+
if isinstance(num, str) and num != num.strip():
3553+
return self._raise_error(ConversionSyntax,
3554+
"no trailing or leading whitespace is "
3555+
"permitted.")
3556+
35463557
d = Decimal(num, context=self)
35473558
if d._isnan() and len(d._int) > self.prec - self._clamp:
35483559
return self._raise_error(ConversionSyntax,
@@ -5157,7 +5168,7 @@ def _convert_other(other, raiseit=False):
51575168
(?P<diag>\d*) # with (possibly empty) diagnostic information.
51585169
)
51595170
# \s*
5160-
$
5171+
\Z
51615172
""", re.VERBOSE | re.IGNORECASE).match
51625173

51635174
_all_zeros = re.compile('0*$').match

Lib/test/test_decimal.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ def test_explicit_from_string(self):
429429
#just not a number
430430
self.assertEqual(str(Decimal('ugly')), 'NaN')
431431

432+
#leading and trailing whitespace permitted
433+
self.assertEqual(str(Decimal('1.3E4 \n')), '1.3E+4')
434+
self.assertEqual(str(Decimal(' -7.89')), '-7.89')
435+
432436
def test_explicit_from_tuples(self):
433437

434438
#zero
@@ -517,6 +521,10 @@ def test_explicit_context_create_decimal(self):
517521
self.assertEqual(str(d), '456789')
518522
d = nc.create_decimal('456789')
519523
self.assertEqual(str(d), '4.57E+5')
524+
# leading and trailing whitespace should result in a NaN;
525+
# spaces are already checked in Cowlishaw's test-suite, so
526+
# here we just check that a trailing newline results in a NaN
527+
self.assertEqual(str(nc.create_decimal('3.14\n')), 'NaN')
520528

521529
# from tuples
522530
d = Decimal( (1, (4, 3, 4, 9, 1, 3, 5, 3, 4), -25) )

0 commit comments

Comments
 (0)