106
diff -r 8527427914a2 Doc/README.txt
110
as long as you don't change or remove the copyright notice:
112
----------------------------------------------------------------------
113
-Copyright (c) 2000-2008 Python Software Foundation.
114
+Copyright (c) 2000-2012 Python Software Foundation.
117
Copyright (c) 2000 BeOpen.com.
118
diff -r 8527427914a2 Doc/bugs.rst
123
Each bug report will be assigned to a developer who will determine what needs to
124
be done to correct the problem. You will receive an update each time action is
125
-taken on the bug. See http://www.python.org/dev/workflow/ for a detailed
126
-description of the issue workflow.
132
+ `Python Developer's Guide <http://docs.python.org/devguide/>`_
133
+ Detailed description of the issue workflow and developers tools.
135
`How to Report Bugs Effectively <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>`_
136
Article which goes into some detail about how to create a useful bug report.
137
This describes what kind of information is useful and why it is useful.
138
diff -r 8527427914a2 Doc/c-api/arg.rst
139
--- a/Doc/c-api/arg.rst
140
+++ b/Doc/c-api/arg.rst
142
that matches the format unit; and the entry in [square] brackets is the type
143
of the C variable(s) whose address should be passed.
145
+These formats allow to access an object as a contiguous chunk of memory.
146
+You don't have to provide raw storage for the returned unicode or bytes
147
+area. Also, you won't have to release any memory yourself, except with the
148
+``es``, ``es#``, ``et`` and ``et#`` formats.
150
``s`` (string or Unicode) [const char \*]
151
Convert a Python string or Unicode object to a C pointer to a character
152
string. You must not provide storage for the string itself; a pointer to
153
diff -r 8527427914a2 Doc/c-api/complex.rst
154
--- a/Doc/c-api/complex.rst
155
+++ b/Doc/c-api/complex.rst
157
Return the quotient of two complex numbers, using the C :ctype:`Py_complex`
160
+ If *divisor* is null, this method returns zero and sets
161
+ :cdata:`errno` to :cdata:`EDOM`.
164
.. cfunction:: Py_complex _Py_c_pow(Py_complex num, Py_complex exp)
166
Return the exponentiation of *num* by *exp*, using the C :ctype:`Py_complex`
169
+ If *num* is null and *exp* is not a positive real number,
170
+ this method returns zero and sets :cdata:`errno` to :cdata:`EDOM`.
173
Complex Numbers as Python Objects
174
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
176
.. cfunction:: Py_complex PyComplex_AsCComplex(PyObject *op)
178
Return the :ctype:`Py_complex` value of the complex number *op*.
179
+ Upon failure, this method returns ``-1.0`` as a real value.
181
.. versionchanged:: 2.6
182
If *op* is not a Python complex number object but has a :meth:`__complex__`
98
183
diff -r 8527427914a2 Doc/c-api/exceptions.rst
99
184
--- a/Doc/c-api/exceptions.rst
100
185
+++ b/Doc/c-api/exceptions.rst
992
1129
in two separate namespaces. When the binding in one namespace changes, the
993
1130
binding in the other will not, so there will be a discrepancy between them. This
994
1131
happens when, for example, one module is reloaded, or changes the definition of
1132
diff -r 8527427914a2 Doc/howto/functional.rst
1133
--- a/Doc/howto/functional.rst
1134
+++ b/Doc/howto/functional.rst
1136
functional languages include the ML family (Standard ML, OCaml, and other
1137
variants) and Haskell.
1139
-The designers of some computer languages choose to emphasize one
1140
-particular approach to programming. This often makes it difficult to
1141
-write programs that use a different approach. Other languages are
1142
-multi-paradigm languages that support several different approaches.
1143
-Lisp, C++, and Python are multi-paradigm; you can write programs or
1144
-libraries that are largely procedural, object-oriented, or functional
1145
-in all of these languages. In a large program, different sections
1146
-might be written using different approaches; the GUI might be
1147
-object-oriented while the processing logic is procedural or
1148
+The designers of some computer languages choose to emphasize one particular
1149
+approach to programming. This often makes it difficult to write programs that
1150
+use a different approach. Other languages are multi-paradigm languages that
1151
+support several different approaches. Lisp, C++, and Python are
1152
+multi-paradigm; you can write programs or libraries that are largely
1153
+procedural, object-oriented, or functional in all of these languages. In a
1154
+large program, different sections might be written using different approaches;
1155
+the GUI might be object-oriented while the processing logic is procedural or
1156
functional, for example.
1158
In a functional program, input flows through a set of functions. Each function
1159
@@ -1115,132 +1114,6 @@
1160
Consult the operator module's documentation for a complete list.
1164
-The functional module
1165
----------------------
1167
-Collin Winter's `functional module <http://oakwinter.com/code/functional/>`__
1168
-provides a number of more advanced tools for functional programming. It also
1169
-reimplements several Python built-ins, trying to make them more intuitive to
1170
-those used to functional programming in other languages.
1172
-This section contains an introduction to some of the most important functions in
1173
-``functional``; full documentation can be found at `the project's website
1174
-<http://oakwinter.com/code/functional/documentation/>`__.
1176
-``compose(outer, inner, unpack=False)``
1178
-The ``compose()`` function implements function composition. In other words, it
1179
-returns a wrapper around the ``outer`` and ``inner`` callables, such that the
1180
-return value from ``inner`` is fed directly to ``outer``. That is, ::
1182
- >>> def add(a, b):
1185
- >>> def double(a):
1188
- >>> compose(double, add)(5, 6)
1191
-is equivalent to ::
1193
- >>> double(add(5, 6))
1196
-The ``unpack`` keyword is provided to work around the fact that Python functions
1197
-are not always `fully curried <http://en.wikipedia.org/wiki/Currying>`__. By
1198
-default, it is expected that the ``inner`` function will return a single object
1199
-and that the ``outer`` function will take a single argument. Setting the
1200
-``unpack`` argument causes ``compose`` to expect a tuple from ``inner`` which
1201
-will be expanded before being passed to ``outer``. Put simply, ::
1203
- compose(f, g)(5, 6)
1211
- compose(f, g, unpack=True)(5, 6)
1217
-Even though ``compose()`` only accepts two functions, it's trivial to build up a
1218
-version that will compose any number of functions. We'll use ``reduce()``,
1219
-``compose()`` and ``partial()`` (the last of which is provided by both
1220
-``functional`` and ``functools``). ::
1222
- from functional import compose, partial
1224
- multi_compose = partial(reduce, compose)
1227
-We can also use ``map()``, ``compose()`` and ``partial()`` to craft a version of
1228
-``"".join(...)`` that converts its arguments to string::
1230
- from functional import compose, partial
1232
- join = compose("".join, partial(map, str))
1237
-``flip()`` wraps the callable in ``func`` and causes it to receive its
1238
-non-keyword arguments in reverse order. ::
1240
- >>> def triple(a, b, c):
1241
- ... return (a, b, c)
1243
- >>> triple(5, 6, 7)
1246
- >>> flipped_triple = flip(triple)
1247
- >>> flipped_triple(5, 6, 7)
1250
-``foldl(func, start, iterable)``
1252
-``foldl()`` takes a binary function, a starting value (usually some kind of
1253
-'zero'), and an iterable. The function is applied to the starting value and the
1254
-first element of the list, then the result of that and the second element of the
1255
-list, then the result of that and the third element of the list, and so on.
1257
-This means that a call such as::
1259
- foldl(f, 0, [1, 2, 3])
1263
- f(f(f(0, 1), 2), 3)
1266
-``foldl()`` is roughly equivalent to the following recursive function::
1268
- def foldl(func, start, seq):
1272
- return foldl(func, func(start, seq[0]), seq[1:])
1274
-Speaking of equivalence, the above ``foldl`` call can be expressed in terms of
1275
-the built-in ``reduce`` like so::
1277
- reduce(f, [1, 2, 3], 0)
1280
-We can use ``foldl()``, ``operator.concat()`` and ``partial()`` to write a
1281
-cleaner, more aesthetically-pleasing version of Python's ``"".join(...)``
1284
- from functional import foldl, partial from operator import concat
1286
- join = partial(foldl, concat, "")
1289
Revision History and Acknowledgements
1290
=====================================
1292
@@ -1296,9 +1169,10 @@
1294
Mertz also wrote a 3-part series of articles on functional programming
1295
for IBM's DeveloperWorks site; see
1296
-`part 1 <http://www-128.ibm.com/developerworks/library/l-prog.html>`__,
1297
-`part 2 <http://www-128.ibm.com/developerworks/library/l-prog2.html>`__, and
1298
-`part 3 <http://www-128.ibm.com/developerworks/linux/library/l-prog3.html>`__,
1300
+`part 1 <http://www.ibm.com/developerworks/linux/library/l-prog/index.html>`__,
1301
+`part 2 <http://www.ibm.com/developerworks/linux/library/l-prog2/index.html>`__, and
1302
+`part 3 <http://www.ibm.com/developerworks/linux/library/l-prog3/index.html>`__,
1305
Python documentation
995
1306
diff -r 8527427914a2 Doc/howto/index.rst
996
1307
--- a/Doc/howto/index.rst
997
1308
+++ b/Doc/howto/index.rst
5868
6296
The :mod:`mimetypes` module converts between a filename or URL and the MIME type
5869
6297
associated with the filename extension. Conversions are provided from filename
5870
6298
to MIME type and from MIME type to filename extension; encodings are not
6300
the information :func:`init` sets up.
6303
-.. function:: guess_type(filename[, strict])
6304
+.. function:: guess_type(url, strict=True)
6306
.. index:: pair: MIME; headers
6308
- Guess the type of a file based on its filename or URL, given by *filename*. The
6309
+ Guess the type of a file based on its filename or URL, given by *url*. The
6310
return value is a tuple ``(type, encoding)`` where *type* is ``None`` if the
6311
type can't be guessed (missing or unknown suffix) or a string of the form
6312
``'type/subtype'``, usable for a MIME :mailheader:`content-type` header.
6314
*encoding* is ``None`` for no encoding or the name of the program used to encode
6315
(e.g. :program:`compress` or :program:`gzip`). The encoding is suitable for use
6316
- as a :mailheader:`Content-Encoding` header, *not* as a
6317
+ as a :mailheader:`Content-Encoding` header, **not** as a
6318
:mailheader:`Content-Transfer-Encoding` header. The mappings are table driven.
6319
Encoding suffixes are case sensitive; type suffixes are first tried case
6320
sensitively, then case insensitively.
6322
- Optional *strict* is a flag specifying whether the list of known MIME types
6323
+ The optional *strict* argument is a flag specifying whether the list of known MIME types
6324
is limited to only the official types `registered with IANA
6325
- <http://www.iana.org/assignments/media-types/>`_ are recognized.
6326
- When *strict* is true (the default), only the IANA types are supported; when
6327
- *strict* is false, some additional non-standard but commonly used MIME types
6328
+ <http://www.iana.org/assignments/media-types/>`_.
6329
+ When *strict* is ``True`` (the default), only the IANA types are supported; when
6330
+ *strict* is ``False``, some additional non-standard but commonly used MIME types
6331
are also recognized.
6334
-.. function:: guess_all_extensions(type[, strict])
6335
+.. function:: guess_all_extensions(type, strict=True)
6337
Guess the extensions for a file based on its MIME type, given by *type*. The
6338
return value is a list of strings giving all possible filename extensions,
6340
been associated with any particular data stream, but would be mapped to the MIME
6341
type *type* by :func:`guess_type`.
6343
- Optional *strict* has the same meaning as with the :func:`guess_type` function.
6344
+ The optional *strict* argument has the same meaning as with the :func:`guess_type` function.
6347
-.. function:: guess_extension(type[, strict])
6348
+.. function:: guess_extension(type, strict=True)
6350
Guess the extension for a file based on its MIME type, given by *type*. The
6351
return value is a string giving a filename extension, including the leading dot
6352
(``'.'``). The extension is not guaranteed to have been associated with any
6353
- particular data stream, but would be mapped to the MIME type *type* by
6354
+ particular data stream, but would be mapped to the MIME type *type* by
6355
:func:`guess_type`. If no extension can be guessed for *type*, ``None`` is
6358
- Optional *strict* has the same meaning as with the :func:`guess_type` function.
6359
+ The optional *strict* argument has the same meaning as with the :func:`guess_type` function.
6361
Some additional functions and data items are available for controlling the
6362
behavior of the module.
6365
-.. function:: init([files])
6366
+.. function:: init(files=None)
6368
Initialize the internal data structures. If given, *files* must be a sequence
6369
of file names which should be used to augment the default type map. If omitted,
6372
.. function:: read_mime_types(filename)
6374
- Load the type map given in the file *filename*, if it exists. The type map is
6375
+ Load the type map given in the file *filename*, if it exists. The type map is
6376
returned as a dictionary mapping filename extensions, including the leading dot
6377
(``'.'``), to strings of the form ``'type/subtype'``. If the file *filename*
6378
does not exist or cannot be read, ``None`` is returned.
6381
-.. function:: add_type(type, ext[, strict])
6382
+.. function:: add_type(type, ext, strict=True)
6384
- Add a mapping from the mimetype *type* to the extension *ext*. When the
6385
+ Add a mapping from the MIME type *type* to the extension *ext*. When the
6386
extension is already known, the new type will replace the old one. When the type
6387
is already known the extension will be added to the list of known extensions.
6389
- When *strict* is True (the default), the mapping will added to the official MIME
6390
+ When *strict* is ``True`` (the default), the mapping will added to the official MIME
6391
types, otherwise to the non-standard ones.
6396
Flag indicating whether or not the global data structures have been initialized.
6397
- This is set to true by :func:`init`.
6398
+ This is set to ``True`` by :func:`init`.
6401
.. data:: knownfiles
6402
@@ -142,23 +145,6 @@
6403
Dictionary mapping filename extensions to non-standard, but commonly found MIME
6406
-The :class:`MimeTypes` class may be useful for applications which may want more
6407
-than one MIME-type database:
6410
-.. class:: MimeTypes([filenames])
6412
- This class represents a MIME-types database. By default, it provides access to
6413
- the same database as the rest of this module. The initial database is a copy of
6414
- that provided by the module, and may be extended by loading additional
6415
- :file:`mime.types`\ -style files into the database using the :meth:`read` or
6416
- :meth:`readfp` methods. The mapping dictionaries may also be cleared before
6417
- loading additional data if the default data is not desired.
6419
- The optional *filenames* parameter can be used to cause additional files to be
6420
- loaded "on top" of the default database.
6422
- .. versionadded:: 2.2
6424
An example usage of the module::
6426
@@ -179,70 +165,96 @@
6430
-:class:`MimeTypes` instances provide an interface which is very like that of the
6431
+The :class:`MimeTypes` class may be useful for applications which may want more
6432
+than one MIME-type database; it provides an interface similar to the one of the
6433
:mod:`mimetypes` module.
6436
+.. class:: MimeTypes(filenames=(), strict=True)
6438
+ This class represents a MIME-types database. By default, it provides access to
6439
+ the same database as the rest of this module. The initial database is a copy of
6440
+ that provided by the module, and may be extended by loading additional
6441
+ :file:`mime.types`\ -style files into the database using the :meth:`read` or
6442
+ :meth:`readfp` methods. The mapping dictionaries may also be cleared before
6443
+ loading additional data if the default data is not desired.
6445
+ The optional *filenames* parameter can be used to cause additional files to be
6446
+ loaded "on top" of the default database.
6449
.. attribute:: MimeTypes.suffix_map
6451
Dictionary mapping suffixes to suffixes. This is used to allow recognition of
6452
encoded files for which the encoding and the type are indicated by the same
6453
extension. For example, the :file:`.tgz` extension is mapped to :file:`.tar.gz`
6454
to allow the encoding and type to be recognized separately. This is initially a
6455
- copy of the global ``suffix_map`` defined in the module.
6456
+ copy of the global :data:`suffix_map` defined in the module.
6459
.. attribute:: MimeTypes.encodings_map
6461
Dictionary mapping filename extensions to encoding types. This is initially a
6462
- copy of the global ``encodings_map`` defined in the module.
6463
+ copy of the global :data:`encodings_map` defined in the module.
6466
.. attribute:: MimeTypes.types_map
6468
- Dictionary mapping filename extensions to MIME types. This is initially a copy
6469
- of the global ``types_map`` defined in the module.
6470
+ Tuple containing two dictionaries, mapping filename extensions to MIME types:
6471
+ the first dictionary is for the non-standards types and the second one is for
6472
+ the standard types. They are initialized by :data:`common_types` and
6473
+ :data:`types_map`.
6476
-.. attribute:: MimeTypes.common_types
6477
+.. attribute:: MimeTypes.types_map_inv
6479
- Dictionary mapping filename extensions to non-standard, but commonly found MIME
6480
- types. This is initially a copy of the global ``common_types`` defined in the
6482
+ Tuple containing two dictionaries, mapping MIME types to a list of filename
6483
+ extensions: the first dictionary is for the non-standards types and the
6484
+ second one is for the standard types. They are initialized by
6485
+ :data:`common_types` and :data:`types_map`.
6488
-.. method:: MimeTypes.guess_extension(type[, strict])
6489
+.. method:: MimeTypes.guess_extension(type, strict=True)
6491
Similar to the :func:`guess_extension` function, using the tables stored as part
6495
-.. method:: MimeTypes.guess_all_extensions(type[, strict])
6497
- Similar to the :func:`guess_all_extensions` function, using the tables stored as part
6501
-.. method:: MimeTypes.guess_type(url[, strict])
6502
+.. method:: MimeTypes.guess_type(url, strict=True)
6504
Similar to the :func:`guess_type` function, using the tables stored as part of
6508
-.. method:: MimeTypes.read(path)
6509
+.. method:: MimeTypes.guess_all_extensions(type, strict=True)
6511
- Load MIME information from a file named *path*. This uses :meth:`readfp` to
6512
+ Similar to the :func:`guess_all_extensions` function, using the tables stored
6513
+ as part of the object.
6516
+.. method:: MimeTypes.read(filename, strict=True)
6518
+ Load MIME information from a file named *filename*. This uses :meth:`readfp` to
6521
+ If *strict* is ``True``, information will be added to list of standard types,
6522
+ else to the list of non-standard types.
6524
-.. method:: MimeTypes.readfp(file)
6526
- Load MIME type information from an open file. The file must have the format of
6527
+.. method:: MimeTypes.readfp(fp, strict=True)
6529
+ Load MIME type information from an open file *fp*. The file must have the format of
6530
the standard :file:`mime.types` files.
6532
+ If *strict* is ``True``, information will be added to the list of standard
6533
+ types, else to the list of non-standard types.
6535
-.. method:: MimeTypes.read_windows_registry()
6537
+.. method:: MimeTypes.read_windows_registry(strict=True)
6539
Load MIME type information from the Windows registry. Availability: Windows.
6541
+ If *strict* is ``True``, information will be added to the list of standard
6542
+ types, else to the list of non-standard types.
6544
.. versionadded:: 2.7
5871
6545
diff -r 8527427914a2 Doc/library/mmap.rst
5872
6546
--- a/Doc/library/mmap.rst
5873
6547
+++ b/Doc/library/mmap.rst
10768
11737
thread-state, even if no auto-thread-state call has been made
10769
11738
on the main thread.
11740
diff -r 8527427914a2 LICENSE
11744
analyze, test, perform and/or display publicly, prepare derivative works,
11745
distribute, and otherwise use Python alone or in any derivative version,
11746
provided, however, that PSF's License Agreement and PSF's notice of copyright,
11747
-i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
11748
-Python Software Foundation; All Rights Reserved" are retained in Python alone or
11749
-in any derivative version prepared by Licensee.
11750
+i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
11751
+2011, 2012 Python Software Foundation; All Rights Reserved" are retained in Python
11752
+alone or in any derivative version prepared by Licensee.
11754
3. In the event Licensee prepares a derivative work that is based on
11755
or incorporates Python or any part thereof, and wants to make
11756
diff -r 8527427914a2 Lib/BaseHTTPServer.py
11757
--- a/Lib/BaseHTTPServer.py
11758
+++ b/Lib/BaseHTTPServer.py
11759
@@ -244,14 +244,11 @@
11760
self.request_version = version = self.default_request_version
11761
self.close_connection = 1
11762
requestline = self.raw_requestline
11763
- if requestline[-2:] == '\r\n':
11764
- requestline = requestline[:-2]
11765
- elif requestline[-1:] == '\n':
11766
- requestline = requestline[:-1]
11767
+ requestline = requestline.rstrip('\r\n')
11768
self.requestline = requestline
11769
words = requestline.split()
11770
if len(words) == 3:
11771
- [command, path, version] = words
11772
+ command, path, version = words
11773
if version[:5] != 'HTTP/':
11774
self.send_error(400, "Bad request version (%r)" % version)
11776
@@ -277,7 +274,7 @@
11777
"Invalid HTTP Version (%s)" % base_version_number)
11779
elif len(words) == 2:
11780
- [command, path] = words
11781
+ command, path = words
11782
self.close_connection = 1
11783
if command != 'GET':
11784
self.send_error(400,
10771
11785
diff -r 8527427914a2 Lib/ConfigParser.py
10772
11786
--- a/Lib/ConfigParser.py
10773
11787
+++ b/Lib/ConfigParser.py
12204
13218
+ name, equals, value = runshared.partition('=')
12205
13219
+ cmd.library_dirs = value.split(os.pathsep)
13220
diff -r 8527427914a2 Lib/distutils/tests/test_archive_util.py
13221
--- a/Lib/distutils/tests/test_archive_util.py
13222
+++ b/Lib/distutils/tests/test_archive_util.py
13224
+# -*- coding: utf-8 -*-
13225
"""Tests for distutils.archive_util."""
13226
__revision__ = "$Id$"
13232
from os.path import splitdrive
13235
except ImportError:
13238
+def can_fs_encode(filename):
13240
+ Return True if the filename can be saved in the file system.
13242
+ if os.path.supports_unicode_filenames:
13245
+ filename.encode(sys.getfilesystemencoding())
13246
+ except UnicodeEncodeError:
13251
class ArchiveUtilTestCase(support.TempdirManager,
13252
support.LoggingSilencer,
13255
@unittest.skipUnless(zlib, "requires zlib")
13256
def test_make_tarball(self):
13257
+ self._make_tarball('archive')
13259
+ def _make_tarball(self, target_name):
13260
# creating something to tar
13261
tmpdir = self.mkdtemp()
13262
self.write_file([tmpdir, 'file1'], 'xxx')
13264
unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
13265
"source and target should be on same drive")
13267
- base_name = os.path.join(tmpdir2, 'archive')
13268
+ base_name = os.path.join(tmpdir2, target_name)
13270
# working with relative paths to avoid tar warnings
13271
old_dir = os.getcwd()
13273
self.assertTrue(os.path.exists(tarball))
13275
# trying an uncompressed one
13276
- base_name = os.path.join(tmpdir2, 'archive')
13277
+ base_name = os.path.join(tmpdir2, target_name)
13278
old_dir = os.getcwd()
13281
@@ -277,6 +294,33 @@
13283
del ARCHIVE_FORMATS['xxx']
13285
+ @unittest.skipUnless(zlib, "requires zlib")
13286
+ def test_make_tarball_unicode(self):
13288
+ Mirror test_make_tarball, except filename is unicode.
13290
+ self._make_tarball(u'archive')
13292
+ @unittest.skipUnless(zlib, "requires zlib")
13293
+ @unittest.skipUnless(can_fs_encode(u'årchiv'),
13294
+ 'File system cannot handle this filename')
13295
+ def test_make_tarball_unicode_latin1(self):
13297
+ Mirror test_make_tarball, except filename is unicode and contains
13298
+ latin characters.
13300
+ self._make_tarball(u'årchiv') # note this isn't a real word
13302
+ @unittest.skipUnless(zlib, "requires zlib")
13303
+ @unittest.skipUnless(can_fs_encode(u'のアーカイブ'),
13304
+ 'File system cannot handle this filename')
13305
+ def test_make_tarball_unicode_extended(self):
13307
+ Mirror test_make_tarball, except filename is unicode and contains
13308
+ characters outside the latin charset.
13310
+ self._make_tarball(u'のアーカイブ') # japanese for archive
13313
return unittest.makeSuite(ArchiveUtilTestCase)
12206
13315
diff -r 8527427914a2 Lib/distutils/tests/test_bdist.py
12207
13316
--- a/Lib/distutils/tests/test_bdist.py
12208
13317
+++ b/Lib/distutils/tests/test_bdist.py
13570
14708
def test_suite():
13571
14709
return unittest.makeSuite(SDistTestCase)
14711
diff -r 8527427914a2 Lib/doctest.py
14712
--- a/Lib/doctest.py
14713
+++ b/Lib/doctest.py
14714
@@ -451,6 +451,25 @@
14715
self.options = options
14716
self.exc_msg = exc_msg
14718
+ def __eq__(self, other):
14719
+ if type(self) is not type(other):
14720
+ return NotImplemented
14722
+ return self.source == other.source and \
14723
+ self.want == other.want and \
14724
+ self.lineno == other.lineno and \
14725
+ self.indent == other.indent and \
14726
+ self.options == other.options and \
14727
+ self.exc_msg == other.exc_msg
14729
+ def __ne__(self, other):
14730
+ return not self == other
14732
+ def __hash__(self):
14733
+ return hash((self.source, self.want, self.lineno, self.indent,
14739
A collection of doctest examples that should be run in a single
14740
@@ -499,6 +518,22 @@
14741
return ('<DocTest %s from %s:%s (%s)>' %
14742
(self.name, self.filename, self.lineno, examples))
14744
+ def __eq__(self, other):
14745
+ if type(self) is not type(other):
14746
+ return NotImplemented
14748
+ return self.examples == other.examples and \
14749
+ self.docstring == other.docstring and \
14750
+ self.globs == other.globs and \
14751
+ self.name == other.name and \
14752
+ self.filename == other.filename and \
14753
+ self.lineno == other.lineno
14755
+ def __ne__(self, other):
14756
+ return not self == other
14758
+ def __hash__(self):
14759
+ return hash((self.docstring, self.name, self.filename, self.lineno))
14761
# This lets us sort tests by name:
14762
def __cmp__(self, other):
14763
@@ -2252,6 +2287,23 @@
14765
return self._dt_test.name
14767
+ def __eq__(self, other):
14768
+ if type(self) is not type(other):
14769
+ return NotImplemented
14771
+ return self._dt_test == other._dt_test and \
14772
+ self._dt_optionflags == other._dt_optionflags and \
14773
+ self._dt_setUp == other._dt_setUp and \
14774
+ self._dt_tearDown == other._dt_tearDown and \
14775
+ self._dt_checker == other._dt_checker
14777
+ def __ne__(self, other):
14778
+ return not self == other
14780
+ def __hash__(self):
14781
+ return hash((self._dt_optionflags, self._dt_setUp, self._dt_tearDown,
14782
+ self._dt_checker))
14784
def __repr__(self):
14785
name = self._dt_test.name.split('.')
14786
return "%s (%s)" % (name[-1], '.'.join(name[:-1]))
13573
14787
diff -r 8527427914a2 Lib/filecmp.py
13574
14788
--- a/Lib/filecmp.py
13575
14789
+++ b/Lib/filecmp.py
13911
15125
diff -r 8527427914a2 Lib/inspect.py
13912
15126
--- a/Lib/inspect.py
13913
15127
+++ b/Lib/inspect.py
13914
@@ -524,9 +524,13 @@
15128
@@ -247,12 +247,23 @@
15129
def getmembers(object, predicate=None):
15130
"""Return all members of an object as (name, value) pairs sorted by name.
15131
Optionally, only return members that satisfy a given predicate."""
15132
+ if isclass(object):
15133
+ mro = (object,) + getmro(object)
15137
for key in dir(object):
15139
- value = getattr(object, key)
15140
- except AttributeError:
15142
+ # First try to get the value via __dict__. Some descriptors don't
15143
+ # like calling their __get__ (see bug #1785).
15145
+ if key in base.__dict__:
15146
+ value = base.__dict__[key]
15150
+ value = getattr(object, key)
15151
+ except AttributeError:
15153
if not predicate or predicate(value):
15154
results.append((key, value))
15156
@@ -288,30 +299,21 @@
15160
- # Get the object associated with the name.
15161
+ # Get the object associated with the name, and where it was defined.
15162
# Getting an obj from the __dict__ sometimes reveals more than
15163
# using getattr. Static and class methods are dramatic examples.
15164
- if name in cls.__dict__:
15165
- obj = cls.__dict__[name]
15166
+ # Furthermore, some objects may raise an Exception when fetched with
15167
+ # getattr(). This is the case with some descriptors (bug #1785).
15168
+ # Thus, we only use getattr() as a last resort.
15170
+ for base in (cls,) + mro:
15171
+ if name in base.__dict__:
15172
+ obj = base.__dict__[name]
15176
obj = getattr(cls, name)
15178
- # Figure out where it was defined.
15179
- homecls = getattr(obj, "__objclass__", None)
15180
- if homecls is None:
15181
- # search the dicts.
15183
- if name in base.__dict__:
15187
- # Get the object again, in order to get it from the defining
15188
- # __dict__ instead of via getattr (if possible).
15189
- if homecls is not None and name in homecls.__dict__:
15190
- obj = homecls.__dict__[name]
15192
- # Also get the object via getattr.
15193
- obj_via_getattr = getattr(cls, name)
15194
+ homecls = getattr(obj, "__objclass__", homecls)
15196
# Classify the object.
15197
if isinstance(obj, staticmethod):
15198
@@ -320,11 +322,18 @@
15199
kind = "class method"
15200
elif isinstance(obj, property):
15202
- elif (ismethod(obj_via_getattr) or
15203
- ismethoddescriptor(obj_via_getattr)):
15204
+ elif ismethoddescriptor(obj):
15206
+ elif isdatadescriptor(obj):
15210
+ obj_via_getattr = getattr(cls, name)
15211
+ if (ismethod(obj_via_getattr) or
15212
+ ismethoddescriptor(obj_via_getattr)):
15216
+ obj = obj_via_getattr
15218
result.append(Attribute(name, kind, homecls, obj))
15220
@@ -524,9 +533,13 @@
13915
15221
or code object. The source code is returned as a list of all the lines
13916
15222
in the file and the line number indexes a line in that list. An IOError
13917
15223
is raised if the source code cannot be retrieved."""
14859
16191
info = inspect.getmoduleinfo(filename)
14861
16193
file = open(filename)
14862
@@ -1454,13 +1454,14 @@
16194
@@ -740,8 +740,15 @@
16197
for name, kind, homecls, value in ok:
16198
- push(self.document(getattr(object, name), name, mod,
16199
- funcs, classes, mdict, object))
16201
+ value = getattr(object, name)
16202
+ except Exception:
16203
+ # Some descriptors may meet a failure in their __get__.
16205
+ push(self._docdescriptor(name, value, mod))
16207
+ push(self.document(value, name, mod,
16208
+ funcs, classes, mdict, object))
16212
@@ -781,7 +788,12 @@
16214
for key, kind, homecls, value in attrs:
16215
mdict[key] = anchor = '#' + name + '-' + key
16216
- value = getattr(object, key)
16218
+ value = getattr(object, name)
16219
+ except Exception:
16220
+ # Some descriptors may meet a failure in their __get__.
16224
# The value may not be hashable (e.g., a data attr with
16225
# a dict or list value).
16226
@@ -1161,8 +1173,15 @@
16229
for name, kind, homecls, value in ok:
16230
- push(self.document(getattr(object, name),
16231
- name, mod, object))
16233
+ value = getattr(object, name)
16234
+ except Exception:
16235
+ # Some descriptors may meet a failure in their __get__.
16237
+ push(self._docdescriptor(name, value, mod))
16239
+ push(self.document(value,
16240
+ name, mod, object))
16243
def spilldescriptors(msg, attrs, predicate):
16244
@@ -1454,13 +1473,14 @@
14865
16247
object = module
16089
17516
"""%(bug1333982.func_code.co_firstlineno + 1,
16090
17517
bug1333982.func_code.co_firstlineno + 2,
16091
17518
bug1333982.func_code.co_firstlineno + 3)
17519
diff -r 8527427914a2 Lib/test/test_doctest.py
17520
--- a/Lib/test/test_doctest.py
17521
+++ b/Lib/test/test_doctest.py
17522
@@ -258,6 +258,21 @@
17523
>>> e = doctest.Example('raise X()', '', exc_msg)
17527
+Compare `Example`:
17528
+ >>> example = doctest.Example('print 1', '1\n')
17529
+ >>> same_example = doctest.Example('print 1', '1\n')
17530
+ >>> other_example = doctest.Example('print 42', '42\n')
17531
+ >>> example == same_example
17533
+ >>> example != same_example
17535
+ >>> hash(example) == hash(same_example)
17537
+ >>> example == other_example
17539
+ >>> example != other_example
17543
def test_DocTest(): r"""
17544
@@ -347,6 +362,50 @@
17545
Traceback (most recent call last):
17546
ValueError: line 2 of the docstring for some_test lacks blank after ...: '...print 1'
17548
+Compare `DocTest`:
17550
+ >>> docstring = '''
17554
+ >>> test = parser.get_doctest(docstring, globs, 'some_test',
17555
+ ... 'some_test', 20)
17556
+ >>> same_test = parser.get_doctest(docstring, globs, 'some_test',
17557
+ ... 'some_test', 20)
17558
+ >>> test == same_test
17560
+ >>> test != same_test
17562
+ >>> hash(test) == hash(same_test)
17564
+ >>> docstring = '''
17568
+ >>> other_test = parser.get_doctest(docstring, globs, 'other_test',
17569
+ ... 'other_file', 10)
17570
+ >>> test == other_test
17572
+ >>> test != other_test
17575
+Compare `DocTestCase`:
17577
+ >>> DocTestCase = doctest.DocTestCase
17578
+ >>> test_case = DocTestCase(test)
17579
+ >>> same_test_case = DocTestCase(same_test)
17580
+ >>> other_test_case = DocTestCase(other_test)
17581
+ >>> test_case == same_test_case
17583
+ >>> test_case != same_test_case
17585
+ >>> hash(test_case) == hash(same_test_case)
17587
+ >>> test == other_test_case
17589
+ >>> test != other_test_case
17594
def test_DocTestFinder(): r"""
17595
diff -r 8527427914a2 Lib/test/test_epoll.py
17596
--- a/Lib/test/test_epoll.py
17597
+++ b/Lib/test/test_epoll.py
17600
if e.errno == errno.ENOSYS:
17601
raise unittest.SkipTest("kernel doesn't support epoll()")
17604
class TestEPoll(unittest.TestCase):
16092
17606
diff -r 8527427914a2 Lib/test/test_exceptions.py
16093
17607
--- a/Lib/test/test_exceptions.py
16094
17608
+++ b/Lib/test/test_exceptions.py
16147
17661
def test_floatasratio(self):
16148
17662
for f, ratio in [
16149
17663
(0.875, (7, 8)),
17664
diff -r 8527427914a2 Lib/test/test_ftplib.py
17665
--- a/Lib/test/test_ftplib.py
17666
+++ b/Lib/test/test_ftplib.py
17667
@@ -667,7 +667,7 @@
17669
self.evt = threading.Event()
17670
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
17671
- self.sock.settimeout(3)
17672
+ self.sock.settimeout(10)
17673
self.port = test_support.bind_port(self.sock)
17674
threading.Thread(target=self.server, args=(self.evt,self.sock)).start()
17675
# Wait for the server to be ready.
17676
diff -r 8527427914a2 Lib/test/test_gdb.py
17677
--- a/Lib/test/test_gdb.py
17678
+++ b/Lib/test/test_gdb.py
17680
if gdbpy_version == '':
17681
raise unittest.SkipTest("gdb not built with embedded python support")
17683
+def python_is_optimized():
17684
+ cflags = sysconfig.get_config_vars()['PY_CFLAGS']
17686
+ for opt in cflags.split():
17687
+ if opt.startswith('-O'):
17689
+ return (final_opt and final_opt != '-O0')
17691
def gdb_has_frame_select():
17692
# Does this build of gdb have gdb.Frame.select ?
17693
cmd = "--eval-command=python print(dir(gdb.Frame))"
17694
@@ -543,6 +551,8 @@
17696
'Unexpected gdb representation: %r\n%s' % (gdb_output, gdb_output))
17698
+@unittest.skipIf(python_is_optimized(),
17699
+ "Python was compiled with optimizations")
17700
class PyListTests(DebuggerTests):
17701
def assertListing(self, expected, actual):
17702
self.assertEndsWith(actual, expected)
17703
@@ -585,6 +595,8 @@
17705
class StackNavigationTests(DebuggerTests):
17706
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
17707
+ @unittest.skipIf(python_is_optimized(),
17708
+ "Python was compiled with optimizations")
17709
def test_pyup_command(self):
17710
'Verify that the "py-up" command works'
17711
bt = self.get_stack_trace(script=self.get_sample_script(),
17712
@@ -612,6 +624,8 @@
17713
'Unable to find an older python frame\n')
17715
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
17716
+ @unittest.skipIf(python_is_optimized(),
17717
+ "Python was compiled with optimizations")
17718
def test_up_then_down(self):
17719
'Verify "py-up" followed by "py-down"'
17720
bt = self.get_stack_trace(script=self.get_sample_script(),
17721
@@ -625,6 +639,8 @@
17724
class PyBtTests(DebuggerTests):
17725
+ @unittest.skipIf(python_is_optimized(),
17726
+ "Python was compiled with optimizations")
17727
def test_basic_command(self):
17728
'Verify that the "py-bt" command works'
17729
bt = self.get_stack_trace(script=self.get_sample_script(),
17730
@@ -636,10 +652,12 @@
17731
#[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 4, in foo \(a=1, b=2, c=3\)
17733
#[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 12, in <module> \(\)
17738
class PyPrintTests(DebuggerTests):
17739
+ @unittest.skipIf(python_is_optimized(),
17740
+ "Python was compiled with optimizations")
17741
def test_basic_command(self):
17742
'Verify that the "py-print" command works'
17743
bt = self.get_stack_trace(script=self.get_sample_script(),
17744
@@ -648,18 +666,24 @@
17745
r".*\nlocal 'args' = \(1, 2, 3\)\n.*")
17747
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
17748
+ @unittest.skipIf(python_is_optimized(),
17749
+ "Python was compiled with optimizations")
17750
def test_print_after_up(self):
17751
bt = self.get_stack_trace(script=self.get_sample_script(),
17752
cmds_after_breakpoint=['py-up', 'py-print c', 'py-print b', 'py-print a'])
17753
self.assertMultilineMatches(bt,
17754
r".*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*")
17756
+ @unittest.skipIf(python_is_optimized(),
17757
+ "Python was compiled with optimizations")
17758
def test_printing_global(self):
17759
bt = self.get_stack_trace(script=self.get_sample_script(),
17760
cmds_after_breakpoint=['py-print __name__'])
17761
self.assertMultilineMatches(bt,
17762
r".*\nglobal '__name__' = '__main__'\n.*")
17764
+ @unittest.skipIf(python_is_optimized(),
17765
+ "Python was compiled with optimizations")
17766
def test_printing_builtin(self):
17767
bt = self.get_stack_trace(script=self.get_sample_script(),
17768
cmds_after_breakpoint=['py-print len'])
17769
@@ -667,6 +691,8 @@
17770
r".*\nbuiltin 'len' = <built-in function len>\n.*")
17772
class PyLocalsTests(DebuggerTests):
17773
+ @unittest.skipIf(python_is_optimized(),
17774
+ "Python was compiled with optimizations")
17775
def test_basic_command(self):
17776
bt = self.get_stack_trace(script=self.get_sample_script(),
17777
cmds_after_breakpoint=['py-locals'])
17778
@@ -674,6 +700,8 @@
17779
r".*\nargs = \(1, 2, 3\)\n.*")
17781
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
17782
+ @unittest.skipIf(python_is_optimized(),
17783
+ "Python was compiled with optimizations")
17784
def test_locals_after_up(self):
17785
bt = self.get_stack_trace(script=self.get_sample_script(),
17786
cmds_after_breakpoint=['py-up', 'py-locals'])
17787
@@ -681,15 +709,6 @@
17788
r".*\na = 1\nb = 2\nc = 3\n.*")
17791
- cflags = sysconfig.get_config_vars()['PY_CFLAGS']
17793
- for opt in cflags.split():
17794
- if opt.startswith('-O'):
17796
- if final_opt and final_opt != '-O0':
17797
- raise unittest.SkipTest("Python was built with compiler optimizations, "
17798
- "tests can't reliably succeed")
17800
run_unittest(PrettyPrintTests,
17802
StackNavigationTests,
16150
17803
diff -r 8527427914a2 Lib/test/test_grammar.py
16151
17804
--- a/Lib/test/test_grammar.py
16152
17805
+++ b/Lib/test/test_grammar.py
16472
18125
+ [("href", "http://www.example.org/\">;")]),
16473
18126
+ ("data", "spam"), ("endtag", "a")])
18128
+ def test_condcoms(self):
18129
+ html = ('<!--[if IE & !(lte IE 8)]>aren\'t<![endif]-->'
18130
+ '<!--[if IE 8]>condcoms<![endif]-->'
18131
+ '<!--[if lte IE 7]>pretty?<![endif]-->')
18132
+ expected = [('comment', "[if IE & !(lte IE 8)]>aren't<![endif]"),
18133
+ ('comment', '[if IE 8]>condcoms<![endif]'),
18134
+ ('comment', '[if lte IE 7]>pretty?<![endif]')]
18135
+ self._run_check(html, expected)
18137
+ def test_broken_condcoms(self):
18138
+ # these condcoms are missing the '--' after '<!' and before the '>'
18139
+ html = ('<![if !(IE)]>broken condcom<![endif]>'
18140
+ '<![if ! IE]><link href="favicon.tiff"/><![endif]>'
18141
+ '<![if !IE 6]><img src="firefox.png" /><![endif]>'
18142
+ '<![if !ie 6]><b>foo</b><![endif]>'
18143
+ '<![if (!IE)|(lt IE 9)]><img src="mammoth.bmp" /><![endif]>')
18144
+ # According to the HTML5 specs sections "8.2.4.44 Bogus comment state"
18145
+ # and "8.2.4.45 Markup declaration open state", comment tokens should
18146
+ # be emitted instead of 'unknown decl', but calling unknown_decl
18147
+ # provides more flexibility.
18148
+ # See also Lib/_markupbase.py:parse_declaration
18150
+ ('unknown decl', 'if !(IE)'),
18151
+ ('data', 'broken condcom'),
18152
+ ('unknown decl', 'endif'),
18153
+ ('unknown decl', 'if ! IE'),
18154
+ ('startendtag', 'link', [('href', 'favicon.tiff')]),
18155
+ ('unknown decl', 'endif'),
18156
+ ('unknown decl', 'if !IE 6'),
18157
+ ('startendtag', 'img', [('src', 'firefox.png')]),
18158
+ ('unknown decl', 'endif'),
18159
+ ('unknown decl', 'if !ie 6'),
18160
+ ('starttag', 'b', []),
18163
+ ('unknown decl', 'endif'),
18164
+ ('unknown decl', 'if (!IE)|(lt IE 9)'),
18165
+ ('startendtag', 'img', [('src', 'mammoth.bmp')]),
18166
+ ('unknown decl', 'endif')
18168
+ self._run_check(html, expected)
16476
18171
def test_main():
16477
18172
- test_support.run_unittest(HTMLParserTestCase)
16600
18300
class TestDecorators(GetSourceBase):
16601
18301
fodderFile = mod2
18303
@@ -387,10 +404,37 @@
18304
self.assertEqual(inspect.findsource(co), (lines,0))
18305
self.assertEqual(inspect.getsource(co), lines[0])
18308
+class _BrokenDataDescriptor(object):
18310
+ A broken data descriptor. See bug #1785.
18312
+ def __get__(*args):
18313
+ raise AssertionError("should not __get__ data descriptors")
18315
+ def __set__(*args):
18316
+ raise RuntimeError
18318
+ def __getattr__(*args):
18319
+ raise AssertionError("should not __getattr__ data descriptors")
18322
+class _BrokenMethodDescriptor(object):
18324
+ A broken method descriptor. See bug #1785.
18326
+ def __get__(*args):
18327
+ raise AssertionError("should not __get__ method descriptors")
18329
+ def __getattr__(*args):
18330
+ raise AssertionError("should not __getattr__ method descriptors")
18333
# Helper for testing classify_class_attrs.
18334
def attrs_wo_objs(cls):
18335
return [t[:3] for t in inspect.classify_class_attrs(cls)]
18338
class TestClassesAndFunctions(unittest.TestCase):
18339
def test_classic_mro(self):
18340
# Test classic-class method resolution order.
18341
@@ -477,6 +521,9 @@
18345
+ dd = _BrokenDataDescriptor()
18346
+ md = _BrokenMethodDescriptor()
18348
attrs = attrs_wo_objs(A)
18349
self.assertIn(('s', 'static method', A), attrs, 'missing static method')
18350
self.assertIn(('c', 'class method', A), attrs, 'missing class method')
18351
@@ -484,6 +531,8 @@
18352
self.assertIn(('m', 'method', A), attrs, 'missing plain method')
18353
self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
18354
self.assertIn(('datablob', 'data', A), attrs, 'missing data')
18355
+ self.assertIn(('md', 'method', A), attrs, 'missing method descriptor')
18356
+ self.assertIn(('dd', 'data', A), attrs, 'missing data descriptor')
18360
@@ -495,6 +544,8 @@
18361
self.assertIn(('m', 'method', B), attrs, 'missing plain method')
18362
self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
18363
self.assertIn(('datablob', 'data', A), attrs, 'missing data')
18364
+ self.assertIn(('md', 'method', A), attrs, 'missing method descriptor')
18365
+ self.assertIn(('dd', 'data', A), attrs, 'missing data descriptor')
18369
@@ -508,6 +559,8 @@
18370
self.assertIn(('m', 'method', C), attrs, 'missing plain method')
18371
self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
18372
self.assertIn(('datablob', 'data', A), attrs, 'missing data')
18373
+ self.assertIn(('md', 'method', A), attrs, 'missing method descriptor')
18374
+ self.assertIn(('dd', 'data', A), attrs, 'missing data descriptor')
18378
@@ -522,6 +575,8 @@
18379
self.assertIn(('m', 'method', B), attrs, 'missing plain method')
18380
self.assertIn(('m1', 'method', D), attrs, 'missing plain method')
18381
self.assertIn(('datablob', 'data', A), attrs, 'missing data')
18382
+ self.assertIn(('md', 'method', A), attrs, 'missing method descriptor')
18383
+ self.assertIn(('dd', 'data', A), attrs, 'missing data descriptor')
18386
def test_classify_oldstyle(self):
18387
@@ -537,6 +592,64 @@
18389
self._classify_test(True)
18391
+ def test_classify_builtin_types(self):
18392
+ # Simple sanity check that all built-in types can have their
18393
+ # attributes classified.
18394
+ for name in dir(__builtin__):
18395
+ builtin = getattr(__builtin__, name)
18396
+ if isinstance(builtin, type):
18397
+ inspect.classify_class_attrs(builtin)
18399
+ def test_getmembers_descriptors(self):
18400
+ # Old-style classes
18402
+ dd = _BrokenDataDescriptor()
18403
+ md = _BrokenMethodDescriptor()
18405
+ self.assertEqual(inspect.getmembers(A, inspect.ismethoddescriptor),
18406
+ [('md', A.__dict__['md'])])
18407
+ self.assertEqual(inspect.getmembers(A, inspect.isdatadescriptor),
18408
+ [('dd', A.__dict__['dd'])])
18413
+ self.assertEqual(inspect.getmembers(B, inspect.ismethoddescriptor),
18414
+ [('md', A.__dict__['md'])])
18415
+ self.assertEqual(inspect.getmembers(B, inspect.isdatadescriptor),
18416
+ [('dd', A.__dict__['dd'])])
18418
+ # New-style classes
18420
+ dd = _BrokenDataDescriptor()
18421
+ md = _BrokenMethodDescriptor()
18423
+ def pred_wrapper(pred):
18424
+ # A quick'n'dirty way to discard standard attributes of new-style
18426
+ class Empty(object):
18429
+ if hasattr(x, '__name__') and hasattr(Empty, x.__name__):
18434
+ ismethoddescriptor = pred_wrapper(inspect.ismethoddescriptor)
18435
+ isdatadescriptor = pred_wrapper(inspect.isdatadescriptor)
18437
+ self.assertEqual(inspect.getmembers(A, ismethoddescriptor),
18438
+ [('md', A.__dict__['md'])])
18439
+ self.assertEqual(inspect.getmembers(A, isdatadescriptor),
18440
+ [('dd', A.__dict__['dd'])])
18445
+ self.assertEqual(inspect.getmembers(B, ismethoddescriptor),
18446
+ [('md', A.__dict__['md'])])
18447
+ self.assertEqual(inspect.getmembers(B, isdatadescriptor),
18448
+ [('dd', A.__dict__['dd'])])
18451
class TestGetcallargsFunctions(unittest.TestCase):
16603
18452
diff -r 8527427914a2 Lib/test/test_io.py
16604
18453
--- a/Lib/test/test_io.py
16605
18454
+++ b/Lib/test/test_io.py
18266
20182
def test_DER_to_PEM(self):
18267
20183
with open(SVN_PYTHON_ORG_ROOT_CERT, 'r') as f:
18268
@@ -966,6 +983,8 @@
20184
@@ -400,10 +417,11 @@
20185
ca_certs=self.server.cacerts,
20186
cert_reqs=self.server.certreqs,
20187
ciphers=self.server.ciphers)
20188
- except ssl.SSLError:
20189
+ except ssl.SSLError as e:
20190
# XXX Various errors can have happened here, for example
20191
# a mismatching protocol version, an invalid certificate,
20192
# or a low-level bug. This should be made more discriminating.
20193
+ self.server.conn_errors.append(e)
20194
if self.server.chatty:
20195
handle_error("\n server: bad connection attempt from " +
20196
str(self.sock.getpeername()) + ":\n")
20197
@@ -512,9 +530,19 @@
20198
sys.stdout.write(' server: wrapped server socket as %s\n' % str(self.sock))
20199
self.port = test_support.bind_port(self.sock)
20200
self.active = False
20201
+ self.conn_errors = []
20202
threading.Thread.__init__(self)
20205
+ def __enter__(self):
20206
+ self.start(threading.Event())
20210
+ def __exit__(self, *args):
20214
def start(self, flag=None):
20216
threading.Thread.start(self)
20217
@@ -621,6 +649,21 @@
20219
return "<%s %s>" % (self.__class__.__name__, self.server)
20221
+ def __enter__(self):
20222
+ self.start(threading.Event())
20226
+ def __exit__(self, *args):
20227
+ if test_support.verbose:
20228
+ sys.stdout.write(" cleanup: stopping server.\n")
20230
+ if test_support.verbose:
20231
+ sys.stdout.write(" cleanup: joining server thread.\n")
20233
+ if test_support.verbose:
20234
+ sys.stdout.write(" cleanup: successfully joined.\n")
20236
def start(self, flag=None):
20238
threading.Thread.start(self)
20239
@@ -735,12 +778,7 @@
20240
server = ThreadedEchoServer(CERTFILE,
20241
certreqs=ssl.CERT_REQUIRED,
20242
cacerts=CERTFILE, chatty=False)
20243
- flag = threading.Event()
20244
- server.start(flag)
20245
- # wait for it to start
20251
s = ssl.wrap_socket(socket.socket(),
20253
@@ -754,9 +792,6 @@
20254
sys.stdout.write("\nsocket.error is %s\n" % x[1])
20256
raise AssertionError("Use of invalid cert should have failed!")
20261
def server_params_test(certfile, protocol, certreqs, cacertsfile,
20262
client_certfile, client_protocol=None, indata="FOO\n",
20263
@@ -774,14 +809,10 @@
20265
connectionchatty=connectionchatty,
20266
wrap_accepting_socket=wrap_accepting_socket)
20267
- flag = threading.Event()
20268
- server.start(flag)
20269
- # wait for it to start
20272
- if client_protocol is None:
20273
- client_protocol = protocol
20277
+ if client_protocol is None:
20278
+ client_protocol = protocol
20279
s = ssl.wrap_socket(socket.socket(),
20280
certfile=client_certfile,
20281
ca_certs=cacertsfile,
20282
@@ -809,9 +840,6 @@
20283
if test_support.verbose:
20284
sys.stdout.write(" client: closing connection.\n")
20290
def try_protocol_combo(server_protocol,
20292
@@ -913,12 +941,7 @@
20293
ssl_version=ssl.PROTOCOL_SSLv23,
20296
- flag = threading.Event()
20297
- server.start(flag)
20298
- # wait for it to start
20303
s = ssl.wrap_socket(socket.socket(),
20306
@@ -940,9 +963,6 @@
20307
"Missing or invalid 'organizationName' field in certificate subject; "
20308
"should be 'Python Software Foundation'.")
20314
def test_empty_cert(self):
20315
"""Connecting with an empty cert file"""
20316
@@ -966,6 +986,8 @@
18269
20317
"""Connecting to an SSLv2 server with various client options"""
18270
20318
if test_support.verbose:
18271
20319
sys.stdout.write("\n")
18306
20354
def test_starttls(self):
18307
20355
"""Switching from clear text to encrypted and back again."""
18308
@@ -1329,15 +1338,18 @@
20356
@@ -1033,13 +1045,8 @@
20357
starttls_server=True,
20359
connectionchatty=True)
20360
- flag = threading.Event()
20361
- server.start(flag)
20362
- # wait for it to start
20368
s = socket.socket()
20370
s.connect((HOST, server.port))
20371
@@ -1084,9 +1091,6 @@
20379
def test_socketserver(self):
20380
"""Using a SocketServer to create and manage SSL connections."""
20381
@@ -1136,12 +1140,7 @@
20382
if test_support.verbose:
20383
sys.stdout.write("\n")
20384
server = AsyncoreEchoServer(CERTFILE)
20385
- flag = threading.Event()
20386
- server.start(flag)
20387
- # wait for it to start
20392
s = ssl.wrap_socket(socket.socket())
20393
s.connect(('127.0.0.1', server.port))
20394
if test_support.verbose:
20395
@@ -1160,10 +1159,6 @@
20396
if test_support.verbose:
20397
sys.stdout.write(" client: closing connection.\n")
20401
- # wait for server thread to end
20404
def test_recv_send(self):
20405
"""Test recv(), send() and friends."""
20406
@@ -1176,19 +1171,14 @@
20409
connectionchatty=False)
20410
- flag = threading.Event()
20411
- server.start(flag)
20412
- # wait for it to start
20415
- s = ssl.wrap_socket(socket.socket(),
20416
- server_side=False,
20417
- certfile=CERTFILE,
20418
- ca_certs=CERTFILE,
20419
- cert_reqs=ssl.CERT_NONE,
20420
- ssl_version=ssl.PROTOCOL_TLSv1)
20421
- s.connect((HOST, server.port))
20424
+ s = ssl.wrap_socket(socket.socket(),
20425
+ server_side=False,
20426
+ certfile=CERTFILE,
20427
+ ca_certs=CERTFILE,
20428
+ cert_reqs=ssl.CERT_NONE,
20429
+ ssl_version=ssl.PROTOCOL_TLSv1)
20430
+ s.connect((HOST, server.port))
20431
# helper methods for standardising recv* method signatures
20433
b = bytearray("\0"*100)
20434
@@ -1276,9 +1266,6 @@
20436
s.write("over\n".encode("ASCII", "strict"))
20442
def test_handshake_timeout(self):
20443
# Issue #5103: SSL handshake must respect the socket timeout
20444
@@ -1327,17 +1314,39 @@
20448
+ def test_default_ciphers(self):
20449
+ with ThreadedEchoServer(CERTFILE,
20450
+ ssl_version=ssl.PROTOCOL_SSLv23,
20451
+ chatty=False) as server:
20452
+ sock = socket.socket()
20454
+ # Force a set of weak ciphers on our client socket
20456
+ s = ssl.wrap_socket(sock,
20457
+ ssl_version=ssl.PROTOCOL_SSLv23,
20459
+ except ssl.SSLError:
20460
+ self.skipTest("no DES cipher available")
20461
+ with self.assertRaises((OSError, ssl.SSLError)):
20462
+ s.connect((HOST, server.port))
20465
+ self.assertIn("no shared cipher", str(server.conn_errors[0]))
18311
20468
def test_main(verbose=False):
18312
20469
- global CERTFILE, SVN_PYTHON_ORG_ROOT_CERT
20277
22519
# Standard values:
20278
22520
self.compress_type = ZIP_STORED # Type of compression for the file
20279
22521
self.comment = "" # Comment for each file
22522
diff -r 8527427914a2 Mac/IDLE/Info.plist.in
22523
--- a/Mac/IDLE/Info.plist.in
22524
+++ b/Mac/IDLE/Info.plist.in
22526
<key>CFBundleExecutable</key>
22527
<string>IDLE</string>
22528
<key>CFBundleGetInfoString</key>
22529
- <string>%VERSION%, © 2001-2011 Python Software Foundation</string>
22530
+ <string>%VERSION%, © 2001-2012 Python Software Foundation</string>
22531
<key>CFBundleIconFile</key>
22532
<string>IDLE.icns</string>
22533
<key>CFBundleIdentifier</key>
22534
diff -r 8527427914a2 Mac/PythonLauncher/Info.plist.in
22535
--- a/Mac/PythonLauncher/Info.plist.in
22536
+++ b/Mac/PythonLauncher/Info.plist.in
22538
<key>CFBundleExecutable</key>
22539
<string>PythonLauncher</string>
22540
<key>CFBundleGetInfoString</key>
22541
- <string>%VERSION%, © 2001-2011 Python Software Foundation</string>
22542
+ <string>%VERSION%, © 2001-2012 Python Software Foundation</string>
22543
<key>CFBundleIconFile</key>
22544
<string>PythonLauncher.icns</string>
22545
<key>CFBundleIdentifier</key>
22546
diff -r 8527427914a2 Mac/Resources/app/Info.plist.in
22547
--- a/Mac/Resources/app/Info.plist.in
22548
+++ b/Mac/Resources/app/Info.plist.in
22550
<key>CFBundleExecutable</key>
22551
<string>Python</string>
22552
<key>CFBundleGetInfoString</key>
22553
- <string>%version%, (c) 2004-2011 Python Software Foundation.</string>
22554
+ <string>%version%, (c) 2004-2012 Python Software Foundation.</string>
22555
<key>CFBundleHelpBookFolder</key>
22557
<string>Documentation</string>
22559
<key>CFBundleInfoDictionaryVersion</key>
22560
<string>6.0</string>
22561
<key>CFBundleLongVersionString</key>
22562
- <string>%version%, (c) 2004-2011 Python Software Foundation.</string>
22563
+ <string>%version%, (c) 2004-2012 Python Software Foundation.</string>
22564
<key>CFBundleName</key>
22565
<string>Python</string>
22566
<key>CFBundlePackageType</key>
22568
<key>NSAppleScriptEnabled</key>
22570
<key>NSHumanReadableCopyright</key>
22571
- <string>(c) 2011 Python Software Foundation.</string>
22572
+ <string>(c) 2012 Python Software Foundation.</string>
22575
diff -r 8527427914a2 Mac/Resources/framework/Info.plist.in
22576
--- a/Mac/Resources/framework/Info.plist.in
22577
+++ b/Mac/Resources/framework/Info.plist.in
22579
<key>CFBundlePackageType</key>
22580
<string>FMWK</string>
22581
<key>CFBundleShortVersionString</key>
22582
- <string>%VERSION%, (c) 2004-2011 Python Software Foundation.</string>
22583
+ <string>%VERSION%, (c) 2004-2012 Python Software Foundation.</string>
22584
<key>CFBundleLongVersionString</key>
22585
- <string>%VERSION%, (c) 2004-2011 Python Software Foundation.</string>
22586
+ <string>%VERSION%, (c) 2004-2012 Python Software Foundation.</string>
22587
<key>CFBundleSignature</key>
22588
<string>????</string>
22589
<key>CFBundleVersion</key>
20280
22590
diff -r 8527427914a2 Makefile.pre.in
20281
22591
--- a/Makefile.pre.in
20282
22592
+++ b/Makefile.pre.in
23402
25874
Py_INCREF(Py_None);
23403
25875
return Py_None;
25877
diff -r 8527427914a2 README
25881
This is Python version 2.7.2
25882
============================
25884
-Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
25885
-Python Software Foundation. All rights reserved.
25886
+Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
25887
+2012 Python Software Foundation. All rights reserved.
25889
Copyright (c) 2000 BeOpen.com.
25890
All rights reserved.
25891
diff -r 8527427914a2 Tools/gdb/libpython.py
25892
--- a/Tools/gdb/libpython.py
25893
+++ b/Tools/gdb/libpython.py
25895
_type_char_ptr = gdb.lookup_type('char').pointer() # char*
25896
_type_unsigned_char_ptr = gdb.lookup_type('unsigned char').pointer() # unsigned char*
25897
_type_void_ptr = gdb.lookup_type('void').pointer() # void*
25898
-_type_size_t = gdb.lookup_type('size_t')
25900
SIZEOF_VOID_P = _type_void_ptr.sizeof
25902
@@ -410,11 +409,15 @@
25905
def _PyObject_VAR_SIZE(typeobj, nitems):
25906
+ if _PyObject_VAR_SIZE._type_size_t is None:
25907
+ _PyObject_VAR_SIZE._type_size_t = gdb.lookup_type('size_t')
25909
return ( ( typeobj.field('tp_basicsize') +
25910
nitems * typeobj.field('tp_itemsize') +
25911
(SIZEOF_VOID_P - 1)
25912
) & ~(SIZEOF_VOID_P - 1)
25913
- ).cast(_type_size_t)
25914
+ ).cast(_PyObject_VAR_SIZE._type_size_t)
25915
+_PyObject_VAR_SIZE._type_size_t = None
25917
class HeapTypeObjectPtr(PyObjectPtr):
25918
_typename = 'PyObject'
25919
@@ -786,7 +789,7 @@
25920
class PyFrameObjectPtr(PyObjectPtr):
25921
_typename = 'PyFrameObject'
25923
- def __init__(self, gdbval, cast_to):
25924
+ def __init__(self, gdbval, cast_to=None):
25925
PyObjectPtr.__init__(self, gdbval, cast_to)
25927
if not self.is_optimized_out():
25928
@@ -820,7 +823,7 @@
25929
the global variables of this frame
25931
if self.is_optimized_out():
25935
pyop_globals = self.pyop_field('f_globals')
25936
return pyop_globals.iteritems()
25937
@@ -831,7 +834,7 @@
25938
the builtin variables
25940
if self.is_optimized_out():
25944
pyop_builtins = self.pyop_field('f_builtins')
25945
return pyop_builtins.iteritems()
25946
@@ -1205,7 +1208,20 @@
25947
def get_pyop(self):
25949
f = self._gdbframe.read_var('f')
25950
- return PyFrameObjectPtr.from_pyobject_ptr(f)
25951
+ frame = PyFrameObjectPtr.from_pyobject_ptr(f)
25952
+ if not frame.is_optimized_out():
25954
+ # gdb is unable to get the "f" argument of PyEval_EvalFrameEx()
25955
+ # because it was "optimized out". Try to get "f" from the frame
25956
+ # of the caller, PyEval_EvalCodeEx().
25957
+ orig_frame = frame
25958
+ caller = self._gdbframe.older()
25960
+ f = caller.read_var('f')
25961
+ frame = PyFrameObjectPtr.from_pyobject_ptr(f)
25962
+ if not frame.is_optimized_out():
25964
+ return orig_frame
25968
@@ -1235,7 +1251,9 @@
25969
pyop = self.get_pyop()
25971
sys.stdout.write('#%i %s\n' % (self.get_index(), pyop.get_truncated_repr(MAX_OUTPUT_LEN)))
25972
- sys.stdout.write(pyop.current_line())
25973
+ if not pyop.is_optimized_out():
25974
+ line = pyop.current_line()
25975
+ sys.stdout.write(' %s\n' % line.strip())
25977
sys.stdout.write('#%i (unable to read python frame information)\n' % self.get_index())
25979
@@ -1281,7 +1299,7 @@
25982
pyop = frame.get_pyop()
25984
+ if not pyop or pyop.is_optimized_out():
25985
print 'Unable to read information on python frame'
23405
25988
diff -r 8527427914a2 Tools/iobench/iobench.py
23406
25989
--- a/Tools/iobench/iobench.py
23407
25990
+++ b/Tools/iobench/iobench.py