1
# DP: hg updates of the 3.2 release branch (until 2012-02-16).
3
# hg diff -r v3.2.2 | filterdiff --exclude=Lib/pstats.py --exclude=Lib/profile.py --exclude=.hgignore --exclude=.hgeol --exclude=.hgtags --remove-timestamps
5
diff -r 137e45f15c0b Doc/ACKS.txt
19
* Hernán Martínez Foffani
30
* Steffen Daode Nurpmeso
54
diff -r 137e45f15c0b Doc/README.txt
58
as long as you don't change or remove the copyright notice:
60
----------------------------------------------------------------------
61
-Copyright (c) 2000-2011 Python Software Foundation.
62
+Copyright (c) 2000-2012 Python Software Foundation.
65
Copyright (c) 2000 BeOpen.com.
66
diff -r 137e45f15c0b Doc/bugs.rst
71
Each bug report will be assigned to a developer who will determine what needs to
72
be done to correct the problem. You will receive an update each time action is
73
-taken on the bug. See http://www.python.org/dev/workflow/ for a detailed
74
-description of the issue workflow.
80
+ `Python Developer's Guide <http://docs.python.org/devguide/>`_
81
+ Detailed description of the issue workflow and developers tools.
83
`How to Report Bugs Effectively <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>`_
84
Article which goes into some detail about how to create a useful bug report.
85
This describes what kind of information is useful and why it is useful.
86
diff -r 137e45f15c0b Doc/c-api/code.rst
87
--- a/Doc/c-api/code.rst
88
+++ b/Doc/c-api/code.rst
91
Return the number of free variables in *co*.
93
-.. c:function:: PyCodeObject *PyCode_New(int argcount, int nlocals, int stacksize, int flags, PyObject *code, PyObject *consts, PyObject *names, PyObject *varnames, PyObject *freevars, PyObject *cellvars, PyObject *filename, PyObject *name, int firstlineno, PyObject *lnotab)
94
+.. c:function:: PyCodeObject *PyCode_New(int argcount, int kwonlyargcount, int nlocals, int stacksize, int flags, PyObject *code, PyObject *consts, PyObject *names, PyObject *varnames, PyObject *freevars, PyObject *cellvars, PyObject *filename, PyObject *name, int firstlineno, PyObject *lnotab)
96
Return a new code object. If you need a dummy code object to
97
create a frame, use :c:func:`PyCode_NewEmpty` instead. Calling
98
diff -r 137e45f15c0b Doc/c-api/complex.rst
99
--- a/Doc/c-api/complex.rst
100
+++ b/Doc/c-api/complex.rst
102
Return the quotient of two complex numbers, using the C :c:type:`Py_complex`
105
+ If *divisor* is null, this method returns zero and sets
106
+ :c:data:`errno` to :c:data:`EDOM`.
109
.. c:function:: Py_complex _Py_c_pow(Py_complex num, Py_complex exp)
111
Return the exponentiation of *num* by *exp*, using the C :c:type:`Py_complex`
114
+ If *num* is null and *exp* is not a positive real number,
115
+ this method returns zero and sets :c:data:`errno` to :c:data:`EDOM`.
118
Complex Numbers as Python Objects
119
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
122
If *op* is not a Python complex number object but has a :meth:`__complex__`
123
method, this method will first be called to convert *op* to a Python complex
125
+ number object. Upon failure, this method returns ``-1.0`` as a real value.
126
diff -r 137e45f15c0b Doc/c-api/float.rst
127
--- a/Doc/c-api/float.rst
128
+++ b/Doc/c-api/float.rst
130
Return a C :c:type:`double` representation of the contents of *pyfloat*. If
131
*pyfloat* is not a Python floating point object but has a :meth:`__float__`
132
method, this method will first be called to convert *pyfloat* into a float.
133
+ This method returns ``-1.0`` upon failure, so one should call
134
+ :c:func:`PyErr_Occurred` to check for errors.
137
.. c:function:: double PyFloat_AS_DOUBLE(PyObject *pyfloat)
138
diff -r 137e45f15c0b Doc/c-api/init.rst
139
--- a/Doc/c-api/init.rst
140
+++ b/Doc/c-api/init.rst
143
Initialize the Python interpreter. In an application embedding Python, this
144
should be called before using any other Python/C API functions; with the
145
- exception of :c:func:`Py_SetProgramName` and :c:func:`Py_SetPath`. This initializes
146
+ exception of :c:func:`Py_SetProgramName`, :c:func:`Py_SetPythonHome` and :c:func:`Py_SetPath`. This initializes
147
the table of loaded modules (``sys.modules``), and creates the fundamental
148
modules :mod:`builtins`, :mod:`__main__` and :mod:`sys`. It also initializes
149
the module search path (``sys.path``). It does not set ``sys.argv``; use
150
diff -r 137e45f15c0b Doc/c-api/intro.rst
151
--- a/Doc/c-api/intro.rst
152
+++ b/Doc/c-api/intro.rst
153
@@ -246,17 +246,19 @@
155
set_all(PyObject *target, PyObject *item)
160
n = PyObject_Length(target);
163
for (i = 0; i < n; i++) {
164
- PyObject *index = PyLong_FromLong(i);
165
+ PyObject *index = PyLong_FromSsize_t(i);
168
- if (PyObject_SetItem(target, index, item) < 0)
169
+ if (PyObject_SetItem(target, index, item) < 0) {
178
sum_list(PyObject *list)
183
+ long total = 0, value;
186
n = PyList_Size(list);
188
for (i = 0; i < n; i++) {
189
item = PyList_GetItem(list, i); /* Can't fail */
190
if (!PyLong_Check(item)) continue; /* Skip non-integers */
191
- total += PyLong_AsLong(item);
192
+ value = PyLong_AsLong(item);
193
+ if (value == -1 && PyErr_Occurred())
194
+ /* Integer too big to fit in a C long, bail out */
202
sum_sequence(PyObject *sequence)
207
+ long total = 0, value;
209
n = PySequence_Length(sequence);
212
item = PySequence_GetItem(sequence, i);
214
return -1; /* Not a sequence, or other failure */
215
- if (PyLong_Check(item))
216
- total += PyLong_AsLong(item);
217
- Py_DECREF(item); /* Discard reference ownership */
218
+ if (PyLong_Check(item)) {
219
+ value = PyLong_AsLong(item);
221
+ if (value == -1 && PyErr_Occurred())
222
+ /* Integer too big to fit in a C long, bail out */
227
+ Py_DECREF(item); /* Discard reference ownership */
232
diff -r 137e45f15c0b Doc/c-api/memoryview.rst
233
--- a/Doc/c-api/memoryview.rst
234
+++ b/Doc/c-api/memoryview.rst
237
Create a memoryview object from an object that provides the buffer interface.
238
If *obj* supports writable buffer exports, the memoryview object will be
239
- readable and writable, other it will be read-only.
240
+ readable and writable, otherwise it will be read-only.
243
.. c:function:: PyObject *PyMemoryView_FromBuffer(Py_buffer *view)
245
Create a memoryview object to a contiguous chunk of memory (in either
246
'C' or 'F'ortran *order*) from an object that defines the buffer
247
interface. If memory is contiguous, the memoryview object points to the
248
- original memory. Otherwise copy is made and the memoryview points to a
249
+ original memory. Otherwise, a copy is made and the memoryview points to a
253
diff -r 137e45f15c0b Doc/c-api/method.rst
254
--- a/Doc/c-api/method.rst
255
+++ b/Doc/c-api/method.rst
257
.. c:function:: PyObject* PyInstanceMethod_New(PyObject *func)
259
Return a new instance method object, with *func* being any callable object
260
- *func* is is the function that will be called when the instance method is
261
+ *func* is the function that will be called when the instance method is
266
.. c:function:: PyObject* PyMethod_New(PyObject *func, PyObject *self)
268
Return a new method object, with *func* being any callable object and *self*
269
- the instance the method should be bound. *func* is is the function that will
270
+ the instance the method should be bound. *func* is the function that will
271
be called when the method is called. *self* must not be *NULL*.
274
diff -r 137e45f15c0b Doc/c-api/number.rst
275
--- a/Doc/c-api/number.rst
276
+++ b/Doc/c-api/number.rst
277
@@ -239,10 +239,10 @@
279
.. c:function:: PyObject* PyNumber_ToBase(PyObject *n, int base)
281
- Returns the integer *n* converted to *base* as a string with a base
282
- marker of ``'0b'``, ``'0o'``, or ``'0x'`` if applicable. When
283
- *base* is not 2, 8, 10, or 16, the format is ``'x#num'`` where x is the
284
- base. If *n* is not an int object, it is converted with
285
+ Returns the integer *n* converted to base *base* as a string. The *base*
286
+ argument must be one of 2, 8, 10, or 16. For base 2, 8, or 16, the
287
+ returned string is prefixed with a base marker of ``'0b'``, ``'0o'``, or
288
+ ``'0x'``, respectively. If *n* is not a Python int, it is converted with
289
:c:func:`PyNumber_Index` first.
292
diff -r 137e45f15c0b Doc/c-api/unicode.rst
293
--- a/Doc/c-api/unicode.rst
294
+++ b/Doc/c-api/unicode.rst
295
@@ -338,16 +338,21 @@
297
.. c:function:: Py_UNICODE* PyUnicode_AsUnicode(PyObject *unicode)
299
- Return a read-only pointer to the Unicode object's internal :c:type:`Py_UNICODE`
300
- buffer, *NULL* if *unicode* is not a Unicode object.
301
+ Return a read-only pointer to the Unicode object's internal
302
+ :c:type:`Py_UNICODE` buffer, *NULL* if *unicode* is not a Unicode object.
303
+ Note that the resulting :c:type:`Py_UNICODE*` string may contain embedded
304
+ null characters, which would cause the string to be truncated when used in
308
.. c:function:: Py_UNICODE* PyUnicode_AsUnicodeCopy(PyObject *unicode)
310
Create a copy of a Unicode string ending with a nul character. Return *NULL*
311
and raise a :exc:`MemoryError` exception on memory allocation failure,
312
- otherwise return a new allocated buffer (use :c:func:`PyMem_Free` to free the
314
+ otherwise return a new allocated buffer (use :c:func:`PyMem_Free` to free
315
+ the buffer). Note that the resulting :c:type:`Py_UNICODE*` string may contain
316
+ embedded null characters, which would cause the string to be truncated when
317
+ used in most C functions.
319
.. versionadded:: 3.2
323
Encode a Unicode object to :c:data:`Py_FileSystemDefaultEncoding` with the
324
``'surrogateescape'`` error handler, or ``'strict'`` on Windows, and return
326
+ :class:`bytes`. Note that the resulting :class:`bytes` object may contain
329
If :c:data:`Py_FileSystemDefaultEncoding` is not set, fall back to the
332
copied or -1 in case of an error. Note that the resulting :c:type:`wchar_t`
333
string may or may not be 0-terminated. It is the responsibility of the caller
334
to make sure that the :c:type:`wchar_t` string is 0-terminated in case this is
335
- required by the application.
336
+ required by the application. Also, note that the :c:type:`wchar_t*` string
337
+ might contain null characters, which would cause the string to be truncated
338
+ when used with most C functions.
341
.. c:function:: wchar_t* PyUnicode_AsWideCharString(PyObject *unicode, Py_ssize_t *size)
343
of wide characters (excluding the trailing 0-termination character) into
346
- Returns a buffer allocated by :c:func:`PyMem_Alloc` (use :c:func:`PyMem_Free`
347
- to free it) on success. On error, returns *NULL*, *\*size* is undefined and
348
- raises a :exc:`MemoryError`.
349
+ Returns a buffer allocated by :c:func:`PyMem_Alloc` (use
350
+ :c:func:`PyMem_Free` to free it) on success. On error, returns *NULL*,
351
+ *\*size* is undefined and raises a :exc:`MemoryError`. Note that the
352
+ resulting :c:type:`wchar_t*` string might contain null characters, which
353
+ would cause the string to be truncated when used with most C functions.
355
.. versionadded:: 3.2
357
diff -r 137e45f15c0b Doc/conf.py
361
'The Python/C API', _stdauthor, 'manual'),
362
('distutils/index', 'distutils.tex',
363
'Distributing Python Modules', _stdauthor, 'manual'),
364
- ('documenting/index', 'documenting.tex',
365
- 'Documenting Python', 'Georg Brandl', 'manual'),
366
('extending/index', 'extending.tex',
367
'Extending and Embedding Python', _stdauthor, 'manual'),
368
('install/index', 'install.tex',
369
diff -r 137e45f15c0b Doc/contents.rst
370
--- a/Doc/contents.rst
371
+++ b/Doc/contents.rst
376
- documenting/index.rst
380
diff -r 137e45f15c0b Doc/copyright.rst
381
--- a/Doc/copyright.rst
382
+++ b/Doc/copyright.rst
385
Python and this documentation is:
387
-Copyright © 2001-2011 Python Software Foundation. All rights reserved.
388
+Copyright © 2001-2012 Python Software Foundation. All rights reserved.
390
Copyright © 2000 BeOpen.com. All rights reserved.
392
diff -r 137e45f15c0b Doc/data/refcounts.dat
393
--- a/Doc/data/refcounts.dat
394
+++ b/Doc/data/refcounts.dat
396
PyEval_EvalCode:PyObject*:globals:0:
397
PyEval_EvalCode:PyObject*:locals:0:
399
+PyException_GetTraceback:PyObject*::+1:
401
PyFile_AsFile:FILE*:::
402
PyFile_AsFile:PyFileObject*:p:0:
404
diff -r 137e45f15c0b Doc/distutils/apiref.rst
405
--- a/Doc/distutils/apiref.rst
406
+++ b/Doc/distutils/apiref.rst
408
+====================+================================+=============================================================+
409
| *name* | The name of the package | a string |
410
+--------------------+--------------------------------+-------------------------------------------------------------+
411
- | *version* | The version number of the | See :mod:`distutils.version` |
413
+ | *version* | The version number of the | a string |
414
+ | | package; see | |
415
+ | | :mod:`distutils.version` | |
416
+--------------------+--------------------------------+-------------------------------------------------------------+
417
| *description* | A single line describing the | a string |
420
| | maintainer, if different from | |
422
+--------------------+--------------------------------+-------------------------------------------------------------+
423
- | *maintainer_email* | The email address of the | |
424
+ | *maintainer_email* | The email address of the | a string |
425
| | current maintainer, if | |
426
| | different from the author | |
427
+--------------------+--------------------------------+-------------------------------------------------------------+
428
- | *url* | A URL for the package | a URL |
429
+ | *url* | A URL for the package | a string |
431
+--------------------+--------------------------------+-------------------------------------------------------------+
432
- | *download_url* | A URL to download the package | a URL |
433
+ | *download_url* | A URL to download the package | a string |
434
+--------------------+--------------------------------+-------------------------------------------------------------+
435
| *packages* | A list of Python packages that | a list of strings |
436
| | distutils will manipulate | |
438
| | files to be built and | |
440
+--------------------+--------------------------------+-------------------------------------------------------------+
441
- | *ext_modules* | A list of Python extensions to | A list of instances of |
442
+ | *ext_modules* | A list of Python extensions to | a list of instances of |
443
| | be built | :class:`distutils.core.Extension` |
444
+--------------------+--------------------------------+-------------------------------------------------------------+
445
- | *classifiers* | A list of categories for the | The list of available |
446
- | | package | categorizations is available on `PyPI |
447
- | | | <http://pypi.python.org/pypi?:action=list_classifiers>`_. |
448
+ | *classifiers* | A list of categories for the | a list of strings; valid classifiers are listed on `PyPI |
449
+ | | package | <http://pypi.python.org/pypi?:action=list_classifiers>`_. |
450
+--------------------+--------------------------------+-------------------------------------------------------------+
451
- | *distclass* | the :class:`Distribution` | A subclass of |
452
+ | *distclass* | the :class:`Distribution` | a subclass of |
453
| | class to use | :class:`distutils.core.Distribution` |
454
+--------------------+--------------------------------+-------------------------------------------------------------+
455
| *script_name* | The name of the setup.py | a string |
457
| *script_args* | Arguments to supply to the | a list of strings |
459
+--------------------+--------------------------------+-------------------------------------------------------------+
460
- | *options* | default options for the setup | a string |
461
+ | *options* | default options for the setup | a dictionary |
463
+--------------------+--------------------------------+-------------------------------------------------------------+
464
| *license* | The license for the package | a string |
465
+--------------------+--------------------------------+-------------------------------------------------------------+
466
- | *keywords* | Descriptive meta-data, see | |
467
+ | *keywords* | Descriptive meta-data, see | a list of strings or a comma-separated string |
469
+--------------------+--------------------------------+-------------------------------------------------------------+
470
- | *platforms* | | |
471
+ | *platforms* | | a list of strings or a comma-separated string |
472
+--------------------+--------------------------------+-------------------------------------------------------------+
473
| *cmdclass* | A mapping of command names to | a dictionary |
474
| | :class:`Command` subclasses | |
475
@@ -165,13 +165,13 @@
476
+------------------------+--------------------------------+---------------------------+
477
| argument name | value | type |
478
+========================+================================+===========================+
479
- | *name* | the full name of the | string |
480
+ | *name* | the full name of the | a string |
481
| | extension, including any | |
482
| | packages --- ie. *not* a | |
483
| | filename or pathname, but | |
484
| | Python dotted name | |
485
+------------------------+--------------------------------+---------------------------+
486
- | *sources* | list of source filenames, | string |
487
+ | *sources* | list of source filenames, | a list of strings |
488
| | relative to the distribution | |
489
| | root (where the setup script | |
490
| | lives), in Unix form (slash- | |
491
@@ -184,12 +184,12 @@
492
| | as source for a Python | |
494
+------------------------+--------------------------------+---------------------------+
495
- | *include_dirs* | list of directories to search | string |
496
+ | *include_dirs* | list of directories to search | a list of strings |
497
| | for C/C++ header files (in | |
498
| | Unix form for portability) | |
499
+------------------------+--------------------------------+---------------------------+
500
- | *define_macros* | list of macros to define; each | (string, string) tuple or |
501
- | | macro is defined using a | (name, ``None``) |
502
+ | *define_macros* | list of macros to define; each | a list of tuples |
503
+ | | macro is defined using a | |
504
| | 2-tuple ``(name, value)``, | |
505
| | where *value* is | |
506
| | either the string to define it | |
507
@@ -200,31 +200,31 @@
508
| | on Unix C compiler command | |
510
+------------------------+--------------------------------+---------------------------+
511
- | *undef_macros* | list of macros to undefine | string |
512
+ | *undef_macros* | list of macros to undefine | a list of strings |
514
+------------------------+--------------------------------+---------------------------+
515
- | *library_dirs* | list of directories to search | string |
516
+ | *library_dirs* | list of directories to search | a list of strings |
517
| | for C/C++ libraries at link | |
519
+------------------------+--------------------------------+---------------------------+
520
- | *libraries* | list of library names (not | string |
521
+ | *libraries* | list of library names (not | a list of strings |
522
| | filenames or paths) to link | |
524
+------------------------+--------------------------------+---------------------------+
525
- | *runtime_library_dirs* | list of directories to search | string |
526
+ | *runtime_library_dirs* | list of directories to search | a list of strings |
527
| | for C/C++ libraries at run | |
528
| | time (for shared extensions, | |
529
| | this is when the extension is | |
531
+------------------------+--------------------------------+---------------------------+
532
- | *extra_objects* | list of extra files to link | string |
533
+ | *extra_objects* | list of extra files to link | a list of strings |
534
| | with (eg. object files not | |
535
| | implied by 'sources', static | |
536
| | library that must be | |
537
| | explicitly specified, binary | |
538
| | resource files, etc.) | |
539
+------------------------+--------------------------------+---------------------------+
540
- | *extra_compile_args* | any extra platform- and | string |
541
+ | *extra_compile_args* | any extra platform- and | a list of strings |
542
| | compiler-specific information | |
543
| | to use when compiling the | |
544
| | source files in 'sources'. For | |
546
| | for other platforms it could | |
548
+------------------------+--------------------------------+---------------------------+
549
- | *extra_link_args* | any extra platform- and | string |
550
+ | *extra_link_args* | any extra platform- and | a list of strings |
551
| | compiler-specific information | |
552
| | to use when linking object | |
553
| | files together to create the | |
555
| | Similar interpretation as for | |
556
| | 'extra_compile_args'. | |
557
+------------------------+--------------------------------+---------------------------+
558
- | *export_symbols* | list of symbols to be exported | string |
559
+ | *export_symbols* | list of symbols to be exported | a list of strings |
560
| | from a shared extension. Not | |
561
| | used on all platforms, and not | |
562
| | generally necessary for Python | |
563
@@ -252,10 +252,10 @@
564
| | export exactly one symbol: | |
565
| | ``init`` + extension_name. | |
566
+------------------------+--------------------------------+---------------------------+
567
- | *depends* | list of files that the | string |
568
+ | *depends* | list of files that the | a list of strings |
569
| | extension depends on | |
570
+------------------------+--------------------------------+---------------------------+
571
- | *language* | extension language (i.e. | string |
572
+ | *language* | extension language (i.e. | a string |
573
| | ``'c'``, ``'c++'``, | |
574
| | ``'objc'``). Will be detected | |
575
| | from the source extensions if | |
577
Define a preprocessor macro for all compilations driven by this compiler object.
578
The optional parameter *value* should be a string; if it is not supplied, then
579
the macro will be defined without an explicit value and the exact outcome
580
- depends on the compiler used (XXX true? does ANSI say anything about this?)
581
+ depends on the compiler used.
583
+ .. XXX true? does ANSI say anything about this?
586
.. method:: CCompiler.undefine_macro(name)
589
*output_libname* should be a library name, not a filename; the filename will be
590
inferred from the library name. *output_dir* is the directory where the library
591
- file will be put. XXX defaults to what?
594
+ .. XXX defaults to what?
596
*debug* is a boolean; if true, debugging information will be included in the
597
library (note that on most platforms, it is the compile step where this matters:
598
@@ -723,30 +727,29 @@
600
Invokes :func:`distutils.util.execute` This method invokes a Python function
601
*func* with the given arguments *args*, after logging and taking into account
602
- the *dry_run* flag. XXX see also.
603
+ the *dry_run* flag.
606
.. method:: CCompiler.spawn(cmd)
608
Invokes :func:`distutils.util.spawn`. This invokes an external process to run
609
- the given command. XXX see also.
613
.. method:: CCompiler.mkpath(name[, mode=511])
615
Invokes :func:`distutils.dir_util.mkpath`. This creates a directory and any
616
- missing ancestor directories. XXX see also.
617
+ missing ancestor directories.
620
.. method:: CCompiler.move_file(src, dst)
622
- Invokes :meth:`distutils.file_util.move_file`. Renames *src* to *dst*. XXX see
624
+ Invokes :meth:`distutils.file_util.move_file`. Renames *src* to *dst*.
627
.. method:: CCompiler.announce(msg[, level=1])
629
- Write a message using :func:`distutils.log.debug`. XXX see also.
630
+ Write a message using :func:`distutils.log.debug`.
633
.. method:: CCompiler.warn(msg)
635
prefix of all files and directories in the archive. *root_dir* and *base_dir*
636
both default to the current directory. Returns the name of the archive file.
638
- .. XXX This should be changed to support bz2 files.
641
.. function:: make_tarball(base_name, base_dir[, compress='gzip', verbose=0, dry_run=0])
644
possibly plus the appropriate compression extension (:file:`.gz`, :file:`.bz2`
645
or :file:`.Z`). Return the output filename.
647
- .. XXX This should be replaced with calls to the :mod:`tarfile` module.
650
.. function:: make_zipfile(base_name, base_dir[, verbose=0, dry_run=0])
653
errors are ignored (apart from being reported to ``sys.stdout`` if *verbose* is
656
-.. XXX Some of this could be replaced with the shutil module?
659
:mod:`distutils.file_util` --- Single file operations
660
=====================================================
661
@@ -1115,8 +1112,6 @@
663
* ``macosx-10.6-intel``
665
- .. % XXX isn't this also provided by some other non-distutils module?
668
.. function:: convert_path(pathname)
670
@@ -1204,9 +1199,9 @@
671
.. function:: byte_compile(py_files[, optimize=0, force=0, prefix=None, base_dir=None, verbose=1, dry_run=0, direct=None])
673
Byte-compile a collection of Python source files to either :file:`.pyc` or
674
- :file:`.pyo` files in the same directory. *py_files* is a list of files to
675
- compile; any files that don't end in :file:`.py` are silently skipped.
676
- *optimize* must be one of the following:
677
+ :file:`.pyo` files in a :file:`__pycache__` subdirectory (see :pep:`3147`).
678
+ *py_files* is a list of files to compile; any files that don't end in
679
+ :file:`.py` are silently skipped. *optimize* must be one of the following:
681
* ``0`` - don't optimize (generate :file:`.pyc`)
682
* ``1`` - normal optimization (like ``python -O``)
683
@@ -1231,6 +1226,11 @@
684
is used by the script generated in indirect mode; unless you know what you're
685
doing, leave it set to ``None``.
687
+ .. versionchanged:: 3.2.3
688
+ Create ``.pyc`` or ``.pyo`` files with an :func:`import magic tag
689
+ <imp.get_tag>` in their name, in a :file:`__pycache__` subdirectory
690
+ instead of files without tag in the current directory.
693
.. function:: rfc822_escape(header)
695
@@ -1316,8 +1316,6 @@
696
the "negative alias" of :option:`--verbose`, then :option:`--quiet` on the
697
command line sets *verbose* to false.
699
-.. XXX Should be replaced with optparse
701
.. function:: fancy_getopt(options, negative_opt, object, args)
703
Wrapper function. *options* is a list of ``(long_option, short_option,
704
@@ -1333,9 +1331,6 @@
706
Wraps *text* to less than *width* wide.
708
- .. XXX Should be replaced with :mod:`textwrap` (which is available in Python
712
.. class:: FancyGetopt([option_table=None])
714
@@ -1398,10 +1393,6 @@
715
:synopsis: A simple logging mechanism, 282-style
718
-.. XXX Should be replaced with standard :mod:`logging` module.
722
:mod:`distutils.spawn` --- Spawn a sub-process
723
==============================================
725
@@ -1740,7 +1731,7 @@
726
Set final values for all the options that this command supports. This is
727
always called as late as possible, ie. after any option assignments from the
728
command-line or from other commands have been done. Thus, this is the place
729
- to to code option dependencies: if *foo* depends on *bar*, then it is safe to
730
+ to code option dependencies: if *foo* depends on *bar*, then it is safe to
731
set *foo* from *bar* as long as *foo* still has the same value it was
732
assigned in :meth:`initialize_options`.
734
diff -r 137e45f15c0b Doc/distutils/introduction.rst
735
--- a/Doc/distutils/introduction.rst
736
+++ b/Doc/distutils/introduction.rst
739
python setup.py sdist
741
-For Windows, open a command prompt windows ("DOS box") and change the command
743
+For Windows, open a command prompt window (:menuselection:`Start -->
744
+Accessories`) and change the command to::
748
diff -r 137e45f15c0b Doc/distutils/setupscript.rst
749
--- a/Doc/distutils/setupscript.rst
750
+++ b/Doc/distutils/setupscript.rst
753
If you need to include header files from some other Python extension, you can
754
take advantage of the fact that header files are installed in a consistent way
755
-by the Distutils :command:`install_header` command. For example, the Numerical
756
+by the Distutils :command:`install_headers` command. For example, the Numerical
757
Python header files are installed (on a standard Unix installation) to
758
:file:`/usr/local/include/python1.5/Numerical`. (The exact location will differ
759
according to your platform and Python installation.) Since the Python include
760
diff -r 137e45f15c0b Doc/documenting/building.rst
761
--- a/Doc/documenting/building.rst
764
-Building the documentation
765
-==========================
767
-You need to have Python 2.4 or higher installed; the toolset used to build the
768
-docs is written in Python. It is called *Sphinx*, it is not included in this
769
-tree, but maintained separately. Also needed are the docutils, supplying the
770
-base markup that Sphinx uses, Jinja, a templating engine, and optionally
771
-Pygments, a code highlighter.
777
-Luckily, a Makefile has been prepared so that on Unix, provided you have
778
-installed Python and Subversion, you can just run ::
783
-to check out the necessary toolset in the :file:`tools/` subdirectory and build
784
-the HTML output files. To view the generated HTML, point your favorite browser
785
-at the top-level index :file:`build/html/index.html` after running "make".
787
-Available make targets are:
789
- * "html", which builds standalone HTML files for offline viewing.
791
- * "htmlhelp", which builds HTML files and a HTML Help project file usable to
792
- convert them into a single Compiled HTML (.chm) file -- these are popular
793
- under Microsoft Windows, but very handy on every platform.
795
- To create the CHM file, you need to run the Microsoft HTML Help Workshop
796
- over the generated project (.hhp) file.
798
- * "latex", which builds LaTeX source files as input to "pdflatex" to produce
801
- * "text", which builds a plain text file for each source file.
803
- * "linkcheck", which checks all external references to see whether they are
804
- broken, redirected or malformed, and outputs this information to stdout
805
- as well as a plain-text (.txt) file.
807
- * "changes", which builds an overview over all versionadded/versionchanged/
808
- deprecated items in the current version. This is meant as a help for the
809
- writer of the "What's New" document.
811
- * "coverage", which builds a coverage overview for standard library modules
814
- * "pydoc-topics", which builds a Python module containing a dictionary with
815
- plain text documentation for the labels defined in
816
- :file:`tools/sphinxext/pyspecific.py` -- pydoc needs these to show topic and
819
-A "make update" updates the Subversion checkouts in :file:`tools/`.
825
-You'll need to install the Sphinx package, either by checking it out via ::
827
- svn co http://svn.python.org/projects/external/Sphinx-0.6.5/sphinx tools/sphinx
829
-or by installing it from PyPI.
831
-Then, you need to install Docutils, either by checking it out via ::
833
- svn co http://svn.python.org/projects/external/docutils-0.6/docutils tools/docutils
835
-or by installing it from http://docutils.sf.net/.
837
-You also need Jinja2, either by checking it out via ::
839
- svn co http://svn.python.org/projects/external/Jinja-2.3.1/jinja2 tools/jinja2
841
-or by installing it from PyPI.
843
-You can optionally also install Pygments, either as a checkout via ::
845
- svn co http://svn.python.org/projects/external/Pygments-1.3.1/pygments tools/pygments
847
-or from PyPI at http://pypi.python.org/pypi/Pygments.
850
-Then, make an output directory, e.g. under `build/`, and run ::
852
- python tools/sphinx-build.py -b<builder> . build/<outputdirectory>
854
-where `<builder>` is one of html, text, latex, or htmlhelp (for explanations see
855
-the make targets above).
856
diff -r 137e45f15c0b Doc/documenting/fromlatex.rst
857
--- a/Doc/documenting/fromlatex.rst
860
-.. highlightlang:: rest
862
-Differences to the LaTeX markup
863
-===============================
865
-Though the markup language is different, most of the concepts and markup types
866
-of the old LaTeX docs have been kept -- environments as reST directives, inline
867
-commands as reST roles and so forth.
869
-However, there are some differences in the way these work, partly due to the
870
-differences in the markup languages, partly due to improvements in Sphinx. This
871
-section lists these differences, in order to give those familiar with the old
872
-format a quick overview of what they might run into.
877
-These changes have been made to inline markup:
879
-* **Cross-reference roles**
881
- Most of the following semantic roles existed previously as inline commands,
882
- but didn't do anything except formatting the content as code. Now, they
883
- cross-reference to known targets (some names have also been shortened):
885
- | *mod* (previously *refmodule* or *module*)
886
- | *func* (previously *function*)
890
- | *meth* (previously *method*)
891
- | *attr* (previously *member*)
892
- | *exc* (previously *exception*)
894
- | *cfunc* (previously *cfunction*)
895
- | *cmacro* (previously *csimplemacro*)
898
- Also different is the handling of *func* and *meth*: while previously
899
- parentheses were added to the callable name (like ``\func{str()}``), they are
900
- now appended by the build system -- appending them in the source will result
901
- in double parentheses. This also means that ``:func:`str(object)``` will not
902
- work as expected -- use ````str(object)```` instead!
904
-* **Inline commands implemented as directives**
906
- These were inline commands in LaTeX, but are now directives in reST:
912
- These are used like so::
914
- .. deprecated:: 2.5
915
- Reason of deprecation.
917
- Also, no period is appended to the text for *versionadded* and
923
- These are used like so::
929
-* **Otherwise changed commands**
931
- The *samp* command previously formatted code and added quotation marks around
932
- it. The *samp* role, however, features a new highlighting system just like
935
- ``:samp:`open({filename}, {mode})``` results in :samp:`open({filename}, {mode})`
937
-* **Dropped commands**
939
- These were commands in LaTeX, but are not available as roles:
942
- | *character* (use :samp:`\`\`'c'\`\``)
943
- | *citetitle* (use ```Title <URL>`_``)
944
- | *code* (use ````code````)
945
- | *email* (just write the address in body text)
947
- | *filevar* (use the ``{...}`` highlighting feature of *file*)
948
- | *programopt*, *longprogramopt* (use *option*)
949
- | *ulink* (use ```Title <URL>`_``)
950
- | *url* (just write the URL in body text)
951
- | *var* (use ``*var*``)
952
- | *infinity*, *plusminus* (use the Unicode character)
953
- | *shortversion*, *version* (use the ``|version|`` and ``|release|`` substitutions)
954
- | *emph*, *strong* (use the reST markup)
956
-* **Backslash escaping**
958
- In reST, a backslash must be escaped in normal text, and in the content of
959
- roles. However, in code literals and literal blocks, it must not be escaped.
960
- Example: ``:file:`C:\\Temp\\my.tmp``` vs. ````open("C:\Temp\my.tmp")````.
966
-Information units (*...desc* environments) have been made reST directives.
967
-These changes to information units should be noted:
971
- "desc" has been removed from every name. Additionally, these directives have
974
- | *cfunction* (previously *cfuncdesc*)
975
- | *cmacro* (previously *csimplemacrodesc*)
976
- | *exception* (previously *excdesc*)
977
- | *function* (previously *funcdesc*)
978
- | *attribute* (previously *memberdesc*)
980
- The *classdesc\** and *excclassdesc* environments have been dropped, the
981
- *class* and *exception* directives support classes documented with and without
982
- constructor arguments.
984
-* **Multiple objects**
986
- The equivalent of the *...line* commands is::
988
- .. function:: do_foo(bar)
991
- Description of the functions.
993
- IOW, just give one signatures per line, at the same indentation level.
997
- There is no *optional* command. Just give function signatures like they
998
- should appear in the output::
1000
- .. function:: open(filename[, mode[, buffering]])
1004
- Note: markup in the signature is not supported.
1008
- The *...descni* environments have been dropped. To mark an information unit
1009
- as unsuitable for index entry generation, use the *noindex* option like so::
1011
- .. function:: foo_*
1016
-* **New information units**
1018
- There are new generic information units: One is called "describe" and can be
1019
- used to document things that are not covered by the other units::
1021
- .. describe:: a == b
1023
- The equals operator.
1029
- Describes a command-line option.
1031
- .. envvar:: PYTHONINSPECT
1033
- Describes an environment variable.
1039
-The LaTeX docs were split in several toplevel manuals. Now, all files are part
1040
-of the same documentation tree, as indicated by the *toctree* directives in the
1041
-sources (though individual output formats may choose to split them up into parts
1042
-again). Every *toctree* directive embeds other files as subdocuments of the
1043
-current file (this structure is not necessarily mirrored in the filesystem
1044
-layout). The toplevel file is :file:`contents.rst`.
1046
-However, most of the old directory structure has been kept, with the
1047
-directories renamed as follows:
1049
-* :file:`api` -> :file:`c-api`
1050
-* :file:`dist` -> :file:`distutils`, with the single TeX file split up
1051
-* :file:`doc` -> :file:`documenting`
1052
-* :file:`ext` -> :file:`extending`
1053
-* :file:`inst` -> :file:`installing`
1054
-* :file:`lib` -> :file:`library`
1055
-* :file:`mac` -> merged into :file:`library`, with :file:`mac/using.tex`
1056
- moved to :file:`using/mac.rst`
1057
-* :file:`ref` -> :file:`reference`
1058
-* :file:`tut` -> :file:`tutorial`, with the single TeX file split up
1061
-.. XXX more (index-generating, production lists, ...)
1062
diff -r 137e45f15c0b Doc/documenting/index.rst
1063
--- a/Doc/documenting/index.rst
1066
-.. _documenting-index:
1068
-######################
1069
- Documenting Python
1070
-######################
1073
-The Python language has a substantial body of documentation, much of it
1074
-contributed by various authors. The markup used for the Python documentation is
1075
-`reStructuredText`_, developed by the `docutils`_ project, amended by custom
1076
-directives and using a toolset named `Sphinx`_ to postprocess the HTML output.
1078
-This document describes the style guide for our documentation as well as the
1079
-custom reStructuredText markup introduced by Sphinx to support Python
1080
-documentation and how it should be used.
1082
-.. _reStructuredText: http://docutils.sf.net/rst.html
1083
-.. _docutils: http://docutils.sf.net/
1084
-.. _Sphinx: http://sphinx.pocoo.org/
1088
- If you're interested in contributing to Python's documentation, there's no
1089
- need to write reStructuredText if you're not so inclined; plain text
1090
- contributions are more than welcome as well. Send an e-mail to
1091
- docs@python.org or open an issue on the :ref:`tracker <reporting-bugs>`.
1104
diff -r 137e45f15c0b Doc/documenting/intro.rst
1105
--- a/Doc/documenting/intro.rst
1111
-Python's documentation has long been considered to be good for a free
1112
-programming language. There are a number of reasons for this, the most
1113
-important being the early commitment of Python's creator, Guido van Rossum, to
1114
-providing documentation on the language and its libraries, and the continuing
1115
-involvement of the user community in providing assistance for creating and
1116
-maintaining documentation.
1118
-The involvement of the community takes many forms, from authoring to bug reports
1119
-to just plain complaining when the documentation could be more complete or
1122
-This document is aimed at authors and potential authors of documentation for
1123
-Python. More specifically, it is for people contributing to the standard
1124
-documentation and developing additional documents using the same tools as the
1125
-standard documents. This guide will be less useful for authors using the Python
1126
-documentation tools for topics other than Python, and less useful still for
1127
-authors not using the tools at all.
1129
-If your interest is in contributing to the Python documentation, but you don't
1130
-have the time or inclination to learn reStructuredText and the markup structures
1131
-documented here, there's a welcoming place for you among the Python contributors
1132
-as well. Any time you feel that you can clarify existing documentation or
1133
-provide documentation that's missing, the existing documentation team will
1134
-gladly work with you to integrate your text, dealing with the markup for you.
1135
-Please don't let the material in this document stand between the documentation
1136
-and your desire to help out!
1137
\ No newline at end of file
1138
diff -r 137e45f15c0b Doc/documenting/markup.rst
1139
--- a/Doc/documenting/markup.rst
1142
-.. highlightlang:: rest
1144
-Additional Markup Constructs
1145
-============================
1147
-Sphinx adds a lot of new directives and interpreted text roles to standard reST
1148
-markup. This section contains the reference material for these facilities.
1149
-Documentation for "standard" reST constructs is not included here, though
1150
-they are used in the Python documentation.
1154
- This is just an overview of Sphinx' extended markup capabilities; full
1155
- coverage can be found in `its own documentation
1156
- <http://sphinx.pocoo.org/contents.html>`_.
1159
-Meta-information markup
1160
------------------------
1162
-.. describe:: sectionauthor
1164
- Identifies the author of the current section. The argument should include
1165
- the author's name such that it can be used for presentation (though it isn't)
1166
- and email address. The domain name portion of the address should be lower
1169
- .. sectionauthor:: Guido van Rossum <guido@python.org>
1171
- Currently, this markup isn't reflected in the output in any way, but it helps
1172
- keep track of contributions.
1175
-Module-specific markup
1176
-----------------------
1178
-The markup described in this section is used to provide information about a
1179
-module being documented. Each module should be documented in its own file.
1180
-Normally this markup appears after the title heading of that file; a typical
1181
-file might start like this::
1183
- :mod:`parrot` -- Dead parrot access
1184
- ===================================
1186
- .. module:: parrot
1187
- :platform: Unix, Windows
1188
- :synopsis: Analyze and reanimate dead parrots.
1189
- .. moduleauthor:: Eric Cleese <eric@python.invalid>
1190
- .. moduleauthor:: John Idle <john@python.invalid>
1192
-As you can see, the module-specific markup consists of two directives, the
1193
-``module`` directive and the ``moduleauthor`` directive.
1195
-.. describe:: module
1197
- This directive marks the beginning of the description of a module, package,
1198
- or submodule. The name should be fully qualified (i.e. including the
1199
- package name for submodules).
1201
- The ``platform`` option, if present, is a comma-separated list of the
1202
- platforms on which the module is available (if it is available on all
1203
- platforms, the option should be omitted). The keys are short identifiers;
1204
- examples that are in use include "IRIX", "Mac", "Windows", and "Unix". It is
1205
- important to use a key which has already been used when applicable.
1207
- The ``synopsis`` option should consist of one sentence describing the
1208
- module's purpose -- it is currently only used in the Global Module Index.
1210
- The ``deprecated`` option can be given (with no value) to mark a module as
1211
- deprecated; it will be designated as such in various locations then.
1213
-.. describe:: moduleauthor
1215
- The ``moduleauthor`` directive, which can appear multiple times, names the
1216
- authors of the module code, just like ``sectionauthor`` names the author(s)
1217
- of a piece of documentation. It too does not result in any output currently.
1221
- It is important to make the section title of a module-describing file
1222
- meaningful since that value will be inserted in the table-of-contents trees
1223
- in overview files.
1229
-There are a number of directives used to describe specific features provided by
1230
-modules. Each directive requires one or more signatures to provide basic
1231
-information about what is being described, and the content should be the
1232
-description. The basic version makes entries in the general index; if no index
1233
-entry is desired, you can give the directive option flag ``:noindex:``. The
1234
-following example shows all of the features of this directive type::
1236
- .. function:: spam(eggs)
1240
- Spam or ham the foo.
1242
-The signatures of object methods or data attributes should not include the
1243
-class name, but be nested in a class directive. The generated files will
1244
-reflect this nesting, and the target identifiers (for HTML output) will use
1245
-both the class and method name, to enable consistent cross-references. If you
1246
-describe methods belonging to an abstract protocol such as context managers,
1247
-use a class directive with a (pseudo-)type name too to make the
1248
-index entries more informative.
1250
-The directives are:
1252
-.. describe:: c:function
1254
- Describes a C function. The signature should be given as in C, e.g.::
1256
- .. c:function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
1258
- This is also used to describe function-like preprocessor macros. The names
1259
- of the arguments should be given so they may be used in the description.
1261
- Note that you don't have to backslash-escape asterisks in the signature,
1262
- as it is not parsed by the reST inliner.
1264
-.. describe:: c:member
1266
- Describes a C struct member. Example signature::
1268
- .. c:member:: PyObject* PyTypeObject.tp_bases
1270
- The text of the description should include the range of values allowed, how
1271
- the value should be interpreted, and whether the value can be changed.
1272
- References to structure members in text should use the ``member`` role.
1274
-.. describe:: c:macro
1276
- Describes a "simple" C macro. Simple macros are macros which are used
1277
- for code expansion, but which do not take arguments so cannot be described as
1278
- functions. This is not to be used for simple constant definitions. Examples
1279
- of its use in the Python documentation include :c:macro:`PyObject_HEAD` and
1280
- :c:macro:`Py_BEGIN_ALLOW_THREADS`.
1282
-.. describe:: c:type
1284
- Describes a C type. The signature should just be the type name.
1286
-.. describe:: c:var
1288
- Describes a global C variable. The signature should include the type, such
1291
- .. cvar:: PyObject* PyClass_Type
1295
- Describes global data in a module, including both variables and values used
1296
- as "defined constants." Class and object attributes are not documented
1297
- using this directive.
1299
-.. describe:: exception
1301
- Describes an exception class. The signature can, but need not include
1302
- parentheses with constructor arguments.
1304
-.. describe:: function
1306
- Describes a module-level function. The signature should include the
1307
- parameters, enclosing optional parameters in brackets. Default values can be
1308
- given if it enhances clarity. For example::
1310
- .. function:: repeat([repeat=3[, number=1000000]])
1312
- Object methods are not documented using this directive. Bound object methods
1313
- placed in the module namespace as part of the public interface of the module
1314
- are documented using this, as they are equivalent to normal functions for
1317
- The description should include information about the parameters required and
1318
- how they are used (especially whether mutable objects passed as parameters
1319
- are modified), side effects, and possible exceptions. A small example may be
1322
-.. describe:: decorator
1324
- Describes a decorator function. The signature should *not* represent the
1325
- signature of the actual function, but the usage as a decorator. For example,
1326
- given the functions
1328
- .. code-block:: python
1330
- def removename(func):
1331
- func.__name__ = ''
1334
- def setnewname(name):
1335
- def decorator(func):
1336
- func.__name__ = name
1340
- the descriptions should look like this::
1342
- .. decorator:: removename
1344
- Remove name of the decorated function.
1346
- .. decorator:: setnewname(name)
1348
- Set name of the decorated function to *name*.
1350
- There is no ``deco`` role to link to a decorator that is marked up with
1351
- this directive; rather, use the ``:func:`` role.
1353
-.. describe:: class
1355
- Describes a class. The signature can include parentheses with parameters
1356
- which will be shown as the constructor arguments.
1358
-.. describe:: attribute
1360
- Describes an object data attribute. The description should include
1361
- information about the type of the data to be expected and whether it may be
1362
- changed directly. This directive should be nested in a class directive,
1363
- like in this example::
1367
- Description of the class.
1371
- Description of the attribute.
1373
- If is also possible to document an attribute outside of a class directive,
1374
- for example if the documentation for different attributes and methods is
1375
- split in multiple sections. The class name should then be included
1378
- .. data:: Spam.eggs
1380
-.. describe:: method
1382
- Describes an object method. The parameters should not include the ``self``
1383
- parameter. The description should include similar information to that
1384
- described for ``function``. This directive should be nested in a class
1385
- directive, like in the example above.
1387
-.. describe:: decoratormethod
1389
- Same as ``decorator``, but for decorators that are methods.
1391
- Refer to a decorator method using the ``:meth:`` role.
1393
-.. describe:: opcode
1395
- Describes a Python :term:`bytecode` instruction.
1397
-.. describe:: cmdoption
1399
- Describes a Python command line option or switch. Option argument names
1400
- should be enclosed in angle brackets. Example::
1402
- .. cmdoption:: -m <module>
1404
- Run a module as a script.
1406
-.. describe:: envvar
1408
- Describes an environment variable that Python uses or defines.
1411
-There is also a generic version of these directives:
1413
-.. describe:: describe
1415
- This directive produces the same formatting as the specific ones explained
1416
- above but does not create index entries or cross-referencing targets. It is
1417
- used, for example, to describe the directives in this document. Example::
1419
- .. describe:: opcode
1421
- Describes a Python bytecode instruction.
1424
-Showing code examples
1425
----------------------
1427
-Examples of Python source code or interactive sessions are represented using
1428
-standard reST literal blocks. They are started by a ``::`` at the end of the
1429
-preceding paragraph and delimited by indentation.
1431
-Representing an interactive session requires including the prompts and output
1432
-along with the Python code. No special markup is required for interactive
1433
-sessions. After the last line of input or output presented, there should not be
1434
-an "unused" primary prompt; this is an example of what *not* to do::
1440
-Syntax highlighting is handled in a smart way:
1442
-* There is a "highlighting language" for each source file. Per default,
1443
- this is ``'python'`` as the majority of files will have to highlight Python
1446
-* Within Python highlighting mode, interactive sessions are recognized
1447
- automatically and highlighted appropriately.
1449
-* The highlighting language can be changed using the ``highlightlang``
1450
- directive, used as follows::
1452
- .. highlightlang:: c
1454
- This language is used until the next ``highlightlang`` directive is
1457
-* The values normally used for the highlighting language are:
1459
- * ``python`` (the default)
1462
- * ``none`` (no highlighting)
1464
-* If highlighting with the current language fails, the block is not highlighted
1467
-Longer displays of verbatim text may be included by storing the example text in
1468
-an external file containing only plain text. The file may be included using the
1469
-``literalinclude`` directive. [1]_ For example, to include the Python source file
1470
-:file:`example.py`, use::
1472
- .. literalinclude:: example.py
1474
-The file name is relative to the current file's path. Documentation-specific
1475
-include files should be placed in the ``Doc/includes`` subdirectory.
1481
-As said before, Sphinx uses interpreted text roles to insert semantic markup in
1484
-Names of local variables, such as function/method arguments, are an exception,
1485
-they should be marked simply with ``*var*``.
1487
-For all other roles, you have to write ``:rolename:`content```.
1489
-There are some additional facilities that make cross-referencing roles more
1492
-* You may supply an explicit title and reference target, like in reST direct
1493
- hyperlinks: ``:role:`title <target>``` will refer to *target*, but the link
1494
- text will be *title*.
1496
-* If you prefix the content with ``!``, no reference/hyperlink will be created.
1498
-* For the Python object roles, if you prefix the content with ``~``, the link
1499
- text will only be the last component of the target. For example,
1500
- ``:meth:`~Queue.Queue.get``` will refer to ``Queue.Queue.get`` but only
1501
- display ``get`` as the link text.
1503
- In HTML output, the link's ``title`` attribute (that is e.g. shown as a
1504
- tool-tip on mouse-hover) will always be the full target name.
1506
-The following roles refer to objects in modules and are possibly hyperlinked if
1507
-a matching identifier is found:
1511
- The name of a module; a dotted name may be used. This should also be used for
1516
- The name of a Python function; dotted names may be used. The role text
1517
- should not include trailing parentheses to enhance readability. The
1518
- parentheses are stripped when searching for identifiers.
1522
- The name of a module-level variable or constant.
1524
-.. describe:: const
1526
- The name of a "defined" constant. This may be a C-language ``#define``
1527
- or a Python variable that is not intended to be changed.
1529
-.. describe:: class
1531
- A class name; a dotted name may be used.
1535
- The name of a method of an object. The role text should include the type
1536
- name and the method name. A dotted name may be used.
1540
- The name of a data attribute of an object.
1544
- The name of an exception. A dotted name may be used.
1546
-The name enclosed in this markup can include a module name and/or a class name.
1547
-For example, ``:func:`filter``` could refer to a function named ``filter`` in
1548
-the current module, or the built-in function of that name. In contrast,
1549
-``:func:`foo.filter``` clearly refers to the ``filter`` function in the ``foo``
1552
-Normally, names in these roles are searched first without any further
1553
-qualification, then with the current module name prepended, then with the
1554
-current module and class name (if any) prepended. If you prefix the name with a
1555
-dot, this order is reversed. For example, in the documentation of the
1556
-:mod:`codecs` module, ``:func:`open``` always refers to the built-in function,
1557
-while ``:func:`.open``` refers to :func:`codecs.open`.
1559
-A similar heuristic is used to determine whether the name is an attribute of
1560
-the currently documented class.
1562
-The following roles create cross-references to C-language constructs if they
1563
-are defined in the API documentation:
1565
-.. describe:: c:data
1567
- The name of a C-language variable.
1569
-.. describe:: c:func
1571
- The name of a C-language function. Should include trailing parentheses.
1573
-.. describe:: c:macro
1575
- The name of a "simple" C macro, as defined above.
1577
-.. describe:: c:type
1579
- The name of a C-language type.
1581
-.. describe:: c:member
1583
- The name of a C type member, as defined above.
1586
-The following role does possibly create a cross-reference, but does not refer
1589
-.. describe:: token
1591
- The name of a grammar token (used in the reference manual to create links
1592
- between production displays).
1595
-The following role creates a cross-reference to the term in the glossary:
1599
- Reference to a term in the glossary. The glossary is created using the
1600
- ``glossary`` directive containing a definition list with terms and
1601
- definitions. It does not have to be in the same file as the ``term``
1602
- markup, in fact, by default the Python docs have one global glossary
1603
- in the ``glossary.rst`` file.
1605
- If you use a term that's not explained in a glossary, you'll get a warning
1610
-The following roles don't do anything special except formatting the text
1611
-in a different style:
1613
-.. describe:: command
1615
- The name of an OS-level command, such as ``rm``.
1619
- Mark the defining instance of a term in the text. (No index entries are
1622
-.. describe:: envvar
1624
- An environment variable. Index entries are generated.
1628
- The name of a file or directory. Within the contents, you can use curly
1629
- braces to indicate a "variable" part, for example::
1631
- ... is installed in :file:`/usr/lib/python2.{x}/site-packages` ...
1633
- In the built documentation, the ``x`` will be displayed differently to
1634
- indicate that it is to be replaced by the Python minor version.
1636
-.. describe:: guilabel
1638
- Labels presented as part of an interactive user interface should be marked
1639
- using ``guilabel``. This includes labels from text-based interfaces such as
1640
- those created using :mod:`curses` or other text-based libraries. Any label
1641
- used in the interface should be marked with this role, including button
1642
- labels, window titles, field names, menu and menu selection names, and even
1643
- values in selection lists.
1647
- Mark a sequence of keystrokes. What form the key sequence takes may depend
1648
- on platform- or application-specific conventions. When there are no relevant
1649
- conventions, the names of modifier keys should be spelled out, to improve
1650
- accessibility for new users and non-native speakers. For example, an
1651
- *xemacs* key sequence may be marked like ``:kbd:`C-x C-f```, but without
1652
- reference to a specific application or platform, the same sequence should be
1653
- marked as ``:kbd:`Control-x Control-f```.
1655
-.. describe:: keyword
1657
- The name of a keyword in Python.
1659
-.. describe:: mailheader
1661
- The name of an RFC 822-style mail header. This markup does not imply that
1662
- the header is being used in an email message, but can be used to refer to any
1663
- header of the same "style." This is also used for headers defined by the
1664
- various MIME specifications. The header name should be entered in the same
1665
- way it would normally be found in practice, with the camel-casing conventions
1666
- being preferred where there is more than one common usage. For example:
1667
- ``:mailheader:`Content-Type```.
1669
-.. describe:: makevar
1671
- The name of a :command:`make` variable.
1673
-.. describe:: manpage
1675
- A reference to a Unix manual page including the section,
1676
- e.g. ``:manpage:`ls(1)```.
1678
-.. describe:: menuselection
1680
- Menu selections should be marked using the ``menuselection`` role. This is
1681
- used to mark a complete sequence of menu selections, including selecting
1682
- submenus and choosing a specific operation, or any subsequence of such a
1683
- sequence. The names of individual selections should be separated by
1686
- For example, to mark the selection "Start > Programs", use this markup::
1688
- :menuselection:`Start --> Programs`
1690
- When including a selection that includes some trailing indicator, such as the
1691
- ellipsis some operating systems use to indicate that the command opens a
1692
- dialog, the indicator should be omitted from the selection name.
1694
-.. describe:: mimetype
1696
- The name of a MIME type, or a component of a MIME type (the major or minor
1697
- portion, taken alone).
1699
-.. describe:: newsgroup
1701
- The name of a Usenet newsgroup.
1703
-.. describe:: option
1705
- A command-line option of Python. The leading hyphen(s) must be included.
1706
- If a matching ``cmdoption`` directive exists, it is linked to. For options
1707
- of other programs or scripts, use simple ````code```` markup.
1709
-.. describe:: program
1711
- The name of an executable program. This may differ from the file name for
1712
- the executable for some platforms. In particular, the ``.exe`` (or other)
1713
- extension should be omitted for Windows programs.
1715
-.. describe:: regexp
1717
- A regular expression. Quotes should not be included.
1721
- A piece of literal text, such as code. Within the contents, you can use
1722
- curly braces to indicate a "variable" part, as in ``:file:``.
1724
- If you don't need the "variable part" indication, use the standard
1725
- ````code```` instead.
1728
-The following roles generate external links:
1732
- A reference to a Python Enhancement Proposal. This generates appropriate
1733
- index entries. The text "PEP *number*\ " is generated; in the HTML output,
1734
- this text is a hyperlink to an online copy of the specified PEP.
1738
- A reference to an Internet Request for Comments. This generates appropriate
1739
- index entries. The text "RFC *number*\ " is generated; in the HTML output,
1740
- this text is a hyperlink to an online copy of the specified RFC.
1743
-Note that there are no special roles for including hyperlinks as you can use
1744
-the standard reST markup for that purpose.
1749
-Cross-linking markup
1750
---------------------
1752
-To support cross-referencing to arbitrary sections in the documentation, the
1753
-standard reST labels are "abused" a bit: Every label must precede a section
1754
-title; and every label name must be unique throughout the entire documentation
1757
-You can then reference to these sections using the ``:ref:`label-name``` role.
1761
- .. _my-reference-label:
1763
- Section to cross-reference
1764
- --------------------------
1766
- This is the text of the section.
1768
- It refers to the section itself, see :ref:`my-reference-label`.
1770
-The ``:ref:`` invocation is replaced with the section title.
1772
-Alternatively, you can reference any label (not just section titles)
1773
-if you provide the link text ``:ref:`link text <reference-label>```.
1775
-Paragraph-level markup
1776
-----------------------
1778
-These directives create short paragraphs and can be used inside information
1779
-units as well as normal text:
1783
- An especially important bit of information about an API that a user should be
1784
- aware of when using whatever bit of API the note pertains to. The content of
1785
- the directive should be written in complete sentences and include all
1786
- appropriate punctuation.
1792
- This function is not suitable for sending spam e-mails.
1794
-.. describe:: warning
1796
- An important bit of information about an API that a user should be aware of
1797
- when using whatever bit of API the warning pertains to. The content of the
1798
- directive should be written in complete sentences and include all appropriate
1799
- punctuation. In the interest of not scaring users away from pages filled
1800
- with warnings, this directive should only be chosen over ``note`` for
1801
- information regarding the possibility of crashes, data loss, or security
1804
-.. describe:: versionadded
1806
- This directive documents the version of Python which added the described
1807
- feature to the library or C API. When this applies to an entire module, it
1808
- should be placed at the top of the module section before any prose.
1810
- The first argument must be given and is the version in question; you can add
1811
- a second argument consisting of a *brief* explanation of the change.
1815
- .. versionadded:: 3.1
1816
- The *spam* parameter.
1818
- Note that there must be no blank line between the directive head and the
1819
- explanation; this is to make these blocks visually continuous in the markup.
1821
-.. describe:: versionchanged
1823
- Similar to ``versionadded``, but describes when and what changed in the named
1824
- feature in some way (new parameters, changed side effects, etc.).
1828
-.. describe:: impl-detail
1830
- This directive is used to mark CPython-specific information. Use either with
1831
- a block content or a single sentence as an argument, i.e. either ::
1835
- This describes some implementation detail.
1841
- .. impl-detail:: This shortly mentions an implementation detail.
1843
- "\ **CPython implementation detail:**\ " is automatically prepended to the
1846
-.. describe:: seealso
1848
- Many sections include a list of references to module documentation or
1849
- external documents. These lists are created using the ``seealso`` directive.
1851
- The ``seealso`` directive is typically placed in a section just before any
1852
- sub-sections. For the HTML output, it is shown boxed off from the main flow
1855
- The content of the ``seealso`` directive should be a reST definition list.
1860
- Module :mod:`zipfile`
1861
- Documentation of the :mod:`zipfile` standard module.
1863
- `GNU tar manual, Basic Tar Format <http://link>`_
1864
- Documentation for tar archive files, including GNU tar extensions.
1866
-.. describe:: rubric
1868
- This directive creates a paragraph heading that is not used to create a
1869
- table of contents node. It is currently used for the "Footnotes" caption.
1871
-.. describe:: centered
1873
- This directive creates a centered boldfaced paragraph. Use it as follows::
1877
- Paragraph contents.
1880
-Table-of-contents markup
1881
-------------------------
1883
-Since reST does not have facilities to interconnect several documents, or split
1884
-documents into multiple output files, Sphinx uses a custom directive to add
1885
-relations between the single files the documentation is made of, as well as
1886
-tables of contents. The ``toctree`` directive is the central element.
1888
-.. describe:: toctree
1890
- This directive inserts a "TOC tree" at the current location, using the
1891
- individual TOCs (including "sub-TOC trees") of the files given in the
1892
- directive body. A numeric ``maxdepth`` option may be given to indicate the
1893
- depth of the tree; by default, all levels are included.
1895
- Consider this example (taken from the library reference index)::
1904
- (many more files listed here)
1906
- This accomplishes two things:
1908
- * Tables of contents from all those files are inserted, with a maximum depth
1909
- of two, that means one nested heading. ``toctree`` directives in those
1910
- files are also taken into account.
1911
- * Sphinx knows that the relative order of the files ``intro``,
1912
- ``strings`` and so forth, and it knows that they are children of the
1913
- shown file, the library index. From this information it generates "next
1914
- chapter", "previous chapter" and "parent chapter" links.
1916
- In the end, all files included in the build process must occur in one
1917
- ``toctree`` directive; Sphinx will emit a warning if it finds a file that is
1918
- not included, because that means that this file will not be reachable through
1919
- standard navigation.
1921
- The special file ``contents.rst`` at the root of the source directory is the
1922
- "root" of the TOC tree hierarchy; from it the "Contents" page is generated.
1925
-Index-generating markup
1926
------------------------
1928
-Sphinx automatically creates index entries from all information units (like
1929
-functions, classes or attributes) like discussed before.
1931
-However, there is also an explicit directive available, to make the index more
1932
-comprehensive and enable index entries in documents where information is not
1933
-mainly contained in information units, such as the language reference.
1935
-The directive is ``index`` and contains one or more index entries. Each entry
1936
-consists of a type and a value, separated by a colon.
1941
- single: execution; context
1944
- triple: module; search; path
1946
-This directive contains five entries, which will be converted to entries in the
1947
-generated index which link to the exact location of the index statement (or, in
1948
-case of offline media, the corresponding page number).
1950
-The possible entry types are:
1953
- Creates a single index entry. Can be made a subentry by separating the
1954
- subentry text with a semicolon (this notation is also used below to describe
1955
- what entries are created).
1957
- ``pair: loop; statement`` is a shortcut that creates two index entries,
1958
- namely ``loop; statement`` and ``statement; loop``.
1960
- Likewise, ``triple: module; search; path`` is a shortcut that creates three
1961
- index entries, which are ``module; search path``, ``search; path, module`` and
1962
- ``path; module search``.
1963
-module, keyword, operator, object, exception, statement, builtin
1964
- These all create two index entries. For example, ``module: hashlib`` creates
1965
- the entries ``module; hashlib`` and ``hashlib; module``.
1967
-For index directives containing only "single" entries, there is a shorthand
1970
- .. index:: BNF, grammar, syntax, notation
1972
-This creates four index entries.
1975
-Grammar production displays
1976
----------------------------
1978
-Special markup is available for displaying the productions of a formal grammar.
1979
-The markup is simple and does not attempt to model all aspects of BNF (or any
1980
-derived forms), but provides enough to allow context-free grammars to be
1981
-displayed in a way that causes uses of a symbol to be rendered as hyperlinks to
1982
-the definition of the symbol. There is this directive:
1984
-.. describe:: productionlist
1986
- This directive is used to enclose a group of productions. Each production is
1987
- given on a single line and consists of a name, separated by a colon from the
1988
- following definition. If the definition spans multiple lines, each
1989
- continuation line must begin with a colon placed at the same column as in the
1992
- Blank lines are not allowed within ``productionlist`` directive arguments.
1994
- The definition can contain token names which are marked as interpreted text
1995
- (e.g. ``unaryneg ::= "-" `integer```) -- this generates cross-references
1996
- to the productions of these tokens.
1998
- Note that no further reST parsing is done in the production, so that you
1999
- don't have to escape ``*`` or ``|`` characters.
2002
-.. XXX describe optional first parameter
2004
-The following is an example taken from the Python Reference Manual::
2006
- .. productionlist::
2007
- try_stmt: try1_stmt | try2_stmt
2008
- try1_stmt: "try" ":" `suite`
2009
- : ("except" [`expression` ["," `target`]] ":" `suite`)+
2010
- : ["else" ":" `suite`]
2011
- : ["finally" ":" `suite`]
2012
- try2_stmt: "try" ":" `suite`
2013
- : "finally" ":" `suite`
2019
-The documentation system provides three substitutions that are defined by default.
2020
-They are set in the build configuration file :file:`conf.py`.
2022
-.. describe:: |release|
2024
- Replaced by the Python release the documentation refers to. This is the full
2025
- version string including alpha/beta/release candidate tags, e.g. ``2.5.2b3``.
2027
-.. describe:: |version|
2029
- Replaced by the Python version the documentation refers to. This consists
2030
- only of the major and minor version parts, e.g. ``2.5``, even for version
2033
-.. describe:: |today|
2035
- Replaced by either today's date, or the date set in the build configuration
2036
- file. Normally has the format ``April 14, 2007``.
2039
-.. rubric:: Footnotes
2041
-.. [1] There is a standard ``.. include`` directive, but it raises errors if the
2042
- file is not found. This one only emits a warning.
2043
diff -r 137e45f15c0b Doc/documenting/rest.rst
2044
--- a/Doc/documenting/rest.rst
2047
-.. highlightlang:: rest
2049
-reStructuredText Primer
2050
-=======================
2052
-This section is a brief introduction to reStructuredText (reST) concepts and
2053
-syntax, intended to provide authors with enough information to author documents
2054
-productively. Since reST was designed to be a simple, unobtrusive markup
2055
-language, this will not take too long.
2059
- The authoritative `reStructuredText User
2060
- Documentation <http://docutils.sourceforge.net/rst.html>`_.
2066
-The paragraph is the most basic block in a reST document. Paragraphs are simply
2067
-chunks of text separated by one or more blank lines. As in Python, indentation
2068
-is significant in reST, so all lines of the same paragraph must be left-aligned
2069
-to the same level of indentation.
2075
-The standard reST inline markup is quite simple: use
2077
-* one asterisk: ``*text*`` for emphasis (italics),
2078
-* two asterisks: ``**text**`` for strong emphasis (boldface), and
2079
-* backquotes: ````text```` for code samples.
2081
-If asterisks or backquotes appear in running text and could be confused with
2082
-inline markup delimiters, they have to be escaped with a backslash.
2084
-Be aware of some restrictions of this markup:
2086
-* it may not be nested,
2087
-* content may not start or end with whitespace: ``* text*`` is wrong,
2088
-* it must be separated from surrounding text by non-word characters. Use a
2089
- backslash escaped space to work around that: ``thisis\ *one*\ word``.
2091
-These restrictions may be lifted in future versions of the docutils.
2093
-reST also allows for custom "interpreted text roles"', which signify that the
2094
-enclosed text should be interpreted in a specific way. Sphinx uses this to
2095
-provide semantic markup and cross-referencing of identifiers, as described in
2096
-the appropriate section. The general syntax is ``:rolename:`content```.
2102
-List markup is natural: just place an asterisk at the start of a paragraph and
2103
-indent properly. The same goes for numbered lists; they can also be
2104
-autonumbered using a ``#`` sign::
2106
- * This is a bulleted list.
2107
- * It has two items, the second
2108
- item uses two lines.
2110
- 1. This is a numbered list.
2111
- 2. It has two items too.
2113
- #. This is a numbered list.
2114
- #. It has two items too.
2117
-Nested lists are possible, but be aware that they must be separated from the
2118
-parent list items by blank lines::
2123
- * with a nested list
2124
- * and some subitems
2126
- * and here the parent list continues
2128
-Definition lists are created as follows::
2130
- term (up to a line of text)
2131
- Definition of the term, which must be indented
2133
- and can even consist of multiple paragraphs
2139
-Paragraphs are quoted by just indenting them more than the surrounding
2146
-Literal code blocks are introduced by ending a paragraph with the special marker
2147
-``::``. The literal block must be indented::
2149
- This is a normal text paragraph. The next paragraph is a code sample::
2151
- It is not processed in any way, except
2152
- that the indentation is removed.
2154
- It can span multiple lines.
2156
- This is a normal text paragraph again.
2158
-The handling of the ``::`` marker is smart:
2160
-* If it occurs as a paragraph of its own, that paragraph is completely left
2161
- out of the document.
2162
-* If it is preceded by whitespace, the marker is removed.
2163
-* If it is preceded by non-whitespace, the marker is replaced by a single
2166
-That way, the second sentence in the above example's first paragraph would be
2167
-rendered as "The next paragraph is a code sample:".
2176
-Use ```Link text <http://target>`_`` for inline web links. If the link text
2177
-should be the web address, you don't need special markup at all, the parser
2178
-finds links and mail addresses in ordinary text.
2183
-Internal linking is done via a special reST role, see the section on specific
2184
-markup, :ref:`doc-ref-role`.
2190
-Section headers are created by underlining (and optionally overlining) the
2191
-section title with a punctuation character, at least as long as the text::
2197
-Normally, there are no heading levels assigned to certain characters as the
2198
-structure is determined from the succession of headings. However, for the
2199
-Python documentation, we use this convention:
2201
-* ``#`` with overline, for parts
2202
-* ``*`` with overline, for chapters
2203
-* ``=``, for sections
2204
-* ``-``, for subsections
2205
-* ``^``, for subsubsections
2206
-* ``"``, for paragraphs
2212
-"Explicit markup" is used in reST for most constructs that need special
2213
-handling, such as footnotes, specially-highlighted paragraphs, comments, and
2214
-generic directives.
2216
-An explicit markup block begins with a line starting with ``..`` followed by
2217
-whitespace and is terminated by the next paragraph at the same level of
2218
-indentation. (There needs to be a blank line between explicit markup and normal
2219
-paragraphs. This may all sound a bit complicated, but it is intuitive enough
2220
-when you write it.)
2226
-A directive is a generic block of explicit markup. Besides roles, it is one of
2227
-the extension mechanisms of reST, and Sphinx makes heavy use of it.
2229
-Basically, a directive consists of a name, arguments, options and content. (Keep
2230
-this terminology in mind, it is used in the next chapter describing custom
2231
-directives.) Looking at this example, ::
2233
- .. function:: foo(x)
2237
- Return a line of text input from the user.
2239
-``function`` is the directive name. It is given two arguments here, the
2240
-remainder of the first line and the second line, as well as one option ``bar``
2241
-(as you can see, options are given in the lines immediately following the
2242
-arguments and indicated by the colons).
2244
-The directive content follows after a blank line and is indented relative to the
2251
-For footnotes, use ``[#]_`` to mark the footnote location, and add the footnote
2252
-body at the bottom of the document after a "Footnotes" rubric heading, like so::
2254
- Lorem ipsum [#]_ dolor sit amet ... [#]_
2256
- .. rubric:: Footnotes
2258
- .. [#] Text of the first footnote.
2259
- .. [#] Text of the second footnote.
2261
-You can also explicitly number the footnotes for better context.
2267
-Every explicit markup block which isn't a valid markup construct (like the
2268
-footnotes above) is regarded as a comment.
2274
-Since the easiest way to include special characters like em dashes or copyright
2275
-signs in reST is to directly write them as Unicode characters, one has to
2276
-specify an encoding:
2278
-All Python documentation source files must be in UTF-8 encoding, and the HTML
2279
-documents written from them will be in that encoding as well.
2285
-There are some problems one commonly runs into while authoring reST documents:
2287
-* **Separation of inline markup:** As said above, inline markup spans must be
2288
- separated from the surrounding text by non-word characters, you have to use
2289
- an escaped space to get around that.
2290
diff -r 137e45f15c0b Doc/documenting/style.rst
2291
--- a/Doc/documenting/style.rst
2294
-.. highlightlang:: rest
2299
-The Python documentation should follow the `Apple Publications Style Guide`_
2300
-wherever possible. This particular style guide was selected mostly because it
2301
-seems reasonable and is easy to get online.
2303
-Topics which are either not covered in Apple's style guide or treated
2304
-differently in Python documentation will be discussed in this
2310
-All reST files use an indentation of 3 spaces. The maximum line length is 80
2311
-characters for normal text, but tables, deeply indented code samples and long
2312
-links may extend beyond that.
2314
-Make generous use of blank lines where applicable; they help grouping things
2317
-A sentence-ending period may be followed by one or two spaces; while reST
2318
-ignores the second space, it is customarily put in by some users, for example
2319
-to aid Emacs' auto-fill mode.
2324
-Footnotes are generally discouraged, though they may be used when they are the
2325
-best way to present specific information. When a footnote reference is added at
2326
-the end of the sentence, it should follow the sentence-ending punctuation. The
2327
-reST markup should appear something like this::
2329
- This sentence has a footnote reference. [#]_ This is the next sentence.
2331
-Footnotes should be gathered at the end of a file, or if the file is very long,
2332
-at the end of a section. The docutils will automatically create backlinks to
2333
-the footnote reference.
2335
-Footnotes may appear in the middle of sentences where appropriate.
2340
-.. sidebar:: Sentence case
2342
- Sentence case is a set of capitalization rules used in English
2343
- sentences: the first word is always capitalized and other words are
2344
- only capitalized if there is a specific rule requiring it.
2346
-Apple style guide recommends the use of title case in section titles.
2347
-However, rules for which words should be capitalized in title case
2348
-vary greaty between publications.
2350
-In Python documentation, use of sentence case in section titles is
2351
-preferable, but consistency within a unit is more important than
2352
-following this rule. If you add a section to the chapter where most
2353
-sections are in title case you can either convert all titles to
2354
-sentence case or use the dominant style in the new section title.
2356
-Sentences that start with a word for which specific rules require
2357
-starting it with a lower case letter should be avoided in titles and
2362
- Sections that describe a library module often have titles in the
2363
- form of "modulename --- Short description of the module." In this
2364
- case, the description should be capitalized as a stand-alone
2367
-Many special names are used in the Python documentation, including the names of
2368
-operating systems, programming languages, standards bodies, and the like. Most
2369
-of these entities are not assigned any special markup, but the preferred
2370
-spellings are given here to aid authors in maintaining the consistency of
2371
-presentation in the Python documentation.
2373
-Other terms and words deserve special mention as well; these conventions should
2374
-be used to ensure consistency throughout the documentation:
2377
- For "central processing unit." Many style guides say this should be
2378
- spelled out on the first use (and if you must use it, do so!). For
2379
- the Python documentation, this abbreviation should be avoided since
2380
- there's no reasonable way to predict which occurrence will be the
2381
- first seen by the reader. It is better to use the word "processor"
2385
- The name assigned to a particular group of standards. This is always
2389
- The name of our favorite programming language is always capitalized.
2392
- For "reStructuredText," an easy to read, plaintext markup syntax
2393
- used to produce Python documentation. When spelled out, it is
2394
- always one word and both forms start with a lower case 'r'.
2397
- The name of a character coding system. This is always written
2401
- The name of the operating system developed at AT&T Bell Labs in the early
2407
-The documentation focuses on affirmatively stating what the language does and
2408
-how to use it effectively.
2410
-Except for certain security risks or segfault risks, the docs should avoid
2411
-wording along the lines of "feature x is dangerous" or "experts only". These
2412
-kinds of value judgments belong in external blogs and wikis, not in the core
2415
-Bad example (creating worry in the mind of a reader):
2417
- Warning: failing to explicitly close a file could result in lost data or
2418
- excessive resource consumption. Never rely on reference counting to
2419
- automatically close a file.
2421
-Good example (establishing confident knowledge in the effective use of the language):
2423
- A best practice for using files is use a try/finally pair to explicitly
2424
- close a file after it is used. Alternatively, using a with-statement can
2425
- achieve the same effect. This assures that files are flushed and file
2426
- descriptor resources are released in a timely manner.
2428
-Economy of Expression
2429
----------------------
2431
-More documentation is not necessarily better documentation. Err on the side
2434
-It is an unfortunate fact that making documentation longer can be an impediment
2435
-to understanding and can result in even more ways to misread or misinterpret the
2436
-text. Long descriptions full of corner cases and caveats can create the
2437
-impression that a function is more complex or harder to use than it actually is.
2439
-The documentation for :func:`super` is an example of where a good deal of
2440
-information was condensed into a few short paragraphs. Discussion of
2441
-:func:`super` could have filled a chapter in a book, but it is often easier to
2442
-grasp a terse description than a lengthy narrative.
2448
-Short code examples can be a useful adjunct to understanding. Readers can often
2449
-grasp a simple example more quickly than they can digest a formal description in
2452
-People learn faster with concrete, motivating examples that match the context of
2453
-a typical use case. For instance, the :func:`str.rpartition` method is better
2454
-demonstrated with an example splitting the domain from a URL than it would be
2455
-with an example of removing the last word from a line of Monty Python dialog.
2457
-The ellipsis for the :attr:`sys.ps2` secondary interpreter prompt should only be
2458
-used sparingly, where it is necessary to clearly differentiate between input
2459
-lines and output lines. Besides contributing visual clutter, it makes it
2460
-difficult for readers to cut-and-paste examples so they can experiment with
2466
-Giving pure Python code equivalents (or approximate equivalents) can be a useful
2467
-adjunct to a prose description. A documenter should carefully weigh whether the
2468
-code equivalent adds value.
2470
-A good example is the code equivalent for :func:`all`. The short 4-line code
2471
-equivalent is easily digested; it re-emphasizes the early-out behavior; and it
2472
-clarifies the handling of the corner-case where the iterable is empty. In
2473
-addition, it serves as a model for people wanting to implement a commonly
2474
-requested alternative where :func:`all` would return the specific object
2475
-evaluating to False whenever the function terminates early.
2477
-A more questionable example is the code for :func:`itertools.groupby`. Its code
2478
-equivalent borders on being too complex to be a quick aid to understanding.
2479
-Despite its complexity, the code equivalent was kept because it serves as a
2480
-model to alternative implementations and because the operation of the "grouper"
2481
-is more easily shown in code than in English prose.
2483
-An example of when not to use a code equivalent is for the :func:`oct` function.
2484
-The exact steps in converting a number to octal doesn't add value for a user
2485
-trying to learn what the function does.
2490
-The tone of the tutorial (and all the docs) needs to be respectful of the
2491
-reader's intelligence. Don't presume that the readers are stupid. Lay out the
2492
-relevant information, show motivating use cases, provide glossary links, and do
2493
-your best to connect-the-dots, but don't talk down to them or waste their time.
2495
-The tutorial is meant for newcomers, many of whom will be using the tutorial to
2496
-evaluate the language as a whole. The experience needs to be positive and not
2497
-leave the reader with worries that something bad will happen if they make a
2498
-misstep. The tutorial serves as guide for intelligent and curious readers,
2499
-saving details for the how-to guides and other sources.
2501
-Be careful accepting requests for documentation changes from the rare but vocal
2502
-category of reader who is looking for vindication for one of their programming
2503
-errors ("I made a mistake, therefore the docs must be wrong ..."). Typically,
2504
-the documentation wasn't consulted until after the error was made. It is
2505
-unfortunate, but typically no documentation edit would have saved the user from
2506
-making false assumptions about the language ("I was surprised by ...").
2509
-.. _Apple Publications Style Guide: http://developer.apple.com/mac/library/documentation/UserExperience/Conceptual/APStyleGuide/APSG_2009.pdf
2511
diff -r 137e45f15c0b Doc/extending/embedding.rst
2512
--- a/Doc/extending/embedding.rst
2513
+++ b/Doc/extending/embedding.rst
2516
This code loads a Python script using ``argv[1]``, and calls the function named
2517
in ``argv[2]``. Its integer arguments are the other values of the ``argv``
2518
-array. If you compile and link this program (let's call the finished executable
2519
-:program:`call`), and use it to execute a Python script, such as::
2520
+array. If you :ref:`compile and link <compiling>` this program (let's call
2521
+the finished executable :program:`call`), and use it to execute a Python
2525
print("Will compute", a, "times", b)
2526
@@ -257,37 +258,53 @@
2527
program. There is no need to recompile Python itself using C++.
2533
-Linking Requirements
2534
-====================
2535
+Compiling and Linking under Unix-like systems
2536
+=============================================
2538
-While the :program:`configure` script shipped with the Python sources will
2539
-correctly build Python to export the symbols needed by dynamically linked
2540
-extensions, this is not automatically inherited by applications which embed the
2541
-Python library statically, at least on Unix. This is an issue when the
2542
-application is linked to the static runtime library (:file:`libpython.a`) and
2543
-needs to load dynamic extensions (implemented as :file:`.so` files).
2544
+It is not necessarily trivial to find the right flags to pass to your
2545
+compiler (and linker) in order to embed the Python interpreter into your
2546
+application, particularly because Python needs to load library modules
2547
+implemented as C dynamic extensions (:file:`.so` files) linked against
2550
-The problem is that some entry points are defined by the Python runtime solely
2551
-for extension modules to use. If the embedding application does not use any of
2552
-these entry points, some linkers will not include those entries in the symbol
2553
-table of the finished executable. Some additional options are needed to inform
2554
-the linker not to remove these symbols.
2555
+To find out the required compiler and linker flags, you can execute the
2556
+:file:`python{X.Y}-config` script which is generated as part of the
2557
+installation process (a :file:`python3-config` script may also be
2558
+available). This script has several options, of which the following will
2559
+be directly useful to you:
2561
-Determining the right options to use for any given platform can be quite
2562
-difficult, but fortunately the Python configuration already has those values.
2563
-To retrieve them from an installed Python interpreter, start an interactive
2564
-interpreter and have a short session like this::
2565
+* ``pythonX.Y-config --cflags`` will give you the recommended flags when
2568
- >>> import distutils.sysconfig
2569
- >>> distutils.sysconfig.get_config_var('LINKFORSHARED')
2570
+ $ /opt/bin/python3.2-config --cflags
2571
+ -I/opt/include/python3.2m -I/opt/include/python3.2m -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
2573
+* ``pythonX.Y-config --ldflags`` will give you the recommended flags when
2576
+ $ /opt/bin/python3.2-config --ldflags
2577
+ -I/opt/lib/python3.2/config-3.2m -lpthread -ldl -lutil -lm -lpython3.2m -Xlinker -export-dynamic
2580
+ To avoid confusion between several Python installations (and especially
2581
+ between the system Python and your own compiled Python), it is recommended
2582
+ that you use the absolute path to :file:`python{X.Y}-config`, as in the above
2585
+If this procedure doesn't work for you (it is not guaranteed to work for
2586
+all Unix-like platforms; however, we welcome :ref:`bug reports <reporting-bugs>`)
2587
+you will have to read your system's documentation about dynamic linking and/or
2588
+examine Python's :file:`Makefile` (use :func:`sysconfig.get_makefile_filename`
2589
+to find its location) and compilation
2590
+options. In this case, the :mod:`sysconfig` module is a useful tool to
2591
+programmatically extract the configuration values that you will want to
2594
+ >>> import sysconfig
2595
+ >>> sysconfig.get_config_var('LINKFORSHARED')
2596
'-Xlinker -export-dynamic'
2598
-.. index:: module: distutils.sysconfig
2600
-The contents of the string presented will be the options that should be used.
2601
-If the string is empty, there's no need to add any additional options. The
2602
-:const:`LINKFORSHARED` definition corresponds to the variable of the same name
2603
-in Python's top-level :file:`Makefile`.
2605
+.. XXX similar documentation for Windows missing
2606
diff -r 137e45f15c0b Doc/faq/design.rst
2607
--- a/Doc/faq/design.rst
2608
+++ b/Doc/faq/design.rst
2609
@@ -380,11 +380,24 @@
2610
Can Python be compiled to machine code, C or some other language?
2611
-----------------------------------------------------------------
2613
-Not easily. Python's high level data types, dynamic typing of objects and
2616
+`Cython <http://cython.org/>`_ and `Pyrex <http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/>`_
2617
+compile a modified version of Python with optional annotations into C
2618
+extensions. `Weave <http://www.scipy.org/Weave>`_ makes it easy to
2619
+intermingle Python and C code in various ways to increase performance.
2620
+`Nuitka <http://www.nuitka.net/>`_ is an up-and-coming compiler of Python
2621
+into C++ code, aiming to support the full Python language.
2623
+Theoretical answer:
2625
+ .. XXX not sure what to make of this
2627
+Not trivially. Python's high level data types, dynamic typing of objects and
2628
run-time invocation of the interpreter (using :func:`eval` or :func:`exec`)
2629
-together mean that a "compiled" Python program would probably consist mostly of
2630
-calls into the Python run-time system, even for seemingly simple operations like
2632
+together mean that a naïvely "compiled" Python program would probably consist
2633
+mostly of calls into the Python run-time system, even for seemingly simple
2634
+operations like ``x+1``.
2636
Several projects described in the Python newsgroup or at past `Python
2637
conferences <http://python.org/community/workshops/>`_ have shown that this
2638
@@ -395,99 +408,64 @@
2639
from the `1997 Python conference
2640
<http://python.org/workshops/1997-10/proceedings/>`_ for more information.)
2642
-Internally, Python source code is always translated into a bytecode
2643
-representation, and this bytecode is then executed by the Python virtual
2644
-machine. In order to avoid the overhead of repeatedly parsing and translating
2645
-modules that rarely change, this byte code is written into a file whose name
2646
-ends in ".pyc" whenever a module is parsed. When the corresponding .py file is
2647
-changed, it is parsed and translated again and the .pyc file is rewritten.
2649
-There is no performance difference once the .pyc file has been loaded, as the
2650
-bytecode read from the .pyc file is exactly the same as the bytecode created by
2651
-direct translation. The only difference is that loading code from a .pyc file
2652
-is faster than parsing and translating a .py file, so the presence of
2653
-precompiled .pyc files improves the start-up time of Python scripts. If
2654
-desired, the Lib/compileall.py module can be used to create valid .pyc files for
2655
-a given set of modules.
2657
-Note that the main script executed by Python, even if its filename ends in .py,
2658
-is not compiled to a .pyc file. It is compiled to bytecode, but the bytecode is
2659
-not saved to a file. Usually main scripts are quite short, so this doesn't cost
2662
-.. XXX check which of these projects are still alive
2664
-There are also several programs which make it easier to intermingle Python and C
2665
-code in various ways to increase performance. See, for example, `Cython
2666
-<http://cython.org/>`_, `Pyrex
2667
-<http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/>`_ and `Weave
2668
-<http://www.scipy.org/Weave>`_.
2671
How does Python manage memory?
2672
------------------------------
2674
The details of Python memory management depend on the implementation. The
2675
-standard C implementation of Python uses reference counting to detect
2676
-inaccessible objects, and another mechanism to collect reference cycles,
2677
+standard implementation of Python, :term:`CPython`, uses reference counting to
2678
+detect inaccessible objects, and another mechanism to collect reference cycles,
2679
periodically executing a cycle detection algorithm which looks for inaccessible
2680
cycles and deletes the objects involved. The :mod:`gc` module provides functions
2681
to perform a garbage collection, obtain debugging statistics, and tune the
2682
collector's parameters.
2684
-Jython relies on the Java runtime so the JVM's garbage collector is used. This
2685
-difference can cause some subtle porting problems if your Python code depends on
2686
-the behavior of the reference counting implementation.
2687
+Other implementations (such as `Jython <http://www.jython.org>`_ or
2688
+`PyPy <http://www.pypy.org>`_), however, can rely on a different mechanism
2689
+such as a full-blown garbage collector. This difference can cause some
2690
+subtle porting problems if your Python code depends on the behavior of the
2691
+reference counting implementation.
2693
-.. XXX relevant for Python 3?
2694
+In some Python implementations, the following code (which is fine in CPython)
2695
+will probably run out of file descriptors::
2697
- Sometimes objects get stuck in traceback temporarily and hence are not
2698
- deallocated when you might expect. Clear the traceback with::
2699
+ for file in very_long_list_of_files:
2704
- sys.last_traceback = None
2705
+Indeed, using CPython's reference counting and destructor scheme, each new
2706
+assignment to *f* closes the previous file. With a traditional GC, however,
2707
+those file objects will only get collected (and closed) at varying and possibly
2710
- Tracebacks are used for reporting errors, implementing debuggers and related
2711
- things. They contain a portion of the program state extracted during the
2712
- handling of an exception (usually the most recent exception).
2713
+If you want to write code that will work with any Python implementation,
2714
+you should explicitly close the file or use the :keyword:`with` statement;
2715
+this will work regardless of memory management scheme::
2717
-In the absence of circularities, Python programs do not need to manage memory
2719
+ for file in very_long_list_of_files:
2720
+ with open(file) as f:
2723
-Why doesn't Python use a more traditional garbage collection scheme? For one
2724
-thing, this is not a C standard feature and hence it's not portable. (Yes, we
2725
-know about the Boehm GC library. It has bits of assembler code for *most*
2726
-common platforms, not for all of them, and although it is mostly transparent, it
2727
-isn't completely transparent; patches are required to get Python to work with
2730
+Why doesn't CPython use a more traditional garbage collection scheme?
2731
+---------------------------------------------------------------------
2733
+For one thing, this is not a C standard feature and hence it's not portable.
2734
+(Yes, we know about the Boehm GC library. It has bits of assembler code for
2735
+*most* common platforms, not for all of them, and although it is mostly
2736
+transparent, it isn't completely transparent; patches are required to get
2737
+Python to work with it.)
2739
Traditional GC also becomes a problem when Python is embedded into other
2740
applications. While in a standalone Python it's fine to replace the standard
2741
malloc() and free() with versions provided by the GC library, an application
2742
embedding Python may want to have its *own* substitute for malloc() and free(),
2743
-and may not want Python's. Right now, Python works with anything that
2744
+and may not want Python's. Right now, CPython works with anything that
2745
implements malloc() and free() properly.
2747
-In Jython, the following code (which is fine in CPython) will probably run out
2748
-of file descriptors long before it runs out of memory::
2750
- for file in very_long_list_of_files:
2754
-Using the current reference counting and destructor scheme, each new assignment
2755
-to f closes the previous file. Using GC, this is not guaranteed. If you want
2756
-to write code that will work with any Python implementation, you should
2757
-explicitly close the file or use the :keyword:`with` statement; this will work
2760
- for file in very_long_list_of_files:
2761
- with open(file) as f:
2765
-Why isn't all memory freed when Python exits?
2766
----------------------------------------------
2767
+Why isn't all memory freed when CPython exits?
2768
+----------------------------------------------
2770
Objects referenced from the global namespaces of Python modules are not always
2771
deallocated when Python exits. This may happen if there are circular
2772
@@ -647,10 +625,10 @@
2773
you won't be fooled into accidentally overwriting a list when you need a sorted
2774
copy but also need to keep the unsorted version around.
2776
-In Python 2.4 a new built-in function -- :func:`sorted` -- has been added.
2777
-This function creates a new list from a provided iterable, sorts it and returns
2778
-it. For example, here's how to iterate over the keys of a dictionary in sorted
2780
+If you want to return a new list, use the built-in :func:`sorted` function
2781
+instead. This function creates a new list from a provided iterable, sorts
2782
+it and returns it. For example, here's how to iterate over the keys of a
2783
+dictionary in sorted order::
2785
for key in sorted(mydict):
2786
... # do whatever with mydict[key]...
2787
diff -r 137e45f15c0b Doc/faq/extending.rst
2788
--- a/Doc/faq/extending.rst
2789
+++ b/Doc/faq/extending.rst
2791
There are a number of alternatives to writing your own C extensions, depending
2792
on what you're trying to do.
2794
-.. XXX make sure these all work; mention Cython
2796
-If you need more speed, `Psyco <http://psyco.sourceforge.net/>`_ generates x86
2797
-assembly code from Python bytecode. You can use Psyco to compile the most
2798
-time-critical functions in your code, and gain a significant improvement with
2799
-very little effort, as long as you're running on a machine with an
2800
-x86-compatible processor.
2801
+.. XXX make sure these all work
2803
`Cython <http://cython.org>`_ and its relative `Pyrex
2804
<http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/>`_ are compilers
2806
How do I use Py_BuildValue() to create a tuple of arbitrary length?
2807
-------------------------------------------------------------------
2809
-You can't. Use ``t = PyTuple_New(n)`` instead, and fill it with objects using
2810
-``PyTuple_SetItem(t, i, o)`` -- note that this "eats" a reference count of
2811
-``o``, so you have to :c:func:`Py_INCREF` it. Lists have similar functions
2812
-``PyList_New(n)`` and ``PyList_SetItem(l, i, o)``. Note that you *must* set all
2813
-the tuple items to some value before you pass the tuple to Python code --
2814
-``PyTuple_New(n)`` initializes them to NULL, which isn't a valid Python value.
2815
+You can't. Use :c:func:`PyTuple_Pack` instead.
2818
How do I call an object's method from C?
2819
@@ -153,21 +142,30 @@
2820
just allow the standard traceback mechanism to work. Then, the output will go
2821
wherever your ``write()`` method sends it.
2823
-The easiest way to do this is to use the StringIO class in the standard library.
2824
+The easiest way to do this is to use the :class:`io.StringIO` class::
2826
-Sample code and use for catching stdout:
2827
+ >>> import io, sys
2828
+ >>> sys.stdout = io.StringIO()
2830
+ >>> print('hello world!')
2831
+ >>> sys.stderr.write(sys.stdout.getvalue())
2835
- >>> class StdoutCatcher:
2836
+A custom object to do the same would look like this::
2838
+ >>> import io, sys
2839
+ >>> class StdoutCatcher(io.TextIOBase):
2840
... def __init__(self):
2841
- ... self.data = ''
2842
+ ... self.data = []
2843
... def write(self, stuff):
2844
- ... self.data = self.data + stuff
2845
+ ... self.data.append(stuff)
2848
>>> sys.stdout = StdoutCatcher()
2850
>>> print('hello world!')
2851
- >>> sys.stderr.write(sys.stdout.data)
2852
+ >>> sys.stderr.write(''.join(sys.stdout.data))
2856
diff -r 137e45f15c0b Doc/faq/general.rst
2857
--- a/Doc/faq/general.rst
2858
+++ b/Doc/faq/general.rst
2860
window systems, and is extensible in C or C++. It is also usable as an
2861
extension language for applications that need a programmable interface.
2862
Finally, Python is portable: it runs on many Unix variants, on the Mac, and on
2863
-PCs under MS-DOS, Windows, Windows NT, and OS/2.
2864
+Windows 2000 and later.
2866
To find out more, start with :ref:`tutorial-index`. The `Beginner's Guide to
2867
Python <http://wiki.python.org/moin/BeginnersGuide>`_ links to other
2868
@@ -157,16 +157,14 @@
2870
The latest Python source distribution is always available from python.org, at
2871
http://www.python.org/download/. The latest development sources can be obtained
2872
-via anonymous Subversion at http://svn.python.org/projects/python/trunk.
2873
+via anonymous Mercurial access at http://hg.python.org/cpython.
2875
The source distribution is a gzipped tar file containing the complete C source,
2876
Sphinx-formatted documentation, Python library modules, example programs, and
2877
several useful pieces of freely distributable software. The source will compile
2878
and run out of the box on most UNIX platforms.
2880
-.. XXX update link once the dev faq is relocated
2882
-Consult the `Developer FAQ <http://www.python.org/dev/faq/>`__ for more
2883
+Consult the `Developer FAQ <http://docs.python.org/devguide/faq>`__ for more
2884
information on getting the source code and compiling it.
2887
@@ -221,10 +219,8 @@
2888
newsgroups and on the Python home page at http://www.python.org/; an RSS feed of
2891
-.. XXX update link once the dev faq is relocated
2893
You can also access the development version of Python through Subversion. See
2894
-http://www.python.org/dev/faq/ for details.
2895
+http://docs.python.org/devguide/faq for details.
2898
How do I submit bug reports and patches for Python?
2899
@@ -239,10 +235,8 @@
2900
report bugs to Python, you can obtain your Roundup password through Roundup's
2901
`password reset procedure <http://bugs.python.org/user?@template=forgotten>`_.
2903
-.. XXX adapt link to dev guide
2905
For more information on how Python is developed, consult `the Python Developer's
2906
-Guide <http://python.org/dev/>`_.
2907
+Guide <http://docs.python.org/devguide/>`_.
2910
Are there any published articles about Python that I can reference?
2911
@@ -475,38 +469,3 @@
2912
If you want to discuss Python's use in education, you may be interested in
2913
joining `the edu-sig mailing list
2914
<http://python.org/community/sigs/current/edu-sig>`_.
2920
-What is this bsddb185 module my application keeps complaining about?
2921
---------------------------------------------------------------------
2923
-.. XXX remove this question?
2925
-Starting with Python2.3, the distribution includes the `PyBSDDB package
2926
-<http://pybsddb.sf.net/>` as a replacement for the old bsddb module. It
2927
-includes functions which provide backward compatibility at the API level, but
2928
-requires a newer version of the underlying `Berkeley DB
2929
-<http://www.sleepycat.com>`_ library. Files created with the older bsddb module
2930
-can't be opened directly using the new module.
2932
-Using your old version of Python and a pair of scripts which are part of Python
2933
-2.3 (db2pickle.py and pickle2db.py, in the Tools/scripts directory) you can
2934
-convert your old database files to the new format. Using your old Python
2935
-version, run the db2pickle.py script to convert it to a pickle, e.g.::
2937
- python2.2 <pathto>/db2pickley.py database.db database.pck
2939
-Rename your database file::
2941
- mv database.db olddatabase.db
2943
-Now convert the pickle file to a new format database::
2945
- python <pathto>/pickle2db.py database.db database.pck
2947
-The precise commands you use will vary depending on the particulars of your
2948
-installation. For full details about operation of these two scripts check the
2949
-doc string at the start of each one.
2950
diff -r 137e45f15c0b Doc/faq/gui.rst
2951
--- a/Doc/faq/gui.rst
2952
+++ b/Doc/faq/gui.rst
2957
-PyGtk bindings for the `Gtk+ toolkit <http://www.gtk.org>`_ have been
2958
-implemented by James Henstridge; see <http://www.pygtk.org>.
2959
+The `GObject introspection bindings <https://live.gnome.org/PyGObject>`_
2960
+for Python allow you to write GTK+ 3 applications. There is also a
2961
+`Python GTK+ 3 Tutorial <http://python-gtk-3-tutorial.readthedocs.org/en/latest/>`_.
2963
+The older PyGtk bindings for the `Gtk+ 2 toolkit <http://www.gtk.org>`_ have
2964
+been implemented by James Henstridge; see <http://www.pygtk.org>.
2968
diff -r 137e45f15c0b Doc/faq/library.rst
2969
--- a/Doc/faq/library.rst
2970
+++ b/Doc/faq/library.rst
2971
@@ -814,52 +814,6 @@
2972
general such as using gdbm with pickle/shelve.
2975
-If my program crashes with a bsddb (or anydbm) database open, it gets corrupted. How come?
2976
-------------------------------------------------------------------------------------------
2978
-.. XXX move this FAQ entry elsewhere?
2982
- The bsddb module is now available as a standalone package `pybsddb
2983
- <http://www.jcea.es/programacion/pybsddb.htm>`_.
2985
-Databases opened for write access with the bsddb module (and often by the anydbm
2986
-module, since it will preferentially use bsddb) must explicitly be closed using
2987
-the ``.close()`` method of the database. The underlying library caches database
2988
-contents which need to be converted to on-disk form and written.
2990
-If you have initialized a new bsddb database but not written anything to it
2991
-before the program crashes, you will often wind up with a zero-length file and
2992
-encounter an exception the next time the file is opened.
2995
-I tried to open Berkeley DB file, but bsddb produces bsddb.error: (22, 'Invalid argument'). Help! How can I restore my data?
2996
-----------------------------------------------------------------------------------------------------------------------------
2998
-.. XXX move this FAQ entry elsewhere?
3002
- The bsddb module is now available as a standalone package `pybsddb
3003
- <http://www.jcea.es/programacion/pybsddb.htm>`_.
3005
-Don't panic! Your data is probably intact. The most frequent cause for the error
3006
-is that you tried to open an earlier Berkeley DB file with a later version of
3007
-the Berkeley DB library.
3009
-Many Linux systems now have all three versions of Berkeley DB available. If you
3010
-are migrating from version 1 to a newer version use db_dump185 to dump a plain
3011
-text version of the database. If you are migrating from version 2 to version 3
3012
-use db2_dump to create a plain text version of the database. In either case,
3013
-use db_load to create a new native database for the latest version installed on
3014
-your computer. If you have version 3 of Berkeley DB installed, you should be
3015
-able to use db2_load to create a native version 2 database.
3017
-You should move away from Berkeley DB version 1 files because the hash file code
3018
-contains known bugs that can corrupt your data.
3021
Mathematics and Numerics
3022
========================
3024
diff -r 137e45f15c0b Doc/faq/programming.rst
3025
--- a/Doc/faq/programming.rst
3026
+++ b/Doc/faq/programming.rst
3027
@@ -115,167 +115,6 @@
3031
-My program is too slow. How do I speed it up?
3032
----------------------------------------------
3034
-That's a tough one, in general. There are many tricks to speed up Python code;
3035
-consider rewriting parts in C as a last resort.
3037
-In some cases it's possible to automatically translate Python to C or x86
3038
-assembly language, meaning that you don't have to modify your code to gain
3041
-.. XXX seems to have overlap with other questions!
3043
-`Cython <http://cython.org>`_ and `Pyrex <http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/>`_
3044
-can compile a slightly modified version of Python code into a C extension, and
3045
-can be used on many different platforms.
3047
-`Psyco <http://psyco.sourceforge.net>`_ is a just-in-time compiler that
3048
-translates Python code into x86 assembly language. If you can use it, Psyco can
3049
-provide dramatic speedups for critical functions.
3051
-The rest of this answer will discuss various tricks for squeezing a bit more
3052
-speed out of Python code. *Never* apply any optimization tricks unless you know
3053
-you need them, after profiling has indicated that a particular function is the
3054
-heavily executed hot spot in the code. Optimizations almost always make the
3055
-code less clear, and you shouldn't pay the costs of reduced clarity (increased
3056
-development time, greater likelihood of bugs) unless the resulting performance
3057
-benefit is worth it.
3059
-There is a page on the wiki devoted to `performance tips
3060
-<http://wiki.python.org/moin/PythonSpeed/PerformanceTips>`_.
3062
-Guido van Rossum has written up an anecdote related to optimization at
3063
-http://www.python.org/doc/essays/list2str.html.
3065
-One thing to notice is that function and (especially) method calls are rather
3066
-expensive; if you have designed a purely OO interface with lots of tiny
3067
-functions that don't do much more than get or set an instance variable or call
3068
-another method, you might consider using a more direct way such as directly
3069
-accessing instance variables. Also see the standard module :mod:`profile` which
3070
-makes it possible to find out where your program is spending most of its time
3071
-(if you have some patience -- the profiling itself can slow your program down by
3072
-an order of magnitude).
3074
-Remember that many standard optimization heuristics you may know from other
3075
-programming experience may well apply to Python. For example it may be faster
3076
-to send output to output devices using larger writes rather than smaller ones in
3077
-order to reduce the overhead of kernel system calls. Thus CGI scripts that
3078
-write all output in "one shot" may be faster than those that write lots of small
3081
-Also, be sure to use Python's core features where appropriate. For example,
3082
-slicing allows programs to chop up lists and other sequence objects in a single
3083
-tick of the interpreter's mainloop using highly optimized C implementations.
3084
-Thus to get the same effect as::
3087
- for i in range(3):
3090
-it is much shorter and far faster to use ::
3092
- L2 = list(L1[:3]) # "list" is redundant if L1 is a list.
3094
-Note that the functionally-oriented built-in functions such as :func:`map`,
3095
-:func:`zip`, and friends can be a convenient accelerator for loops that
3096
-perform a single task. For example to pair the elements of two lists
3099
- >>> list(zip([1, 2, 3], [4, 5, 6]))
3100
- [(1, 4), (2, 5), (3, 6)]
3102
-or to compute a number of sines::
3104
- >>> list(map(math.sin, (1, 2, 3, 4)))
3105
- [0.841470984808, 0.909297426826, 0.14112000806, -0.756802495308]
3107
-The operation completes very quickly in such cases.
3109
-Other examples include the ``join()`` and ``split()`` :ref:`methods
3110
-of string objects <string-methods>`.
3112
-For example if s1..s7 are large (10K+) strings then
3113
-``"".join([s1,s2,s3,s4,s5,s6,s7])`` may be far faster than the more obvious
3114
-``s1+s2+s3+s4+s5+s6+s7``, since the "summation" will compute many
3115
-subexpressions, whereas ``join()`` does all the copying in one pass. For
3116
-manipulating strings, use the ``replace()`` and the ``format()`` :ref:`methods
3117
-on string objects <string-methods>`. Use regular expressions only when you're
3118
-not dealing with constant string patterns.
3120
-Be sure to use the :meth:`list.sort` built-in method to do sorting, and see the
3121
-`sorting mini-HOWTO <http://wiki.python.org/moin/HowTo/Sorting>`_ for examples
3122
-of moderately advanced usage. :meth:`list.sort` beats other techniques for
3123
-sorting in all but the most extreme circumstances.
3125
-Another common trick is to "push loops into functions or methods." For example
3126
-suppose you have a program that runs slowly and you use the profiler to
3127
-determine that a Python function ``ff()`` is being called lots of times. If you
3128
-notice that ``ff()``::
3131
- ... # do something with x computing result...
3134
-tends to be called in loops like::
3136
- list = map(ff, oldlist)
3140
- for x in sequence:
3142
- ... # do something with value...
3144
-then you can often eliminate function call overhead by rewriting ``ff()`` to::
3149
- ... # do something with x computing result...
3150
- resultseq.append(result)
3153
-and rewrite the two examples to ``list = ffseq(oldlist)`` and to::
3155
- for value in ffseq(sequence):
3156
- ... # do something with value...
3158
-Single calls to ``ff(x)`` translate to ``ffseq([x])[0]`` with little penalty.
3159
-Of course this technique is not always appropriate and there are other variants
3160
-which you can figure out.
3162
-You can gain some performance by explicitly storing the results of a function or
3163
-method lookup into a local variable. A loop like::
3166
- dict[key] = dict.get(key, 0) + 1
3168
-resolves ``dict.get`` every iteration. If the method isn't going to change, a
3169
-slightly faster implementation is::
3171
- dict_get = dict.get # look up the method once
3173
- dict[key] = dict_get(key, 0) + 1
3175
-Default arguments can be used to determine values once, at compile time instead
3176
-of at run time. This can only be done for functions or objects which will not
3177
-be changed during program execution, such as replacing ::
3179
- def degree_sin(deg):
3180
- return math.sin(deg * math.pi / 180.0)
3184
- def degree_sin(deg, factor=math.pi/180.0, sin=math.sin):
3185
- return sin(deg * factor)
3187
-Because this trick uses default arguments for terms which should not be changed,
3188
-it should only be used when you are not concerned with presenting a possibly
3189
-confusing API to your users.
1
# DP: hg updates of the 3.2 release branch (until 2012-03-09).
3
# hg diff -r v3.2.3rc1 | filterdiff --exclude=.hgignore --exclude=.hgeol --exclude=.hgtags --remove-timestamps
5
diff -r 7085403daf43 .hgtags
9
ac1f7e5c05104d557d5acd922e95625ba5d1fe10 v3.2.1
10
c860feaa348d663e598986894ee4680480577e15 v3.2.2rc1
11
137e45f15c0bd262c9ad4c032d97425bc0589456 v3.2.2
12
+7085403daf439adb3f9e70ef13f6bedb1c447376 v3.2.3rc1
13
diff -r 7085403daf43 Doc/howto/advocacy.rst
14
--- a/Doc/howto/advocacy.rst
15
+++ b/Doc/howto/advocacy.rst
18
**What are the restrictions on Python's use?**
20
-They're practically nonexistent. Consult the :file:`Misc/COPYRIGHT` file in the
21
-source distribution, or the section :ref:`history-and-license` for the full
22
+They're practically nonexistent. Consult :ref:`history-and-license` for the full
23
language, but it boils down to three conditions:
25
* You have to leave the copyright notice on the software; if you don't include
26
diff -r 7085403daf43 Doc/howto/cporting.rst
27
--- a/Doc/howto/cporting.rst
28
+++ b/Doc/howto/cporting.rst
33
-********************************
34
-Porting Extension Modules to 3.0
35
-********************************
36
+*************************************
37
+Porting Extension Modules to Python 3
38
+*************************************
40
:author: Benjamin Peterson
45
- Although changing the C-API was not one of Python 3.0's objectives, the many
46
- Python level changes made leaving 2.x's API intact impossible. In fact, some
47
- changes such as :func:`int` and :func:`long` unification are more obvious on
48
- the C level. This document endeavors to document incompatibilities and how
49
- they can be worked around.
50
+ Although changing the C-API was not one of Python 3's objectives,
51
+ the many Python-level changes made leaving Python 2's API intact
52
+ impossible. In fact, some changes such as :func:`int` and
53
+ :func:`long` unification are more obvious on the C level. This
54
+ document endeavors to document incompatibilities and how they can
58
Conditional compilation
59
=======================
61
-The easiest way to compile only some code for 3.0 is to check if
62
-:c:macro:`PY_MAJOR_VERSION` is greater than or equal to 3. ::
63
+The easiest way to compile only some code for Python 3 is to check
64
+if :c:macro:`PY_MAJOR_VERSION` is greater than or equal to 3. ::
66
#if PY_MAJOR_VERSION >= 3
69
Changes to Object APIs
70
======================
72
-Python 3.0 merged together some types with similar functions while cleanly
73
+Python 3 merged together some types with similar functions while cleanly
78
-----------------------
81
-Python 3.0's :func:`str` (``PyString_*`` functions in C) type is equivalent to
82
-2.x's :func:`unicode` (``PyUnicode_*``). The old 8-bit string type has become
83
-:func:`bytes`. Python 2.6 and later provide a compatibility header,
84
+Python 3's :func:`str` (``PyString_*`` functions in C) type is equivalent to
85
+Python 2's :func:`unicode` (``PyUnicode_*``). The old 8-bit string type has
86
+become :func:`bytes`. Python 2.6 and later provide a compatibility header,
87
:file:`bytesobject.h`, mapping ``PyBytes`` names to ``PyString`` ones. For best
88
-compatibility with 3.0, :c:type:`PyUnicode` should be used for textual data and
89
+compatibility with Python 3, :c:type:`PyUnicode` should be used for textual data and
90
:c:type:`PyBytes` for binary data. It's also important to remember that
91
-:c:type:`PyBytes` and :c:type:`PyUnicode` in 3.0 are not interchangeable like
92
-:c:type:`PyString` and :c:type:`PyUnicode` are in 2.x. The following example
93
+:c:type:`PyBytes` and :c:type:`PyUnicode` in Python 3 are not interchangeable like
94
+:c:type:`PyString` and :c:type:`PyUnicode` are in Python 2. The following example
95
shows best practices with regards to :c:type:`PyUnicode`, :c:type:`PyString`,
96
and :c:type:`PyBytes`. ::
102
-In Python 3.0, there is only one integer type. It is called :func:`int` on the
103
-Python level, but actually corresponds to 2.x's :func:`long` type. In the
104
-C-API, ``PyInt_*`` functions are replaced by their ``PyLong_*`` neighbors. The
105
-best course of action here is using the ``PyInt_*`` functions aliased to
106
+Python 3 has only one integer type, :func:`int`. But it actually
107
+corresponds to Python 2's :func:`long` type--the :func:`int` type
108
+used in Python 2 was removed. In the C-API, ``PyInt_*`` functions
109
+are replaced by their ``PyLong_*`` equivalents.
111
+The best course of action here is using the ``PyInt_*`` functions aliased to
112
``PyLong_*`` found in :file:`intobject.h`. The abstract ``PyNumber_*`` APIs
113
can also be used in some cases. ::
115
@@ -120,10 +123,11 @@
116
Module initialization and state
117
===============================
119
-Python 3.0 has a revamped extension module initialization system. (See
120
-:pep:`3121`.) Instead of storing module state in globals, they should be stored
121
-in an interpreter specific structure. Creating modules that act correctly in
122
-both 2.x and 3.0 is tricky. The following simple example demonstrates how. ::
123
+Python 3 has a revamped extension module initialization system. (See
124
+:pep:`3121`.) Instead of storing module state in globals, they should
125
+be stored in an interpreter specific structure. Creating modules that
126
+act correctly in both Python 2 and Python 3 is tricky. The following
127
+simple example demonstrates how. ::
131
@@ -209,10 +213,65 @@
135
+CObject replaced with Capsule
136
+=============================
138
+The :c:type:`Capsule` object was introduced in Python 3.1 and 2.7 to replace
139
+:c:type:`CObject`. CObjects were useful,
140
+but the :c:type:`CObject` API was problematic: it didn't permit distinguishing
141
+between valid CObjects, which allowed mismatched CObjects to crash the
142
+interpreter, and some of its APIs relied on undefined behavior in C.
143
+(For further reading on the rationale behind Capsules, please see :issue:`5630`.)
145
+If you're currently using CObjects, and you want to migrate to 3.1 or newer,
146
+you'll need to switch to Capsules.
147
+:c:type:`CObject` was deprecated in 3.1 and 2.7 and completely removed in
148
+Python 3.2. If you only support 2.7, or 3.1 and above, you
149
+can simply switch to :c:type:`Capsule`. If you need to support Python 3.0,
150
+or versions of Python earlier than 2.7,
151
+you'll have to support both CObjects and Capsules.
152
+(Note that Python 3.0 is no longer supported, and it is not recommended
153
+for production use.)
155
+The following example header file :file:`capsulethunk.h` may
156
+solve the problem for you. Simply write your code against the
157
+:c:type:`Capsule` API and include this header file after
158
+:file:`Python.h`. Your code will automatically use Capsules
159
+in versions of Python with Capsules, and switch to CObjects
160
+when Capsules are unavailable.
162
+:file:`capsulethunk.h` simulates Capsules using CObjects. However,
163
+:c:type:`CObject` provides no place to store the capsule's "name". As a
164
+result the simulated :c:type:`Capsule` objects created by :file:`capsulethunk.h`
165
+behave slightly differently from real Capsules. Specifically:
167
+ * The name parameter passed in to :c:func:`PyCapsule_New` is ignored.
169
+ * The name parameter passed in to :c:func:`PyCapsule_IsValid` and
170
+ :c:func:`PyCapsule_GetPointer` is ignored, and no error checking
171
+ of the name is performed.
173
+ * :c:func:`PyCapsule_GetName` always returns NULL.
175
+ * :c:func:`PyCapsule_SetName` always throws an exception and
176
+ returns failure. (Since there's no way to store a name
177
+ in a CObject, noisy failure of :c:func:`PyCapsule_SetName`
178
+ was deemed preferable to silent failure here. If this is
179
+ inconveient, feel free to modify your local
180
+ copy as you see fit.)
182
+You can find :file:`capsulethunk.h` in the Python source distribution
183
+as :source:`Doc/includes/capsulethunk.h`. We also include it here for
186
+.. literalinclude:: ../includes/capsulethunk.h
3195
@@ -687,61 +526,21 @@
3196
Is there an equivalent of C's "?:" ternary operator?
3197
----------------------------------------------------
3199
-Yes, this feature was added in Python 2.5. The syntax would be as follows::
3200
+Yes, there is. The syntax is as follows::
3202
[on_true] if [expression] else [on_false]
3206
small = x if x < y else y
3208
-For versions previous to 2.5 the answer would be 'No'.
3209
+Before this syntax was introduced in Python 2.5, a common idiom was to use
3210
+logical operators::
3212
-.. XXX remove rest?
3213
+ [expression] and [on_true] or [on_false]
3215
-In many cases you can mimic ``a ? b : c`` with ``a and b or c``, but there's a
3216
-flaw: if *b* is zero (or empty, or ``None`` -- anything that tests false) then
3217
-*c* will be selected instead. In many cases you can prove by looking at the
3218
-code that this can't happen (e.g. because *b* is a constant or has a type that
3219
-can never be false), but in general this can be a problem.
3221
-Tim Peters (who wishes it was Steve Majewski) suggested the following solution:
3222
-``(a and [b] or [c])[0]``. Because ``[b]`` is a singleton list it is never
3223
-false, so the wrong path is never taken; then applying ``[0]`` to the whole
3224
-thing gets the *b* or *c* that you really wanted. Ugly, but it gets you there
3225
-in the rare cases where it is really inconvenient to rewrite your code using
3228
-The best course is usually to write a simple ``if...else`` statement. Another
3229
-solution is to implement the ``?:`` operator as a function::
3231
- def q(cond, on_true, on_false):
3233
- if not isfunction(on_true):
3238
- if not isfunction(on_false):
3243
-In most cases you'll pass b and c directly: ``q(a, b, c)``. To avoid evaluating
3244
-b or c when they shouldn't be, encapsulate them within a lambda function, e.g.:
3245
-``q(a, lambda: b, lambda: c)``.
3247
-It has been asked *why* Python has no if-then-else expression. There are
3248
-several answers: many languages do just fine without one; it can easily lead to
3249
-less readable code; no sufficiently "Pythonic" syntax has been discovered; a
3250
-search of the standard library found remarkably few places where using an
3251
-if-then-else expression would make the code more understandable.
3253
-In 2002, :pep:`308` was written proposing several possible syntaxes and the
3254
-community was asked to vote on the issue. The vote was inconclusive. Most
3255
-people liked one of the syntaxes, but also hated other syntaxes; many votes
3256
-implied that people preferred no ternary operator rather than having a syntax
3258
+However, this idiom is unsafe, as it can give wrong results when *on_true*
3259
+has a false boolean value. Therefore, it is always better to use
3260
+the ``... if ... else ...`` form.
3263
Is it possible to write obfuscated one-liners in Python?
3264
@@ -860,15 +659,21 @@
3265
How do I modify a string in place?
3266
----------------------------------
3268
-You can't, because strings are immutable. If you need an object with this
3269
-ability, try converting the string to a list or use the array module::
3270
+You can't, because strings are immutable. In most situations, you should
3271
+simply construct a new string from the various parts you want to assemble
3272
+it from. However, if you need an object with the ability to modify in-place
3273
+unicode data, try using a :class:`io.StringIO` object or the :mod:`array`
3276
>>> s = "Hello, world"
3279
- ['H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd']
3280
- >>> a[7:] = list("there!")
3282
+ >>> sio = io.StringIO(s)
3283
+ >>> sio.getvalue()
3287
+ >>> sio.write("there!")
3289
+ >>> sio.getvalue()
3293
@@ -943,11 +748,11 @@
3294
Is there an equivalent to Perl's chomp() for removing trailing newlines from strings?
3295
-------------------------------------------------------------------------------------
3297
-Starting with Python 2.2, you can use ``S.rstrip("\r\n")`` to remove all
3298
-occurrences of any line terminator from the end of the string ``S`` without
3299
-removing other trailing whitespace. If the string ``S`` represents more than
3300
-one line, with several empty lines at the end, the line terminators for all the
3301
-blank lines will be removed::
3302
+You can use ``S.rstrip("\r\n")`` to remove all occurrences of any line
3303
+terminator from the end of the string ``S`` without removing other trailing
3304
+whitespace. If the string ``S`` represents more than one line, with several
3305
+empty lines at the end, the line terminators for all the blank lines will
3308
>>> lines = ("line 1 \r\n"
3310
@@ -958,15 +763,6 @@
3311
Since this is typically only desired when reading text one line at a time, using
3312
``S.rstrip()`` this way works well.
3314
-For older versions of Python, there are two partial substitutes:
3316
- string objects. This removes all trailing whitespace, not just a single
3319
- ``S.splitlines()[0]``.
3322
Is there a scanf() or sscanf() equivalent?
3323
------------------------------------------
3324
@@ -989,6 +785,94 @@
3325
See the :ref:`unicode-howto`.
3331
+My program is too slow. How do I speed it up?
3332
+---------------------------------------------
3334
+That's a tough one, in general. First, here are a list of things to
3335
+remember before diving further:
3337
+* Performance characteristics vary accross Python implementations. This FAQ
3338
+ focusses on :term:`CPython`.
3339
+* Behaviour can vary accross operating systems, especially when talking about
3340
+ I/O or multi-threading.
3341
+* You should always find the hot spots in your program *before* attempting to
3342
+ optimize any code (see the :mod:`profile` module).
3343
+* Writing benchmark scripts will allow you to iterate quickly when searching
3344
+ for improvements (see the :mod:`timeit` module).
3345
+* It is highly recommended to have good code coverage (through unit testing
3346
+ or any other technique) before potentially introducing regressions hidden
3347
+ in sophisticated optimizations.
3349
+That being said, there are many tricks to speed up Python code. Here are
3350
+some general principles which go a long way towards reaching acceptable
3351
+performance levels:
3353
+* Making your algorithms faster (or changing to faster ones) can yield
3354
+ much larger benefits than trying to sprinkle micro-optimization tricks
3355
+ all over your code.
3357
+* Use the right data structures. Study documentation for the :ref:`bltin-types`
3358
+ and the :mod:`collections` module.
3360
+* When the standard library provides a primitive for doing something, it is
3361
+ likely (although not guaranteed) to be faster than any alternative you
3362
+ may come up with. This is doubly true for primitives written in C, such
3363
+ as builtins and some extension types. For example, be sure to use
3364
+ either the :meth:`list.sort` built-in method or the related :func:`sorted`
3365
+ function to do sorting (and see the
3366
+ `sorting mini-HOWTO <http://wiki.python.org/moin/HowTo/Sorting>`_ for examples
3367
+ of moderately advanced usage).
3369
+* Abstractions tend to create indirections and force the interpreter to work
3370
+ more. If the levels of indirection outweigh the amount of useful work
3371
+ done, your program will be slower. You should avoid excessive abstraction,
3372
+ especially under the form of tiny functions or methods (which are also often
3373
+ detrimental to readability).
3375
+If you have reached the limit of what pure Python can allow, there are tools
3376
+to take you further away. For example, `Cython <http://cython.org>`_ can
3377
+compile a slightly modified version of Python code into a C extension, and
3378
+can be used on many different platforms. Cython can take advantage of
3379
+compilation (and optional type annotations) to make your code significantly
3380
+faster than when interpreted. If you are confident in your C programming
3381
+skills, you can also :ref:`write a C extension module <extending-index>`
3385
+ The wiki page devoted to `performance tips
3386
+ <http://wiki.python.org/moin/PythonSpeed/PerformanceTips>`_.
3388
+.. _efficient_string_concatenation:
3390
+What is the most efficient way to concatenate many strings together?
3391
+--------------------------------------------------------------------
3393
+:class:`str` and :class:`bytes` objects are immutable, therefore concatenating
3394
+many strings together is inefficient as each concatenation creates a new
3395
+object. In the general case, the total runtime cost is quadratic in the
3396
+total string length.
3398
+To accumulate many :class:`str` objects, the recommended idiom is to place
3399
+them into a list and call :meth:`str.join` at the end::
3402
+ for s in my_strings:
3404
+ result = ''.join(chunks)
3406
+(another reasonably efficient idiom is to use :class:`io.StringIO`)
3408
+To accumulate many :class:`bytes` objects, the recommended idiom is to extend
3409
+a :class:`bytearray` object using in-place concatenation (the ``+=`` operator)::
3411
+ result = bytearray()
3412
+ for b in my_bytes_objects:
3416
Sequences (Tuples/Lists)
3417
========================
3419
@@ -1058,15 +942,8 @@
3423
-If all elements of the list may be used as dictionary keys (i.e. they are all
3424
-hashable) this is often faster ::
3429
- mylist = list(d.keys())
3431
-In Python 2.5 and later, the following is possible instead::
3432
+If all elements of the list may be used as set keys (i.e. they are all
3433
+:term:`hashable`) this is often faster ::
3435
mylist = list(set(mylist))
3437
@@ -1436,15 +1313,7 @@
3441
-Static methods are possible since Python 2.2::
3444
- def static(arg1, arg2, arg3):
3445
- # No 'self' parameter!
3447
- static = staticmethod(static)
3449
-With Python 2.4's decorators, this can also be written as ::
3450
+Static methods are possible::
3454
diff -r 137e45f15c0b Doc/glossary.rst
3455
--- a/Doc/glossary.rst
3456
+++ b/Doc/glossary.rst
3458
Abstract base classes complement :term:`duck-typing` by
3459
providing a way to define interfaces when other techniques like
3460
:func:`hasattr` would be clumsy or subtly wrong (for example with
3461
- :ref:`magic methods <special-lookup>`). Python comes with many built-in ABCs for
3462
+ :ref:`magic methods <special-lookup>`). ABCs introduce virtual
3463
+ subclasses, which are classes that don't inherit from a class but are
3464
+ still recognized by :func:`isinstance` and :func:`issubclass`; see the
3465
+ :mod:`abc` module documentation. Python comes with many built-in ABCs for
3466
data structures (in the :mod:`collections` module), numbers (in the
3467
:mod:`numbers` module), streams (in the :mod:`io` module), import finders
3468
and loaders (in the :mod:`importlib.abc` module). You can create your own
3470
well-designed code improves its flexibility by allowing polymorphic
3471
substitution. Duck-typing avoids tests using :func:`type` or
3472
:func:`isinstance`. (Note, however, that duck-typing can be complemented
3473
- with :term:`abstract base class`\ es.) Instead, it typically employs
3474
- :func:`hasattr` tests or :term:`EAFP` programming.
3475
+ with :term:`abstract base classes <abstract base class>`.) Instead, it
3476
+ typically employs :func:`hasattr` tests or :term:`EAFP` programming.
3479
Easier to ask for forgiveness than permission. This common Python coding
3480
diff -r 137e45f15c0b Doc/howto/functional.rst
3481
--- a/Doc/howto/functional.rst
3482
+++ b/Doc/howto/functional.rst
3483
@@ -1010,135 +1010,6 @@
3484
Consult the operator module's documentation for a complete list.
3488
-The functional module
3489
----------------------
3491
-Collin Winter's `functional module <http://oakwinter.com/code/functional/>`__
3492
-provides a number of more advanced tools for functional programming. It also
3493
-reimplements several Python built-ins, trying to make them more intuitive to
3494
-those used to functional programming in other languages.
3496
-This section contains an introduction to some of the most important functions in
3497
-``functional``; full documentation can be found at `the project's website
3498
-<http://oakwinter.com/code/functional/documentation/>`__.
3500
-``compose(outer, inner, unpack=False)``
3502
-The ``compose()`` function implements function composition. In other words, it
3503
-returns a wrapper around the ``outer`` and ``inner`` callables, such that the
3504
-return value from ``inner`` is fed directly to ``outer``. That is, ::
3506
- >>> def add(a, b):
3509
- >>> def double(a):
3512
- >>> compose(double, add)(5, 6)
3515
-is equivalent to ::
3517
- >>> double(add(5, 6))
3520
-The ``unpack`` keyword is provided to work around the fact that Python functions
3521
-are not always `fully curried <http://en.wikipedia.org/wiki/Currying>`__. By
3522
-default, it is expected that the ``inner`` function will return a single object
3523
-and that the ``outer`` function will take a single argument. Setting the
3524
-``unpack`` argument causes ``compose`` to expect a tuple from ``inner`` which
3525
-will be expanded before being passed to ``outer``. Put simply, ::
3527
- compose(f, g)(5, 6)
3535
- compose(f, g, unpack=True)(5, 6)
3541
-Even though ``compose()`` only accepts two functions, it's trivial to build up a
3542
-version that will compose any number of functions. We'll use
3543
-:func:`functools.reduce`, ``compose()`` and ``partial()`` (the last of which is
3544
-provided by both ``functional`` and ``functools``). ::
3546
- from functional import compose, partial
3550
- multi_compose = partial(functools.reduce, compose)
3553
-We can also use ``map()``, ``compose()`` and ``partial()`` to craft a version of
3554
-``"".join(...)`` that converts its arguments to string::
3556
- from functional import compose, partial
3558
- join = compose("".join, partial(map, str))
3563
-``flip()`` wraps the callable in ``func`` and causes it to receive its
3564
-non-keyword arguments in reverse order. ::
3566
- >>> def triple(a, b, c):
3567
- ... return (a, b, c)
3569
- >>> triple(5, 6, 7)
3572
- >>> flipped_triple = flip(triple)
3573
- >>> flipped_triple(5, 6, 7)
3576
-``foldl(func, start, iterable)``
3578
-``foldl()`` takes a binary function, a starting value (usually some kind of
3579
-'zero'), and an iterable. The function is applied to the starting value and the
3580
-first element of the list, then the result of that and the second element of the
3581
-list, then the result of that and the third element of the list, and so on.
3583
-This means that a call such as::
3585
- foldl(f, 0, [1, 2, 3])
3589
- f(f(f(0, 1), 2), 3)
3592
-``foldl()`` is roughly equivalent to the following recursive function::
3594
- def foldl(func, start, seq):
3598
- return foldl(func, func(start, seq[0]), seq[1:])
3600
-Speaking of equivalence, the above ``foldl`` call can be expressed in terms of
3601
-the built-in :func:`functools.reduce` like so::
3604
- functools.reduce(f, [1, 2, 3], 0)
3607
-We can use ``foldl()``, ``operator.concat()`` and ``partial()`` to write a
3608
-cleaner, more aesthetically-pleasing version of Python's ``"".join(...)``
3611
- from functional import foldl, partial from operator import concat
3613
- join = partial(foldl, concat, "")
3616
Small functions and the lambda expression
3617
=========================================
3619
@@ -1280,9 +1151,9 @@
3621
Mertz also wrote a 3-part series of articles on functional programming
3622
for IBM's DeveloperWorks site; see
3623
-`part 1 <http://www-128.ibm.com/developerworks/library/l-prog.html>`__,
3624
-`part 2 <http://www-128.ibm.com/developerworks/library/l-prog2.html>`__, and
3625
-`part 3 <http://www-128.ibm.com/developerworks/linux/library/l-prog3.html>`__,
3626
+`part 1 <http://www.ibm.com/developerworks/linux/library/l-prog/index.html>`__,
3627
+`part 2 <http://www.ibm.com/developerworks/linux/library/l-prog2/index.html>`__, and
3628
+`part 3 <http://www.ibm.com/developerworks/linux/library/l-prog3/index.html>`__,
3631
Python documentation
3632
diff -r 137e45f15c0b Doc/howto/logging-cookbook.rst
193
If you are writing a new extension module, you might consider `Cython
194
<http://www.cython.org>`_. It translates a Python-like language to C. The
195
-extension modules it creates are compatible with Python 3.x and 2.x.
196
+extension modules it creates are compatible with Python 3 and Python 2.
198
diff -r 7085403daf43 Doc/howto/logging-cookbook.rst
3633
199
--- a/Doc/howto/logging-cookbook.rst
3634
200
+++ b/Doc/howto/logging-cookbook.rst
3635
@@ -674,9 +674,10 @@
3636
to have all the processes log to a :class:`SocketHandler`, and have a separate
3637
process which implements a socket server which reads from the socket and logs
3638
to file. (If you prefer, you can dedicate one thread in one of the existing
3639
-processes to perform this function.) The following section documents this
3640
-approach in more detail and includes a working socket receiver which can be
3641
-used as a starting point for you to adapt in your own applications.
3642
+processes to perform this function.) :ref:`This section <network-logging>`
3643
+documents this approach in more detail and includes a working socket receiver
3644
+which can be used as a starting point for you to adapt in your own
3647
If you are using a recent version of Python which includes the
3648
:mod:`multiprocessing` module, you could write your own handler which uses the
3650
``.1``. Each of the existing backup files is renamed to increment the suffix
3651
(``.1`` becomes ``.2``, etc.) and the ``.6`` file is erased.
3653
-Obviously this example sets the log length much much too small as an extreme
3654
+Obviously this example sets the log length much too small as an extreme
201
@@ -268,12 +268,12 @@
202
.. currentmodule:: logging.handlers
204
Sometimes you have to get your logging handlers to do their work without
205
-blocking the thread you’re logging from. This is common in Web applications,
206
+blocking the thread you're logging from. This is common in Web applications,
207
though of course it also occurs in other scenarios.
209
A common culprit which demonstrates sluggish behaviour is the
210
:class:`SMTPHandler`: sending emails can take a long time, for a
211
-number of reasons outside the developer’s control (for example, a poorly
212
+number of reasons outside the developer's control (for example, a poorly
213
performing mail or network infrastructure). But almost any network-based
214
handler can block: Even a :class:`SocketHandler` operation may do a
215
DNS query under the hood which is too slow (and this query can be deep in the
218
The second part of the solution is :class:`QueueListener`, which has been
219
designed as the counterpart to :class:`QueueHandler`. A
220
-:class:`QueueListener` is very simple: it’s passed a queue and some handlers,
221
+:class:`QueueListener` is very simple: it's passed a queue and some handlers,
222
and it fires up an internal thread which listens to its queue for LogRecords
223
sent from ``QueueHandlers`` (or any other source of ``LogRecords``, for that
224
matter). The ``LogRecords`` are removed from the queue and passed to the
228
import sys, traceback
229
- print >> sys.stderr, 'Whoops! Problem:'
230
+ print('Whoops! Problem:', file=sys.stderr)
231
traceback.print_exc(file=sys.stderr)
233
# Arrays used for random selections in this demo
234
@@ -964,6 +964,219 @@
235
Obviously this example sets the log length much too small as an extreme
3655
236
example. You would want to set *maxBytes* to an appropriate value.
240
+Use of alternative formatting styles
241
+------------------------------------
243
+When logging was added to the Python standard library, the only way of
244
+formatting messages with variable content was to use the %-formatting
245
+method. Since then, Python has gained two new formatting approaches:
246
+:class:`string.Template` (added in Python 2.4) and :meth:`str.format`
247
+(added in Python 2.6).
249
+Logging (as of 3.2) provides improved support for these two additional
250
+formatting styles. The :class:`Formatter` class been enhanced to take an
251
+additional, optional keyword parameter named ``style``. This defaults to
252
+``'%'``, but other possible values are ``'{'`` and ``'$'``, which correspond
253
+to the other two formatting styles. Backwards compatibility is maintained by
254
+default (as you would expect), but by explicitly specifying a style parameter,
255
+you get the ability to specify format strings which work with
256
+:meth:`str.format` or :class:`string.Template`. Here's an example console
257
+session to show the possibilities:
259
+.. code-block:: pycon
262
+ >>> root = logging.getLogger()
263
+ >>> root.setLevel(logging.DEBUG)
264
+ >>> handler = logging.StreamHandler()
265
+ >>> bf = logging.Formatter('{asctime} {name} {levelname:8s} {message}',
267
+ >>> handler.setFormatter(bf)
268
+ >>> root.addHandler(handler)
269
+ >>> logger = logging.getLogger('foo.bar')
270
+ >>> logger.debug('This is a DEBUG message')
271
+ 2010-10-28 15:11:55,341 foo.bar DEBUG This is a DEBUG message
272
+ >>> logger.critical('This is a CRITICAL message')
273
+ 2010-10-28 15:12:11,526 foo.bar CRITICAL This is a CRITICAL message
274
+ >>> df = logging.Formatter('$asctime $name ${levelname} $message',
276
+ >>> handler.setFormatter(df)
277
+ >>> logger.debug('This is a DEBUG message')
278
+ 2010-10-28 15:13:06,924 foo.bar DEBUG This is a DEBUG message
279
+ >>> logger.critical('This is a CRITICAL message')
280
+ 2010-10-28 15:13:11,494 foo.bar CRITICAL This is a CRITICAL message
283
+Note that the formatting of logging messages for final output to logs is
284
+completely independent of how an individual logging message is constructed.
285
+That can still use %-formatting, as shown here::
287
+ >>> logger.error('This is an%s %s %s', 'other,', 'ERROR,', 'message')
288
+ 2010-10-28 15:19:29,833 foo.bar ERROR This is another, ERROR, message
291
+Logging calls (``logger.debug()``, ``logger.info()`` etc.) only take
292
+positional parameters for the actual logging message itself, with keyword
293
+parameters used only for determining options for how to handle the actual
294
+logging call (e.g. the ``exc_info`` keyword parameter to indicate that
295
+traceback information should be logged, or the ``extra`` keyword parameter
296
+to indicate additional contextual information to be added to the log). So
297
+you cannot directly make logging calls using :meth:`str.format` or
298
+:class:`string.Template` syntax, because internally the logging package
299
+uses %-formatting to merge the format string and the variable arguments.
300
+There would no changing this while preserving backward compatibility, since
301
+all logging calls which are out there in existing code will be using %-format
304
+There is, however, a way that you can use {}- and $- formatting to construct
305
+your individual log messages. Recall that for a message you can use an
306
+arbitrary object as a message format string, and that the logging package will
307
+call ``str()`` on that object to get the actual format string. Consider the
308
+following two classes::
310
+ class BraceMessage(object):
311
+ def __init__(self, fmt, *args, **kwargs):
314
+ self.kwargs = kwargs
317
+ return self.fmt.format(*self.args, **self.kwargs)
319
+ class DollarMessage(object):
320
+ def __init__(self, fmt, **kwargs):
322
+ self.kwargs = kwargs
325
+ from string import Template
326
+ return Template(self.fmt).substitute(**self.kwargs)
328
+Either of these can be used in place of a format string, to allow {}- or
329
+$-formatting to be used to build the actual "message" part which appears in the
330
+formatted log output in place of "%(message)s" or "{message}" or "$message".
331
+It's a little unwieldy to use the class names whenever you want to log
332
+something, but it's quite palatable if you use an alias such as __ (double
333
+underscore – not to be confused with _, the single underscore used as a
334
+synonym/alias for :func:`gettext.gettext` or its brethren).
336
+The above classes are not included in Python, though they're easy enough to
337
+copy and paste into your own code. They can be used as follows (assuming that
338
+they're declared in a module called ``wherever``):
340
+.. code-block:: pycon
342
+ >>> from wherever import BraceMessage as __
343
+ >>> print(__('Message with {0} {name}', 2, name='placeholders'))
344
+ Message with 2 placeholders
345
+ >>> class Point: pass
350
+ >>> print(__('Message with coordinates: ({point.x:.2f}, {point.y:.2f})',
352
+ Message with coordinates: (0.50, 0.50)
353
+ >>> from wherever import DollarMessage as __
354
+ >>> print(__('Message with $num $what', num=2, what='placeholders'))
355
+ Message with 2 placeholders
358
+While the above examples use ``print()`` to show how the formatting works, you
359
+would of course use ``logger.debug()`` or similar to actually log using this
362
+One thing to note is that you pay no significant performance penalty with this
363
+approach: the actual formatting happens not when you make the logging call, but
364
+when (and if) the logged message is actually about to be output to a log by a
365
+handler. So the only slightly unusual thing which might trip you up is that the
366
+parentheses go around the format string and the arguments, not just the format
367
+string. That's because the __ notation is just syntax sugar for a constructor
368
+call to one of the XXXMessage classes.
371
+.. currentmodule:: logging
373
+.. _custom-logrecord:
375
+Customising ``LogRecord``
376
+-------------------------
378
+Every logging event is represented by a :class:`LogRecord` instance.
379
+When an event is logged and not filtered out by a logger's level, a
380
+:class:`LogRecord` is created, populated with information about the event and
381
+then passed to the handlers for that logger (and its ancestors, up to and
382
+including the logger where further propagation up the hierarchy is disabled).
383
+Before Python 3.2, there were only two places where this creation was done:
385
+* :meth:`Logger.makeRecord`, which is called in the normal process of
386
+ logging an event. This invoked :class:`LogRecord` directly to create an
388
+* :func:`makeLogRecord`, which is called with a dictionary containing
389
+ attributes to be added to the LogRecord. This is typically invoked when a
390
+ suitable dictionary has been received over the network (e.g. in pickle form
391
+ via a :class:`~handlers.SocketHandler`, or in JSON form via an
392
+ :class:`~handlers.HTTPHandler`).
394
+This has usually meant that if you need to do anything special with a
395
+:class:`LogRecord`, you've had to do one of the following.
397
+* Create your own :class:`Logger` subclass, which overrides
398
+ :meth:`Logger.makeRecord`, and set it using :func:`~logging.setLoggerClass`
399
+ before any loggers that you care about are instantiated.
400
+* Add a :class:`Filter` to a logger or handler, which does the
401
+ necessary special manipulation you need when its
402
+ :meth:`~Filter.filter` method is called.
404
+The first approach would be a little unwieldy in the scenario where (say)
405
+several different libraries wanted to do different things. Each would attempt
406
+to set its own :class:`Logger` subclass, and the one which did this last would
409
+The second approach works reasonably well for many cases, but does not allow
410
+you to e.g. use a specialized subclass of :class:`LogRecord`. Library
411
+developers can set a suitable filter on their loggers, but they would have to
412
+remember to do this every time they introduced a new logger (which they would
413
+do simply by adding new packages or modules and doing ::
415
+ logger = logging.getLogger(__name__)
417
+at module level). It's probably one too many things to think about. Developers
418
+could also add the filter to a :class:`~logging.NullHandler` attached to their
419
+top-level logger, but this would not be invoked if an application developer
420
+attached a handler to a lower-level library logger – so output from that
421
+handler would not reflect the intentions of the library developer.
423
+In Python 3.2 and later, :class:`~logging.LogRecord` creation is done through a
424
+factory, which you can specify. The factory is just a callable you can set with
425
+:func:`~logging.setLogRecordFactory`, and interrogate with
426
+:func:`~logging.getLogRecordFactory`. The factory is invoked with the same
427
+signature as the :class:`~logging.LogRecord` constructor, as :class:`LogRecord`
428
+is the default setting for the factory.
430
+This approach allows a custom factory to control all aspects of LogRecord
431
+creation. For example, you could return a subclass, or just add some additional
432
+attributes to the record once created, using a pattern similar to this::
434
+ old_factory = logging.getLogRecordFactory()
436
+ def record_factory(*args, **kwargs):
437
+ record = old_factory(*args, **kwargs)
438
+ record.custom_attribute = 0xdecafbad
441
+ logging.setLogRecordFactory(record_factory)
443
+This pattern allows different libraries to chain factories together, and as
444
+long as they don't overwrite each other's attributes or unintentionally
445
+overwrite the attributes provided as standard, there should be no surprises.
446
+However, it should be borne in mind that each link in the chain adds run-time
447
+overhead to all logging operations, and the technique should only be used when
448
+the use of a :class:`Filter` does not provide the desired result.
3657
451
.. _zeromq-handlers:
3658
@@ -1037,3 +1038,67 @@
3659
:ref:`A basic logging tutorial <logging-basic-tutorial>`
3661
:ref:`A more advanced logging tutorial <logging-advanced-tutorial>`
3664
+An example dictionary-based configuration
3665
+-----------------------------------------
3667
+Below is an example of a logging configuration dictionary - it's taken from
3668
+the `documentation on the Django project <https://docs.djangoproject.com/en/1.3/topics/logging/#configuring-logging>`_.
3669
+This dictionary is passed to :func:`~logging.config.dictConfig` to put the configuration into effect::
3673
+ 'disable_existing_loggers': True,
3676
+ 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
3679
+ 'format': '%(levelname)s %(message)s'
3684
+ '()': 'project.logging.SpecialFilter',
3691
+ 'class':'django.utils.log.NullHandler',
3695
+ 'class':'logging.StreamHandler',
3696
+ 'formatter': 'simple'
3700
+ 'class': 'django.utils.log.AdminEmailHandler',
3701
+ 'filters': ['special']
3706
+ 'handlers':['null'],
3707
+ 'propagate': True,
3710
+ 'django.request': {
3711
+ 'handlers': ['mail_admins'],
3713
+ 'propagate': False,
3715
+ 'myproject.custom': {
3716
+ 'handlers': ['console', 'mail_admins'],
3718
+ 'filters': ['special']
3723
+For more information about this configuration, you can see the `relevant
3724
+section <https://docs.djangoproject.com/en/1.3/topics/logging/#configuring-logging>`_
3725
+of the Django documentation.
3726
diff -r 137e45f15c0b Doc/howto/logging.rst
3727
--- a/Doc/howto/logging.rst
3728
+++ b/Doc/howto/logging.rst
3733
- format: format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
3734
+ format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
3737
class: logging.StreamHandler
3738
diff -r 137e45f15c0b Doc/howto/pyporting.rst
3739
--- a/Doc/howto/pyporting.rst
3740
+++ b/Doc/howto/pyporting.rst
3742
textual data, people have over the years been rather loose in their delineation
3743
of what ``str`` instances held text compared to bytes. In Python 3 you cannot
3744
be so care-free anymore and need to properly handle the difference. The key
3745
-handling this issue to to make sure that **every** string literal in your
3746
+handling this issue to make sure that **every** string literal in your
3747
Python 2 code is either syntactically of functionally marked as either bytes or
3748
text data. After this is done you then need to make sure your APIs are designed
3749
to either handle a specific type or made to be properly polymorphic.
3750
@@ -505,6 +505,18 @@
3754
+Update `map` for imbalanced input sequences
3755
+'''''''''''''''''''''''''''''''''''''''''''
3757
+With Python 2, `map` would pad input sequences of unequal length with
3758
+`None` values, returning a sequence as long as the longest input sequence.
3760
+With Python 3, if the input sequences to `map` are of unequal length, `map`
3761
+will stop at the termination of the shortest of the sequences. For full
3762
+compatibility with `map` from Python 2.x, also wrap the sequences in
3763
+:func:`itertools.zip_longest`, e.g. ``map(func, *sequences)`` becomes
3764
+``list(map(func, itertools.zip_longest(*sequences)))``.
3766
Eliminate ``-3`` Warnings
3767
-------------------------
3769
diff -r 137e45f15c0b Doc/howto/sockets.rst
3770
--- a/Doc/howto/sockets.rst
3771
+++ b/Doc/howto/sockets.rst
3775
****************************
3776
Socket Programming HOWTO
3777
****************************
3779
Roughly speaking, when you clicked on the link that brought you to this page,
3780
your browser did something like the following::
3782
- #create an INET, STREAMing socket
3783
+ # create an INET, STREAMing socket
3784
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
3785
- #now connect to the web server on port 80
3786
- # - the normal http port
3787
- s.connect(("www.mcmillan-inc.com", 80))
3788
+ # now connect to the web server on port 80 - the normal http port
3789
+ s.connect(("www.python.org", 80))
3791
When the ``connect`` completes, the socket ``s`` can be used to send
3792
in a request for the text of the page. The same socket will read the
3794
What happens in the web server is a bit more complex. First, the web server
3795
creates a "server socket"::
3797
- #create an INET, STREAMing socket
3798
- serversocket = socket.socket(
3799
- socket.AF_INET, socket.SOCK_STREAM)
3800
- #bind the socket to a public host,
3801
- # and a well-known port
3802
+ # create an INET, STREAMing socket
3803
+ serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
3804
+ # bind the socket to a public host, and a well-known port
3805
serversocket.bind((socket.gethostname(), 80))
3806
- #become a server socket
3807
+ # become a server socket
3808
serversocket.listen(5)
3810
A couple things to notice: we used ``socket.gethostname()`` so that the socket
3811
@@ -101,10 +100,10 @@
3812
mainloop of the web server::
3815
- #accept connections from outside
3816
+ # accept connections from outside
3817
(clientsocket, address) = serversocket.accept()
3818
- #now do something with the clientsocket
3819
- #in this case, we'll pretend this is a threaded server
3820
+ # now do something with the clientsocket
3821
+ # in this case, we'll pretend this is a threaded server
3822
ct = client_thread(clientsocket)
3825
@@ -126,12 +125,13 @@
3828
If you need fast IPC between two processes on one machine, you should look into
3829
-whatever form of shared memory the platform offers. A simple protocol based
3830
-around shared memory and locks or semaphores is by far the fastest technique.
3831
+pipes or shared memory. If you do decide to use AF_INET sockets, bind the
3832
+"server" socket to ``'localhost'``. On most platforms, this will take a
3833
+shortcut around a couple of layers of network code and be quite a bit faster.
3835
-If you do decide to use sockets, bind the "server" socket to ``'localhost'``. On
3836
-most platforms, this will take a shortcut around a couple of layers of network
3837
-code and be quite a bit faster.
3839
+ The :mod:`multiprocessing` integrates cross-platform IPC into a higher-level
3846
Probably the worst thing about using blocking sockets is what happens when the
3847
other side comes down hard (without doing a ``close``). Your socket is likely to
3848
-hang. SOCKSTREAM is a reliable protocol, and it will wait a long, long time
3849
+hang. TCP is a reliable protocol, and it will wait a long, long time
3850
before giving up on a connection. If you're using threads, the entire thread is
3851
essentially dead. There's not much you can do about it. As long as you aren't
3852
doing something dumb, like holding a lock while doing a blocking read, the
3853
@@ -395,19 +395,13 @@
3855
There's no question that the fastest sockets code uses non-blocking sockets and
3856
select to multiplex them. You can put together something that will saturate a
3857
-LAN connection without putting any strain on the CPU. The trouble is that an app
3858
-written this way can't do much of anything else - it needs to be ready to
3859
-shuffle bytes around at all times.
3860
+LAN connection without putting any strain on the CPU.
3862
-Assuming that your app is actually supposed to do something more than that,
3863
-threading is the optimal solution, (and using non-blocking sockets will be
3864
-faster than using blocking sockets). Unfortunately, threading support in Unixes
3865
-varies both in API and quality. So the normal Unix solution is to fork a
3866
-subprocess to deal with each connection. The overhead for this is significant
3867
-(and don't do this on Windows - the overhead of process creation is enormous
3868
-there). It also means that unless each subprocess is completely independent,
3869
-you'll need to use another form of IPC, say a pipe, or shared memory and
3870
-semaphores, to communicate between the parent and child processes.
3871
+The trouble is that an app written this way can't do much of anything else -
3872
+it needs to be ready to shuffle bytes around at all times. Assuming that your
3873
+app is actually supposed to do something more than that, threading is the
3874
+optimal solution, (and using non-blocking sockets will be faster than using
3877
Finally, remember that even though blocking sockets are somewhat slower than
3878
non-blocking, in many cases they are the "right" solution. After all, if your
3879
diff -r 137e45f15c0b Doc/howto/unicode.rst
3880
--- a/Doc/howto/unicode.rst
3881
+++ b/Doc/howto/unicode.rst
3887
Tips for Writing Unicode-aware Programs
3888
---------------------------------------
3890
@@ -572,28 +571,12 @@
3891
When using data coming from a web browser or some other untrusted source, a
3892
common technique is to check for illegal characters in a string before using the
3893
string in a generated command line or storing it in a database. If you're doing
3894
-this, be careful to check the string once it's in the form that will be used or
3895
-stored; it's possible for encodings to be used to disguise characters. This is
3896
-especially true if the input data also specifies the encoding; many encodings
3897
-leave the commonly checked-for characters alone, but Python includes some
3898
-encodings such as ``'base64'`` that modify every single character.
3899
+this, be careful to check the decoded string, not the encoded bytes data;
3900
+some encodings may have interesting properties, such as not being bijective
3901
+or not being fully ASCII-compatible. This is especially true if the input
3902
+data also specifies the encoding, since the attacker can then choose a
3903
+clever way to hide malicious text in the encoded bytestream.
3905
-For example, let's say you have a content management system that takes a Unicode
3906
-filename, and you want to disallow paths with a '/' character. You might write
3909
- def read_file(filename, encoding):
3910
- if '/' in filename:
3911
- raise ValueError("'/' not allowed in filenames")
3912
- unicode_name = filename.decode(encoding)
3913
- with open(unicode_name, 'r') as f:
3914
- # ... return contents of file ...
3916
-However, if an attacker could specify the ``'base64'`` encoding, they could pass
3917
-``'L2V0Yy9wYXNzd2Q='``, which is the base-64 encoded form of the string
3918
-``'/etc/passwd'``, to read a system file. The above code looks for ``'/'``
3919
-characters in the encoded form and misses the dangerous character in the
3920
-resulting decoded form.
3924
diff -r 137e45f15c0b Doc/howto/webservers.rst
3925
--- a/Doc/howto/webservers.rst
3926
+++ b/Doc/howto/webservers.rst
3929
* `FastCGI, SCGI, and Apache: Background and Future
3930
<http://www.vmunix.com/mark/blog/archives/2006/01/02/fastcgi-scgi-and-apache-background-and-future/>`_
3931
- is a discussion on why the concept of FastCGI and SCGI is better that that
3932
+ is a discussion on why the concept of FastCGI and SCGI is better than that
3937
Each web server requires a specific module.
3939
* Apache has both `mod_fastcgi <http://www.fastcgi.com/drupal/>`_ and `mod_fcgid
3940
- <http://fastcgi.coremail.cn/>`_. ``mod_fastcgi`` is the original one, but it
3941
+ <http://httpd.apache.org/mod_fcgid/>`_. ``mod_fastcgi`` is the original one, but it
3942
has some licensing issues, which is why it is sometimes considered non-free.
3943
``mod_fcgid`` is a smaller, compatible alternative. One of these modules needs
3944
to be loaded by Apache.
3947
A really great WSGI feature is middleware. Middleware is a layer around your
3948
program which can add various functionality to it. There is quite a bit of
3949
-`middleware <http://wsgi.org/wsgi/Middleware_and_Utilities>`_ already
3950
+`middleware <http://www.wsgi.org/en/latest/libraries.html>`_ already
3951
available. For example, instead of writing your own session management (HTTP
3952
is a stateless protocol, so to associate multiple HTTP requests with a single
3953
user your application must create and manage such state via a session), you can
3958
- A good overview of WSGI-related code can be found in the `WSGI wiki
3959
- <http://wsgi.org/wsgi>`_, which contains an extensive list of `WSGI servers
3960
- <http://wsgi.org/wsgi/Servers>`_ which can be used by *any* application
3961
+ A good overview of WSGI-related code can be found in the `WSGI homepage
3962
+ <http://www.wsgi.org/en/latest/index.html>`_, which contains an extensive list of `WSGI servers
3963
+ <http://www.wsgi.org/en/latest/servers.html>`_ which can be used by *any* application
3966
You might be interested in some WSGI-supporting modules already contained in
3967
diff -r 137e45f15c0b Doc/includes/sqlite3/converter_point.py
3968
--- a/Doc/includes/sqlite3/converter_point.py
3969
+++ b/Doc/includes/sqlite3/converter_point.py
3971
return "(%f;%f)" % (self.x, self.y)
3973
def adapt_point(point):
3974
- return "%f;%f" % (point.x, point.y)
3975
+ return ("%f;%f" % (point.x, point.y)).encode('ascii')
3977
def convert_point(s):
3978
- x, y = list(map(float, s.split(";")))
3979
+ x, y = list(map(float, s.split(b";")))
3982
# Register the adapter
3983
diff -r 137e45f15c0b Doc/includes/sqlite3/ctx_manager.py
3984
--- a/Doc/includes/sqlite3/ctx_manager.py
3985
+++ b/Doc/includes/sqlite3/ctx_manager.py
3987
con.execute("insert into person(firstname) values (?)", ("Joe",))
3989
# con.rollback() is called after the with block finishes with an exception, the
3990
-# exception is still raised and must be catched
3991
+# exception is still raised and must be caught
3994
con.execute("insert into person(firstname) values (?)", ("Joe",))
3995
diff -r 137e45f15c0b Doc/includes/sqlite3/execute_1.py
3996
--- a/Doc/includes/sqlite3/execute_1.py
3997
+++ b/Doc/includes/sqlite3/execute_1.py
4001
-con = sqlite3.connect("mydb")
4003
+con = sqlite3.connect(":memory:")
4005
+cur.execute("create table people (name_last, age)")
4010
-cur.execute("select name_last, age from people where name_last=? and age=?", (who, age))
4011
+# This is the qmark style:
4012
+cur.execute("insert into people values (?, ?)", (who, age))
4014
+# And this is the named style:
4015
+cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
4017
print(cur.fetchone())
4018
diff -r 137e45f15c0b Doc/includes/sqlite3/execute_2.py
4019
--- a/Doc/includes/sqlite3/execute_2.py
4024
-con = sqlite3.connect("mydb")
4031
-cur.execute("select name_last, age from people where name_last=:who and age=:age",
4032
- {"who": who, "age": age})
4033
-print(cur.fetchone())
4034
diff -r 137e45f15c0b Doc/includes/sqlite3/executemany_2.py
4035
--- a/Doc/includes/sqlite3/executemany_2.py
4036
+++ b/Doc/includes/sqlite3/executemany_2.py
4041
def char_generator():
4043
- for c in string.letters[:26]:
4044
+ for c in string.ascii_lowercase:
4047
con = sqlite3.connect(":memory:")
4048
diff -r 137e45f15c0b Doc/includes/sqlite3/md5func.py
4049
--- a/Doc/includes/sqlite3/md5func.py
4050
+++ b/Doc/includes/sqlite3/md5func.py
4052
con = sqlite3.connect(":memory:")
4053
con.create_function("md5", 1, md5sum)
4055
-cur.execute("select md5(?)", ("foo",))
4056
+cur.execute("select md5(?)", (b"foo",))
4057
print(cur.fetchone()[0])
4058
diff -r 137e45f15c0b Doc/includes/sqlite3/rowclass.py
4059
--- a/Doc/includes/sqlite3/rowclass.py
4060
+++ b/Doc/includes/sqlite3/rowclass.py
4064
-con = sqlite3.connect("mydb")
4065
+con = sqlite3.connect(":memory:")
4066
con.row_factory = sqlite3.Row
4069
-cur.execute("select name_last, age from people")
4070
+cur.execute("select 'John' as name, 42 as age")
4072
- assert row[0] == row["name_last"]
4073
- assert row["name_last"] == row["nAmE_lAsT"]
4074
+ assert row[0] == row["name"]
4075
+ assert row["name"] == row["nAmE"]
4076
assert row[1] == row["age"]
4077
assert row[1] == row["AgE"]
4078
diff -r 137e45f15c0b Doc/includes/sqlite3/text_factory.py
4079
--- a/Doc/includes/sqlite3/text_factory.py
4080
+++ b/Doc/includes/sqlite3/text_factory.py
4082
con = sqlite3.connect(":memory:")
4086
-con.execute("create table person(lastname, firstname)")
4088
AUSTRIA = "\xd6sterreich"
4090
# by default, rows are returned as Unicode
4092
assert row[0] == AUSTRIA
4094
# but we can make sqlite3 always return bytestrings ...
4095
-con.text_factory = str
4096
+con.text_factory = bytes
4097
cur.execute("select ?", (AUSTRIA,))
4098
row = cur.fetchone()
4099
-assert type(row[0]) == str
4100
+assert type(row[0]) is bytes
4101
# the bytestrings will be encoded in UTF-8, unless you stored garbage in the
4103
assert row[0] == AUSTRIA.encode("utf-8")
4105
# we can also implement a custom text_factory ...
4106
-# here we implement one that will ignore Unicode characters that cannot be
4107
-# decoded from UTF-8
4108
-con.text_factory = lambda x: str(x, "utf-8", "ignore")
4109
-cur.execute("select ?", ("this is latin1 and would normally create errors" +
4110
- "\xe4\xf6\xfc".encode("latin1"),))
4111
+# here we implement one that appends "foo" to all strings
4112
+con.text_factory = lambda x: x.decode("utf-8") + "foo"
4113
+cur.execute("select ?", ("bar",))
4114
row = cur.fetchone()
4115
-assert type(row[0]) == str
4117
-# sqlite3 offers a built-in optimized text_factory that will return bytestring
4118
-# objects, if the data is in ASCII only, and otherwise return unicode objects
4119
-con.text_factory = sqlite3.OptimizedUnicode
4120
-cur.execute("select ?", (AUSTRIA,))
4121
-row = cur.fetchone()
4122
-assert type(row[0]) == str
4124
-cur.execute("select ?", ("Germany",))
4125
-row = cur.fetchone()
4126
-assert type(row[0]) == str
4127
+assert row[0] == "barfoo"
4128
diff -r 137e45f15c0b Doc/install/index.rst
4129
--- a/Doc/install/index.rst
4130
+++ b/Doc/install/index.rst
4133
python setup.py install
4135
-For Windows, this command should be run from a command prompt windows ("DOS
4137
+For Windows, this command should be run from a command prompt window
4138
+(:menuselection:`Start --> Accessories`)::
4143
:file:`C:\\Temp\\foo-1.0`; you can use either a archive manipulator with a
4144
graphical user interface (such as WinZip) or a command-line tool (such as
4145
:program:`unzip` or :program:`pkunzip`) to unpack the archive. Then, open a
4146
-command prompt window ("DOS box"), and run::
4147
+command prompt window and run::
4150
python setup.py install
4151
diff -r 137e45f15c0b Doc/library/2to3.rst
4152
--- a/Doc/library/2to3.rst
4153
+++ b/Doc/library/2to3.rst
4155
:option:`-p` to run fixers on code that already has had its print statements
4158
+The :option:`-o` or :option:`--output-dir` option allows specification of an
4159
+alternate directory for processed output files to be written to. The
4160
+:option:`-n` flag is required when using this as backup files do not make sense
4161
+when not overwriting the input files.
4163
+.. versionadded:: 3.2.3
4164
+ The :option:`-o` option was added.
4166
+The :option:`-W` or :option:`--write-unchanged-files` flag tells 2to3 to always
4167
+write output files even if no changes were required to the file. This is most
4168
+useful with :option:`-o` so that an entire Python source tree is copied with
4169
+translation from one directory to another.
4170
+This option implies the :option:`-w` flag as it would not make sense otherwise.
4172
+.. versionadded:: 3.2.3
4173
+ The :option:`-W` flag was added.
4175
+The :option:`--add-suffix` option specifies a string to append to all output
4176
+filenames. The :option:`-n` flag is required when specifying this as backups
4177
+are not necessary when writing to different filenames. Example::
4179
+ $ 2to3 -n -W --add-suffix=3 example.py
4181
+Will cause a converted file named ``example.py3`` to be written.
4183
+.. versionadded:: 3.2.3
4184
+ The :option:`--add-suffix` option was added.
4186
+To translate an entire project from one directory tree to another use::
4188
+ $ 2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode
4194
.. 2to3fixer:: callable
4196
Converts ``callable(x)`` to ``isinstance(x, collections.Callable)``, adding
4197
- an import to :mod:`collections` if needed.
4198
+ an import to :mod:`collections` if needed. Note ``callable(x)`` has returned
4199
+ in Python 3.2, so if you do not intend to support Python 3.1, you can disable
4204
diff -r 137e45f15c0b Doc/library/archiving.rst
4205
--- a/Doc/library/archiving.rst
4206
+++ b/Doc/library/archiving.rst
4209
The modules described in this chapter support data compression with the zlib,
4210
gzip, and bzip2 algorithms, and the creation of ZIP- and tar-format archives.
4211
+See also :ref:`archiving-operations` provided by the :mod:`shutil` module.
4215
diff -r 137e45f15c0b Doc/library/argparse.rst
4216
--- a/Doc/library/argparse.rst
4217
+++ b/Doc/library/argparse.rst
4219
.. moduleauthor:: Steven Bethard <steven.bethard@gmail.com>
4220
.. sectionauthor:: Steven Bethard <steven.bethard@gmail.com>
4222
+.. versionadded:: 3.2
4224
**Source code:** :source:`Lib/argparse.py`
4226
-.. versionadded:: 3.2
4230
The :mod:`argparse` module makes it easy to write user-friendly command-line
4233
:class:`ArgumentParser` parses arguments through the
4234
:meth:`~ArgumentParser.parse_args` method. This will inspect the command line,
4235
-convert each arg to the appropriate type and then invoke the appropriate action.
4236
+convert each argument to the appropriate type and then invoke the appropriate action.
4237
In most cases, this means a simple :class:`Namespace` object will be built up from
4238
attributes parsed out of the command line::
4243
The help option is typically ``-h/--help``. The exception to this is
4244
-if the ``prefix_chars=`` is specified and does not include ``'-'``, in
4245
+if the ``prefix_chars=`` is specified and does not include ``-``, in
4246
which case ``-h`` and ``--help`` are not valid options. In
4247
this case, the first character in ``prefix_chars`` is used to prefix
4253
-Most command-line options will use ``'-'`` as the prefix, e.g. ``-f/--foo``.
4254
+Most command-line options will use ``-`` as the prefix, e.g. ``-f/--foo``.
4255
Parsers that need to support different or additional prefix
4256
characters, e.g. for options
4257
like ``+f`` or ``/foo``, may specify them using the ``prefix_chars=`` argument
4259
Namespace(bar='Y', f='X')
4261
The ``prefix_chars=`` argument defaults to ``'-'``. Supplying a set of
4262
-characters that does not include ``'-'`` will cause ``-f/--foo`` options to be
4263
+characters that does not include ``-`` will cause ``-f/--foo`` options to be
4268
likewise for this epilog whose whitespace will be cleaned up and whose words
4269
will be wrapped across a couple lines
4271
-Passing :class:`~argparse.RawDescriptionHelpFormatter` as ``formatter_class=``
4272
+Passing :class:`RawDescriptionHelpFormatter` as ``formatter_class=``
4273
indicates that description_ and epilog_ are already correctly formatted and
4274
should not be line-wrapped::
4278
-h, --help show this help message and exit
4280
-:class:`RawTextHelpFormatter` maintains whitespace for all sorts of help text
4281
+:class:`RawTextHelpFormatter` maintains whitespace for all sorts of help text,
4282
including argument descriptions.
4284
The other formatter class available, :class:`ArgumentDefaultsHelpFormatter`,
4285
@@ -703,7 +703,20 @@
4286
>>> parser.add_argument('--str', dest='types', action='append_const', const=str)
4287
>>> parser.add_argument('--int', dest='types', action='append_const', const=int)
4288
>>> parser.parse_args('--str --int'.split())
4289
- Namespace(types=[<type 'str'>, <type 'int'>])
4290
+ Namespace(types=[<class 'str'>, <class 'int'>])
4292
+* ``'count'`` - This counts the number of times a keyword argument occurs. For
4293
+ example, this is useful for increasing verbosity levels::
4295
+ >>> parser = argparse.ArgumentParser()
4296
+ >>> parser.add_argument('--verbose', '-v', action='count')
4297
+ >>> parser.parse_args('-vvv'.split())
4298
+ Namespace(verbose=3)
4300
+* ``'help'`` - This prints a complete help message for all the options in the
4301
+ current parser and then exits. By default a help action is automatically
4302
+ added to the parser. See :class:`ArgumentParser` for details of how the
4303
+ output is created.
4305
* ``'version'`` - This expects a ``version=`` keyword argument in the
4306
:meth:`~ArgumentParser.add_argument` call, and prints version information
4308
different number of command-line arguments with a single action. The supported
4311
-* N (an integer). N arguments from the command line will be gathered together into a
4312
+* ``N`` (an integer). ``N`` arguments from the command line will be gathered together into a
4315
>>> parser = argparse.ArgumentParser()
4316
@@ -771,11 +784,11 @@
4317
Note that ``nargs=1`` produces a list of one item. This is different from
4318
the default, in which the item is produced by itself.
4320
-* ``'?'``. One arg will be consumed from the command line if possible, and
4321
- produced as a single item. If no command-line arg is present, the value from
4322
+* ``'?'``. One argument will be consumed from the command line if possible, and
4323
+ produced as a single item. If no command-line argument is present, the value from
4324
default_ will be produced. Note that for optional arguments, there is an
4325
additional case - the option string is present but not followed by a
4326
- command-line arg. In this case the value from const_ will be produced. Some
4327
+ command-line argument. In this case the value from const_ will be produced. Some
4328
examples to illustrate this::
4330
>>> parser = argparse.ArgumentParser()
4333
* ``'+'``. Just like ``'*'``, all command-line args present are gathered into a
4334
list. Additionally, an error message will be generated if there wasn't at
4335
- least one command-line arg present. For example::
4336
+ least one command-line argument present. For example::
4338
>>> parser = argparse.ArgumentParser(prog='PROG')
4339
>>> parser.add_argument('foo', nargs='+')
4340
@@ -827,8 +840,19 @@
4341
usage: PROG [-h] foo [foo ...]
4342
PROG: error: too few arguments
4344
+* ``argparse.REMAINDER``. All the remaining command-line arguments are gathered
4345
+ into a list. This is commonly useful for command line utilities that dispatch
4346
+ to other command line utilities.
4348
+ >>> parser = argparse.ArgumentParser(prog='PROG')
4349
+ >>> parser.add_argument('--foo')
4350
+ >>> parser.add_argument('command')
4351
+ >>> parser.add_argument('args', nargs=argparse.REMAINDER)
4352
+ >>> print parser.parse_args('--foo B cmd --arg1 XX ZZ'.split())
4353
+ Namespace(args=['--arg1', 'XX', 'ZZ'], command='cmd', foo='B')
4355
If the ``nargs`` keyword argument is not provided, the number of arguments consumed
4356
-is determined by the action_. Generally this means a single command-line arg
4357
+is determined by the action_. Generally this means a single command-line argument
4358
will be consumed and a single item (not a list) will be produced.
4362
(like ``-f`` or ``--foo``) and ``nargs='?'``. This creates an optional
4363
argument that can be followed by zero or one command-line arguments.
4364
When parsing the command line, if the option string is encountered with no
4365
- command-line arg following it, the value of ``const`` will be assumed instead.
4366
+ command-line argument following it, the value of ``const`` will be assumed instead.
4367
See the nargs_ description for examples.
4369
The ``const`` keyword argument defaults to ``None``.
4371
All optional arguments and some positional arguments may be omitted at the
4372
command line. The ``default`` keyword argument of
4373
:meth:`~ArgumentParser.add_argument`, whose value defaults to ``None``,
4374
-specifies what value should be used if the command-line arg is not present.
4375
+specifies what value should be used if the command-line argument is not present.
4376
For optional arguments, the ``default`` value is used when the option string
4377
was not present at the command line::
4380
>>> parser.parse_args(''.split())
4383
-For positional arguments with nargs_ ``='?'`` or ``'*'``, the ``default`` value
4384
-is used when no command-line arg was present::
4385
+For positional arguments with nargs_ equal to ``?`` or ``*``, the ``default`` value
4386
+is used when no command-line argument was present::
4388
>>> parser = argparse.ArgumentParser()
4389
>>> parser.add_argument('foo', nargs='?', default=42)
4391
Some command-line arguments should be selected from a restricted set of values.
4392
These can be handled by passing a container object as the ``choices`` keyword
4393
argument to :meth:`~ArgumentParser.add_argument`. When the command line is
4394
-parsed, arg values will be checked, and an error message will be displayed if
4395
-the arg was not one of the acceptable values::
4396
+parsed, argument values will be checked, and an error message will be displayed if
4397
+the argument was not one of the acceptable values::
4399
>>> parser = argparse.ArgumentParser(prog='PROG')
4400
>>> parser.add_argument('foo', choices='abc')
4401
@@ -1051,6 +1075,17 @@
4403
-h, --help show this help message and exit
4405
+:mod:`argparse` supports silencing the help entry for certain options, by
4406
+setting the ``help`` value to ``argparse.SUPPRESS``::
4408
+ >>> parser = argparse.ArgumentParser(prog='frobble')
4409
+ >>> parser.add_argument('--foo', help=argparse.SUPPRESS)
4410
+ >>> parser.print_help()
4411
+ usage: frobble [-h]
4413
+ optional arguments:
4414
+ -h, --help show this help message and exit
4419
@@ -1060,8 +1095,8 @@
4420
value as the "name" of each object. By default, for positional argument
4421
actions, the dest_ value is used directly, and for optional argument actions,
4422
the dest_ value is uppercased. So, a single positional argument with
4423
-``dest='bar'`` will that argument will be referred to as ``bar``. A single
4424
-optional argument ``--foo`` that should be followed by a single command-line arg
4425
+``dest='bar'`` will be referred to as ``bar``. A single
4426
+optional argument ``--foo`` that should be followed by a single command-line argument
4427
will be referred to as ``FOO``. An example::
4429
>>> parser = argparse.ArgumentParser()
4430
@@ -1133,10 +1168,10 @@
4432
For optional argument actions, the value of ``dest`` is normally inferred from
4433
the option strings. :class:`ArgumentParser` generates the value of ``dest`` by
4434
-taking the first long option string and stripping away the initial ``'--'``
4435
+taking the first long option string and stripping away the initial ``--``
4436
string. If no long option strings were supplied, ``dest`` will be derived from
4437
-the first short option string by stripping the initial ``'-'`` character. Any
4438
-internal ``'-'`` characters will be converted to ``'_'`` characters to make sure
4439
+the first short option string by stripping the initial ``-`` character. Any
4440
+internal ``-`` characters will be converted to ``_`` characters to make sure
4441
the string is a valid attribute name. The examples below illustrate this
4444
@@ -1168,7 +1203,7 @@
4445
created and how they are assigned. See the documentation for
4446
:meth:`add_argument` for details.
4448
- By default, the arg strings are taken from :data:`sys.argv`, and a new empty
4449
+ By default, the argument strings are taken from :data:`sys.argv`, and a new empty
4450
:class:`Namespace` object is created for the attributes.
4453
@@ -1239,15 +1274,15 @@
4454
PROG: error: extra arguments found: badger
4457
-Arguments containing ``"-"``
4458
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4459
+Arguments containing ``-``
4460
+^^^^^^^^^^^^^^^^^^^^^^^^^^
4462
The :meth:`~ArgumentParser.parse_args` method attempts to give errors whenever
4463
the user has clearly made a mistake, but some situations are inherently
4464
-ambiguous. For example, the command-line arg ``'-1'`` could either be an
4465
+ambiguous. For example, the command-line argument ``-1`` could either be an
4466
attempt to specify an option or an attempt to provide a positional argument.
4467
The :meth:`~ArgumentParser.parse_args` method is cautious here: positional
4468
-arguments may only begin with ``'-'`` if they look like negative numbers and
4469
+arguments may only begin with ``-`` if they look like negative numbers and
4470
there are no options in the parser that look like negative numbers::
4472
>>> parser = argparse.ArgumentParser(prog='PROG')
4473
@@ -1280,7 +1315,7 @@
4474
usage: PROG [-h] [-1 ONE] [foo]
4475
PROG: error: argument -1: expected one argument
4477
-If you have positional arguments that must begin with ``'-'`` and don't look
4478
+If you have positional arguments that must begin with ``-`` and don't look
4479
like negative numbers, you can insert the pseudo-argument ``'--'`` which tells
4480
:meth:`~ArgumentParser.parse_args` that everything after that is a positional
4482
@@ -1398,7 +1433,7 @@
4483
>>> parser_b = subparsers.add_parser('b', help='b help')
4484
>>> parser_b.add_argument('--baz', choices='XYZ', help='baz help')
4486
- >>> # parse some arg lists
4487
+ >>> # parse some argument lists
4488
>>> parser.parse_args(['a', '12'])
4489
Namespace(bar=12, foo=False)
4490
>>> parser.parse_args(['--foo', 'b', '--baz', 'Z'])
4491
@@ -1407,8 +1442,8 @@
4492
Note that the object returned by :meth:`parse_args` will only contain
4493
attributes for the main parser and the subparser that was selected by the
4494
command line (and not any other subparsers). So in the example above, when
4495
- the ``"a"`` command is specified, only the ``foo`` and ``bar`` attributes are
4496
- present, and when the ``"b"`` command is specified, only the ``foo`` and
4497
+ the ``a`` command is specified, only the ``foo`` and ``bar`` attributes are
4498
+ present, and when the ``b`` command is specified, only the ``foo`` and
4499
``baz`` attributes are present.
4501
Similarly, when a help message is requested from a subparser, only the help
4502
diff -r 137e45f15c0b Doc/library/atexit.rst
4503
--- a/Doc/library/atexit.rst
4504
+++ b/Doc/library/atexit.rst
4507
Register *func* as a function to be executed at termination. Any optional
4508
arguments that are to be passed to *func* must be passed as arguments to
4510
+ :func:`register`. It is possible to register the same function and arguments
4513
At normal program termination (for instance, if :func:`sys.exit` is called or
4514
the main module's execution completes), all functions registered are called in
4516
saved. After all exit handlers have had a chance to run the last exception to
4517
be raised is re-raised.
4519
- This function returns *func* which makes it possible to use it as a decorator
4520
- without binding the original name to ``None``.
4521
+ This function returns *func*, which makes it possible to use it as a
4525
.. function:: unregister(func)
4527
- Remove a function *func* from the list of functions to be run at interpreter-
4528
+ Remove *func* from the list of functions to be run at interpreter
4529
shutdown. After calling :func:`unregister`, *func* is guaranteed not to be
4530
- called when the interpreter shuts down.
4531
+ called when the interpreter shuts down, even if it was registered more than
4532
+ once. :func:`unregister` silently does nothing if *func* was not previously
4539
print("You are now leaving the Python sector.")
4541
-This obviously only works with functions that don't take arguments.
4544
+This only works with functions that can be called without arguments.
4545
diff -r 137e45f15c0b Doc/library/base64.rst
4546
--- a/Doc/library/base64.rst
4547
+++ b/Doc/library/base64.rst
4549
at least length 2 (additional characters are ignored) which specifies the
4550
alternative alphabet used instead of the ``+`` and ``/`` characters.
4552
- The decoded string is returned. A `binascii.Error` is raised if *s* is
4553
- incorrectly padded.
4554
+ The decoded string is returned. A :exc:`binascii.Error` exception is raised
4555
+ if *s* is incorrectly padded.
4557
If *validate* is ``False`` (the default), non-base64-alphabet characters are
4558
discarded prior to the padding check. If *validate* is ``True``,
4559
diff -r 137e45f15c0b Doc/library/builtins.rst
4560
--- a/Doc/library/builtins.rst
4561
+++ b/Doc/library/builtins.rst
4564
As an implementation detail, most modules have the name ``__builtins__`` made
4565
available as part of their globals. The value of ``__builtins__`` is normally
4566
-either this module or the value of this modules's :attr:`__dict__` attribute.
4567
+either this module or the value of this module's :attr:`__dict__` attribute.
4568
Since this is an implementation detail, it may not be used by alternate
4569
implementations of Python.
4570
diff -r 137e45f15c0b Doc/library/bz2.rst
4571
--- a/Doc/library/bz2.rst
4572
+++ b/Doc/library/bz2.rst
4574
It implements a complete file interface, one-shot (de)compression functions, and
4575
types for sequential (de)compression.
4577
-For other archive formats, see the :mod:`gzip`, :mod:`zipfile`, and
4578
-:mod:`tarfile` modules.
4580
Here is a summary of the features offered by the bz2 module:
4582
* :class:`BZ2File` class implements a complete file interface, including
4584
Support for the :keyword:`with` statement was added.
4589
+ This class does not support input files containing multiple streams (such
4590
+ as those produced by the :program:`pbzip2` tool). When reading such an
4591
+ input file, only the first stream will be accessible. If you require
4592
+ support for multi-stream files, consider using the third-party
4593
+ :mod:`bz2file` module (available from
4594
+ `PyPI <http://pypi.python.org/pypi/bz2file>`_). This module provides a
4595
+ backport of Python 3.3's :class:`BZ2File` class, which does support
4596
+ multi-stream files.
4601
Close the file. Sets data attribute :attr:`closed` to true. A closed file
4602
diff -r 137e45f15c0b Doc/library/cmd.rst
4603
--- a/Doc/library/cmd.rst
4604
+++ b/Doc/library/cmd.rst
4606
:mod:`readline`, on systems that support it, the interpreter will automatically
4607
support :program:`Emacs`\ -like line editing and command-history keystrokes.)
4617
def do_left(self, arg):
4618
'Turn turtle left by given number of degrees: LEFT 90'
4619
- right(*parse(arg))
4621
def do_goto(self, arg):
4622
'Move turtle to an absolute position with changing orientation. GOTO 100 200'
4624
diff -r 137e45f15c0b Doc/library/codecs.rst
4625
--- a/Doc/library/codecs.rst
4626
+++ b/Doc/library/codecs.rst
4627
@@ -810,27 +810,28 @@
4628
Windows). There's a string constant with 256 characters that shows you which
4629
character is mapped to which byte value.
4631
-All of these encodings can only encode 256 of the 65536 (or 1114111) codepoints
4632
+All of these encodings can only encode 256 of the 1114112 codepoints
4633
defined in Unicode. A simple and straightforward way that can store each Unicode
4634
-code point, is to store each codepoint as two consecutive bytes. There are two
4635
-possibilities: Store the bytes in big endian or in little endian order. These
4636
-two encodings are called UTF-16-BE and UTF-16-LE respectively. Their
4637
-disadvantage is that if e.g. you use UTF-16-BE on a little endian machine you
4638
-will always have to swap bytes on encoding and decoding. UTF-16 avoids this
4639
-problem: Bytes will always be in natural endianness. When these bytes are read
4640
+code point, is to store each codepoint as four consecutive bytes. There are two
4641
+possibilities: store the bytes in big endian or in little endian order. These
4642
+two encodings are called ``UTF-32-BE`` and ``UTF-32-LE`` respectively. Their
4643
+disadvantage is that if e.g. you use ``UTF-32-BE`` on a little endian machine you
4644
+will always have to swap bytes on encoding and decoding. ``UTF-32`` avoids this
4645
+problem: bytes will always be in natural endianness. When these bytes are read
4646
by a CPU with a different endianness, then bytes have to be swapped though. To
4647
-be able to detect the endianness of a UTF-16 byte sequence, there's the so
4648
-called BOM (the "Byte Order Mark"). This is the Unicode character ``U+FEFF``.
4649
-This character will be prepended to every UTF-16 byte sequence. The byte swapped
4650
-version of this character (``0xFFFE``) is an illegal character that may not
4651
-appear in a Unicode text. So when the first character in an UTF-16 byte sequence
4652
+be able to detect the endianness of a ``UTF-16`` or ``UTF-32`` byte sequence,
4653
+there's the so called BOM ("Byte Order Mark"). This is the Unicode character
4654
+``U+FEFF``. This character can be prepended to every ``UTF-16`` or ``UTF-32``
4655
+byte sequence. The byte swapped version of this character (``0xFFFE``) is an
4656
+illegal character that may not appear in a Unicode text. So when the
4657
+first character in an ``UTF-16`` or ``UTF-32`` byte sequence
4658
appears to be a ``U+FFFE`` the bytes have to be swapped on decoding.
4659
-Unfortunately upto Unicode 4.0 the character ``U+FEFF`` had a second purpose as
4660
-a ``ZERO WIDTH NO-BREAK SPACE``: A character that has no width and doesn't allow
4661
+Unfortunately the character ``U+FEFF`` had a second purpose as
4662
+a ``ZERO WIDTH NO-BREAK SPACE``: a character that has no width and doesn't allow
4663
a word to be split. It can e.g. be used to give hints to a ligature algorithm.
4664
With Unicode 4.0 using ``U+FEFF`` as a ``ZERO WIDTH NO-BREAK SPACE`` has been
4665
deprecated (with ``U+2060`` (``WORD JOINER``) assuming this role). Nevertheless
4666
-Unicode software still must be able to handle ``U+FEFF`` in both roles: As a BOM
4667
+Unicode software still must be able to handle ``U+FEFF`` in both roles: as a BOM
4668
it's a device to determine the storage layout of the encoded bytes, and vanishes
4669
once the byte sequence has been decoded into a string; as a ``ZERO WIDTH
4670
NO-BREAK SPACE`` it's a normal character that will be decoded like any other.
4672
There's another encoding that is able to encoding the full range of Unicode
4673
characters: UTF-8. UTF-8 is an 8-bit encoding, which means there are no issues
4674
with byte order in UTF-8. Each byte in a UTF-8 byte sequence consists of two
4675
-parts: Marker bits (the most significant bits) and payload bits. The marker bits
4676
-are a sequence of zero to six 1 bits followed by a 0 bit. Unicode characters are
4677
+parts: marker bits (the most significant bits) and payload bits. The marker bits
4678
+are a sequence of zero to four ``1`` bits followed by a ``0`` bit. Unicode characters are
4679
encoded like this (with x being payload bits, which when concatenated give the
4682
@@ -852,12 +853,7 @@
4683
+-----------------------------------+----------------------------------------------+
4684
| ``U-00000800`` ... ``U-0000FFFF`` | 1110xxxx 10xxxxxx 10xxxxxx |
4685
+-----------------------------------+----------------------------------------------+
4686
-| ``U-00010000`` ... ``U-001FFFFF`` | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
4687
-+-----------------------------------+----------------------------------------------+
4688
-| ``U-00200000`` ... ``U-03FFFFFF`` | 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx |
4689
-+-----------------------------------+----------------------------------------------+
4690
-| ``U-04000000`` ... ``U-7FFFFFFF`` | 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx |
4692
+| ``U-00010000`` ... ``U-0010FFFF`` | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
4693
+-----------------------------------+----------------------------------------------+
4695
The least significant bit of the Unicode character is the rightmost x bit.
4696
@@ -882,13 +878,14 @@
4697
| RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
4698
| INVERTED QUESTION MARK
4700
-in iso-8859-1), this increases the probability that a utf-8-sig encoding can be
4701
+in iso-8859-1), this increases the probability that a ``utf-8-sig`` encoding can be
4702
correctly guessed from the byte sequence. So here the BOM is not used to be able
4703
to determine the byte order used for generating the byte sequence, but as a
4704
signature that helps in guessing the encoding. On encoding the utf-8-sig codec
4705
will write ``0xef``, ``0xbb``, ``0xbf`` as the first three bytes to the file. On
4706
-decoding utf-8-sig will skip those three bytes if they appear as the first three
4708
+decoding ``utf-8-sig`` will skip those three bytes if they appear as the first
4709
+three bytes in the file. In UTF-8, the use of the BOM is discouraged and
4710
+should generally be avoided.
4713
.. _standard-encodings:
4714
diff -r 137e45f15c0b Doc/library/collections.rst
4715
--- a/Doc/library/collections.rst
4716
+++ b/Doc/library/collections.rst
4719
:mod:`collections` --- Container datatypes
4720
==========================================
4723
* The multiset methods are designed only for use cases with positive values.
4724
The inputs may be negative or zero, but only outputs with positive values
4725
are created. There are no type restrictions, but the value type needs to
4726
- support support addition, subtraction, and comparison.
4727
+ support addition, subtraction, and comparison.
4729
* The :meth:`elements` method requires integer counts. It ignores zero and
4731
@@ -469,6 +468,11 @@
4732
:class:`dict` class when the requested key is not found; whatever it
4733
returns or raises is then returned or raised by :meth:`__getitem__`.
4735
+ Note that :meth:`__missing__` is *not* called for any operations besides
4736
+ :meth:`__getitem__`. This means that :meth:`get` will, like normal
4737
+ dictionaries, return ``None`` as a default rather than using
4738
+ :attr:`default_factory`.
4741
:class:`defaultdict` objects support the following instance variable:
4745
OrderedDict.__setitem__(self, key, value)
4747
-An ordered dictionary can combined with the :class:`Counter` class
4748
+An ordered dictionary can be combined with the :class:`Counter` class
4749
so that the counter remembers the order elements are first encountered::
4751
class OrderedCounter(Counter, OrderedDict):
4753
subclass) or an arbitrary sequence which can be converted into a string using
4754
the built-in :func:`str` function.
4757
.. _collections-abstract-base-classes:
4759
ABCs - abstract base classes
4760
diff -r 137e45f15c0b Doc/library/concurrent.futures.rst
4761
--- a/Doc/library/concurrent.futures.rst
4762
+++ b/Doc/library/concurrent.futures.rst
4764
.. module:: concurrent.futures
4765
:synopsis: Execute computations concurrently using threads or processes.
4767
+.. versionadded:: 3.2
4769
**Source code:** :source:`Lib/concurrent/futures/thread.py`
4770
and :source:`Lib/concurrent/futures/process.py`
4772
-.. versionadded:: 3.2
4776
The :mod:`concurrent.futures` module provides a high-level interface for
4777
asynchronously executing callables.
4779
-The asynchronous execution can be be performed with threads, using
4780
+The asynchronous execution can be performed with threads, using
4781
:class:`ThreadPoolExecutor`, or separate processes, using
4782
:class:`ProcessPoolExecutor`. Both implement the same interface, which is
4783
defined by the abstract :class:`Executor` class.
4784
diff -r 137e45f15c0b Doc/library/configparser.rst
4785
--- a/Doc/library/configparser.rst
4786
+++ b/Doc/library/configparser.rst
4787
@@ -806,17 +806,17 @@
4788
cfg = configparser.ConfigParser()
4789
cfg.read('example.cfg')
4791
- # Set the optional `raw` argument of get() to True if you wish to disable
4792
+ # Set the optional *raw* argument of get() to True if you wish to disable
4793
# interpolation in a single get operation.
4794
print(cfg.get('Section1', 'foo', raw=False)) # -> "Python is fun!"
4795
print(cfg.get('Section1', 'foo', raw=True)) # -> "%(bar)s is %(baz)s!"
4797
- # The optional `vars` argument is a dict with members that will take
4798
+ # The optional *vars* argument is a dict with members that will take
4799
# precedence in interpolation.
4800
print(cfg.get('Section1', 'foo', vars={'bar': 'Documentation',
4803
- # The optional `fallback` argument can be used to provide a fallback value
4804
+ # The optional *fallback* argument can be used to provide a fallback value
4805
print(cfg.get('Section1', 'foo'))
4806
# -> "Python is fun!"
4808
diff -r 137e45f15c0b Doc/library/copy.rst
4809
--- a/Doc/library/copy.rst
4810
+++ b/Doc/library/copy.rst
4813
:synopsis: Shallow and deep copy operations.
4815
-This module provides generic (shallow and deep) copying operations.
4816
+Assignment statements in Python do not copy objects, they create bindings
4817
+between a target and an object. For collections that are mutable or contain
4818
+mutable items, a copy is sometimes needed so one can change one copy without
4819
+changing the other. This module provides generic shallow and deep copy
4820
+operations (explained below).
4824
diff -r 137e45f15c0b Doc/library/ctypes.rst
4825
--- a/Doc/library/ctypes.rst
4826
+++ b/Doc/library/ctypes.rst
4827
@@ -1815,8 +1815,6 @@
4828
termination character. An integer can be passed as second argument which allows
4829
to specify the size of the array if the length of the bytes should not be used.
4831
- If the first parameter is a string, it is converted into a bytes object
4832
- according to ctypes conversion rules.
4835
.. function:: create_unicode_buffer(init_or_size, size=None)
4836
@@ -1833,8 +1831,6 @@
4837
allows to specify the size of the array if the length of the string should not
4840
- If the first parameter is a bytes object, it is converted into an unicode string
4841
- according to ctypes conversion rules.
4844
.. function:: DllCanUnloadNow()
4845
@@ -1958,7 +1954,7 @@
4847
.. function:: string_at(address, size=-1)
4849
- This function returns the C string starting at memory address address as a bytes
4850
+ This function returns the C string starting at memory address *address* as a bytes
4851
object. If size is specified, it is used as size, otherwise the string is assumed
4852
to be zero-terminated.
4854
diff -r 137e45f15c0b Doc/library/curses.rst
4855
--- a/Doc/library/curses.rst
4856
+++ b/Doc/library/curses.rst
4859
Instantiate the string *str* with the supplied parameters, where *str* should
4860
be a parameterized string obtained from the terminfo database. E.g.
4861
- ``tparm(tigetstr("cup"), 5, 3)`` could result in ``'\033[6;4H'``, the exact
4862
+ ``tparm(tigetstr("cup"), 5, 3)`` could result in ``b'\033[6;4H'``, the exact
4863
result depending on terminal type.
4866
diff -r 137e45f15c0b Doc/library/datetime.rst
4867
--- a/Doc/library/datetime.rst
4868
+++ b/Doc/library/datetime.rst
4870
There are two kinds of date and time objects: "naive" and "aware". This
4871
distinction refers to whether the object has any notion of time zone, daylight
4872
saving time, or other kind of algorithmic or political time adjustment. Whether
4873
-a naive :class:`datetime` object represents Coordinated Universal Time (UTC),
4874
+a naive :class:`.datetime` object represents Coordinated Universal Time (UTC),
4875
local time, or time in some other timezone is purely up to the program, just
4876
like it's up to the program whether a particular number represents metres,
4877
-miles, or mass. Naive :class:`datetime` objects are easy to understand and to
4878
+miles, or mass. Naive :class:`.datetime` objects are easy to understand and to
4879
work with, at the cost of ignoring some aspects of reality.
4881
-For applications requiring more, :class:`datetime` and :class:`time` objects
4882
+For applications requiring more, :class:`.datetime` and :class:`.time` objects
4883
have an optional time zone information attribute, :attr:`tzinfo`, that can be
4884
set to an instance of a subclass of the abstract :class:`tzinfo` class. These
4885
:class:`tzinfo` objects capture information about the offset from UTC time, the
4886
time zone name, and whether Daylight Saving Time is in effect. Note that only
4887
one concrete :class:`tzinfo` class, the :class:`timezone` class, is supplied by the
4888
-:mod:`datetime` module. The :class:`timezone` class can reprsent simple
4889
+:mod:`datetime` module. The :class:`timezone` class can represent simple
4890
timezones with fixed offset from UTC such as UTC itself or North American EST and
4891
EDT timezones. Supporting timezones at whatever level of detail is
4892
required is up to the application. The rules for time adjustment across the
4897
- The smallest year number allowed in a :class:`date` or :class:`datetime` object.
4898
+ The smallest year number allowed in a :class:`date` or :class:`.datetime` object.
4899
:const:`MINYEAR` is ``1``.
4904
- The largest year number allowed in a :class:`date` or :class:`datetime` object.
4905
+ The largest year number allowed in a :class:`date` or :class:`.datetime` object.
4906
:const:`MAXYEAR` is ``9999``.
4910
.. class:: timedelta
4913
- A duration expressing the difference between two :class:`date`, :class:`time`,
4914
- or :class:`datetime` instances to microsecond resolution.
4915
+ A duration expressing the difference between two :class:`date`, :class:`.time`,
4916
+ or :class:`.datetime` instances to microsecond resolution.
4921
An abstract base class for time zone information objects. These are used by the
4922
- :class:`datetime` and :class:`time` classes to provide a customizable notion of
4923
+ :class:`.datetime` and :class:`.time` classes to provide a customizable notion of
4924
time adjustment (for example, to account for time zone and/or daylight saving
4929
Objects of the :class:`date` type are always naive.
4931
-An object *d* of type :class:`time` or :class:`datetime` may be naive or aware.
4932
+An object *d* of type :class:`.time` or :class:`.datetime` may be naive or aware.
4933
*d* is aware if ``d.tzinfo`` is not ``None`` and ``d.tzinfo.utcoffset(d)`` does
4934
not return ``None``. If ``d.tzinfo`` is ``None``, or if ``d.tzinfo`` is not
4935
``None`` but ``d.tzinfo.utcoffset(d)`` returns ``None``, *d* is naive.
4939
In addition to the operations listed above :class:`timedelta` objects support
4940
-certain additions and subtractions with :class:`date` and :class:`datetime`
4941
+certain additions and subtractions with :class:`date` and :class:`.datetime`
4942
objects (see below).
4944
.. versionchanged:: 3.2
4945
@@ -638,10 +638,10 @@
4946
:class:`datetime` Objects
4947
-------------------------
4949
-A :class:`datetime` object is a single object containing all the information
4950
-from a :class:`date` object and a :class:`time` object. Like a :class:`date`
4951
-object, :class:`datetime` assumes the current Gregorian calendar extended in
4952
-both directions; like a time object, :class:`datetime` assumes there are exactly
4953
+A :class:`.datetime` object is a single object containing all the information
4954
+from a :class:`date` object and a :class:`.time` object. Like a :class:`date`
4955
+object, :class:`.datetime` assumes the current Gregorian calendar extended in
4956
+both directions; like a time object, :class:`.datetime` assumes there are exactly
4957
3600\*24 seconds in every day.
4962
Return the current UTC date and time, with :attr:`tzinfo` ``None``. This is like
4963
:meth:`now`, but returns the current UTC date and time, as a naive
4964
- :class:`datetime` object. An aware current UTC datetime can be obtained by
4965
+ :class:`.datetime` object. An aware current UTC datetime can be obtained by
4966
calling ``datetime.now(timezone.utc)``. See also :meth:`now`.
4968
.. classmethod:: datetime.fromtimestamp(timestamp, tz=None)
4970
Return the local date and time corresponding to the POSIX timestamp, such as is
4971
returned by :func:`time.time`. If optional argument *tz* is ``None`` or not
4972
specified, the timestamp is converted to the platform's local date and time, and
4973
- the returned :class:`datetime` object is naive.
4974
+ the returned :class:`.datetime` object is naive.
4976
Else *tz* must be an instance of a class :class:`tzinfo` subclass, and the
4977
timestamp is converted to *tz*'s time zone. In this case the result is
4978
@@ -710,12 +710,12 @@
4979
1970 through 2038. Note that on non-POSIX systems that include leap seconds in
4980
their notion of a timestamp, leap seconds are ignored by :meth:`fromtimestamp`,
4981
and then it's possible to have two timestamps differing by a second that yield
4982
- identical :class:`datetime` objects. See also :meth:`utcfromtimestamp`.
4983
+ identical :class:`.datetime` objects. See also :meth:`utcfromtimestamp`.
4986
.. classmethod:: datetime.utcfromtimestamp(timestamp)
4988
- Return the UTC :class:`datetime` corresponding to the POSIX timestamp, with
4989
+ Return the UTC :class:`.datetime` corresponding to the POSIX timestamp, with
4990
:attr:`tzinfo` ``None``. This may raise :exc:`ValueError`, if the timestamp is
4991
out of the range of values supported by the platform C :c:func:`gmtime` function.
4992
It's common for this to be restricted to years in 1970 through 2038. See also
4995
.. classmethod:: datetime.fromordinal(ordinal)
4997
- Return the :class:`datetime` corresponding to the proleptic Gregorian ordinal,
4998
+ Return the :class:`.datetime` corresponding to the proleptic Gregorian ordinal,
4999
where January 1 of year 1 has ordinal 1. :exc:`ValueError` is raised unless ``1
5000
<= ordinal <= datetime.max.toordinal()``. The hour, minute, second and
5001
microsecond of the result are all 0, and :attr:`tzinfo` is ``None``.
5002
@@ -732,18 +732,18 @@
5004
.. classmethod:: datetime.combine(date, time)
5006
- Return a new :class:`datetime` object whose date components are equal to the
5007
+ Return a new :class:`.datetime` object whose date components are equal to the
5008
given :class:`date` object's, and whose time components and :attr:`tzinfo`
5009
- attributes are equal to the given :class:`time` object's. For any
5010
- :class:`datetime` object *d*,
5011
+ attributes are equal to the given :class:`.time` object's. For any
5012
+ :class:`.datetime` object *d*,
5013
``d == datetime.combine(d.date(), d.timetz())``. If date is a
5014
- :class:`datetime` object, its time components and :attr:`tzinfo` attributes
5015
+ :class:`.datetime` object, its time components and :attr:`tzinfo` attributes
5019
.. classmethod:: datetime.strptime(date_string, format)
5021
- Return a :class:`datetime` corresponding to *date_string*, parsed according to
5022
+ Return a :class:`.datetime` corresponding to *date_string*, parsed according to
5023
*format*. This is equivalent to ``datetime(*(time.strptime(date_string,
5024
format)[0:6]))``. :exc:`ValueError` is raised if the date_string and format
5025
can't be parsed by :func:`time.strptime` or if it returns a value which isn't a
5026
@@ -755,19 +755,19 @@
5028
.. attribute:: datetime.min
5030
- The earliest representable :class:`datetime`, ``datetime(MINYEAR, 1, 1,
5031
+ The earliest representable :class:`.datetime`, ``datetime(MINYEAR, 1, 1,
5035
.. attribute:: datetime.max
5037
- The latest representable :class:`datetime`, ``datetime(MAXYEAR, 12, 31, 23, 59,
5038
+ The latest representable :class:`.datetime`, ``datetime(MAXYEAR, 12, 31, 23, 59,
5039
59, 999999, tzinfo=None)``.
5042
.. attribute:: datetime.resolution
5044
- The smallest possible difference between non-equal :class:`datetime` objects,
5045
+ The smallest possible difference between non-equal :class:`.datetime` objects,
5046
``timedelta(microseconds=1)``.
5049
@@ -810,24 +810,24 @@
5051
.. attribute:: datetime.tzinfo
5053
- The object passed as the *tzinfo* argument to the :class:`datetime` constructor,
5054
+ The object passed as the *tzinfo* argument to the :class:`.datetime` constructor,
5055
or ``None`` if none was passed.
5058
Supported operations:
5060
-+---------------------------------------+-------------------------------+
5061
-| Operation | Result |
5062
-+=======================================+===============================+
5063
-| ``datetime2 = datetime1 + timedelta`` | \(1) |
5064
-+---------------------------------------+-------------------------------+
5065
-| ``datetime2 = datetime1 - timedelta`` | \(2) |
5066
-+---------------------------------------+-------------------------------+
5067
-| ``timedelta = datetime1 - datetime2`` | \(3) |
5068
-+---------------------------------------+-------------------------------+
5069
-| ``datetime1 < datetime2`` | Compares :class:`datetime` to |
5070
-| | :class:`datetime`. (4) |
5071
-+---------------------------------------+-------------------------------+
5072
++---------------------------------------+--------------------------------+
5073
+| Operation | Result |
5074
++=======================================+================================+
5075
+| ``datetime2 = datetime1 + timedelta`` | \(1) |
5076
++---------------------------------------+--------------------------------+
5077
+| ``datetime2 = datetime1 - timedelta`` | \(2) |
5078
++---------------------------------------+--------------------------------+
5079
+| ``timedelta = datetime1 - datetime2`` | \(3) |
5080
++---------------------------------------+--------------------------------+
5081
+| ``datetime1 < datetime2`` | Compares :class:`.datetime` to |
5082
+| | :class:`.datetime`. (4) |
5083
++---------------------------------------+--------------------------------+
5086
datetime2 is a duration of timedelta removed from datetime1, moving forward in
5088
in isolation can overflow in cases where datetime1 - timedelta does not.
5091
- Subtraction of a :class:`datetime` from a :class:`datetime` is defined only if
5092
+ Subtraction of a :class:`.datetime` from a :class:`.datetime` is defined only if
5093
both operands are naive, or if both are aware. If one is aware and the other is
5094
naive, :exc:`TypeError` is raised.
5096
@@ -875,16 +875,16 @@
5098
In order to stop comparison from falling back to the default scheme of comparing
5099
object addresses, datetime comparison normally raises :exc:`TypeError` if the
5100
- other comparand isn't also a :class:`datetime` object. However,
5101
+ other comparand isn't also a :class:`.datetime` object. However,
5102
``NotImplemented`` is returned instead if the other comparand has a
5103
:meth:`timetuple` attribute. This hook gives other kinds of date objects a
5104
- chance at implementing mixed-type comparison. If not, when a :class:`datetime`
5105
+ chance at implementing mixed-type comparison. If not, when a :class:`.datetime`
5106
object is compared to an object of a different type, :exc:`TypeError` is raised
5107
unless the comparison is ``==`` or ``!=``. The latter cases return
5108
:const:`False` or :const:`True`, respectively.
5110
-:class:`datetime` objects can be used as dictionary keys. In Boolean contexts,
5111
-all :class:`datetime` objects are considered to be true.
5112
+:class:`.datetime` objects can be used as dictionary keys. In Boolean contexts,
5113
+all :class:`.datetime` objects are considered to be true.
5117
@@ -895,13 +895,13 @@
5119
.. method:: datetime.time()
5121
- Return :class:`time` object with same hour, minute, second and microsecond.
5122
+ Return :class:`.time` object with same hour, minute, second and microsecond.
5123
:attr:`tzinfo` is ``None``. See also method :meth:`timetz`.
5126
.. method:: datetime.timetz()
5128
- Return :class:`time` object with same hour, minute, second, microsecond, and
5129
+ Return :class:`.time` object with same hour, minute, second, microsecond, and
5130
tzinfo attributes. See also method :meth:`time`.
5135
.. method:: datetime.astimezone(tz)
5137
- Return a :class:`datetime` object with new :attr:`tzinfo` attribute *tz*,
5138
+ Return a :class:`.datetime` object with new :attr:`tzinfo` attribute *tz*,
5139
adjusting the date and time data so the result is the same UTC time as
5140
*self*, but in *tz*'s local time.
5144
.. method:: datetime.utctimetuple()
5146
- If :class:`datetime` instance *d* is naive, this is the same as
5147
+ If :class:`.datetime` instance *d* is naive, this is the same as
5148
``d.timetuple()`` except that :attr:`tm_isdst` is forced to 0 regardless of what
5149
``d.dst()`` returns. DST is never in effect for a UTC time.
5151
@@ -1050,7 +1050,7 @@
5153
.. method:: datetime.__str__()
5155
- For a :class:`datetime` instance *d*, ``str(d)`` is equivalent to
5156
+ For a :class:`.datetime` instance *d*, ``str(d)`` is equivalent to
5157
``d.isoformat(' ')``.
5160
@@ -1199,19 +1199,19 @@
5162
.. attribute:: time.min
5164
- The earliest representable :class:`time`, ``time(0, 0, 0, 0)``.
5165
+ The earliest representable :class:`.time`, ``time(0, 0, 0, 0)``.
5168
.. attribute:: time.max
5170
- The latest representable :class:`time`, ``time(23, 59, 59, 999999)``.
5171
+ The latest representable :class:`.time`, ``time(23, 59, 59, 999999)``.
5174
.. attribute:: time.resolution
5176
- The smallest possible difference between non-equal :class:`time` objects,
5177
- ``timedelta(microseconds=1)``, although note that arithmetic on :class:`time`
5178
- objects is not supported.
5179
+ The smallest possible difference between non-equal :class:`.time` objects,
5180
+ ``timedelta(microseconds=1)``, although note that arithmetic on
5181
+ :class:`.time` objects is not supported.
5184
Instance attributes (read-only):
5185
@@ -1238,13 +1238,13 @@
5187
.. attribute:: time.tzinfo
5189
- The object passed as the tzinfo argument to the :class:`time` constructor, or
5190
+ The object passed as the tzinfo argument to the :class:`.time` constructor, or
5191
``None`` if none was passed.
5194
Supported operations:
5196
-* comparison of :class:`time` to :class:`time`, where *a* is considered less
5197
+* comparison of :class:`.time` to :class:`.time`, where *a* is considered less
5198
than *b* when *a* precedes *b* in time. If one comparand is naive and the other
5199
is aware, :exc:`TypeError` is raised. If both comparands are aware, and have
5200
the same :attr:`tzinfo` attribute, the common :attr:`tzinfo` attribute is
5201
@@ -1252,7 +1252,7 @@
5202
have different :attr:`tzinfo` attributes, the comparands are first adjusted by
5203
subtracting their UTC offsets (obtained from ``self.utcoffset()``). In order
5204
to stop mixed-type comparisons from falling back to the default comparison by
5205
- object address, when a :class:`time` object is compared to an object of a
5206
+ object address, when a :class:`.time` object is compared to an object of a
5207
different type, :exc:`TypeError` is raised unless the comparison is ``==`` or
5208
``!=``. The latter cases return :const:`False` or :const:`True`, respectively.
5210
@@ -1260,7 +1260,7 @@
5212
* efficient pickling
5214
-* in Boolean contexts, a :class:`time` object is considered to be true if and
5215
+* in Boolean contexts, a :class:`.time` object is considered to be true if and
5216
only if, after converting it to minutes and subtracting :meth:`utcoffset` (or
5217
``0`` if that's ``None``), the result is non-zero.
5219
@@ -1269,10 +1269,10 @@
5221
.. method:: time.replace([hour[, minute[, second[, microsecond[, tzinfo]]]]])
5223
- Return a :class:`time` with the same value, except for those attributes given
5224
+ Return a :class:`.time` with the same value, except for those attributes given
5225
new values by whichever keyword arguments are specified. Note that
5226
- ``tzinfo=None`` can be specified to create a naive :class:`time` from an
5227
- aware :class:`time`, without conversion of the time data.
5228
+ ``tzinfo=None`` can be specified to create a naive :class:`.time` from an
5229
+ aware :class:`.time`, without conversion of the time data.
5232
.. method:: time.isoformat()
5233
@@ -1350,13 +1350,13 @@
5234
:class:`tzinfo` is an abstract base class, meaning that this class should not be
5235
instantiated directly. You need to derive a concrete subclass, and (at least)
5236
supply implementations of the standard :class:`tzinfo` methods needed by the
5237
-:class:`datetime` methods you use. The :mod:`datetime` module supplies
5238
+:class:`.datetime` methods you use. The :mod:`datetime` module supplies
5239
a simple concrete subclass of :class:`tzinfo` :class:`timezone` which can reprsent
5240
timezones with fixed offset from UTC such as UTC itself or North American EST and
5243
An instance of (a concrete subclass of) :class:`tzinfo` can be passed to the
5244
-constructors for :class:`datetime` and :class:`time` objects. The latter objects
5245
+constructors for :class:`.datetime` and :class:`.time` objects. The latter objects
5246
view their attributes as being in local time, and the :class:`tzinfo` object
5247
supports methods revealing offset of local time from UTC, the name of the time
5248
zone, and DST offset, all relative to a date or time object passed to them.
5249
@@ -1411,7 +1411,7 @@
5251
``tz.utcoffset(dt) - tz.dst(dt)``
5253
- must return the same result for every :class:`datetime` *dt* with ``dt.tzinfo ==
5254
+ must return the same result for every :class:`.datetime` *dt* with ``dt.tzinfo ==
5255
tz`` For sane :class:`tzinfo` subclasses, this expression yields the time
5256
zone's "standard offset", which should not depend on the date or the time, but
5257
only on geographic location. The implementation of :meth:`datetime.astimezone`
5258
@@ -1422,13 +1422,13 @@
5260
Most implementations of :meth:`dst` will probably look like one of these two::
5263
+ def dst(self, dt):
5264
# a fixed-offset class: doesn't account for DST
5270
+ def dst(self, dt):
5271
# Code to set dston and dstoff to the time zone's DST
5272
# transition times based on the input dt.year, and expressed
5273
# in standard local time. Then
5274
@@ -1443,7 +1443,7 @@
5276
.. method:: tzinfo.tzname(dt)
5278
- Return the time zone name corresponding to the :class:`datetime` object *dt*, as
5279
+ Return the time zone name corresponding to the :class:`.datetime` object *dt*, as
5280
a string. Nothing about string names is defined by the :mod:`datetime` module,
5281
and there's no requirement that it mean anything in particular. For example,
5282
"GMT", "UTC", "-500", "-5:00", "EDT", "US/Eastern", "America/New York" are all
5283
@@ -1456,11 +1456,11 @@
5284
The default implementation of :meth:`tzname` raises :exc:`NotImplementedError`.
5287
-These methods are called by a :class:`datetime` or :class:`time` object, in
5288
-response to their methods of the same names. A :class:`datetime` object passes
5289
-itself as the argument, and a :class:`time` object passes ``None`` as the
5290
+These methods are called by a :class:`.datetime` or :class:`.time` object, in
5291
+response to their methods of the same names. A :class:`.datetime` object passes
5292
+itself as the argument, and a :class:`.time` object passes ``None`` as the
5293
argument. A :class:`tzinfo` subclass's methods should therefore be prepared to
5294
-accept a *dt* argument of ``None``, or of class :class:`datetime`.
5295
+accept a *dt* argument of ``None``, or of class :class:`.datetime`.
5297
When ``None`` is passed, it's up to the class designer to decide the best
5298
response. For example, returning ``None`` is appropriate if the class wishes to
5299
@@ -1468,7 +1468,7 @@
5300
may be more useful for ``utcoffset(None)`` to return the standard UTC offset, as
5301
there is no other convention for discovering the standard offset.
5303
-When a :class:`datetime` object is passed in response to a :class:`datetime`
5304
+When a :class:`.datetime` object is passed in response to a :class:`.datetime`
5305
method, ``dt.tzinfo`` is the same object as *self*. :class:`tzinfo` methods can
5306
rely on this, unless user code calls :class:`tzinfo` methods directly. The
5307
intent is that the :class:`tzinfo` methods interpret *dt* as being in local
5308
@@ -1606,7 +1606,7 @@
5309
.. method:: timezone.fromutc(dt)
5311
Return ``dt + offset``. The *dt* argument must be an aware
5312
- :class:`datetime` instance, with ``tzinfo`` set to ``self``.
5313
+ :class:`.datetime` instance, with ``tzinfo`` set to ``self``.
5317
@@ -1620,18 +1620,18 @@
5318
:meth:`strftime` and :meth:`strptime` Behavior
5319
----------------------------------------------
5321
-:class:`date`, :class:`datetime`, and :class:`time` objects all support a
5322
+:class:`date`, :class:`.datetime`, and :class:`.time` objects all support a
5323
``strftime(format)`` method, to create a string representing the time under the
5324
control of an explicit format string. Broadly speaking, ``d.strftime(fmt)``
5325
acts like the :mod:`time` module's ``time.strftime(fmt, d.timetuple())``
5326
although not all objects support a :meth:`timetuple` method.
5328
Conversely, the :meth:`datetime.strptime` class method creates a
5329
-:class:`datetime` object from a string representing a date and time and a
5330
+:class:`.datetime` object from a string representing a date and time and a
5331
corresponding format string. ``datetime.strptime(date_string, format)`` is
5332
equivalent to ``datetime(*(time.strptime(date_string, format)[0:6]))``.
5334
-For :class:`time` objects, the format codes for year, month, and day should not
5335
+For :class:`.time` objects, the format codes for year, month, and day should not
5336
be used, as time objects have no such values. If they're used anyway, ``1900``
5337
is substituted for the year, and ``1`` for the month and day.
5339
@@ -1789,5 +1789,5 @@
5341
.. versionchanged:: 3.2
5342
When the ``%z`` directive is provided to the :meth:`strptime` method, an
5343
- aware :class:`datetime` object will be produced. The ``tzinfo`` of the
5344
+ aware :class:`.datetime` object will be produced. The ``tzinfo`` of the
5345
result will be set to a :class:`timezone` instance.
5346
diff -r 137e45f15c0b Doc/library/decimal.rst
5347
--- a/Doc/library/decimal.rst
5348
+++ b/Doc/library/decimal.rst
5350
people learn at school." -- excerpt from the decimal arithmetic specification.
5352
* Decimal numbers can be represented exactly. In contrast, numbers like
5353
- :const:`1.1` and :const:`2.2` do not have an exact representations in binary
5354
+ :const:`1.1` and :const:`2.2` do not have exact representations in binary
5355
floating point. End users typically would not expect ``1.1 + 2.2`` to display
5356
as :const:`3.3000000000000003` as it does with binary floating point.
5358
diff -r 137e45f15c0b Doc/library/email.header.rst
5359
--- a/Doc/library/email.header.rst
5360
+++ b/Doc/library/email.header.rst
5361
@@ -141,11 +141,11 @@
5362
Returns an approximation of the :class:`Header` as a string, using an
5363
unlimited line length. All pieces are converted to unicode using the
5364
specified encoding and joined together appropriately. Any pieces with a
5365
- charset of `unknown-8bit` are decoded as `ASCII` using the `replace`
5366
+ charset of ``'unknown-8bit'`` are decoded as ASCII using the ``'replace'``
5369
.. versionchanged:: 3.2
5370
- Added handling for the `unknown-8bit` charset.
5371
+ Added handling for the ``'unknown-8bit'`` charset.
5374
.. method:: __eq__(other)
5375
diff -r 137e45f15c0b Doc/library/email.message.rst
5376
--- a/Doc/library/email.message.rst
5377
+++ b/Doc/library/email.message.rst
5380
Content-Disposition: attachment; filename="bud.gif"
5382
- An example with with non-ASCII characters::
5383
+ An example with non-ASCII characters::
5385
msg.add_header('Content-Disposition', 'attachment',
5386
filename=('iso-8859-1', '', 'Fußballer.ppt'))
5387
diff -r 137e45f15c0b Doc/library/email.parser.rst
5388
--- a/Doc/library/email.parser.rst
5389
+++ b/Doc/library/email.parser.rst
5391
data or by a blank line. Following the header block is the body of the
5392
message (which may contain MIME-encoded subparts).
5394
- Optional *headersonly* is as with the :meth:`parse` method.
5395
+ Optional *headersonly* is a flag specifying whether to stop parsing after
5396
+ reading the headers or not. The default is ``False``, meaning it parses
5397
+ the entire contents of the file.
5399
.. method:: parsestr(text, headersonly=False)
5402
equivalent to wrapping *text* in a :class:`~io.StringIO` instance first and
5403
calling :meth:`parse`.
5405
- Optional *headersonly* is a flag specifying whether to stop parsing after
5406
- reading the headers or not. The default is ``False``, meaning it parses
5407
- the entire contents of the file.
5408
+ Optional *headersonly* is as with the :meth:`parse` method.
5411
.. class:: BytesParser(_class=email.message.Message, strict=None)
5412
diff -r 137e45f15c0b Doc/library/exceptions.rst
5413
--- a/Doc/library/exceptions.rst
5414
+++ b/Doc/library/exceptions.rst
5417
The base class for all built-in exceptions. It is not meant to be directly
5418
inherited by user-defined classes (for that, use :exc:`Exception`). If
5419
- :func:`bytes` or :func:`str` is called on an instance of this class, the
5420
- representation of the argument(s) to the instance are returned, or the empty
5421
- string when there were no arguments.
5422
+ :func:`str` is called on an instance of this class, the representation of
5423
+ the argument(s) to the instance are returned, or the empty string when
5424
+ there were no arguments.
5428
diff -r 137e45f15c0b Doc/library/functions.rst
5429
--- a/Doc/library/functions.rst
5430
+++ b/Doc/library/functions.rst
5432
=================== ================= ================== ================ ====================
5433
.. .. Built-in Functions .. ..
5434
=================== ================= ================== ================ ====================
5435
-:func:`abs` :func:`dict` :func:`help` :func:`min` :func:`setattr`
5436
+:func:`abs` |func-dict|_ :func:`help` :func:`min` :func:`setattr`
5437
:func:`all` :func:`dir` :func:`hex` :func:`next` :func:`slice`
5438
:func:`any` :func:`divmod` :func:`id` :func:`object` :func:`sorted`
5439
:func:`ascii` :func:`enumerate` :func:`input` :func:`oct` :func:`staticmethod`
5441
:func:`bytearray` :func:`filter` :func:`issubclass` :func:`pow` :func:`super`
5442
:func:`bytes` :func:`float` :func:`iter` :func:`print` :func:`tuple`
5443
:func:`callable` :func:`format` :func:`len` :func:`property` :func:`type`
5444
-:func:`chr` :func:`frozenset` :func:`list` :func:`range` :func:`vars`
5445
+:func:`chr` |func-frozenset|_ :func:`list` :func:`range` :func:`vars`
5446
:func:`classmethod` :func:`getattr` :func:`locals` :func:`repr` :func:`zip`
5447
:func:`compile` :func:`globals` :func:`map` :func:`reversed` :func:`__import__`
5448
:func:`complex` :func:`hasattr` :func:`max` :func:`round`
5449
-:func:`delattr` :func:`hash` :func:`memoryview` :func:`set`
5450
+:func:`delattr` :func:`hash` |func-memoryview|_ |func-set|_
5451
=================== ================= ================== ================ ====================
5453
+.. using :func:`dict` would create a link to another page, so local targets are
5454
+ used, with replacement texts to make the output in the table consistent
5456
+.. |func-dict| replace:: ``dict()``
5457
+.. |func-frozenset| replace:: ``frozenset()``
5458
+.. |func-memoryview| replace:: ``memoryview()``
5459
+.. |func-set| replace:: ``set()``
5462
.. function:: abs(x)
5464
Return the absolute value of a number. The argument may be an
5467
.. function:: bool([x])
5469
- Convert a value to a Boolean, using the standard truth testing procedure. If
5470
- *x* is false or omitted, this returns :const:`False`; otherwise it returns
5471
- :const:`True`. :class:`bool` is also a class, which is a subclass of
5472
- :class:`int`. Class :class:`bool` cannot be subclassed further. Its only
5473
- instances are :const:`False` and :const:`True`.
5474
+ Convert a value to a Boolean, using the standard :ref:`truth testing
5475
+ procedure <truth>`. If *x* is false or omitted, this returns ``False``;
5476
+ otherwise it returns ``True``. :class:`bool` is also a class, which is a
5477
+ subclass of :class:`int` (see :ref:`typesnumeric`). Class :class:`bool`
5478
+ cannot be subclassed further. Its only instances are ``False`` and
5479
+ ``True`` (see :ref:`bltin-boolean-values`).
5481
.. index:: pair: Boolean; type
5484
example, ``delattr(x, 'foobar')`` is equivalent to ``del x.foobar``.
5488
.. function:: dict([arg])
5493
The float type is described in :ref:`typesnumeric`.
5496
.. function:: format(value[, format_spec])
5500
:exc:`TypeError` exception is raised if the method is not found or if either
5501
the *format_spec* or the return value are not strings.
5504
+.. _func-frozenset:
5505
.. function:: frozenset([iterable])
5509
.. function:: isinstance(object, classinfo)
5511
Return true if the *object* argument is an instance of the *classinfo*
5512
- argument, or of a (direct or indirect) subclass thereof. If *object* is not
5513
+ argument, or of a (direct, indirect or :term:`virtual <abstract base
5514
+ class>`) subclass thereof. If *object* is not
5515
an object of the given type, the function always returns false. If
5516
*classinfo* is not a class (type object), it may be a tuple of type objects,
5517
or may recursively contain other such tuples (other sequence types are not
5520
.. function:: issubclass(class, classinfo)
5522
- Return true if *class* is a subclass (direct or indirect) of *classinfo*. A
5523
+ Return true if *class* is a subclass (direct, indirect or :term:`virtual
5524
+ <abstract base class>`) of *classinfo*. A
5525
class is considered a subclass of itself. *classinfo* may be a tuple of class
5526
objects, in which case every entry in *classinfo* will be checked. In any other
5527
case, a :exc:`TypeError` exception is raised.
5529
such as ``sorted(iterable, key=keyfunc, reverse=True)[0]`` and
5530
``heapq.nlargest(1, iterable, key=keyfunc)``.
5533
+.. _func-memoryview:
5534
.. function:: memoryview(obj)
5540
Python doesn't depend on the underlying operating system's notion of text
5541
- files; all the the processing is done by Python itself, and is therefore
5542
+ files; all the processing is done by Python itself, and is therefore
5543
platform-independent.
5545
*buffering* is an optional integer used to set the buffering policy. Pass 0
5547
.. XXX works for bytes too, but should it?
5548
.. function:: ord(c)
5550
- Given a string representing one Uncicode character, return an integer
5551
+ Given a string representing one Unicode character, return an integer
5552
representing the Unicode code
5553
point of that character. For example, ``ord('a')`` returns the integer ``97``
5554
and ``ord('\u2020')`` returns ``8224``. This is the inverse of :func:`chr`.
5558
The *file* argument must be an object with a ``write(string)`` method; if it
5559
- is not present or ``None``, :data:`sys.stdout` will be used.
5560
+ is not present or ``None``, :data:`sys.stdout` will be used. Output buffering
5561
+ is determined by *file*. Use ``file.flush()`` to ensure, for instance,
5562
+ immediate appearance on a screen.
5565
.. function:: property(fget=None, fset=None, fdel=None, doc=None)
5566
@@ -1038,7 +1058,7 @@
5568
Range objects implement the :class:`collections.Sequence` ABC, and provide
5569
features such as containment tests, element index lookup, slicing and
5570
- support for negative indices:
5571
+ support for negative indices (see :ref:`typesseq`):
5573
>>> r = range(0, 20, 2)
5575
@@ -1106,6 +1126,8 @@
5576
can't be represented exactly as a float. See :ref:`tut-fp-issues` for
5581
.. function:: set([iterable])
5584
@@ -1347,10 +1369,10 @@
5585
def zip(*iterables):
5586
# zip('ABCD', 'xy') --> Ax By
5588
- iterables = [iter(it) for it in iterables]
5590
+ iterators = [iter(it) for it in iterables]
5593
- for it in iterables:
5594
+ for it in iterators:
5595
elem = next(it, sentinel)
5596
if elem is sentinel:
5598
diff -r 137e45f15c0b Doc/library/functools.rst
5599
--- a/Doc/library/functools.rst
5600
+++ b/Doc/library/functools.rst
5602
-:mod:`functools` --- Higher order functions and operations on callable objects
5603
+:mod:`functools` --- Higher-order functions and operations on callable objects
5604
==============================================================================
5606
.. module:: functools
5607
- :synopsis: Higher order functions and operations on callable objects.
5608
+ :synopsis: Higher-order functions and operations on callable objects.
5609
.. moduleauthor:: Peter Harris <scav@blueyonder.co.uk>
5610
.. moduleauthor:: Raymond Hettinger <python@rcn.com>
5611
.. moduleauthor:: Nick Coghlan <ncoghlan@gmail.com>
5614
.. function:: cmp_to_key(func)
5616
- Transform an old-style comparison function to a key-function. Used with
5617
+ Transform an old-style comparison function to a key function. Used with
5618
tools that accept key functions (such as :func:`sorted`, :func:`min`,
5619
:func:`max`, :func:`heapq.nlargest`, :func:`heapq.nsmallest`,
5620
:func:`itertools.groupby`). This function is primarily used as a transition
5621
- tool for programs being converted from Py2.x which supported the use of
5622
+ tool for programs being converted from Python 2 which supported the use of
5623
comparison functions.
5625
- A compare function is any callable that accept two arguments, compares them,
5626
+ A comparison function is any callable that accept two arguments, compares them,
5627
and returns a negative number for less-than, zero for equality, or a positive
5628
number for greater-than. A key function is a callable that accepts one
5629
argument and returns another value indicating the position in the desired
5630
diff -r 137e45f15c0b Doc/library/gettext.rst
5631
--- a/Doc/library/gettext.rst
5632
+++ b/Doc/library/gettext.rst
5635
.. method:: lngettext(singular, plural, n)
5637
- If a fallback has been set, forward :meth:`ngettext` to the fallback.
5638
+ If a fallback has been set, forward :meth:`lngettext` to the fallback.
5639
Otherwise, return the translated message. Overridden in derived classes.
5643
.. [#] See the footnote for :func:`bindtextdomain` above.
5645
.. [#] François Pinard has written a program called :program:`xpot` which does a
5646
- similar job. It is available as part of his :program:`po-utils` package at http
5647
- ://po-utils.progiciels-bpi.ca/.
5648
+ similar job. It is available as part of his `po-utils package
5649
+ <http://po-utils.progiciels-bpi.ca/>`_.
5651
.. [#] :program:`msgfmt.py` is binary compatible with GNU :program:`msgfmt` except that
5652
it provides a simpler, all-Python implementation. With this and
5653
diff -r 137e45f15c0b Doc/library/gzip.rst
5654
--- a/Doc/library/gzip.rst
5655
+++ b/Doc/library/gzip.rst
5657
:program:`gzip` and :program:`gunzip` programs, such as those produced by
5658
:program:`compress` and :program:`pack`, are not supported by this module.
5660
-For other archive formats, see the :mod:`bz2`, :mod:`zipfile`, and
5661
-:mod:`tarfile` modules.
5663
The module defines the following items:
5668
The *mode* argument can be any of ``'r'``, ``'rb'``, ``'a'``, ``'ab'``, ``'w'``,
5669
or ``'wb'``, depending on whether the file will be read or written. The default
5670
- is the mode of *fileobj* if discernible; otherwise, the default is ``'rb'``. If
5671
- not given, the 'b' flag will be added to the mode to ensure the file is opened
5672
- in binary mode for cross-platform portability.
5673
+ is the mode of *fileobj* if discernible; otherwise, the default is ``'rb'``.
5675
+ Note that the file is always opened in binary mode; text mode is not
5676
+ supported. If you need to read a compressed file in text mode, wrap your
5677
+ :class:`GzipFile` with an :class:`io.TextIOWrapper`.
5679
The *compresslevel* argument is an integer from ``1`` to ``9`` controlling the
5680
level of compression; ``1`` is fastest and produces the least compression, and
5681
diff -r 137e45f15c0b Doc/library/heapq.rst
5682
--- a/Doc/library/heapq.rst
5683
+++ b/Doc/library/heapq.rst
5684
@@ -173,36 +173,36 @@
5685
with a dictionary pointing to an entry in the queue.
5687
Removing the entry or changing its priority is more difficult because it would
5688
-break the heap structure invariants. So, a possible solution is to mark an
5689
-entry as invalid and optionally add a new entry with the revised priority::
5690
+break the heap structure invariants. So, a possible solution is to mark the
5691
+entry as removed and add a new entry with the revised priority::
5693
- pq = [] # the priority queue list
5694
- counter = itertools.count(1) # unique sequence count
5695
- task_finder = {} # mapping of tasks to entries
5696
- INVALID = 0 # mark an entry as deleted
5697
+ pq = [] # list of entries arranged in a heap
5698
+ entry_finder = {} # mapping of tasks to entries
5699
+ REMOVED = '<removed-task>' # placeholder for a removed task
5700
+ counter = itertools.count() # unique sequence count
5702
- def add_task(priority, task, count=None):
5704
- count = next(counter)
5705
+ def add_task(task, priority=0):
5706
+ 'Add a new task or update the priority of an existing task'
5707
+ if task in entry_finder:
5709
+ count = next(counter)
5710
entry = [priority, count, task]
5711
- task_finder[task] = entry
5712
+ entry_finder[task] = entry
5715
- def get_top_priority():
5717
+ def remove_task(task):
5718
+ 'Mark an existing task as REMOVED. Raise KeyError if not found.'
5719
+ entry = entry_finder.pop(task)
5720
+ entry[-1] = REMOVED
5723
+ 'Remove and return the lowest priority task. Raise KeyError if empty.'
5725
priority, count, task = heappop(pq)
5726
- del task_finder[task]
5727
- if count is not INVALID:
5728
+ if task is not REMOVED:
5729
+ del entry_finder[task]
5732
- def delete_task(task):
5733
- entry = task_finder[task]
5734
- entry[1] = INVALID
5736
- def reprioritize(priority, task):
5737
- entry = task_finder[task]
5738
- add_task(priority, task, entry[1])
5739
- entry[1] = INVALID
5740
+ raise KeyError('pop from an empty priority queue')
5744
diff -r 137e45f15c0b Doc/library/hmac.rst
5745
--- a/Doc/library/hmac.rst
5746
+++ b/Doc/library/hmac.rst
5749
An HMAC object has the following methods:
5751
-.. method:: hmac.update(msg)
5752
+.. method:: HMAC.update(msg)
5754
Update the hmac object with the bytes object *msg*. Repeated calls are
5755
equivalent to a single call with the concatenation of all the arguments:
5756
``m.update(a); m.update(b)`` is equivalent to ``m.update(a + b)``.
5759
-.. method:: hmac.digest()
5760
+.. method:: HMAC.digest()
5762
Return the digest of the bytes passed to the :meth:`update` method so far.
5763
This bytes object will be the same length as the *digest_size* of the digest
5768
-.. method:: hmac.hexdigest()
5769
+.. method:: HMAC.hexdigest()
5771
Like :meth:`digest` except the digest is returned as a string twice the
5772
length containing only hexadecimal digits. This may be used to exchange the
5773
value safely in email or other non-binary environments.
5776
-.. method:: hmac.copy()
5777
+.. method:: HMAC.copy()
5779
Return a copy ("clone") of the hmac object. This can be used to efficiently
5780
compute the digests of strings that share a common initial substring.
5781
diff -r 137e45f15c0b Doc/library/html.parser.rst
5782
--- a/Doc/library/html.parser.rst
5783
+++ b/Doc/library/html.parser.rst
5785
.. method:: HTMLParser.handle_startendtag(tag, attrs)
5787
Similar to :meth:`handle_starttag`, but called when the parser encounters an
5788
- XHTML-style empty tag (``<a .../>``). This method may be overridden by
5789
+ XHTML-style empty tag (``<img ... />``). This method may be overridden by
5790
subclasses which require this particular lexical information; the default
5791
- implementation simple calls :meth:`handle_starttag` and :meth:`handle_endtag`.
5792
+ implementation simply calls :meth:`handle_starttag` and :meth:`handle_endtag`.
5795
.. method:: HTMLParser.handle_endtag(tag)
5798
.. method:: HTMLParser.handle_data(data)
5800
- This method is called to process arbitrary data. It is intended to be
5801
+ This method is called to process arbitrary data (e.g. the content of
5802
+ ``<script>...</script>`` and ``<style>...</style>``). It is intended to be
5803
overridden by a derived class; the base class implementation does nothing.
5806
@@ -178,27 +179,23 @@
5807
Example HTML Parser Application
5808
-------------------------------
5810
-As a basic example, below is a very basic HTML parser that uses the
5811
-:class:`HTMLParser` class to print out tags as they are encountered::
5812
+As a basic example, below is a simple HTML parser that uses the
5813
+:class:`HTMLParser` class to print out start tags, end tags, and data
5814
+as they are encountered::
5816
- >>> from html.parser import HTMLParser
5818
- >>> class MyHTMLParser(HTMLParser):
5819
- ... def handle_starttag(self, tag, attrs):
5820
- ... print("Encountered a {} start tag".format(tag))
5821
- ... def handle_endtag(self, tag):
5822
- ... print("Encountered a {} end tag".format(tag))
5824
- >>> page = """<html><h1>Title</h1><p>I'm a paragraph!</p></html>"""
5826
- >>> myparser = MyHTMLParser()
5827
- >>> myparser.feed(page)
5828
- Encountered a html start tag
5829
- Encountered a h1 start tag
5830
- Encountered a h1 end tag
5831
- Encountered a p start tag
5832
- Encountered a p end tag
5833
- Encountered a html end tag
5834
+ from html.parser import HTMLParser
5836
+ class MyHTMLParser(HTMLParser):
5837
+ def handle_starttag(self, tag, attrs):
5838
+ print("Encountered a start tag:", tag)
5839
+ def handle_endtag(self, tag):
5840
+ print("Encountered an end tag:", tag)
5841
+ def handle_data(self, data):
5842
+ print("Encountered some data:", data)
5844
+ parser = MyHTMLParser()
5845
+ parser.feed('<html><head><title>Test</title></head>'
5846
+ '<body><h1>Parse me!</h1></body></html>')
5849
.. rubric:: Footnotes
5850
diff -r 137e45f15c0b Doc/library/http.client.rst
5851
--- a/Doc/library/http.client.rst
5852
+++ b/Doc/library/http.client.rst
5854
Set the host and the port for HTTP Connect Tunnelling. Normally used when it
5855
is required to a HTTPS Connection through a proxy server.
5857
- The headers argument should be a mapping of extra HTTP headers to to sent
5858
+ The headers argument should be a mapping of extra HTTP headers to send
5859
with the CONNECT request.
5861
.. versionadded:: 3.2
5862
@@ -472,10 +472,13 @@
5866
-.. method:: HTTPConnection.endheaders()
5867
+.. method:: HTTPConnection.endheaders(message_body=None)
5869
- Send a blank line to the server, signalling the end of the headers.
5871
+ Send a blank line to the server, signalling the end of the headers. The
5872
+ optional *message_body* argument can be used to pass a message body
5873
+ associated with the request. The message body will be sent in the same
5874
+ packet as the message headers if it is string, otherwise it is sent in a
5877
.. method:: HTTPConnection.send(data)
5879
diff -r 137e45f15c0b Doc/library/imaplib.rst
5880
--- a/Doc/library/imaplib.rst
5881
+++ b/Doc/library/imaplib.rst
5883
Convert *date_time* to an IMAP4 ``INTERNALDATE`` representation. The
5884
return value is a string in the form: ``"DD-Mmm-YYYY HH:MM:SS
5885
+HHMM"`` (including double-quotes). The *date_time* argument can be a
5886
- number (int or float) represening seconds since epoch (as returned
5887
+ number (int or float) representing seconds since epoch (as returned
5888
by :func:`time.time`), a 9-tuple representing local time (as returned by
5889
:func:`time.localtime`), or a double-quoted string. In the last case, it
5890
is assumed to already be in the correct format.
5891
diff -r 137e45f15c0b Doc/library/inspect.rst
5892
--- a/Doc/library/inspect.rst
5893
+++ b/Doc/library/inspect.rst
5894
@@ -575,13 +575,13 @@
5897
For cases where you want passive introspection, like documentation tools, this
5898
-can be inconvenient. `getattr_static` has the same signature as :func:`getattr`
5899
+can be inconvenient. :func:`getattr_static` has the same signature as :func:`getattr`
5900
but avoids executing code when it fetches attributes.
5902
.. function:: getattr_static(obj, attr, default=None)
5904
Retrieve attributes without triggering dynamic lookup via the
5905
- descriptor protocol, `__getattr__` or `__getattribute__`.
5906
+ descriptor protocol, :meth:`__getattr__` or :meth:`__getattribute__`.
5908
Note: this function may not be able to retrieve all attributes
5909
that getattr can fetch (like dynamically created attributes)
5910
@@ -589,12 +589,12 @@
5911
that raise AttributeError). It can also return descriptors objects
5912
instead of instance members.
5914
- If the instance `__dict__` is shadowed by another member (for example a
5915
+ If the instance :attr:`__dict__` is shadowed by another member (for example a
5916
property) then this function will be unable to find instance members.
5918
.. versionadded:: 3.2
5920
-`getattr_static` does not resolve descriptors, for example slot descriptors or
5921
+:func:`getattr_static` does not resolve descriptors, for example slot descriptors or
5922
getset descriptors on objects implemented in C. The descriptor object
5923
is returned instead of the underlying attribute.
5925
diff -r 137e45f15c0b Doc/library/io.rst
5926
--- a/Doc/library/io.rst
5927
+++ b/Doc/library/io.rst
5929
:class:`IOBase` object can be iterated over yielding the lines in a stream.
5930
Lines are defined slightly differently depending on whether the stream is
5931
a binary stream (yielding bytes), or a text stream (yielding character
5932
- strings). See :meth:`readline` below.
5933
+ strings). See :meth:`~IOBase.readline` below.
5935
IOBase is also a context manager and therefore supports the
5936
:keyword:`with` statement. In this example, *file* is closed after the
5937
@@ -704,6 +704,32 @@
5938
Read until newline or EOF and return a single ``str``. If the stream is
5939
already at EOF, an empty string is returned.
5941
+ .. method:: seek(offset, whence=SEEK_SET)
5943
+ Change the stream position to the given *offset*. Behaviour depends
5944
+ on the *whence* parameter:
5946
+ * :data:`SEEK_SET` or ``0``: seek from the start of the stream
5947
+ (the default); *offset* must either be a number returned by
5948
+ :meth:`TextIOBase.tell`, or zero. Any other *offset* value
5949
+ produces undefined behaviour.
5950
+ * :data:`SEEK_CUR` or ``1``: "seek" to the current position;
5951
+ *offset* must be zero, which is a no-operation (all other values
5953
+ * :data:`SEEK_END` or ``2``: seek to the end of the stream;
5954
+ *offset* must be zero (all other values are unsupported).
5956
+ Return the new absolute position as an opaque number.
5958
+ .. versionadded:: 3.1
5959
+ The ``SEEK_*`` constants.
5961
+ .. method:: tell()
5963
+ Return the current stream position as an opaque number. The number
5964
+ does not usually represent a number of bytes in the underlying
5967
.. method:: write(s)
5969
Write the string *s* to the stream and return the number of characters
5970
diff -r 137e45f15c0b Doc/library/itertools.rst
5971
--- a/Doc/library/itertools.rst
5972
+++ b/Doc/library/itertools.rst
5976
indices = list(range(n))
5977
- cycles = range(n, n-r, -1)
5978
+ cycles = list(range(n, n-r, -1))
5979
yield tuple(pool[i] for i in indices[:r])
5981
for i in reversed(range(r)):
5982
@@ -496,6 +496,11 @@
5983
for i in range(times):
5986
+ A common use for *repeat* is to supply a stream of constant values to *map*
5989
+ >>> list(map(pow, range(10), repeat(2)))
5990
+ [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
5992
.. function:: starmap(function, iterable)
5994
@@ -557,16 +562,25 @@
5995
iterables are of uneven length, missing values are filled-in with *fillvalue*.
5996
Iteration continues until the longest iterable is exhausted. Equivalent to::
5998
- def zip_longest(*args, fillvalue=None):
5999
+ class ZipExhausted(Exception):
6002
+ def zip_longest(*args, **kwds):
6003
# zip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
6004
- def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
6005
- yield counter() # yields the fillvalue, or raises IndexError
6006
+ fillvalue = kwds.get('fillvalue')
6007
+ counter = len(args) - 1
6011
+ raise ZipExhausted
6014
fillers = repeat(fillvalue)
6015
- iters = [chain(it, sentinel(), fillers) for it in args]
6016
+ iterators = [chain(it, sentinel(), fillers) for it in args]
6018
- for tup in zip(*iters):
6020
- except IndexError:
6022
+ yield tuple(map(next, iterators))
6023
+ except ZipExhausted:
6026
If one of the iterables is potentially infinite, then the :func:`zip_longest`
6027
diff -r 137e45f15c0b Doc/library/json.rst
6028
--- a/Doc/library/json.rst
6029
+++ b/Doc/library/json.rst
6030
@@ -125,6 +125,10 @@
6031
:class:`bytes` objects. Therefore, ``fp.write()`` must support :class:`str`
6034
+ If *ensure_ascii* is ``True`` (the default), the output is guaranteed to
6035
+ have all incoming non-ASCII characters escaped. If *ensure_ascii* is
6036
+ ``False``, these characters will be output as-is.
6038
If *check_circular* is ``False`` (default: ``True``), then the circular
6039
reference check for container types will be skipped and a circular reference
6040
will result in an :exc:`OverflowError` (or worse).
6041
diff -r 137e45f15c0b Doc/library/locale.rst
6042
--- a/Doc/library/locale.rst
6043
+++ b/Doc/library/locale.rst
6046
.. exception:: Error
6048
- Exception raised when :func:`setlocale` fails.
6049
+ Exception raised when the locale passed to :func:`setlocale` is not
6053
.. function:: setlocale(category, locale=None)
6055
- If *locale* is specified, it may be a string, a tuple of the form ``(language
6056
- code, encoding)``, or ``None``. If it is a tuple, it is converted to a string
6057
- using the locale aliasing engine. If *locale* is given and not ``None``,
6058
- :func:`setlocale` modifies the locale setting for the *category*. The available
6059
- categories are listed in the data description below. The value is the name of a
6060
- locale. An empty string specifies the user's default settings. If the
6061
- modification of the locale fails, the exception :exc:`Error` is raised. If
6062
- successful, the new locale setting is returned.
6063
+ If *locale* is given and not ``None``, :func:`setlocale` modifies the locale
6064
+ setting for the *category*. The available categories are listed in the data
6065
+ description below. *locale* may be a string, or an iterable of two strings
6066
+ (language code and encoding). If it's an iterable, it's converted to a locale
6067
+ name using the locale aliasing engine. An empty string specifies the user's
6068
+ default settings. If the modification of the locale fails, the exception
6069
+ :exc:`Error` is raised. If successful, the new locale setting is returned.
6071
If *locale* is omitted or ``None``, the current setting for *category* is
6073
diff -r 137e45f15c0b Doc/library/logging.handlers.rst
6074
--- a/Doc/library/logging.handlers.rst
6075
+++ b/Doc/library/logging.handlers.rst
6081
+.. _queue-listener:
6085
diff -r 137e45f15c0b Doc/library/logging.rst
453
Subclassing QueueHandler - a ZeroMQ example
454
diff -r 7085403daf43 Doc/howto/regex.rst
455
--- a/Doc/howto/regex.rst
456
+++ b/Doc/howto/regex.rst
459
You can learn about this by interactively experimenting with the :mod:`re`
460
module. If you have :mod:`tkinter` available, you may also want to look at
461
-:file:`Tools/demo/redemo.py`, a demonstration program included with the
462
+:source:`Tools/demo/redemo.py`, a demonstration program included with the
463
Python distribution. It allows you to enter REs and strings, and displays
464
whether the RE matches or fails. :file:`redemo.py` can be quite useful when
465
trying to debug a complicated RE. Phil Schwartz's `Kodos
467
the same ones in several locations, then it might be worthwhile to collect all
468
the definitions in one place, in a section of code that compiles all the REs
469
ahead of time. To take an example from the standard library, here's an extract
470
-from the now deprecated :file:`xmllib.py`::
471
+from the now-defunct Python 2 standard :mod:`xmllib` module::
473
ref = re.compile( ... )
474
entityref = re.compile( ... )
475
diff -r 7085403daf43 Doc/includes/capsulethunk.h
477
+++ b/Doc/includes/capsulethunk.h
479
+#ifndef __CAPSULETHUNK_H
480
+#define __CAPSULETHUNK_H
482
+#if ( (PY_VERSION_HEX < 0x02070000) \
483
+ || ((PY_VERSION_HEX >= 0x03000000) \
484
+ && (PY_VERSION_HEX < 0x03010000)) )
486
+#define __PyCapsule_GetField(capsule, field, default_value) \
487
+ ( PyCapsule_CheckExact(capsule) \
488
+ ? (((PyCObject *)capsule)->field) \
489
+ : (default_value) \
492
+#define __PyCapsule_SetField(capsule, field, value) \
493
+ ( PyCapsule_CheckExact(capsule) \
494
+ ? (((PyCObject *)capsule)->field = value), 1 \
499
+#define PyCapsule_Type PyCObject_Type
501
+#define PyCapsule_CheckExact(capsule) (PyCObject_Check(capsule))
502
+#define PyCapsule_IsValid(capsule, name) (PyCObject_Check(capsule))
505
+#define PyCapsule_New(pointer, name, destructor) \
506
+ (PyCObject_FromVoidPtr(pointer, destructor))
509
+#define PyCapsule_GetPointer(capsule, name) \
510
+ (PyCObject_AsVoidPtr(capsule))
512
+/* Don't call PyCObject_SetPointer here, it fails if there's a destructor */
513
+#define PyCapsule_SetPointer(capsule, pointer) \
514
+ __PyCapsule_SetField(capsule, cobject, pointer)
517
+#define PyCapsule_GetDestructor(capsule) \
518
+ __PyCapsule_GetField(capsule, destructor)
520
+#define PyCapsule_SetDestructor(capsule, dtor) \
521
+ __PyCapsule_SetField(capsule, destructor, dtor)
525
+ * Sorry, there's simply no place
526
+ * to store a Capsule "name" in a CObject.
528
+#define PyCapsule_GetName(capsule) NULL
531
+PyCapsule_SetName(PyObject *capsule, const char *unused)
534
+ PyErr_SetString(PyExc_NotImplementedError,
535
+ "can't use PyCapsule_SetName with CObjects");
541
+#define PyCapsule_GetContext(capsule) \
542
+ __PyCapsule_GetField(capsule, descr)
544
+#define PyCapsule_SetContext(capsule, context) \
545
+ __PyCapsule_SetField(capsule, descr, context)
549
+PyCapsule_Import(const char *name, int no_block)
551
+ PyObject *object = NULL;
552
+ void *return_value = NULL;
554
+ size_t name_length = (strlen(name) + 1) * sizeof(char);
555
+ char *name_dup = (char *)PyMem_MALLOC(name_length);
561
+ memcpy(name_dup, name, name_length);
565
+ char *dot = strchr(trace, '.');
570
+ if (object == NULL) {
572
+ object = PyImport_ImportModuleNoBlock(trace);
574
+ object = PyImport_ImportModule(trace);
576
+ PyErr_Format(PyExc_ImportError,
577
+ "PyCapsule_Import could not "
578
+ "import module \"%s\"", trace);
582
+ PyObject *object2 = PyObject_GetAttrString(object, trace);
593
+ if (PyCObject_Check(object)) {
594
+ PyCObject *cobject = (PyCObject *)object;
595
+ return_value = cobject->cobject;
597
+ PyErr_Format(PyExc_AttributeError,
598
+ "PyCapsule_Import \"%s\" is not valid",
603
+ Py_XDECREF(object);
605
+ PyMem_FREE(name_dup);
607
+ return return_value;
610
+#endif /* #if PY_VERSION_HEX < 0x02070000 */
612
+#endif /* __CAPSULETHUNK_H */
613
diff -r 7085403daf43 Doc/library/logging.rst
6086
614
--- a/Doc/library/logging.rst
6087
615
+++ b/Doc/library/logging.rst
6090
.. attribute:: Logger.propagate
6092
- If this evaluates to false, logging messages are not passed by this logger or by
6093
- its child loggers to the handlers of higher level (ancestor) loggers. The
6094
- constructor sets this attribute to 1.
6095
+ If this evaluates to true, logging messages are passed by this logger and by
6096
+ its child loggers to the handlers of higher level (ancestor) loggers.
6097
+ Messages are passed directly to the ancestor loggers' handlers - neither the
6098
+ level nor filters of the ancestor loggers in question are considered.
6100
+ If this evaluates to false, logging messages are not passed to the handlers
6101
+ of ancestor loggers.
6103
+ The constructor sets this attribute to ``True``.
6106
.. method:: Logger.setLevel(lvl)
6108
If the root is reached, and it has a level of NOTSET, then all messages will be
6109
processed. Otherwise, the root's level will be used as the effective level.
6111
+ .. versionchanged:: 3.2
6112
+ The *lvl* parameter now accepts a string representation of the
6113
+ level such as 'INFO' as an alternative to the integer constants
6114
+ such as :const:`INFO`.
6117
.. method:: Logger.isEnabledFor(lvl)
6121
Stack (most recent call last):
6123
- This mimics the `Traceback (most recent call last):` which is used when
6124
+ This mimics the ``Traceback (most recent call last):`` which is used when
6125
displaying exception frames.
6127
The third keyword argument is *extra* which can be used to pass a
6128
@@ -313,6 +324,11 @@
6129
severe than *lvl* will be ignored. When a handler is created, the level is set
6130
to :const:`NOTSET` (which causes all messages to be processed).
6132
+ .. versionchanged:: 3.2
6133
+ The *lvl* parameter now accepts a string representation of the
6134
+ level such as 'INFO' as an alternative to the integer constants
6135
+ such as :const:`INFO`.
6138
.. method:: Handler.setFormatter(form)
6142
Stack (most recent call last):
6144
- This mimics the `Traceback (most recent call last):` which is used when
6145
+ This mimics the ``Traceback (most recent call last):`` which is used when
6146
displaying exception frames.
6148
The third optional keyword argument is *extra* which can be used to pass a
6149
@@ -1059,11 +1075,11 @@
618
FORMAT = '%(asctime)-15s %(clientip)s %(user)-8s %(message)s'
619
logging.basicConfig(format=FORMAT)
620
- d = { 'clientip' : '192.168.0.1', 'user' : 'fbloggs' }
621
+ d = {'clientip': '192.168.0.1', 'user': 'fbloggs'}
622
logger = logging.getLogger('tcpserver')
623
logger.warning('Protocol problem: %s', 'connection reset', extra=d)
625
@@ -1077,7 +1077,7 @@
6150
626
If *capture* is ``True``, warnings issued by the :mod:`warnings` module will
6151
627
be redirected to the logging system. Specifically, a warning will be
6152
628
formatted using :func:`warnings.formatwarning` and the resulting string
6153
- logged to a logger named 'py.warnings' with a severity of `WARNING`.
6154
+ logged to a logger named ``'py.warnings'`` with a severity of ``'WARNING'``.
629
- logged to a logger named ``'py.warnings'`` with a severity of ``'WARNING'``.
630
+ logged to a logger named ``'py.warnings'`` with a severity of :const:`WARNING`.
6156
632
If *capture* is ``False``, the redirection of warnings to the logging system
6157
633
will stop, and warnings will be redirected to their original destinations
6158
- (i.e. those in effect before `captureWarnings(True)` was called).
6159
+ (i.e. those in effect before ``captureWarnings(True)`` was called).
6163
diff -r 137e45f15c0b Doc/library/mailbox.rst
6164
--- a/Doc/library/mailbox.rst
6165
+++ b/Doc/library/mailbox.rst
6167
There is no requirement that :class:`Message` instances be used to represent
6168
messages retrieved using :class:`Mailbox` instances. In some situations, the
6169
time and memory required to generate :class:`Message` representations might
6170
- not not acceptable. For such situations, :class:`Mailbox` instances also
6171
+ not be acceptable. For such situations, :class:`Mailbox` instances also
6172
offer string and file-like representations, and a custom message factory may
6173
be specified when a :class:`Mailbox` instance is initialized.
6175
diff -r 137e45f15c0b Doc/library/mimetypes.rst
6176
--- a/Doc/library/mimetypes.rst
6177
+++ b/Doc/library/mimetypes.rst
6180
.. index:: pair: MIME; headers
6182
- Guess the type of a file based on its filename or URL, given by *filename*. The
6183
+ Guess the type of a file based on its filename or URL, given by *url*. The
6184
return value is a tuple ``(type, encoding)`` where *type* is ``None`` if the
6185
type can't be guessed (missing or unknown suffix) or a string of the form
6186
``'type/subtype'``, usable for a MIME :mailheader:`content-type` header.
6188
*encoding* is ``None`` for no encoding or the name of the program used to encode
6189
(e.g. :program:`compress` or :program:`gzip`). The encoding is suitable for use
6190
- as a :mailheader:`Content-Encoding` header, *not* as a
6191
+ as a :mailheader:`Content-Encoding` header, **not** as a
6192
:mailheader:`Content-Transfer-Encoding` header. The mappings are table driven.
6193
Encoding suffixes are case sensitive; type suffixes are first tried case
6194
sensitively, then case insensitively.
6196
- Optional *strict* is a flag specifying whether the list of known MIME types
6197
+ The optional *strict* argument is a flag specifying whether the list of known MIME types
6198
is limited to only the official types `registered with IANA
6199
- <http://www.iana.org/assignments/media-types/>`_ are recognized.
6200
- When *strict* is true (the default), only the IANA types are supported; when
6201
- *strict* is false, some additional non-standard but commonly used MIME types
6202
+ <http://www.iana.org/assignments/media-types/>`_.
6203
+ When *strict* is ``True`` (the default), only the IANA types are supported; when
6204
+ *strict* is ``False``, some additional non-standard but commonly used MIME types
6205
are also recognized.
6209
been associated with any particular data stream, but would be mapped to the MIME
6210
type *type* by :func:`guess_type`.
6212
- Optional *strict* has the same meaning as with the :func:`guess_type` function.
6213
+ The optional *strict* argument has the same meaning as with the :func:`guess_type` function.
6216
.. function:: guess_extension(type, strict=True)
6218
Guess the extension for a file based on its MIME type, given by *type*. The
6219
return value is a string giving a filename extension, including the leading dot
6220
(``'.'``). The extension is not guaranteed to have been associated with any
6221
- particular data stream, but would be mapped to the MIME type *type* by
6222
+ particular data stream, but would be mapped to the MIME type *type* by
6223
:func:`guess_type`. If no extension can be guessed for *type*, ``None`` is
6226
- Optional *strict* has the same meaning as with the :func:`guess_type` function.
6227
+ The optional *strict* argument has the same meaning as with the :func:`guess_type` function.
6229
Some additional functions and data items are available for controlling the
6230
behavior of the module.
6233
.. function:: read_mime_types(filename)
6235
- Load the type map given in the file *filename*, if it exists. The type map is
6236
+ Load the type map given in the file *filename*, if it exists. The type map is
6237
returned as a dictionary mapping filename extensions, including the leading dot
6238
(``'.'``), to strings of the form ``'type/subtype'``. If the file *filename*
6239
does not exist or cannot be read, ``None`` is returned.
6242
.. function:: add_type(type, ext, strict=True)
6244
- Add a mapping from the mimetype *type* to the extension *ext*. When the
6245
+ Add a mapping from the MIME type *type* to the extension *ext*. When the
6246
extension is already known, the new type will replace the old one. When the type
6247
is already known the extension will be added to the list of known extensions.
6249
- When *strict* is True (the default), the mapping will added to the official MIME
6250
+ When *strict* is ``True`` (the default), the mapping will added to the official MIME
6251
types, otherwise to the non-standard ones.
6256
Flag indicating whether or not the global data structures have been initialized.
6257
- This is set to true by :func:`init`.
6258
+ This is set to ``True`` by :func:`init`.
6261
.. data:: knownfiles
6262
@@ -145,22 +145,6 @@
6263
Dictionary mapping filename extensions to non-standard, but commonly found MIME
6266
-The :class:`MimeTypes` class may be useful for applications which may want more
6267
-than one MIME-type database:
6270
-.. class:: MimeTypes(filenames=(), strict=True)
6272
- This class represents a MIME-types database. By default, it provides access to
6273
- the same database as the rest of this module. The initial database is a copy of
6274
- that provided by the module, and may be extended by loading additional
6275
- :file:`mime.types`\ -style files into the database using the :meth:`read` or
6276
- :meth:`readfp` methods. The mapping dictionaries may also be cleared before
6277
- loading additional data if the default data is not desired.
6279
- The optional *filenames* parameter can be used to cause additional files to be
6280
- loaded "on top" of the default database.
6283
An example usage of the module::
6285
@@ -181,36 +165,53 @@
6289
-:class:`MimeTypes` instances provide an interface which is very like that of the
6290
+The :class:`MimeTypes` class may be useful for applications which may want more
6291
+than one MIME-type database; it provides an interface similar to the one of the
6292
:mod:`mimetypes` module.
6295
+.. class:: MimeTypes(filenames=(), strict=True)
6297
+ This class represents a MIME-types database. By default, it provides access to
6298
+ the same database as the rest of this module. The initial database is a copy of
6299
+ that provided by the module, and may be extended by loading additional
6300
+ :file:`mime.types`\ -style files into the database using the :meth:`read` or
6301
+ :meth:`readfp` methods. The mapping dictionaries may also be cleared before
6302
+ loading additional data if the default data is not desired.
6304
+ The optional *filenames* parameter can be used to cause additional files to be
6305
+ loaded "on top" of the default database.
6308
.. attribute:: MimeTypes.suffix_map
6310
Dictionary mapping suffixes to suffixes. This is used to allow recognition of
6311
encoded files for which the encoding and the type are indicated by the same
6312
extension. For example, the :file:`.tgz` extension is mapped to :file:`.tar.gz`
6313
to allow the encoding and type to be recognized separately. This is initially a
6314
- copy of the global ``suffix_map`` defined in the module.
6315
+ copy of the global :data:`suffix_map` defined in the module.
6318
.. attribute:: MimeTypes.encodings_map
6320
Dictionary mapping filename extensions to encoding types. This is initially a
6321
- copy of the global ``encodings_map`` defined in the module.
6322
+ copy of the global :data:`encodings_map` defined in the module.
6325
.. attribute:: MimeTypes.types_map
6327
- Dictionary mapping filename extensions to MIME types. This is initially a copy
6328
- of the global ``types_map`` defined in the module.
6329
+ Tuple containing two dictionaries, mapping filename extensions to MIME types:
6330
+ the first dictionary is for the non-standards types and the second one is for
6331
+ the standard types. They are initialized by :data:`common_types` and
6332
+ :data:`types_map`.
6335
-.. attribute:: MimeTypes.common_types
6336
+.. attribute:: MimeTypes.types_map_inv
6338
- Dictionary mapping filename extensions to non-standard, but commonly found MIME
6339
- types. This is initially a copy of the global ``common_types`` defined in the
6341
+ Tuple containing two dictionaries, mapping MIME types to a list of filename
6342
+ extensions: the first dictionary is for the non-standards types and the
6343
+ second one is for the standard types. They are initialized by
6344
+ :data:`common_types` and :data:`types_map`.
6347
.. method:: MimeTypes.guess_extension(type, strict=True)
6348
@@ -225,20 +226,35 @@
6352
-.. method:: MimeTypes.read(path)
6353
+.. method:: MimeTypes.guess_all_extensions(type, strict=True)
6355
- Load MIME information from a file named *path*. This uses :meth:`readfp` to
6356
+ Similar to the :func:`guess_all_extensions` function, using the tables stored
6357
+ as part of the object.
6360
+.. method:: MimeTypes.read(filename, strict=True)
6362
+ Load MIME information from a file named *filename*. This uses :meth:`readfp` to
6365
+ If *strict* is ``True``, information will be added to list of standard types,
6366
+ else to the list of non-standard types.
6368
-.. method:: MimeTypes.readfp(file)
6370
- Load MIME type information from an open file. The file must have the format of
6371
+.. method:: MimeTypes.readfp(fp, strict=True)
6373
+ Load MIME type information from an open file *fp*. The file must have the format of
6374
the standard :file:`mime.types` files.
6376
+ If *strict* is ``True``, information will be added to the list of standard
6377
+ types, else to the list of non-standard types.
6379
-.. method:: MimeTypes.read_windows_registry()
6381
+.. method:: MimeTypes.read_windows_registry(strict=True)
6383
Load MIME type information from the Windows registry. Availability: Windows.
6385
+ If *strict* is ``True``, information will be added to the list of standard
6386
+ types, else to the list of non-standard types.
6388
.. versionadded:: 3.2
6389
diff -r 137e45f15c0b Doc/library/mmap.rst
6390
--- a/Doc/library/mmap.rst
6391
+++ b/Doc/library/mmap.rst
6394
.. method:: write_byte(byte)
6396
- Write the the integer *byte* into memory at the current
6397
+ Write the integer *byte* into memory at the current
6398
position of the file pointer; the file position is advanced by ``1``. If
6399
the mmap was created with :const:`ACCESS_READ`, then writing to it will
6400
raise a :exc:`TypeError` exception.
6401
diff -r 137e45f15c0b Doc/library/multiprocessing.rst
6402
--- a/Doc/library/multiprocessing.rst
6403
+++ b/Doc/library/multiprocessing.rst
6405
For passing messages one can use :func:`Pipe` (for a connection between two
6406
processes) or a queue (which allows multiple producers and consumers).
6408
-The :class:`Queue` and :class:`JoinableQueue` types are multi-producer,
6409
+The :class:`Queue`, :class:`multiprocessing.queues.SimpleQueue` and :class:`JoinableQueue` types are multi-producer,
6410
multi-consumer FIFO queues modelled on the :class:`queue.Queue` class in the
6411
standard library. They differ in that :class:`Queue` lacks the
6412
:meth:`~queue.Queue.task_done` and :meth:`~queue.Queue.join` methods introduced
6415
If you use :class:`JoinableQueue` then you **must** call
6416
:meth:`JoinableQueue.task_done` for each task removed from the queue or else the
6417
-semaphore used to count the number of unfinished tasks may eventually overflow
6418
+semaphore used to count the number of unfinished tasks may eventually overflow,
6419
raising an exception.
6421
Note that one can also create a shared queue by using a manager object -- see
6424
If a process is killed using :meth:`Process.terminate` or :func:`os.kill`
6425
while it is trying to use a :class:`Queue`, then the data in the queue is
6426
- likely to become corrupted. This may cause any other processes to get an
6427
+ likely to become corrupted. This may cause any other process to get an
6428
exception when it tries to use the queue later on.
6432
Return ``True`` if the queue is full, ``False`` otherwise. Because of
6433
multithreading/multiprocessing semantics, this is not reliable.
6435
- .. method:: put(item[, block[, timeout]])
6437
- Put item into the queue. If the optional argument *block* is ``True``
6438
+ .. method:: put(obj[, block[, timeout]])
6440
+ Put obj into the queue. If the optional argument *block* is ``True``
6441
(the default) and *timeout* is ``None`` (the default), block if necessary until
6442
a free slot is available. If *timeout* is a positive number, it blocks at
6443
most *timeout* seconds and raises the :exc:`queue.Full` exception if no
6445
available, else raise the :exc:`queue.Full` exception (*timeout* is
6446
ignored in that case).
6448
- .. method:: put_nowait(item)
6450
- Equivalent to ``put(item, False)``.
6451
+ .. method:: put_nowait(obj)
6453
+ Equivalent to ``put(obj, False)``.
6455
.. method:: get([block[, timeout]])
6457
@@ -610,6 +610,23 @@
6458
exits -- see :meth:`join_thread`.
6461
+.. class:: multiprocessing.queues.SimpleQueue()
6463
+ It is a simplified :class:`Queue` type, very close to a locked :class:`Pipe`.
6465
+ .. method:: empty()
6467
+ Return ``True`` if the queue is empty, ``False`` otherwise.
6471
+ Remove and return an item from the queue.
6473
+ .. method:: put(item)
6475
+ Put *item* into the queue.
6478
.. class:: JoinableQueue([maxsize])
6480
:class:`JoinableQueue`, a :class:`Queue` subclass, is a queue which
6482
(By default :data:`sys.executable` is used). Embedders will probably need to
6483
do some thing like ::
6485
- setExecutable(os.path.join(sys.exec_prefix, 'pythonw.exe'))
6486
+ set_executable(os.path.join(sys.exec_prefix, 'pythonw.exe'))
6488
before they can create child processes. (Windows only)
6491
Connection objects allow the sending and receiving of picklable objects or
6492
strings. They can be thought of as message oriented connected sockets.
6494
-Connection objects usually created using :func:`Pipe` -- see also
6495
+Connection objects are usually created using :func:`Pipe` -- see also
6496
:ref:`multiprocessing-listeners-clients`.
6498
.. class:: Connection
6499
@@ -727,12 +744,13 @@
6502
Return an object sent from the other end of the connection using
6503
- :meth:`send`. Raises :exc:`EOFError` if there is nothing left to receive
6504
+ :meth:`send`. Blocks until there its something to receive. Raises
6505
+ :exc:`EOFError` if there is nothing left to receive
6506
and the other end was closed.
6508
.. method:: fileno()
6510
- Returns the file descriptor or handle used by the connection.
6511
+ Return the file descriptor or handle used by the connection.
6515
@@ -756,12 +774,13 @@
6516
If *offset* is given then data is read from that position in *buffer*. If
6517
*size* is given then that many bytes will be read from buffer. Very large
6518
buffers (approximately 32 MB+, though it depends on the OS) may raise a
6519
- ValueError exception
6520
+ :exc:`ValueError` exception
6522
.. method:: recv_bytes([maxlength])
6524
Return a complete message of byte data sent from the other end of the
6525
- connection as a string. Raises :exc:`EOFError` if there is nothing left
6526
+ connection as a string. Blocks until there is something to receive.
6527
+ Raises :exc:`EOFError` if there is nothing left
6528
to receive and the other end has closed.
6530
If *maxlength* is specified and the message is longer than *maxlength*
6532
.. method:: recv_bytes_into(buffer[, offset])
6534
Read into *buffer* a complete message of byte data sent from the other end
6535
- of the connection and return the number of bytes in the message. Raises
6536
+ of the connection and return the number of bytes in the message. Blocks
6537
+ until there is something to receive. Raises
6538
:exc:`EOFError` if there is nothing left to receive and the other end was
6541
@@ -873,14 +893,6 @@
6545
- The :meth:`acquire` method of :class:`BoundedSemaphore`, :class:`Lock`,
6546
- :class:`RLock` and :class:`Semaphore` has a timeout parameter not supported
6547
- by the equivalents in :mod:`threading`. The signature is
6548
- ``acquire(block=True, timeout=None)`` with keyword parameters being
6549
- acceptable. If *block* is ``True`` and *timeout* is not ``None`` then it
6550
- specifies a timeout in seconds. If *block* is ``False`` then *timeout* is
6553
On Mac OS X, ``sem_timedwait`` is unsupported, so calling ``acquire()`` with
6554
a timeout will emulate that function's behavior using a sleeping loop.
6556
@@ -1329,7 +1341,7 @@
6559
To create one's own manager, one creates a subclass of :class:`BaseManager` and
6560
-use the :meth:`~BaseManager.register` classmethod to register new types or
6561
+uses the :meth:`~BaseManager.register` classmethod to register new types or
6562
callables with the manager class. For example::
6564
from multiprocessing.managers import BaseManager
6565
@@ -1494,7 +1506,7 @@
6566
a new shared object -- see documentation for the *method_to_typeid*
6567
argument of :meth:`BaseManager.register`.
6569
- If an exception is raised by the call, then then is re-raised by
6570
+ If an exception is raised by the call, then is re-raised by
6571
:meth:`_callmethod`. If some other exception is raised in the manager's
6572
process then this is converted into a :exc:`RemoteError` exception and is
6573
raised by :meth:`_callmethod`.
6574
@@ -1580,9 +1592,9 @@
6575
.. method:: apply(func[, args[, kwds]])
6577
Call *func* with arguments *args* and keyword arguments *kwds*. It blocks
6578
- till the result is ready. Given this blocks, :meth:`apply_async` is better
6579
- suited for performing work in parallel. Additionally, the passed in
6580
- function is only executed in one of the workers of the pool.
6581
+ until the result is ready. Given this blocks, :meth:`apply_async` is
6582
+ better suited for performing work in parallel. Additionally, *func*
6583
+ is only executed in one of the workers of the pool.
6585
.. method:: apply_async(func[, args[, kwds[, callback[, error_callback]]]])
6587
@@ -1603,7 +1615,7 @@
6588
.. method:: map(func, iterable[, chunksize])
6590
A parallel equivalent of the :func:`map` built-in function (it supports only
6591
- one *iterable* argument though). It blocks till the result is ready.
6592
+ one *iterable* argument though). It blocks until the result is ready.
6594
This method chops the iterable into a number of chunks which it submits to
6595
the process pool as separate tasks. The (approximate) size of these
6596
@@ -1631,7 +1643,7 @@
6598
The *chunksize* argument is the same as the one used by the :meth:`.map`
6599
method. For very long iterables using a large value for *chunksize* can
6600
- make make the job complete **much** faster than using the default value of
6601
+ make the job complete **much** faster than using the default value of
6604
Also if *chunksize* is ``1`` then the :meth:`!next` method of the iterator
6605
@@ -2060,7 +2072,7 @@
6606
On Windows many types from :mod:`multiprocessing` need to be picklable so
6607
that child processes can use them. However, one should generally avoid
6608
sending shared objects to other processes using pipes or queues. Instead
6609
- you should arrange the program so that a process which need access to a
6610
+ you should arrange the program so that a process which needs access to a
6611
shared resource created elsewhere can inherit it from an ancestor process.
6613
Avoid terminating processes
6614
@@ -2139,7 +2151,7 @@
6616
Process(target=f, args=(lock,)).start()
6618
-Beware replacing sys.stdin with a "file like object"
6619
+Beware of replacing :data:`sys.stdin` with a "file like object"
6621
:mod:`multiprocessing` originally unconditionally called::
6623
@@ -2257,7 +2269,7 @@
6626
An example showing how to use queues to feed tasks to a collection of worker
6627
-process and collect the results:
6628
+processes and collect the results:
6630
.. literalinclude:: ../includes/mp_workers.py
6632
diff -r 137e45f15c0b Doc/library/operator.rst
634
diff -r 7085403daf43 Doc/library/markup.rst
635
--- a/Doc/library/markup.rst
636
+++ b/Doc/library/markup.rst
642
+ xml.etree.elementtree.rst
650
- xml.etree.elementtree.rst
652
diff -r 7085403daf43 Doc/library/operator.rst
6633
653
--- a/Doc/library/operator.rst
6634
654
+++ b/Doc/library/operator.rst
6636
from operator import itemgetter, iadd
6639
-The :mod:`operator` module exports a set of functions implemented in C
6640
-corresponding to the intrinsic operators of Python. For example,
6641
-``operator.add(x, y)`` is equivalent to the expression ``x+y``. The function
6642
-names are those used for special class methods; variants without leading and
6643
-trailing ``__`` are also provided for convenience.
6644
+The :mod:`operator` module exports a set of efficient functions corresponding to
6645
+the intrinsic operators of Python. For example, ``operator.add(x, y)`` is
6646
+equivalent to the expression ``x+y``. The function names are those used for
6647
+special class methods; variants without leading and trailing ``__`` are also
6648
+provided for convenience.
6650
The functions fall into categories that perform object comparisons, logical
6651
operations, mathematical operations and sequence operations.
6653
+-----------------------+-------------------------+---------------------------------------+
6654
| Right Shift | ``a >> b`` | ``rshift(a, b)`` |
6655
+-----------------------+-------------------------+---------------------------------------+
6656
-| Sequence Repetition | ``seq * i`` | ``repeat(seq, i)`` |
6657
-+-----------------------+-------------------------+---------------------------------------+
6658
| Slice Assignment | ``seq[i:j] = values`` | ``setitem(seq, slice(i, j), values)`` |
6659
+-----------------------+-------------------------+---------------------------------------+
6660
| Slice Deletion | ``del seq[i:j]`` | ``delitem(seq, slice(i, j))`` |
6661
diff -r 137e45f15c0b Doc/library/optparse.rst
6662
--- a/Doc/library/optparse.rst
6663
+++ b/Doc/library/optparse.rst
6665
.. moduleauthor:: Greg Ward <gward@python.net>
6666
.. sectionauthor:: Greg Ward <gward@python.net>
6668
-**Source code:** :source:`Lib/optparse.py`
6672
-.. deprecated:: 2.7
6673
+.. deprecated:: 3.2
6674
The :mod:`optparse` module is deprecated and will not be developed further;
6675
development will continue with the :mod:`argparse` module.
6677
+**Source code:** :source:`Lib/optparse.py`
6681
:mod:`optparse` is a more convenient, flexible, and powerful library for parsing
6682
command-line options than the old :mod:`getopt` module. :mod:`optparse` uses a
6683
more declarative style of command-line parsing: you create an instance of
6688
-A bit more complete example might invole using more than one group: still
6689
-extendind the previous example::
6690
+A bit more complete example might involve using more than one group: still
6691
+extending the previous example::
6693
group = OptionGroup(parser, "Dangerous Options",
6694
"Caution: use these options at your own risk. "
6695
diff -r 137e45f15c0b Doc/library/os.rst
6696
--- a/Doc/library/os.rst
6697
+++ b/Doc/library/os.rst
6699
objects, and result in an object of the same type, if a path or file name is
6704
- If not separately noted, all functions that claim "Availability: Unix" are
6705
- supported on Mac OS X, which builds on a Unix core.
6707
* An "Availability: Unix" note means that this function is commonly found on
6708
Unix systems. It does not make any claims about its existence on a specific
6711
by *how*: :const:`SEEK_SET` or ``0`` to set the position relative to the
6712
beginning of the file; :const:`SEEK_CUR` or ``1`` to set it relative to the
6713
current position; :const:`os.SEEK_END` or ``2`` to set it relative to the end of
6715
+ the file. Return the new cursor position in bytes, starting from the beginning.
6717
Availability: Unix, Windows.
6722
except IOError as e:
6723
- if e.errno == errno.EACCESS:
6724
+ if e.errno == errno.EACCES:
6725
return "some default data"
6726
# Not a permission error.
6728
@@ -1434,11 +1429,9 @@
6729
*target_is_directory*, which defaults to ``False``.
6731
On Windows, a symlink represents a file or a directory, and does not morph to
6732
- the target dynamically. For this reason, when creating a symlink on Windows,
6733
- if the target is not already present, the symlink will default to being a
6734
- file symlink. If *target_is_directory* is set to ``True``, the symlink will
6735
- be created as a directory symlink. This parameter is ignored if the target
6736
- exists (and the symlink is created with the same type as the target).
6737
+ the target dynamically. If *target_is_directory* is set to ``True``, the
6738
+ symlink will be created as a directory symlink, otherwise as a file symlink
6741
Symbolic link support was introduced in Windows 6.0 (Vista). :func:`symlink`
6742
will raise a :exc:`NotImplementedError` on Windows versions earlier than 6.0.
6743
@@ -1451,7 +1444,6 @@
6744
administrator level. Either obtaining the privilege or running your
6745
application as an administrator are ways to successfully create symlinks.
6748
:exc:`OSError` is raised when the function is called by an unprivileged
6751
@@ -1519,7 +1511,7 @@
6752
ineffective, because in bottom-up mode the directories in *dirnames* are
6753
generated before *dirpath* itself is generated.
6755
- By default errors from the :func:`listdir` call are ignored. If optional
6756
+ By default, errors from the :func:`listdir` call are ignored. If optional
6757
argument *onerror* is specified, it should be a function; it will be called with
6758
one argument, an :exc:`OSError` instance. It can report the error to continue
6759
with the walk, or raise the exception to abort the walk. Note that the filename
6760
diff -r 137e45f15c0b Doc/library/othergui.rst
6761
--- a/Doc/library/othergui.rst
6762
+++ b/Doc/library/othergui.rst
6764
Other Graphical User Interface Packages
6765
=======================================
6767
-There are an number of extension widget sets to :mod:`tkinter`.
6768
+Major cross-platform (Windows, Mac OS X, Unix-like) GUI toolkits are
6769
+available for Python:
6773
- `Python megawidgets <http://pmw.sourceforge.net/>`_
6774
- is a toolkit for building high-level compound widgets in Python using the
6775
- :mod:`tkinter` package. It consists of a set of base classes and a library of
6776
- flexible and extensible megawidgets built on this foundation. These megawidgets
6777
- include notebooks, comboboxes, selection widgets, paned widgets, scrolled
6778
- widgets, dialog windows, etc. Also, with the Pmw.Blt interface to BLT, the
6779
- busy, graph, stripchart, tabset and vector commands are be available.
6780
+ `PyGObject <https://live.gnome.org/PyGObject>`_
6781
+ provides introspection bindings for C libraries using
6782
+ `GObject <http://developer.gnome.org/gobject/stable/>`_. One of
6783
+ these libraries is the `GTK+ 3 <http://www.gtk.org/>`_ widget set.
6784
+ GTK+ comes with many more widgets than Tkinter provides. An online
6785
+ `Python GTK+ 3 Tutorial <http://python-gtk-3-tutorial.readthedocs.org/en/latest/>`_
6788
- The initial ideas for Pmw were taken from the Tk ``itcl`` extensions ``[incr
6789
- Tk]`` by Michael McLennan and ``[incr Widgets]`` by Mark Ulferts. Several of the
6790
- megawidgets are direct translations from the itcl to Python. It offers most of
6791
- the range of widgets that ``[incr Widgets]`` does, and is almost as complete as
6792
- Tix, lacking however Tix's fast :class:`HList` widget for drawing trees.
6794
- `Tkinter3000 Widget Construction Kit (WCK) <http://tkinter.effbot.org/>`_
6795
- is a library that allows you to write new Tkinter widgets in pure Python. The
6796
- WCK framework gives you full control over widget creation, configuration, screen
6797
- appearance, and event handling. WCK widgets can be very fast and light-weight,
6798
- since they can operate directly on Python data structures, without having to
6799
- transfer data through the Tk/Tcl layer.
6802
-The major cross-platform (Windows, Mac OS X, Unix-like) GUI toolkits that are
6803
-also available for Python:
6807
- `PyGTK <http://www.pygtk.org/>`_
6808
- is a set of bindings for the `GTK <http://www.gtk.org/>`_ widget set. It
6809
- provides an object oriented interface that is slightly higher level than
6810
- the C one. It comes with many more widgets than Tkinter provides, and has
6811
- good Python-specific reference documentation. There are also bindings to
6812
+ `PyGTK <http://www.pygtk.org/>`_ provides bindings for an older version
6813
+ of the library, GTK+ 2. It provides an object oriented interface that
6814
+ is slightly higher level than the C one. There are also bindings to
6815
`GNOME <http://www.gnome.org>`_. One well known PyGTK application is
6816
`PythonCAD <http://www.pythoncad.org/>`_. An online `tutorial
6817
<http://www.pygtk.org/pygtk2tutorial/index.html>`_ is available.
6819
with Python and Qt <http://www.qtrac.eu/pyqtbook.html>`_, by Mark
6822
+ `PySide <http://www.pyside.org/>`_
6823
+ is a newer binding to the Qt toolkit, provided by Nokia.
6824
+ Compared to PyQt, its licensing scheme is friendlier to non-open source
6827
`wxPython <http://www.wxpython.org>`_
6828
wxPython is a cross-platform GUI toolkit for Python that is built around
6829
the popular `wxWidgets <http://www.wxwidgets.org/>`_ (formerly wxWindows)
6830
diff -r 137e45f15c0b Doc/library/pickle.rst
6831
--- a/Doc/library/pickle.rst
6832
+++ b/Doc/library/pickle.rst
6835
.. exception:: UnpicklingError
6837
- Error raised when there a problem unpickling an object, such as a data
6838
+ Error raised when there is a problem unpickling an object, such as a data
6839
corruption or a security violation. It inherits :exc:`PickleError`.
6841
Note that other exceptions may also be raised during unpickling, including
6842
@@ -324,11 +324,11 @@
6844
.. method:: persistent_load(pid)
6846
- Raise an :exc:`UnpickingError` by default.
6847
+ Raise an :exc:`UnpicklingError` by default.
6849
If defined, :meth:`persistent_load` should return the object specified by
6850
the persistent ID *pid*. If an invalid persistent ID is encountered, an
6851
- :exc:`UnpickingError` should be raised.
6852
+ :exc:`UnpicklingError` should be raised.
6854
See :ref:`pickle-persistent` for details and examples of uses.
6858
Note that functions (built-in and user-defined) are pickled by "fully qualified"
6859
name reference, not by value. This means that only the function name is
6860
-pickled, along with the name of module the function is defined in. Neither the
6861
+pickled, along with the name of the module the function is defined in. Neither the
6862
function's code, nor any of its function attributes are pickled. Thus the
6863
defining module must be importable in the unpickling environment, and the module
6864
must contain the named object, otherwise an exception will be raised. [#]_
6866
For this reason, you may want to control what gets unpickled by customizing
6867
:meth:`Unpickler.find_class`. Unlike its name suggests, :meth:`find_class` is
6868
called whenever a global (i.e., a class or a function) is requested. Thus it is
6869
-possible to either forbid completely globals or restrict them to a safe subset.
6870
+possible to either completely forbid globals or restrict them to a safe subset.
6872
Here is an example of an unpickler allowing only few safe classes from the
6873
:mod:`builtins` module to be loaded::
6874
diff -r 137e45f15c0b Doc/library/platform.rst
6875
--- a/Doc/library/platform.rst
6876
+++ b/Doc/library/platform.rst
6878
.. function:: win32_ver(release='', version='', csd='', ptype='')
6880
Get additional version information from the Windows Registry and return a tuple
6881
- ``(version, csd, ptype)`` referring to version number, CSD level and OS type
6882
- (multi/single processor).
6883
+ ``(version, csd, ptype)`` referring to version number, CSD level
6884
+ (service pack) and OS type (multi/single processor).
6886
As a hint: *ptype* is ``'Uniprocessor Free'`` on single processor NT machines
6887
and ``'Multiprocessor Free'`` on multi processor machines. The *'Free'* refers
6888
diff -r 137e45f15c0b Doc/library/random.rst
6889
--- a/Doc/library/random.rst
6890
+++ b/Doc/library/random.rst
6892
The end-point value ``b`` may or may not be included in the range
6893
depending on floating-point rounding in the equation ``a + (b-a) * random()``.
6896
.. function:: triangular(low, high, mode)
6898
Return a random floating point number *N* such that ``low <= N <= high`` and
6899
@@ -191,6 +192,12 @@
6900
Gamma distribution. (*Not* the gamma function!) Conditions on the
6901
parameters are ``alpha > 0`` and ``beta > 0``.
6903
+ The probability distribution function is::
6905
+ x ** (alpha - 1) * math.exp(-x / beta)
6906
+ pdf(x) = --------------------------------------
6907
+ math.gamma(alpha) * beta ** alpha
6910
.. function:: gauss(mu, sigma)
6912
diff -r 137e45f15c0b Doc/library/re.rst
656
+-----------------------+-------------------------+---------------------------------------+
657
| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
658
+-----------------------+-------------------------+---------------------------------------+
659
-| Division | ``a / b`` | ``div(a, b)`` |
660
+| Division | ``a / b`` | ``truediv(a, b)`` |
661
+-----------------------+-------------------------+---------------------------------------+
662
| Division | ``a // b`` | ``floordiv(a, b)`` |
663
+-----------------------+-------------------------+---------------------------------------+
664
diff -r 7085403daf43 Doc/library/re.rst
6913
665
--- a/Doc/library/re.rst
6914
666
+++ b/Doc/library/re.rst
6916
characters either stand for classes of ordinary characters, or affect
6917
how the regular expressions around them are interpreted. Regular
6918
expression pattern strings may not contain null bytes, but can specify
6919
-the null byte using the ``\number`` notation, e.g., ``'\x00'``.
6920
+the null byte using a ``\number`` notation such as ``'\x00'``.
6923
The special characters are:
6924
@@ -161,30 +161,36 @@
6925
raw strings for all but the simplest expressions.
6928
- Used to indicate a set of characters. Characters can be listed individually, or
6929
- a range of characters can be indicated by giving two characters and separating
6930
- them by a ``'-'``. Special characters are not active inside sets. For example,
6931
- ``[akm$]`` will match any of the characters ``'a'``, ``'k'``,
6932
- ``'m'``, or ``'$'``; ``[a-z]`` will match any lowercase letter, and
6933
- ``[a-zA-Z0-9]`` matches any letter or digit. Character classes such
6934
- as ``\w`` or ``\S`` (defined below) are also acceptable inside a
6935
- range, although the characters they match depends on whether
6936
- :const:`ASCII` or :const:`LOCALE` mode is in force. If you want to
6937
- include a ``']'`` or a ``'-'`` inside a set, precede it with a
6938
- backslash, or place it as the first character. The pattern ``[]]``
6939
- will match ``']'``, for example.
6940
+ Used to indicate a set of characters. In a set:
6942
- You can match the characters not within a range by :dfn:`complementing` the set.
6943
- This is indicated by including a ``'^'`` as the first character of the set;
6944
- ``'^'`` elsewhere will simply match the ``'^'`` character. For example,
6945
- ``[^5]`` will match any character except ``'5'``, and ``[^^]`` will match any
6946
- character except ``'^'``.
6947
+ * Characters can be listed individually, e.g. ``[amk]`` will match ``'a'``,
6948
+ ``'m'``, or ``'k'``.
6950
- Note that inside ``[]`` the special forms and special characters lose
6951
- their meanings and only the syntaxes described here are valid. For
6952
- example, ``+``, ``*``, ``(``, ``)``, and so on are treated as
6953
- literals inside ``[]``, and backreferences cannot be used inside
6955
+ * Ranges of characters can be indicated by giving two characters and separating
6956
+ them by a ``'-'``, for example ``[a-z]`` will match any lowercase ASCII letter,
6957
+ ``[0-5][0-9]`` will match all the two-digits numbers from ``00`` to ``59``, and
6958
+ ``[0-9A-Fa-f]`` will match any hexadecimal digit. If ``-`` is escaped (e.g.
6959
+ ``[a\-z]``) or if it's placed as the first or last character (e.g. ``[a-]``),
6960
+ it will match a literal ``'-'``.
6962
+ * Special characters lose their special meaning inside sets. For example,
6963
+ ``[(+*)]`` will match any of the literal characters ``'('``, ``'+'``,
6964
+ ``'*'``, or ``')'``.
6966
+ * Character classes such as ``\w`` or ``\S`` (defined below) are also accepted
6967
+ inside a set, although the characters they match depends on whether
6968
+ :const:`ASCII` or :const:`LOCALE` mode is in force.
6970
+ * Characters that are not within a range can be matched by :dfn:`complementing`
6971
+ the set. If the first character of the set is ``'^'``, all the characters
6972
+ that are *not* in the set will be matched. For example, ``[^5]`` will match
6973
+ any character except ``'5'``, and ``[^^]`` will match any character except
6974
+ ``'^'``. ``^`` has no special meaning if it's not the first character in
6977
+ * To match a literal ``']'`` inside a set, precede it with a backslash, or
6978
+ place it at the beginning of the set. For example, both ``[()[\]{}]`` and
6979
+ ``[]()[{}]`` will both match a parenthesis.
6982
``A|B``, where A and B can be arbitrary REs, creates a regular expression that
6987
-Octal escapes are included in a limited form: If the first digit is a 0, or if
6988
+Octal escapes are included in a limited form. If the first digit is a 0, or if
6989
there are three octal digits, it is considered an octal escape. Otherwise, it is
6990
a group reference. As for string literals, octal escapes are always at most
667
@@ -330,16 +330,22 @@
668
Matches the empty string, but only at the beginning or end of a word.
669
A word is defined as a sequence of Unicode alphanumeric or underscore
670
characters, so the end of a word is indicated by whitespace or a
671
- non-alphanumeric, non-underscore Unicode character. Note that
672
- formally, ``\b`` is defined as the boundary between a ``\w`` and a
673
- ``\W`` character (or vice versa). By default Unicode alphanumerics
674
- are the ones used, but this can be changed by using the :const:`ASCII`
675
- flag. Inside a character range, ``\b`` represents the backspace
676
- character, for compatibility with Python's string literals.
677
+ non-alphanumeric, non-underscore Unicode character. Note that formally,
678
+ ``\b`` is defined as the boundary between a ``\w`` and a ``\W`` character
679
+ (or vice versa), or between ``\w`` and the beginning/end of the string.
680
+ This means that ``r'\bfoo\b'`` matches ``'foo'``, ``'foo.'``, ``'(foo)'``,
681
+ ``'bar foo baz'`` but not ``'foobar'`` or ``'foo3'``.
683
+ By default Unicode alphanumerics are the ones used, but this can be changed
684
+ by using the :const:`ASCII` flag. Inside a character range, ``\b``
685
+ represents the backspace character, for compatibility with Python's string
689
- Matches the empty string, but only when it is *not* at the beginning or end of a
690
- word. This is just the opposite of ``\b``, so word characters are
691
+ Matches the empty string, but only when it is *not* at the beginning or end
692
+ of a word. This means that ``r'py\B'`` matches ``'python'``, ``'py3'``,
693
+ ``'py2'``, but not ``'py'``, ``'py.'``, or ``'py!'``.
694
+ ``\B`` is just the opposite of ``\b``, so word characters are
695
Unicode alphanumerics or the underscore, although this can be changed
696
by using the :const:`ASCII` flag.
6991
699
three digits in length.
6994
.. _matching-searching:
6996
-Matching vs Searching
6997
----------------------
6998
+Matching vs. Searching
6999
+----------------------
7001
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
7003
@@ -492,6 +498,11 @@
7004
isn't allowed for bytes).
7009
+ Display debug information about compiled expression.
7016
['', '...', 'words', ', ', 'words', '...', '']
7018
That way, separator components are always found at the same relative
7019
- indices within the result list (e.g., if there's one capturing group
7020
- in the separator, the 0th, the 2nd and so forth).
7021
+ indices within the result list.
7023
Note that *split* will never split a string on an empty pattern match.
7026
--------------------------
7028
Compiled regular expression objects support the following methods and
7032
.. method:: regex.search(string[, pos[, endpos]])
7035
The optional parameter *endpos* limits how far the string will be searched; it
7036
will be as if the string is *endpos* characters long, so only the characters
7037
from *pos* to ``endpos - 1`` will be searched for a match. If *endpos* is less
7038
- than *pos*, no match will be found, otherwise, if *rx* is a compiled regular
7039
+ than *pos*, no match will be found; otherwise, if *rx* is a compiled regular
7040
expression object, ``rx.search(string, 0, 50)`` is equivalent to
7041
``rx.search(string[:50], 0)``.
7047
-Match objects always have a boolean value of :const:`True`, so that you can test
7048
-whether e.g. :func:`match` resulted in a match with a simple if statement. They
7049
+Match objects always have a boolean value of :const:`True`. This lets you
7050
+use a simple if-statement to test whether a match was found. Match objects
7051
support the following methods and attributes:
7054
@@ -998,7 +1008,7 @@
7055
---------------------------
7058
-Checking For a Pair
7059
+Checking for a Pair
7062
In this example, we'll use the following helper function to display match
7063
@@ -1013,16 +1023,16 @@
7065
Suppose you are writing a poker program where a player's hand is represented as
7066
a 5-character string with each character representing a card, "a" for ace, "k"
7067
-for king, "q" for queen, j for jack, "0" for 10, and "1" through "9"
7068
+for king, "q" for queen, "j" for jack, "t" for 10, and "2" through "9"
7069
representing the card with that value.
7071
To see if a given string is a valid hand, one could do the following:
7073
- >>> valid = re.compile(r"[0-9akqj]{5}$")
7074
- >>> displaymatch(valid.match("ak05q")) # Valid.
7075
- "<Match: 'ak05q', groups=()>"
7076
- >>> displaymatch(valid.match("ak05e")) # Invalid.
7077
- >>> displaymatch(valid.match("ak0")) # Invalid.
7078
+ >>> valid = re.compile(r"^[a2-9tjqk]{5}$")
7079
+ >>> displaymatch(valid.match("akt5q")) # Valid.
7080
+ "<Match: 'akt5q', groups=()>"
7081
+ >>> displaymatch(valid.match("akt5e")) # Invalid.
7082
+ >>> displaymatch(valid.match("akt")) # Invalid.
7083
>>> displaymatch(valid.match("727ak")) # Valid.
7084
"<Match: '727ak', groups=()>"
7086
@@ -1106,7 +1116,7 @@
7088
If you create regular expressions that require the engine to perform a lot of
7089
recursion, you may encounter a :exc:`RuntimeError` exception with the message
7090
-``maximum recursion limit`` exceeded. For example, ::
7091
+``maximum recursion limit exceeded``. For example, ::
7093
>>> s = 'Begin ' + 1000*'a very long string ' + 'end'
7094
>>> re.match('Begin (\w| )*? end', s).end()
7095
diff -r 137e45f15c0b Doc/library/sched.rst
7096
--- a/Doc/library/sched.rst
7097
+++ b/Doc/library/sched.rst
7100
.. method:: scheduler.enter(delay, priority, action, argument)
7102
- Schedule an event for *delay* more time units. Other then the relative time, the
7103
+ Schedule an event for *delay* more time units. Other than the relative time, the
7104
other arguments, the effect and the return value are the same as those for
7107
diff -r 137e45f15c0b Doc/library/shutil.rst
7108
--- a/Doc/library/shutil.rst
7109
+++ b/Doc/library/shutil.rst
7114
- Even the higher-level file copying functions (:func:`copy`, :func:`copy2`)
7115
- cannot copy all file metadata.
7116
+ Even the higher-level file copying functions (:func:`shutil.copy`,
7117
+ :func:`shutil.copy2`) cannot copy all file metadata.
7119
On POSIX platforms, this means that file owner and group are lost as well
7120
as ACLs. On Mac OS, the resource fork and other metadata are not used.
7125
+.. _file-operations:
7127
Directory and files operations
7128
------------------------------
7132
.. function:: copyfile(src, dst)
7134
- Copy the contents (no metadata) of the file named *src* to a file named *dst*.
7135
- *dst* must be the complete target file name; look at :func:`copy` for a copy that
7136
- accepts a target directory path. If *src* and *dst* are the same files,
7137
- :exc:`Error` is raised.
7138
+ Copy the contents (no metadata) of the file named *src* to a file named
7139
+ *dst*. *dst* must be the complete target file name; look at
7140
+ :func:`shutil.copy` for a copy that accepts a target directory path. If
7141
+ *src* and *dst* are the same files, :exc:`Error` is raised.
7142
The destination location must be writable; otherwise, an :exc:`IOError` exception
7143
will be raised. If *dst* already exists, it will be replaced. Special files
7144
such as character or block devices and pipes cannot be copied with this
7147
.. function:: copy2(src, dst)
7149
- Similar to :func:`copy`, but metadata is copied as well -- in fact, this is just
7150
- :func:`copy` followed by :func:`copystat`. This is similar to the
7151
- Unix command :program:`cp -p`.
7152
+ Similar to :func:`shutil.copy`, but metadata is copied as well -- in fact,
7153
+ this is just :func:`shutil.copy` followed by :func:`copystat`. This is
7154
+ similar to the Unix command :program:`cp -p`.
7157
.. function:: ignore_patterns(\*patterns)
7159
.. function:: copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, ignore_dangling_symlinks=False)
7161
Recursively copy an entire directory tree rooted at *src*. The destination
7162
- directory, named by *dst*, must not already exist; it will be created as well
7163
- as missing parent directories. Permissions and times of directories are
7164
- copied with :func:`copystat`, individual files are copied using
7166
+ directory, named by *dst*, must not already exist; it will be created as
7167
+ well as missing parent directories. Permissions and times of directories
7168
+ are copied with :func:`copystat`, individual files are copied using
7169
+ :func:`shutil.copy2`.
7171
If *symlinks* is true, symbolic links in the source tree are represented as
7172
symbolic links in the new tree, but the metadata of the original links is NOT
7173
@@ -124,10 +126,10 @@
7175
If exception(s) occur, an :exc:`Error` is raised with a list of reasons.
7177
- If *copy_function* is given, it must be a callable that will be used
7178
- to copy each file. It will be called with the source path and the
7179
- destination path as arguments. By default, :func:`copy2` is used, but any
7180
- function that supports the same signature (like :func:`copy`) can be used.
7181
+ If *copy_function* is given, it must be a callable that will be used to copy
7182
+ each file. It will be called with the source path and the destination path
7183
+ as arguments. By default, :func:`shutil.copy2` is used, but any function
7184
+ that supports the same signature (like :func:`copy`) can be used.
7186
.. versionchanged:: 3.2
7187
Added the *copy_function* argument to be able to provide a custom copy
7189
:func:`os.rename` semantics.
7191
If the destination is on the current filesystem, then :func:`os.rename` is
7192
- used. Otherwise, *src* is copied (using :func:`copy2`) to *dst* and then
7194
+ used. Otherwise, *src* is copied (using :func:`shutil.copy2`) to *dst* and
7198
.. exception:: Error
7200
(*srcname*, *dstname*, *exception*).
7203
-.. _shutil-example:
7204
+.. _shutil-copytree-example:
7209
Archiving operations
7210
--------------------
7212
+High-level utilities to create and read compressed and archived files are also
7213
+provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
7215
.. function:: make_archive(base_name, format, [root_dir, [base_dir, [verbose, [dry_run, [owner, [group, [logger]]]]]]])
7217
Create an archive file (such as zip or tar) and return its name.
7219
*owner* and *group* are used when creating a tar archive. By default,
7220
uses the current owner and group.
7222
- *logger* is an instance of :class:`logging.Logger`.
7223
+ *logger* must be an object compatible with :pep:`282`, usually an instance of
7224
+ :class:`logging.Logger`.
7226
.. versionadded:: 3.2
7229
.. versionadded:: 3.2
7232
+.. _shutil-archiving-example:
7237
-rw------- tarek/staff 1675 2008-06-09 13:26:54 ./id_rsa
7238
-rw-r--r-- tarek/staff 397 2008-06-09 13:26:54 ./id_rsa.pub
7239
-rw-r--r-- tarek/staff 37192 2010-02-06 18:23:10 ./known_hosts
7242
diff -r 137e45f15c0b Doc/library/smtplib.rst
7243
--- a/Doc/library/smtplib.rst
7244
+++ b/Doc/library/smtplib.rst
7245
@@ -281,10 +281,10 @@
7246
envelope used by the transport agents. ``sendmail`` does not modify the
7247
message headers in any way.
7249
- msg may be a string containing characters in the ASCII range, or a byte
7250
+ *msg* may be a string containing characters in the ASCII range, or a byte
7251
string. A string is encoded to bytes using the ascii codec, and lone ``\r``
7252
- and ``\n`` characters are converted to ``\r\n`` characters. A byte string
7254
+ and ``\n`` characters are converted to ``\r\n`` characters. A byte string is
7257
If there has been no previous ``EHLO`` or ``HELO`` command this session, this
7258
method tries ESMTP ``EHLO`` first. If the server does ESMTP, message size and
7259
diff -r 137e45f15c0b Doc/library/socket.rst
7260
--- a/Doc/library/socket.rst
7261
+++ b/Doc/library/socket.rst
7263
tuple, and the fields depend on the address type. The general tuple form is
7264
``(addr_type, v1, v2, v3 [, scope])``, where:
7266
- - *addr_type* is one of TIPC_ADDR_NAMESEQ, TIPC_ADDR_NAME, or
7268
- - *scope* is one of TIPC_ZONE_SCOPE, TIPC_CLUSTER_SCOPE, and
7270
- - If *addr_type* is TIPC_ADDR_NAME, then *v1* is the server type, *v2* is
7271
+ - *addr_type* is one of :const:`TIPC_ADDR_NAMESEQ`, :const:`TIPC_ADDR_NAME`,
7272
+ or :const:`TIPC_ADDR_ID`.
7273
+ - *scope* is one of :const:`TIPC_ZONE_SCOPE`, :const:`TIPC_CLUSTER_SCOPE`, and
7274
+ :const:`TIPC_NODE_SCOPE`.
7275
+ - If *addr_type* is :const:`TIPC_ADDR_NAME`, then *v1* is the server type, *v2* is
7276
the port identifier, and *v3* should be 0.
7278
- If *addr_type* is TIPC_ADDR_NAMESEQ, then *v1* is the server type, *v2*
7279
+ If *addr_type* is :const:`TIPC_ADDR_NAMESEQ`, then *v1* is the server type, *v2*
7280
is the lower port number, and *v3* is the upper port number.
7282
- If *addr_type* is TIPC_ADDR_ID, then *v1* is the node, *v2* is the
7283
+ If *addr_type* is :const:`TIPC_ADDR_ID`, then *v1* is the node, *v2* is the
7284
reference, and *v3* should be set to 0.
7286
- If *addr_type* is TIPC_ADDR_ID, then *v1* is the node, *v2* is the
7287
+ If *addr_type* is :const:`TIPC_ADDR_ID`, then *v1* is the node, *v2* is the
7288
reference, and *v3* should be set to 0.
7290
- Certain other address families (:const:`AF_BLUETOOTH`, :const:`AF_PACKET`)
7291
@@ -236,10 +236,17 @@
7293
.. function:: create_connection(address[, timeout[, source_address]])
7295
- Convenience function. Connect to *address* (a 2-tuple ``(host, port)``),
7296
- and return the socket object. Passing the optional *timeout* parameter will
7297
- set the timeout on the socket instance before attempting to connect. If no
7298
- *timeout* is supplied, the global default timeout setting returned by
7299
+ Connect to a TCP service listening on the Internet *address* (a 2-tuple
7300
+ ``(host, port)``), and return the socket object. This is a higher-level
7301
+ function than :meth:`socket.connect`: if *host* is a non-numeric hostname,
7302
+ it will try to resolve it for both :data:`AF_INET` and :data:`AF_INET6`,
7303
+ and then try to connect to all possible addresses in turn until a
7304
+ connection succeeds. This makes it easy to write clients that are
7305
+ compatible to both IPv4 and IPv6.
7307
+ Passing the optional *timeout* parameter will set the timeout on the
7308
+ socket instance before attempting to connect. If no *timeout* is
7309
+ supplied, the global default timeout setting returned by
7310
:func:`getdefaulttimeout` is used.
7312
If supplied, *source_address* must be a 2-tuple ``(host, port)`` for the
7314
optional *flags* argument has the same meaning as for :meth:`recv` above.
7315
Returns the number of bytes sent. Applications are responsible for checking that
7316
all data has been sent; if only some of the data was transmitted, the
7317
- application needs to attempt delivery of the remaining data.
7318
+ application needs to attempt delivery of the remaining data. For further
7319
+ information on this topic, consult the :ref:`socket-howto`.
7322
.. method:: socket.sendall(bytes[, flags])
7324
:meth:`~socket.bind`, :meth:`~socket.listen`, :meth:`~socket.accept` (possibly
7325
repeating the :meth:`~socket.accept` to service more than one client), while a
7326
client only needs the sequence :func:`socket`, :meth:`~socket.connect`. Also
7327
-note that the server does not :meth:`~socket.send`/:meth:`~socket.recv` on the
7328
-socket it is listening on but on the new socket returned by
7329
+note that the server does not :meth:`~socket.sendall`/:meth:`~socket.recv` on
7330
+the socket it is listening on but on the new socket returned by
7331
:meth:`~socket.accept`.
7333
The first two examples support IPv4 only. ::
7336
data = conn.recv(1024)
7339
+ conn.sendall(data)
7344
PORT = 50007 # The same port as used by the server
7345
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7346
s.connect((HOST, PORT))
7347
- s.send(b'Hello, world')
7348
+ s.sendall(b'Hello, world')
7351
print('Received', repr(data))
7354
print('could not open socket')
7356
- s.send(b'Hello, world')
7357
+ s.sendall(b'Hello, world')
7360
print('Received', repr(data))
7361
diff -r 137e45f15c0b Doc/library/socketserver.rst
7362
--- a/Doc/library/socketserver.rst
7363
+++ b/Doc/library/socketserver.rst
7366
When inheriting from :class:`ThreadingMixIn` for threaded connection behavior,
7367
you should explicitly declare how you want your threads to behave on an abrupt
7368
-shutdown. The :class:`ThreadingMixIn` class defines an attribute
7369
+shutdown. The :class:`ThreadingMixIn` class defines an attribute
7370
*daemon_threads*, which indicates whether or not the server should wait for
7371
-thread termination. You should set the flag explicitly if you would like threads
7372
-to behave autonomously; the default is :const:`False`, meaning that Python will
7373
-not exit until all threads created by :class:`ThreadingMixIn` have exited.
7374
+thread termination. You should set the flag explicitly if you would like
7375
+threads to behave autonomously; the default is :const:`False`, meaning that
7376
+Python will not exit until all threads created by :class:`ThreadingMixIn` have
7379
Server classes have the same external methods and attributes, no matter what
7380
network protocol they use.
7382
finished requests and to use :func:`select` to decide which request to work on
7383
next (or whether to handle a new incoming request). This is particularly
7384
important for stream services where each client can potentially be connected for
7385
-a long time (if threads or subprocesses cannot be used). See :mod:`asyncore` for
7386
-another way to manage this.
7387
+a long time (if threads or subprocesses cannot be used). See :mod:`asyncore`
7388
+for another way to manage this.
7390
.. XXX should data and methods be intermingled, or separate?
7391
how should the distinction between class and instance variables be drawn?
7392
@@ -152,13 +153,14 @@
7394
.. method:: BaseServer.serve_forever(poll_interval=0.5)
7396
- Handle requests until an explicit :meth:`shutdown` request. Polls for
7397
- shutdown every *poll_interval* seconds.
7398
+ Handle requests until an explicit :meth:`shutdown` request.
7399
+ Poll for shutdown every *poll_interval* seconds. Ignores :attr:`self.timeout`.
7400
+ If you need to do periodic tasks, do them in another thread.
7403
.. method:: BaseServer.shutdown()
7405
- Tells the :meth:`serve_forever` loop to stop and waits until it does.
7406
+ Tell the :meth:`serve_forever` loop to stop and wait until it does.
7409
.. attribute:: BaseServer.address_family
7412
.. attribute:: BaseServer.allow_reuse_address
7414
- Whether the server will allow the reuse of an address. This defaults to
7415
+ Whether the server will allow the reuse of an address. This defaults to
7416
:const:`False`, and can be set in subclasses to change the policy.
7420
.. method:: BaseServer.server_activate()
7422
Called by the server's constructor to activate the server. The default behavior
7423
- just :meth:`listen`\ s to the server's socket. May be overridden.
7424
+ just :meth:`listen`\ s to the server's socket. May be overridden.
7427
.. method:: BaseServer.server_bind()
7428
@@ -280,10 +282,10 @@
7430
.. method:: BaseServer.verify_request(request, client_address)
7432
- Must return a Boolean value; if the value is :const:`True`, the request will be
7433
- processed, and if it's :const:`False`, the request will be denied. This function
7434
- can be overridden to implement access controls for a server. The default
7435
- implementation always returns :const:`True`.
7436
+ Must return a Boolean value; if the value is :const:`True`, the request will
7437
+ be processed, and if it's :const:`False`, the request will be denied. This
7438
+ function can be overridden to implement access controls for a server. The
7439
+ default implementation always returns :const:`True`.
7442
RequestHandler Objects
7443
@@ -348,10 +350,10 @@
7445
# self.request is the TCP socket connected to the client
7446
self.data = self.request.recv(1024).strip()
7447
- print("%s wrote:" % self.client_address[0])
7448
+ print("{} wrote:".format(self.client_address[0]))
7450
# just send back the same data, but upper-cased
7451
- self.request.send(self.data.upper())
7452
+ self.request.sendall(self.data.upper())
7454
if __name__ == "__main__":
7455
HOST, PORT = "localhost", 9999
7457
# self.rfile is a file-like object created by the handler;
7458
# we can now use e.g. readline() instead of raw recv() calls
7459
self.data = self.rfile.readline().strip()
7460
- print("%s wrote:" % self.client_address[0])
7461
+ print("{} wrote:".format(self.client_address[0]))
7463
# Likewise, self.wfile is a file-like object used to write back
7466
The difference is that the ``readline()`` call in the second handler will call
7467
``recv()`` multiple times until it encounters a newline character, while the
7468
single ``recv()`` call in the first handler will just return what has been sent
7469
-from the client in one ``send()`` call.
7470
+from the client in one ``sendall()`` call.
7473
This is the client side::
7474
@@ -395,16 +397,18 @@
7475
# Create a socket (SOCK_STREAM means a TCP socket)
7476
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7478
- # Connect to server and send data
7479
- sock.connect((HOST, PORT))
7480
- sock.send(bytes(data + "\n","utf8"))
7482
+ # Connect to server and send data
7483
+ sock.connect((HOST, PORT))
7484
+ sock.sendall(bytes(data + "\n", "utf-8"))
7486
- # Receive data from the server and shut down
7487
- received = sock.recv(1024)
7489
+ # Receive data from the server and shut down
7490
+ received = str(sock.recv(1024), "utf-8")
7494
- print("Sent: %s" % data)
7495
- print("Received: %s" % received)
7496
+ print("Sent: {}".format(data))
7497
+ print("Received: {}".format(received))
7500
The output of the example should look something like this:
7501
@@ -421,10 +425,10 @@
7503
$ python TCPClient.py hello world with TCP
7504
Sent: hello world with TCP
7505
- Received: b'HELLO WORLD WITH TCP'
7506
+ Received: HELLO WORLD WITH TCP
7507
$ python TCPClient.py python is nice
7508
Sent: python is nice
7509
- Received: b'PYTHON IS NICE'
7510
+ Received: PYTHON IS NICE
7513
:class:`socketserver.UDPServer` Example
7516
data = self.request[0].strip()
7517
socket = self.request[1]
7518
- print("%s wrote:" % self.client_address[0])
7519
+ print("{} wrote:".format(self.client_address[0]))
7521
socket.sendto(data.upper(), self.client_address)
7523
@@ -467,11 +471,11 @@
7525
# As you can see, there is no connect() call; UDP has no connections.
7526
# Instead, data is directly sent to the recipient via sendto().
7527
- sock.sendto(bytes(data + "\n","utf8"), (HOST, PORT))
7528
- received = sock.recv(1024)
7529
+ sock.sendto(bytes(data + "\n", "utf-8"), (HOST, PORT))
7530
+ received = str(sock.recv(1024), "utf-8")
7532
- print("Sent: %s" % data)
7533
- print("Received: %s" % received)
7534
+ print("Sent: {}".format(data))
7535
+ print("Received: {}".format(received))
7537
The output of the example should look exactly like for the TCP server example.
7539
@@ -491,10 +495,10 @@
7540
class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
7543
- data = self.request.recv(1024)
7544
+ data = str(self.request.recv(1024), 'ascii')
7545
cur_thread = threading.current_thread()
7546
- response = bytes("%s: %s" % (cur_thread.getName(), data),'ascii')
7547
- self.request.send(response)
7548
+ response = bytes("{}: {}".format(cur_thread.name, data), 'ascii')
7549
+ self.request.sendall(response)
7551
class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
7553
@@ -502,10 +506,12 @@
7554
def client(ip, port, message):
7555
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7556
sock.connect((ip, port))
7557
- sock.send(message)
7558
- response = sock.recv(1024)
7559
- print("Received: %s" % response)
7562
+ sock.sendall(bytes(message, 'ascii'))
7563
+ response = str(sock.recv(1024), 'ascii')
7564
+ print("Received: {}".format(response))
7568
if __name__ == "__main__":
7569
# Port 0 means to select an arbitrary unused port
7570
@@ -518,13 +524,13 @@
7571
# more thread for each request
7572
server_thread = threading.Thread(target=server.serve_forever)
7573
# Exit the server thread when the main thread terminates
7574
- server_thread.setDaemon(True)
7575
+ server_thread.daemon = True
7576
server_thread.start()
7577
print("Server loop running in thread:", server_thread.name)
7579
- client(ip, port, b"Hello World 1")
7580
- client(ip, port, b"Hello World 2")
7581
- client(ip, port, b"Hello World 3")
7582
+ client(ip, port, "Hello World 1")
7583
+ client(ip, port, "Hello World 2")
7584
+ client(ip, port, "Hello World 3")
7590
$ python ThreadedTCPServer.py
7591
Server loop running in thread: Thread-1
7592
- Received: b"Thread-2: b'Hello World 1'"
7593
- Received: b"Thread-3: b'Hello World 2'"
7594
- Received: b"Thread-4: b'Hello World 3'"
7595
+ Received: Thread-2: Hello World 1
7596
+ Received: Thread-3: Hello World 2
7597
+ Received: Thread-4: Hello World 3
7600
The :class:`ForkingMixIn` class is used in the same way, except that the server
7601
diff -r 137e45f15c0b Doc/library/sqlite3.rst
702
-.. _matching-searching:
704
-Matching vs. Searching
705
-----------------------
707
-.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
710
-Python offers two different primitive operations based on regular expressions:
711
-**match** checks for a match only at the beginning of the string, while
712
-**search** checks for a match anywhere in the string (this is what Perl does
715
-Note that match may differ from search even when using a regular expression
716
-beginning with ``'^'``: ``'^'`` matches only at the start of the string, or in
717
-:const:`MULTILINE` mode also immediately following a newline. The "match"
718
-operation succeeds only if the pattern matches at the start of the string
719
-regardless of mode, or at the starting position given by the optional *pos*
720
-argument regardless of whether a newline precedes it.
722
- >>> re.match("c", "abcdef") # No match
723
- >>> re.search("c", "abcdef") # Match
724
- <_sre.SRE_Match object at ...>
727
.. _contents-of-module-re:
730
@@ -575,10 +556,11 @@
731
<match-objects>`. Return ``None`` if the string does not match the pattern;
732
note that this is different from a zero-length match.
735
+ Note that even in :const:`MULTILINE` mode, :func:`re.match` will only match
736
+ at the beginning of the string and not at the beginning of each line.
738
- If you want to locate a match anywhere in *string*, use :func:`search`
740
+ If you want to locate a match anywhere in *string*, use :func:`search`
741
+ instead (see also :ref:`search-vs-match`).
744
.. function:: split(pattern, string, maxsplit=0, flags=0)
745
@@ -762,16 +744,14 @@
746
The optional *pos* and *endpos* parameters have the same meaning as for the
747
:meth:`~regex.search` method.
751
- If you want to locate a match anywhere in *string*, use
752
- :meth:`~regex.search` instead.
754
>>> pattern = re.compile("o")
755
>>> pattern.match("dog") # No match as "o" is not at the start of "dog".
756
>>> pattern.match("dog", 1) # Match as "o" is the 2nd character of "dog".
757
<_sre.SRE_Match object at ...>
759
+ If you want to locate a match anywhere in *string*, use
760
+ :meth:`~regex.search` instead (see also :ref:`search-vs-match`).
763
.. method:: regex.split(string, maxsplit=0)
765
@@ -1133,37 +1113,39 @@
766
[a-zA-Z0-9_ ]*?end``. As a further benefit, such regular expressions will run
767
faster than their recursive equivalents.
769
+.. _search-vs-match:
774
-In a nutshell, :func:`match` only attempts to match a pattern at the beginning
775
-of a string where :func:`search` will match a pattern anywhere in a string.
777
+.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
779
- >>> re.match("o", "dog") # No match as "o" is not the first letter of "dog".
780
- >>> re.search("o", "dog") # Match as search() looks everywhere in the string.
781
+Python offers two different primitive operations based on regular expressions:
782
+:func:`re.match` checks for a match only at the beginning of the string, while
783
+:func:`re.search` checks for a match anywhere in the string (this is what Perl
788
+ >>> re.match("c", "abcdef") # No match
789
+ >>> re.search("c", "abcdef") # Match
790
<_sre.SRE_Match object at ...>
793
+Regular expressions beginning with ``'^'`` can be used with :func:`search` to
794
+restrict the match at the beginning of the string::
796
- The following applies only to regular expression objects like those created
797
- with ``re.compile("pattern")``, not the primitives ``re.match(pattern,
798
- string)`` or ``re.search(pattern, string)``.
799
+ >>> re.match("c", "abcdef") # No match
800
+ >>> re.search("^c", "abcdef") # No match
801
+ >>> re.search("^a", "abcdef") # Match
802
+ <_sre.SRE_Match object at ...>
804
-:func:`match` has an optional second parameter that gives an index in the string
805
-where the search is to start::
806
+Note however that in :const:`MULTILINE` mode :func:`match` only matches at the
807
+beginning of the string, whereas using :func:`search` with a regular expression
808
+beginning with ``'^'`` will match at the beginning of each line.
810
- >>> pattern = re.compile("o")
811
- >>> pattern.match("dog") # No match as "o" is not at the start of "dog."
813
- # Equivalent to the above expression as 0 is the default starting index:
814
- >>> pattern.match("dog", 0)
816
- # Match as "o" is the 2nd character of "dog" (index 0 is the first):
817
- >>> pattern.match("dog", 1)
818
+ >>> re.match('X', 'A\nB\nX', re.MULTILINE) # No match
819
+ >>> re.search('^X', 'A\nB\nX', re.MULTILINE) # Match
820
<_sre.SRE_Match object at ...>
821
- >>> pattern.match("dog", 2) # No match as "o" is not the 3rd character of "dog."
825
diff -r 7085403daf43 Doc/library/sqlite3.rst
7602
826
--- a/Doc/library/sqlite3.rst
7603
827
+++ b/Doc/library/sqlite3.rst
7605
.. method:: Connection.commit()
7607
This method commits the current transaction. If you don't call this method,
7608
- anything you did since the last call to ``commit()`` is not visible from from
7609
+ anything you did since the last call to ``commit()`` is not visible from
7610
other database connections. If you wonder why you don't see the data you've
7611
written to the database, please check you didn't forget to call this method.
7613
@@ -472,14 +472,10 @@
7614
kinds of placeholders: question marks (qmark style) and named placeholders
7617
- This example shows how to use parameters with qmark style:
7618
+ Here's an example of both styles:
7620
.. literalinclude:: ../includes/sqlite3/execute_1.py
7622
- This example shows how to use the named style:
7624
- .. literalinclude:: ../includes/sqlite3/execute_2.py
7626
:meth:`execute` will only execute a single SQL statement. If you try to execute
7627
more than one statement with it, it will raise a Warning. Use
7628
:meth:`executescript` if you want to execute multiple SQL statements with one
7632
def convert_point(s):
7633
- x, y = map(float, s.split(";"))
7634
+ x, y = map(float, s.split(b";"))
7637
Now you need to make the :mod:`sqlite3` module know that what you select from
7638
diff -r 137e45f15c0b Doc/library/ssl.rst
7639
--- a/Doc/library/ssl.rst
7640
+++ b/Doc/library/ssl.rst
7642
The parameter ``ssl_version`` specifies which version of the SSL protocol to
7643
use. Typically, the server chooses a particular protocol version, and the
7644
client must adapt to the server's choice. Most of the versions are not
7645
- interoperable with the other versions. If not specified, for client-side
7646
- operation, the default SSL version is SSLv3; for server-side operation,
7647
- SSLv23. These version selections provide the most compatibility with other
7648
+ interoperable with the other versions. If not specified, the default is
7649
+ :data:`PROTOCOL_SSLv23`; it provides the most compatibility with other
7652
Here's a table showing which versions in a client (down the side) can connect
7654
*client* / **server** **SSLv2** **SSLv3** **SSLv23** **TLSv1**
7655
------------------------ --------- --------- ---------- ---------
7656
*SSLv2* yes no yes no
7657
- *SSLv3* yes yes yes no
7658
+ *SSLv3* no yes yes no
7659
*SSLv23* yes no yes no
7660
*TLSv1* no no yes yes
7661
======================== ========= ========= ========== =========
7665
Enables workarounds for various bugs present in other SSL implementations.
7666
- This option is set by default.
7667
+ This option is set by default. It does not necessarily set the same
7668
+ flags as OpenSSL's ``SSL_OP_ALL`` constant.
7670
.. versionadded:: 3.2
7672
@@ -788,10 +788,19 @@
7673
# note that closing the SSLSocket will also close the underlying socket
7676
-As of October 6, 2010, the certificate printed by this program looks like
7677
+As of January 6, 2012, the certificate printed by this program looks like
7680
- {'notAfter': 'May 25 23:59:59 2012 GMT',
7681
+ {'issuer': ((('countryName', 'US'),),
7682
+ (('organizationName', 'VeriSign, Inc.'),),
7683
+ (('organizationalUnitName', 'VeriSign Trust Network'),),
7684
+ (('organizationalUnitName',
7685
+ 'Terms of use at https://www.verisign.com/rpa (c)06'),),
7687
+ 'VeriSign Class 3 Extended Validation SSL SGC CA'),)),
7688
+ 'notAfter': 'May 25 23:59:59 2012 GMT',
7689
+ 'notBefore': 'May 26 00:00:00 2010 GMT',
7690
+ 'serialNumber': '53D2BEF924A7245E83CA01E46CAA2477',
7691
'subject': ((('1.3.6.1.4.1.311.60.2.1.3', 'US'),),
7692
(('1.3.6.1.4.1.311.60.2.1.2', 'Delaware'),),
7693
(('businessCategory', 'V1.0, Clause 5.(b)'),),
7694
@@ -803,7 +812,16 @@
7695
(('streetAddress', '487 East Middlefield Road'),),
7696
(('organizationName', 'VeriSign, Inc.'),),
7697
(('organizationalUnitName', ' Production Security Services'),),
7698
- (('commonName', 'www.verisign.com'),))}
7699
+ (('commonName', 'www.verisign.com'),)),
7700
+ 'subjectAltName': (('DNS', 'www.verisign.com'),
7701
+ ('DNS', 'verisign.com'),
7702
+ ('DNS', 'www.verisign.net'),
7703
+ ('DNS', 'verisign.net'),
7704
+ ('DNS', 'www.verisign.mobi'),
7705
+ ('DNS', 'verisign.mobi'),
7706
+ ('DNS', 'www.verisign.eu'),
7707
+ ('DNS', 'verisign.eu')),
7710
This other example first creates an SSL context, instructs it to verify
7711
certificates sent by peers, and feeds it a set of recognized certificate
7712
@@ -834,9 +852,26 @@
7713
(that is, the HTTPS host ``linuxfr.org``)::
7715
>>> pprint.pprint(cert)
7716
- {'notAfter': 'Jun 26 21:41:46 2011 GMT',
7717
+ {'issuer': ((('organizationName', 'CAcert Inc.'),),
7718
+ (('organizationalUnitName', 'http://www.CAcert.org'),),
7719
+ (('commonName', 'CAcert Class 3 Root'),)),
7720
+ 'notAfter': 'Jun 7 21:02:24 2013 GMT',
7721
+ 'notBefore': 'Jun 8 21:02:24 2011 GMT',
7722
+ 'serialNumber': 'D3E9',
7723
'subject': ((('commonName', 'linuxfr.org'),),),
7724
- 'subjectAltName': (('DNS', 'linuxfr.org'), ('othername', '<unsupported>'))}
7725
+ 'subjectAltName': (('DNS', 'linuxfr.org'),
7726
+ ('othername', '<unsupported>'),
7727
+ ('DNS', 'linuxfr.org'),
7728
+ ('othername', '<unsupported>'),
7729
+ ('DNS', 'dev.linuxfr.org'),
7730
+ ('othername', '<unsupported>'),
7731
+ ('DNS', 'prod.linuxfr.org'),
7732
+ ('othername', '<unsupported>'),
7733
+ ('DNS', 'alpha.linuxfr.org'),
7734
+ ('othername', '<unsupported>'),
7735
+ ('DNS', '*.linuxfr.org'),
7736
+ ('othername', '<unsupported>')),
7739
Now that you are assured of its authenticity, you can proceed to talk with
7741
@@ -984,14 +1019,33 @@
7742
The SSL context created above will allow SSLv3 and TLSv1 connections, but
7748
+If you have advanced security requirements, fine-tuning of the ciphers
7749
+enabled when negotiating a SSL session is possible through the
7750
+:meth:`SSLContext.set_ciphers` method. Starting from Python 3.2.3, the
7751
+ssl module disables certain weak ciphers by default, but you may want
7752
+to further restrict the cipher choice. For example::
7754
+ context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
7755
+ context.set_ciphers('HIGH:!aNULL:!eNULL')
7757
+The ``!aNULL:!eNULL`` part of the cipher spec is necessary to disable ciphers
7758
+which don't provide both encryption and authentication. Be sure to read
7759
+OpenSSL's documentation about the `cipher list
7760
+format <http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT>`_.
7761
+If you want to check which ciphers are enabled by a given cipher list,
7762
+use the ``openssl ciphers`` command on your system.
7767
Class :class:`socket.socket`
7768
Documentation of underlying :mod:`socket` class
7770
- `Introducing SSL and Certificates using OpenSSL <http://old.pseudonym.org/ssl/wwwj-index.html>`_
7771
- Frederick J. Hirsch
7772
+ `TLS (Transport Layer Security) and SSL (Secure Socket Layer) <http://www3.rad.com/networks/applications/secure/tls.htm>`_
7775
`RFC 1422: Privacy Enhancement for Internet Electronic Mail: Part II: Certificate-Based Key Management <http://www.ietf.org/rfc/rfc1422>`_
7777
diff -r 137e45f15c0b Doc/library/stdtypes.rst
831
:synopsis: A DB-API 2.0 implementation using SQLite 3.x.
832
-.. sectionauthor:: Gerhard Häring <gh@ghaering.de>
833
+.. sectionauthor:: Gerhard Häring <gh@ghaering.de>
836
SQLite is a C library that provides a lightweight disk-based database that
838
represents the database. Here the data will be stored in the
839
:file:`/tmp/example` file::
842
conn = sqlite3.connect('/tmp/example')
844
You can also supply the special name ``:memory:`` to create a database in RAM.
847
# Never do this -- insecure!
849
- c.execute("... where symbol = '%s'" % symbol)
850
+ c.execute("select * from stocks where symbol = '%s'" % symbol)
857
for t in [('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
858
- ('2006-04-05', 'BUY', 'MSOFT', 1000, 72.00),
859
+ ('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
860
('2006-04-06', 'SELL', 'IBM', 500, 53.00),
862
c.execute('insert into stocks values (?,?,?,?,?)', t)
864
calling the cursor method, then calls the cursor's :meth:`executemany
865
<Cursor.executemany>` method with the parameters given.
868
.. method:: Connection.executescript(sql_script)
870
This is a nonstandard shortcut that creates an intermediate cursor object by
871
@@ -376,22 +376,22 @@
872
aggregates or whole new virtual table implementations. One well-known
873
extension is the fulltext-search extension distributed with SQLite.
875
+ Loadable extensions are disabled by default. See [#f1]_.
877
.. versionadded:: 3.2
879
.. literalinclude:: ../includes/sqlite3/load_extension.py
881
- Loadable extensions are disabled by default. See [#f1]_.
883
.. method:: Connection.load_extension(path)
885
This routine loads a SQLite extension from a shared library. You have to
886
enable extension loading with :meth:`enable_load_extension` before you can
889
+ Loadable extensions are disabled by default. See [#f1]_.
891
.. versionadded:: 3.2
893
- Loadable extensions are disabled by default. See [#f1]_.
895
.. attribute:: Connection.row_factory
897
You can change this attribute to a callable that accepts the cursor and the
898
diff -r 7085403daf43 Doc/library/stdtypes.rst
7778
899
--- a/Doc/library/stdtypes.rst
7779
900
+++ b/Doc/library/stdtypes.rst
7782
* instances of user-defined classes, if the class defines a :meth:`__bool__` or
7783
:meth:`__len__` method, when that method returns the integer zero or
7784
- :class:`bool` value ``False``. [#]_
7785
+ :class:`bool` value ``False``. [1]_
7787
.. index:: single: true
7790
operands of different numeric types, the operand with the "narrower" type is
7791
widened to that of the other, where integer is narrower than floating point,
7792
which is narrower than complex. Comparisons between numbers of mixed type use
7793
-the same rule. [#]_ The constructors :func:`int`, :func:`float`, and
7794
+the same rule. [2]_ The constructors :func:`int`, :func:`float`, and
7795
:func:`complex` can be used to produce numbers of a specific type.
7797
All numeric types (except complex) support the following operations, sorted by
7798
@@ -379,12 +379,12 @@
7802
-Bit-string Operations on Integer Types
7803
+Bitwise Operations on Integer Types
7804
--------------------------------------
7807
triple: operations on; integer; types
7808
- pair: bit-string; operations
7809
+ pair: bitwise; operations
7810
pair: shifting; operations
7811
pair: masking; operations
7813
@@ -392,15 +392,15 @@
7817
-Integers support additional operations that make sense only for bit-strings.
7818
-Negative numbers are treated as their 2's complement value (this assumes a
7819
-sufficiently large number of bits that no overflow occurs during the operation).
7820
+Bitwise operations only make sense for integers. Negative numbers are treated
7821
+as their 2's complement value (this assumes a sufficiently large number of bits
7822
+that no overflow occurs during the operation).
7824
The priorities of the binary bitwise operations are all lower than the numeric
7825
operations and higher than the comparisons; the unary operation ``~`` has the
7826
same priority as the other unary numeric operations (``+`` and ``-``).
7828
-This table lists the bit-string operations sorted in ascending priority
7829
+This table lists the bitwise operations sorted in ascending priority
7830
(operations in the same box have the same priority):
7832
+------------+--------------------------------+----------+
7834
Most sequence types support the following operations. The ``in`` and ``not in``
7835
operations have the same priorities as the comparison operations. The ``+`` and
7836
``*`` operations have the same priority as the corresponding numeric operations.
7837
-[#]_ Additional methods are provided for :ref:`typesseq-mutable`.
7838
+[3]_ Additional methods are provided for :ref:`typesseq-mutable`.
7840
This table lists the sequence operations sorted in ascending priority
7841
(operations in the same box have the same priority). In the table, *s* and *t*
7843
| ``s * n, n * s`` | *n* shallow copies of *s* | \(2) |
7844
| | concatenated | |
7845
+------------------+--------------------------------+----------+
7846
-| ``s[i]`` | *i*'th item of *s*, origin 0 | \(3) |
7847
+| ``s[i]`` | *i*\ th item of *s*, origin 0 | \(3) |
7848
+------------------+--------------------------------+----------+
7849
| ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) |
7850
+------------------+--------------------------------+----------+
7851
@@ -964,15 +964,18 @@
7852
If *k* is ``None``, it is treated like ``1``.
7857
- If *s* and *t* are both strings, some Python implementations such as
7858
- CPython can usually perform an in-place optimization for assignments of
7859
- the form ``s = s + t`` or ``s += t``. When applicable, this optimization
7860
- makes quadratic run-time much less likely. This optimization is both
7861
- version and implementation dependent. For performance sensitive code, it
7862
- is preferable to use the :meth:`str.join` method which assures consistent
7863
- linear concatenation performance across versions and implementations.
7864
+ Concatenating immutable strings always results in a new object. This means
7865
+ that building up a string by repeated concatenation will have a quadratic
7866
+ runtime cost in the total string length. To get a linear runtime cost,
7867
+ you must switch to one of the alternatives below:
7869
+ * if concatenating :class:`str` objects, you can build a list and use
7870
+ :meth:`str.join` at the end;
7872
+ * if concatenating :class:`bytes` objects, you can similarly use
7873
+ :meth:`bytes.join`, or you can do in-place concatenation with a
7874
+ :class:`bytearray` object. :class:`bytearray` objects are mutable and
7875
+ have an efficient overallocation mechanism.
7879
@@ -1033,7 +1036,7 @@
7881
.. method:: str.expandtabs([tabsize])
7883
- Return a copy of the string where all tab characters are replaced by one or
7884
+ Return a copy of the string where all tab characters are replaced by zero or
7885
more spaces, depending on the current column and the given tab size. The
7886
column number is reset to zero after each newline occurring in the string.
7887
If *tabsize* is not given, a tab size of ``8`` characters is assumed. This
7888
@@ -1117,7 +1120,7 @@
7889
characters and there is at least one character, false
7890
otherwise. Decimal characters are those from general category "Nd". This category
7891
includes digit characters, and all characters
7892
- that that can be used to form decimal-radix numbers, e.g. U+0660,
7893
+ that can be used to form decimal-radix numbers, e.g. U+0660,
7894
ARABIC-INDIC DIGIT ZERO.
7897
@@ -1137,10 +1140,8 @@
7899
.. method:: str.islower()
7901
- Return true if all cased characters in the string are lowercase and there is at
7902
- least one cased character, false otherwise. Cased characters are those with
7903
- general category property being one of "Lu", "Ll", or "Lt" and lowercase characters
7904
- are those with general category property "Ll".
7905
+ Return true if all cased characters [4]_ in the string are lowercase and
7906
+ there is at least one cased character, false otherwise.
7909
.. method:: str.isnumeric()
7910
@@ -1180,17 +1181,15 @@
7912
.. method:: str.isupper()
7914
- Return true if all cased characters in the string are uppercase and there is at
7915
- least one cased character, false otherwise. Cased characters are those with
7916
- general category property being one of "Lu", "Ll", or "Lt" and uppercase characters
7917
- are those with general category property "Lu".
7918
+ Return true if all cased characters [4]_ in the string are uppercase and
7919
+ there is at least one cased character, false otherwise.
7922
.. method:: str.join(iterable)
7924
Return a string which is the concatenation of the strings in the
7925
:term:`iterable` *iterable*. A :exc:`TypeError` will be raised if there are
7926
- any non-string values in *seq*, including :class:`bytes` objects. The
7927
+ any non-string values in *iterable*, including :class:`bytes` objects. The
7928
separator between elements is the string providing this method.
7931
@@ -1198,12 +1197,13 @@
7933
Return the string left justified in a string of length *width*. Padding is done
7934
using the specified *fillchar* (default is a space). The original string is
7935
- returned if *width* is less than ``len(s)``.
7936
+ returned if *width* is less than or equal to ``len(s)``.
7939
.. method:: str.lower()
7941
- Return a copy of the string converted to lowercase.
7942
+ Return a copy of the string with all the cased characters [4]_ converted to
7946
.. method:: str.lstrip([chars])
7947
@@ -1266,7 +1266,7 @@
7949
Return the string right justified in a string of length *width*. Padding is done
7950
using the specified *fillchar* (default is a space). The original string is
7951
- returned if *width* is less than ``len(s)``.
7952
+ returned if *width* is less than or equal to ``len(s)``.
7955
.. method:: str.rpartition(sep)
7956
@@ -1404,14 +1404,17 @@
7958
.. method:: str.upper()
7960
- Return a copy of the string converted to uppercase.
7961
+ Return a copy of the string with all the cased characters [4]_ converted to
7962
+ uppercase. Note that ``str.upper().isupper()`` might be ``False`` if ``s``
7963
+ contains uncased characters or if the Unicode category of the resulting
7964
+ character(s) is not "Lu" (Letter, uppercase), but e.g. "Lt" (Letter, titlecase).
7967
.. method:: str.zfill(width)
7969
Return the numeric string left filled with zeros in a string of length
7970
*width*. A sign prefix is handled correctly. The original string is
7971
- returned if *width* is less than ``len(s)``.
7972
+ returned if *width* is less than or equal to ``len(s)``.
7976
@@ -1444,7 +1447,7 @@
7977
The effect is similar to the using :c:func:`sprintf` in the C language.
7979
If *format* requires a single argument, *values* may be a single non-tuple
7980
-object. [#]_ Otherwise, *values* must be a tuple with exactly the number of
7981
+object. [5]_ Otherwise, *values* must be a tuple with exactly the number of
7982
items specified by the format string, or a single mapping object (for example, a
7985
@@ -2712,6 +2715,8 @@
7986
It is written as ``Ellipsis`` or ``...``.
7989
+.. _bltin-notimplemented-object:
7991
The NotImplemented Object
7992
-------------------------
7994
@@ -2722,6 +2727,8 @@
7995
It is written as ``NotImplemented``.
7998
+.. _bltin-boolean-values:
8003
@@ -2729,9 +2736,9 @@
8004
used to represent truth values (although other values can also be considered
8005
false or true). In numeric contexts (for example when used as the argument to
8006
an arithmetic operator), they behave like the integers 0 and 1, respectively.
8007
-The built-in function :func:`bool` can be used to cast any value to a Boolean,
8008
-if the value can be interpreted as a truth value (see section Truth Value
8010
+The built-in function :func:`bool` can be used to convert any value to a
8011
+Boolean, if the value can be interpreted as a truth value (see section
8012
+:ref:`truth` above).
8016
@@ -2781,8 +2788,6 @@
8017
The name of the class or type.
8020
-The following attributes are only supported by :term:`new-style class`\ es.
8022
.. attribute:: class.__mro__
8024
This attribute is a tuple of classes that are considered when looking for
8025
@@ -2798,23 +2803,26 @@
8027
.. method:: class.__subclasses__
8029
- Each new-style class keeps a list of weak references to its immediate
8030
- subclasses. This method returns a list of all those references still alive.
8031
+ Each class keeps a list of weak references to its immediate subclasses. This
8032
+ method returns a list of all those references still alive.
8035
>>> int.__subclasses__()
8040
.. rubric:: Footnotes
8042
-.. [#] Additional information on these special methods may be found in the Python
8043
+.. [1] Additional information on these special methods may be found in the Python
8044
Reference Manual (:ref:`customization`).
8046
-.. [#] As a consequence, the list ``[1, 2]`` is considered equal to ``[1.0, 2.0]``, and
8047
+.. [2] As a consequence, the list ``[1, 2]`` is considered equal to ``[1.0, 2.0]``, and
8048
similarly for tuples.
8050
-.. [#] They must have since the parser can't tell the type of the operands.
8052
-.. [#] To format only a tuple you should therefore provide a singleton tuple whose only
8053
+.. [3] They must have since the parser can't tell the type of the operands.
8055
+.. [4] Cased characters are those with general category property being one of
8056
+ "Lu" (Letter, uppercase), "Ll" (Letter, lowercase), or "Lt" (Letter, titlecase).
8058
+.. [5] To format only a tuple you should therefore provide a singleton tuple whose only
8059
element is the tuple to be formatted.
8060
diff -r 137e45f15c0b Doc/library/string.rst
8061
--- a/Doc/library/string.rst
8062
+++ b/Doc/library/string.rst
8065
:synopsis: Common string operations.
8067
+**Source code:** :source:`Lib/string.py`
8075
:ref:`string-methods`
8077
-**Source code:** :source:`Lib/string.py`
8086
See also the :ref:`formatspec` section.
8088
-The *field_name* itself begins with an *arg_name* that is either either a number or a
8089
+The *field_name* itself begins with an *arg_name* that is either a number or a
8090
keyword. If it's a number, it refers to a positional argument, and if it's a keyword,
8091
it refers to a named keyword argument. If the numerical arg_names in a format string
8092
are 0, 1, 2, ... in sequence, they can all be omitted (not just some)
8097
- >>> 'Correct answers: {:.2%}.'.format(points/total)
8098
+ >>> 'Correct answers: {:.2%}'.format(points/total)
8099
'Correct answers: 86.36%'
8101
Using type-specific formatting::
8102
diff -r 137e45f15c0b Doc/library/subprocess.rst
8103
--- a/Doc/library/subprocess.rst
8104
+++ b/Doc/library/subprocess.rst
8106
Using the subprocess Module
8107
---------------------------
8109
-This module defines one class called :class:`Popen`:
8110
+The recommended approach to invoking subprocesses is to use the following
8111
+convenience functions for all use cases they can handle. For more advanced
8112
+use cases, the underlying :class:`Popen` interface can be used directly.
8115
+.. function:: call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
8117
+ Run the command described by *args*. Wait for command to complete, then
8118
+ return the :attr:`returncode` attribute.
8120
+ The arguments shown above are merely the most common ones, described below
8121
+ in :ref:`frequently-used-arguments` (hence the slightly odd notation in
8122
+ the abbreviated signature). The full function signature is the same as
8123
+ that of the :class:`Popen` constructor - this functions passes all
8124
+ supplied arguments directly through to that interface.
8128
+ >>> subprocess.call(["ls", "-l"])
8131
+ >>> subprocess.call("exit 1", shell=True)
8136
+ Invoking the system shell with ``shell=True`` can be a security hazard
8137
+ if combined with untrusted input. See the warning under
8138
+ :ref:`frequently-used-arguments` for details.
8142
+ Do not use ``stdout=PIPE`` or ``stderr=PIPE`` with this function. As
8143
+ the pipes are not being read in the current process, the child
8144
+ process may block if it generates enough output to a pipe to fill up
8145
+ the OS pipe buffer.
8148
+.. function:: check_call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
8150
+ Run command with arguments. Wait for command to complete. If the return
8151
+ code was zero then return, otherwise raise :exc:`CalledProcessError`. The
8152
+ :exc:`CalledProcessError` object will have the return code in the
8153
+ :attr:`returncode` attribute.
8155
+ The arguments shown above are merely the most common ones, described below
8156
+ in :ref:`frequently-used-arguments` (hence the slightly odd notation in
8157
+ the abbreviated signature). The full function signature is the same as
8158
+ that of the :class:`Popen` constructor - this functions passes all
8159
+ supplied arguments directly through to that interface.
8163
+ >>> subprocess.check_call(["ls", "-l"])
8166
+ >>> subprocess.check_call("exit 1", shell=True)
8167
+ Traceback (most recent call last):
8169
+ subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1
8171
+ .. versionadded:: 2.5
8175
+ Invoking the system shell with ``shell=True`` can be a security hazard
8176
+ if combined with untrusted input. See the warning under
8177
+ :ref:`frequently-used-arguments` for details.
8181
+ Do not use ``stdout=PIPE`` or ``stderr=PIPE`` with this function. As
8182
+ the pipes are not being read in the current process, the child
8183
+ process may block if it generates enough output to a pipe to fill up
8184
+ the OS pipe buffer.
8187
+.. function:: check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False)
8189
+ Run command with arguments and return its output as a byte string.
8191
+ If the return code was non-zero it raises a :exc:`CalledProcessError`. The
8192
+ :exc:`CalledProcessError` object will have the return code in the
8193
+ :attr:`returncode` attribute and any output in the :attr:`output`
8196
+ The arguments shown above are merely the most common ones, described below
8197
+ in :ref:`frequently-used-arguments` (hence the slightly odd notation in
8198
+ the abbreviated signature). The full function signature is largely the
8199
+ same as that of the :class:`Popen` constructor, except that *stdout* is
8200
+ not permitted as it is used internally. All other supplied arguments are
8201
+ passed directly through to the :class:`Popen` constructor.
8205
+ >>> subprocess.check_output(["echo", "Hello World!"])
8208
+ >>> subprocess.check_output(["echo", "Hello World!"], universal_newlines=True)
8211
+ >>> subprocess.check_output("exit 1", shell=True)
8212
+ Traceback (most recent call last):
8214
+ subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1
8216
+ By default, this function will return the data as encoded bytes. The actual
8217
+ encoding of the output data may depend on the command being invoked, so the
8218
+ decoding to text will often need to be handled at the application level.
8220
+ This behaviour may be overridden by setting *universal_newlines* to
8221
+ :const:`True` as described below in :ref:`frequently-used-arguments`.
8223
+ To also capture standard error in the result, use
8224
+ ``stderr=subprocess.STDOUT``::
8226
+ >>> subprocess.check_output(
8227
+ ... "ls non_existent_file; exit 0",
8228
+ ... stderr=subprocess.STDOUT,
8230
+ 'ls: non_existent_file: No such file or directory\n'
8232
+ .. versionadded:: 2.7
8236
+ Invoking the system shell with ``shell=True`` can be a security hazard
8237
+ if combined with untrusted input. See the warning under
8238
+ :ref:`frequently-used-arguments` for details.
8242
+ Do not use ``stderr=PIPE`` with this function. As the pipe is not being
8243
+ read in the current process, the child process may block if it
8244
+ generates enough output to the pipe to fill up the OS pipe buffer.
8249
+ Special value that can be used as the *stdin*, *stdout* or *stderr* argument
8250
+ to :class:`Popen` and indicates that a pipe to the standard stream should be
8256
+ Special value that can be used as the *stderr* argument to :class:`Popen` and
8257
+ indicates that standard error should go into the same handle as standard
8261
+.. _frequently-used-arguments:
8263
+Frequently Used Arguments
8264
+^^^^^^^^^^^^^^^^^^^^^^^^^
8266
+To support a wide variety of use cases, the :class:`Popen` constructor (and
8267
+the convenience functions) accept a large number of optional arguments. For
8268
+most typical use cases, many of these arguments can be safely left at their
8269
+default values. The arguments that are most commonly needed are:
8271
+ *args* is required for all calls and should be a string, or a sequence of
8272
+ program arguments. Providing a sequence of arguments is generally
8273
+ preferred, as it allows the module to take care of any required escaping
8274
+ and quoting of arguments (e.g. to permit spaces in file names). If passing
8275
+ a single string, either *shell* must be :const:`True` (see below) or else
8276
+ the string must simply name the program to be executed without specifying
8279
+ *stdin*, *stdout* and *stderr* specify the executed program's standard input,
8280
+ standard output and standard error file handles, respectively. Valid values
8281
+ are :data:`PIPE`, an existing file descriptor (a positive integer), an
8282
+ existing file object, and ``None``. :data:`PIPE` indicates that a new pipe
8283
+ to the child should be created. With the default settings of ``None``, no
8284
+ redirection will occur; the child's file handles will be inherited from the
8285
+ parent. Additionally, *stderr* can be :data:`STDOUT`, which indicates that
8286
+ the stderr data from the child process should be captured into the same file
8287
+ handle as for stdout.
8289
+ When *stdout* or *stderr* are pipes and *universal_newlines* is
8290
+ :const:`True` then the output data is assumed to be encoded as UTF-8 and
8291
+ will automatically be decoded to text. All line endings will be converted
8292
+ to ``'\n'`` as described for the universal newlines `'U'`` mode argument
8295
+ If *shell* is :const:`True`, the specified command will be executed through
8296
+ the shell. This can be useful if you are using Python primarily for the
8297
+ enhanced control flow it offers over most system shells and still want
8298
+ access to other shell features such as filename wildcards, shell pipes and
8299
+ environment variable expansion.
8303
+ Executing shell commands that incorporate unsanitized input from an
8304
+ untrusted source makes a program vulnerable to `shell injection
8305
+ <http://en.wikipedia.org/wiki/Shell_injection#Shell_injection>`_,
8306
+ a serious security flaw which can result in arbitrary command execution.
8307
+ For this reason, the use of *shell=True* is **strongly discouraged** in cases
8308
+ where the command string is constructed from external input::
8310
+ >>> from subprocess import call
8311
+ >>> filename = input("What file would you like to display?\n")
8312
+ What file would you like to display?
8313
+ non_existent; rm -rf / #
8314
+ >>> call("cat " + filename, shell=True) # Uh-oh. This will end badly...
8316
+ ``shell=False`` disables all shell based features, but does not suffer
8317
+ from this vulnerability; see the Note in the :class:`Popen` constructor
8318
+ documentation for helpful hints in getting ``shell=False`` to work.
8320
+These options, along with all of the other options, are described in more
8321
+detail in the :class:`Popen` constructor documentation.
8327
+The underlying process creation and management in this module is handled by
8328
+the :class:`Popen` class. It offers a lot of flexibility so that developers
8329
+are able to handle the less common cases not covered by the convenience
8333
.. class:: Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=True, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, restore_signals=True, start_new_session=False, pass_fds=())
8338
- Executing shell commands that incorporate unsanitized input from an
8339
- untrusted source makes a program vulnerable to `shell injection
8340
- <http://en.wikipedia.org/wiki/Shell_injection#Shell_injection>`_,
8341
- a serious security flaw which can result in arbitrary command execution.
8342
- For this reason, the use of *shell=True* is **strongly discouraged** in cases
8343
- where the command string is constructed from external input::
8345
- >>> from subprocess import call
8346
- >>> filename = input("What file would you like to display?\n")
8347
- What file would you like to display?
8348
- non_existent; rm -rf / #
8349
- >>> call("cat " + filename, shell=True) # Uh-oh. This will end badly...
8351
- *shell=False* does not suffer from this vulnerability; the above Note may be
8352
- helpful in getting code using *shell=False* to work.
8353
+ Enabling this option can be a security hazard if combined with untrusted
8354
+ input. See the warning under :ref:`frequently-used-arguments`
8357
On Windows: the :class:`Popen` class uses CreateProcess() to execute the
8358
child program, which operates on strings. If *args* is a sequence, it will
8359
@@ -121,14 +329,15 @@
8360
You don't need ``shell=True`` to run a batch file, nor to run a console-based
8363
- *stdin*, *stdout* and *stderr* specify the executed programs' standard input,
8364
+ *stdin*, *stdout* and *stderr* specify the executed program's standard input,
8365
standard output and standard error file handles, respectively. Valid values
8366
are :data:`PIPE`, an existing file descriptor (a positive integer), an
8367
existing :term:`file object`, and ``None``. :data:`PIPE` indicates that a
8368
- new pipe to the child should be created. With ``None``, no redirection will
8369
- occur; the child's file handles will be inherited from the parent. Additionally,
8370
- *stderr* can be :data:`STDOUT`, which indicates that the stderr data from the
8371
- applications should be captured into the same file handle as for stdout.
8372
+ new pipe to the child should be created. With the default settings of
8373
+ ``None``, no redirection will occur; the child's file handles will be
8374
+ inherited from the parent. Additionally, *stderr* can be :data:`STDOUT`,
8375
+ which indicates that the stderr data from the applications should be
8376
+ captured into the same file handle as for stdout.
8378
If *preexec_fn* is set to a callable object, this object will be called in the
8379
child process just before the child is executed.
8380
@@ -228,118 +437,6 @@
8381
Added context manager support.
8386
- Special value that can be used as the *stdin*, *stdout* or *stderr* argument
8387
- to :class:`Popen` and indicates that a pipe to the standard stream should be
8393
- Special value that can be used as the *stderr* argument to :class:`Popen` and
8394
- indicates that standard error should go into the same handle as standard
8398
-Convenience Functions
8399
-^^^^^^^^^^^^^^^^^^^^^
8401
-This module also defines the following shortcut functions:
8404
-.. function:: call(*popenargs, **kwargs)
8406
- Run command with arguments. Wait for command to complete, then return the
8407
- :attr:`returncode` attribute.
8409
- The arguments are the same as for the :class:`Popen` constructor. Example::
8411
- >>> retcode = subprocess.call(["ls", "-l"])
8415
- Like :meth:`Popen.wait`, this will deadlock when using
8416
- ``stdout=PIPE`` and/or ``stderr=PIPE`` and the child process
8417
- generates enough output to a pipe such that it blocks waiting
8418
- for the OS pipe buffer to accept more data.
8421
-.. function:: check_call(*popenargs, **kwargs)
8423
- Run command with arguments. Wait for command to complete. If the exit code was
8424
- zero then return, otherwise raise :exc:`CalledProcessError`. The
8425
- :exc:`CalledProcessError` object will have the return code in the
8426
- :attr:`returncode` attribute.
8428
- The arguments are the same as for the :class:`Popen` constructor. Example::
8430
- >>> subprocess.check_call(["ls", "-l"])
8435
- See the warning for :func:`call`.
8438
-.. function:: check_output(*popenargs, **kwargs)
8440
- Run command with arguments and return its output as a byte string.
8442
- If the exit code was non-zero it raises a :exc:`CalledProcessError`. The
8443
- :exc:`CalledProcessError` object will have the return code in the
8444
- :attr:`returncode`
8445
- attribute and output in the :attr:`output` attribute.
8447
- The arguments are the same as for the :class:`Popen` constructor. Example::
8449
- >>> subprocess.check_output(["ls", "-l", "/dev/null"])
8450
- b'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
8452
- The stdout argument is not allowed as it is used internally.
8453
- To capture standard error in the result, use ``stderr=subprocess.STDOUT``::
8455
- >>> subprocess.check_output(
8456
- ... ["/bin/sh", "-c", "ls non_existent_file; exit 0"],
8457
- ... stderr=subprocess.STDOUT)
8458
- b'ls: non_existent_file: No such file or directory\n'
8460
- .. versionadded:: 3.1
8463
-.. function:: getstatusoutput(cmd)
8465
- Return ``(status, output)`` of executing *cmd* in a shell.
8467
- Execute the string *cmd* in a shell with :func:`os.popen` and return a 2-tuple
8468
- ``(status, output)``. *cmd* is actually run as ``{ cmd ; } 2>&1``, so that the
8469
- returned output will contain output or error messages. A trailing newline is
8470
- stripped from the output. The exit status for the command can be interpreted
8471
- according to the rules for the C function :c:func:`wait`. Example::
8473
- >>> subprocess.getstatusoutput('ls /bin/ls')
8475
- >>> subprocess.getstatusoutput('cat /bin/junk')
8476
- (256, 'cat: /bin/junk: No such file or directory')
8477
- >>> subprocess.getstatusoutput('/bin/junk')
8478
- (256, 'sh: /bin/junk: not found')
8480
- Availability: UNIX.
8483
-.. function:: getoutput(cmd)
8485
- Return output (stdout and stderr) of executing *cmd* in a shell.
8487
- Like :func:`getstatusoutput`, except the exit status is ignored and the return
8488
- value is a string containing the command's output. Example::
8490
- >>> subprocess.getoutput('ls /bin/ls')
8493
- Availability: UNIX.
8499
@@ -355,16 +452,19 @@
8500
A :exc:`ValueError` will be raised if :class:`Popen` is called with invalid
8503
-check_call() will raise :exc:`CalledProcessError`, if the called process returns
8504
-a non-zero return code.
8505
+:func:`check_call` and :func:`check_output` will raise
8506
+:exc:`CalledProcessError` if the called process returns a non-zero return
8513
-Unlike some other popen functions, this implementation will never call /bin/sh
8514
-implicitly. This means that all characters, including shell metacharacters, can
8515
-safely be passed to child processes.
8516
+Unlike some other popen functions, this implementation will never call a
8517
+system shell implicitly. This means that all characters, including shell
8518
+metacharacters, can safely be passed to child processes. Obviously, if the
8519
+shell is invoked explicitly, then it is the application's responsibility to
8520
+ensure that all whitespace and metacharacters are quoted appropriately.
8524
@@ -592,15 +692,21 @@
8525
Replacing Older Functions with the subprocess Module
8526
----------------------------------------------------
8528
-In this section, "a ==> b" means that b can be used as a replacement for a.
8529
+In this section, "a becomes b" means that b can be used as a replacement for a.
901
@@ -1437,8 +1437,13 @@
8533
- All functions in this section fail (more or less) silently if the executed
8534
- program cannot be found; this module raises an :exc:`OSError` exception.
8535
+ All "a" functions in this section fail (more or less) silently if the
8536
+ executed program cannot be found; the "b" replacements raise :exc:`OSError`
8539
-In the following examples, we assume that the subprocess module is imported with
8540
-"from subprocess import \*".
8541
+ In addition, the replacements using :func:`check_output` will fail with a
8542
+ :exc:`CalledProcessError` if the requested operation produces a non-zero
8543
+ return code. The output is still available as the ``output`` attribute of
8544
+ the raised exception.
8546
+In the following examples, we assume that the relevant functions have already
8547
+been imported from the subprocess module.
8550
Replacing /bin/sh shell backquote
8554
output=`mycmd myarg`
8556
- output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]
8558
+ output = check_output(["mycmd", "myarg"])
8561
Replacing shell pipeline
8565
output=`dmesg | grep hda`
8568
p1 = Popen(["dmesg"], stdout=PIPE)
8569
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
8570
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
8571
@@ -628,22 +734,27 @@
8572
The p1.stdout.close() call after starting the p2 is important in order for p1
8573
to receive a SIGPIPE if p2 exits before p1.
8575
+Alternatively, for trusted input, the shell's own pipeline support may still
8578
+ output=`dmesg | grep hda`
8580
+ output=check_output("dmesg | grep hda", shell=True)
8583
Replacing :func:`os.system`
8584
^^^^^^^^^^^^^^^^^^^^^^^^^^^
8588
sts = os.system("mycmd" + " myarg")
8590
- p = Popen("mycmd" + " myarg", shell=True)
8591
- sts = os.waitpid(p.pid, 0)[1]
8593
+ sts = call("mycmd" + " myarg", shell=True)
8597
* Calling the program through the shell is usually not required.
8599
-* It's easier to look at the :attr:`returncode` attribute than the exit status.
8601
A more realistic example would look like this::
8604
@@ -768,6 +879,48 @@
8605
``close_fds=True`` with :class:`Popen` to guarantee this behavior on
8606
all platforms or past Python versions.
8609
+Legacy Shell Invocation Functions
8610
+---------------------------------
8612
+This module also provides the following legacy functions from the 2.x
8613
+``commands`` module. These operations implicitly invoke the system shell and
8614
+none of the guarantees described above regarding security and exception
8615
+handling consistency are valid for these functions.
8617
+.. function:: getstatusoutput(cmd)
8619
+ Return ``(status, output)`` of executing *cmd* in a shell.
8621
+ Execute the string *cmd* in a shell with :func:`os.popen` and return a 2-tuple
8622
+ ``(status, output)``. *cmd* is actually run as ``{ cmd ; } 2>&1``, so that the
8623
+ returned output will contain output or error messages. A trailing newline is
8624
+ stripped from the output. The exit status for the command can be interpreted
8625
+ according to the rules for the C function :c:func:`wait`. Example::
8627
+ >>> subprocess.getstatusoutput('ls /bin/ls')
8629
+ >>> subprocess.getstatusoutput('cat /bin/junk')
8630
+ (256, 'cat: /bin/junk: No such file or directory')
8631
+ >>> subprocess.getstatusoutput('/bin/junk')
8632
+ (256, 'sh: /bin/junk: not found')
8634
+ Availability: UNIX.
8637
+.. function:: getoutput(cmd)
8639
+ Return output (stdout and stderr) of executing *cmd* in a shell.
8641
+ Like :func:`getstatusoutput`, except the exit status is ignored and the return
8642
+ value is a string containing the command's output. Example::
8644
+ >>> subprocess.getoutput('ls /bin/ls')
8647
+ Availability: UNIX.
8654
backslash. If the number of backslashes is odd, the last
8655
backslash escapes the next double quotation mark as
8656
described in rule 3.
8659
diff -r 137e45f15c0b Doc/library/symbol.rst
8660
--- a/Doc/library/symbol.rst
8661
+++ b/Doc/library/symbol.rst
8663
Dictionary mapping the numeric values of the constants defined in this module
8664
back to name strings, allowing more human-readable representation of parse trees
8670
- Module :mod:`parser`
8671
- The second example for the :mod:`parser` module shows how to use the
8672
- :mod:`symbol` module.
8674
diff -r 137e45f15c0b Doc/library/sys.rst
8675
--- a/Doc/library/sys.rst
8676
+++ b/Doc/library/sys.rst
8677
@@ -121,6 +121,15 @@
8678
Use ``'backslashreplace'`` error handler on :exc:`UnicodeEncodeError`.
8681
+.. data:: dont_write_bytecode
8683
+ If this is true, Python won't try to write ``.pyc`` or ``.pyo`` files on the
8684
+ import of source modules. This value is initially set to ``True`` or
8685
+ ``False`` depending on the :option:`-B` command line option and the
8686
+ :envvar:`PYTHONDONTWRITEBYTECODE` environment variable, but you can set it
8687
+ yourself to control bytecode file generation.
8690
.. function:: excepthook(type, value, traceback)
8692
This function prints out a given traceback and exception to ``sys.stderr``.
8693
@@ -185,16 +194,18 @@
8694
Python files are installed; by default, this is also ``'/usr/local'``. This can
8695
be set at build time with the ``--exec-prefix`` argument to the
8696
:program:`configure` script. Specifically, all configuration files (e.g. the
8697
- :file:`pyconfig.h` header file) are installed in the directory ``exec_prefix +
8698
- '/lib/pythonversion/config'``, and shared library modules are installed in
8699
- ``exec_prefix + '/lib/pythonversion/lib-dynload'``, where *version* is equal to
8701
+ :file:`pyconfig.h` header file) are installed in the directory
8702
+ :file:`{exec_prefix}/lib/python{X.Y}/config', and shared library modules are
8703
+ installed in :file:`{exec_prefix}/lib/python{X.Y}/lib-dynload`, where *X.Y*
8704
+ is the version number of Python, for example ``3.2``.
8707
.. data:: executable
8709
- A string giving the name of the executable binary for the Python interpreter, on
8710
- systems where this makes sense.
8711
+ A string giving the absolute path of the executable binary for the Python
8712
+ interpreter, on systems where this makes sense. If Python is unable to retrieve
8713
+ the real path to its executable, :data:`sys.executable` will be an empty string
8717
.. function:: exit([arg])
8718
@@ -287,8 +298,12 @@
8719
+---------------------+----------------+--------------------------------------------------+
8720
| :const:`radix` | FLT_RADIX | radix of exponent representation |
8721
+---------------------+----------------+--------------------------------------------------+
8722
- | :const:`rounds` | FLT_ROUNDS | constant representing rounding mode |
8723
- | | | used for arithmetic operations |
8724
+ | :const:`rounds` | FLT_ROUNDS | integer constant representing the rounding mode |
8725
+ | | | used for arithmetic operations. This reflects |
8726
+ | | | the value of the system FLT_ROUNDS macro at |
8727
+ | | | interpreter startup time. See section 5.2.4.2.2 |
8728
+ | | | of the C99 standard for an explanation of the |
8729
+ | | | possible values and their meanings. |
8730
+---------------------+----------------+--------------------------------------------------+
8732
The attribute :attr:`sys.float_info.dig` needs further explanation. If
8733
@@ -743,10 +758,10 @@
8734
independent Python files are installed; by default, this is the string
8735
``'/usr/local'``. This can be set at build time with the ``--prefix``
8736
argument to the :program:`configure` script. The main collection of Python
8737
- library modules is installed in the directory ``prefix + '/lib/pythonversion'``
8738
+ library modules is installed in the directory :file:`{prefix}/lib/python{X.Y}``
8739
while the platform independent header files (all except :file:`pyconfig.h`) are
8740
- stored in ``prefix + '/include/pythonversion'``, where *version* is equal to
8742
+ stored in :file:`{prefix}/include/python{X.Y}``, where *X.Y* is the version
8743
+ number of Python, for example ``3.2``.
8747
@@ -764,15 +779,6 @@
8748
implement a dynamic prompt.
8751
-.. data:: dont_write_bytecode
8753
- If this is true, Python won't try to write ``.pyc`` or ``.pyo`` files on the
8754
- import of source modules. This value is initially set to ``True`` or ``False``
8755
- depending on the ``-B`` command line option and the ``PYTHONDONTWRITEBYTECODE``
8756
- environment variable, but you can set it yourself to control bytecode file
8760
.. function:: setcheckinterval(interval)
8762
Set the interpreter's "check interval". This integer value determines how often
8763
@@ -930,31 +936,42 @@
8767
- :term:`File objects <file object>` corresponding to the interpreter's standard
8768
- input, output and error streams. ``stdin`` is used for all interpreter input
8769
- except for scripts but including calls to :func:`input`. ``stdout`` is used
8770
- for the output of :func:`print` and :term:`expression` statements and for the
8771
- prompts of :func:`input`. The interpreter's own prompts
8772
- and (almost all of) its error messages go to ``stderr``. ``stdout`` and
8773
- ``stderr`` needn't be built-in file objects: any object is acceptable as long
8774
- as it has a :meth:`write` method that takes a string argument. (Changing these
8775
- objects doesn't affect the standard I/O streams of processes executed by
8776
- :func:`os.popen`, :func:`os.system` or the :func:`exec\*` family of functions in
8777
- the :mod:`os` module.)
8778
+ :term:`File objects <file object>` used by the interpreter for standard
8779
+ input, output and errors:
8781
- The standard streams are in text mode by default. To write or read binary
8782
- data to these, use the underlying binary buffer. For example, to write bytes
8783
- to :data:`stdout`, use ``sys.stdout.buffer.write(b'abc')``. Using
8784
- :meth:`io.TextIOBase.detach` streams can be made binary by default. This
8785
+ * ``stdin`` is used for all interactive input (including calls to
8787
+ * ``stdout`` is used for the output of :func:`print` and :term:`expression`
8788
+ statements and for the prompts of :func:`input`;
8789
+ * The interpreter's own prompts and its error messages go to ``stderr``.
8791
+ By default, these streams are regular text streams as returned by the
8792
+ :func:`open` function. Their parameters are chosen as follows:
8794
+ * The character encoding is platform-dependent. Under Windows, if the stream
8795
+ is interactive (that is, if its :meth:`isatty` method returns True), the
8796
+ console codepage is used, otherwise the ANSI code page. Under other
8797
+ platforms, the locale encoding is used (see :meth:`locale.getpreferredencoding`).
8799
+ Under all platforms though, you can override this value by setting the
8800
+ :envvar:`PYTHONIOENCODING` environment variable.
8802
+ * When interactive, standard streams are line-buffered. Otherwise, they
8803
+ are block-buffered like regular text files. You can override this
8804
+ value with the :option:`-u` command-line option.
8806
+ To write or read binary data from/to the standard streams, use the
8807
+ underlying binary :data:`~io.TextIOBase.buffer`. For example, to write
8808
+ bytes to :data:`stdout`, use ``sys.stdout.buffer.write(b'abc')``. Using
8809
+ :meth:`io.TextIOBase.detach`, streams can be made binary by default. This
8810
function sets :data:`stdin` and :data:`stdout` to binary::
8812
def make_streams_binary():
8813
sys.stdin = sys.stdin.detach()
8814
sys.stdout = sys.stdout.detach()
8816
- Note that the streams can be replaced with objects (like
8817
- :class:`io.StringIO`) that do not support the
8818
- :attr:`~io.BufferedIOBase.buffer` attribute or the
8819
+ Note that the streams may be replaced with objects (like :class:`io.StringIO`)
8820
+ that do not support the :attr:`~io.BufferedIOBase.buffer` attribute or the
8821
:meth:`~io.BufferedIOBase.detach` method and can raise :exc:`AttributeError`
8822
or :exc:`io.UnsupportedOperation`.
8824
diff -r 137e45f15c0b Doc/library/sysconfig.rst
8825
--- a/Doc/library/sysconfig.rst
8826
+++ b/Doc/library/sysconfig.rst
8829
.. module:: sysconfig
8830
:synopsis: Python's configuration information
8831
-.. moduleauthor:: Tarek Ziade <tarek@ziade.org>
8832
-.. sectionauthor:: Tarek Ziade <tarek@ziade.org>
8833
+.. moduleauthor:: Tarek Ziadé <tarek@ziade.org>
8834
+.. sectionauthor:: Tarek Ziadé <tarek@ziade.org>
8837
single: configuration information
8839
+.. versionadded:: 3.2
8841
**Source code:** :source:`Lib/sysconfig.py`
8843
-.. versionadded:: 3.2
8847
The :mod:`sysconfig` module provides access to Python's configuration
8849
one may call this function and get the default value.
8851
If *scheme* is provided, it must be a value from the list returned by
8852
- :func:`get_path_names`. Otherwise, the default scheme for the current
8853
+ :func:`get_scheme_names`. Otherwise, the default scheme for the current
8856
If *vars* is provided, it must be a dictionary of variables that will update
8857
diff -r 137e45f15c0b Doc/library/syslog.rst
8858
--- a/Doc/library/syslog.rst
8859
+++ b/Doc/library/syslog.rst
8861
``openlog()`` will be called with no arguments.
8864
-.. function:: openlog([ident[, logopt[, facility]]])
8865
+.. function:: openlog([ident[, logoption[, facility]]])
8867
Logging options of subsequent :func:`syslog` calls can be set by calling
8868
:func:`openlog`. :func:`syslog` will call :func:`openlog` with no arguments
8871
The optional *ident* keyword argument is a string which is prepended to every
8872
message, and defaults to ``sys.argv[0]`` with leading path components
8873
- stripped. The optional *logopt* keyword argument (default is 0) is a bit
8874
+ stripped. The optional *logoption* keyword argument (default is 0) is a bit
8875
field -- see below for possible values to combine. The optional *facility*
8876
keyword argument (default is :const:`LOG_USER`) sets the default facility for
8877
messages which do not have a facility explicitly encoded.
8879
logged messages, and write the messages to the destination facility used for
8882
- syslog.openlog(logopt=syslog.LOG_PID, facility=syslog.LOG_MAIL)
8883
+ syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_MAIL)
8884
syslog.syslog('E-mail processing initiated...')
8885
diff -r 137e45f15c0b Doc/library/tarfile.rst
8886
--- a/Doc/library/tarfile.rst
8887
+++ b/Doc/library/tarfile.rst
8890
The :mod:`tarfile` module makes it possible to read and write tar
8891
archives, including those using gzip or bz2 compression.
8892
-(:file:`.zip` files can be read and written using the :mod:`zipfile` module.)
8893
+Use the :mod:`zipfile` module to read or write :file:`.zip` files, or the
8894
+higher-level functions in :ref:`shutil <archiving-operations>`.
8896
Some facts and figures:
8898
@@ -101,10 +102,10 @@
8899
+-------------+--------------------------------------------+
8900
| ``'w|'`` | Open an uncompressed *stream* for writing. |
8901
+-------------+--------------------------------------------+
8902
- | ``'w|gz'`` | Open an gzip compressed *stream* for |
8903
+ | ``'w|gz'`` | Open a gzip compressed *stream* for |
8905
+-------------+--------------------------------------------+
8906
- | ``'w|bz2'`` | Open an bzip2 compressed *stream* for |
8907
+ | ``'w|bz2'`` | Open a bzip2 compressed *stream* for |
8909
+-------------+--------------------------------------------+
8911
diff -r 137e45f15c0b Doc/library/threading.rst
8912
--- a/Doc/library/threading.rst
8913
+++ b/Doc/library/threading.rst
8914
@@ -634,20 +634,21 @@
8916
.. versionadded:: 3.2
8918
- .. method:: notify()
8919
+ .. method:: notify(n=1)
8921
- Wake up a thread waiting on this condition, if any. If the calling thread
8922
- has not acquired the lock when this method is called, a
8923
+ By default, wake up one thread waiting on this condition, if any. If the
8924
+ calling thread has not acquired the lock when this method is called, a
8925
:exc:`RuntimeError` is raised.
8927
- This method wakes up one of the threads waiting for the condition
8928
- variable, if any are waiting; it is a no-op if no threads are waiting.
8929
+ This method wakes up at most *n* of the threads waiting for the condition
8930
+ variable; it is a no-op if no threads are waiting.
8932
- The current implementation wakes up exactly one thread, if any are
8933
- waiting. However, it's not safe to rely on this behavior. A future,
8934
- optimized implementation may occasionally wake up more than one thread.
8935
+ The current implementation wakes up exactly *n* threads, if at least *n*
8936
+ threads are waiting. However, it's not safe to rely on this behavior.
8937
+ A future, optimized implementation may occasionally wake up more than
8940
- Note: the awakened thread does not actually return from its :meth:`wait`
8941
+ Note: an awakened thread does not actually return from its :meth:`wait`
8942
call until it can reacquire the lock. Since :meth:`notify` does not
8943
release the lock, its caller should.
8945
@@ -781,8 +782,10 @@
8946
floating point number specifying a timeout for the operation in seconds
8947
(or fractions thereof).
8949
- This method returns the internal flag on exit, so it will always return
8950
- ``True`` except if a timeout is given and the operation times out.
8951
+ This method returns true if and only if the internal flag has been set to
8952
+ true, either before the wait call or after the wait starts, so it will
8953
+ always return ``True`` except if a timeout is given and the operation
8956
.. versionchanged:: 3.1
8957
Previously, the method always returned ``None``.
8960
Pass the barrier. When all the threads party to the barrier have called
8961
this function, they are all released simultaneously. If a *timeout* is
8962
- provided, is is used in preference to any that was supplied to the class
8963
+ provided, it is used in preference to any that was supplied to the class
8966
The return value is an integer in the range 0 to *parties* -- 1, different
8967
diff -r 137e45f15c0b Doc/library/tkinter.ttk.rst
8968
--- a/Doc/library/tkinter.ttk.rst
8969
+++ b/Doc/library/tkinter.ttk.rst
8970
@@ -1240,7 +1240,7 @@
8971
*layoutspec*, if specified, is expected to be a list or some other
8972
sequence type (excluding strings), where each item should be a tuple and
8973
the first item is the layout name and the second item should have the
8974
- format described described in `Layouts`_.
8975
+ format described in `Layouts`_.
8977
To understand the format, see the following example (it is not
8978
intended to do anything useful)::
8979
@@ -1291,7 +1291,7 @@
8982
Specifies how the image is placed within the final parcel. spec
8983
- contains zero or more characters “n”, “s”, “w”, or “e”.
8984
+ contains zero or more characters "n", "s", "w", or "e".
8987
Specifies a minimum width for the element. If less than zero, the
8988
diff -r 137e45f15c0b Doc/library/token.rst
8989
--- a/Doc/library/token.rst
8990
+++ b/Doc/library/token.rst
9008
diff -r 137e45f15c0b Doc/library/tokenize.rst
9009
--- a/Doc/library/tokenize.rst
9010
+++ b/Doc/library/tokenize.rst
9012
as well, making it useful for implementing "pretty-printers," including
9013
colorizers for on-screen displays.
9015
+To simplify token stream handling, all :ref:`operators` and :ref:`delimiters`
9016
+tokens are returned using the generic :data:`token.OP` token type. The exact
9017
+type can be determined by checking the token ``string`` field on the
9018
+:term:`named tuple` returned from :func:`tokenize.tokenize` for the character
9019
+sequence that identifies a specific operator token.
9021
The primary entry point is a :term:`generator`:
9023
.. function:: tokenize(readline)
9024
diff -r 137e45f15c0b Doc/library/turtle.rst
9025
--- a/Doc/library/turtle.rst
9026
+++ b/Doc/library/turtle.rst
9028
| :func:`onkeypress`
9029
| :func:`onclick` | :func:`onscreenclick`
9031
- | :func:`mainloop`
9032
+ | :func:`mainloop` | :func:`done`
9034
Settings and special methods
9036
@@ -1773,6 +1773,7 @@
9039
.. function:: mainloop()
9042
Starts event loop - calling Tkinter's mainloop function.
9043
Must be the last statement in a turtle graphics program.
9044
diff -r 137e45f15c0b Doc/library/unicodedata.rst
9045
--- a/Doc/library/unicodedata.rst
9046
+++ b/Doc/library/unicodedata.rst
9048
based on the definition of canonical equivalence and compatibility equivalence.
9049
In Unicode, several characters can be expressed in various way. For example, the
9050
character U+00C7 (LATIN CAPITAL LETTER C WITH CEDILLA) can also be expressed as
9051
- the sequence U+0327 (COMBINING CEDILLA) U+0043 (LATIN CAPITAL LETTER C).
9052
+ the sequence U+0043 (LATIN CAPITAL LETTER C) U+0327 (COMBINING CEDILLA).
9054
For each character, there are two normal forms: normal form C and normal form D.
9055
Normal form D (NFD) is also known as canonical decomposition, and translates
9056
diff -r 137e45f15c0b Doc/library/unittest.rst
9057
--- a/Doc/library/unittest.rst
9058
+++ b/Doc/library/unittest.rst
9061
As a shortcut, ``python -m unittest`` is the equivalent of
9062
``python -m unittest discover``. If you want to pass arguments to test
9063
- discovery the `discover` sub-command must be used explicitly.
9064
+ discovery the ``discover`` sub-command must be used explicitly.
9066
The ``discover`` sub-command has the following options:
9068
@@ -305,11 +305,11 @@
9070
.. cmdoption:: -s directory
9072
- Directory to start discovery ('.' default)
9073
+ Directory to start discovery (``.`` default)
9075
.. cmdoption:: -p pattern
9077
- Pattern to match test files ('test*.py' default)
9078
+ Pattern to match test files (``test*.py`` default)
9080
.. cmdoption:: -t directory
9083
widget = Widget('The widget')
9084
self.assertEqual(widget.size(), (50, 50), 'incorrect default size')
9086
-Note that in order to test something, we use the one of the :meth:`assert\*`
9087
+Note that in order to test something, we use one of the :meth:`assert\*`
9088
methods provided by the :class:`TestCase` base class. If the test fails, an
9089
exception will be raised, and :mod:`unittest` will identify the test case as a
9090
:dfn:`failure`. Any other exceptions will be treated as :dfn:`errors`. This
9093
.. versionchanged:: 3.2
9094
:class:`TestCase` can be instantiated successfully without providing a method
9095
- name. This makes it easier to experiment with `TestCase` from the
9096
+ name. This makes it easier to experiment with :class:`TestCase` from the
9097
interactive interpreter.
9099
*methodName* defaults to :meth:`runTest`.
9100
@@ -869,13 +869,13 @@
9102
In addition, if *first* and *second* are the exact same type and one of
9103
list, tuple, dict, set, frozenset or str or any type that a subclass
9104
- registers with :meth:`addTypeEqualityFunc` the type specific equality
9105
+ registers with :meth:`addTypeEqualityFunc` the type-specific equality
9106
function will be called in order to generate a more useful default
9107
error message (see also the :ref:`list of type-specific methods
9108
<type-specific-methods>`).
9110
.. versionchanged:: 3.1
9111
- Added the automatic calling of type specific equality function.
9112
+ Added the automatic calling of type-specific equality function.
9114
.. versionchanged:: 3.2
9115
:meth:`assertMultiLineEqual` added as the default type equality
9118
Test that *obj* is (or is not) an instance of *cls* (which can be a
9119
class or a tuple of classes, as supported by :func:`isinstance`).
9120
+ To check for the exact type, use :func:`assertIs(type(obj), cls) <assertIs>`.
9122
.. versionadded:: 3.2
9124
@@ -940,17 +941,17 @@
9125
+---------------------------------------------------------+--------------------------------------+------------+
9126
| Method | Checks that | New in |
9127
+=========================================================+======================================+============+
9128
- | :meth:`assertRaises(exc, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises `exc` | |
9129
+ | :meth:`assertRaises(exc, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises *exc* | |
9130
| <TestCase.assertRaises>` | | |
9131
+---------------------------------------------------------+--------------------------------------+------------+
9132
- | :meth:`assertRaisesRegex(exc, re, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises `exc` | 3.1 |
9133
- | <TestCase.assertRaisesRegex>` | and the message matches `re` | |
9134
+ | :meth:`assertRaisesRegex(exc, re, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises *exc* | 3.1 |
9135
+ | <TestCase.assertRaisesRegex>` | and the message matches *re* | |
9136
+---------------------------------------------------------+--------------------------------------+------------+
9137
- | :meth:`assertWarns(warn, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises `warn` | 3.2 |
9138
+ | :meth:`assertWarns(warn, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises *warn* | 3.2 |
9139
| <TestCase.assertWarns>` | | |
9140
+---------------------------------------------------------+--------------------------------------+------------+
9141
- | :meth:`assertWarnsRegex(warn, re, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises `warn` | 3.2 |
9142
- | <TestCase.assertWarnsRegex>` | and the message matches `re` | |
9143
+ | :meth:`assertWarnsRegex(warn, re, fun, *args, **kwds) | ``fun(*args, **kwds)`` raises *warn* | 3.2 |
9144
+ | <TestCase.assertWarnsRegex>` | and the message matches *re* | |
9145
+---------------------------------------------------------+--------------------------------------+------------+
9147
.. method:: assertRaises(exception, callable, *args, **kwds)
9148
@@ -1092,7 +1093,7 @@
9149
| :meth:`assertNotRegex(s, re) | ``not regex.search(s)`` | 3.2 |
9150
| <TestCase.assertNotRegex>` | | |
9151
+---------------------------------------+--------------------------------+--------------+
9152
- | :meth:`assertCountEqual(a, b) | `a` and `b` have the same | 3.2 |
9153
+ | :meth:`assertCountEqual(a, b) | *a* and *b* have the same | 3.2 |
9154
| <TestCase.assertCountEqual>` | elements in the same number, | |
9155
| | regardless of their order | |
9156
+---------------------------------------+--------------------------------+--------------+
9157
@@ -1887,7 +1888,7 @@
9158
.. class:: TextTestRunner(stream=None, descriptions=True, verbosity=1, runnerclass=None, warnings=None)
9160
A basic test runner implementation that outputs results to a stream. If *stream*
9161
- is `None`, the default, `sys.stderr` is used as the output stream. This class
9162
+ is ``None``, the default, :data:`sys.stderr` is used as the output stream. This class
9163
has a few configurable parameters, but is essentially very simple. Graphical
9164
applications which run test suites should provide alternate implementations.
9166
@@ -1904,7 +1905,7 @@
9167
Added the ``warnings`` argument.
9169
.. versionchanged:: 3.2
9170
- The default stream is set to `sys.stderr` at instantiation time rather
9171
+ The default stream is set to :data:`sys.stderr` at instantiation time rather
9174
.. method:: _makeResult()
9175
diff -r 137e45f15c0b Doc/library/urllib.parse.rst
9176
--- a/Doc/library/urllib.parse.rst
9177
+++ b/Doc/library/urllib.parse.rst
9182
+**Source code:** :source:`Lib/urllib/parse.py`
9186
This module defines a standard interface to break Uniform Resource Locator (URL)
9187
strings up in components (addressing scheme, network location, path etc.), to
9188
combine the components back into a URL string, and to convert a "relative URL"
9189
diff -r 137e45f15c0b Doc/library/urllib.request.rst
9190
--- a/Doc/library/urllib.request.rst
9191
+++ b/Doc/library/urllib.request.rst
9192
@@ -124,10 +124,10 @@
9193
.. function:: getproxies()
9195
This helper function returns a dictionary of scheme to proxy server URL
9196
- mappings. It scans the environment for variables named ``<scheme>_proxy``
9197
- for all operating systems first, and when it cannot find it, looks for proxy
9198
- information from Mac OSX System Configuration for Mac OS X and Windows
9199
- Systems Registry for Windows.
9200
+ mappings. It scans the environment for variables named ``<scheme>_proxy``,
9201
+ in a case insensitive approach, for all operating systems first, and when it
9202
+ cannot find it, looks for proxy information from Mac OSX System
9203
+ Configuration for Mac OS X and Windows Systems Registry for Windows.
9206
The following classes are provided:
9207
@@ -1257,11 +1257,11 @@
9208
pair: HTTP; protocol
9211
-* Currently, only the following protocols are supported: HTTP, (versions 0.9 and
9212
- 1.0), FTP, and local files.
9213
+* Currently, only the following protocols are supported: HTTP (versions 0.9 and
9214
+ 1.0), FTP, and local files.
9216
-* The caching feature of :func:`urlretrieve` has been disabled until I find the
9217
- time to hack proper processing of Expiration time headers.
9218
+* The caching feature of :func:`urlretrieve` has been disabled until someone
9219
+ finds the time to hack proper processing of Expiration time headers.
9221
* There should be a function to query whether a particular URL is in the cache.
9223
diff -r 137e45f15c0b Doc/library/uuid.rst
9224
--- a/Doc/library/uuid.rst
9225
+++ b/Doc/library/uuid.rst
9226
@@ -222,34 +222,34 @@
9230
- # make a UUID based on the host ID and current time
9231
+ >>> # make a UUID based on the host ID and current time
9233
UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')
9235
- # make a UUID using an MD5 hash of a namespace UUID and a name
9236
+ >>> # make a UUID using an MD5 hash of a namespace UUID and a name
9237
>>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
9238
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')
9240
- # make a random UUID
9241
+ >>> # make a random UUID
9243
UUID('16fd2706-8baf-433b-82eb-8c7fada847da')
9245
- # make a UUID using a SHA-1 hash of a namespace UUID and a name
9246
+ >>> # make a UUID using a SHA-1 hash of a namespace UUID and a name
9247
>>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
9248
UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')
9250
- # make a UUID from a string of hex digits (braces and hyphens ignored)
9251
+ >>> # make a UUID from a string of hex digits (braces and hyphens ignored)
9252
>>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}')
9254
- # convert a UUID to a string of hex digits in standard form
9255
+ >>> # convert a UUID to a string of hex digits in standard form
9257
'00010203-0405-0607-0809-0a0b0c0d0e0f'
9259
- # get the raw 16 bytes of the UUID
9260
+ >>> # get the raw 16 bytes of the UUID
9262
b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
9264
- # make a UUID from a 16-byte string
9265
+ >>> # make a UUID from a 16-byte string
9266
>>> uuid.UUID(bytes=x.bytes)
9267
UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
9269
diff -r 137e45f15c0b Doc/library/xml.etree.elementtree.rst
9270
--- a/Doc/library/xml.etree.elementtree.rst
9271
+++ b/Doc/library/xml.etree.elementtree.rst
9273
elements whose tag equals *tag* are returned from the iterator. If the
9274
tree structure is modified during iteration, the result is undefined.
9276
+ .. versionadded:: 3.2
9279
.. method:: iterfind(match)
9281
diff -r 137e45f15c0b Doc/library/xmlrpc.client.rst
9282
--- a/Doc/library/xmlrpc.client.rst
9283
+++ b/Doc/library/xmlrpc.client.rst
9288
-In http://www.xmlrpc.com/discuss/msgReader%241208, an approach is presented to
9289
-encapsulate multiple calls to a remote server into a single request.
9290
+The :class:`MultiCall` object provides a way to encapsulate multiple calls to a
9291
+remote server into a single request [#]_.
9294
.. class:: MultiCall(server)
9295
@@ -534,3 +534,10 @@
9296
See :ref:`simplexmlrpcserver-example`.
9299
+.. rubric:: Footnotes
9301
+.. [#] This approach has been first presented in `a discussion on xmlrpc.com
9302
+ <http://web.archive.org/web/20060624230303/http://www.xmlrpc.com/discuss/msgReader$1208?mode=topic>`_.
9303
+.. the link now points to webarchive since the one at
9304
+.. http://www.xmlrpc.com/discuss/msgReader%241208 is broken (and webadmin
9306
diff -r 137e45f15c0b Doc/library/zipfile.rst
9307
--- a/Doc/library/zipfile.rst
9308
+++ b/Doc/library/zipfile.rst
9310
create an encrypted file. Decryption is extremely slow as it is
9311
implemented in native Python rather than C.
9313
-For other archive formats, see the :mod:`bz2`, :mod:`gzip`, and
9314
-:mod:`tarfile` modules.
9316
The module defines the following items:
9318
.. exception:: BadZipFile
9320
- The error raised for bad ZIP files (old name: ``zipfile.error``).
9321
+ The error raised for bad ZIP files.
9323
.. versionadded:: 3.2
9326
.. exception:: BadZipfile
9328
- This is an alias for :exc:`BadZipFile` that exists for compatibility with
9329
- Python versions prior to 3.2. Usage is deprecated.
9330
+ Alias of :exc:`BadZipFile`, for compatibility with older Python versions.
9332
+ .. deprecated:: 3.2
9335
.. exception:: LargeZipFile
9337
+-------+--------------------------+
9339
+=======+==========================+
9341
+ | ``0`` | Year (>= 1980) |
9342
+-------+--------------------------+
9343
| ``1`` | Month (one-based) |
9344
+-------+--------------------------+
9345
@@ -410,6 +408,10 @@
9346
| ``5`` | Seconds (zero-based) |
9347
+-------+--------------------------+
9351
+ The ZIP file format does not support timestamps before 1980.
9354
.. attribute:: ZipInfo.compress_type
9356
diff -r 137e45f15c0b Doc/library/zlib.rst
9357
--- a/Doc/library/zlib.rst
9358
+++ b/Doc/library/zlib.rst
9360
consult the zlib manual at http://www.zlib.net/manual.html for authoritative
9363
-For reading and writing ``.gz`` files see the :mod:`gzip` module. For
9364
-other archive formats, see the :mod:`bz2`, :mod:`zipfile`, and
9365
-:mod:`tarfile` modules.
9366
+For reading and writing ``.gz`` files see the :mod:`gzip` module.
9368
The available exception and functions in this module are:
9370
diff -r 137e45f15c0b Doc/license.rst
9371
--- a/Doc/license.rst
9372
+++ b/Doc/license.rst
9374
analyze, test, perform and/or display publicly, prepare derivative works,
9375
distribute, and otherwise use Python |release| alone or in any derivative
9376
version, provided, however, that PSF's License Agreement and PSF's notice of
9377
- copyright, i.e., "Copyright © 2001-2011 Python Software Foundation; All Rights
9378
+ copyright, i.e., "Copyright © 2001-2012 Python Software Foundation; All Rights
9379
Reserved" are retained in Python |release| alone or in any derivative version
9380
prepared by Licensee.
9382
diff -r 137e45f15c0b Doc/reference/compound_stmts.rst
9383
--- a/Doc/reference/compound_stmts.rst
9384
+++ b/Doc/reference/compound_stmts.rst
9386
is executed. If there is a saved exception, it is re-raised at the end of the
9387
:keyword:`finally` clause. If the :keyword:`finally` clause raises another
9388
exception or executes a :keyword:`return` or :keyword:`break` statement, the
9389
-saved exception is lost. The exception information is not available to the
9390
-program during execution of the :keyword:`finally` clause.
9391
+saved exception is set as the context of the new exception. The exception
9392
+information is not available to the program during execution of the
9393
+:keyword:`finally` clause.
9399
funcdef: [`decorators`] "def" `funcname` "(" [`parameter_list`] ")" ["->" `expression`] ":" `suite`
9400
decorators: `decorator`+
9401
- decorator: "@" `dotted_name` ["(" [`argument_list` [","]] ")"] NEWLINE
9402
+ decorator: "@" `dotted_name` ["(" [`parameter_list` [","]] ")"] NEWLINE
9403
dotted_name: `identifier` ("." `identifier`)*
9404
parameter_list: (`defparameter` ",")*
9405
: ( "*" [`parameter`] ("," `defparameter`)*
9408
**Default parameter values are evaluated when the function definition is
9409
executed.** This means that the expression is evaluated once, when the function
9410
-is defined, and that that same "pre-computed" value is used for each call. This
9411
+is defined, and that the same "pre-computed" value is used for each call. This
9412
is especially important to understand when a default parameter is a mutable
9413
object, such as a list or a dictionary: if the function modifies the object
9414
(e.g. by appending an item to a list), the default value is in effect modified.
9418
classdef: [`decorators`] "class" `classname` [`inheritance`] ":" `suite`
9419
- inheritance: "(" [`argument_list` [","] | `comprehension`] ")"
9420
+ inheritance: "(" [`parameter_list`] ")"
9421
classname: `identifier`
9423
A class definition is an executable statement. The inheritance list usually
9424
diff -r 137e45f15c0b Doc/reference/datamodel.rst
9425
--- a/Doc/reference/datamodel.rst
9426
+++ b/Doc/reference/datamodel.rst
9427
@@ -1157,6 +1157,14 @@
9428
.. XXX what about subclasses of string?
9431
+.. method:: object.__bytes__(self)
9433
+ .. index:: builtin: bytes
9435
+ Called by :func:`bytes` to compute a byte-string representation of an
9436
+ object. This should return a ``bytes`` object.
9439
.. method:: object.__format__(self, format_spec)
9442
diff -r 137e45f15c0b Doc/reference/introduction.rst
9443
--- a/Doc/reference/introduction.rst
9444
+++ b/Doc/reference/introduction.rst
9446
An alternate Python for .NET. Unlike Python.NET, this is a complete Python
9447
implementation that generates IL, and compiles Python code directly to .NET
9448
assemblies. It was created by Jim Hugunin, the original creator of Jython. For
9449
- more information, see `the IronPython website <http://www.ironpython.com/>`_.
9450
+ more information, see `the IronPython website <http://www.ironpython.net/>`_.
9453
An implementation of Python written completely in Python. It supports several
9454
diff -r 137e45f15c0b Doc/reference/simple_stmts.rst
9455
--- a/Doc/reference/simple_stmts.rst
9456
+++ b/Doc/reference/simple_stmts.rst
9458
del_stmt: "del" `target_list`
9460
Deletion is recursively defined very similar to the way assignment is defined.
9461
-Rather that spelling it out in full details, here are some hints.
9462
+Rather than spelling it out in full details, here are some hints.
9464
Deletion of a target list recursively deletes each target, from left to right.
9468
If no expressions are present, :keyword:`raise` re-raises the last exception
9469
that was active in the current scope. If no exception is active in the current
9470
-scope, a :exc:`TypeError` exception is raised indicating that this is an error
9471
-(if running under IDLE, a :exc:`queue.Empty` exception is raised instead).
9472
+scope, a :exc:`RuntimeError` exception is raised indicating that this is an
9475
Otherwise, :keyword:`raise` evaluates the first expression as the exception
9476
object. It must be either a subclass or an instance of :class:`BaseException`.
9477
diff -r 137e45f15c0b Doc/reference/toplevel_components.rst
9478
--- a/Doc/reference/toplevel_components.rst
9479
+++ b/Doc/reference/toplevel_components.rst
9482
single: readline() (file method)
9484
-Note: to read 'raw' input line without interpretation, you can use the the
9485
+Note: to read 'raw' input line without interpretation, you can use the
9486
:meth:`readline` method of file objects, including ``sys.stdin``.
9488
diff -r 137e45f15c0b Doc/tools/sphinxext/indexcontent.html
9489
--- a/Doc/tools/sphinxext/indexcontent.html
9490
+++ b/Doc/tools/sphinxext/indexcontent.html
9492
<span class="linkdescr">information for installers & sys-admins</span></p>
9493
<p class="biglink"><a class="biglink" href="{{ pathto("distutils/index") }}">Distributing Python Modules</a><br/>
9494
<span class="linkdescr">sharing modules with others</span></p>
9495
- <p class="biglink"><a class="biglink" href="{{ pathto("documenting/index") }}">Documenting Python</a><br/>
9496
- <span class="linkdescr">guide for documentation authors</span></p>
9497
<p class="biglink"><a class="biglink" href="{{ pathto("faq/index") }}">FAQs</a><br/>
9498
<span class="linkdescr">frequently asked questions (with answers!)</span></p>
9500
diff -r 137e45f15c0b Doc/tools/sphinxext/layout.html
905
- The formatting operations described here are obsolete and may go away in future
906
- versions of Python. Use the new :ref:`string-formatting` in new code.
907
+ The formatting operations described here are modelled on C's printf()
908
+ syntax. They only support formatting of certain builtin types. The
909
+ use of a binary operator means that care may be needed in order to
910
+ format tuples and dictionaries correctly. As the new
911
+ :ref:`string-formatting` syntax is more flexible and handles tuples and
912
+ dictionaries naturally, it is recommended for new code. However, there
913
+ are no current plans to deprecate printf-style formatting.
915
String objects have one unique built-in operation: the ``%`` operator (modulo).
916
This is also known as the string *formatting* or *interpolation* operator.
917
diff -r 7085403daf43 Doc/library/xml.dom.minidom.rst
918
--- a/Doc/library/xml.dom.minidom.rst
919
+++ b/Doc/library/xml.dom.minidom.rst
921
Model interface. It is intended to be simpler than the full DOM and also
922
significantly smaller.
926
+ The :mod:`xml.dom.minidom` module provides an implementation of the W3C-DOM,
927
+ with an API similar to that in other programming languages. Users who are
928
+ unfamiliar with the W3C-DOM interface or who would like to write less code
929
+ for processing XML files should consider using the
930
+ :mod:`xml.etree.ElementTree` module instead.
932
DOM applications typically start by parsing some XML into a DOM. With
933
:mod:`xml.dom.minidom`, this is done through the parse functions::
935
diff -r 7085403daf43 Doc/tools/sphinxext/layout.html
9501
936
--- a/Doc/tools/sphinxext/layout.html
9502
937
+++ b/Doc/tools/sphinxext/layout.html
9505
940
{% block extrahead %}
9506
941
<link rel="shortcut icon" type="image/png" href="{{ pathto('_static/py.png', 1) }}" />
9507
+ <script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>
942
- <script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>
943
+ {% if not embedded %}<script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>{% endif %}
9510
946
{% block footer %}
9511
diff -r 137e45f15c0b Doc/tools/sphinxext/static/copybutton.js
9513
+++ b/Doc/tools/sphinxext/static/copybutton.js
9515
+$(document).ready(function() {
9516
+ /* Add a [>>>] button on the top-right corner of code samples to hide
9517
+ * the >>> and ... prompts and the output and thus make the code
9519
+ var div = $('.highlight-python .highlight,' +
9520
+ '.highlight-python3 .highlight')
9521
+ var pre = div.find('pre');
9523
+ // get the styles from the current theme
9524
+ pre.parent().parent().css('position', 'relative');
9525
+ var hide_text = 'Hide the prompts and output';
9526
+ var show_text = 'Show the prompts and output';
9527
+ var border_width = pre.css('border-top-width');
9528
+ var border_style = pre.css('border-top-style');
9529
+ var border_color = pre.css('border-top-color');
9530
+ var button_styles = {
9531
+ 'cursor':'pointer', 'position': 'absolute', 'top': '0', 'right': '0',
9532
+ 'border-color': border_color, 'border-style': border_style,
9533
+ 'border-width': border_width, 'color': border_color, 'text-size': '75%',
9534
+ 'font-family': 'monospace', 'padding-left': '0.2em', 'padding-right': '0.2em'
9537
+ // create and add the button to all the code blocks that contain >>>
9538
+ div.each(function(index) {
9539
+ var jthis = $(this);
9540
+ if (jthis.find('.gp').length > 0) {
9541
+ var button = $('<span class="copybutton">>>></span>');
9542
+ button.css(button_styles)
9543
+ button.attr('title', hide_text);
9544
+ jthis.prepend(button);
9546
+ // tracebacks (.gt) contain bare text elements that need to be
9547
+ // wrapped in a span to work with .nextUntil() (see later)
9548
+ jthis.find('pre:has(.gt)').contents().filter(function() {
9549
+ return ((this.nodeType == 3) && (this.data.trim().length > 0));
9550
+ }).wrap('<span>');
9553
+ // define the behavior of the button when it's clicked
9554
+ $('.copybutton').toggle(
9556
+ var button = $(this);
9557
+ button.parent().find('.go, .gp, .gt').hide();
9558
+ button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden');
9559
+ button.css('text-decoration', 'line-through');
9560
+ button.attr('title', show_text);
9563
+ var button = $(this);
9564
+ button.parent().find('.go, .gp, .gt').show();
9565
+ button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible');
9566
+ button.css('text-decoration', 'none');
9567
+ button.attr('title', hide_text);
9571
diff -r 137e45f15c0b Doc/tools/sphinxext/susp-ignored.csv
9572
--- a/Doc/tools/sphinxext/susp-ignored.csv
9573
+++ b/Doc/tools/sphinxext/susp-ignored.csv
9574
@@ -164,35 +164,6 @@
9575
whatsnew/2.5,,:step,[start:stop:step]
9576
whatsnew/2.5,,:stop,[start:stop:step]
9577
distutils/examples,267,`,This is the description of the ``foobar`` package.
9578
-documenting/fromlatex,39,:func,:func:`str(object)`
9579
-documenting/fromlatex,39,`,:func:`str(object)`
9580
-documenting/fromlatex,39,`,``str(object)``
9581
-documenting/fromlatex,55,.. deprecated:,.. deprecated:: 2.5
9582
-documenting/fromlatex,66,.. note:,.. note::
9583
-documenting/fromlatex,76,:samp,":samp:`open({filename}, {mode})`"
9584
-documenting/fromlatex,76,`,":samp:`open({filename}, {mode})`"
9585
-documenting/fromlatex,80,`,``'c'``
9586
-documenting/fromlatex,80,`,`Title <URL>`_
9587
-documenting/fromlatex,80,`,``code``
9588
-documenting/fromlatex,80,`,`Title <URL>`_
9589
-documenting/fromlatex,99,:file,:file:`C:\\Temp\\my.tmp`
9590
-documenting/fromlatex,99,`,:file:`C:\\Temp\\my.tmp`
9591
-documenting/fromlatex,99,`,"``open(""C:\Temp\my.tmp"")``"
9592
-documenting/fromlatex,129,.. function:,.. function:: do_foo(bar)
9593
-documenting/fromlatex,141,.. function:,".. function:: open(filename[, mode[, buffering]])"
9594
-documenting/fromlatex,152,.. function:,.. function:: foo_*
9595
-documenting/fromlatex,152,:noindex,:noindex:
9596
-documenting/fromlatex,162,.. describe:,.. describe:: a == b
9597
-documenting/fromlatex,168,.. cmdoption:,.. cmdoption:: -O
9598
-documenting/fromlatex,168,.. envvar:,.. envvar:: PYTHONINSPECT
9599
-documenting/rest,33,`,``text``
9600
-documenting/rest,47,:rolename,:rolename:`content`
9601
-documenting/rest,47,`,:rolename:`content`
9602
-documenting/rest,103,::,This is a normal text paragraph. The next paragraph is a code sample::
9603
-documenting/rest,130,`,`Link text <http://target>`_
9604
-documenting/rest,187,.. function:,.. function:: foo(x)
9605
-documenting/rest,187,:bar,:bar: no
9606
-documenting/rest,208,.. rubric:,.. rubric:: Footnotes
9607
faq/programming,,:reduce,"print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,"
9608
faq/programming,,:reduce,"Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,"
9609
faq/programming,,:chr,">=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr("
9611
howto/logging,,:logger,severity:logger name:message
9612
howto/logging,,:message,severity:logger name:message
9613
library/logging.handlers,,:port,host:port
9614
-documenting/markup,613,`,:ref:`link text <reference-label>`
9615
library/imaplib,116,:MM,"""DD-Mmm-YYYY HH:MM:SS"
9616
library/imaplib,116,:SS,"""DD-Mmm-YYYY HH:MM:SS"
9617
whatsnew/3.2,,::,"$ export PYTHONWARNINGS='ignore::RuntimeWarning::,once::UnicodeWarning::'"
9618
@@ -292,104 +262,6 @@
9619
whatsnew/3.2,,:affe,"netloc='[dead:beef:cafe:5417:affe:8FA3:deaf:feed]',"
9620
whatsnew/3.2,,:deaf,"netloc='[dead:beef:cafe:5417:affe:8FA3:deaf:feed]',"
9621
whatsnew/3.2,,:feed,"netloc='[dead:beef:cafe:5417:affe:8FA3:deaf:feed]',"
9622
-documenting/markup,33,.. sectionauthor:,.. sectionauthor:: Guido van Rossum <guido@python.org>
9623
-documenting/markup,42,:mod,:mod:`parrot` -- Dead parrot access
9624
-documenting/markup,42,`,:mod:`parrot` -- Dead parrot access
9625
-documenting/markup,42,.. module:,.. module:: parrot
9626
-documenting/markup,42,:platform,":platform: Unix, Windows"
9627
-documenting/markup,42,:synopsis,:synopsis: Analyze and reanimate dead parrots.
9628
-documenting/markup,42,.. moduleauthor:,.. moduleauthor:: Eric Cleese <eric@python.invalid>
9629
-documenting/markup,42,.. moduleauthor:,.. moduleauthor:: John Idle <john@python.invalid>
9630
-documenting/markup,88,:noindex,:noindex:
9631
-documenting/markup,95,.. function:,.. function:: spam(eggs)
9632
-documenting/markup,95,:noindex,:noindex:
9633
-documenting/markup,101,.. method:,.. method:: FileInput.input(...)
9634
-documenting/markup,121,:function,c:function
9635
-documenting/markup,121,.. c:,".. c:function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)"
9636
-documenting/markup,121,::,".. c:function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)"
9637
-documenting/markup,131,:member,c:member
9638
-documenting/markup,131,.. c:,.. c:member:: PyObject* PyTypeObject.tp_bases
9639
-documenting/markup,131,::,.. c:member:: PyObject* PyTypeObject.tp_bases
9640
-documenting/markup,139,:macro,c:macro
9641
-documenting/markup,143,:type,c:type
9642
-documenting/markup,150,:var,c:var
9643
-documenting/markup,150,.. cvar:,.. cvar:: PyObject* PyClass_Type
9644
-documenting/markup,179,.. function:,".. function:: repeat([repeat=3[, number=1000000]])"
9645
-documenting/markup,210,.. decorator:,.. decorator:: removename
9646
-documenting/markup,210,.. decorator:,.. decorator:: setnewname(name)
9647
-documenting/markup,210,:func,:func:
9648
-documenting/markup,237,.. class:,.. class:: Spam
9649
-documenting/markup,237,.. data:,.. data:: ham
9650
-documenting/markup,237,.. data:,.. data:: Spam.eggs
9651
-documenting/markup,250,:meth,:meth:
9652
-documenting/markup,263,.. cmdoption:,.. cmdoption:: -m <module>
9653
-documenting/markup,281,.. describe:,.. describe:: opcode
9654
-documenting/markup,310,.. highlightlang:,.. highlightlang:: c
9655
-documenting/markup,330,.. literalinclude:,.. literalinclude:: example.py
9656
-documenting/markup,345,:rolename,:rolename:`content`
9657
-documenting/markup,345,`,:rolename:`content`
9658
-documenting/markup,350,:role,:role:`title <target>`
9659
-documenting/markup,350,`,:role:`title <target>`
9660
-documenting/markup,356,:meth,:meth:`~Queue.Queue.get`
9661
-documenting/markup,356,`,:meth:`~Queue.Queue.get`
9662
-documenting/markup,404,:func,:func:`filter`
9663
-documenting/markup,404,`,:func:`filter`
9664
-documenting/markup,404,:func,:func:`foo.filter`
9665
-documenting/markup,404,`,:func:`foo.filter`
9666
-documenting/markup,410,:func,:func:`open`
9667
-documenting/markup,410,`,:func:`open`
9668
-documenting/markup,410,:func,:func:`.open`
9669
-documenting/markup,410,`,:func:`.open`
9670
-documenting/markup,426,:data,c:data
9671
-documenting/markup,430,:func,c:func
9672
-documenting/markup,434,:macro,c:macro
9673
-documenting/markup,438,:type,c:type
9674
-documenting/markup,443,:member,c:member
9675
-documenting/markup,493,:file,... is installed in :file:`/usr/lib/python2.{x}/site-packages` ...
9676
-documenting/markup,493,`,... is installed in :file:`/usr/lib/python2.{x}/site-packages` ...
9677
-documenting/markup,512,:kbd,:kbd:`C-x C-f`
9678
-documenting/markup,512,`,:kbd:`C-x C-f`
9679
-documenting/markup,512,:kbd,:kbd:`Control-x Control-f`
9680
-documenting/markup,512,`,:kbd:`Control-x Control-f`
9681
-documenting/markup,526,:mailheader,:mailheader:`Content-Type`
9682
-documenting/markup,526,`,:mailheader:`Content-Type`
9683
-documenting/markup,535,:manpage,:manpage:`ls(1)`
9684
-documenting/markup,535,`,:manpage:`ls(1)`
9685
-documenting/markup,551,:menuselection,:menuselection:`Start --> Programs`
9686
-documenting/markup,551,`,:menuselection:`Start --> Programs`
9687
-documenting/markup,566,`,``code``
9688
-documenting/markup,585,:file,:file:
9689
-documenting/markup,585,`,``code``
9690
-documenting/markup,615,:ref,:ref:`label-name`
9691
-documenting/markup,615,`,:ref:`label-name`
9692
-documenting/markup,619,:ref,"It refers to the section itself, see :ref:`my-reference-label`."
9693
-documenting/markup,619,`,"It refers to the section itself, see :ref:`my-reference-label`."
9694
-documenting/markup,628,:ref,:ref:
9695
-documenting/markup,630,:ref,:ref:`link text <reference-label>`
9696
-documenting/markup,630,`,:ref:`link text <reference-label>`
9697
-documenting/markup,651,.. note:,.. note::
9698
-documenting/markup,678,.. versionadded:,.. versionadded:: 3.1
9699
-documenting/markup,703,::,.. impl-detail::
9700
-documenting/markup,703,::,.. impl-detail:: This shortly mentions an implementation detail.
9701
-documenting/markup,723,.. seealso:,.. seealso::
9702
-documenting/markup,723,:mod,Module :mod:`zipfile`
9703
-documenting/markup,723,`,Module :mod:`zipfile`
9704
-documenting/markup,723,:mod,Documentation of the :mod:`zipfile` standard module.
9705
-documenting/markup,723,`,Documentation of the :mod:`zipfile` standard module.
9706
-documenting/markup,723,`,"`GNU tar manual, Basic Tar Format <http://link>`_"
9707
-documenting/markup,737,.. centered:,.. centered::
9708
-documenting/markup,782,.. toctree:,.. toctree::
9709
-documenting/markup,782,:maxdepth,:maxdepth: 2
9710
-documenting/markup,798,.. index:,.. index::
9711
-documenting/markup,828,.. index:,".. index:: BNF, grammar, syntax, notation"
9712
-documenting/markup,859,`,"unaryneg ::= ""-"" `integer`"
9713
-documenting/markup,864,.. productionlist:,.. productionlist::
9714
-documenting/markup,864,`,"try1_stmt: ""try"" "":"" `suite`"
9715
-documenting/markup,864,`,": (""except"" [`expression` ["","" `target`]] "":"" `suite`)+"
9716
-documenting/markup,864,`,": [""else"" "":"" `suite`]"
9717
-documenting/markup,864,`,": [""finally"" "":"" `suite`]"
9718
-documenting/markup,864,`,"try2_stmt: ""try"" "":"" `suite`"
9719
-documenting/markup,864,`,": ""finally"" "":"" `suite`"
9720
library/pprint,209,::,"'classifiers': ['Development Status :: 4 - Beta',"
9721
library/pprint,209,::,"'Intended Audience :: Developers',"
9722
library/pprint,209,::,"'License :: OSI Approved :: MIT License',"
9723
diff -r 137e45f15c0b Doc/tutorial/classes.rst
947
diff -r 7085403daf43 Doc/tutorial/classes.rst
9724
948
--- a/Doc/tutorial/classes.rst
9725
949
+++ b/Doc/tutorial/classes.rst
9729
Methods may reference global names in the same way as ordinary functions. The
9730
-global scope associated with a method is the module containing the class
9731
-definition. (The class itself is never used as a global scope.) While one
9732
+global scope associated with a method is the module containing its
9733
+definition. (A class is never used as a global scope.) While one
9734
rarely encounters a good reason for using global data in a method, there are
9735
many legitimate uses of the global scope: for one thing, functions and modules
9736
imported into the global scope can be used by methods, as well as functions and
9737
diff -r 137e45f15c0b Doc/tutorial/controlflow.rst
9738
--- a/Doc/tutorial/controlflow.rst
9739
+++ b/Doc/tutorial/controlflow.rst
9744
-Functions can also be called using keyword arguments of the form ``keyword =
9745
-value``. For instance, the following function::
9746
+Functions can also be called using :term:`keyword arguments <keyword argument>`
9747
+of the form ``kwarg=value``. For instance, the following function::
9749
def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
9750
print("-- This parrot wouldn't", action, end=' ')
9751
@@ -421,26 +421,31 @@
9752
print("-- Lovely plumage, the", type)
9753
print("-- It's", state, "!")
9755
-could be called in any of the following ways::
9756
+accepts one required argument (``voltage``) and three optional arguments
9757
+(``state``, ``action``, and ``type``). This function can be called in any
9758
+of the following ways::
9761
- parrot(action = 'VOOOOOM', voltage = 1000000)
9762
- parrot('a thousand', state = 'pushing up the daisies')
9763
- parrot('a million', 'bereft of life', 'jump')
9764
+ parrot(1000) # 1 positional argument
9765
+ parrot(voltage=1000) # 1 keyword argument
9766
+ parrot(voltage=1000000, action='VOOOOOM') # 2 keyword arguments
9767
+ parrot(action='VOOOOOM', voltage=1000000) # 2 keyword arguments
9768
+ parrot('a million', 'bereft of life', 'jump') # 3 positional arguments
9769
+ parrot('a thousand', state='pushing up the daisies') # 1 positional, 1 keyword
9771
-but the following calls would all be invalid::
9772
+but all the following calls would be invalid::
9774
parrot() # required argument missing
9775
- parrot(voltage=5.0, 'dead') # non-keyword argument following keyword
9776
- parrot(110, voltage=220) # duplicate value for argument
9777
- parrot(actor='John Cleese') # unknown keyword
9778
+ parrot(voltage=5.0, 'dead') # non-keyword argument after a keyword argument
9779
+ parrot(110, voltage=220) # duplicate value for the same argument
9780
+ parrot(actor='John Cleese') # unknown keyword argument
9782
-In general, an argument list must have any positional arguments followed by any
9783
-keyword arguments, where the keywords must be chosen from the formal parameter
9784
-names. It's not important whether a formal parameter has a default value or
9785
-not. No argument may receive a value more than once --- formal parameter names
9786
-corresponding to positional arguments cannot be used as keywords in the same
9787
-calls. Here's an example that fails due to this restriction::
9788
+In a function call, keyword arguments must follow positional arguments.
9789
+All the keyword arguments passed must match one of the arguments
9790
+accepted by the function (e.g. ``actor`` is not a valid argument for the
9791
+``parrot`` function), and their order is not important. This also includes
9792
+non-optional arguments (e.g. ``parrot(voltage=1000)`` is valid too).
9793
+No argument may receive a value more than once.
9794
+Here's an example that fails due to this restriction::
9796
>>> def function(a):
9798
diff -r 137e45f15c0b Doc/tutorial/datastructures.rst
9799
--- a/Doc/tutorial/datastructures.rst
9800
+++ b/Doc/tutorial/datastructures.rst
9801
@@ -163,107 +163,137 @@
9805
-List comprehensions provide a concise way to create lists from sequences.
9806
-Common applications are to make lists where each element is the result of
9807
-some operations applied to each member of the sequence, or to create a
9808
-subsequence of those elements that satisfy a certain condition.
9809
+List comprehensions provide a concise way to create lists.
9810
+Common applications are to make new lists where each element is the result of
9811
+some operations applied to each member of another sequence or iterable, or to
9812
+create a subsequence of those elements that satisfy a certain condition.
9814
+For example, assume we want to create a list of squares, like::
9817
+ >>> for x in range(10):
9818
+ ... squares.append(x**2)
9821
+ [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
9823
+We can obtain the same result with::
9825
+ squares = [x**2 for x in range(10)]
9827
+This is also equivalent to ``squares = map(lambda x: x**2, range(10))``,
9828
+but it's more concise and readable.
9830
A list comprehension consists of brackets containing an expression followed
9831
by a :keyword:`for` clause, then zero or more :keyword:`for` or :keyword:`if`
9832
-clauses. The result will be a list resulting from evaluating the expression in
9833
-the context of the :keyword:`for` and :keyword:`if` clauses which follow it. If
9834
-the expression would evaluate to a tuple, it must be parenthesized.
9835
+clauses. The result will be a new list resulting from evaluating the expression
9836
+in the context of the :keyword:`for` and :keyword:`if` clauses which follow it.
9837
+For example, this listcomp combines the elements of two lists if they are not
9840
-Here we take a list of numbers and return a list of three times each number::
9841
+ >>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
9842
+ [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
9844
- >>> vec = [2, 4, 6]
9845
- >>> [3*x for x in vec]
9847
+and it's equivalent to::
9849
-Now we get a little fancier::
9851
+ >>> for x in [1,2,3]:
9852
+ ... for y in [3,1,4]:
9854
+ ... combs.append((x, y))
9857
+ [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
9859
- >>> [[x, x**2] for x in vec]
9860
- [[2, 4], [4, 16], [6, 36]]
9861
+Note how the order of the :keyword:`for` and :keyword:`if` statements is the
9862
+same in both these snippets.
9864
-Here we apply a method call to each item in a sequence::
9865
+If the expression is a tuple (e.g. the ``(x, y)`` in the previous example),
9866
+it must be parenthesized. ::
9868
+ >>> vec = [-4, -2, 0, 2, 4]
9869
+ >>> # create a new list with the values doubled
9870
+ >>> [x*2 for x in vec]
9872
+ >>> # filter the list to exclude negative numbers
9873
+ >>> [x for x in vec if x >= 0]
9875
+ >>> # apply a function to all the elements
9876
+ >>> [abs(x) for x in vec]
9878
+ >>> # call a method on each element
9879
>>> freshfruit = [' banana', ' loganberry ', 'passion fruit ']
9880
>>> [weapon.strip() for weapon in freshfruit]
9881
['banana', 'loganberry', 'passion fruit']
9883
-Using the :keyword:`if` clause we can filter the stream::
9885
- >>> [3*x for x in vec if x > 3]
9887
- >>> [3*x for x in vec if x < 2]
9890
-Tuples can often be created without their parentheses, but not here::
9892
- >>> [x, x**2 for x in vec] # error - parens required for tuples
9893
+ >>> # create a list of 2-tuples like (number, square)
9894
+ >>> [(x, x**2) for x in range(6)]
9895
+ [(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]
9896
+ >>> # the tuple must be parenthesized, otherwise an error is raised
9897
+ >>> [x, x**2 for x in range(6)]
9898
File "<stdin>", line 1, in ?
9899
- [x, x**2 for x in vec]
9900
+ [x, x**2 for x in range(6)]
9902
SyntaxError: invalid syntax
9903
- >>> [(x, x**2) for x in vec]
9904
- [(2, 4), (4, 16), (6, 36)]
9905
+ >>> # flatten a list using a listcomp with two 'for'
9906
+ >>> vec = [[1,2,3], [4,5,6], [7,8,9]]
9907
+ >>> [num for elem in vec for num in elem]
9908
+ [1, 2, 3, 4, 5, 6, 7, 8, 9]
9910
-Here are some nested for loops and other fancy behavior::
9911
+List comprehensions can contain complex expressions and nested functions::
9913
- >>> vec1 = [2, 4, 6]
9914
- >>> vec2 = [4, 3, -9]
9915
- >>> [x*y for x in vec1 for y in vec2]
9916
- [8, 6, -18, 16, 12, -36, 24, 18, -54]
9917
- >>> [x+y for x in vec1 for y in vec2]
9918
- [6, 5, -7, 8, 7, -5, 10, 9, -3]
9919
- >>> [vec1[i]*vec2[i] for i in range(len(vec1))]
9922
-List comprehensions can be applied to complex expressions and nested functions::
9924
- >>> [str(round(355/113, i)) for i in range(1, 6)]
9925
+ >>> from math import pi
9926
+ >>> [str(round(pi, i)) for i in range(1, 6)]
9927
['3.1', '3.14', '3.142', '3.1416', '3.14159']
9930
Nested List Comprehensions
9931
--------------------------
9933
-If you've got the stomach for it, list comprehensions can be nested. They are a
9934
-powerful tool but -- like all powerful tools -- they need to be used carefully,
9936
+The initial expression in a list comprehension can be any arbitrary expression,
9937
+including another list comprehension.
9939
-Consider the following example of a 3x3 matrix held as a list containing three
9940
-lists, one list per row::
9941
+Consider the following example of a 3x4 matrix implemented as a list of
9942
+3 lists of length 4::
9952
+ ... [9, 10, 11, 12],
9955
-Now, if you wanted to swap rows and columns, you could use a list
9957
+The following list comprehension will transpose rows and columns::
9959
- >>> print([[row[i] for row in mat] for i in [0, 1, 2]])
9960
- [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
9961
+ >>> [[row[i] for row in matrix] for i in range(4)]
9962
+ [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
9964
-Special care has to be taken for the *nested* list comprehension:
9965
+As we saw in the previous section, the nested listcomp is evaluated in
9966
+the context of the :keyword:`for` that follows it, so this example is
9969
- To avoid apprehension when nesting list comprehensions, read from right to
9971
+ >>> transposed = []
9972
+ >>> for i in range(4):
9973
+ ... transposed.append([row[i] for row in matrix])
9976
+ [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
9978
-A more verbose version of this snippet shows the flow explicitly::
9979
+which, in turn, is the same as::
9981
- for i in [0, 1, 2]:
9983
- print(row[i], end="")
9985
+ >>> transposed = []
9986
+ >>> for i in range(4):
9987
+ ... # the following 3 lines implement the nested listcomp
9988
+ ... transposed_row = []
9989
+ ... for row in matrix:
9990
+ ... transposed_row.append(row[i])
9991
+ ... transposed.append(transposed_row)
9994
+ [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
9996
-In real world, you should prefer built-in functions to complex flow statements.
9997
+In the real world, you should prefer built-in functions to complex flow statements.
9998
The :func:`zip` function would do a great job for this use case::
10000
- >>> list(zip(*mat))
10001
- [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
10003
+ [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
10005
See :ref:`tut-unpacking-arguments` for details on the asterisk in this line.
10007
diff -r 137e45f15c0b Doc/tutorial/floatingpoint.rst
10008
--- a/Doc/tutorial/floatingpoint.rst
10009
+++ b/Doc/tutorial/floatingpoint.rst
10011
(although some languages may not *display* the difference by default, or in all
10014
-For more pleasant output, you may may wish to use string formatting to produce a limited number of significant digits::
10015
+For more pleasant output, you may wish to use string formatting to produce a limited number of significant digits::
10017
>>> format(math.pi, '.12g') # give 12 significant digits
10019
diff -r 137e45f15c0b Doc/tutorial/interpreter.rst
10020
--- a/Doc/tutorial/interpreter.rst
10021
+++ b/Doc/tutorial/interpreter.rst
10024
When a script file is used, it is sometimes useful to be able to run the script
10025
and enter interactive mode afterwards. This can be done by passing :option:`-i`
10026
-before the script. (This does not work if the script is read from standard
10027
-input, for the same reason as explained in the previous paragraph.)
10028
+before the script.
10031
.. _tut-argpassing:
10032
diff -r 137e45f15c0b Doc/tutorial/introduction.rst
10033
--- a/Doc/tutorial/introduction.rst
10034
+++ b/Doc/tutorial/introduction.rst
10035
@@ -593,13 +593,13 @@
10036
and ``!=`` (not equal to).
10038
* The *body* of the loop is *indented*: indentation is Python's way of grouping
10039
- statements. Python does not (yet!) provide an intelligent input line editing
10040
- facility, so you have to type a tab or space(s) for each indented line. In
10041
- practice you will prepare more complicated input for Python with a text editor;
10042
- most text editors have an auto-indent facility. When a compound statement is
10043
- entered interactively, it must be followed by a blank line to indicate
10044
- completion (since the parser cannot guess when you have typed the last line).
10045
- Note that each line within a basic block must be indented by the same amount.
10046
+ statements. At the interactive prompt, you have to type a tab or space(s) for
10047
+ each indented line. In practice you will prepare more complicated input
10048
+ for Python with a text editor; all decent text editors have an auto-indent
10049
+ facility. When a compound statement is entered interactively, it must be
10050
+ followed by a blank line to indicate completion (since the parser cannot
10051
+ guess when you have typed the last line). Note that each line within a basic
10052
+ block must be indented by the same amount.
10054
* The :func:`print` function writes the value of the expression(s) it is
10055
given. It differs from just writing the expression you want to write (as we did
10056
diff -r 137e45f15c0b Doc/tutorial/modules.rst
10057
--- a/Doc/tutorial/modules.rst
10058
+++ b/Doc/tutorial/modules.rst
10059
@@ -159,24 +159,22 @@
10061
.. index:: triple: module; search; path
10063
-When a module named :mod:`spam` is imported, the interpreter searches for a
10064
-file named :file:`spam.py` in the directory containing the input script and
10065
-then in the list of directories specified by the environment variable
10066
-:envvar:`PYTHONPATH`. This has the same syntax as the shell variable
10067
-:envvar:`PATH`, that is, a list of directory names. When :envvar:`PYTHONPATH`
10068
-is not set, or when the file is not found there, the search continues in an
10069
-installation-dependent default path; on Unix, this is usually
10070
-:file:`.:/usr/local/lib/python`.
10071
+When a module named :mod:`spam` is imported, the interpreter first searches for
10072
+a built-in module with that name. If not found, it then searches for a file
10073
+named :file:`spam.py` in a list of directories given by the variable
10074
+:data:`sys.path`. :data:`sys.path` is initialized from these locations:
10076
-Actually, modules are searched in the list of directories given by the variable
10077
-``sys.path`` which is initialized from the directory containing the input script
10078
-(or the current directory), :envvar:`PYTHONPATH` and the installation- dependent
10079
-default. This allows Python programs that know what they're doing to modify or
10080
-replace the module search path. Note that because the directory containing the
10081
-script being run is on the search path, it is important that the script not have
10082
-the same name as a standard module, or Python will attempt to load the script as
10083
-a module when that module is imported. This will generally be an error. See
10084
-section :ref:`tut-standardmodules` for more information.
10085
+* the directory containing the input script (or the current directory).
10086
+* :envvar:`PYTHONPATH` (a list of directory names, with the same syntax as the
10087
+ shell variable :envvar:`PATH`).
10088
+* the installation-dependent default.
10090
+After initialization, Python programs can modify :data:`sys.path`. The
10091
+directory containing the script being run is placed at the beginning of the
10092
+search path, ahead of the standard library path. This means that scripts in that
10093
+directory will be loaded instead of modules of the same name in the library
10094
+directory. This is an error unless the replacement is intended. See section
10095
+:ref:`tut-standardmodules` for more information.
10098
Do we need stuff on zip files etc. ? DUBOIS
10099
diff -r 137e45f15c0b Doc/using/cmdline.rst
10100
--- a/Doc/using/cmdline.rst
10101
+++ b/Doc/using/cmdline.rst
10102
@@ -247,7 +247,8 @@
10104
Force the binary layer of the stdin, stdout and stderr streams (which is
10105
available as their ``buffer`` attribute) to be unbuffered. The text I/O
10106
- layer will still be line-buffered.
10107
+ layer will still be line-buffered if writing to the console, or
10108
+ block-buffered if redirected to a non-interactive file.
10110
See also :envvar:`PYTHONUNBUFFERED`.
10112
@@ -447,13 +448,14 @@
10113
.. envvar:: PYTHONCASEOK
10115
If this is set, Python ignores case in :keyword:`import` statements. This
10116
- only works on Windows.
10117
+ only works on Windows, OS X, and OS/2.
10120
.. envvar:: PYTHONDONTWRITEBYTECODE
10122
If this is set, Python won't try to write ``.pyc`` or ``.pyo`` files on the
10123
- import of source modules.
10124
+ import of source modules. This is equivalent to specifying the :option:`-B`
10128
.. envvar:: PYTHONIOENCODING
10129
diff -r 137e45f15c0b Doc/using/unix.rst
10130
--- a/Doc/using/unix.rst
10131
+++ b/Doc/using/unix.rst
10133
-.. highlightlang:: none
10134
+.. highlightlang:: sh
10138
@@ -26,11 +26,11 @@
10142
- http://www.linux.com/articles/60383
10143
+ http://www.debian.org/doc/manuals/maint-guide/first.en.html
10145
http://linuxmafia.com/pub/linux/suse-linux-internals/chapter35.html
10147
- http://docs.fedoraproject.org/drafts/rpm-guide-en/ch-creating-rpms.html
10148
+ http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-creating-rpms.html
10150
http://www.slackbook.org/html/package-management-making-packages.html
10151
for Slackware users
10156
-To install the newest Python versions on OpenSolaris, install blastwave
10157
-(http://www.blastwave.org/howto.html) and type "pkg_get -i python" at the
10158
+To install the newest Python versions on OpenSolaris, install `blastwave
10159
+<http://www.blastwave.org/howto.html>`_ and type ``pkg_get -i python`` at the
10163
@@ -65,22 +65,23 @@
10165
If you want to compile CPython yourself, first thing you should do is get the
10166
`source <http://python.org/download/source/>`_. You can download either the
10167
-latest release's source or just grab a fresh `checkout
10168
-<http://www.python.org/dev/faq/#how-do-i-get-a-checkout-of-the-repository-read-only-and-read-write>`_.
10169
+latest release's source or just grab a fresh `clone
10170
+<http://docs.python.org/devguide/setup#getting-the-source-code>`_. (If you want
10171
+to contribute patches, you will need a clone.)
10173
-The build process consists the usual ::
10174
+The build process consists in the usual ::
10180
invocations. Configuration options and caveats for specific Unix platforms are
10181
-extensively documented in the :file:`README` file in the root of the Python
10182
+extensively documented in the :source:`README` file in the root of the Python
10187
- ``make install`` can overwrite or masquerade the :file:`python` binary.
10188
+ ``make install`` can overwrite or masquerade the :file:`python3` binary.
10189
``make altinstall`` is therefore recommended instead of ``make install``
10190
since it only installs :file:`{exec_prefix}/bin/python{version}`.
10193
+-----------------------------------------------+------------------------------------------+
10194
| File/directory | Meaning |
10195
+===============================================+==========================================+
10196
-| :file:`{exec_prefix}/bin/python` | Recommended location of the interpreter. |
10197
+| :file:`{exec_prefix}/bin/python3` | Recommended location of the interpreter. |
10198
+-----------------------------------------------+------------------------------------------+
10199
| :file:`{prefix}/lib/python{version}`, | Recommended locations of the directories |
10200
| :file:`{exec_prefix}/lib/python{version}` | containing the standard modules. |
10201
@@ -108,10 +109,6 @@
10202
| | developing Python extensions and |
10203
| | embedding the interpreter. |
10204
+-----------------------------------------------+------------------------------------------+
10205
-| :file:`~/.pythonrc.py` | User-specific initialization file loaded |
10206
-| | by the user module; not used by default |
10207
-| | or by most applications. |
10208
-+-----------------------------------------------+------------------------------------------+
10212
@@ -125,11 +122,11 @@
10213
and put an appropriate Shebang line at the top of the script. A good choice is
10216
- #!/usr/bin/env python
10217
+ #!/usr/bin/env python3
10219
which searches for the Python interpreter in the whole :envvar:`PATH`. However,
10220
some Unices may not have the :program:`env` command, so you may need to hardcode
10221
-``/usr/bin/python`` as the interpreter path.
10222
+``/usr/bin/python3`` as the interpreter path.
10224
To use shell commands in your Python scripts, look at the :mod:`subprocess` module.
10226
diff -r 137e45f15c0b Doc/using/windows.rst
10227
--- a/Doc/using/windows.rst
10228
+++ b/Doc/using/windows.rst
10230
"7 Minutes to "Hello World!""
10231
by Richard Dooling, 2006
10233
- `Installing on Windows <http://diveintopython.org/installing_python/windows.html>`_
10234
+ `Installing on Windows <http://diveintopython.net/installing_python/windows.html>`_
10235
in "`Dive into Python: Python from novice to pro
10236
- <http://diveintopython.org/index.html>`_"
10237
+ <http://diveintopython.net/index.html>`_"
10238
by Mark Pilgrim, 2004,
10241
@@ -290,7 +290,7 @@
10242
If you want to compile CPython yourself, first thing you should do is get the
10243
`source <http://python.org/download/source/>`_. You can download either the
10244
latest release's source or just grab a fresh `checkout
10245
-<http://www.python.org/dev/faq/#how-do-i-get-a-checkout-of-the-repository-read-only-and-read-write>`_.
10246
+<http://docs.python.org/devguide/setup#checking-out-the-code>`_.
10248
For Microsoft Visual C++, which is the compiler with which official Python
10249
releases are built, the source tree contains solutions/project files. View the
10250
diff -r 137e45f15c0b Doc/whatsnew/2.4.rst
10251
--- a/Doc/whatsnew/2.4.rst
10252
+++ b/Doc/whatsnew/2.4.rst
10253
@@ -947,7 +947,7 @@
10254
:meth:`__len__` method. (Contributed by Raymond Hettinger.)
10256
* The methods :meth:`list.__getitem__`, :meth:`dict.__getitem__`, and
10257
- :meth:`dict.__contains__` are are now implemented as :class:`method_descriptor`
10258
+ :meth:`dict.__contains__` are now implemented as :class:`method_descriptor`
10259
objects rather than :class:`wrapper_descriptor` objects. This form of access
10260
doubles their performance and makes them more suitable for use as arguments to
10261
functionals: ``map(mydict.__getitem__, keylist)``. (Contributed by Raymond
10262
diff -r 137e45f15c0b Doc/whatsnew/2.6.rst
10263
--- a/Doc/whatsnew/2.6.rst
10264
+++ b/Doc/whatsnew/2.6.rst
10265
@@ -234,7 +234,7 @@
10269
- :ref:`documenting-index`
10270
+ `Documenting Python <http://docs.python.org/devguide/documenting.html>`__
10271
Describes how to write for Python's documentation.
10273
`Sphinx <http://sphinx.pocoo.org/>`__
10274
@@ -615,8 +615,8 @@
10275
result = queue.get()
10276
print 'Factorial', N, '=', result
10278
-A :class:`Queue` is used to communicate the input parameter *N* and
10279
-the result. The :class:`Queue` object is stored in a global variable.
10280
+A :class:`Queue` is used to communicate the result of the factorial.
10281
+The :class:`Queue` object is stored in a global variable.
10282
The child process will use the value of the variable when the child
10283
was created; because it's a :class:`Queue`, parent and child can use
10284
the object to communicate. (If the parent were to change the value of
10285
diff -r 137e45f15c0b Doc/whatsnew/2.7.rst
10286
--- a/Doc/whatsnew/2.7.rst
10287
+++ b/Doc/whatsnew/2.7.rst
10288
@@ -1952,7 +1952,7 @@
10289
version 1.3. Some of the new features are:
10291
* The various parsing functions now take a *parser* keyword argument
10292
- giving an :class:`XMLParser` instance that will
10293
+ giving an :class:`~xml.etree.ElementTree.XMLParser` instance that will
10294
be used. This makes it possible to override the file's internal encoding::
10296
p = ET.XMLParser(encoding='utf-8')
10297
@@ -1964,8 +1964,8 @@
10299
* ElementTree's code for converting trees to a string has been
10300
significantly reworked, making it roughly twice as fast in many
10301
- cases. The :class:`ElementTree` :meth:`write` and :class:`Element`
10302
- :meth:`write` methods now have a *method* parameter that can be
10303
+ cases. The :meth:`ElementTree.write() <xml.etree.ElementTree.ElementTree.write>`
10304
+ and :meth:`Element.write` methods now have a *method* parameter that can be
10305
"xml" (the default), "html", or "text". HTML mode will output empty
10306
elements as ``<empty></empty>`` instead of ``<empty/>``, and text
10307
mode will skip over elements and only output the text chunks. If
10308
@@ -1978,11 +1978,12 @@
10309
declarations are now output on the root element, not scattered throughout
10310
the resulting XML. You can set the default namespace for a tree
10311
by setting the :attr:`default_namespace` attribute and can
10312
- register new prefixes with :meth:`register_namespace`. In XML mode,
10313
+ register new prefixes with :meth:`~xml.etree.ElementTree.register_namespace`. In XML mode,
10314
you can use the true/false *xml_declaration* parameter to suppress the
10317
-* New :class:`Element` method: :meth:`extend` appends the items from a
10318
+* New :class:`~xml.etree.ElementTree.Element` method:
10319
+ :meth:`~xml.etree.ElementTree.Element.extend` appends the items from a
10320
sequence to the element's children. Elements themselves behave like
10321
sequences, so it's easy to move children from one element to
10323
@@ -1998,13 +1999,15 @@
10324
# Outputs <root><item>1</item>...</root>
10325
print ET.tostring(new)
10327
-* New :class:`Element` method: :meth:`iter` yields the children of the
10328
+* New :class:`Element` method:
10329
+ :meth:`~xml.etree.ElementTree.Element.iter` yields the children of the
10330
element as a generator. It's also possible to write ``for child in
10331
elem:`` to loop over an element's children. The existing method
10332
:meth:`getiterator` is now deprecated, as is :meth:`getchildren`
10333
which constructs and returns a list of children.
10335
-* New :class:`Element` method: :meth:`itertext` yields all chunks of
10336
+* New :class:`Element` method:
10337
+ :meth:`~xml.etree.ElementTree.Element.itertext` yields all chunks of
10338
text that are descendants of the element. For example::
10340
t = ET.XML("""<list>
10341
diff -r 137e45f15c0b Doc/whatsnew/3.0.rst
10342
--- a/Doc/whatsnew/3.0.rst
10343
+++ b/Doc/whatsnew/3.0.rst
10344
@@ -154,7 +154,9 @@
10345
:meth:`dict.itervalues` methods are no longer supported.
10347
* :func:`map` and :func:`filter` return iterators. If you really need
10348
- a list, a quick fix is e.g. ``list(map(...))``, but a better fix is
10349
+ a list and the input sequences are all of equal length, a quick
10350
+ fix is to wrap :func:`map` in :func:`list`, e.g. ``list(map(...))``,
10351
+ but a better fix is
10352
often to use a list comprehension (especially when the original code
10353
uses :keyword:`lambda`), or rewriting the code so it doesn't need a
10354
list at all. Particularly tricky is :func:`map` invoked for the
10355
@@ -162,6 +164,12 @@
10356
regular :keyword:`for` loop (since creating a list would just be
10359
+ If the input sequences are not of equal length, :func:`map` will
10360
+ stop at the termination of the shortest of the sequences. For full
10361
+ compatibility with `map` from Python 2.x, also wrap the sequences in
10362
+ :func:`itertools.zip_longest`, e.g. ``map(func, *sequences)`` becomes
10363
+ ``list(map(func, itertools.zip_longest(*sequences)))``.
10365
* :func:`range` now behaves like :func:`xrange` used to behave, except
10366
it works with values of arbitrary size. The latter no longer
10368
@@ -293,6 +301,12 @@
10369
There is no longer any need for using the encoding-aware streams
10370
in the :mod:`codecs` module.
10372
+* The initial values of :data:`sys.stdin`, :data:`sys.stdout` and
10373
+ :data:`sys.stderr` are now unicode-only text files (i.e., they are
10374
+ instances of :class:`io.TextIOBase`). To read and write bytes data
10375
+ with these streams, you need to use their :data:`io.TextIOBase.buffer`
10378
* Filenames are passed to and returned from APIs as (Unicode) strings.
10379
This can present platform-specific problems because on some
10380
platforms filenames are arbitrary byte strings. (On the other hand,
10381
@@ -503,9 +517,7 @@
10382
produces a literal of type :class:`bytes`.
10384
* :ref:`pep-3116`. The :mod:`io` module is now the standard way of
10385
- doing file I/O, and the initial values of :data:`sys.stdin`,
10386
- :data:`sys.stdout` and :data:`sys.stderr` are now instances of
10387
- :class:`io.TextIOBase`. The built-in :func:`open` function is now an
10388
+ doing file I/O. The built-in :func:`open` function is now an
10389
alias for :func:`io.open` and has additional keyword arguments
10390
*encoding*, *errors*, *newline* and *closefd*. Also note that an
10391
invalid *mode* argument now raises :exc:`ValueError`, not
10392
diff -r 137e45f15c0b Doc/whatsnew/3.2.rst
10393
--- a/Doc/whatsnew/3.2.rst
10394
+++ b/Doc/whatsnew/3.2.rst
10395
@@ -234,8 +234,8 @@
10396
namespace, *concurrent*. Its first member is a *futures* package which provides
10397
a uniform high-level interface for managing threads and processes.
10399
-The design for :mod:`concurrent.futures` was inspired by
10400
-*java.util.concurrent.package*. In that model, a running call and its result
10401
+The design for :mod:`concurrent.futures` was inspired by the
10402
+*java.util.concurrent* package. In that model, a running call and its result
10403
are represented by a :class:`~concurrent.futures.Future` object that abstracts
10404
features common to threads, processes, and remote procedure calls. That object
10405
supports status checks (running or done), timeouts, cancellations, adding
10406
@@ -2362,7 +2362,7 @@
10407
(Patch by Florent Xicluna in :issue:`7622` and :issue:`7462`.)
10410
-* String to integer conversions now work two "digits" at a time, reducing the
10411
+* Integer to string conversions now work two "digits" at a time, reducing the
10412
number of division and modulo operations.
10414
(:issue:`6713` by Gawain Bolton, Mark Dickinson, and Victor Stinner.)
10415
diff -r 137e45f15c0b Grammar/Grammar
10416
--- a/Grammar/Grammar
10417
+++ b/Grammar/Grammar
10419
and_test: not_test ('and' not_test)*
10420
not_test: 'not' not_test | comparison
10421
comparison: expr (comp_op expr)*
10422
+# <> isn't actually a valid comparison operator in Python. It's here for the
10423
+# sake of a __future__ import described in PEP 401
10424
comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
10425
star_expr: '*' expr
10426
expr: xor_expr ('|' xor_expr)*
10427
diff -r 137e45f15c0b Include/Python.h
10428
--- a/Include/Python.h
10429
+++ b/Include/Python.h
10430
@@ -100,7 +100,7 @@
10431
#include "warnings.h"
10432
#include "weakrefobject.h"
10433
#include "structseq.h"
10437
#include "codecs.h"
10438
#include "pyerrors.h"
10439
@@ -141,7 +141,7 @@
10442
/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
10443
-#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
10444
+#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
10448
diff -r 137e45f15c0b Include/accu.h
10450
+++ b/Include/accu.h
10452
+#ifndef Py_LIMITED_API
10456
+/*** This is a private API for use by the interpreter and the stdlib.
10457
+ *** Its definition may be changed or removed at any moment.
10461
+ * A two-level accumulator of unicode objects that avoids both the overhead
10462
+ * of keeping a huge number of small separate objects, and the quadratic
10463
+ * behaviour of using a naive repeated concatenation scheme.
10466
+#ifdef __cplusplus
10471
+ PyObject *large; /* A list of previously accumulated large strings */
10472
+ PyObject *small; /* Pending small strings */
10475
+PyAPI_FUNC(int) _PyAccu_Init(_PyAccu *acc);
10476
+PyAPI_FUNC(int) _PyAccu_Accumulate(_PyAccu *acc, PyObject *unicode);
10477
+PyAPI_FUNC(PyObject *) _PyAccu_FinishAsList(_PyAccu *acc);
10478
+PyAPI_FUNC(PyObject *) _PyAccu_Finish(_PyAccu *acc);
10479
+PyAPI_FUNC(void) _PyAccu_Destroy(_PyAccu *acc);
10481
+#ifdef __cplusplus
10485
+#endif /* Py_ACCU_H */
10486
+#endif /* Py_LIMITED_API */
10487
diff -r 137e45f15c0b Include/descrobject.h
10488
--- a/Include/descrobject.h
10489
+++ b/Include/descrobject.h
10491
PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
10492
PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
10493
PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
10494
+PyAPI_DATA(PyTypeObject) _PyMethodWrapper_Type;
10496
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
10497
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
10498
diff -r 137e45f15c0b Include/dynamic_annotations.h
10499
--- a/Include/dynamic_annotations.h
10500
+++ b/Include/dynamic_annotations.h
10501
@@ -103,26 +103,26 @@
10503
/* Report that wait on the condition variable at address "cv" has succeeded
10504
and the lock at address "lock" is held. */
10505
- #define _Py_ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) \
10506
+#define _Py_ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) \
10507
AnnotateCondVarWait(__FILE__, __LINE__, cv, lock)
10509
/* Report that wait on the condition variable at "cv" has succeeded. Variant
10511
- #define _Py_ANNOTATE_CONDVAR_WAIT(cv) \
10512
+#define _Py_ANNOTATE_CONDVAR_WAIT(cv) \
10513
AnnotateCondVarWait(__FILE__, __LINE__, cv, NULL)
10515
/* Report that we are about to signal on the condition variable at address
10517
- #define _Py_ANNOTATE_CONDVAR_SIGNAL(cv) \
10518
+#define _Py_ANNOTATE_CONDVAR_SIGNAL(cv) \
10519
AnnotateCondVarSignal(__FILE__, __LINE__, cv)
10521
/* Report that we are about to signal_all on the condition variable at "cv". */
10522
- #define _Py_ANNOTATE_CONDVAR_SIGNAL_ALL(cv) \
10523
+#define _Py_ANNOTATE_CONDVAR_SIGNAL_ALL(cv) \
10524
AnnotateCondVarSignalAll(__FILE__, __LINE__, cv)
10526
/* Annotations for user-defined synchronization mechanisms. */
10527
- #define _Py_ANNOTATE_HAPPENS_BEFORE(obj) _Py_ANNOTATE_CONDVAR_SIGNAL(obj)
10528
- #define _Py_ANNOTATE_HAPPENS_AFTER(obj) _Py_ANNOTATE_CONDVAR_WAIT(obj)
10529
+#define _Py_ANNOTATE_HAPPENS_BEFORE(obj) _Py_ANNOTATE_CONDVAR_SIGNAL(obj)
10530
+#define _Py_ANNOTATE_HAPPENS_AFTER(obj) _Py_ANNOTATE_CONDVAR_WAIT(obj)
10532
/* Report that the bytes in the range [pointer, pointer+size) are about
10533
to be published safely. The race checker will create a happens-before
10534
@@ -131,7 +131,7 @@
10535
Note: this annotation may not work properly if the race detector uses
10536
sampling, i.e. does not observe all memory accesses.
10538
- #define _Py_ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size) \
10539
+#define _Py_ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size) \
10540
AnnotatePublishMemoryRange(__FILE__, __LINE__, pointer, size)
10542
/* Instruct the tool to create a happens-before arc between mu->Unlock() and
10543
@@ -141,7 +141,7 @@
10544
This annotation makes sense only for hybrid race detectors. For pure
10545
happens-before detectors this is a no-op. For more details see
10546
http://code.google.com/p/data-race-test/wiki/PureHappensBeforeVsHybrid . */
10547
- #define _Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) \
10548
+#define _Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) \
10549
AnnotateMutexIsUsedAsCondVar(__FILE__, __LINE__, mu)
10551
/* -------------------------------------------------------------
10552
@@ -152,7 +152,7 @@
10553
This might be used when the memory has been retrieved from a free list and
10554
is about to be reused, or when a the locking discipline for a variable
10556
- #define _Py_ANNOTATE_NEW_MEMORY(address, size) \
10557
+#define _Py_ANNOTATE_NEW_MEMORY(address, size) \
10558
AnnotateNewMemory(__FILE__, __LINE__, address, size)
10560
/* -------------------------------------------------------------
10561
@@ -164,20 +164,20 @@
10562
be used only for FIFO queues. For non-FIFO queues use
10563
_Py_ANNOTATE_HAPPENS_BEFORE (for put) and _Py_ANNOTATE_HAPPENS_AFTER (for
10565
- #define _Py_ANNOTATE_PCQ_CREATE(pcq) \
10566
+#define _Py_ANNOTATE_PCQ_CREATE(pcq) \
10567
AnnotatePCQCreate(__FILE__, __LINE__, pcq)
10569
/* Report that the queue at address "pcq" is about to be destroyed. */
10570
- #define _Py_ANNOTATE_PCQ_DESTROY(pcq) \
10571
+#define _Py_ANNOTATE_PCQ_DESTROY(pcq) \
10572
AnnotatePCQDestroy(__FILE__, __LINE__, pcq)
10574
/* Report that we are about to put an element into a FIFO queue at address
10576
- #define _Py_ANNOTATE_PCQ_PUT(pcq) \
10577
+#define _Py_ANNOTATE_PCQ_PUT(pcq) \
10578
AnnotatePCQPut(__FILE__, __LINE__, pcq)
10580
/* Report that we've just got an element from a FIFO queue at address "pcq". */
10581
- #define _Py_ANNOTATE_PCQ_GET(pcq) \
10582
+#define _Py_ANNOTATE_PCQ_GET(pcq) \
10583
AnnotatePCQGet(__FILE__, __LINE__, pcq)
10585
/* -------------------------------------------------------------
10586
@@ -189,13 +189,13 @@
10587
"sizeof(*(pointer))". "pointer" must be a non-void* pointer. Insert at the
10588
point where "pointer" has been allocated, preferably close to the point
10589
where the race happens. See also _Py_ANNOTATE_BENIGN_RACE_STATIC. */
10590
- #define _Py_ANNOTATE_BENIGN_RACE(pointer, description) \
10591
+#define _Py_ANNOTATE_BENIGN_RACE(pointer, description) \
10592
AnnotateBenignRaceSized(__FILE__, __LINE__, pointer, \
10593
sizeof(*(pointer)), description)
10595
/* Same as _Py_ANNOTATE_BENIGN_RACE(address, description), but applies to
10596
the memory range [address, address+size). */
10597
- #define _Py_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \
10598
+#define _Py_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \
10599
AnnotateBenignRaceSized(__FILE__, __LINE__, address, size, description)
10601
/* Request the analysis tool to ignore all reads in the current thread
10602
@@ -203,30 +203,30 @@
10603
Useful to ignore intentional racey reads, while still checking
10604
other reads and all writes.
10605
See also _Py_ANNOTATE_UNPROTECTED_READ. */
10606
- #define _Py_ANNOTATE_IGNORE_READS_BEGIN() \
10607
+#define _Py_ANNOTATE_IGNORE_READS_BEGIN() \
10608
AnnotateIgnoreReadsBegin(__FILE__, __LINE__)
10610
/* Stop ignoring reads. */
10611
- #define _Py_ANNOTATE_IGNORE_READS_END() \
10612
+#define _Py_ANNOTATE_IGNORE_READS_END() \
10613
AnnotateIgnoreReadsEnd(__FILE__, __LINE__)
10615
/* Similar to _Py_ANNOTATE_IGNORE_READS_BEGIN, but ignore writes. */
10616
- #define _Py_ANNOTATE_IGNORE_WRITES_BEGIN() \
10617
+#define _Py_ANNOTATE_IGNORE_WRITES_BEGIN() \
10618
AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
10620
/* Stop ignoring writes. */
10621
- #define _Py_ANNOTATE_IGNORE_WRITES_END() \
10622
+#define _Py_ANNOTATE_IGNORE_WRITES_END() \
10623
AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
10625
/* Start ignoring all memory accesses (reads and writes). */
10626
- #define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \
10627
+#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \
10629
_Py_ANNOTATE_IGNORE_READS_BEGIN();\
10630
_Py_ANNOTATE_IGNORE_WRITES_BEGIN();\
10633
/* Stop ignoring all memory accesses. */
10634
- #define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_END() \
10635
+#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_END() \
10637
_Py_ANNOTATE_IGNORE_WRITES_END();\
10638
_Py_ANNOTATE_IGNORE_READS_END();\
10639
@@ -234,29 +234,29 @@
10641
/* Similar to _Py_ANNOTATE_IGNORE_READS_BEGIN, but ignore synchronization events:
10642
RWLOCK* and CONDVAR*. */
10643
- #define _Py_ANNOTATE_IGNORE_SYNC_BEGIN() \
10644
+#define _Py_ANNOTATE_IGNORE_SYNC_BEGIN() \
10645
AnnotateIgnoreSyncBegin(__FILE__, __LINE__)
10647
/* Stop ignoring sync events. */
10648
- #define _Py_ANNOTATE_IGNORE_SYNC_END() \
10649
+#define _Py_ANNOTATE_IGNORE_SYNC_END() \
10650
AnnotateIgnoreSyncEnd(__FILE__, __LINE__)
10653
/* Enable (enable!=0) or disable (enable==0) race detection for all threads.
10654
This annotation could be useful if you want to skip expensive race analysis
10655
during some period of program execution, e.g. during initialization. */
10656
- #define _Py_ANNOTATE_ENABLE_RACE_DETECTION(enable) \
10657
+#define _Py_ANNOTATE_ENABLE_RACE_DETECTION(enable) \
10658
AnnotateEnableRaceDetection(__FILE__, __LINE__, enable)
10660
/* -------------------------------------------------------------
10661
Annotations useful for debugging. */
10663
/* Request to trace every access to "address". */
10664
- #define _Py_ANNOTATE_TRACE_MEMORY(address) \
10665
+#define _Py_ANNOTATE_TRACE_MEMORY(address) \
10666
AnnotateTraceMemory(__FILE__, __LINE__, address)
10668
/* Report the current thread name to a race detector. */
10669
- #define _Py_ANNOTATE_THREAD_NAME(name) \
10670
+#define _Py_ANNOTATE_THREAD_NAME(name) \
10671
AnnotateThreadName(__FILE__, __LINE__, name)
10673
/* -------------------------------------------------------------
10674
@@ -265,20 +265,20 @@
10675
The "lock" argument is a pointer to the lock object. */
10677
/* Report that a lock has been created at address "lock". */
10678
- #define _Py_ANNOTATE_RWLOCK_CREATE(lock) \
10679
+#define _Py_ANNOTATE_RWLOCK_CREATE(lock) \
10680
AnnotateRWLockCreate(__FILE__, __LINE__, lock)
10682
/* Report that the lock at address "lock" is about to be destroyed. */
10683
- #define _Py_ANNOTATE_RWLOCK_DESTROY(lock) \
10684
+#define _Py_ANNOTATE_RWLOCK_DESTROY(lock) \
10685
AnnotateRWLockDestroy(__FILE__, __LINE__, lock)
10687
/* Report that the lock at address "lock" has been acquired.
10688
is_w=1 for writer lock, is_w=0 for reader lock. */
10689
- #define _Py_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \
10690
+#define _Py_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \
10691
AnnotateRWLockAcquired(__FILE__, __LINE__, lock, is_w)
10693
/* Report that the lock at address "lock" is about to be released. */
10694
- #define _Py_ANNOTATE_RWLOCK_RELEASED(lock, is_w) \
10695
+#define _Py_ANNOTATE_RWLOCK_RELEASED(lock, is_w) \
10696
AnnotateRWLockReleased(__FILE__, __LINE__, lock, is_w)
10698
/* -------------------------------------------------------------
10699
@@ -289,20 +289,20 @@
10700
/* Report that the "barrier" has been initialized with initial "count".
10701
If 'reinitialization_allowed' is true, initialization is allowed to happen
10702
multiple times w/o calling barrier_destroy() */
10703
- #define _Py_ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \
10704
+#define _Py_ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \
10705
AnnotateBarrierInit(__FILE__, __LINE__, barrier, count, \
10706
reinitialization_allowed)
10708
/* Report that we are about to enter barrier_wait("barrier"). */
10709
- #define _Py_ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \
10710
+#define _Py_ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \
10711
AnnotateBarrierWaitBefore(__FILE__, __LINE__, barrier)
10713
/* Report that we just exited barrier_wait("barrier"). */
10714
- #define _Py_ANNOTATE_BARRIER_WAIT_AFTER(barrier) \
10715
+#define _Py_ANNOTATE_BARRIER_WAIT_AFTER(barrier) \
10716
AnnotateBarrierWaitAfter(__FILE__, __LINE__, barrier)
10718
/* Report that the "barrier" has been destroyed. */
10719
- #define _Py_ANNOTATE_BARRIER_DESTROY(barrier) \
10720
+#define _Py_ANNOTATE_BARRIER_DESTROY(barrier) \
10721
AnnotateBarrierDestroy(__FILE__, __LINE__, barrier)
10723
/* -------------------------------------------------------------
10724
@@ -310,61 +310,61 @@
10726
/* Report that we expect a race on the variable at "address".
10727
Use only in unit tests for a race detector. */
10728
- #define _Py_ANNOTATE_EXPECT_RACE(address, description) \
10729
+#define _Py_ANNOTATE_EXPECT_RACE(address, description) \
10730
AnnotateExpectRace(__FILE__, __LINE__, address, description)
10732
/* A no-op. Insert where you like to test the interceptors. */
10733
- #define _Py_ANNOTATE_NO_OP(arg) \
10734
+#define _Py_ANNOTATE_NO_OP(arg) \
10735
AnnotateNoOp(__FILE__, __LINE__, arg)
10737
/* Force the race detector to flush its state. The actual effect depends on
10738
* the implementation of the detector. */
10739
- #define _Py_ANNOTATE_FLUSH_STATE() \
10740
+#define _Py_ANNOTATE_FLUSH_STATE() \
10741
AnnotateFlushState(__FILE__, __LINE__)
10744
#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */
10746
- #define _Py_ANNOTATE_RWLOCK_CREATE(lock) /* empty */
10747
- #define _Py_ANNOTATE_RWLOCK_DESTROY(lock) /* empty */
10748
- #define _Py_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) /* empty */
10749
- #define _Py_ANNOTATE_RWLOCK_RELEASED(lock, is_w) /* empty */
10750
- #define _Py_ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) /* */
10751
- #define _Py_ANNOTATE_BARRIER_WAIT_BEFORE(barrier) /* empty */
10752
- #define _Py_ANNOTATE_BARRIER_WAIT_AFTER(barrier) /* empty */
10753
- #define _Py_ANNOTATE_BARRIER_DESTROY(barrier) /* empty */
10754
- #define _Py_ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) /* empty */
10755
- #define _Py_ANNOTATE_CONDVAR_WAIT(cv) /* empty */
10756
- #define _Py_ANNOTATE_CONDVAR_SIGNAL(cv) /* empty */
10757
- #define _Py_ANNOTATE_CONDVAR_SIGNAL_ALL(cv) /* empty */
10758
- #define _Py_ANNOTATE_HAPPENS_BEFORE(obj) /* empty */
10759
- #define _Py_ANNOTATE_HAPPENS_AFTER(obj) /* empty */
10760
- #define _Py_ANNOTATE_PUBLISH_MEMORY_RANGE(address, size) /* empty */
10761
- #define _Py_ANNOTATE_UNPUBLISH_MEMORY_RANGE(address, size) /* empty */
10762
- #define _Py_ANNOTATE_SWAP_MEMORY_RANGE(address, size) /* empty */
10763
- #define _Py_ANNOTATE_PCQ_CREATE(pcq) /* empty */
10764
- #define _Py_ANNOTATE_PCQ_DESTROY(pcq) /* empty */
10765
- #define _Py_ANNOTATE_PCQ_PUT(pcq) /* empty */
10766
- #define _Py_ANNOTATE_PCQ_GET(pcq) /* empty */
10767
- #define _Py_ANNOTATE_NEW_MEMORY(address, size) /* empty */
10768
- #define _Py_ANNOTATE_EXPECT_RACE(address, description) /* empty */
10769
- #define _Py_ANNOTATE_BENIGN_RACE(address, description) /* empty */
10770
- #define _Py_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) /* empty */
10771
- #define _Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) /* empty */
10772
- #define _Py_ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mu) /* empty */
10773
- #define _Py_ANNOTATE_TRACE_MEMORY(arg) /* empty */
10774
- #define _Py_ANNOTATE_THREAD_NAME(name) /* empty */
10775
- #define _Py_ANNOTATE_IGNORE_READS_BEGIN() /* empty */
10776
- #define _Py_ANNOTATE_IGNORE_READS_END() /* empty */
10777
- #define _Py_ANNOTATE_IGNORE_WRITES_BEGIN() /* empty */
10778
- #define _Py_ANNOTATE_IGNORE_WRITES_END() /* empty */
10779
- #define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() /* empty */
10780
- #define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_END() /* empty */
10781
- #define _Py_ANNOTATE_IGNORE_SYNC_BEGIN() /* empty */
10782
- #define _Py_ANNOTATE_IGNORE_SYNC_END() /* empty */
10783
- #define _Py_ANNOTATE_ENABLE_RACE_DETECTION(enable) /* empty */
10784
- #define _Py_ANNOTATE_NO_OP(arg) /* empty */
10785
- #define _Py_ANNOTATE_FLUSH_STATE() /* empty */
10786
+#define _Py_ANNOTATE_RWLOCK_CREATE(lock) /* empty */
10787
+#define _Py_ANNOTATE_RWLOCK_DESTROY(lock) /* empty */
10788
+#define _Py_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) /* empty */
10789
+#define _Py_ANNOTATE_RWLOCK_RELEASED(lock, is_w) /* empty */
10790
+#define _Py_ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) /* */
10791
+#define _Py_ANNOTATE_BARRIER_WAIT_BEFORE(barrier) /* empty */
10792
+#define _Py_ANNOTATE_BARRIER_WAIT_AFTER(barrier) /* empty */
10793
+#define _Py_ANNOTATE_BARRIER_DESTROY(barrier) /* empty */
10794
+#define _Py_ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) /* empty */
10795
+#define _Py_ANNOTATE_CONDVAR_WAIT(cv) /* empty */
10796
+#define _Py_ANNOTATE_CONDVAR_SIGNAL(cv) /* empty */
10797
+#define _Py_ANNOTATE_CONDVAR_SIGNAL_ALL(cv) /* empty */
10798
+#define _Py_ANNOTATE_HAPPENS_BEFORE(obj) /* empty */
10799
+#define _Py_ANNOTATE_HAPPENS_AFTER(obj) /* empty */
10800
+#define _Py_ANNOTATE_PUBLISH_MEMORY_RANGE(address, size) /* empty */
10801
+#define _Py_ANNOTATE_UNPUBLISH_MEMORY_RANGE(address, size) /* empty */
10802
+#define _Py_ANNOTATE_SWAP_MEMORY_RANGE(address, size) /* empty */
10803
+#define _Py_ANNOTATE_PCQ_CREATE(pcq) /* empty */
10804
+#define _Py_ANNOTATE_PCQ_DESTROY(pcq) /* empty */
10805
+#define _Py_ANNOTATE_PCQ_PUT(pcq) /* empty */
10806
+#define _Py_ANNOTATE_PCQ_GET(pcq) /* empty */
10807
+#define _Py_ANNOTATE_NEW_MEMORY(address, size) /* empty */
10808
+#define _Py_ANNOTATE_EXPECT_RACE(address, description) /* empty */
10809
+#define _Py_ANNOTATE_BENIGN_RACE(address, description) /* empty */
10810
+#define _Py_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) /* empty */
10811
+#define _Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) /* empty */
10812
+#define _Py_ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mu) /* empty */
10813
+#define _Py_ANNOTATE_TRACE_MEMORY(arg) /* empty */
10814
+#define _Py_ANNOTATE_THREAD_NAME(name) /* empty */
10815
+#define _Py_ANNOTATE_IGNORE_READS_BEGIN() /* empty */
10816
+#define _Py_ANNOTATE_IGNORE_READS_END() /* empty */
10817
+#define _Py_ANNOTATE_IGNORE_WRITES_BEGIN() /* empty */
10818
+#define _Py_ANNOTATE_IGNORE_WRITES_END() /* empty */
10819
+#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() /* empty */
10820
+#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_END() /* empty */
10821
+#define _Py_ANNOTATE_IGNORE_SYNC_BEGIN() /* empty */
10822
+#define _Py_ANNOTATE_IGNORE_SYNC_END() /* empty */
10823
+#define _Py_ANNOTATE_ENABLE_RACE_DETECTION(enable) /* empty */
10824
+#define _Py_ANNOTATE_NO_OP(arg) /* empty */
10825
+#define _Py_ANNOTATE_FLUSH_STATE() /* empty */
10827
#endif /* DYNAMIC_ANNOTATIONS_ENABLED */
10829
@@ -477,7 +477,7 @@
10832
/* Apply _Py_ANNOTATE_BENIGN_RACE_SIZED to a static variable. */
10833
- #define _Py_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \
10834
+#define _Py_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \
10836
class static_var ## _annotator { \
10838
@@ -491,8 +491,8 @@
10840
#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */
10842
- #define _Py_ANNOTATE_UNPROTECTED_READ(x) (x)
10843
- #define _Py_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) /* empty */
10844
+#define _Py_ANNOTATE_UNPROTECTED_READ(x) (x)
10845
+#define _Py_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) /* empty */
10847
#endif /* DYNAMIC_ANNOTATIONS_ENABLED */
10849
diff -r 137e45f15c0b Include/fileobject.h
10850
--- a/Include/fileobject.h
10851
+++ b/Include/fileobject.h
10854
#endif /* Py_LIMITED_API */
10856
+/* A routine to check if a file descriptor can be select()-ed. */
10857
+#ifdef HAVE_SELECT
10858
+ #define _PyIsSelectable_fd(FD) (((FD) >= 0) && ((FD) < FD_SETSIZE))
10860
+ #define _PyIsSelectable_fd(FD) (1)
10861
+#endif /* HAVE_SELECT */
10866
diff -r 137e45f15c0b Include/object.h
10867
--- a/Include/object.h
10868
+++ b/Include/object.h
10869
@@ -449,6 +449,7 @@
10870
#ifndef Py_LIMITED_API
10871
PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
10872
PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, char *, PyObject **);
10873
+PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
10875
PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
10876
PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
10877
diff -r 137e45f15c0b Include/patchlevel.h
10878
--- a/Include/patchlevel.h
10879
+++ b/Include/patchlevel.h
10881
#define PY_RELEASE_SERIAL 0
10883
/* Version as a string */
10884
-#define PY_VERSION "3.2.2"
10885
+#define PY_VERSION "3.2.2+"
10886
/*--end constants--*/
10888
/* Subversion Revision number of this file (not of the repository). Empty
10889
diff -r 137e45f15c0b Include/pyatomic.h
10890
--- a/Include/pyatomic.h
10891
+++ b/Include/pyatomic.h
10892
@@ -58,13 +58,15 @@
10893
static __inline__ void
10894
_Py_ANNOTATE_MEMORY_ORDER(const volatile void *address, _Py_memory_order order)
10896
+ (void)address; /* shut up -Wunused-parameter */
10898
case _Py_memory_order_release:
10899
case _Py_memory_order_acq_rel:
10900
case _Py_memory_order_seq_cst:
10901
_Py_ANNOTATE_HAPPENS_BEFORE(address);
10904
+ case _Py_memory_order_relaxed:
10905
+ case _Py_memory_order_acquire:
10910
case _Py_memory_order_seq_cst:
10911
_Py_ANNOTATE_HAPPENS_AFTER(address);
10914
+ case _Py_memory_order_relaxed:
10915
+ case _Py_memory_order_release:
10919
diff -r 137e45f15c0b Include/pyctype.h
10920
--- a/Include/pyctype.h
10921
+++ b/Include/pyctype.h
10923
#define PY_CTF_SPACE 0x08
10924
#define PY_CTF_XDIGIT 0x10
10926
-extern const unsigned int _Py_ctype_table[256];
10927
+PyAPI_DATA(const unsigned int) _Py_ctype_table[256];
10929
/* Unlike their C counterparts, the following macros are not meant to
10930
* handle an int with any of the values [EOF, 0-UCHAR_MAX]. The argument
10932
#define Py_ISALNUM(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_ALNUM)
10933
#define Py_ISSPACE(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_SPACE)
10935
-extern const unsigned char _Py_ctype_tolower[256];
10936
-extern const unsigned char _Py_ctype_toupper[256];
10937
+PyAPI_DATA(const unsigned char) _Py_ctype_tolower[256];
10938
+PyAPI_DATA(const unsigned char) _Py_ctype_toupper[256];
10940
#define Py_TOLOWER(c) (_Py_ctype_tolower[Py_CHARMASK(c)])
10941
#define Py_TOUPPER(c) (_Py_ctype_toupper[Py_CHARMASK(c)])
10942
diff -r 137e45f15c0b Include/pyport.h
10943
--- a/Include/pyport.h
10944
+++ b/Include/pyport.h
10945
@@ -131,6 +131,9 @@
10949
+/* Prime multiplier used in string and various other hashes. */
10950
+#define _PyHASH_MULTIPLIER 1000003 /* 0xf4243 */
10952
/* Parameters used for the numeric hash implementation. See notes for
10953
_PyHash_Double in Objects/object.c. Numeric hashes are based on
10954
reduction modulo the prime 2**_PyHASH_BITS - 1. */
10955
@@ -143,7 +146,7 @@
10956
#define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1)
10957
#define _PyHASH_INF 314159
10958
#define _PyHASH_NAN 0
10959
-#define _PyHASH_IMAG 1000003UL
10960
+#define _PyHASH_IMAG _PyHASH_MULTIPLIER
10962
/* uintptr_t is the C9X name for an unsigned integral type such that a
10963
* legitimate void* can be cast to uintptr_t and then back to void* again
10964
diff -r 137e45f15c0b Include/token.h
10965
--- a/Include/token.h
10966
+++ b/Include/token.h
10967
@@ -34,38 +34,37 @@
10971
-/* #define BACKQUOTE 25 */
10974
-#define EQEQUAL 28
10975
-#define NOTEQUAL 29
10976
-#define LESSEQUAL 30
10977
-#define GREATEREQUAL 31
10979
-#define CIRCUMFLEX 33
10980
-#define LEFTSHIFT 34
10981
-#define RIGHTSHIFT 35
10982
-#define DOUBLESTAR 36
10983
-#define PLUSEQUAL 37
10984
-#define MINEQUAL 38
10985
-#define STAREQUAL 39
10986
-#define SLASHEQUAL 40
10987
-#define PERCENTEQUAL 41
10988
-#define AMPEREQUAL 42
10989
-#define VBAREQUAL 43
10990
-#define CIRCUMFLEXEQUAL 44
10991
-#define LEFTSHIFTEQUAL 45
10992
-#define RIGHTSHIFTEQUAL 46
10993
-#define DOUBLESTAREQUAL 47
10994
-#define DOUBLESLASH 48
10995
-#define DOUBLESLASHEQUAL 49
10998
-#define ELLIPSIS 52
11001
+#define EQEQUAL 27
11002
+#define NOTEQUAL 28
11003
+#define LESSEQUAL 29
11004
+#define GREATEREQUAL 30
11006
+#define CIRCUMFLEX 32
11007
+#define LEFTSHIFT 33
11008
+#define RIGHTSHIFT 34
11009
+#define DOUBLESTAR 35
11010
+#define PLUSEQUAL 36
11011
+#define MINEQUAL 37
11012
+#define STAREQUAL 38
11013
+#define SLASHEQUAL 39
11014
+#define PERCENTEQUAL 40
11015
+#define AMPEREQUAL 41
11016
+#define VBAREQUAL 42
11017
+#define CIRCUMFLEXEQUAL 43
11018
+#define LEFTSHIFTEQUAL 44
11019
+#define RIGHTSHIFTEQUAL 45
11020
+#define DOUBLESTAREQUAL 46
11021
+#define DOUBLESLASH 47
11022
+#define DOUBLESLASHEQUAL 48
11025
+#define ELLIPSIS 51
11026
/* Don't forget to update the table _PyParser_TokenNames in tokenizer.c! */
11028
-#define ERRORTOKEN 54
11029
-#define N_TOKENS 55
11031
+#define ERRORTOKEN 53
11032
+#define N_TOKENS 54
11034
/* Special definitions for cooperation with parser */
11036
diff -r 137e45f15c0b Include/unicodeobject.h
11037
--- a/Include/unicodeobject.h
11038
+++ b/Include/unicodeobject.h
11039
@@ -595,7 +595,7 @@
11041
/* Convert the Unicode object to a wide character string. The output string
11042
always ends with a nul character. If size is not NULL, write the number of
11043
- wide characters (including the nul character) into *size.
11044
+ wide characters (excluding the null character) into *size.
11046
Returns a buffer allocated by PyMem_Alloc() (use PyMem_Free() to free it)
11047
on success. On error, returns NULL, *size is undefined and raises a
11048
@@ -1501,6 +1501,12 @@
11049
PyObject *element /* Element string */
11052
+/* Checks whether the string contains any NUL characters. */
11054
+#ifndef Py_LIMITED_API
11055
+PyAPI_FUNC(int) _PyUnicode_HasNULChars(PyObject *);
11058
/* Checks whether argument is a valid identifier. */
11060
PyAPI_FUNC(int) PyUnicode_IsIdentifier(PyObject *s);
11061
diff -r 137e45f15c0b LICENSE
11064
@@ -108,7 +108,7 @@
11065
distribute, and otherwise use Python alone or in any derivative version,
11066
provided, however, that PSF's License Agreement and PSF's notice of copyright,
11067
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
11068
-2011 Python Software Foundation; All Rights Reserved" are retained in Python
11069
+2011, 2012 Python Software Foundation; All Rights Reserved" are retained in Python
11070
alone or in any derivative version prepared by Licensee.
11072
3. In the event Licensee prepares a derivative work that is based on
11073
diff -r 137e45f15c0b Lib/_markupbase.py
11074
--- a/Lib/_markupbase.py
11075
+++ b/Lib/_markupbase.py
11076
@@ -107,6 +107,10 @@
11077
if decltype == "doctype":
11078
self.handle_decl(data)
11080
+ # According to the HTML5 specs sections "8.2.4.44 Bogus
11081
+ # comment state" and "8.2.4.45 Markup declaration open
11082
+ # state", a comment token should be emitted.
11083
+ # Calling unknown_decl provides more flexibility though.
11084
self.unknown_decl(data)
11087
diff -r 137e45f15c0b Lib/_pyio.py
11095
# Import _thread instead of threading to reduce startup cost
11097
from _thread import allocate_lock as Lock
11098
@@ -720,8 +721,11 @@
11101
if self.raw is not None and not self.closed:
11105
+ # may raise BlockingIOError or BrokenPipeError etc
11111
if self.raw is None:
11112
@@ -1080,13 +1084,9 @@
11113
# XXX we can implement some more tricks to try and avoid
11115
if len(self._write_buf) > self.buffer_size:
11116
- # We're full, so let's pre-flush the buffer
11118
- self._flush_unlocked()
11119
- except BlockingIOError as e:
11120
- # We can't accept anything else.
11121
- # XXX Why not just let the exception pass through?
11122
- raise BlockingIOError(e.errno, e.strerror, 0)
11123
+ # We're full, so let's pre-flush the buffer. (This may
11124
+ # raise BlockingIOError with characters_written == 0.)
11125
+ self._flush_unlocked()
11126
before = len(self._write_buf)
11127
self._write_buf.extend(b)
11128
written = len(self._write_buf) - before
11129
@@ -1117,24 +1117,23 @@
11130
def _flush_unlocked(self):
11132
raise ValueError("flush of closed file")
11135
- while self._write_buf:
11137
- n = self.raw.write(self._write_buf)
11138
- except IOError as e:
11139
- if e.errno != EINTR:
11142
- if n > len(self._write_buf) or n < 0:
11143
- raise IOError("write() returned incorrect number of bytes")
11144
- del self._write_buf[:n]
11146
- except BlockingIOError as e:
11147
- n = e.characters_written
11148
+ while self._write_buf:
11150
+ n = self.raw.write(self._write_buf)
11151
+ except BlockingIOError:
11152
+ raise RuntimeError("self.raw should implement RawIOBase: it "
11153
+ "should not raise BlockingIOError")
11154
+ except IOError as e:
11155
+ if e.errno != EINTR:
11159
+ raise BlockingIOError(
11161
+ "write could not complete without blocking", 0)
11162
+ if n > len(self._write_buf) or n < 0:
11163
+ raise IOError("write() returned incorrect number of bytes")
11164
del self._write_buf[:n]
11166
- raise BlockingIOError(e.errno, e.strerror, written)
11169
return _BufferedIOMixin.tell(self) + len(self._write_buf)
11170
@@ -1460,7 +1459,7 @@
11171
enabled. With this enabled, on input, the lines endings '\n', '\r',
11172
or '\r\n' are translated to '\n' before being returned to the
11173
caller. Conversely, on output, '\n' is translated to the system
11174
- default line seperator, os.linesep. If newline is any other of its
11175
+ default line separator, os.linesep. If newline is any other of its
11176
legal values, that newline becomes the newline when the file is read
11177
and it is returned untranslated. On output, '\n' is converted to the
11179
diff -r 137e45f15c0b Lib/aifc.py
11182
@@ -162,6 +162,12 @@
11183
except struct.error:
11186
+def _read_ushort(file):
11188
+ return struct.unpack('>H', file.read(2))[0]
11189
+ except struct.error:
11192
def _read_string(file):
11193
length = ord(file.read(1))
11195
@@ -194,13 +200,19 @@
11196
def _write_short(f, x):
11197
f.write(struct.pack('>h', x))
11199
+def _write_ushort(f, x):
11200
+ f.write(struct.pack('>H', x))
11202
def _write_long(f, x):
11203
+ f.write(struct.pack('>l', x))
11205
+def _write_ulong(f, x):
11206
f.write(struct.pack('>L', x))
11208
def _write_string(f, s):
11210
raise ValueError("string exceeds maximum pstring length")
11211
- f.write(struct.pack('b', len(s)))
11212
+ f.write(struct.pack('B', len(s)))
11214
if len(s) & 1 == 0:
11216
@@ -218,7 +230,7 @@
11219
fmant, expon = math.frexp(x)
11220
- if expon > 16384 or fmant >= 1: # Infinity or NaN
11221
+ if expon > 16384 or fmant >= 1 or fmant != fmant: # Infinity or NaN
11222
expon = sign|0x7FFF
11225
@@ -234,9 +246,9 @@
11226
fmant = math.ldexp(fmant - fsmant, 32)
11227
fsmant = math.floor(fmant)
11228
lomant = int(fsmant)
11229
- _write_short(f, expon)
11230
- _write_long(f, himant)
11231
- _write_long(f, lomant)
11232
+ _write_ushort(f, expon)
11233
+ _write_ulong(f, himant)
11234
+ _write_ulong(f, lomant)
11236
from chunk import Chunk
11238
@@ -539,8 +551,7 @@
11239
self._aifc = 1 # AIFF-C is default
11247
# User visible methods.
11248
@@ -643,8 +654,8 @@
11249
raise Error('marker ID must be > 0')
11251
raise Error('marker position must be >= 0')
11252
- if not isinstance(name, str):
11253
- raise Error('marker name must be a string')
11254
+ if not isinstance(name, bytes):
11255
+ raise Error('marker name must be bytes')
11256
for i in range(len(self._markers)):
11257
if id == self._markers[i][0]:
11258
self._markers[i] = id, pos, name
11259
@@ -681,19 +692,21 @@
11260
self._patchheader()
11263
- self._ensure_header_written(0)
11264
- if self._datawritten & 1:
11265
- # quick pad to even size
11266
- self._file.write(b'\x00')
11267
- self._datawritten = self._datawritten + 1
11268
- self._writemarkers()
11269
- if self._nframeswritten != self._nframes or \
11270
- self._datalength != self._datawritten or \
11271
- self._marklength:
11272
- self._patchheader()
11273
- # Prevent ref cycles
11274
- self._convert = None
11275
- self._file.close()
11277
+ self._ensure_header_written(0)
11278
+ if self._datawritten & 1:
11279
+ # quick pad to even size
11280
+ self._file.write(b'\x00')
11281
+ self._datawritten = self._datawritten + 1
11282
+ self._writemarkers()
11283
+ if self._nframeswritten != self._nframes or \
11284
+ self._datalength != self._datawritten or \
11285
+ self._marklength:
11286
+ self._patchheader()
11287
+ # Prevent ref cycles
11288
+ self._convert = None
11289
+ self._file.close()
11290
+ self._file = None
11293
# Internal methods.
11294
@@ -716,18 +729,12 @@
11296
def _ensure_header_written(self, datasize):
11297
if not self._nframeswritten:
11298
- if self._comptype in (b'ULAW', b'ALAW'):
11299
+ if self._comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'):
11300
if not self._sampwidth:
11301
self._sampwidth = 2
11302
if self._sampwidth != 2:
11303
raise Error('sample width must be 2 when compressing '
11304
- 'with ulaw/ULAW or alaw/ALAW')
11305
- if self._comptype == b'G722':
11306
- if not self._sampwidth:
11307
- self._sampwidth = 2
11308
- if self._sampwidth != 2:
11309
- raise Error('sample width must be 2 when compressing '
11310
- 'with G7.22 (ADPCM)')
11311
+ 'with ulaw/ULAW, alaw/ALAW or G7.22 (ADPCM)')
11312
if not self._nchannels:
11313
raise Error('# channels not specified')
11314
if not self._sampwidth:
11315
@@ -743,8 +750,6 @@
11316
self._convert = self._lin2ulaw
11317
elif self._comptype in (b'alaw', b'ALAW'):
11318
self._convert = self._lin2alaw
11320
- raise Error('unsupported compression type')
11322
def _write_header(self, initlength):
11323
if self._aifc and self._comptype != b'NONE':
11324
@@ -769,15 +774,15 @@
11326
self._file.write(b'AIFC')
11327
self._file.write(b'FVER')
11328
- _write_long(self._file, 4)
11329
- _write_long(self._file, self._version)
11330
+ _write_ulong(self._file, 4)
11331
+ _write_ulong(self._file, self._version)
11333
self._file.write(b'AIFF')
11334
self._file.write(b'COMM')
11335
- _write_long(self._file, commlength)
11336
+ _write_ulong(self._file, commlength)
11337
_write_short(self._file, self._nchannels)
11338
self._nframes_pos = self._file.tell()
11339
- _write_long(self._file, self._nframes)
11340
+ _write_ulong(self._file, self._nframes)
11341
_write_short(self._file, self._sampwidth * 8)
11342
_write_float(self._file, self._framerate)
11344
@@ -785,9 +790,9 @@
11345
_write_string(self._file, self._compname)
11346
self._file.write(b'SSND')
11347
self._ssnd_length_pos = self._file.tell()
11348
- _write_long(self._file, self._datalength + 8)
11349
- _write_long(self._file, 0)
11350
- _write_long(self._file, 0)
11351
+ _write_ulong(self._file, self._datalength + 8)
11352
+ _write_ulong(self._file, 0)
11353
+ _write_ulong(self._file, 0)
11355
def _write_form_length(self, datalength):
11357
@@ -798,8 +803,8 @@
11361
- _write_long(self._file, 4 + verslength + self._marklength + \
11362
- 8 + commlength + 16 + datalength)
11363
+ _write_ulong(self._file, 4 + verslength + self._marklength + \
11364
+ 8 + commlength + 16 + datalength)
11367
def _patchheader(self):
11368
@@ -817,9 +822,9 @@
11369
self._file.seek(self._form_length_pos, 0)
11370
dummy = self._write_form_length(datalength)
11371
self._file.seek(self._nframes_pos, 0)
11372
- _write_long(self._file, self._nframeswritten)
11373
+ _write_ulong(self._file, self._nframeswritten)
11374
self._file.seek(self._ssnd_length_pos, 0)
11375
- _write_long(self._file, datalength + 8)
11376
+ _write_ulong(self._file, datalength + 8)
11377
self._file.seek(curpos, 0)
11378
self._nframes = self._nframeswritten
11379
self._datalength = datalength
11380
@@ -834,13 +839,13 @@
11381
length = length + len(name) + 1 + 6
11382
if len(name) & 1 == 0:
11383
length = length + 1
11384
- _write_long(self._file, length)
11385
+ _write_ulong(self._file, length)
11386
self._marklength = length + 8
11387
_write_short(self._file, len(self._markers))
11388
for marker in self._markers:
11389
id, pos, name = marker
11390
_write_short(self._file, id)
11391
- _write_long(self._file, pos)
11392
+ _write_ulong(self._file, pos)
11393
_write_string(self._file, name)
11395
def open(f, mode=None):
11396
diff -r 137e45f15c0b Lib/argparse.py
11397
--- a/Lib/argparse.py
11398
+++ b/Lib/argparse.py
11400
from gettext import gettext as _, ngettext
11403
-def _callable(obj):
11404
- return hasattr(obj, '__call__') or hasattr(obj, '__bases__')
11407
SUPPRESS = '==SUPPRESS=='
11410
@@ -1286,13 +1282,13 @@
11412
# create the action object, and add it to the parser
11413
action_class = self._pop_action_class(kwargs)
11414
- if not _callable(action_class):
11415
+ if not callable(action_class):
11416
raise ValueError('unknown action "%s"' % (action_class,))
11417
action = action_class(**kwargs)
11419
# raise an error if the action type is not callable
11420
type_func = self._registry_get('type', action.type, action.type)
11421
- if not _callable(type_func):
11422
+ if not callable(type_func):
11423
raise ValueError('%r is not callable' % (type_func,))
11425
# raise an error if the metavar does not match the type
11426
@@ -2240,7 +2236,7 @@
11428
def _get_value(self, action, arg_string):
11429
type_func = self._registry_get('type', action.type, action.type)
11430
- if not _callable(type_func):
11431
+ if not callable(type_func):
11432
msg = _('%r is not callable')
11433
raise ArgumentError(action, msg % type_func)
11435
diff -r 137e45f15c0b Lib/cgi.py
11438
@@ -291,7 +291,7 @@
11439
while s[:1] == ';':
11442
- while end > 0 and s.count('"', 0, end) % 2:
11443
+ while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
11444
end = s.find(';', end + 1)
11447
diff -r 137e45f15c0b Lib/cmd.py
11450
@@ -205,6 +205,8 @@
11452
return self.default(line)
11453
self.lastcmd = line
11454
+ if line == 'EOF' :
11455
+ self.lastcmd = ''
11457
return self.default(line)
11459
diff -r 137e45f15c0b Lib/collections.py
11460
--- a/Lib/collections.py
11461
+++ b/Lib/collections.py
11463
# The circular doubly linked list starts and ends with a sentinel element.
11464
# The sentinel element never gets deleted (this simplifies the algorithm).
11465
# The sentinel is in self.__hardroot with a weakref proxy in self.__root.
11466
- # The prev/next links are weakref proxies (to prevent circular references).
11467
+ # The prev links are weakref proxies (to prevent circular references).
11468
# Individual links are kept alive by the hard reference in self.__map.
11469
# Those hard references disappear when a key is deleted from an OrderedDict.
11471
@@ -583,8 +583,12 @@
11472
def __repr__(self):
11474
return '%s()' % self.__class__.__name__
11475
- items = ', '.join(map('%r: %r'.__mod__, self.most_common()))
11476
- return '%s({%s})' % (self.__class__.__name__, items)
11478
+ items = ', '.join(map('%r: %r'.__mod__, self.most_common()))
11479
+ return '%s({%s})' % (self.__class__.__name__, items)
11480
+ except TypeError:
11481
+ # handle case where values are not orderable
11482
+ return '{0}({1!r})'.format(self.__class__.__name__, dict(self))
11484
# Multiset-style mathematical operations discussed in:
11485
# Knuth TAOCP Volume II section 4.6.3 exercise 19
11486
diff -r 137e45f15c0b Lib/compileall.py
11487
--- a/Lib/compileall.py
11488
+++ b/Lib/compileall.py
11489
@@ -142,7 +142,7 @@
11491
Arguments (all optional):
11493
- skip_curdir: if true, skip current directory (default true)
11494
+ skip_curdir: if true, skip current directory (default True)
11495
maxlevels: max recursion level (default 0)
11496
force: as for compile_dir() (default False)
11497
quiet: as for compile_dir() (default False)
11498
@@ -177,17 +177,17 @@
11499
help='use legacy (pre-PEP3147) compiled file locations')
11500
parser.add_argument('-d', metavar='DESTDIR', dest='ddir', default=None,
11501
help=('directory to prepend to file paths for use in '
11502
- 'compile time tracebacks and in runtime '
11503
+ 'compile-time tracebacks and in runtime '
11504
'tracebacks in cases where the source file is '
11506
parser.add_argument('-x', metavar='REGEXP', dest='rx', default=None,
11507
- help=('skip files matching the regular expression. '
11508
- 'The regexp is searched for in the full path '
11509
- 'to each file considered for compilation.'))
11510
+ help=('skip files matching the regular expression; '
11511
+ 'the regexp is searched for in the full path '
11512
+ 'of each file considered for compilation'))
11513
parser.add_argument('-i', metavar='FILE', dest='flist',
11514
help=('add all the files and directories listed in '
11515
- 'FILE to the list considered for compilation. '
11516
- 'If "-", names are read from stdin.'))
11517
+ 'FILE to the list considered for compilation; '
11518
+ 'if "-", names are read from stdin'))
11519
parser.add_argument('compile_dest', metavar='FILE|DIR', nargs='*',
11520
help=('zero or more file and directory names '
11521
'to compile; if no arguments given, defaults '
11522
diff -r 137e45f15c0b Lib/concurrent/futures/process.py
11523
--- a/Lib/concurrent/futures/process.py
11524
+++ b/Lib/concurrent/futures/process.py
11525
@@ -213,9 +213,7 @@
11526
work_item.future.set_exception(result_item.exception)
11528
work_item.future.set_result(result_item.result)
11530
- # If we come here, we either got a timeout or were explicitly woken up.
11531
- # In either case, check whether we should start shutting down.
11532
+ # Check whether we should start shutting down.
11533
executor = executor_reference()
11534
# No more work items can be added if:
11535
# - The interpreter is shutting down OR
11536
@@ -234,9 +232,6 @@
11541
- # Start shutting down by telling a process it can exit.
11542
- shutdown_one_process()
11545
_system_limits_checked = False
11546
diff -r 137e45f15c0b Lib/configparser.py
11547
--- a/Lib/configparser.py
11548
+++ b/Lib/configparser.py
11549
@@ -381,7 +381,7 @@
11551
would resolve the "%(dir)s" to the value of dir. All reference
11552
expansions are done late, on demand. If a user needs to use a bare % in
11553
- a configuration file, she can escape it by writing %%. Other other % usage
11554
+ a configuration file, she can escape it by writing %%. Other % usage
11555
is considered a user error and raises `InterpolationSyntaxError'."""
11557
_KEYCRE = re.compile(r"%\(([^)]+)\)s")
11558
diff -r 137e45f15c0b Lib/copyreg.py
11559
--- a/Lib/copyreg.py
11560
+++ b/Lib/copyreg.py
11562
dispatch_table = {}
11564
def pickle(ob_type, pickle_function, constructor_ob=None):
11565
- if not hasattr(pickle_function, '__call__'):
11566
+ if not callable(pickle_function):
11567
raise TypeError("reduction functions must be callable")
11568
dispatch_table[ob_type] = pickle_function
11571
constructor(constructor_ob)
11573
def constructor(object):
11574
- if not hasattr(object, '__call__'):
11575
+ if not callable(object):
11576
raise TypeError("constructors must be callable")
11578
# Example: provide pickling support for complex numbers.
11579
diff -r 137e45f15c0b Lib/ctypes/__init__.py
11580
--- a/Lib/ctypes/__init__.py
11581
+++ b/Lib/ctypes/__init__.py
11582
@@ -265,7 +265,21 @@
11583
class c_wchar(_SimpleCData):
11586
-POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param
11587
+def _reset_cache():
11588
+ _pointer_type_cache.clear()
11589
+ _c_functype_cache.clear()
11590
+ if _os.name in ("nt", "ce"):
11591
+ _win_functype_cache.clear()
11592
+ # _SimpleCData.c_wchar_p_from_param
11593
+ POINTER(c_wchar).from_param = c_wchar_p.from_param
11594
+ # _SimpleCData.c_char_p_from_param
11595
+ POINTER(c_char).from_param = c_char_p.from_param
11596
+ _pointer_type_cache[None] = c_void_p
11597
+ # XXX for whatever reasons, creating the first instance of a callback
11598
+ # function is needed for the unittests on Win64 to succeed. This MAY
11599
+ # be a compiler bug, since the problem occurs only when _ctypes is
11600
+ # compiled with the MS SDK compiler. Or an uninitialized variable?
11601
+ CFUNCTYPE(c_int)(lambda: None)
11603
def create_unicode_buffer(init, size=None):
11604
"""create_unicode_buffer(aString) -> character array
11605
@@ -285,7 +299,6 @@
11607
raise TypeError(init)
11609
-POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param
11612
def SetPointerType(pointer, cls):
11613
@@ -445,8 +458,6 @@
11614
descr = FormatError(code).strip()
11615
return WindowsError(code, descr)
11617
-_pointer_type_cache[None] = c_void_p
11619
if sizeof(c_uint) == sizeof(c_void_p):
11622
@@ -529,8 +540,4 @@
11623
elif sizeof(kind) == 8: c_uint64 = kind
11626
-# XXX for whatever reasons, creating the first instance of a callback
11627
-# function is needed for the unittests on Win64 to succeed. This MAY
11628
-# be a compiler bug, since the problem occurs only when _ctypes is
11629
-# compiled with the MS SDK compiler. Or an uninitialized variable?
11630
-CFUNCTYPE(c_int)(lambda: None)
11632
diff -r 137e45f15c0b Lib/ctypes/_endian.py
11633
--- a/Lib/ctypes/_endian.py
11634
+++ b/Lib/ctypes/_endian.py
11637
from ctypes import *
11639
-_array_type = type(c_int * 3)
11640
+_array_type = type(Array)
11642
def _other_endian(typ):
11643
"""Return the type with the 'other' byte order. Simple types like
11644
diff -r 137e45f15c0b Lib/ctypes/test/test_arrays.py
11645
--- a/Lib/ctypes/test/test_arrays.py
11646
+++ b/Lib/ctypes/test/test_arrays.py
11647
@@ -127,5 +127,57 @@
11649
self.assertTrue(t1 is t2)
11651
+ def test_subclass(self):
11666
+ for c in [T, U, V, W]:
11667
+ self.assertEqual(c._type_, c_int)
11668
+ self.assertEqual(c._length_, 13)
11669
+ self.assertEqual(c()._type_, c_int)
11670
+ self.assertEqual(c()._length_, 13)
11672
+ self.assertEqual(X._type_, c_short)
11673
+ self.assertEqual(X._length_, 13)
11674
+ self.assertEqual(X()._type_, c_short)
11675
+ self.assertEqual(X()._length_, 13)
11677
+ self.assertEqual(Y._type_, c_int)
11678
+ self.assertEqual(Y._length_, 187)
11679
+ self.assertEqual(Y()._type_, c_int)
11680
+ self.assertEqual(Y()._length_, 187)
11682
+ def test_bad_subclass(self):
11685
+ with self.assertRaises(AttributeError):
11688
+ with self.assertRaises(AttributeError):
11691
+ with self.assertRaises(AttributeError):
11694
+ with self.assertRaises(OverflowError):
11697
+ _length_ = sys.maxsize * 2
11698
+ with self.assertRaises(AttributeError):
11703
if __name__ == '__main__':
11705
diff -r 137e45f15c0b Lib/ctypes/test/test_as_parameter.py
11706
--- a/Lib/ctypes/test/test_as_parameter.py
11707
+++ b/Lib/ctypes/test/test_as_parameter.py
11709
def test_callbacks(self):
11710
f = dll._testfunc_callback_i_if
11712
+ f.argtypes = None
11714
MyCallback = CFUNCTYPE(c_int, c_int)
11716
diff -r 137e45f15c0b Lib/ctypes/test/test_callbacks.py
11717
--- a/Lib/ctypes/test/test_callbacks.py
11718
+++ b/Lib/ctypes/test/test_callbacks.py
11719
@@ -134,6 +134,14 @@
11720
if isinstance(x, X)]
11721
self.assertEqual(len(live), 0)
11723
+ def test_issue12483(self):
11726
+ def __del__(self):
11728
+ CFUNCTYPE(None)(lambda x=Nasty(): None)
11734
diff -r 137e45f15c0b Lib/ctypes/test/test_functions.py
11735
--- a/Lib/ctypes/test/test_functions.py
11736
+++ b/Lib/ctypes/test/test_functions.py
11737
@@ -250,6 +250,7 @@
11738
def test_callbacks(self):
11739
f = dll._testfunc_callback_i_if
11741
+ f.argtypes = None
11743
MyCallback = CFUNCTYPE(c_int, c_int)
11745
diff -r 137e45f15c0b Lib/ctypes/test/test_structures.py
11746
--- a/Lib/ctypes/test/test_structures.py
11747
+++ b/Lib/ctypes/test/test_structures.py
11748
@@ -239,6 +239,14 @@
11750
self.assertRaises(TypeError, setattr, POINT, "_fields_", [("x", 1), ("y", 2)])
11752
+ def test_invalid_name(self):
11753
+ # field name must be string
11754
+ def declare_with_name(name):
11755
+ class S(Structure):
11756
+ _fields_ = [(name, c_int)]
11758
+ self.assertRaises(TypeError, declare_with_name, b"x")
11760
def test_intarray_fields(self):
11761
class SomeInts(Structure):
11762
_fields_ = [("a", c_int * 4)]
11763
@@ -318,6 +326,18 @@
11765
self.assertEqual(msg, "(Phone) TypeError: too many initializers")
11767
+ def test_huge_field_name(self):
11768
+ # issue12881: segfault with large structure field names
11769
+ def create_class(length):
11770
+ class S(Structure):
11771
+ _fields_ = [('x' * length, c_int)]
11773
+ for length in [10 ** i for i in range(0, 8)]:
11775
+ create_class(length)
11776
+ except MemoryError:
11777
+ # MemoryErrors are OK, we just don't want to segfault
11780
def get_except(self, func, *args):
952
print("In global scope:", spam)
954
-The output of the example code is::
955
+The output of the example code is:
957
+.. code-block:: none
960
After local assignment: test spam
961
After nonlocal assignment: nonlocal spam
962
diff -r 7085403daf43 Lib/_weakrefset.py
963
--- a/Lib/_weakrefset.py
964
+++ b/Lib/_weakrefset.py
969
- return sum(x() is not None for x in self.data)
970
+ return len(self.data) - len(self._pending_removals)
972
def __contains__(self, item):
11782
diff -r 137e45f15c0b Lib/ctypes/util.py
11783
--- a/Lib/ctypes/util.py
11784
+++ b/Lib/ctypes/util.py
11785
@@ -171,22 +171,6 @@
11789
- def _findLib_ldconfig(name):
11790
- # XXX assuming GLIBC's ldconfig (with option -p)
11791
- expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
11792
- with contextlib.closing(os.popen('/sbin/ldconfig -p 2>/dev/null')) as f:
11794
- res = re.search(expr, data)
11796
- # Hm, this works only for libs needed by the python executable.
11797
- cmd = 'ldd %s 2>/dev/null' % sys.executable
11798
- with contextlib.closing(os.popen(cmd)) as f:
11800
- res = re.search(expr, data)
11803
- return res.group(0)
974
@@ -114,36 +114,21 @@
975
def update(self, other):
976
if self._pending_removals:
977
self._commit_removals()
978
- if isinstance(other, self.__class__):
979
- self.data.update(other.data)
981
- for element in other:
983
+ for element in other:
986
def __ior__(self, other):
990
- # Helper functions for simple delegating methods.
991
- def _apply(self, other, method):
992
- if not isinstance(other, self.__class__):
993
- other = self.__class__(other)
994
- newdata = method(other.data)
995
- newset = self.__class__()
996
- newset.data = newdata
997
+ def difference(self, other):
998
+ newset = self.copy()
999
+ newset.difference_update(other)
11805
def _findSoname_ldconfig(name):
11807
if struct.calcsize('l') == 4:
11808
@@ -203,8 +187,7 @@
11809
abi_type = mach_map.get(machine, 'libc6')
11811
# XXX assuming GLIBC's ldconfig (with option -p)
11812
- expr = r'(\S+)\s+\((%s(?:, OS ABI:[^\)]*)?)\)[^/]*(/[^\(\)\s]*lib%s\.[^\(\)\s]*)' \
11813
- % (abi_type, re.escape(name))
11814
+ expr = r'\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)
11815
with contextlib.closing(os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null')) as f:
11817
res = re.search(expr, data)
11818
diff -r 137e45f15c0b Lib/curses/__init__.py
11819
--- a/Lib/curses/__init__.py
11820
+++ b/Lib/curses/__init__.py
11825
- from has_key import has_key
11826
+ from .has_key import has_key
11827
diff -r 137e45f15c0b Lib/datetime.py
11828
--- a/Lib/datetime.py
11829
+++ b/Lib/datetime.py
11830
@@ -2057,7 +2057,7 @@
11832
Because we know z.d said z was in daylight time (else [5] would have held and
11833
we would have stopped then), and we know z.d != z'.d (else [8] would have held
11834
-and we we have stopped then), and there are only 2 possible values dst() can
11835
+and we have stopped then), and there are only 2 possible values dst() can
11836
return in Eastern, it follows that z'.d must be 0 (which it is in the example,
11837
but the reasoning doesn't depend on the example -- it depends on there being
11838
two possible dst() outcomes, one zero and the other non-zero). Therefore
11839
diff -r 137e45f15c0b Lib/dbm/__init__.py
11840
--- a/Lib/dbm/__init__.py
11841
+++ b/Lib/dbm/__init__.py
11842
@@ -166,7 +166,7 @@
11845
# Check for GNU dbm
11846
- if magic == 0x13579ace:
11847
+ if magic in (0x13579ace, 0x13579acd, 0x13579acf):
11850
# Later versions of Berkeley db hash file have a 12-byte pad in
11851
diff -r 137e45f15c0b Lib/distutils/command/bdist_rpm.py
11852
--- a/Lib/distutils/command/bdist_rpm.py
11853
+++ b/Lib/distutils/command/bdist_rpm.py
11854
@@ -365,16 +365,28 @@
11855
self.spawn(rpm_cmd)
11857
if not self.dry_run:
11858
+ if self.distribution.has_ext_modules():
11859
+ pyversion = get_python_version()
11861
+ pyversion = 'any'
11863
if not self.binary_only:
11864
srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
11865
assert(os.path.exists(srpm))
11866
self.move_file(srpm, self.dist_dir)
11867
+ filename = os.path.join(self.dist_dir, source_rpm)
11868
+ self.distribution.dist_files.append(
11869
+ ('bdist_rpm', pyversion, filename))
11871
if not self.source_only:
11872
for rpm in binary_rpms:
11873
rpm = os.path.join(rpm_dir['RPMS'], rpm)
11874
if os.path.exists(rpm):
11875
self.move_file(rpm, self.dist_dir)
11876
+ filename = os.path.join(self.dist_dir,
11877
+ os.path.basename(rpm))
11878
+ self.distribution.dist_files.append(
11879
+ ('bdist_rpm', pyversion, filename))
11881
def _dist_path(self, path):
11882
return os.path.join(self.dist_dir, os.path.basename(path))
11883
diff -r 137e45f15c0b Lib/distutils/command/build_ext.py
11884
--- a/Lib/distutils/command/build_ext.py
11885
+++ b/Lib/distutils/command/build_ext.py
11886
@@ -165,8 +165,7 @@
11887
if plat_py_include != py_include:
11888
self.include_dirs.append(plat_py_include)
11890
- if isinstance(self.libraries, str):
11891
- self.libraries = [self.libraries]
11892
+ self.ensure_string_list('libraries')
11894
# Life is easier if we're not forever checking for None, so
11895
# simplify these options to empty lists if unset
11896
diff -r 137e45f15c0b Lib/distutils/command/build_py.py
11897
--- a/Lib/distutils/command/build_py.py
11898
+++ b/Lib/distutils/command/build_py.py
11901
Implements the Distutils 'build_py' command."""
11907
from glob import glob
11909
@@ -311,9 +312,11 @@
11910
outputs.append(filename)
11911
if include_bytecode:
11913
- outputs.append(filename + "c")
11914
+ outputs.append(imp.cache_from_source(filename,
11915
+ debug_override=True))
11916
if self.optimize > 0:
11917
- outputs.append(filename + "o")
11918
+ outputs.append(imp.cache_from_source(filename,
11919
+ debug_override=False))
11922
os.path.join(build_dir, filename)
11923
diff -r 137e45f15c0b Lib/distutils/command/install_egg_info.py
11924
--- a/Lib/distutils/command/install_egg_info.py
11925
+++ b/Lib/distutils/command/install_egg_info.py
11927
"Creating "+self.install_dir)
11928
log.info("Writing %s", target)
11929
if not self.dry_run:
11930
- f = open(target, 'w')
11931
- self.distribution.metadata.write_pkg_file(f)
11933
+ with open(target, 'w', encoding='UTF-8') as f:
11934
+ self.distribution.metadata.write_pkg_file(f)
11936
def get_outputs(self):
11937
return self.outputs
11938
diff -r 137e45f15c0b Lib/distutils/command/install_lib.py
11939
--- a/Lib/distutils/command/install_lib.py
11940
+++ b/Lib/distutils/command/install_lib.py
11942
(install all Python modules)."""
11948
from distutils.core import Command
11949
@@ -164,9 +165,11 @@
11950
if ext != PYTHON_SOURCE_EXTENSION:
11953
- bytecode_files.append(py_file + "c")
11954
+ bytecode_files.append(imp.cache_from_source(
11955
+ py_file, debug_override=True))
11956
if self.optimize > 0:
11957
- bytecode_files.append(py_file + "o")
11958
+ bytecode_files.append(imp.cache_from_source(
11959
+ py_file, debug_override=False))
11961
return bytecode_files
11963
diff -r 137e45f15c0b Lib/distutils/command/sdist.py
11964
--- a/Lib/distutils/command/sdist.py
11965
+++ b/Lib/distutils/command/sdist.py
11966
@@ -306,7 +306,10 @@
11969
self.filelist.process_template_line(line)
11970
- except DistutilsTemplateError as msg:
11971
+ # the call above can raise a DistutilsTemplateError for
11972
+ # malformed lines, or a ValueError from the lower-level
11973
+ # convert_path function
11974
+ except (DistutilsTemplateError, ValueError) as msg:
11975
self.warn("%s, line %d: %s" % (template.filename,
11976
template.current_line,
11978
diff -r 137e45f15c0b Lib/distutils/dist.py
11979
--- a/Lib/distutils/dist.py
11980
+++ b/Lib/distutils/dist.py
11981
@@ -537,7 +537,7 @@
11982
for (help_option, short, desc, func) in cmd_class.help_options:
11983
if hasattr(opts, parser.get_attr_name(help_option)):
11984
help_option_found=1
11985
- if hasattr(func, '__call__'):
11986
+ if callable(func):
11989
raise DistutilsClassError(
11990
@@ -1010,17 +1010,16 @@
11991
def write_pkg_info(self, base_dir):
11992
"""Write the PKG-INFO file into the release tree.
11994
- pkg_info = open(os.path.join(base_dir, 'PKG-INFO'), 'w')
11996
+ with open(os.path.join(base_dir, 'PKG-INFO'), 'w',
11997
+ encoding='UTF-8') as pkg_info:
11998
self.write_pkg_file(pkg_info)
12002
def write_pkg_file(self, file):
12003
"""Write the PKG-INFO format data to a file object.
12006
- if self.provides or self.requires or self.obsoletes:
12007
+ if (self.provides or self.requires or self.obsoletes or
12008
+ self.classifiers or self.download_url):
12011
file.write('Metadata-Version: %s\n' % version)
12012
diff -r 137e45f15c0b Lib/distutils/filelist.py
1002
- def difference(self, other):
1003
- return self._apply(other, self.data.difference)
1004
__sub__ = difference
1006
def difference_update(self, other):
1007
- if self._pending_removals:
1008
- self._commit_removals()
1012
- self.data.difference_update(ref(item) for item in other)
1013
+ self.__isub__(other)
1014
def __isub__(self, other):
1015
if self._pending_removals:
1016
self._commit_removals()
1017
@@ -154,13 +139,11 @@
1020
def intersection(self, other):
1021
- return self._apply(other, self.data.intersection)
1022
+ return self.__class__(item for item in other if item in self)
1023
__and__ = intersection
1025
def intersection_update(self, other):
1026
- if self._pending_removals:
1027
- self._commit_removals()
1028
- self.data.intersection_update(ref(item) for item in other)
1029
+ self.__iand__(other)
1030
def __iand__(self, other):
1031
if self._pending_removals:
1032
self._commit_removals()
1033
@@ -169,17 +152,17 @@
1035
def issubset(self, other):
1036
return self.data.issubset(ref(item) for item in other)
1040
- def __le__(self, other):
1041
- return self.data <= set(ref(item) for item in other)
1042
+ def __lt__(self, other):
1043
+ return self.data < set(ref(item) for item in other)
1045
def issuperset(self, other):
1046
return self.data.issuperset(ref(item) for item in other)
1047
- __gt__ = issuperset
1048
+ __ge__ = issuperset
1050
- def __ge__(self, other):
1051
- return self.data >= set(ref(item) for item in other)
1052
+ def __gt__(self, other):
1053
+ return self.data > set(ref(item) for item in other)
1055
def __eq__(self, other):
1056
if not isinstance(other, self.__class__):
1057
@@ -187,27 +170,24 @@
1058
return self.data == set(ref(item) for item in other)
1060
def symmetric_difference(self, other):
1061
- return self._apply(other, self.data.symmetric_difference)
1062
+ newset = self.copy()
1063
+ newset.symmetric_difference_update(other)
1065
__xor__ = symmetric_difference
1067
def symmetric_difference_update(self, other):
1068
- if self._pending_removals:
1069
- self._commit_removals()
1073
- self.data.symmetric_difference_update(ref(item) for item in other)
1074
+ self.__ixor__(other)
1075
def __ixor__(self, other):
1076
if self._pending_removals:
1077
self._commit_removals()
1081
- self.data.symmetric_difference_update(ref(item) for item in other)
1082
+ self.data.symmetric_difference_update(ref(item, self._remove) for item in other)
1085
def union(self, other):
1086
- return self._apply(other, self.data.union)
1087
+ return self.__class__(e for s in (self, other) for e in s)
1090
def isdisjoint(self, other):
1091
diff -r 7085403daf43 Lib/distutils/filelist.py
12013
1092
--- a/Lib/distutils/filelist.py
12014
1093
+++ b/Lib/distutils/filelist.py
12015
@@ -313,7 +313,8 @@
1096
Return True if files are found, False otherwise.
1098
+ # XXX docstring lying about what the special chars are?
1100
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
1101
self.debug_print("include_pattern: applying regex r'%s'" %
1102
@@ -284,11 +285,14 @@
1103
# IMHO is wrong -- '?' and '*' aren't supposed to match slash in Unix,
1104
# and by extension they shouldn't match such "special characters" under
1105
# any OS. So change all non-escaped dots in the RE to match any
1106
- # character except the special characters.
1107
- # XXX currently the "special characters" are just slash -- i.e. this is
1109
- pattern_re = re.sub(r'((?<!\\)(\\\\)*)\.', r'\1[^/]', pattern_re)
1111
+ # character except the special characters (currently: just os.sep).
1113
+ if os.sep == '\\':
1114
+ # we're using a regex to manipulate a regex, so we need
1115
+ # to escape the backslash twice
1117
+ escaped = r'\1[^%s]' % sep
1118
+ pattern_re = re.sub(r'((?<!\\)(\\\\)*)\.', escaped, pattern_re)
1122
@@ -312,9 +316,11 @@
1123
if prefix is not None:
12016
1124
# ditch end of pattern character
12017
1125
empty_pattern = glob_to_re('')
12018
prefix_re = (glob_to_re(prefix))[:-len(empty_pattern)]
12019
- pattern_re = "^" + os.path.join(prefix_re, ".*" + pattern_re)
12020
+ # paths should always use / in manifest templates
12021
+ pattern_re = "^%s/.*%s" % (prefix_re, pattern_re)
1126
- prefix_re = (glob_to_re(prefix))[:-len(empty_pattern)]
1127
- # paths should always use / in manifest templates
1128
- pattern_re = "^%s/.*%s" % (prefix_re, pattern_re)
1129
+ prefix_re = glob_to_re(prefix)[:-len(empty_pattern)]
1131
+ if os.sep == '\\':
1133
+ pattern_re = "^" + sep.join((prefix_re, ".*" + pattern_re))
12022
1134
else: # no prefix -- respect anchor flag
12024
1136
pattern_re = "^" + pattern_re
12025
diff -r 137e45f15c0b Lib/distutils/msvc9compiler.py
12026
--- a/Lib/distutils/msvc9compiler.py
12027
+++ b/Lib/distutils/msvc9compiler.py
12028
@@ -627,15 +627,7 @@
12029
self.library_filename(dll_name))
12030
ld_args.append ('/IMPLIB:' + implib_file)
12032
- # Embedded manifests are recommended - see MSDN article titled
12033
- # "How to: Embed a Manifest Inside a C/C++ Application"
12034
- # (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx)
12035
- # Ask the linker to generate the manifest in the temp dir, so
12036
- # we can embed it later.
12037
- temp_manifest = os.path.join(
12039
- os.path.basename(output_filename) + ".manifest")
12040
- ld_args.append('/MANIFESTFILE:' + temp_manifest)
12041
+ self.manifest_setup_ldargs(output_filename, build_temp, ld_args)
12044
ld_args[:0] = extra_preargs
12045
@@ -653,21 +645,54 @@
12046
# will still consider the DLL up-to-date, but it will not have a
12047
# manifest. Maybe we should link to a temp file? OTOH, that
12048
# implies a build environment error that shouldn't go undetected.
12049
- if target_desc == CCompiler.EXECUTABLE:
12053
- # Remove references to the Visual C runtime
12054
- self._remove_visual_c_ref(temp_manifest)
12055
- out_arg = '-outputresource:%s;%s' % (output_filename, mfid)
12057
- self.spawn(['mt.exe', '-nologo', '-manifest',
12058
- temp_manifest, out_arg])
12059
- except DistutilsExecError as msg:
12060
- raise LinkError(msg)
12061
+ mfinfo = self.manifest_get_embed_info(target_desc, ld_args)
12062
+ if mfinfo is not None:
12063
+ mffilename, mfid = mfinfo
12064
+ out_arg = '-outputresource:%s;%s' % (output_filename, mfid)
12066
+ self.spawn(['mt.exe', '-nologo', '-manifest',
12067
+ mffilename, out_arg])
12068
+ except DistutilsExecError as msg:
12069
+ raise LinkError(msg)
12071
log.debug("skipping %s (up-to-date)", output_filename)
12073
+ def manifest_setup_ldargs(self, output_filename, build_temp, ld_args):
12074
+ # If we need a manifest at all, an embedded manifest is recommended.
12075
+ # See MSDN article titled
12076
+ # "How to: Embed a Manifest Inside a C/C++ Application"
12077
+ # (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx)
12078
+ # Ask the linker to generate the manifest in the temp dir, so
12079
+ # we can check it, and possibly embed it, later.
12080
+ temp_manifest = os.path.join(
12082
+ os.path.basename(output_filename) + ".manifest")
12083
+ ld_args.append('/MANIFESTFILE:' + temp_manifest)
12085
+ def manifest_get_embed_info(self, target_desc, ld_args):
12086
+ # If a manifest should be embedded, return a tuple of
12087
+ # (manifest_filename, resource_id). Returns None if no manifest
12088
+ # should be embedded. See http://bugs.python.org/issue7833 for why
12089
+ # we want to avoid any manifest for extension modules if we can)
12090
+ for arg in ld_args:
12091
+ if arg.startswith("/MANIFESTFILE:"):
12092
+ temp_manifest = arg.split(":", 1)[1]
12095
+ # no /MANIFESTFILE so nothing to do.
12097
+ if target_desc == CCompiler.EXECUTABLE:
12098
+ # by default, executables always get the manifest with the
12099
+ # CRT referenced.
12102
+ # Extension modules try and avoid any manifest if possible.
12104
+ temp_manifest = self._remove_visual_c_ref(temp_manifest)
12105
+ if temp_manifest is None:
12107
+ return temp_manifest, mfid
12109
def _remove_visual_c_ref(self, manifest_file):
12111
# Remove references to the Visual C runtime, so they will
12112
@@ -676,6 +701,8 @@
12113
# runtimes are not in WinSxS folder, but in Python's own
12114
# folder), the runtimes do not need to be in every folder
12116
+ # Returns either the filename of the modified manifest or
12117
+ # None if no manifest should be embedded.
12118
manifest_f = open(manifest_file)
12120
manifest_buf = manifest_f.read()
12121
@@ -688,9 +715,18 @@
12122
manifest_buf = re.sub(pattern, "", manifest_buf)
12123
pattern = "<dependentAssembly>\s*</dependentAssembly>"
12124
manifest_buf = re.sub(pattern, "", manifest_buf)
12125
+ # Now see if any other assemblies are referenced - if not, we
12126
+ # don't want a manifest embedded.
12127
+ pattern = re.compile(
12128
+ r"""<assemblyIdentity.*?name=(?:"|')(.+?)(?:"|')"""
12129
+ r""".*?(?:/>|</assemblyIdentity>)""", re.DOTALL)
12130
+ if re.search(pattern, manifest_buf) is None:
12133
manifest_f = open(manifest_file, 'w')
12135
manifest_f.write(manifest_buf)
12136
+ return manifest_file
12140
diff -r 137e45f15c0b Lib/distutils/sysconfig.py
12141
--- a/Lib/distutils/sysconfig.py
12142
+++ b/Lib/distutils/sysconfig.py
12143
@@ -146,6 +146,7 @@
12144
"I don't know where Python installs its library "
12145
"on platform '%s'" % os.name)
12149
def customize_compiler(compiler):
12150
"""Do any platform-specific customization of a CCompiler instance.
12151
@@ -158,8 +159,38 @@
12152
get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
12153
'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS')
12156
if 'CC' in os.environ:
12157
- cc = os.environ['CC']
12158
+ newcc = os.environ['CC']
12159
+ elif sys.platform == 'darwin' and cc == 'gcc-4.2':
12161
+ # Since Apple removed gcc-4.2 in Xcode 4.2, we can no
12162
+ # longer assume it is available for extension module builds.
12163
+ # If Python was built with gcc-4.2, check first to see if
12164
+ # it is available on this system; if not, try to use clang
12165
+ # instead unless the caller explicitly set CC.
12166
+ global _USE_CLANG
12167
+ if _USE_CLANG is None:
12168
+ from distutils import log
12169
+ from subprocess import Popen, PIPE
12170
+ p = Popen("! type gcc-4.2 && type clang && exit 2",
12171
+ shell=True, stdout=PIPE, stderr=PIPE)
12173
+ if p.returncode == 2:
12174
+ _USE_CLANG = True
12175
+ log.warn("gcc-4.2 not found, using clang instead")
12177
+ _USE_CLANG = False
12181
+ # On OS X, if CC is overridden, use that as the default
12182
+ # command for LDSHARED as well
12183
+ if (sys.platform == 'darwin'
12184
+ and 'LDSHARED' not in os.environ
12185
+ and ldshared.startswith(cc)):
12186
+ ldshared = newcc + ldshared[len(cc):]
12188
if 'CXX' in os.environ:
12189
cxx = os.environ['CXX']
12190
if 'LDSHARED' in os.environ:
12191
@@ -218,7 +249,7 @@
12192
"""Return full pathname of installed Makefile from the Python build."""
12194
return os.path.join(os.path.dirname(sys.executable), "Makefile")
12195
- lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
12196
+ lib_dir = get_python_lib(plat_specific=0, standard_lib=1)
12197
config_file = 'config-{}{}'.format(get_python_version(), build_flags)
12198
return os.path.join(lib_dir, config_file, 'Makefile')
12200
diff -r 137e45f15c0b Lib/distutils/tests/support.py
12201
--- a/Lib/distutils/tests/support.py
12202
+++ b/Lib/distutils/tests/support.py
12203
@@ -141,9 +141,9 @@
12207
- def test_compile(self):
12208
- copy_xxmodule_c(self.tmpdir)
12209
- self.assertIn('xxmodule.c', os.listdir(self.tmpdir)
12210
+ def test_compile(self):
12211
+ copy_xxmodule_c(self.tmpdir)
12212
+ self.assertIn('xxmodule.c', os.listdir(self.tmpdir))
12214
If the source file can be found, it will be copied to *directory*. If not,
12215
the test will be skipped. Errors during copy are not caught.
12216
@@ -175,10 +175,9 @@
12217
def fixup_build_ext(cmd):
12218
"""Function needed to make build_ext tests pass.
12220
- When Python was build with --enable-shared on Unix, -L. is not good
12221
- enough to find the libpython<blah>.so. This is because regrtest runs
12222
- it under a tempdir, not in the top level where the .so lives. By the
12223
- time we've gotten here, Python's already been chdir'd to the tempdir.
12224
+ When Python was built with --enable-shared on Unix, -L. is not enough to
12225
+ find libpython<blah>.so, because regrtest runs in a tempdir, not in the
12226
+ source directory where the .so lives.
12228
When Python was built with in debug mode on Windows, build_ext commands
12229
need their debug attribute set, and it is not done automatically for
12230
@@ -189,6 +188,9 @@
12231
cmd = build_ext(dist)
12232
support.fixup_build_ext(cmd)
12233
cmd.ensure_finalized()
12235
+ Unlike most other Unix platforms, Mac OS X embeds absolute paths
12236
+ to shared libraries into executables, so the fixup is not needed there.
12238
if os.name == 'nt':
12239
cmd.debug = sys.executable.endswith('_d.exe')
12240
@@ -200,5 +202,8 @@
12241
if runshared is None:
12242
cmd.library_dirs = ['.']
12244
- name, equals, value = runshared.partition('=')
12245
- cmd.library_dirs = value.split(os.pathsep)
12246
+ if sys.platform == 'darwin':
12247
+ cmd.library_dirs = []
12249
+ name, equals, value = runshared.partition('=')
12250
+ cmd.library_dirs = value.split(os.pathsep)
12251
diff -r 137e45f15c0b Lib/distutils/tests/test_bdist_dumb.py
12252
--- a/Lib/distutils/tests/test_bdist_dumb.py
12253
+++ b/Lib/distutils/tests/test_bdist_dumb.py
12255
"""Tests for distutils.command.bdist_dumb."""
1137
diff -r 7085403daf43 Lib/distutils/tests/test_bdist_msi.py
1138
--- a/Lib/distutils/tests/test_bdist_msi.py
1139
+++ b/Lib/distutils/tests/test_bdist_msi.py
1141
"""Tests for distutils.command.bdist_msi."""
12261
1143
import unittest
12264
1146
from test.support import run_unittest
12266
from distutils.core import Distribution
12267
@@ -72,15 +74,24 @@
12270
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
12271
- base = "%s.%s" % (dist.get_fullname(), cmd.plat_name)
12272
+ base = "%s.%s.zip" % (dist.get_fullname(), cmd.plat_name)
12273
if os.name == 'os2':
12274
base = base.replace(':', '-')
12276
- wanted = ['%s.zip' % base]
12277
- self.assertEqual(dist_created, wanted)
12278
+ self.assertEqual(dist_created, [base])
12280
# now let's check what we have in the zip file
12282
+ fp = zipfile.ZipFile(os.path.join('dist', base))
12284
+ contents = fp.namelist()
12288
+ contents = sorted(os.path.basename(fn) for fn in contents)
12289
+ wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2],
12290
+ 'foo.%s.pyc' % imp.get_tag(),
12292
+ self.assertEqual(contents, sorted(wanted))
12295
return unittest.makeSuite(BuildDumbTestCase)
12296
diff -r 137e45f15c0b Lib/distutils/tests/test_bdist_rpm.py
12297
--- a/Lib/distutils/tests/test_bdist_rpm.py
12298
+++ b/Lib/distutils/tests/test_bdist_rpm.py
12300
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
12301
self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)
12303
+ # bug #2945: upload ignores bdist_rpm files
12304
+ self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files)
12305
+ self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files)
12307
def test_no_optimize_flag(self):
12309
# XXX I am unable yet to make this test work without
12310
@@ -117,6 +121,11 @@
12312
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
12313
self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)
12315
+ # bug #2945: upload ignores bdist_rpm files
12316
+ self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files)
12317
+ self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files)
12319
os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
12322
diff -r 137e45f15c0b Lib/distutils/tests/test_build_ext.py
12323
--- a/Lib/distutils/tests/test_build_ext.py
12324
+++ b/Lib/distutils/tests/test_build_ext.py
12325
@@ -178,21 +178,22 @@
12326
# make sure cmd.libraries is turned into a list
12328
cmd = build_ext(dist)
12329
- cmd.libraries = 'my_lib'
12330
+ cmd.libraries = 'my_lib, other_lib lastlib'
12331
cmd.finalize_options()
12332
- self.assertEqual(cmd.libraries, ['my_lib'])
12333
+ self.assertEqual(cmd.libraries, ['my_lib', 'other_lib', 'lastlib'])
12335
# make sure cmd.library_dirs is turned into a list
12337
cmd = build_ext(dist)
12338
- cmd.library_dirs = 'my_lib_dir'
12339
+ cmd.library_dirs = 'my_lib_dir%sother_lib_dir' % os.pathsep
12340
cmd.finalize_options()
12341
- self.assertTrue('my_lib_dir' in cmd.library_dirs)
12342
+ self.assertIn('my_lib_dir', cmd.library_dirs)
12343
+ self.assertIn('other_lib_dir', cmd.library_dirs)
12345
# make sure rpath is turned into a list
12346
- # if it's a list of os.pathsep's paths
12347
+ # if it's a string
12348
cmd = build_ext(dist)
12349
- cmd.rpath = os.pathsep.join(['one', 'two'])
12350
+ cmd.rpath = 'one%stwo' % os.pathsep
12351
cmd.finalize_options()
12352
self.assertEqual(cmd.rpath, ['one', 'two'])
12354
diff -r 137e45f15c0b Lib/distutils/tests/test_build_py.py
12355
--- a/Lib/distutils/tests/test_build_py.py
12356
+++ b/Lib/distutils/tests/test_build_py.py
12365
from distutils.command.build_py import build_py
12366
@@ -53,23 +53,20 @@
12367
# This makes sure the list of outputs includes byte-compiled
12368
# files for Python modules but not for package data files
12369
# (there shouldn't *be* byte-code files for those!).
12371
self.assertEqual(len(cmd.get_outputs()), 3)
12372
pkgdest = os.path.join(destination, "pkg")
12373
files = os.listdir(pkgdest)
12374
+ pycache_dir = os.path.join(pkgdest, "__pycache__")
12375
self.assertIn("__init__.py", files)
12376
self.assertIn("README.txt", files)
12377
- # XXX even with -O, distutils writes pyc, not pyo; bug?
12378
if sys.dont_write_bytecode:
12379
- self.assertNotIn("__init__.pyc", files)
12380
+ self.assertFalse(os.path.exists(pycache_dir))
12382
- self.assertIn("__init__.pyc", files)
12383
+ pyc_files = os.listdir(pycache_dir)
12384
+ self.assertIn("__init__.%s.pyc" % imp.get_tag(), pyc_files)
12386
def test_empty_package_dir(self):
12387
- # See SF 1668596/1720897.
12388
- cwd = os.getcwd()
12390
- # create the distribution files.
12391
+ # See bugs #1668596/#1720897
12392
sources = self.mkdtemp()
12393
open(os.path.join(sources, "__init__.py"), "w").close()
12395
@@ -78,30 +75,55 @@
12396
open(os.path.join(testdir, "testfile"), "w").close()
12399
- old_stdout = sys.stdout
12400
- sys.stdout = io.StringIO()
12401
+ dist = Distribution({"packages": ["pkg"],
12402
+ "package_dir": {"pkg": ""},
12403
+ "package_data": {"pkg": ["doc/*"]}})
12404
+ # script_name need not exist, it just need to be initialized
12405
+ dist.script_name = os.path.join(sources, "setup.py")
12406
+ dist.script_args = ["build"]
12407
+ dist.parse_command_line()
12410
- dist = Distribution({"packages": ["pkg"],
12411
- "package_dir": {"pkg": ""},
12412
- "package_data": {"pkg": ["doc/*"]}})
12413
- # script_name need not exist, it just need to be initialized
12414
- dist.script_name = os.path.join(sources, "setup.py")
12415
- dist.script_args = ["build"]
12416
- dist.parse_command_line()
12417
+ dist.run_commands()
12418
+ except DistutilsFileError:
12419
+ self.fail("failed package_data test when package_dir is ''")
12422
- dist.run_commands()
12423
- except DistutilsFileError:
12424
- self.fail("failed package_data test when package_dir is ''")
12428
- sys.stdout = old_stdout
12429
+ @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
12430
+ def test_byte_compile(self):
12431
+ project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
12432
+ os.chdir(project_dir)
12433
+ self.write_file('boiledeggs.py', 'import antigravity')
12434
+ cmd = build_py(dist)
12436
+ cmd.build_lib = 'here'
12437
+ cmd.finalize_options()
12440
+ found = os.listdir(cmd.build_lib)
12441
+ self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py'])
12442
+ found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
12443
+ self.assertEqual(found, ['boiledeggs.%s.pyc' % imp.get_tag()])
12445
+ @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
12446
+ def test_byte_compile_optimized(self):
12447
+ project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
12448
+ os.chdir(project_dir)
12449
+ self.write_file('boiledeggs.py', 'import antigravity')
12450
+ cmd = build_py(dist)
12453
+ cmd.build_lib = 'here'
12454
+ cmd.finalize_options()
12457
+ found = os.listdir(cmd.build_lib)
12458
+ self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py'])
12459
+ found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
12460
+ self.assertEqual(sorted(found), ['boiledeggs.%s.pyo' % imp.get_tag()])
12462
def test_dont_write_bytecode(self):
12463
# makes sure byte_compile is not used
12464
- pkg_dir, dist = self.create_dist()
12465
+ dist = self.create_dist()[1]
12466
cmd = build_py(dist)
12469
@@ -115,6 +137,7 @@
12471
self.assertIn('byte-compiling is disabled', self.logs[0][1])
12475
return unittest.makeSuite(BuildPyTestCase)
12477
diff -r 137e45f15c0b Lib/distutils/tests/test_check.py
12478
--- a/Lib/distutils/tests/test_check.py
12479
+++ b/Lib/distutils/tests/test_check.py
12481
cmd = self._run(metadata, strict=1)
12482
self.assertEqual(cmd._warnings, 0)
12484
+ # now a test with non-ASCII characters
12485
+ metadata = {'url': 'xxx', 'author': '\u00c9ric',
12486
+ 'author_email': 'xxx', 'name': 'xxx',
12487
+ 'version': 'xxx',
12488
+ 'description': 'Something about esszet \u00df',
12489
+ 'long_description': 'More things about esszet \u00df'}
12490
+ cmd = self._run(metadata)
12491
+ self.assertEqual(cmd._warnings, 0)
12493
def test_check_document(self):
12494
if not HAS_DOCUTILS: # won't test without docutils
12497
self.assertRaises(DistutilsSetupError, self._run, metadata,
12498
**{'strict': 1, 'restructuredtext': 1})
12500
- # and non-broken rest
12501
- metadata['long_description'] = 'title\n=====\n\ntest'
12502
+ # and non-broken rest, including a non-ASCII character to test #12114
12503
+ metadata['long_description'] = 'title\n=====\n\ntest \u00df'
12504
cmd = self._run(metadata, strict=1, restructuredtext=1)
12505
self.assertEqual(cmd._warnings, 0)
12507
diff -r 137e45f15c0b Lib/distutils/tests/test_config_cmd.py
12508
--- a/Lib/distutils/tests/test_config_cmd.py
12509
+++ b/Lib/distutils/tests/test_config_cmd.py
12510
@@ -44,10 +44,10 @@
12513
# simple pattern searches
12514
- match = cmd.search_cpp(pattern='xxx', body='// xxx')
12515
+ match = cmd.search_cpp(pattern='xxx', body='/* xxx */')
12516
self.assertEqual(match, 0)
12518
- match = cmd.search_cpp(pattern='_configtest', body='// xxx')
12519
+ match = cmd.search_cpp(pattern='_configtest', body='/* xxx */')
12520
self.assertEqual(match, 1)
12522
def test_finalize_options(self):
12523
diff -r 137e45f15c0b Lib/distutils/tests/test_dist.py
12524
--- a/Lib/distutils/tests/test_dist.py
12525
+++ b/Lib/distutils/tests/test_dist.py
12527
self.assertEqual(d.get_command_packages(),
12528
["distutils.command", "foo.bar", "distutils.tests"])
12529
cmd = d.get_command_obj("test_dist")
12530
- self.assertTrue(isinstance(cmd, test_dist))
12531
+ self.assertIsInstance(cmd, test_dist)
12532
self.assertEqual(cmd.sample_option, "sometext")
12534
def test_command_packages_configfile(self):
12535
@@ -106,28 +106,23 @@
12536
def test_empty_options(self):
12537
# an empty options dictionary should not stay in the
12538
# list of attributes
12539
- klass = Distribution
12541
# catching warnings
12547
- old_warn = warnings.warn
12548
+ self.addCleanup(setattr, warnings, 'warn', warnings.warn)
12549
warnings.warn = _warn
12551
- dist = klass(attrs={'author': 'xxx',
12553
- 'version': 'xxx',
12557
- warnings.warn = old_warn
12558
+ dist = Distribution(attrs={'author': 'xxx', 'name': 'xxx',
12559
+ 'version': 'xxx', 'url': 'xxxx',
12562
self.assertEqual(len(warns), 0)
12563
+ self.assertNotIn('options', dir(dist))
12565
def test_finalize_options(self):
12567
attrs = {'keywords': 'one,two',
12568
'platforms': 'one,two'}
12570
@@ -150,7 +145,6 @@
12571
cmds = dist.get_command_packages()
12572
self.assertEqual(cmds, ['distutils.command', 'one', 'two'])
12575
def test_announce(self):
12576
# make sure the level is known
12577
dist = Distribution()
12578
@@ -158,6 +152,7 @@
12579
kwargs = {'level': 'ok2'}
12580
self.assertRaises(ValueError, dist.announce, args, kwargs)
12583
class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
1148
from distutils.tests import support
1150
-@unittest.skipUnless(sys.platform=="win32", "These tests are only for win32")
1152
+@unittest.skipUnless(sys.platform == 'win32', 'these tests require Windows')
1153
class BDistMSITestCase(support.TempdirManager,
1154
support.LoggingSilencer,
12584
1155
unittest.TestCase):
12586
@@ -170,15 +165,20 @@
12587
sys.argv[:] = self.argv[1]
12588
super(MetadataTestCase, self).tearDown()
12590
+ def format_metadata(self, dist):
12591
+ sio = io.StringIO()
12592
+ dist.metadata.write_pkg_file(sio)
12593
+ return sio.getvalue()
12595
def test_simple_metadata(self):
12596
attrs = {"name": "package",
12598
dist = Distribution(attrs)
12599
meta = self.format_metadata(dist)
12600
- self.assertTrue("Metadata-Version: 1.0" in meta)
12601
- self.assertTrue("provides:" not in meta.lower())
12602
- self.assertTrue("requires:" not in meta.lower())
12603
- self.assertTrue("obsoletes:" not in meta.lower())
12604
+ self.assertIn("Metadata-Version: 1.0", meta)
12605
+ self.assertNotIn("provides:", meta.lower())
12606
+ self.assertNotIn("requires:", meta.lower())
12607
+ self.assertNotIn("obsoletes:", meta.lower())
12609
def test_provides(self):
12610
attrs = {"name": "package",
12611
@@ -190,9 +190,9 @@
12612
self.assertEqual(dist.get_provides(),
12613
["package", "package.sub"])
12614
meta = self.format_metadata(dist)
12615
- self.assertTrue("Metadata-Version: 1.1" in meta)
12616
- self.assertTrue("requires:" not in meta.lower())
12617
- self.assertTrue("obsoletes:" not in meta.lower())
12618
+ self.assertIn("Metadata-Version: 1.1", meta)
12619
+ self.assertNotIn("requires:", meta.lower())
12620
+ self.assertNotIn("obsoletes:", meta.lower())
12622
def test_provides_illegal(self):
12623
self.assertRaises(ValueError, Distribution,
12624
@@ -210,11 +210,11 @@
12625
self.assertEqual(dist.get_requires(),
12626
["other", "another (==1.0)"])
12627
meta = self.format_metadata(dist)
12628
- self.assertTrue("Metadata-Version: 1.1" in meta)
12629
- self.assertTrue("provides:" not in meta.lower())
12630
- self.assertTrue("Requires: other" in meta)
12631
- self.assertTrue("Requires: another (==1.0)" in meta)
12632
- self.assertTrue("obsoletes:" not in meta.lower())
12633
+ self.assertIn("Metadata-Version: 1.1", meta)
12634
+ self.assertNotIn("provides:", meta.lower())
12635
+ self.assertIn("Requires: other", meta)
12636
+ self.assertIn("Requires: another (==1.0)", meta)
12637
+ self.assertNotIn("obsoletes:", meta.lower())
12639
def test_requires_illegal(self):
12640
self.assertRaises(ValueError, Distribution,
12641
@@ -232,11 +232,11 @@
12642
self.assertEqual(dist.get_obsoletes(),
12643
["other", "another (<1.0)"])
12644
meta = self.format_metadata(dist)
12645
- self.assertTrue("Metadata-Version: 1.1" in meta)
12646
- self.assertTrue("provides:" not in meta.lower())
12647
- self.assertTrue("requires:" not in meta.lower())
12648
- self.assertTrue("Obsoletes: other" in meta)
12649
- self.assertTrue("Obsoletes: another (<1.0)" in meta)
12650
+ self.assertIn("Metadata-Version: 1.1", meta)
12651
+ self.assertNotIn("provides:", meta.lower())
12652
+ self.assertNotIn("requires:", meta.lower())
12653
+ self.assertIn("Obsoletes: other", meta)
12654
+ self.assertIn("Obsoletes: another (<1.0)", meta)
12656
def test_obsoletes_illegal(self):
12657
self.assertRaises(ValueError, Distribution,
12658
@@ -244,10 +244,34 @@
12660
"obsoletes": ["my.pkg (splat)"]})
12662
- def format_metadata(self, dist):
12663
- sio = io.StringIO()
12664
- dist.metadata.write_pkg_file(sio)
12665
- return sio.getvalue()
12666
+ def test_classifier(self):
12667
+ attrs = {'name': 'Boa', 'version': '3.0',
12668
+ 'classifiers': ['Programming Language :: Python :: 3']}
12669
+ dist = Distribution(attrs)
12670
+ meta = self.format_metadata(dist)
12671
+ self.assertIn('Metadata-Version: 1.1', meta)
12673
+ def test_download_url(self):
12674
+ attrs = {'name': 'Boa', 'version': '3.0',
12675
+ 'download_url': 'http://example.org/boa'}
12676
+ dist = Distribution(attrs)
12677
+ meta = self.format_metadata(dist)
12678
+ self.assertIn('Metadata-Version: 1.1', meta)
12680
+ def test_long_description(self):
12681
+ long_desc = textwrap.dedent("""\
12684
+ and continue here
12685
+ and end here.""")
12686
+ attrs = {"name": "package",
12687
+ "version": "1.0",
12688
+ "long_description": long_desc}
12690
+ dist = Distribution(attrs)
12691
+ meta = self.format_metadata(dist)
12692
+ meta = meta.replace('\n' + 8 * ' ', '\n')
12693
+ self.assertIn(long_desc, meta)
12695
def test_custom_pydistutils(self):
12697
@@ -272,14 +296,14 @@
12698
if sys.platform in ('linux', 'darwin'):
12699
os.environ['HOME'] = temp_dir
12700
files = dist.find_config_files()
12701
- self.assertTrue(user_filename in files)
12702
+ self.assertIn(user_filename, files)
12705
if sys.platform == 'win32':
12706
# home drive should be found
12707
os.environ['HOME'] = temp_dir
12708
files = dist.find_config_files()
12709
- self.assertTrue(user_filename in files,
12710
+ self.assertIn(user_filename, files,
12711
'%r not found in %r' % (user_filename, files))
12713
os.remove(user_filename)
12714
@@ -301,22 +325,8 @@
12716
output = [line for line in s.getvalue().split('\n')
12717
if line.strip() != '']
12718
- self.assertTrue(len(output) > 0)
12719
+ self.assertTrue(output)
12721
- def test_long_description(self):
12722
- long_desc = textwrap.dedent("""\
12725
- and continue here
12726
- and end here.""")
12727
- attrs = {"name": "package",
12728
- "version": "1.0",
12729
- "long_description": long_desc}
12731
- dist = Distribution(attrs)
12732
- meta = self.format_metadata(dist)
12733
- meta = meta.replace('\n' + 8 * ' ', '\n')
12734
- self.assertTrue(long_desc in meta)
1157
def test_minimal(self):
1158
# minimal test XXX need more tests
1159
from distutils.command.bdist_msi import bdist_msi
1160
- pkg_pth, dist = self.create_dist()
1161
+ project_dir, dist = self.create_dist()
1162
cmd = bdist_msi(dist)
1163
cmd.ensure_finalized()
12736
1166
def test_suite():
12737
suite = unittest.TestSuite()
12738
diff -r 137e45f15c0b Lib/distutils/tests/test_filelist.py
1167
return unittest.makeSuite(BDistMSITestCase)
1169
diff -r 7085403daf43 Lib/distutils/tests/test_filelist.py
12739
1170
--- a/Lib/distutils/tests/test_filelist.py
12740
1171
+++ b/Lib/distutils/tests/test_filelist.py
12742
1173
"""Tests for distutils.filelist."""
12744
1176
import unittest
12745
+from distutils import debug
12746
+from distutils.log import WARN
12747
+from distutils.errors import DistutilsTemplateError
12748
+from distutils.filelist import glob_to_re, translate_pattern, FileList
12750
-from distutils.filelist import glob_to_re, FileList
1177
from distutils import debug
12751
1179
from test.support import captured_stdout, run_unittest
12752
-from distutils import debug
12753
+from distutils.tests import support
12755
-class FileListTestCase(unittest.TestCase):
12757
+class FileListTestCase(support.LoggingSilencer,
12758
+ unittest.TestCase):
12760
+ def assertNoWarnings(self):
12761
+ self.assertEqual(self.get_logs(WARN), [])
12762
+ self.clear_logs()
12764
+ def assertWarnings(self):
12765
+ self.assertGreater(len(self.get_logs(WARN)), 0)
12766
+ self.clear_logs()
1180
from distutils.tests import support
1187
+include buildout.cfg
1189
+global-include *.txt
1190
+global-exclude *.tmp
1191
+recursive-include f *.oo
1192
+recursive-exclude global *.x
1198
+def make_local_path(s):
1199
+ """Converts '/' in a string to os.sep"""
1200
+ return s.replace('/', os.sep)
1203
class FileListTestCase(support.LoggingSilencer,
12768
1208
def test_glob_to_re(self):
12770
@@ -23,18 +37,191 @@
12771
file_list = FileList()
12772
with captured_stdout() as stdout:
12773
file_list.debug_print('xxx')
12775
- self.assertEqual(stdout.read(), '')
12776
+ self.assertEqual(stdout.getvalue(), '')
12780
with captured_stdout() as stdout:
12781
file_list.debug_print('xxx')
12783
- self.assertEqual(stdout.read(), 'xxx\n')
12784
+ self.assertEqual(stdout.getvalue(), 'xxx\n')
12786
debug.DEBUG = False
12788
+ def test_set_allfiles(self):
12789
+ file_list = FileList()
12790
+ files = ['a', 'b', 'c']
12791
+ file_list.set_allfiles(files)
12792
+ self.assertEqual(file_list.allfiles, files)
12794
+ def test_remove_duplicates(self):
12795
+ file_list = FileList()
12796
+ file_list.files = ['a', 'b', 'a', 'g', 'c', 'g']
12797
+ # files must be sorted beforehand (sdist does it)
12799
+ file_list.remove_duplicates()
12800
+ self.assertEqual(file_list.files, ['a', 'b', 'c', 'g'])
12802
+ def test_translate_pattern(self):
12804
+ self.assertTrue(hasattr(
12805
+ translate_pattern('a', anchor=True, is_regex=False),
12809
+ regex = re.compile('a')
12810
+ self.assertEqual(
12811
+ translate_pattern(regex, anchor=True, is_regex=True),
12814
+ # plain string flagged as regex
12815
+ self.assertTrue(hasattr(
12816
+ translate_pattern('a', anchor=True, is_regex=True),
12820
+ self.assertTrue(translate_pattern(
12821
+ '*.py', anchor=True, is_regex=False).search('filelist.py'))
12823
+ def test_exclude_pattern(self):
12824
+ # return False if no match
12825
+ file_list = FileList()
12826
+ self.assertFalse(file_list.exclude_pattern('*.py'))
12828
+ # return True if files match
12829
+ file_list = FileList()
12830
+ file_list.files = ['a.py', 'b.py']
12831
+ self.assertTrue(file_list.exclude_pattern('*.py'))
12834
+ file_list = FileList()
12835
+ file_list.files = ['a.py', 'a.txt']
12836
+ file_list.exclude_pattern('*.py')
12837
+ self.assertEqual(file_list.files, ['a.txt'])
12839
+ def test_include_pattern(self):
12840
+ # return False if no match
12841
+ file_list = FileList()
12842
+ file_list.set_allfiles([])
12843
+ self.assertFalse(file_list.include_pattern('*.py'))
12845
+ # return True if files match
12846
+ file_list = FileList()
12847
+ file_list.set_allfiles(['a.py', 'b.txt'])
12848
+ self.assertTrue(file_list.include_pattern('*.py'))
12850
+ # test * matches all files
12851
+ file_list = FileList()
12852
+ self.assertIsNone(file_list.allfiles)
12853
+ file_list.set_allfiles(['a.py', 'b.txt'])
12854
+ file_list.include_pattern('*')
12855
+ self.assertEqual(file_list.allfiles, ['a.py', 'b.txt'])
12857
+ def test_process_template(self):
12859
+ file_list = FileList()
12860
+ for action in ('include', 'exclude', 'global-include',
12861
+ 'global-exclude', 'recursive-include',
12862
+ 'recursive-exclude', 'graft', 'prune', 'blarg'):
12863
+ self.assertRaises(DistutilsTemplateError,
12864
+ file_list.process_template_line, action)
12867
+ file_list = FileList()
12868
+ file_list.set_allfiles(['a.py', 'b.txt', 'd/c.py'])
12870
+ file_list.process_template_line('include *.py')
12871
+ self.assertEqual(file_list.files, ['a.py'])
12872
+ self.assertNoWarnings()
12874
+ file_list.process_template_line('include *.rb')
12875
+ self.assertEqual(file_list.files, ['a.py'])
12876
+ self.assertWarnings()
12879
+ file_list = FileList()
12880
+ file_list.files = ['a.py', 'b.txt', 'd/c.py']
12882
+ file_list.process_template_line('exclude *.py')
12883
+ self.assertEqual(file_list.files, ['b.txt', 'd/c.py'])
12884
+ self.assertNoWarnings()
12886
+ file_list.process_template_line('exclude *.rb')
12887
+ self.assertEqual(file_list.files, ['b.txt', 'd/c.py'])
12888
+ self.assertWarnings()
12891
+ file_list = FileList()
12892
+ file_list.set_allfiles(['a.py', 'b.txt', 'd/c.py'])
12894
+ file_list.process_template_line('global-include *.py')
12895
+ self.assertEqual(file_list.files, ['a.py', 'd/c.py'])
12896
+ self.assertNoWarnings()
12898
+ file_list.process_template_line('global-include *.rb')
12899
+ self.assertEqual(file_list.files, ['a.py', 'd/c.py'])
12900
+ self.assertWarnings()
12903
+ file_list = FileList()
12904
+ file_list.files = ['a.py', 'b.txt', 'd/c.py']
12906
+ file_list.process_template_line('global-exclude *.py')
12907
+ self.assertEqual(file_list.files, ['b.txt'])
12908
+ self.assertNoWarnings()
12910
+ file_list.process_template_line('global-exclude *.rb')
12911
+ self.assertEqual(file_list.files, ['b.txt'])
12912
+ self.assertWarnings()
12914
+ # recursive-include
12915
+ file_list = FileList()
12916
+ file_list.set_allfiles(['a.py', 'd/b.py', 'd/c.txt', 'd/d/e.py'])
12918
+ file_list.process_template_line('recursive-include d *.py')
12919
+ self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
12920
+ self.assertNoWarnings()
12922
+ file_list.process_template_line('recursive-include e *.py')
12923
+ self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
12924
+ self.assertWarnings()
12926
+ # recursive-exclude
12927
+ file_list = FileList()
12928
+ file_list.files = ['a.py', 'd/b.py', 'd/c.txt', 'd/d/e.py']
12930
+ file_list.process_template_line('recursive-exclude d *.py')
12931
+ self.assertEqual(file_list.files, ['a.py', 'd/c.txt'])
12932
+ self.assertNoWarnings()
12934
+ file_list.process_template_line('recursive-exclude e *.py')
12935
+ self.assertEqual(file_list.files, ['a.py', 'd/c.txt'])
12936
+ self.assertWarnings()
12939
+ file_list = FileList()
12940
+ file_list.set_allfiles(['a.py', 'd/b.py', 'd/d/e.py', 'f/f.py'])
12942
+ file_list.process_template_line('graft d')
12943
+ self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
12944
+ self.assertNoWarnings()
12946
+ file_list.process_template_line('graft e')
12947
+ self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
12948
+ self.assertWarnings()
12951
+ file_list = FileList()
12952
+ file_list.files = ['a.py', 'd/b.py', 'd/d/e.py', 'f/f.py']
12954
+ file_list.process_template_line('prune d')
12955
+ self.assertEqual(file_list.files, ['a.py', 'f/f.py'])
12956
+ self.assertNoWarnings()
12958
+ file_list.process_template_line('prune e')
12959
+ self.assertEqual(file_list.files, ['a.py', 'f/f.py'])
12960
+ self.assertWarnings()
12964
return unittest.makeSuite(FileListTestCase)
12966
diff -r 137e45f15c0b Lib/distutils/tests/test_install.py
12967
--- a/Lib/distutils/tests/test_install.py
12968
+++ b/Lib/distutils/tests/test_install.py
12970
"""Tests for distutils.command.install."""
12980
def _make_ext_name(modname):
12981
- if os.name == 'nt':
12982
- if sys.executable.endswith('_d.exe'):
12984
+ if os.name == 'nt' and sys.executable.endswith('_d.exe'):
12986
return modname + sysconfig.get_config_var('SO')
12990
check_path(cmd.install_data, destination)
12992
def test_user_site(self):
12993
- # site.USER_SITE was introduced in 2.6
12994
- if sys.version < '2.6':
12997
+ # test install with --user
12998
# preparing the environment for the test
12999
self.old_user_base = site.USER_BASE
13000
self.old_user_site = site.USER_SITE
13001
@@ -88,19 +85,17 @@
13002
self.old_expand = os.path.expanduser
13003
os.path.expanduser = _expanduser
13006
- # this is the actual test
13007
- self._test_user_site()
13010
site.USER_BASE = self.old_user_base
13011
site.USER_SITE = self.old_user_site
13012
install_module.USER_BASE = self.old_user_base
13013
install_module.USER_SITE = self.old_user_site
13014
os.path.expanduser = self.old_expand
13016
- def _test_user_site(self):
13017
+ self.addCleanup(cleanup)
13019
for key in ('nt_user', 'unix_user', 'os2_home'):
13020
- self.assertTrue(key in INSTALL_SCHEMES)
13021
+ self.assertIn(key, INSTALL_SCHEMES)
13023
dist = Distribution({'name': 'xx'})
13024
cmd = install(dist)
13025
@@ -108,14 +103,14 @@
13026
# making sure the user option is there
13027
options = [name for name, short, lable in
13029
- self.assertTrue('user' in options)
13030
+ self.assertIn('user', options)
13035
# user base and site shouldn't be created yet
13036
- self.assertTrue(not os.path.exists(self.user_base))
13037
- self.assertTrue(not os.path.exists(self.user_site))
13038
+ self.assertFalse(os.path.exists(self.user_base))
13039
+ self.assertFalse(os.path.exists(self.user_site))
13041
# let's run finalize
13042
cmd.ensure_finalized()
13043
@@ -124,8 +119,8 @@
13044
self.assertTrue(os.path.exists(self.user_base))
13045
self.assertTrue(os.path.exists(self.user_site))
13047
- self.assertTrue('userbase' in cmd.config_vars)
13048
- self.assertTrue('usersite' in cmd.config_vars)
13049
+ self.assertIn('userbase', cmd.config_vars)
13050
+ self.assertIn('usersite', cmd.config_vars)
13052
def test_handle_extra_path(self):
13053
dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
13054
@@ -178,15 +173,16 @@
13056
def test_record(self):
13057
install_dir = self.mkdtemp()
13058
- project_dir, dist = self.create_dist(scripts=['hello'])
13059
- self.addCleanup(os.chdir, os.getcwd())
13060
+ project_dir, dist = self.create_dist(py_modules=['hello'],
13061
+ scripts=['sayhi'])
13062
os.chdir(project_dir)
13063
- self.write_file('hello', "print('o hai')")
13064
+ self.write_file('hello.py', "def main(): print('o hai')")
13065
+ self.write_file('sayhi', 'from hello import main; main()')
13067
cmd = install(dist)
13068
dist.command_obj['install'] = cmd
13069
cmd.root = install_dir
13070
- cmd.record = os.path.join(project_dir, 'RECORD')
13071
+ cmd.record = os.path.join(project_dir, 'filelist')
13072
cmd.ensure_finalized()
13075
@@ -197,7 +193,7 @@
13078
found = [os.path.basename(line) for line in content.splitlines()]
13079
- expected = ['hello',
13080
+ expected = ['hello.py', 'hello.%s.pyc' % imp.get_tag(), 'sayhi',
13081
'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
13082
self.assertEqual(found, expected)
13084
@@ -205,7 +201,6 @@
13085
install_dir = self.mkdtemp()
13086
project_dir, dist = self.create_dist(ext_modules=[
13087
Extension('xx', ['xxmodule.c'])])
13088
- self.addCleanup(os.chdir, os.getcwd())
13089
os.chdir(project_dir)
13090
support.copy_xxmodule_c(project_dir)
13092
@@ -217,7 +212,7 @@
13093
dist.command_obj['install'] = cmd
13094
dist.command_obj['build_ext'] = buildextcmd
13095
cmd.root = install_dir
13096
- cmd.record = os.path.join(project_dir, 'RECORD')
13097
+ cmd.record = os.path.join(project_dir, 'filelist')
13098
cmd.ensure_finalized()
13101
@@ -243,6 +238,7 @@
13102
install_module.DEBUG = False
13103
self.assertTrue(len(self.logs) > old_logs_len)
13107
return unittest.makeSuite(InstallTestCase)
13109
diff -r 137e45f15c0b Lib/distutils/tests/test_install_lib.py
13110
--- a/Lib/distutils/tests/test_install_lib.py
13111
+++ b/Lib/distutils/tests/test_install_lib.py
13113
"""Tests for distutils.command.install_data."""
13119
from distutils.command.install_lib import install_lib
13121
from distutils.errors import DistutilsOptionError
13122
from test.support import run_unittest
13125
class InstallLibTestCase(support.TempdirManager,
13126
support.LoggingSilencer,
13127
support.EnvironGuard,
13128
unittest.TestCase):
13130
def test_finalize_options(self):
13131
- pkg_dir, dist = self.create_dist()
13132
+ dist = self.create_dist()[1]
13133
cmd = install_lib(dist)
13135
cmd.finalize_options()
13136
@@ -32,56 +34,64 @@
13137
cmd.finalize_options()
13138
self.assertEqual(cmd.optimize, 2)
13140
- @unittest.skipUnless(not sys.dont_write_bytecode,
13141
- 'byte-compile not supported')
13142
+ @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
13143
def test_byte_compile(self):
13144
- pkg_dir, dist = self.create_dist()
13145
+ project_dir, dist = self.create_dist()
13146
+ os.chdir(project_dir)
13147
cmd = install_lib(dist)
13148
cmd.compile = cmd.optimize = 1
13150
- f = os.path.join(pkg_dir, 'foo.py')
13151
+ f = os.path.join(project_dir, 'foo.py')
13152
self.write_file(f, '# python file')
13153
cmd.byte_compile([f])
13154
- self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
13155
- self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
13156
+ pyc_file = imp.cache_from_source('foo.py', debug_override=True)
13157
+ pyo_file = imp.cache_from_source('foo.py', debug_override=False)
13158
+ self.assertTrue(os.path.exists(pyc_file))
13159
+ self.assertTrue(os.path.exists(pyo_file))
13161
def test_get_outputs(self):
13162
- pkg_dir, dist = self.create_dist()
13163
+ project_dir, dist = self.create_dist()
13164
+ os.chdir(project_dir)
13166
cmd = install_lib(dist)
13168
# setting up a dist environment
13169
cmd.compile = cmd.optimize = 1
13170
- cmd.install_dir = pkg_dir
13171
- f = os.path.join(pkg_dir, 'foo.py')
13172
- self.write_file(f, '# python file')
13173
- cmd.distribution.py_modules = [pkg_dir]
13174
+ cmd.install_dir = self.mkdtemp()
13175
+ f = os.path.join(project_dir, 'spam', '__init__.py')
13176
+ self.write_file(f, '# python package')
13177
cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
13178
- cmd.distribution.packages = [pkg_dir]
13179
+ cmd.distribution.packages = ['spam']
13180
cmd.distribution.script_name = 'setup.py'
13182
- # get_output should return 4 elements
13183
- self.assertTrue(len(cmd.get_outputs()) >= 2)
13184
+ # get_outputs should return 4 elements: spam/__init__.py, .pyc and
13185
+ # .pyo, foo.import-tag-abiflags.so / foo.pyd
13186
+ outputs = cmd.get_outputs()
13187
+ self.assertEqual(len(outputs), 4, outputs)
13189
def test_get_inputs(self):
13190
- pkg_dir, dist = self.create_dist()
13191
+ project_dir, dist = self.create_dist()
13192
+ os.chdir(project_dir)
13194
cmd = install_lib(dist)
13196
# setting up a dist environment
13197
cmd.compile = cmd.optimize = 1
13198
- cmd.install_dir = pkg_dir
13199
- f = os.path.join(pkg_dir, 'foo.py')
13200
- self.write_file(f, '# python file')
13201
- cmd.distribution.py_modules = [pkg_dir]
13202
+ cmd.install_dir = self.mkdtemp()
13203
+ f = os.path.join(project_dir, 'spam', '__init__.py')
13204
+ self.write_file(f, '# python package')
13205
cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
13206
- cmd.distribution.packages = [pkg_dir]
13207
+ cmd.distribution.packages = ['spam']
13208
cmd.distribution.script_name = 'setup.py'
13210
- # get_input should return 2 elements
13211
- self.assertEqual(len(cmd.get_inputs()), 2)
13212
+ # get_inputs should return 2 elements: spam/__init__.py and
13213
+ # foo.import-tag-abiflags.so / foo.pyd
13214
+ inputs = cmd.get_inputs()
13215
+ self.assertEqual(len(inputs), 2, inputs)
13217
def test_dont_write_bytecode(self):
13218
# makes sure byte_compile is not used
13219
- pkg_dir, dist = self.create_dist()
13220
+ dist = self.create_dist()[1]
13221
cmd = install_lib(dist)
13226
self.assertTrue('byte-compiling is disabled' in self.logs[0][1])
13230
return unittest.makeSuite(InstallLibTestCase)
13232
diff -r 137e45f15c0b Lib/distutils/tests/test_msvc9compiler.py
13233
--- a/Lib/distutils/tests/test_msvc9compiler.py
13234
+++ b/Lib/distutils/tests/test_msvc9compiler.py
13236
from distutils.tests import support
13237
from test.support import run_unittest
13240
+# A manifest with the only assembly reference being the msvcrt assembly, so
13241
+# should have the assembly completely stripped. Note that although the
13242
+# assembly has a <security> reference the assembly is removed - that is
13243
+# currently a "feature", not a bug :)
13244
+_MANIFEST_WITH_ONLY_MSVC_REFERENCE = """\
13245
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
13246
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
13247
+ manifestVersion="1.0">
13248
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
13250
+ <requestedPrivileges>
13251
+ <requestedExecutionLevel level="asInvoker" uiAccess="false">
13252
+ </requestedExecutionLevel>
13253
+ </requestedPrivileges>
13257
+ <dependentAssembly>
13258
+ <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
13259
+ version="9.0.21022.8" processorArchitecture="x86"
13260
+ publicKeyToken="XXXX">
13261
+ </assemblyIdentity>
13262
+ </dependentAssembly>
13267
+# A manifest with references to assemblies other than msvcrt. When processed,
13268
+# this assembly should be returned with just the msvcrt part removed.
13269
+_MANIFEST_WITH_MULTIPLE_REFERENCES = """\
13270
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
13271
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
13272
manifestVersion="1.0">
13273
@@ -115,7 +144,7 @@
13274
manifest = os.path.join(tempdir, 'manifest')
13275
f = open(manifest, 'w')
13277
- f.write(_MANIFEST)
13278
+ f.write(_MANIFEST_WITH_MULTIPLE_REFERENCES)
13282
@@ -133,6 +162,20 @@
13283
# makes sure the manifest was properly cleaned
13284
self.assertEqual(content, _CLEANED_MANIFEST)
13286
+ def test_remove_entire_manifest(self):
13287
+ from distutils.msvc9compiler import MSVCCompiler
13288
+ tempdir = self.mkdtemp()
13289
+ manifest = os.path.join(tempdir, 'manifest')
13290
+ f = open(manifest, 'w')
13292
+ f.write(_MANIFEST_WITH_ONLY_MSVC_REFERENCE)
13296
+ compiler = MSVCCompiler()
13297
+ got = compiler._remove_visual_c_ref(manifest)
13298
+ self.assertIs(got, None)
13302
return unittest.makeSuite(msvc9compilerTestCase)
13303
diff -r 137e45f15c0b Lib/distutils/tests/test_register.py
13304
--- a/Lib/distutils/tests/test_register.py
13305
+++ b/Lib/distutils/tests/test_register.py
13306
@@ -214,7 +214,7 @@
13308
# metadata are OK but long_description is broken
13309
metadata = {'url': 'xxx', 'author': 'xxx',
13310
- 'author_email': 'xxx',
13311
+ 'author_email': 'éxéxé',
13312
'name': 'xxx', 'version': 'xxx',
13313
'long_description': 'title\n==\n\ntext'}
13315
@@ -247,6 +247,24 @@
13317
del register_module.input
13319
+ # and finally a Unicode test (bug #12114)
13320
+ metadata = {'url': 'xxx', 'author': '\u00c9ric',
13321
+ 'author_email': 'xxx', 'name': 'xxx',
13322
+ 'version': 'xxx',
13323
+ 'description': 'Something about esszet \u00df',
13324
+ 'long_description': 'More things about esszet \u00df'}
13326
+ cmd = self._get_cmd(metadata)
13327
+ cmd.ensure_finalized()
13329
+ inputs = Inputs('1', 'tarek', 'y')
13330
+ register_module.input = inputs.__call__
13331
+ # let's run the command
13335
+ del register_module.input
13337
def test_check_metadata_deprecated(self):
13338
# makes sure make_metadata is deprecated
13339
cmd = self._get_cmd()
13340
diff -r 137e45f15c0b Lib/distutils/tests/test_sdist.py
1210
- self.assertEqual(glob_to_re('foo*'), 'foo[^/]*\\Z(?ms)')
1211
- self.assertEqual(glob_to_re('foo?'), 'foo[^/]\\Z(?ms)')
1212
- self.assertEqual(glob_to_re('foo??'), 'foo[^/][^/]\\Z(?ms)')
1214
+ if os.sep == '\\':
1215
+ sep = re.escape(os.sep)
1218
- self.assertEqual(glob_to_re(r'foo\\*'), r'foo\\\\[^/]*\Z(?ms)')
1219
- self.assertEqual(glob_to_re(r'foo\\\*'), r'foo\\\\\\[^/]*\Z(?ms)')
1220
- self.assertEqual(glob_to_re('foo????'), r'foo[^/][^/][^/][^/]\Z(?ms)')
1221
- self.assertEqual(glob_to_re(r'foo\\??'), r'foo\\\\[^/][^/]\Z(?ms)')
1222
+ for glob, regex in (
1224
+ ('foo*', r'foo[^%(sep)s]*\Z(?ms)'),
1225
+ ('foo?', r'foo[^%(sep)s]\Z(?ms)'),
1226
+ ('foo??', r'foo[^%(sep)s][^%(sep)s]\Z(?ms)'),
1228
+ (r'foo\\*', r'foo\\\\[^%(sep)s]*\Z(?ms)'),
1229
+ (r'foo\\\*', r'foo\\\\\\[^%(sep)s]*\Z(?ms)'),
1230
+ ('foo????', r'foo[^%(sep)s][^%(sep)s][^%(sep)s][^%(sep)s]\Z(?ms)'),
1231
+ (r'foo\\??', r'foo\\\\[^%(sep)s][^%(sep)s]\Z(?ms)')):
1232
+ regex = regex % {'sep': sep}
1233
+ self.assertEqual(glob_to_re(glob), regex)
1235
+ def test_process_template_line(self):
1236
+ # testing all MANIFEST.in template patterns
1237
+ file_list = FileList()
1238
+ l = make_local_path
1240
+ # simulated file list
1241
+ file_list.allfiles = ['foo.tmp', 'ok', 'xo', 'four.txt',
1243
+ # filelist does not filter out VCS directories,
1244
+ # it's sdist that does
1245
+ l('.hg/last-message.txt'),
1246
+ l('global/one.txt'),
1247
+ l('global/two.txt'),
1248
+ l('global/files.x'),
1249
+ l('global/here.tmp'),
1251
+ l('dir/graft-one'),
1252
+ l('dir/dir2/graft2'),
1254
+ l('dir3/sub/ok.txt'),
1257
+ for line in MANIFEST_IN.split('\n'):
1258
+ if line.strip() == '':
1260
+ file_list.process_template_line(line)
1265
+ l('.hg/last-message.txt'),
1266
+ l('global/one.txt'),
1267
+ l('global/two.txt'),
1269
+ l('dir/graft-one'),
1270
+ l('dir/dir2/graft2'),
1273
+ self.assertEqual(file_list.files, wanted)
1275
def test_debug_print(self):
1276
file_list = FileList()
1278
self.assertEqual(file_list.allfiles, ['a.py', 'b.txt'])
1280
def test_process_template(self):
1281
+ l = make_local_path
1283
file_list = FileList()
1284
for action in ('include', 'exclude', 'global-include',
1288
file_list = FileList()
1289
- file_list.set_allfiles(['a.py', 'b.txt', 'd/c.py'])
1290
+ file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])
1292
file_list.process_template_line('include *.py')
1293
self.assertEqual(file_list.files, ['a.py'])
1294
@@ -139,31 +207,31 @@
1297
file_list = FileList()
1298
- file_list.files = ['a.py', 'b.txt', 'd/c.py']
1299
+ file_list.files = ['a.py', 'b.txt', l('d/c.py')]
1301
file_list.process_template_line('exclude *.py')
1302
- self.assertEqual(file_list.files, ['b.txt', 'd/c.py'])
1303
+ self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
1304
self.assertNoWarnings()
1306
file_list.process_template_line('exclude *.rb')
1307
- self.assertEqual(file_list.files, ['b.txt', 'd/c.py'])
1308
+ self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
1309
self.assertWarnings()
1312
file_list = FileList()
1313
- file_list.set_allfiles(['a.py', 'b.txt', 'd/c.py'])
1314
+ file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])
1316
file_list.process_template_line('global-include *.py')
1317
- self.assertEqual(file_list.files, ['a.py', 'd/c.py'])
1318
+ self.assertEqual(file_list.files, ['a.py', l('d/c.py')])
1319
self.assertNoWarnings()
1321
file_list.process_template_line('global-include *.rb')
1322
- self.assertEqual(file_list.files, ['a.py', 'd/c.py'])
1323
+ self.assertEqual(file_list.files, ['a.py', l('d/c.py')])
1324
self.assertWarnings()
1327
file_list = FileList()
1328
- file_list.files = ['a.py', 'b.txt', 'd/c.py']
1329
+ file_list.files = ['a.py', 'b.txt', l('d/c.py')]
1331
file_list.process_template_line('global-exclude *.py')
1332
self.assertEqual(file_list.files, ['b.txt'])
1333
@@ -175,50 +243,52 @@
1336
file_list = FileList()
1337
- file_list.set_allfiles(['a.py', 'd/b.py', 'd/c.txt', 'd/d/e.py'])
1338
+ file_list.set_allfiles(['a.py', l('d/b.py'), l('d/c.txt'),
1341
file_list.process_template_line('recursive-include d *.py')
1342
- self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
1343
+ self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
1344
self.assertNoWarnings()
1346
file_list.process_template_line('recursive-include e *.py')
1347
- self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
1348
+ self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
1349
self.assertWarnings()
1352
file_list = FileList()
1353
- file_list.files = ['a.py', 'd/b.py', 'd/c.txt', 'd/d/e.py']
1354
+ file_list.files = ['a.py', l('d/b.py'), l('d/c.txt'), l('d/d/e.py')]
1356
file_list.process_template_line('recursive-exclude d *.py')
1357
- self.assertEqual(file_list.files, ['a.py', 'd/c.txt'])
1358
+ self.assertEqual(file_list.files, ['a.py', l('d/c.txt')])
1359
self.assertNoWarnings()
1361
file_list.process_template_line('recursive-exclude e *.py')
1362
- self.assertEqual(file_list.files, ['a.py', 'd/c.txt'])
1363
+ self.assertEqual(file_list.files, ['a.py', l('d/c.txt')])
1364
self.assertWarnings()
1367
file_list = FileList()
1368
- file_list.set_allfiles(['a.py', 'd/b.py', 'd/d/e.py', 'f/f.py'])
1369
+ file_list.set_allfiles(['a.py', l('d/b.py'), l('d/d/e.py'),
1372
file_list.process_template_line('graft d')
1373
- self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
1374
+ self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
1375
self.assertNoWarnings()
1377
file_list.process_template_line('graft e')
1378
- self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
1379
+ self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
1380
self.assertWarnings()
1383
file_list = FileList()
1384
- file_list.files = ['a.py', 'd/b.py', 'd/d/e.py', 'f/f.py']
1385
+ file_list.files = ['a.py', l('d/b.py'), l('d/d/e.py'), l('f/f.py')]
1387
file_list.process_template_line('prune d')
1388
- self.assertEqual(file_list.files, ['a.py', 'f/f.py'])
1389
+ self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
1390
self.assertNoWarnings()
1392
file_list.process_template_line('prune e')
1393
- self.assertEqual(file_list.files, ['a.py', 'f/f.py'])
1394
+ self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
1395
self.assertWarnings()
1398
diff -r 7085403daf43 Lib/distutils/tests/test_sdist.py
13341
1399
--- a/Lib/distutils/tests/test_sdist.py
13342
1400
+++ b/Lib/distutils/tests/test_sdist.py
13344
from distutils.errors import DistutilsOptionError
13345
from distutils.spawn import find_executable
13346
from distutils.log import WARN
13347
+from distutils.filelist import FileList
13348
from distutils.archive_util import ARCHIVE_FORMATS
13352
dist.include_package_data = True
13354
cmd.dist_dir = 'dist'
13355
- def _warn(*args):
13360
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
13361
@@ -235,7 +233,8 @@
13362
# with the `check` subcommand
13363
cmd.ensure_finalized()
13365
- warnings = self.get_logs(WARN)
13366
+ warnings = [msg for msg in self.get_logs(WARN) if
13367
+ msg.startswith('warning: check:')]
13368
self.assertEqual(len(warnings), 2)
13370
# trying with a complete set of metadata
13371
@@ -244,7 +243,8 @@
13372
cmd.ensure_finalized()
13373
cmd.metadata_check = 0
13375
- warnings = self.get_logs(WARN)
13376
+ warnings = [msg for msg in self.get_logs(WARN) if
13377
+ msg.startswith('warning: check:')]
13378
self.assertEqual(len(warnings), 0)
13380
def test_check_metadata_deprecated(self):
13381
@@ -266,7 +266,6 @@
13382
self.assertEqual(len(output), num_formats)
13384
def test_finalize_options(self):
13386
dist, cmd = self.get_cmd()
13387
cmd.finalize_options()
13389
@@ -286,6 +285,32 @@
13390
cmd.formats = 'supazipa'
13391
self.assertRaises(DistutilsOptionError, cmd.finalize_options)
13393
+ # the following tests make sure there is a nice error message instead
13394
+ # of a traceback when parsing an invalid manifest template
13396
+ def _check_template(self, content):
13397
+ dist, cmd = self.get_cmd()
13398
+ os.chdir(self.tmp_dir)
13399
+ self.write_file('MANIFEST.in', content)
13400
+ cmd.ensure_finalized()
13401
+ cmd.filelist = FileList()
13402
+ cmd.read_template()
13403
+ warnings = self.get_logs(WARN)
13404
+ self.assertEqual(len(warnings), 1)
13406
+ def test_invalid_template_unknown_command(self):
13407
+ self._check_template('taunt knights *')
13409
+ def test_invalid_template_wrong_arguments(self):
13410
+ # this manifest command takes one argument
13411
+ self._check_template('prune')
13413
+ @unittest.skipIf(os.name != 'nt', 'test relevant for Windows only')
13414
+ def test_invalid_template_wrong_path(self):
13415
+ # on Windows, trailing slashes are not allowed
13416
+ # this used to crash instead of raising a warning: #8286
13417
+ self._check_template('include examples/')
13419
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
13420
def test_get_file_list(self):
13421
# make sure MANIFEST is recalculated
13422
diff -r 137e45f15c0b Lib/distutils/util.py
13423
--- a/Lib/distutils/util.py
13424
+++ b/Lib/distutils/util.py
13426
one of the other *util.py modules.
13429
-import sys, os, string, re
13435
from distutils.errors import DistutilsPlatformError
13436
from distutils.dep_util import newer
13437
from distutils.spawn import spawn
13439
if release[0] >= "5": # SunOS 5 == Solaris 2
13441
release = "%d.%s" % (int(release[0]) - 3, release[2:])
13442
+ # We can't use "platform.architecture()[0]" because a
13443
+ # bootstrap problem. We use a dict to get an error
13444
+ # if some suspicious happens.
13445
+ bitness = {2147483647:"32bit", 9223372036854775807:"64bit"}
13446
+ machine += ".%s" % bitness[sys.maxsize]
13447
# fall through to standard osname-release-machine representation
13448
elif osname[:4] == "irix": # could be "irix64"!
13449
return "%s-%s" % (osname, release)
13450
@@ -415,9 +424,9 @@
13451
verbose=1, dry_run=0,
13453
"""Byte-compile a collection of Python source files to either .pyc
13454
- or .pyo files in the same directory. 'py_files' is a list of files
13455
- to compile; any files that don't end in ".py" are silently skipped.
13456
- 'optimize' must be one of the following:
13457
+ or .pyo files in a __pycache__ subdirectory. 'py_files' is a list
13458
+ of files to compile; any files that don't end in ".py" are silently
13459
+ skipped. 'optimize' must be one of the following:
13460
0 - don't optimize (generate .pyc)
13461
1 - normal optimization (like "python -O")
13462
2 - extra optimization (like "python -OO")
13463
@@ -529,7 +538,10 @@
13464
# Terminology from the py_compile module:
13465
# cfile - byte-compiled file
13466
# dfile - purported source filename (same as 'file' by default)
13467
- cfile = file + (__debug__ and "c" or "o")
13468
+ if optimize >= 0:
13469
+ cfile = imp.cache_from_source(file, debug_override=not optimize)
13471
+ cfile = imp.cache_from_source(file)
13474
if file[:len(prefix)] != prefix:
13475
diff -r 137e45f15c0b Lib/doctest.py
13476
--- a/Lib/doctest.py
13477
+++ b/Lib/doctest.py
13478
@@ -440,6 +440,25 @@
13479
self.options = options
13480
self.exc_msg = exc_msg
13482
+ def __eq__(self, other):
13483
+ if type(self) is not type(other):
13484
+ return NotImplemented
13486
+ return self.source == other.source and \
13487
+ self.want == other.want and \
13488
+ self.lineno == other.lineno and \
13489
+ self.indent == other.indent and \
13490
+ self.options == other.options and \
13491
+ self.exc_msg == other.exc_msg
13493
+ def __ne__(self, other):
13494
+ return not self == other
13496
+ def __hash__(self):
13497
+ return hash((self.source, self.want, self.lineno, self.indent,
13503
A collection of doctest examples that should be run in a single
13504
@@ -488,6 +507,22 @@
13505
return ('<DocTest %s from %s:%s (%s)>' %
13506
(self.name, self.filename, self.lineno, examples))
13508
+ def __eq__(self, other):
13509
+ if type(self) is not type(other):
13510
+ return NotImplemented
13512
+ return self.examples == other.examples and \
13513
+ self.docstring == other.docstring and \
13514
+ self.globs == other.globs and \
13515
+ self.name == other.name and \
13516
+ self.filename == other.filename and \
13517
+ self.lineno == other.lineno
13519
+ def __ne__(self, other):
13520
+ return not self == other
13522
+ def __hash__(self):
13523
+ return hash((self.docstring, self.name, self.filename, self.lineno))
13525
# This lets us sort tests by name:
13526
def __lt__(self, other):
13527
@@ -2204,6 +2239,23 @@
13529
return self._dt_test.name
13531
+ def __eq__(self, other):
13532
+ if type(self) is not type(other):
13533
+ return NotImplemented
13535
+ return self._dt_test == other._dt_test and \
13536
+ self._dt_optionflags == other._dt_optionflags and \
13537
+ self._dt_setUp == other._dt_setUp and \
13538
+ self._dt_tearDown == other._dt_tearDown and \
13539
+ self._dt_checker == other._dt_checker
13541
+ def __ne__(self, other):
13542
+ return not self == other
13544
+ def __hash__(self):
13545
+ return hash((self._dt_optionflags, self._dt_setUp, self._dt_tearDown,
13546
+ self._dt_checker))
13548
def __repr__(self):
13549
name = self._dt_test.name.split('.')
13550
return "%s (%s)" % (name[-1], '.'.join(name[:-1]))
13551
diff -r 137e45f15c0b Lib/email/_parseaddr.py
13552
--- a/Lib/email/_parseaddr.py
13553
+++ b/Lib/email/_parseaddr.py
13554
@@ -178,7 +178,7 @@
13557
Note: this class interface is deprecated and may be removed in the future.
13558
- Use rfc822.AddressList instead.
13559
+ Use email.utils.AddressList instead.
13562
def __init__(self, field):
13563
diff -r 137e45f15c0b Lib/encodings/__init__.py
13564
--- a/Lib/encodings/__init__.py
13565
+++ b/Lib/encodings/__init__.py
13566
@@ -120,12 +120,11 @@
13567
if not 4 <= len(entry) <= 7:
13568
raise CodecRegistryError('module "%s" (%s) failed to register'
13569
% (mod.__name__, mod.__file__))
13570
- if not hasattr(entry[0], '__call__') or \
13571
- not hasattr(entry[1], '__call__') or \
13572
- (entry[2] is not None and not hasattr(entry[2], '__call__')) or \
13573
- (entry[3] is not None and not hasattr(entry[3], '__call__')) or \
13574
- (len(entry) > 4 and entry[4] is not None and not hasattr(entry[4], '__call__')) or \
13575
- (len(entry) > 5 and entry[5] is not None and not hasattr(entry[5], '__call__')):
13576
+ if not callable(entry[0]) or not callable(entry[1]) or \
13577
+ (entry[2] is not None and not callable(entry[2])) or \
13578
+ (entry[3] is not None and not callable(entry[3])) or \
13579
+ (len(entry) > 4 and entry[4] is not None and not callable(entry[4])) or \
13580
+ (len(entry) > 5 and entry[5] is not None and not callable(entry[5])):
13581
raise CodecRegistryError('incompatible codecs in module "%s" (%s)'
13582
% (mod.__name__, mod.__file__))
13583
if len(entry)<7 or entry[6] is None:
13584
diff -r 137e45f15c0b Lib/fileinput.py
13585
--- a/Lib/fileinput.py
13586
+++ b/Lib/fileinput.py
13587
@@ -225,10 +225,11 @@
13588
raise ValueError("FileInput opening mode must be one of "
13589
"'r', 'rU', 'U' and 'rb'")
13591
- if inplace and openhook:
13592
- raise ValueError("FileInput cannot use an opening hook in inplace mode")
13593
- elif openhook and not hasattr(openhook, '__call__'):
13594
- raise ValueError("FileInput openhook must be callable")
13597
+ raise ValueError("FileInput cannot use an opening hook in inplace mode")
13598
+ if not callable(openhook):
13599
+ raise ValueError("FileInput openhook must be callable")
13600
self._openhook = openhook
13603
diff -r 137e45f15c0b Lib/functools.py
13604
--- a/Lib/functools.py
13605
+++ b/Lib/functools.py
13606
@@ -141,7 +141,7 @@
13609
kwd_mark = (object(),) # separates positional and keyword args
13610
- lock = Lock() # needed because ordereddicts aren't threadsafe
13611
+ lock = Lock() # needed because OrderedDict isn't threadsafe
13613
if maxsize is None:
13614
cache = dict() # simple cache without ordering or size limit
13615
@@ -155,13 +155,15 @@
13617
result = cache[key]
13621
- result = user_function(*args, **kwds)
13622
- cache[key] = result
13625
+ result = user_function(*args, **kwds)
13626
+ cache[key] = result
13630
- cache = OrderedDict() # ordered least recent to most recent
13631
+ cache = OrderedDict() # ordered least recent to most recent
13632
cache_popitem = cache.popitem
13633
cache_renew = cache.move_to_end
13635
@@ -171,18 +173,20 @@
13638
key += kwd_mark + tuple(sorted(kwds.items()))
13643
result = cache[key]
13644
- cache_renew(key) # record recent use of this key
13645
+ cache_renew(key) # record recent use of this key
13648
- result = user_function(*args, **kwds)
13650
- cache[key] = result # record recent use of this key
13652
- if len(cache) > maxsize:
13653
- cache_popitem(0) # purge least recently used cache entry
13657
+ result = user_function(*args, **kwds)
13659
+ cache[key] = result # record recent use of this key
13661
+ if len(cache) > maxsize:
13662
+ cache_popitem(0) # purge least recently used cache entry
13666
diff -r 137e45f15c0b Lib/gzip.py
13669
@@ -105,6 +105,9 @@
13670
"""The GzipFile class simulates most of the methods of a file object with
13671
the exception of the readinto() and truncate() methods.
13673
+ This class only supports opening files in binary mode. If you need to open a
13674
+ compressed file in text mode, wrap your GzipFile with an io.TextIOWrapper.
13679
@@ -131,8 +134,8 @@
13680
The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', or 'wb',
13681
depending on whether the file will be read or written. The default
13682
is the mode of fileobj if discernible; otherwise, the default is 'rb'.
13683
- Be aware that only the 'rb', 'ab', and 'wb' values should be used
13684
- for cross-platform portability.
13685
+ A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
13686
+ 'wb', and 'a' and 'ab'.
13688
The compresslevel argument is an integer from 1 to 9 controlling the
13689
level of compression; 1 is fastest and produces the least compression,
13690
@@ -149,15 +152,17 @@
13694
- # guarantee the file is opened in binary mode on platforms
13695
- # that care about that sort of thing
13696
+ if mode and ('t' in mode or 'U' in mode):
13697
+ raise IOError("Mode " + mode + " not supported")
13698
if mode and 'b' not in mode:
13700
if fileobj is None:
13701
fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
13702
if filename is None:
13703
- if hasattr(fileobj, 'name'): filename = fileobj.name
13704
- else: filename = ''
13705
+ if hasattr(fileobj, 'name') and isinstance(fileobj.name, str):
13706
+ filename = fileobj.name
13710
if hasattr(fileobj, 'mode'): mode = fileobj.mode
13712
diff -r 137e45f15c0b Lib/heapq.py
13715
@@ -185,6 +185,8 @@
13717
Equivalent to: sorted(iterable, reverse=True)[:n]
13721
it = iter(iterable)
13722
result = list(islice(it, n))
13724
@@ -201,6 +203,8 @@
13726
Equivalent to: sorted(iterable)[:n]
13730
if hasattr(iterable, '__len__') and n * 10 <= len(iterable):
13731
# For smaller values of n, the bisect method is faster than a minheap.
13732
# It is also memory efficient, consuming only n elements of space.
13733
diff -r 137e45f15c0b Lib/hmac.py
13738
digestmod = hashlib.md5
13740
- if hasattr(digestmod, '__call__'):
13741
+ if callable(digestmod):
13742
self.digest_cons = digestmod
13744
self.digest_cons = lambda d=b'': digestmod.new(d)
13745
diff -r 137e45f15c0b Lib/html/__init__.py
13746
--- a/Lib/html/__init__.py
13747
+++ b/Lib/html/__init__.py
13750
Replace special characters "&", "<" and ">" to HTML-safe sequences.
13751
If the optional flag quote is true (the default), the quotation mark
13752
- character (") is also translated.
13753
+ characters, both double quote (") and single quote (') characters are also
13757
return s.translate(_escape_map_full)
13758
diff -r 137e45f15c0b Lib/html/parser.py
13759
--- a/Lib/html/parser.py
13760
+++ b/Lib/html/parser.py
13762
# Regular expressions used for parsing
13764
interesting_normal = re.compile('[&<]')
13765
-interesting_cdata = re.compile(r'<(/|\Z)')
13766
incomplete = re.compile('&[a-zA-Z#]')
13768
entityref = re.compile('&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]')
13769
@@ -24,14 +23,17 @@
13770
piclose = re.compile('>')
13771
commentclose = re.compile(r'--\s*>')
13772
tagfind = re.compile('[a-zA-Z][-.a-zA-Z0-9:_]*')
13773
+# see http://www.w3.org/TR/html5/tokenization.html#tag-open-state
13774
+# and http://www.w3.org/TR/html5/tokenization.html#tag-name-state
13775
+tagfind_tolerant = re.compile('[a-zA-Z][^\t\n\r\f />\x00]*')
13776
# Note, the strict one of this pair isn't really strict, but we can't
13777
# make it correctly strict without breaking backward compatibility.
13778
attrfind = re.compile(
13779
r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*'
13780
r'(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?')
13781
attrfind_tolerant = re.compile(
13782
- r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*'
13783
- r'(\'[^\']*\'|"[^"]*"|[^>\s]*))?')
13784
+ r'\s*((?<=[\'"\s])[^\s/>][^\s/=>]*)(\s*=+\s*'
13785
+ r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?')
13786
locatestarttagend = re.compile(r"""
13787
<[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
13788
(?:\s+ # whitespace before attribute name
13789
@@ -49,19 +51,21 @@
13790
locatestarttagend_tolerant = re.compile(r"""
13791
<[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
13792
(?:\s* # optional whitespace before attribute name
13793
- (?:[a-zA-Z_][-.:a-zA-Z0-9_]* # attribute name
13794
- (?:\s*=\s* # value indicator
13795
+ (?:(?<=['"\s])[^\s/>][^\s/=>]* # attribute name
13796
+ (?:\s*=+\s* # value indicator
13797
(?:'[^']*' # LITA-enclosed value
13798
- |\"[^\"]*\" # LIT-enclosed value
13799
- |[^'\">\s]+ # bare value
13800
+ |"[^"]*" # LIT-enclosed value
13801
+ |(?!['"])[^>\s]* # bare value
13803
(?:\s*,)* # possibly followed by a comma
13810
\s* # trailing whitespace
13812
endendtag = re.compile('>')
13813
+# the HTML 5 spec, section 8.1.2.2, doesn't allow spaces between
13814
+# </ and the tag name, so maybe this should be fixed
13815
endtagfind = re.compile('</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
13818
@@ -121,6 +125,7 @@
13820
self.lasttag = '???'
13821
self.interesting = interesting_normal
13822
+ self.cdata_elem = None
13823
_markupbase.ParserBase.reset(self)
13825
def feed(self, data):
13826
@@ -145,11 +150,13 @@
13827
"""Return full source of start tag: '<...>'."""
13828
return self.__starttag_text
13830
- def set_cdata_mode(self):
13831
- self.interesting = interesting_cdata
13832
+ def set_cdata_mode(self, elem):
13833
+ self.cdata_elem = elem.lower()
13834
+ self.interesting = re.compile(r'</\s*%s\s*>' % self.cdata_elem, re.I)
13836
def clear_cdata_mode(self):
13837
self.interesting = interesting_normal
13838
+ self.cdata_elem = None
13840
# Internal -- handle data as far as reasonable. May leave state
13841
# and data to be processed by a subsequent call. If 'end' is
13842
@@ -163,6 +170,8 @@
13846
+ if self.cdata_elem:
13849
if i < j: self.handle_data(rawdata[i:j])
13850
i = self.updatepos(i, j)
13851
@@ -178,7 +187,10 @@
13852
elif startswith("<?", i):
13853
k = self.parse_pi(i)
13854
elif startswith("<!", i):
13855
- k = self.parse_declaration(i)
13857
+ k = self.parse_declaration(i)
13859
+ k = self.parse_html_declaration(i)
13861
self.handle_data("<")
13863
@@ -245,11 +257,46 @@
13865
assert 0, "interesting.search() lied"
13867
- if end and i < n:
13868
+ if end and i < n and not self.cdata_elem:
13869
self.handle_data(rawdata[i:n])
13870
i = self.updatepos(i, n)
13871
self.rawdata = rawdata[i:]
13873
+ # Internal -- parse html declarations, return length or -1 if not terminated
13874
+ # See w3.org/TR/html5/tokenization.html#markup-declaration-open-state
13875
+ # See also parse_declaration in _markupbase
13876
+ def parse_html_declaration(self, i):
13877
+ rawdata = self.rawdata
13878
+ if rawdata[i:i+2] != '<!':
13879
+ self.error('unexpected call to parse_html_declaration()')
13880
+ if rawdata[i:i+4] == '<!--':
13881
+ # this case is actually already handled in goahead()
13882
+ return self.parse_comment(i)
13883
+ elif rawdata[i:i+3] == '<![':
13884
+ return self.parse_marked_section(i)
13885
+ elif rawdata[i:i+9].lower() == '<!doctype':
13886
+ # find the closing >
13887
+ gtpos = rawdata.find('>', i+9)
13890
+ self.handle_decl(rawdata[i+2:gtpos])
13893
+ return self.parse_bogus_comment(i)
13895
+ # Internal -- parse bogus comment, return length or -1 if not terminated
13896
+ # see http://www.w3.org/TR/html5/tokenization.html#bogus-comment-state
13897
+ def parse_bogus_comment(self, i, report=1):
13898
+ rawdata = self.rawdata
13899
+ if rawdata[i:i+2] not in ('<!', '</'):
13900
+ self.error('unexpected call to parse_comment()')
13901
+ pos = rawdata.find('>', i+2)
13905
+ self.handle_comment(rawdata[i+2:pos])
13908
# Internal -- parse processing instr, return end or -1 if not terminated
13909
def parse_pi(self, i):
13910
rawdata = self.rawdata
13911
@@ -277,12 +324,11 @@
13912
assert match, 'unexpected call to parse_starttag()'
13914
self.lasttag = tag = rawdata[i+1:k].lower()
13918
m = attrfind.match(rawdata, k)
13920
- m = attrfind_tolerant.search(rawdata, k)
13921
+ m = attrfind_tolerant.match(rawdata, k)
13924
attrname, rest, attrvalue = m.group(1, 2, 3)
13925
@@ -291,6 +337,7 @@
13926
elif attrvalue[:1] == '\'' == attrvalue[-1:] or \
13927
attrvalue[:1] == '"' == attrvalue[-1:]:
13928
attrvalue = attrvalue[1:-1]
13930
attrvalue = self.unescape(attrvalue)
13931
attrs.append((attrname.lower(), attrvalue))
13933
@@ -315,7 +362,7 @@
13935
self.handle_starttag(tag, attrs)
13936
if tag in self.CDATA_CONTENT_ELEMENTS:
13937
- self.set_cdata_mode()
13938
+ self.set_cdata_mode(tag)
13941
# Internal -- check to see if we have a complete starttag; return end
13942
@@ -369,22 +416,40 @@
13943
match = endendtag.search(rawdata, i+1) # >
13947
+ gtpos = match.end()
13948
match = endtagfind.match(rawdata, i) # </ + tag + >
13950
+ if self.cdata_elem is not None:
13951
+ self.handle_data(rawdata[i:gtpos])
13954
- self.error("bad end tag: %r" % (rawdata[i:j],))
13955
- k = rawdata.find('<', i + 1, j)
13960
- self.handle_data(rawdata[i:j])
13962
- tag = match.group(1)
13963
- self.handle_endtag(tag.lower())
13964
+ self.error("bad end tag: %r" % (rawdata[i:gtpos],))
13965
+ # find the name: w3.org/TR/html5/tokenization.html#tag-name-state
13966
+ namematch = tagfind_tolerant.match(rawdata, i+2)
13967
+ if not namematch:
13968
+ # w3.org/TR/html5/tokenization.html#end-tag-open-state
13969
+ if rawdata[i:i+3] == '</>':
13972
+ return self.parse_bogus_comment(i)
13973
+ tagname = namematch.group().lower()
13974
+ # consume and ignore other stuff between the name and the >
13975
+ # Note: this is not 100% correct, since we might have things like
13976
+ # </tag attr=">">, but looking for > after tha name should cover
13977
+ # most of the cases and is much simpler
13978
+ gtpos = rawdata.find('>', namematch.end())
13979
+ self.handle_endtag(tagname)
13982
+ elem = match.group(1).lower() # script or style
13983
+ if self.cdata_elem is not None:
13984
+ if elem != self.cdata_elem:
13985
+ self.handle_data(rawdata[i:gtpos])
13988
+ self.handle_endtag(elem.lower())
13989
self.clear_cdata_mode()
13993
# Overridable -- finish processing of start+end tag: <tag.../>
13994
def handle_startendtag(self, tag, attrs):
13995
@@ -458,4 +523,4 @@
13998
return re.sub(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));",
13999
- replaceEntities, s, re.ASCII)
14000
+ replaceEntities, s, flags=re.ASCII)
14001
diff -r 137e45f15c0b Lib/http/client.py
14002
--- a/Lib/http/client.py
14003
+++ b/Lib/http/client.py
14004
@@ -678,7 +678,10 @@
14006
port = int(host[i+1:])
14008
- raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
14009
+ if host[i+1:] == "": # http://foo.com:/ == http://foo.com/
14010
+ port = self.default_port
14012
+ raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
14015
port = self.default_port
14016
@@ -947,11 +950,11 @@
14017
def endheaders(self, message_body=None):
14018
"""Indicate that the last header line has been sent to the server.
14020
- This method sends the request to the server. The optional
14021
- message_body argument can be used to pass message body
14022
- associated with the request. The message body will be sent in
14023
- the same packet as the message headers if possible. The
14024
- message_body should be a string.
14025
+ This method sends the request to the server. The optional message_body
14026
+ argument can be used to pass a message body associated with the
14027
+ request. The message body will be sent in the same packet as the
14028
+ message headers if it is a string, otherwise it is sent as a separate
14031
if self.__state == _CS_REQ_STARTED:
14032
self.__state = _CS_REQ_SENT
14033
diff -r 137e45f15c0b Lib/http/cookiejar.py
14034
--- a/Lib/http/cookiejar.py
14035
+++ b/Lib/http/cookiejar.py
14037
-"""HTTP cookie handling for web clients.
14038
+r"""HTTP cookie handling for web clients.
14040
This module has (now fairly distant) origins in Gisle Aas' Perl module
14041
HTTP::Cookies, from the libwww-perl library.
14042
@@ -1020,7 +1020,7 @@
14043
(not erhn.startswith(".") and
14044
not ("."+erhn).endswith(domain))):
14045
_debug(" effective request-host %s (even with added "
14046
- "initial dot) does not end end with %s",
14047
+ "initial dot) does not end with %s",
14050
if (cookie.version > 0 or
14051
diff -r 137e45f15c0b Lib/http/server.py
14052
--- a/Lib/http/server.py
14053
+++ b/Lib/http/server.py
14054
@@ -271,14 +271,11 @@
14055
self.request_version = version = self.default_request_version
14056
self.close_connection = 1
14057
requestline = str(self.raw_requestline, 'iso-8859-1')
14058
- if requestline[-2:] == '\r\n':
14059
- requestline = requestline[:-2]
14060
- elif requestline[-1:] == '\n':
14061
- requestline = requestline[:-1]
14062
+ requestline = requestline.rstrip('\r\n')
14063
self.requestline = requestline
14064
words = requestline.split()
14065
if len(words) == 3:
14066
- [command, path, version] = words
14067
+ command, path, version = words
14068
if version[:5] != 'HTTP/':
14069
self.send_error(400, "Bad request version (%r)" % version)
14071
@@ -304,7 +301,7 @@
14072
"Invalid HTTP Version (%s)" % base_version_number)
14074
elif len(words) == 2:
14075
- [command, path] = words
14076
+ command, path = words
14077
self.close_connection = 1
14078
if command != 'GET':
14079
self.send_error(400,
14080
diff -r 137e45f15c0b Lib/idlelib/AutoComplete.py
14081
--- a/Lib/idlelib/AutoComplete.py
14082
+++ b/Lib/idlelib/AutoComplete.py
14083
@@ -190,8 +190,7 @@
14084
bigl = eval("dir()", namespace)
14086
if "__all__" in bigl:
14087
- smalll = eval("__all__", namespace)
14089
+ smalll = sorted(eval("__all__", namespace))
14091
smalll = [s for s in bigl if s[:1] != '_']
14093
@@ -200,8 +199,7 @@
14096
if "__all__" in bigl:
14097
- smalll = entity.__all__
14099
+ smalll = sorted(entity.__all__)
14101
smalll = [s for s in bigl if s[:1] != '_']
14103
diff -r 137e45f15c0b Lib/idlelib/ColorDelegator.py
14104
--- a/Lib/idlelib/ColorDelegator.py
14105
+++ b/Lib/idlelib/ColorDelegator.py
14106
@@ -15,15 +15,16 @@
14108
kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
14109
builtinlist = [str(name) for name in dir(builtins)
14110
- if not name.startswith('_')]
14111
+ if not name.startswith('_') and \
14112
+ name not in keyword.kwlist]
14113
# self.file = open("file") :
14114
# 1st 'file' colorized normal, 2nd as builtin, 3rd as string
14115
builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
14116
comment = any("COMMENT", [r"#[^\n]*"])
14117
- sqstring = r"(\b[rRuU])?'[^'\\\n]*(\\.[^'\\\n]*)*'?"
14118
- dqstring = r'(\b[rRuU])?"[^"\\\n]*(\\.[^"\\\n]*)*"?'
14119
- sq3string = r"(\b[rRuU])?'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
14120
- dq3string = r'(\b[rRuU])?"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
14121
+ sqstring = r"(\b[rRbB])?'[^'\\\n]*(\\.[^'\\\n]*)*'?"
14122
+ dqstring = r'(\b[rRbB])?"[^"\\\n]*(\\.[^"\\\n]*)*"?'
14123
+ sq3string = r"(\b[rRbB])?'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
14124
+ dq3string = r'(\b[rRbB])?"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
14125
string = any("STRING", [sq3string, dq3string, sqstring, dqstring])
14126
return kw + "|" + builtin + "|" + comment + "|" + string +\
14127
"|" + any("SYNC", [r"\n"])
14128
diff -r 137e45f15c0b Lib/idlelib/EditorWindow.py
14129
--- a/Lib/idlelib/EditorWindow.py
14130
+++ b/Lib/idlelib/EditorWindow.py
14132
descr = os.path.splitext(filename)[1], None, imp.PY_SOURCE
14133
return file, filename, descr
14136
+class HelpDialog(object):
14138
+ def __init__(self):
14139
+ self.parent = None # parent of help window
14140
+ self.dlg = None # the help window iteself
14142
+ def display(self, parent, near=None):
14143
+ """ Display the help dialog.
14145
+ parent - parent widget for the help window
14147
+ near - a Toplevel widget (e.g. EditorWindow or PyShell)
14148
+ to use as a reference for placing the help window
14150
+ if self.dlg is None:
14151
+ self.show_dialog(parent)
14153
+ self.nearwindow(near)
14155
+ def show_dialog(self, parent):
14156
+ self.parent = parent
14157
+ fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt')
14158
+ self.dlg = dlg = textView.view_file(parent,'Help',fn, modal=False)
14159
+ dlg.bind('<Destroy>', self.destroy, '+')
14161
+ def nearwindow(self, near):
14162
+ # Place the help dialog near the window specified by parent.
14163
+ # Note - this may not reposition the window in Metacity
14164
+ # if "/apps/metacity/general/disable_workarounds" is enabled
14166
+ geom = (near.winfo_rootx() + 10, near.winfo_rooty() + 10)
14168
+ dlg.geometry("=+%d+%d" % geom)
14172
+ def destroy(self, ev=None):
14174
+ self.parent = None
14176
+helpDialog = HelpDialog() # singleton instance
14179
class EditorWindow(object):
14180
from idlelib.Percolator import Percolator
14181
from idlelib.ColorDelegator import ColorDelegator
14182
@@ -453,8 +497,11 @@
14183
configDialog.ConfigDialog(self.top,'Settings')
14185
def help_dialog(self, event=None):
14186
- fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt')
14187
- textView.view_file(self.top,'Help',fn)
14189
+ parent = self.root
14191
+ parent = self.top
14192
+ helpDialog.display(parent, near=self.top)
14194
def python_docs(self, event=None):
14195
if sys.platform[:3] == 'win':
14196
@@ -799,12 +846,17 @@
14197
rf_list = [path for path in rf_list if path not in bad_paths]
14198
ulchars = "1234567890ABCDEFGHIJK"
14199
rf_list = rf_list[0:len(ulchars)]
14200
- rf_file = open(self.recent_files_path, 'w',
14201
- encoding='utf_8', errors='replace')
14203
- rf_file.writelines(rf_list)
14206
+ with open(self.recent_files_path, 'w',
14207
+ encoding='utf_8', errors='replace') as rf_file:
14208
+ rf_file.writelines(rf_list)
14209
+ except IOError as err:
14210
+ if not getattr(self.root, "recentfilelist_error_displayed", False):
14211
+ self.root.recentfilelist_error_displayed = True
14212
+ tkMessageBox.showerror(title='IDLE Error',
14213
+ message='Unable to update Recent Files list:\n%s'
14215
+ parent=self.text)
14216
# for each edit window instance, construct the recent files menu
14217
for instance in self.top.instance_dict:
14218
menu = instance.recent_files_menu
14219
@@ -1129,7 +1181,10 @@
14221
want = ((have - 1) // self.indentwidth) * self.indentwidth
14222
# Debug prompt is multilined....
14223
- last_line_of_prompt = sys.ps1.split('\n')[-1]
14224
+ if self.context_use_ps1:
14225
+ last_line_of_prompt = sys.ps1.split('\n')[-1]
14227
+ last_line_of_prompt = ''
14230
if chars == last_line_of_prompt:
14231
diff -r 137e45f15c0b Lib/idlelib/PyShell.py
14232
--- a/Lib/idlelib/PyShell.py
14233
+++ b/Lib/idlelib/PyShell.py
14235
#! /usr/bin/env python3
14255
from code import InteractiveInterpreter
14256
@@ -201,18 +202,26 @@
14257
breaks = self.breakpoints
14258
filename = self.io.filename
14260
- lines = open(self.breakpointPath,"r").readlines()
14261
+ with open(self.breakpointPath, "r") as fp:
14262
+ lines = fp.readlines()
14265
- new_file = open(self.breakpointPath,"w")
14266
- for line in lines:
14267
- if not line.startswith(filename + '='):
14268
- new_file.write(line)
14269
- self.update_breakpoints()
14270
- breaks = self.breakpoints
14272
- new_file.write(filename + '=' + str(breaks) + '\n')
14275
+ with open(self.breakpointPath, "w") as new_file:
14276
+ for line in lines:
14277
+ if not line.startswith(filename + '='):
14278
+ new_file.write(line)
14279
+ self.update_breakpoints()
14280
+ breaks = self.breakpoints
14282
+ new_file.write(filename + '=' + str(breaks) + '\n')
14283
+ except IOError as err:
14284
+ if not getattr(self.root, "breakpoint_error_displayed", False):
14285
+ self.root.breakpoint_error_displayed = True
14286
+ tkMessageBox.showerror(title='IDLE Error',
14287
+ message='Unable to update breakpoint list:\n%s'
14289
+ parent=self.text)
14291
def restore_file_breaks(self):
14292
self.text.update() # this enables setting "BREAK" tags to be visible
14293
@@ -220,7 +229,8 @@
14294
if filename is None:
14296
if os.path.isfile(self.breakpointPath):
14297
- lines = open(self.breakpointPath,"r").readlines()
14298
+ with open(self.breakpointPath, "r") as fp:
14299
+ lines = fp.readlines()
14301
if line.startswith(filename + '='):
14302
breakpoint_linenumbers = eval(line[len(filename)+1:])
14303
@@ -338,6 +348,7 @@
14304
self.restarting = False
14305
self.subprocess_arglist = None
14307
+ self.original_compiler_flags = self.compile.compiler.flags
14311
@@ -400,11 +411,11 @@
14312
self.rpcclt.register("flist", self.tkconsole.flist)
14313
self.rpcclt.register("linecache", linecache)
14314
self.rpcclt.register("interp", self)
14315
- self.transfer_path()
14316
+ self.transfer_path(with_cwd=True)
14317
self.poll_subprocess()
14320
- def restart_subprocess(self):
14321
+ def restart_subprocess(self, with_cwd=False):
14322
if self.restarting:
14324
self.restarting = True
14325
@@ -428,7 +439,7 @@
14326
except socket.timeout as err:
14327
self.display_no_subprocess_error()
14329
- self.transfer_path()
14330
+ self.transfer_path(with_cwd=with_cwd)
14331
# annotate restart in shell window and mark it
14332
console.text.delete("iomark", "end-1c")
14334
@@ -445,6 +456,7 @@
14335
gui = RemoteDebugger.restart_subprocess_debugger(self.rpcclt)
14336
# reload remote debugger breakpoints for all PyShellEditWindows
14337
debug.load_breakpoints()
14338
+ self.compile.compiler.flags = self.original_compiler_flags
14339
self.restarting = False
14342
@@ -476,12 +488,18 @@
14346
- def transfer_path(self):
14347
+ def transfer_path(self, with_cwd=False):
14348
+ if with_cwd: # Issue 13506
14349
+ path = [''] # include Current Working Directory
14350
+ path.extend(sys.path)
14354
self.runcommand("""if 1:
14358
- \n""" % (sys.path,))
14363
@@ -571,7 +589,8 @@
14364
def execfile(self, filename, source=None):
14365
"Execute an existing file"
14367
- source = open(filename, "r").read()
14368
+ with tokenize.open(filename) as fp:
14369
+ source = fp.read()
14371
code = compile(source, filename, "exec")
14372
except (OverflowError, SyntaxError):
14373
@@ -640,9 +659,9 @@
14374
text = tkconsole.text
14375
text.tag_remove("ERROR", "1.0", "end")
14376
type, value, tb = sys.exc_info()
14377
- msg = value.msg or "<no detail available>"
14378
- lineno = value.lineno or 1
14379
- offset = value.offset or 0
14380
+ msg = getattr(value, 'msg', '') or value or "<no detail available>"
14381
+ lineno = getattr(value, 'lineno', '') or 1
14382
+ offset = getattr(value, 'offset', '') or 0
14384
lineno += 1 #mark end of offending line
14386
@@ -1174,7 +1193,8 @@
14387
self.text.see("restart")
14389
def restart_shell(self, event=None):
14390
- self.interp.restart_subprocess()
14391
+ "Callback for Run/Restart Shell Cntl-F6"
14392
+ self.interp.restart_subprocess(with_cwd=True)
14394
def showprompt(self):
14396
diff -r 137e45f15c0b Lib/idlelib/ScriptBinding.py
14397
--- a/Lib/idlelib/ScriptBinding.py
14398
+++ b/Lib/idlelib/ScriptBinding.py
14399
@@ -67,25 +67,20 @@
14401
def tabnanny(self, filename):
14402
# XXX: tabnanny should work on binary files as well
14403
- with open(filename, 'r', encoding='iso-8859-1') as f:
14404
- two_lines = f.readline() + f.readline()
14405
- encoding = IOBinding.coding_spec(two_lines)
14407
- encoding = 'utf-8'
14408
- f = open(filename, 'r', encoding=encoding)
14410
- tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
14411
- except tokenize.TokenError as msg:
14412
- msgtxt, (lineno, start) = msg
14413
- self.editwin.gotoline(lineno)
14414
- self.errorbox("Tabnanny Tokenizing Error",
14415
- "Token Error: %s" % msgtxt)
14417
- except tabnanny.NannyNag as nag:
14418
- # The error messages from tabnanny are too confusing...
14419
- self.editwin.gotoline(nag.get_lineno())
14420
- self.errorbox("Tab/space error", indent_message)
14422
+ with tokenize.open(filename) as f:
14424
+ tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
14425
+ except tokenize.TokenError as msg:
14426
+ msgtxt, (lineno, start) = msg
14427
+ self.editwin.gotoline(lineno)
14428
+ self.errorbox("Tabnanny Tokenizing Error",
14429
+ "Token Error: %s" % msgtxt)
14431
+ except tabnanny.NannyNag as nag:
14432
+ # The error messages from tabnanny are too confusing...
14433
+ self.editwin.gotoline(nag.get_lineno())
14434
+ self.errorbox("Tab/space error", indent_message)
14438
def checksyntax(self, filename):
14439
@@ -106,10 +101,10 @@
14441
# If successful, return the compiled code
14442
return compile(source, filename, "exec")
14443
- except (SyntaxError, OverflowError) as value:
14444
- msg = value.msg or "<no detail available>"
14445
- lineno = value.lineno or 1
14446
- offset = value.offset or 0
14447
+ except (SyntaxError, OverflowError, ValueError) as value:
14448
+ msg = getattr(value, 'msg', '') or value or "<no detail available>"
14449
+ lineno = getattr(value, 'lineno', '') or 1
14450
+ offset = getattr(value, 'offset', '') or 0
14452
lineno += 1 #mark end of offending line
14453
pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1)
14454
@@ -149,10 +144,9 @@
14456
if not self.tabnanny(filename):
14458
- shell = self.shell
14459
- interp = shell.interp
14460
+ interp = self.shell.interp
14461
if PyShell.use_subprocess:
14462
- shell.restart_shell()
14463
+ interp.restart_subprocess(with_cwd=False)
14464
dirname = os.path.dirname(filename)
14465
# XXX Too often this discards arguments the user just set...
14466
interp.runcommand("""if 1:
14467
diff -r 137e45f15c0b Lib/idlelib/configDialog.py
14468
--- a/Lib/idlelib/configDialog.py
14469
+++ b/Lib/idlelib/configDialog.py
14470
@@ -199,7 +199,7 @@
14471
("'string'",'string'),('\n var1 = ','normal'),("'selected'",'hilite'),
14472
('\n var2 = ','normal'),("'found'",'hit'),
14473
('\n var3 = ','normal'),('list', 'builtin'), ('(','normal'),
14474
- ('None', 'builtin'),(')\n\n','normal'),
14475
+ ('None', 'keyword'),(')\n\n','normal'),
14476
(' error ','error'),(' ','normal'),('cursor |','cursor'),
14477
('\n ','normal'),('shell','console'),(' ','normal'),('stdout','stdout'),
14478
(' ','normal'),('stderr','stderr'),('\n','normal'))
14479
diff -r 137e45f15c0b Lib/idlelib/rpc.py
14480
--- a/Lib/idlelib/rpc.py
14481
+++ b/Lib/idlelib/rpc.py
14482
@@ -570,7 +570,7 @@
14483
# Adds names to dictionary argument 'methods'
14484
for name in dir(obj):
14485
attr = getattr(obj, name)
14486
- if hasattr(attr, '__call__'):
14487
+ if callable(attr):
14489
if isinstance(obj, type):
14490
for super in obj.__bases__:
14491
@@ -579,7 +579,7 @@
14492
def _getattributes(obj, attributes):
14493
for name in dir(obj):
14494
attr = getattr(obj, name)
14495
- if not hasattr(attr, '__call__'):
14496
+ if not callable(attr):
14497
attributes[name] = 1
14499
class MethodProxy(object):
14500
diff -r 137e45f15c0b Lib/idlelib/textView.py
14501
--- a/Lib/idlelib/textView.py
14502
+++ b/Lib/idlelib/textView.py
14504
"""A simple text viewer dialog for IDLE
14507
- def __init__(self, parent, title, text):
14508
+ def __init__(self, parent, title, text, modal=True):
14509
"""Show the given text in a scrollable window with a 'close' button
14514
self.CreateWidgets()
14516
- self.transient(parent)
14518
self.protocol("WM_DELETE_WINDOW", self.Ok)
14519
self.parent = parent
14520
self.textView.focus_set()
14522
self.bind('<Escape>',self.Ok) #dismiss dialog
14523
self.textView.insert(0.0, text)
14524
self.textView.config(state=DISABLED)
14525
- self.wait_window()
14528
+ self.transient(parent)
14530
+ self.wait_window()
14532
def CreateWidgets(self):
14533
frameText = Frame(self, relief=SUNKEN, height=700)
14534
@@ -57,10 +59,10 @@
14538
-def view_text(parent, title, text):
14539
- TextViewer(parent, title, text)
14540
+def view_text(parent, title, text, modal=True):
14541
+ return TextViewer(parent, title, text, modal)
14543
-def view_file(parent, title, filename, encoding=None):
14544
+def view_file(parent, title, filename, encoding=None, modal=True):
14546
with open(filename, 'r', encoding=encoding) as file:
14547
contents = file.read()
14549
message='Unable to load file %r .' % filename,
14552
- return view_text(parent, title, contents)
14553
+ return view_text(parent, title, contents, modal)
14556
if __name__ == '__main__':
14557
@@ -80,11 +82,15 @@
14558
filename = './textView.py'
14559
text = file(filename, 'r').read()
14560
btn1 = Button(root, text='view_text',
14561
- command=lambda:view_text(root, 'view_text', text))
14562
+ command=lambda:view_text(root, 'view_text', text))
14563
btn1.pack(side=LEFT)
14564
btn2 = Button(root, text='view_file',
14565
command=lambda:view_file(root, 'view_file', filename))
14566
btn2.pack(side=LEFT)
14567
+ btn3 = Button(root, text='nonmodal view_text',
14568
+ command=lambda:view_text(root, 'nonmodal view_text', text,
14570
+ btn3.pack(side=LEFT)
14571
close = Button(root, text='Close', command=root.destroy)
14572
close.pack(side=RIGHT)
14574
diff -r 137e45f15c0b Lib/imaplib.py
14575
--- a/Lib/imaplib.py
14576
+++ b/Lib/imaplib.py
14577
@@ -1385,7 +1385,7 @@
14578
"""Convert date_time to IMAP4 INTERNALDATE representation.
14580
Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'. The
14581
- date_time argument can be a number (int or float) represening
14582
+ date_time argument can be a number (int or float) representing
14583
seconds since epoch (as returned by time.time()), a 9-tuple
14584
representing local time (as returned by time.localtime()), or a
14585
double-quoted string. In the last case, it is assumed to already
14586
diff -r 137e45f15c0b Lib/importlib/_bootstrap.py
14587
--- a/Lib/importlib/_bootstrap.py
14588
+++ b/Lib/importlib/_bootstrap.py
14589
@@ -816,7 +816,9 @@
14590
for finder in meta_path:
14591
loader = finder.find_module(name, path)
14592
if loader is not None:
14593
- loader.load_module(name)
14594
+ # The parent import may have already imported this module.
14595
+ if name not in sys.modules:
14596
+ loader.load_module(name)
14599
raise ImportError(_ERR_MSG.format(name))
14600
diff -r 137e45f15c0b Lib/importlib/test/source/test_file_loader.py
14601
--- a/Lib/importlib/test/source/test_file_loader.py
14602
+++ b/Lib/importlib/test/source/test_file_loader.py
14604
from .. import util
14605
from . import util as source_util
14611
@@ -128,6 +129,30 @@
14612
pycache = os.path.dirname(imp.cache_from_source(file_path))
14613
shutil.rmtree(pycache)
14615
+ def test_timestamp_overflow(self):
14616
+ # When a modification timestamp is larger than 2**32, it should be
14617
+ # truncated rather than raise an OverflowError.
14618
+ with source_util.create_modules('_temp') as mapping:
14619
+ source = mapping['_temp']
14620
+ compiled = imp.cache_from_source(source)
14621
+ with open(source, 'w') as f:
14624
+ os.utime(source, (2 ** 33 - 5, 2 ** 33 - 5))
14625
+ except OverflowError:
14626
+ self.skipTest("cannot set modification time to large integer")
14627
+ except OSError as e:
14628
+ if e.errno != getattr(errno, 'EOVERFLOW', None):
14630
+ self.skipTest("cannot set modification time to large integer ({})".format(e))
14631
+ loader = _bootstrap._SourceFileLoader('_temp', mapping['_temp'])
14632
+ mod = loader.load_module('_temp')
14634
+ self.assertEqual(mod.__cached__, compiled)
14635
+ self.assertEqual(mod.x, 5)
14636
+ # The pyc file was created.
14637
+ os.stat(compiled)
14640
class BadBytecodeTest(unittest.TestCase):
14642
@@ -256,6 +281,8 @@
14643
with open(bytecode_path, 'rb') as file:
14644
self.assertGreater(len(file.read()), 8)
14646
+ self._test_magic_only(test)
14648
@source_util.writes_bytecode_files
14649
def test_bad_magic(self):
14650
# When the magic number is different, the bytecode should be
14651
@@ -276,6 +303,8 @@
14652
with open(bc_path, 'rb') as file:
14653
self.assertGreater(len(file.read()), 8)
14655
+ self._test_partial_timestamp(test)
14657
@source_util.writes_bytecode_files
14658
def test_no_marshal(self):
14659
# When there is only the magic number and timestamp, raise EOFError.
14660
diff -r 137e45f15c0b Lib/importlib/test/test_api.py
14661
--- a/Lib/importlib/test/test_api.py
14662
+++ b/Lib/importlib/test/test_api.py
14664
importlib.import_module('.support')
14667
+ def test_loaded_once(self):
14668
+ # Issue #13591: Modules should only be loaded once when
14669
+ # initializing the parent package attempts to import the
14670
+ # module currently being imported.
14673
+ importlib.import_module('a.b')
14675
+ nonlocal b_load_count
14676
+ b_load_count += 1
14677
+ code = {'a': load_a, 'a.b': load_b}
14678
+ modules = ['a.__init__', 'a.b']
14679
+ with util.mock_modules(*modules, module_code=code) as mock:
14680
+ with util.import_state(meta_path=[mock]):
14681
+ importlib.import_module('a.b')
14682
+ self.assertEqual(b_load_count, 1)
14685
from test.support import run_unittest
14686
run_unittest(ImportModuleTests)
14687
diff -r 137e45f15c0b Lib/importlib/test/util.py
14688
--- a/Lib/importlib/test/util.py
14689
+++ b/Lib/importlib/test/util.py
14692
"""A mock importer/loader."""
14694
- def __init__(self, *names):
14695
+ def __init__(self, *names, module_code={}):
14697
+ self.module_code = {}
14699
if not name.endswith('.__init__'):
14701
@@ -105,6 +106,8 @@
14702
if import_name != name:
14703
module.__path__ = ['<mock __path__>']
14704
self.modules[import_name] = module
14705
+ if import_name in module_code:
14706
+ self.module_code[import_name] = module_code[import_name]
14708
def __getitem__(self, name):
14709
return self.modules[name]
14710
@@ -120,6 +123,8 @@
14713
sys.modules[fullname] = self.modules[fullname]
14714
+ if fullname in self.module_code:
14715
+ self.module_code[fullname]()
14716
return self.modules[fullname]
14718
def __enter__(self):
14719
diff -r 137e45f15c0b Lib/inspect.py
14720
--- a/Lib/inspect.py
14721
+++ b/Lib/inspect.py
14722
@@ -100,11 +100,11 @@
14723
tests return false from the ismethoddescriptor() test, simply because
14724
the other tests promise more -- you can, e.g., count on having the
14725
__func__ attribute (etc) when an object passes ismethod()."""
14726
- return (hasattr(object, "__get__")
14727
- and not hasattr(object, "__set__") # else it's a data descriptor
14728
- and not ismethod(object) # mutual exclusion
14729
- and not isfunction(object)
14730
- and not isclass(object))
14731
+ if isclass(object) or ismethod(object) or isfunction(object):
14732
+ # mutual exclusion
14734
+ tp = type(object)
14735
+ return hasattr(tp, "__get__") and not hasattr(tp, "__set__")
14737
def isdatadescriptor(object):
14738
"""Return true if the object is a data descriptor.
14739
@@ -114,7 +114,11 @@
14740
Typically, data descriptors will also have __name__ and __doc__ attributes
14741
(properties, getsets, and members have both of these attributes), but this
14742
is not guaranteed."""
14743
- return (hasattr(object, "__set__") and hasattr(object, "__get__"))
14744
+ if isclass(object) or ismethod(object) or isfunction(object):
14745
+ # mutual exclusion
14747
+ tp = type(object)
14748
+ return hasattr(tp, "__set__") and hasattr(tp, "__get__")
14750
if hasattr(types, 'MemberDescriptorType'):
14751
# CPython and equivalent
14752
@@ -254,12 +258,23 @@
14753
def getmembers(object, predicate=None):
14754
"""Return all members of an object as (name, value) pairs sorted by name.
14755
Optionally, only return members that satisfy a given predicate."""
14756
+ if isclass(object):
14757
+ mro = (object,) + getmro(object)
14761
for key in dir(object):
14763
- value = getattr(object, key)
14764
- except AttributeError:
14766
+ # First try to get the value via __dict__. Some descriptors don't
14767
+ # like calling their __get__ (see bug #1785).
14769
+ if key in base.__dict__:
14770
+ value = base.__dict__[key]
14774
+ value = getattr(object, key)
14775
+ except AttributeError:
14777
if not predicate or predicate(value):
14778
results.append((key, value))
14780
@@ -295,30 +310,21 @@
14784
- # Get the object associated with the name.
14785
+ # Get the object associated with the name, and where it was defined.
14786
# Getting an obj from the __dict__ sometimes reveals more than
14787
# using getattr. Static and class methods are dramatic examples.
14788
- if name in cls.__dict__:
14789
- obj = cls.__dict__[name]
14790
+ # Furthermore, some objects may raise an Exception when fetched with
14791
+ # getattr(). This is the case with some descriptors (bug #1785).
14792
+ # Thus, we only use getattr() as a last resort.
14794
+ for base in (cls,) + mro:
14795
+ if name in base.__dict__:
14796
+ obj = base.__dict__[name]
14800
obj = getattr(cls, name)
14802
- # Figure out where it was defined.
14803
- homecls = getattr(obj, "__objclass__", None)
14804
- if homecls is None:
14805
- # search the dicts.
14807
- if name in base.__dict__:
14811
- # Get the object again, in order to get it from the defining
14812
- # __dict__ instead of via getattr (if possible).
14813
- if homecls is not None and name in homecls.__dict__:
14814
- obj = homecls.__dict__[name]
14816
- # Also get the object via getattr.
14817
- obj_via_getattr = getattr(cls, name)
14818
+ homecls = getattr(obj, "__objclass__", homecls)
14820
# Classify the object.
14821
if isinstance(obj, staticmethod):
14822
@@ -327,11 +333,18 @@
14823
kind = "class method"
14824
elif isinstance(obj, property):
14826
- elif (isfunction(obj_via_getattr) or
14827
- ismethoddescriptor(obj_via_getattr)):
14828
+ elif ismethoddescriptor(obj):
14830
+ elif isdatadescriptor(obj):
14834
+ obj_via_getattr = getattr(cls, name)
14835
+ if (isfunction(obj_via_getattr) or
14836
+ ismethoddescriptor(obj_via_getattr)):
14840
+ obj = obj_via_getattr
14842
result.append(Attribute(name, kind, homecls, obj))
14844
@@ -483,7 +496,7 @@
14845
return sys.modules.get(modulesbyfile[file])
14846
# Update the filename to module name cache and check yet again
14847
# Copy sys.modules in order to cope with changes while iterating
14848
- for modname, module in sys.modules.items():
14849
+ for modname, module in list(sys.modules.items()):
14850
if ismodule(module) and hasattr(module, '__file__'):
14851
f = module.__file__
14852
if f == _filesbymodname.get(modname, None):
14853
@@ -1084,7 +1097,7 @@
14855
def _check_class(klass, attr):
14856
for entry in _static_getmro(klass):
14857
- if not _shadowed_dict(type(entry)):
14858
+ if _shadowed_dict(type(entry)) is _sentinel:
14860
return entry.__dict__[attr]
14862
@@ -1109,8 +1122,8 @@
14863
if not (type(class_dict) is types.GetSetDescriptorType and
14864
class_dict.__name__ == "__dict__" and
14865
class_dict.__objclass__ is entry):
14868
+ return class_dict
14871
def getattr_static(obj, attr, default=_sentinel):
14872
"""Retrieve attributes without triggering dynamic lookup via the
14873
@@ -1126,7 +1139,9 @@
14874
instance_result = _sentinel
14875
if not _is_type(obj):
14877
- if not _shadowed_dict(klass):
14878
+ dict_attr = _shadowed_dict(klass)
14879
+ if (dict_attr is _sentinel or
14880
+ type(dict_attr) is types.MemberDescriptorType):
14881
instance_result = _check_instance(obj, attr)
14884
@@ -1146,10 +1161,11 @@
14886
# for types we check the metaclass too
14887
for entry in _static_getmro(type(klass)):
14889
- return entry.__dict__[attr]
14892
+ if _shadowed_dict(type(entry)) is _sentinel:
14894
+ return entry.__dict__[attr]
14897
if default is not _sentinel:
14899
raise AttributeError(attr)
14900
diff -r 137e45f15c0b Lib/keyword.py
14901
--- a/Lib/keyword.py
14902
+++ b/Lib/keyword.py
14904
To update the symbols in this file, 'cd' to the top directory of
14905
the python source tree after building the interpreter and run:
14907
- python Lib/keyword.py
14908
+ ./python Lib/keyword.py
14911
__all__ = ["iskeyword", "kwlist"]
14912
diff -r 137e45f15c0b Lib/lib2to3/Grammar.txt
14913
--- a/Lib/lib2to3/Grammar.txt
14914
+++ b/Lib/lib2to3/Grammar.txt
14916
-# Grammar for Python
14917
+# Grammar for 2to3. This grammar supports Python 2.x and 3.x.
14919
# Note: Changing the grammar specified in this file will most likely
14920
# require corresponding changes in the parser module
14921
diff -r 137e45f15c0b Lib/lib2to3/main.py
14922
--- a/Lib/lib2to3/main.py
14923
+++ b/Lib/lib2to3/main.py
14924
@@ -25,12 +25,41 @@
14926
class StdoutRefactoringTool(refactor.MultiprocessRefactoringTool):
14928
+ A refactoring tool that can avoid overwriting its input files.
14929
Prints output to stdout.
14931
+ Output files can optionally be written to a different directory and or
14932
+ have an extra file suffix appended to their name for use in situations
14933
+ where you do not want to replace the input files.
14936
- def __init__(self, fixers, options, explicit, nobackups, show_diffs):
14937
+ def __init__(self, fixers, options, explicit, nobackups, show_diffs,
14938
+ input_base_dir='', output_dir='', append_suffix=''):
14941
+ fixers: A list of fixers to import.
14942
+ options: A dict with RefactoringTool configuration.
14943
+ explicit: A list of fixers to run even if they are explicit.
14944
+ nobackups: If true no backup '.bak' files will be created for those
14945
+ files that are being refactored.
14946
+ show_diffs: Should diffs of the refactoring be printed to stdout?
14947
+ input_base_dir: The base directory for all input files. This class
14948
+ will strip this path prefix off of filenames before substituting
14949
+ it with output_dir. Only meaningful if output_dir is supplied.
14950
+ All files processed by refactor() must start with this path.
14951
+ output_dir: If supplied, all converted files will be written into
14952
+ this directory tree instead of input_base_dir.
14953
+ append_suffix: If supplied, all files output by this tool will have
14954
+ this appended to their filename. Useful for changing .py to
14955
+ .py3 for example by passing append_suffix='3'.
14957
self.nobackups = nobackups
14958
self.show_diffs = show_diffs
14959
+ if input_base_dir and not input_base_dir.endswith(os.sep):
14960
+ input_base_dir += os.sep
14961
+ self._input_base_dir = input_base_dir
14962
+ self._output_dir = output_dir
14963
+ self._append_suffix = append_suffix
14964
super(StdoutRefactoringTool, self).__init__(fixers, options, explicit)
14966
def log_error(self, msg, *args, **kwargs):
14968
self.logger.error(msg, *args, **kwargs)
14970
def write_file(self, new_text, filename, old_text, encoding):
14971
+ orig_filename = filename
14972
+ if self._output_dir:
14973
+ if filename.startswith(self._input_base_dir):
14974
+ filename = os.path.join(self._output_dir,
14975
+ filename[len(self._input_base_dir):])
14977
+ raise ValueError('filename %s does not start with the '
14978
+ 'input_base_dir %s' % (
14979
+ filename, self._input_base_dir))
14980
+ if self._append_suffix:
14981
+ filename += self._append_suffix
14982
+ if orig_filename != filename:
14983
+ output_dir = os.path.dirname(filename)
14984
+ if not os.path.isdir(output_dir):
14985
+ os.makedirs(output_dir)
14986
+ self.log_message('Writing converted %s to %s.', orig_filename,
14988
if not self.nobackups:
14990
backup = filename + ".bak"
14992
write(new_text, filename, old_text, encoding)
14993
if not self.nobackups:
14994
shutil.copymode(backup, filename)
14995
+ if orig_filename != filename:
14996
+ # Preserve the file mode in the new output directory.
14997
+ shutil.copymode(orig_filename, filename)
14999
def print_output(self, old, new, filename, equal):
15001
@@ -113,11 +162,33 @@
15002
help="Write back modified files")
15003
parser.add_option("-n", "--nobackups", action="store_true", default=False,
15004
help="Don't write backups for modified files")
15005
+ parser.add_option("-o", "--output-dir", action="store", type="str",
15006
+ default="", help="Put output files in this directory "
15007
+ "instead of overwriting the input files. Requires -n.")
15008
+ parser.add_option("-W", "--write-unchanged-files", action="store_true",
15009
+ help="Also write files even if no changes were required"
15010
+ " (useful with --output-dir); implies -w.")
15011
+ parser.add_option("--add-suffix", action="store", type="str", default="",
15012
+ help="Append this string to all output filenames."
15013
+ " Requires -n if non-empty. "
15014
+ "ex: --add-suffix='3' will generate .py3 files.")
15016
# Parse command line arguments
15017
refactor_stdin = False
15019
options, args = parser.parse_args(args)
15020
+ if options.write_unchanged_files:
15021
+ flags["write_unchanged_files"] = True
15022
+ if not options.write:
15023
+ warn("--write-unchanged-files/-W implies -w.")
15024
+ options.write = True
15025
+ # If we allowed these, the original files would be renamed to backup names
15026
+ # but not replaced.
15027
+ if options.output_dir and not options.nobackups:
15028
+ parser.error("Can't use --output-dir/-o without -n.")
15029
+ if options.add_suffix and not options.nobackups:
15030
+ parser.error("Can't use --add-suffix without -n.")
15032
if not options.write and options.no_diffs:
15033
warn("not writing files and not printing diffs; that's not very useful")
15034
if not options.write and options.nobackups:
15035
@@ -143,6 +214,7 @@
15036
# Set up logging handler
15037
level = logging.DEBUG if options.verbose else logging.INFO
15038
logging.basicConfig(format='%(name)s: %(message)s', level=level)
15039
+ logger = logging.getLogger('lib2to3.main')
15041
# Initialize the refactoring tool
15042
avail_fixes = set(refactor.get_fixers_from_package(fixer_pkg))
15043
@@ -159,8 +231,23 @@
15045
requested = avail_fixes.union(explicit)
15046
fixer_names = requested.difference(unwanted_fixes)
15047
- rt = StdoutRefactoringTool(sorted(fixer_names), flags, sorted(explicit),
15048
- options.nobackups, not options.no_diffs)
15049
+ input_base_dir = os.path.commonprefix(args)
15050
+ if (input_base_dir and not input_base_dir.endswith(os.sep)
15051
+ and not os.path.isdir(input_base_dir)):
15052
+ # One or more similar names were passed, their directory is the base.
15053
+ # os.path.commonprefix() is ignorant of path elements, this corrects
15054
+ # for that weird API.
15055
+ input_base_dir = os.path.dirname(input_base_dir)
15056
+ if options.output_dir:
15057
+ input_base_dir = input_base_dir.rstrip(os.sep)
15058
+ logger.info('Output in %r will mirror the input directory %r layout.',
15059
+ options.output_dir, input_base_dir)
15060
+ rt = StdoutRefactoringTool(
15061
+ sorted(fixer_names), flags, sorted(explicit),
15062
+ options.nobackups, not options.no_diffs,
15063
+ input_base_dir=input_base_dir,
15064
+ output_dir=options.output_dir,
15065
+ append_suffix=options.add_suffix)
15067
# Refactor all files and directories passed as arguments
15069
diff -r 137e45f15c0b Lib/lib2to3/patcomp.py
15070
--- a/Lib/lib2to3/patcomp.py
15071
+++ b/Lib/lib2to3/patcomp.py
15073
__author__ = "Guido van Rossum <guido@python.org>"
15079
# Fairly local imports
15081
def tokenize_wrapper(input):
15082
"""Tokenizes a string suppressing significant whitespace."""
15083
skip = set((token.NEWLINE, token.INDENT, token.DEDENT))
15084
- tokens = tokenize.generate_tokens(driver.generate_lines(input).__next__)
15085
+ tokens = tokenize.generate_tokens(io.StringIO(input).readline)
15086
for quintuple in tokens:
15087
type, value, start, end, line_text = quintuple
15088
if type not in skip:
15089
diff -r 137e45f15c0b Lib/lib2to3/pgen2/driver.py
15090
--- a/Lib/lib2to3/pgen2/driver.py
15091
+++ b/Lib/lib2to3/pgen2/driver.py
15100
@@ -101,18 +102,10 @@
15102
def parse_string(self, text, debug=False):
15103
"""Parse a string and return the syntax tree."""
15104
- tokens = tokenize.generate_tokens(generate_lines(text).__next__)
15105
+ tokens = tokenize.generate_tokens(io.StringIO(text).readline)
15106
return self.parse_tokens(tokens, debug)
15109
-def generate_lines(text):
15110
- """Generator that behaves like readline without using StringIO."""
15111
- for line in text.splitlines(True):
15117
def load_grammar(gt="Grammar.txt", gp=None,
15118
save=True, force=False, logger=None):
15119
"""Load the grammar (maybe from a pickle)."""
15120
diff -r 137e45f15c0b Lib/lib2to3/refactor.py
15121
--- a/Lib/lib2to3/refactor.py
15122
+++ b/Lib/lib2to3/refactor.py
15123
@@ -173,7 +173,8 @@
15125
class RefactoringTool(object):
15127
- _default_options = {"print_function" : False}
15128
+ _default_options = {"print_function" : False,
15129
+ "write_unchanged_files" : False}
15131
CLASS_PREFIX = "Fix" # The prefix for fixer classes
15132
FILE_PREFIX = "fix_" # The prefix for modules with a fixer within
15133
@@ -195,6 +196,10 @@
15134
self.grammar = pygram.python_grammar_no_print_statement
15136
self.grammar = pygram.python_grammar
15137
+ # When this is True, the refactor*() methods will call write_file() for
15138
+ # files processed even if they were not changed during refactoring. If
15139
+ # and only if the refactor method's write parameter was True.
15140
+ self.write_unchanged_files = self.options.get("write_unchanged_files")
15142
self.logger = logging.getLogger("RefactoringTool")
15143
self.fixer_log = []
15144
@@ -341,13 +346,13 @@
15146
self.log_debug("Refactoring doctests in %s", filename)
15147
output = self.refactor_docstring(input, filename)
15148
- if output != input:
15149
+ if self.write_unchanged_files or output != input:
15150
self.processed_file(output, filename, input, write, encoding)
15152
self.log_debug("No doctest changes in %s", filename)
15154
tree = self.refactor_string(input, filename)
15155
- if tree and tree.was_changed:
15156
+ if self.write_unchanged_files or (tree and tree.was_changed):
15157
# The [:-1] is to take off the \n we added earlier
15158
self.processed_file(str(tree)[:-1], filename,
15159
write=write, encoding=encoding)
15160
@@ -386,13 +391,13 @@
15162
self.log_debug("Refactoring doctests in stdin")
15163
output = self.refactor_docstring(input, "<stdin>")
15164
- if output != input:
15165
+ if self.write_unchanged_files or output != input:
15166
self.processed_file(output, "<stdin>", input)
15168
self.log_debug("No doctest changes in stdin")
15170
tree = self.refactor_string(input, "<stdin>")
15171
- if tree and tree.was_changed:
15172
+ if self.write_unchanged_files or (tree and tree.was_changed):
15173
self.processed_file(str(tree), "<stdin>", input)
15175
self.log_debug("No changes in stdin")
15176
@@ -502,7 +507,7 @@
15177
def processed_file(self, new_text, filename, old_text=None, write=False,
15180
- Called when a file has been refactored, and there are changes.
15181
+ Called when a file has been refactored and there may be changes.
15183
self.files.append(filename)
15184
if old_text is None:
15185
@@ -513,7 +518,8 @@
15186
self.print_output(old_text, new_text, filename, equal)
15188
self.log_debug("No changes to %s", filename)
15190
+ if not self.write_unchanged_files:
15193
self.write_file(new_text, filename, old_text, encoding)
15195
diff -r 137e45f15c0b Lib/lib2to3/tests/test_main.py
15196
--- a/Lib/lib2to3/tests/test_main.py
15197
+++ b/Lib/lib2to3/tests/test_main.py
15199
# -*- coding: utf-8 -*-
15213
from lib2to3 import main
15216
+TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
15217
+PY2_TEST_MODULE = os.path.join(TEST_DATA_DIR, "py2_test_grammar.py")
15220
class TestMain(unittest.TestCase):
15223
+ self.temp_dir = None # tearDown() will rmtree this directory if set.
15225
def tearDown(self):
15226
# Clean up logging configuration down by main.
15227
del logging.root.handlers[:]
15228
+ if self.temp_dir:
15229
+ shutil.rmtree(self.temp_dir)
15231
def run_2to3_capture(self, args, in_capture, out_capture, err_capture):
15232
save_stdin = sys.stdin
15234
self.assertTrue("-print 'nothing'" in output)
15235
self.assertTrue("WARNING: couldn't encode <stdin>'s diff for "
15236
"your terminal" in err.getvalue())
15238
+ def setup_test_source_trees(self):
15239
+ """Setup a test source tree and output destination tree."""
15240
+ self.temp_dir = tempfile.mkdtemp() # tearDown() cleans this up.
15241
+ self.py2_src_dir = os.path.join(self.temp_dir, "python2_project")
15242
+ self.py3_dest_dir = os.path.join(self.temp_dir, "python3_project")
15243
+ os.mkdir(self.py2_src_dir)
15244
+ os.mkdir(self.py3_dest_dir)
15245
+ # Turn it into a package with a few files.
15246
+ self.setup_files = []
15247
+ open(os.path.join(self.py2_src_dir, "__init__.py"), "w").close()
15248
+ self.setup_files.append("__init__.py")
15249
+ shutil.copy(PY2_TEST_MODULE, self.py2_src_dir)
15250
+ self.setup_files.append(os.path.basename(PY2_TEST_MODULE))
15251
+ self.trivial_py2_file = os.path.join(self.py2_src_dir, "trivial.py")
15252
+ self.init_py2_file = os.path.join(self.py2_src_dir, "__init__.py")
15253
+ with open(self.trivial_py2_file, "w") as trivial:
15254
+ trivial.write("print 'I need a simple conversion.'")
15255
+ self.setup_files.append("trivial.py")
15257
+ def test_filename_changing_on_output_single_dir(self):
15258
+ """2to3 a single directory with a new output dir and suffix."""
15259
+ self.setup_test_source_trees()
15260
+ out = io.StringIO()
15261
+ err = io.StringIO()
15263
+ ret = self.run_2to3_capture(
15264
+ ["-n", "--add-suffix", suffix, "--write-unchanged-files",
15265
+ "--no-diffs", "--output-dir",
15266
+ self.py3_dest_dir, self.py2_src_dir],
15267
+ io.StringIO(""), out, err)
15268
+ self.assertEqual(ret, 0)
15269
+ stderr = err.getvalue()
15270
+ self.assertIn(" implies -w.", stderr)
15272
+ "Output in %r will mirror the input directory %r layout" % (
15273
+ self.py3_dest_dir, self.py2_src_dir), stderr)
15274
+ self.assertEqual(set(name+suffix for name in self.setup_files),
15275
+ set(os.listdir(self.py3_dest_dir)))
15276
+ for name in self.setup_files:
15277
+ self.assertIn("Writing converted %s to %s" % (
15278
+ os.path.join(self.py2_src_dir, name),
15279
+ os.path.join(self.py3_dest_dir, name+suffix)), stderr)
15280
+ sep = re.escape(os.sep)
15281
+ self.assertRegex(
15282
+ stderr, r"No changes to .*/__init__\.py".replace("/", sep))
15283
+ self.assertNotRegex(
15284
+ stderr, r"No changes to .*/trivial\.py".replace("/", sep))
15286
+ def test_filename_changing_on_output_two_files(self):
15287
+ """2to3 two files in one directory with a new output dir."""
15288
+ self.setup_test_source_trees()
15289
+ err = io.StringIO()
15290
+ py2_files = [self.trivial_py2_file, self.init_py2_file]
15291
+ expected_files = set(os.path.basename(name) for name in py2_files)
15292
+ ret = self.run_2to3_capture(
15293
+ ["-n", "-w", "--write-unchanged-files",
15294
+ "--no-diffs", "--output-dir", self.py3_dest_dir] + py2_files,
15295
+ io.StringIO(""), io.StringIO(), err)
15296
+ self.assertEqual(ret, 0)
15297
+ stderr = err.getvalue()
15299
+ "Output in %r will mirror the input directory %r layout" % (
15300
+ self.py3_dest_dir, self.py2_src_dir), stderr)
15301
+ self.assertEqual(expected_files, set(os.listdir(self.py3_dest_dir)))
15303
+ def test_filename_changing_on_output_single_file(self):
15304
+ """2to3 a single file with a new output dir."""
15305
+ self.setup_test_source_trees()
15306
+ err = io.StringIO()
15307
+ ret = self.run_2to3_capture(
15308
+ ["-n", "-w", "--no-diffs", "--output-dir", self.py3_dest_dir,
15309
+ self.trivial_py2_file],
15310
+ io.StringIO(""), io.StringIO(), err)
15311
+ self.assertEqual(ret, 0)
15312
+ stderr = err.getvalue()
15314
+ "Output in %r will mirror the input directory %r layout" % (
15315
+ self.py3_dest_dir, self.py2_src_dir), stderr)
15316
+ self.assertEqual(set([os.path.basename(self.trivial_py2_file)]),
15317
+ set(os.listdir(self.py3_dest_dir)))
15320
+if __name__ == '__main__':
15322
diff -r 137e45f15c0b Lib/lib2to3/tests/test_parser.py
1403
from os.path import join
1404
from textwrap import dedent
1405
+from test.support import captured_stdout, check_warnings, run_unittest
1407
-from test.support import captured_stdout, check_warnings, run_unittest
1410
+ ZLIB_SUPPORT = True
1411
+except ImportError:
1412
+ ZLIB_SUPPORT = False
1415
from distutils.command.sdist import sdist, show_formats
1416
from distutils.core import Distribution
1419
# file GENERATED by distutils, do NOT edit
1426
somecode%(sep)sdoc.txt
1431
- ZLIB_SUPPORT = True
1432
-except ImportError:
1433
- ZLIB_SUPPORT = False
1436
class SDistTestCase(PyPIRCCommandTestCase):
1440
dist_folder = join(self.tmp_dir, 'dist')
1441
result = os.listdir(dist_folder)
1443
- self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'] )
1444
+ self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'])
1446
os.remove(join(dist_folder, 'fake-1.0.tar'))
1447
os.remove(join(dist_folder, 'fake-1.0.tar.gz'))
1448
@@ -180,11 +180,18 @@
1449
self.write_file((data_dir, 'data.dt'), '#')
1450
some_dir = join(self.tmp_dir, 'some')
1452
+ # make sure VCS directories are pruned (#14004)
1453
+ hg_dir = join(self.tmp_dir, '.hg')
1455
+ self.write_file((hg_dir, 'last-message.txt'), '#')
1456
+ # a buggy regex used to prevent this from working on windows (#6884)
1457
+ self.write_file((self.tmp_dir, 'buildout.cfg'), '#')
1458
self.write_file((self.tmp_dir, 'inroot.txt'), '#')
1459
self.write_file((some_dir, 'file.txt'), '#')
1460
self.write_file((some_dir, 'other_file.txt'), '#')
1462
dist.data_files = [('data', ['data/data.dt',
1467
@@ -214,15 +221,15 @@
1470
# making sure everything was added
1471
- self.assertEqual(len(content), 11)
1472
+ self.assertEqual(len(content), 12)
1474
# checking the MANIFEST
1475
f = open(join(self.tmp_dir, 'MANIFEST'))
1478
- self.assertEqual(manifest, MANIFEST % {'sep': os.sep})
1481
+ self.assertEqual(manifest, MANIFEST % {'sep': os.sep})
1483
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
1484
def test_metadata_check_option(self):
1486
# filling data_files by pointing files in package_data
1487
dist.package_data = {'somecode': ['*.txt']}
1488
self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
1489
+ cmd.formats = ['gztar']
1490
cmd.ensure_finalized()
1493
diff -r 7085403daf43 Lib/lib2to3/tests/test_parser.py
15323
1494
--- a/Lib/lib2to3/tests/test_parser.py
15324
1495
+++ b/Lib/lib2to3/tests/test_parser.py
15325
@@ -14,10 +14,21 @@
1498
from . import support
1499
from .support import driver, test_dir
1500
+from test.support import verbose
15327
1502
# Python imports
15331
1509
# Local imports
15332
1510
from lib2to3.pgen2 import tokenize
15333
from ..pgen2.parse import ParseError
15334
+from lib2to3.pygram import python_symbols as syms
15337
+class TestDriver(support.TestCase):
15339
+ def test_formfeed(self):
15340
+ s = """print 1\n\x0Cprint 2\n"""
15341
+ t = driver.parse_string(s)
15342
+ self.assertEqual(t.children[0].children[0].type, syms.print_stmt)
15343
+ self.assertEqual(t.children[1].children[0].type, syms.print_stmt)
15346
class GrammarTest(support.TestCase):
15347
@@ -147,19 +158,22 @@
15349
"""A cut-down version of pytree_idempotency.py."""
15352
+ @unittest.expectedFailure
15353
def test_all_project_files(self):
15354
for filepath in support.all_project_files():
15355
with open(filepath, "rb") as fp:
15356
encoding = tokenize.detect_encoding(fp.readline)[0]
15357
self.assertTrue(encoding is not None,
15358
"can't detect encoding for %s" % filepath)
15359
- with open(filepath, "r") as fp:
15360
+ with open(filepath, "r", encoding=encoding) as fp:
15362
- source = source.decode(encoding)
15363
- tree = driver.parse_string(source)
15365
+ tree = driver.parse_string(source)
15366
+ except ParseError as err:
15367
+ print('ParseError on file', filepath, err)
1511
@@ -171,10 +175,12 @@
1513
tree = driver.parse_string(source)
1514
except ParseError as err:
1515
- print('ParseError on file', filepath, err)
1517
+ warnings.warn('ParseError on file %s (%s)' % (filepath, err))
15369
1519
new = str(tree)
15371
- new = new.encode(encoding)
15372
if diff(filepath, new):
1520
- if diff(filepath, new):
1521
+ x = diff(filepath, new)
15373
1523
self.fail("Idempotency failed: %s" % filepath)
15375
@@ -202,14 +216,14 @@
15379
-def diff(fn, result, encoding):
15380
- f = open("@", "w")
15381
+def diff(fn, result):
15383
- f.write(result.encode(encoding))
15387
+ with open('@', 'w') as f:
15388
+ f.write(str(result))
1525
def test_extended_unpacking(self):
1527
driver.parse_string("(z, *y, w) = m\n")
1528
driver.parse_string("for *z, m in d: pass\n")
1531
class TestLiterals(GrammarTest):
1533
def validate(self, s):
1535
with open('@', 'w') as f:
1536
f.write(str(result))
15389
1537
fn = fn.replace('"', '\\"')
15390
return os.system('diff -u "%s" @' % fn)
1538
- return os.system('diff -u "%s" @' % fn)
1539
+ return subprocess.call(['diff', '-u', fn, '@'], stdout=(subprocess.DEVNULL if verbose < 1 else None))
15397
diff -r 137e45f15c0b Lib/lib2to3/tests/test_refactor.py
15398
--- a/Lib/lib2to3/tests/test_refactor.py
15399
+++ b/Lib/lib2to3/tests/test_refactor.py
15401
self.assertTrue(rt.driver.grammar is
15402
pygram.python_grammar_no_print_statement)
15404
+ def test_write_unchanged_files_option(self):
15406
+ self.assertFalse(rt.write_unchanged_files)
15407
+ rt = self.rt({"write_unchanged_files" : True})
15408
+ self.assertTrue(rt.write_unchanged_files)
15410
def test_fixer_loading_helpers(self):
15411
contents = ["explicit", "first", "last", "parrot", "preorder"]
15412
non_prefixed = refactor.get_all_fix_names("myfixes")
15413
@@ -176,7 +182,9 @@
15415
self.assertEqual(results, expected)
15417
- def check_file_refactoring(self, test_file, fixers=_2TO3_FIXERS):
15418
+ def check_file_refactoring(self, test_file, fixers=_2TO3_FIXERS,
15419
+ options=None, mock_log_debug=None,
15420
+ actually_write=True):
15421
tmpdir = tempfile.mkdtemp(prefix="2to3-test_refactor")
15422
self.addCleanup(shutil.rmtree, tmpdir)
15423
# make a copy of the tested file that we can write to
15424
@@ -189,11 +197,15 @@
15427
old_contents = read_file()
15428
- rt = self.rt(fixers=fixers)
15429
+ rt = self.rt(fixers=fixers, options=options)
15430
+ if mock_log_debug:
15431
+ rt.log_debug = mock_log_debug
15433
rt.refactor_file(test_file)
15434
self.assertEqual(old_contents, read_file())
15436
+ if not actually_write:
15438
rt.refactor_file(test_file, True)
15439
new_contents = read_file()
15440
self.assertNotEqual(old_contents, new_contents)
15441
@@ -203,6 +215,26 @@
15442
test_file = os.path.join(FIXER_DIR, "parrot_example.py")
15443
self.check_file_refactoring(test_file, _DEFAULT_FIXERS)
15445
+ def test_refactor_file_write_unchanged_file(self):
15446
+ test_file = os.path.join(FIXER_DIR, "parrot_example.py")
15447
+ debug_messages = []
15448
+ def recording_log_debug(msg, *args):
15449
+ debug_messages.append(msg % args)
15450
+ self.check_file_refactoring(test_file, fixers=(),
15451
+ options={"write_unchanged_files": True},
15452
+ mock_log_debug=recording_log_debug,
15453
+ actually_write=False)
15454
+ # Testing that it logged this message when write=False was passed is
15455
+ # sufficient to see that it did not bail early after "No changes".
15456
+ message_regex = r"Not writing changes to .*%s%s" % (
15457
+ os.sep, os.path.basename(test_file))
15458
+ for message in debug_messages:
15459
+ if "Not writing changes" in message:
15460
+ self.assertRegexpMatches(message, message_regex)
15463
+ self.fail("%r not matched in %r" % (message_regex, debug_messages))
15465
def test_refactor_dir(self):
15466
def check(structure, expected):
15467
def mock_refactor_file(self, f, *args):
15468
diff -r 137e45f15c0b Lib/locale.py
15469
--- a/Lib/locale.py
15470
+++ b/Lib/locale.py
15471
@@ -142,8 +142,6 @@
15472
grouping = conv[monetary and 'mon_grouping' or 'grouping']
15478
stripped = s.rstrip()
15479
right_spaces = s[len(stripped):]
15480
@@ -442,13 +440,17 @@
15481
No aliasing or normalizing takes place.
15484
- language, encoding = localetuple
15485
- if language is None:
15487
- if encoding is None:
15490
- return language + '.' + encoding
15492
+ language, encoding = localetuple
15494
+ if language is None:
15496
+ if encoding is None:
15499
+ return language + '.' + encoding
15500
+ except (TypeError, ValueError):
15501
+ raise TypeError('Locale must be None, a string, or an iterable of two strings -- language code, encoding.')
15503
def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
15505
@@ -524,9 +526,10 @@
15506
def setlocale(category, locale=None):
15508
""" Set the locale for the given category. The locale can be
15509
- a string, a locale tuple (language code, encoding), or None.
15510
+ a string, an iterable of two strings (language code and encoding),
15513
- Locale tuples are converted to strings the locale aliasing
15514
+ Iterables are converted to strings using the locale aliasing
15515
engine. Locale strings are passed directly to the C lib.
15517
category may be given as one of the LC_* values.
15518
@@ -1595,8 +1598,7 @@
15519
# to include every locale up to Windows Vista.
15521
# NOTE: this mapping is incomplete. If your language is missing, please
15522
-# submit a bug report to Python bug manager, which you can find via:
15523
-# http://www.python.org/dev/
15524
+# submit a bug report to the Python bug tracker at http://bugs.python.org/
15525
# Make sure you include the missing language identifier and the suggested
15528
diff -r 137e45f15c0b Lib/logging/__init__.py
1543
diff -r 7085403daf43 Lib/logging/__init__.py
15529
1544
--- a/Lib/logging/__init__.py
15530
1545
+++ b/Lib/logging/__init__.py
15533
if hasattr(sys, 'frozen'): #support for py2exe
15534
_srcfile = "logging%s__init__%s" % (os.sep, __file__[-4:])
15535
-elif __file__[-4:].lower() in ['.pyc', '.pyo']:
15536
- _srcfile = __file__[:-4] + '.py'
15538
_srcfile = __file__
15539
_srcfile = os.path.normcase(_srcfile)
15540
@@ -296,7 +294,7 @@
15543
self.processName = mp.current_process().name
15544
- except StandardError:
15545
+ except Exception:
15547
if logProcesses and hasattr(os, 'getpid'):
15548
self.process = os.getpid()
15549
@@ -883,7 +881,7 @@
15550
You could, however, replace this with a custom handler if you wish.
15551
The record which was being processed is passed in to this method.
15553
- if raiseExceptions:
15554
+ if raiseExceptions and sys.stderr: # see issue 13807
15555
ei = sys.exc_info()
15557
traceback.print_exception(ei[0], ei[1], ei[2],
15558
@@ -1096,6 +1094,8 @@
15559
placeholder to now point to the logger.
15562
+ if not isinstance(name, str):
15563
+ raise TypeError('A logger name must be a string')
15566
if name in self.loggerDict:
15567
diff -r 137e45f15c0b Lib/logging/config.py
15568
--- a/Lib/logging/config.py
15569
+++ b/Lib/logging/config.py
15570
@@ -471,7 +471,7 @@
15571
def configure_custom(self, config):
15572
"""Configure an object with a user-supplied factory."""
15573
c = config.pop('()')
15574
- if not hasattr(c, '__call__'):
15575
+ if not callable(c):
15576
c = self.resolve(c)
15577
props = config.pop('.', None)
15578
# Check for valid identifiers
15579
@@ -690,7 +690,7 @@
15580
filters = config.pop('filters', None)
15582
c = config.pop('()')
15583
- if not hasattr(c, '__call__') and hasattr(types, 'ClassType') and type(c) != types.ClassType:
15584
+ if not callable(c):
15585
c = self.resolve(c)
15588
diff -r 137e45f15c0b Lib/mailbox.py
15589
--- a/Lib/mailbox.py
15590
+++ b/Lib/mailbox.py
15591
@@ -273,11 +273,9 @@
15593
raise NoSuchMailboxError(self._path)
15595
- self._toc_mtimes = {}
15596
- for subdir in ('cur', 'new'):
15597
- self._toc_mtimes[subdir] = os.path.getmtime(self._paths[subdir])
15598
- self._last_read = time.time() # Records last time we read cur/new
15599
- self._skewfactor = 0.1 # Adjust if os/fs clocks are skewing
15600
+ self._toc_mtimes = {'cur': 0, 'new': 0}
15601
+ self._last_read = 0 # Records last time we read cur/new
15602
+ self._skewfactor = 0.1 # Adjust if os/fs clocks are skewing
15604
def add(self, message):
15605
"""Add message and return assigned key."""
15606
diff -r 137e45f15c0b Lib/mimetypes.py
15607
--- a/Lib/mimetypes.py
15608
+++ b/Lib/mimetypes.py
15609
@@ -199,7 +199,7 @@
15610
list of standard types, else to the list of non-standard
15613
- with open(filename) as fp:
15614
+ with open(filename, encoding='utf-8') as fp:
15615
self.readfp(fp, strict)
15617
def readfp(self, fp, strict=True):
15618
diff -r 137e45f15c0b Lib/msilib/schema.py
15619
--- a/Lib/msilib/schema.py
15620
+++ b/Lib/msilib/schema.py
15621
@@ -958,7 +958,7 @@
15622
('ServiceInstall','StartType','N',0,4,None, None, None, None, 'Type of the service',),
15623
('Shortcut','Name','N',None, None, None, None, 'Filename',None, 'The name of the shortcut to be created.',),
15624
('Shortcut','Description','Y',None, None, None, None, 'Text',None, 'The description for the shortcut.',),
15625
-('Shortcut','Component_','N',None, None, 'Component',1,'Identifier',None, 'Foreign key into the Component table denoting the component whose selection gates the the shortcut creation/deletion.',),
15626
+('Shortcut','Component_','N',None, None, 'Component',1,'Identifier',None, 'Foreign key into the Component table denoting the component whose selection gates the shortcut creation/deletion.',),
15627
('Shortcut','Icon_','Y',None, None, 'Icon',1,'Identifier',None, 'Foreign key into the File table denoting the external icon file for the shortcut.',),
15628
('Shortcut','IconIndex','Y',-32767,32767,None, None, None, None, 'The icon index for the shortcut.',),
15629
('Shortcut','Directory_','N',None, None, 'Directory',1,'Identifier',None, 'Foreign key into the Directory table denoting the directory where the shortcut file is created.',),
15630
diff -r 137e45f15c0b Lib/multiprocessing/__init__.py
15631
--- a/Lib/multiprocessing/__init__.py
15632
+++ b/Lib/multiprocessing/__init__.py
15634
# wrapper for 'threading'.
15636
# Try calling `multiprocessing.doc.main()` to read the html
15637
-# documentation in in a webbrowser.
15638
+# documentation in a webbrowser.
15641
# Copyright (c) 2006-2008, R Oudkerk
15642
diff -r 137e45f15c0b Lib/multiprocessing/connection.py
15643
--- a/Lib/multiprocessing/connection.py
15644
+++ b/Lib/multiprocessing/connection.py
15645
@@ -249,10 +249,14 @@
15647
def __init__(self, address, family, backlog=1):
15648
self._socket = socket.socket(getattr(socket, family))
15649
- self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
15650
- self._socket.bind(address)
15651
- self._socket.listen(backlog)
15652
- self._address = self._socket.getsockname()
15654
+ self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
15655
+ self._socket.bind(address)
15656
+ self._socket.listen(backlog)
15657
+ self._address = self._socket.getsockname()
15658
+ except socket.error:
15659
+ self._socket.close()
15661
self._family = family
15662
self._last_accepted = None
15664
diff -r 137e45f15c0b Lib/multiprocessing/forking.py
15665
--- a/Lib/multiprocessing/forking.py
15666
+++ b/Lib/multiprocessing/forking.py
15667
@@ -124,8 +124,6 @@
15670
code = process_obj._bootstrap()
15671
- sys.stdout.flush()
15672
- sys.stderr.flush()
15675
def poll(self, flag=os.WNOHANG):
15676
diff -r 137e45f15c0b Lib/multiprocessing/managers.py
15677
--- a/Lib/multiprocessing/managers.py
15678
+++ b/Lib/multiprocessing/managers.py
15679
@@ -134,7 +134,7 @@
15681
for name in dir(obj):
15682
func = getattr(obj, name)
15683
- if hasattr(func, '__call__'):
15684
+ if callable(func):
15688
@@ -162,7 +162,7 @@
15689
Listener, Client = listener_client[serializer]
15691
# do authentication later
15692
- self.listener = Listener(address=address, backlog=5)
15693
+ self.listener = Listener(address=address, backlog=16)
15694
self.address = self.listener.address
15696
self.id_to_obj = {'0': (None, ())}
15697
@@ -510,7 +510,7 @@
15699
assert self._state.value == State.INITIAL
15701
- if initializer is not None and not hasattr(initializer, '__call__'):
15702
+ if initializer is not None and not callable(initializer):
15703
raise TypeError('initializer must be a callable')
15705
# pipe over which we will retrieve address of server
15706
diff -r 137e45f15c0b Lib/multiprocessing/pool.py
15707
--- a/Lib/multiprocessing/pool.py
15708
+++ b/Lib/multiprocessing/pool.py
15709
@@ -151,7 +151,7 @@
15711
raise ValueError("Number of processes must be at least 1")
15713
- if initializer is not None and not hasattr(initializer, '__call__'):
15714
+ if initializer is not None and not callable(initializer):
15715
raise TypeError('initializer must be a callable')
15717
self._processes = processes
15718
@@ -321,7 +321,11 @@
15721
def _handle_workers(pool):
15722
- while pool._worker_handler._state == RUN and pool._state == RUN:
15723
+ thread = threading.current_thread()
15725
+ # Keep maintaining workers until the cache gets drained, unless the pool
15727
+ while thread._state == RUN or (pool._cache and thread._state != TERMINATE):
15728
pool._maintain_pool()
15730
# send sentinel to stop workers
15731
diff -r 137e45f15c0b Lib/multiprocessing/process.py
15732
--- a/Lib/multiprocessing/process.py
15733
+++ b/Lib/multiprocessing/process.py
15734
@@ -275,16 +275,17 @@
15735
exitcode = e.args[0]
15737
sys.stderr.write(e.args[0] + '\n')
15738
- sys.stderr.flush()
15743
sys.stderr.write('Process %s:\n' % self.name)
15744
+ traceback.print_exc()
15746
+ util.info('process exiting with exitcode %d' % exitcode)
15747
+ sys.stdout.flush()
15749
- traceback.print_exc()
15751
- util.info('process exiting with exitcode %d' % exitcode)
15755
diff -r 137e45f15c0b Lib/multiprocessing/queues.py
15756
--- a/Lib/multiprocessing/queues.py
15757
+++ b/Lib/multiprocessing/queues.py
15758
@@ -126,7 +126,11 @@
15759
if not self._rlock.acquire(block, timeout):
15762
- if not self._poll(block and (deadline-time.time()) or 0.0):
15764
+ timeout = deadline - time.time()
15765
+ if timeout < 0 or not self._poll(timeout):
15767
+ elif not self._poll():
15770
self._sem.release()
15771
diff -r 137e45f15c0b Lib/nntplib.py
15772
--- a/Lib/nntplib.py
15773
+++ b/Lib/nntplib.py
15774
@@ -324,25 +324,30 @@
15776
self.welcome = self._getresp()
15778
+ # Inquire about capabilities (RFC 3977).
15779
+ self._caps = None
15780
+ self.getcapabilities()
15782
# 'MODE READER' is sometimes necessary to enable 'reader' mode.
15783
# However, the order in which 'MODE READER' and 'AUTHINFO' need to
15784
# arrive differs between some NNTP servers. If _setreadermode() fails
15785
# with an authorization failed error, it will set this to True;
15786
# the login() routine will interpret that as a request to try again
15787
# after performing its normal function.
15788
+ # Enable only if we're not already in READER mode anyway.
15789
self.readermode_afterauth = False
15791
+ if readermode and 'READER' not in self._caps:
15792
self._setreadermode()
15793
+ if not self.readermode_afterauth:
15794
+ # Capabilities might have changed after MODE READER
15795
+ self._caps = None
15796
+ self.getcapabilities()
15798
# RFC 4642 2.2.2: Both the client and the server MUST know if there is
15799
# a TLS session active. A client MUST NOT attempt to start a TLS
15800
# session if a TLS session is already active.
15801
self.tls_on = False
15803
- # Inquire about capabilities (RFC 3977).
15804
- self._caps = None
15805
- self.getcapabilities()
15807
# Log in and encryption setup order is left to subclasses.
15808
self.authenticated = False
15810
@@ -364,7 +369,7 @@
15811
self.nntp_implementation = None
15813
resp, caps = self.capabilities()
15814
- except NNTPPermanentError:
15815
+ except (NNTPPermanentError, NNTPTemporaryError):
15816
# Server doesn't support capabilities
15819
@@ -941,9 +946,16 @@
15820
resp = self._shortcmd('authinfo pass ' + password)
15821
if not resp.startswith('281'):
15822
raise NNTPPermanentError(resp)
15823
+ # Capabilities might have changed after login
15824
+ self._caps = None
15825
+ self.getcapabilities()
15826
# Attempt to send mode reader if it was requested after login.
15827
- if self.readermode_afterauth:
15828
+ # Only do so if we're not in reader mode already.
15829
+ if self.readermode_afterauth and 'READER' not in self._caps:
15830
self._setreadermode()
15831
+ # Capabilities might have changed after MODE READER
15832
+ self._caps = None
15833
+ self.getcapabilities()
15835
def _setreadermode(self):
15837
diff -r 137e45f15c0b Lib/numbers.py
15838
--- a/Lib/numbers.py
15839
+++ b/Lib/numbers.py
15840
@@ -303,7 +303,7 @@
15841
raise NotImplementedError
15843
def __index__(self):
15844
- """someobject[self]"""
15845
+ """Called whenever an index is needed, such as in slicing"""
15849
diff -r 137e45f15c0b Lib/optparse.py
15850
--- a/Lib/optparse.py
15851
+++ b/Lib/optparse.py
15852
@@ -705,7 +705,7 @@
15854
def _check_callback(self):
15855
if self.action == "callback":
15856
- if not hasattr(self.callback, '__call__'):
15857
+ if not callable(self.callback):
15859
"callback not callable: %r" % self.callback, self)
15860
if (self.callback_args is not None and
15861
diff -r 137e45f15c0b Lib/pickle.py
15862
--- a/Lib/pickle.py
15863
+++ b/Lib/pickle.py
15864
@@ -299,20 +299,20 @@
15865
f(self, obj) # Call unbound method with explicit self
15868
- # Check for a class with a custom metaclass; treat as regular class
15870
- issc = issubclass(t, type)
15871
- except TypeError: # t is not a class (old Boost; see SF #502085)
15874
- self.save_global(obj)
15877
# Check copyreg.dispatch_table
15878
reduce = dispatch_table.get(t)
15882
+ # Check for a class with a custom metaclass; treat as regular class
15884
+ issc = issubclass(t, type)
15885
+ except TypeError: # t is not a class (old Boost; see SF #502085)
15888
+ self.save_global(obj)
15891
# Check for a __reduce_ex__ method, fall back to __reduce__
15892
reduce = getattr(obj, "__reduce_ex__", None)
15894
@@ -364,7 +364,7 @@
15895
raise PicklingError("args from save_reduce() should be a tuple")
15897
# Assert that func is callable
15898
- if not hasattr(func, '__call__'):
15899
+ if not callable(func):
15900
raise PicklingError("func from save_reduce() should be callable")
15903
@@ -487,7 +487,11 @@
15905
def save_bytes(self, obj, pack=struct.pack):
15907
- self.save_reduce(bytes, (list(obj),), obj=obj)
15908
+ if len(obj) == 0:
15909
+ self.save_reduce(bytes, (), obj=obj)
15911
+ self.save_reduce(codecs.encode,
15912
+ (str(obj, 'latin1'), 'latin1'), obj=obj)
15916
@@ -1156,16 +1160,22 @@
15918
def load_put(self):
15919
i = int(self.readline()[:-1])
15921
+ raise ValueError("negative PUT argument")
15922
self.memo[i] = self.stack[-1]
15923
dispatch[PUT[0]] = load_put
15925
def load_binput(self):
15926
i = self.read(1)[0]
15928
+ raise ValueError("negative BINPUT argument")
15929
self.memo[i] = self.stack[-1]
15930
dispatch[BINPUT[0]] = load_binput
15932
def load_long_binput(self):
15933
i = mloads(b'i' + self.read(4))
15935
+ raise ValueError("negative LONG_BINPUT argument")
15936
self.memo[i] = self.stack[-1]
15937
dispatch[LONG_BINPUT[0]] = load_long_binput
15939
diff -r 137e45f15c0b Lib/pickletools.py
15940
--- a/Lib/pickletools.py
15941
+++ b/Lib/pickletools.py
15942
@@ -2083,27 +2083,22 @@
15944
30: d DICT (MARK at 29)
15946
- 34: c GLOBAL '__builtin__ bytes'
15950
- 58: l LIST (MARK at 57)
15951
+ 34: c GLOBAL '_codecs encode'
15954
+ 54: V UNICODE 'abc'
15962
- 80: t TUPLE (MARK at 56)
15966
- 88: V UNICODE 'def'
15971
+ 62: V UNICODE 'latin1'
15973
+ 73: t TUPLE (MARK at 53)
15977
+ 81: V UNICODE 'def'
15982
highest protocol among opcodes = 0
15984
Try again with a "binary" pickle.
15985
@@ -2122,25 +2117,22 @@
15989
- 19: c GLOBAL '__builtin__ bytes'
15998
- 51: e APPENDS (MARK at 44)
15999
- 52: t TUPLE (MARK at 40)
16003
- 58: X BINUNICODE 'def'
16006
- 69: e APPENDS (MARK at 3)
16008
+ 19: c GLOBAL '_codecs encode'
16011
+ 38: X BINUNICODE 'abc'
16013
+ 48: X BINUNICODE 'latin1'
16015
+ 61: t TUPLE (MARK at 37)
16019
+ 67: X BINUNICODE 'def'
16022
+ 78: e APPENDS (MARK at 3)
16024
highest protocol among opcodes = 1
16026
Exercise the INST/OBJ/BUILD family.
16027
diff -r 137e45f15c0b Lib/pipes.py
16032
To create a new template object initialized to a given one:
16035
-For an example, see the function test() at the end of the file.
16039
diff -r 137e45f15c0b Lib/pkgutil.py
16040
--- a/Lib/pkgutil.py
16041
+++ b/Lib/pkgutil.py
16042
@@ -191,8 +191,11 @@
16047
- filenames = os.listdir(self.path)
16049
+ filenames = os.listdir(self.path)
16051
+ # ignore unreadable directories like import does
16053
filenames.sort() # handle packages before same-named modules
16055
for fn in filenames:
16056
@@ -205,7 +208,12 @@
16058
if not modname and os.path.isdir(path) and '.' not in fn:
16060
- for fn in os.listdir(path):
16062
+ dircontents = os.listdir(path)
16064
+ # ignore unreadable directories like import does
16066
+ for fn in dircontents:
16067
subname = inspect.getmodulename(fn)
16068
if subname=='__init__':
16070
diff -r 137e45f15c0b Lib/plat-linux3/CDROM.py
16071
--- a/Lib/plat-linux3/CDROM.py
16074
-# Generated by h2py from /usr/include/linux/cdrom.h
16076
-CDROMPAUSE = 0x5301
16077
-CDROMRESUME = 0x5302
16078
-CDROMPLAYMSF = 0x5303
16079
-CDROMPLAYTRKIND = 0x5304
16080
-CDROMREADTOCHDR = 0x5305
16081
-CDROMREADTOCENTRY = 0x5306
16082
-CDROMSTOP = 0x5307
16083
-CDROMSTART = 0x5308
16084
-CDROMEJECT = 0x5309
16085
-CDROMVOLCTRL = 0x530a
16086
-CDROMSUBCHNL = 0x530b
16087
-CDROMREADMODE2 = 0x530c
16088
-CDROMREADMODE1 = 0x530d
16089
-CDROMREADAUDIO = 0x530e
16090
-CDROMEJECT_SW = 0x530f
16091
-CDROMMULTISESSION = 0x5310
16092
-CDROM_GET_MCN = 0x5311
16093
-CDROM_GET_UPC = CDROM_GET_MCN
16094
-CDROMRESET = 0x5312
16095
-CDROMVOLREAD = 0x5313
16096
-CDROMREADRAW = 0x5314
16097
-CDROMREADCOOKED = 0x5315
16098
-CDROMSEEK = 0x5316
16099
-CDROMPLAYBLK = 0x5317
16100
-CDROMREADALL = 0x5318
16101
-CDROMGETSPINDOWN = 0x531d
16102
-CDROMSETSPINDOWN = 0x531e
16103
-CDROMCLOSETRAY = 0x5319
16104
-CDROM_SET_OPTIONS = 0x5320
16105
-CDROM_CLEAR_OPTIONS = 0x5321
16106
-CDROM_SELECT_SPEED = 0x5322
16107
-CDROM_SELECT_DISC = 0x5323
16108
-CDROM_MEDIA_CHANGED = 0x5325
16109
-CDROM_DRIVE_STATUS = 0x5326
16110
-CDROM_DISC_STATUS = 0x5327
16111
-CDROM_CHANGER_NSLOTS = 0x5328
16112
-CDROM_LOCKDOOR = 0x5329
16113
-CDROM_DEBUG = 0x5330
16114
-CDROM_GET_CAPABILITY = 0x5331
16115
-CDROMAUDIOBUFSIZ = 0x5382
16116
-DVD_READ_STRUCT = 0x5390
16117
-DVD_WRITE_STRUCT = 0x5391
16119
-CDROM_SEND_PACKET = 0x5393
16120
-CDROM_NEXT_WRITABLE = 0x5394
16121
-CDROM_LAST_WRITTEN = 0x5395
16122
-CDROM_PACKET_SIZE = 12
16123
-CGC_DATA_UNKNOWN = 0
16124
-CGC_DATA_WRITE = 1
16131
-CD_MSF_OFFSET = 150
16132
-CD_CHUNK_SIZE = 24
16133
-CD_NUM_OF_CHUNKS = 98
16134
-CD_FRAMESIZE_SUB = 96
16136
-CD_SUBHEAD_SIZE = 8
16140
-CD_FRAMESIZE = 2048
16141
-CD_FRAMESIZE_RAW = 2352
16142
-CD_FRAMESIZE_RAWER = 2646
16143
-CD_FRAMESIZE_RAW1 = (CD_FRAMESIZE_RAW-CD_SYNC_SIZE)
16144
-CD_FRAMESIZE_RAW0 = (CD_FRAMESIZE_RAW-CD_SYNC_SIZE-CD_HEAD_SIZE)
16145
-CD_XA_HEAD = (CD_HEAD_SIZE+CD_SUBHEAD_SIZE)
16146
-CD_XA_TAIL = (CD_EDC_SIZE+CD_ECC_SIZE)
16147
-CD_XA_SYNC_HEAD = (CD_SYNC_SIZE+CD_XA_HEAD)
16150
-CDROM_DATA_TRACK = 0x04
16151
-CDROM_LEADOUT = 0xAA
16152
-CDROM_AUDIO_INVALID = 0x00
16153
-CDROM_AUDIO_PLAY = 0x11
16154
-CDROM_AUDIO_PAUSED = 0x12
16155
-CDROM_AUDIO_COMPLETED = 0x13
16156
-CDROM_AUDIO_ERROR = 0x14
16157
-CDROM_AUDIO_NO_STATUS = 0x15
16158
-CDC_CLOSE_TRAY = 0x1
16159
-CDC_OPEN_TRAY = 0x2
16161
-CDC_SELECT_SPEED = 0x8
16162
-CDC_SELECT_DISC = 0x10
16163
-CDC_MULTI_SESSION = 0x20
16165
-CDC_MEDIA_CHANGED = 0x80
16166
-CDC_PLAY_AUDIO = 0x100
16168
-CDC_IOCTLS = 0x400
16169
-CDC_DRIVE_STATUS = 0x800
16170
-CDC_GENERIC_PACKET = 0x1000
16172
-CDC_CD_RW = 0x4000
16174
-CDC_DVD_R = 0x10000
16175
-CDC_DVD_RAM = 0x20000
16179
-CDS_DRIVE_NOT_READY = 3
16187
-CDO_AUTO_CLOSE = 0x1
16188
-CDO_AUTO_EJECT = 0x2
16189
-CDO_USE_FFLAGS = 0x4
16191
-CDO_CHECK_TYPE = 0x10
16193
-CD_PART_MASK = (CD_PART_MAX - 1)
16194
-GPCMD_BLANK = 0xa1
16195
-GPCMD_CLOSE_TRACK = 0x5b
16196
-GPCMD_FLUSH_CACHE = 0x35
16197
-GPCMD_FORMAT_UNIT = 0x04
16198
-GPCMD_GET_CONFIGURATION = 0x46
16199
-GPCMD_GET_EVENT_STATUS_NOTIFICATION = 0x4a
16200
-GPCMD_GET_PERFORMANCE = 0xac
16201
-GPCMD_INQUIRY = 0x12
16202
-GPCMD_LOAD_UNLOAD = 0xa6
16203
-GPCMD_MECHANISM_STATUS = 0xbd
16204
-GPCMD_MODE_SELECT_10 = 0x55
16205
-GPCMD_MODE_SENSE_10 = 0x5a
16206
-GPCMD_PAUSE_RESUME = 0x4b
16207
-GPCMD_PLAY_AUDIO_10 = 0x45
16208
-GPCMD_PLAY_AUDIO_MSF = 0x47
16209
-GPCMD_PLAY_AUDIO_TI = 0x48
16210
-GPCMD_PLAY_CD = 0xbc
16211
-GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1e
16212
-GPCMD_READ_10 = 0x28
16213
-GPCMD_READ_12 = 0xa8
16214
-GPCMD_READ_CDVD_CAPACITY = 0x25
16215
-GPCMD_READ_CD = 0xbe
16216
-GPCMD_READ_CD_MSF = 0xb9
16217
-GPCMD_READ_DISC_INFO = 0x51
16218
-GPCMD_READ_DVD_STRUCTURE = 0xad
16219
-GPCMD_READ_FORMAT_CAPACITIES = 0x23
16220
-GPCMD_READ_HEADER = 0x44
16221
-GPCMD_READ_TRACK_RZONE_INFO = 0x52
16222
-GPCMD_READ_SUBCHANNEL = 0x42
16223
-GPCMD_READ_TOC_PMA_ATIP = 0x43
16224
-GPCMD_REPAIR_RZONE_TRACK = 0x58
16225
-GPCMD_REPORT_KEY = 0xa4
16226
-GPCMD_REQUEST_SENSE = 0x03
16227
-GPCMD_RESERVE_RZONE_TRACK = 0x53
16230
-GPCMD_SEND_DVD_STRUCTURE = 0xad
16231
-GPCMD_SEND_EVENT = 0xa2
16232
-GPCMD_SEND_KEY = 0xa3
16233
-GPCMD_SEND_OPC = 0x54
16234
-GPCMD_SET_READ_AHEAD = 0xa7
16235
-GPCMD_SET_STREAMING = 0xb6
16236
-GPCMD_START_STOP_UNIT = 0x1b
16237
-GPCMD_STOP_PLAY_SCAN = 0x4e
16238
-GPCMD_TEST_UNIT_READY = 0x00
16239
-GPCMD_VERIFY_10 = 0x2f
16240
-GPCMD_WRITE_10 = 0x2a
16241
-GPCMD_WRITE_AND_VERIFY_10 = 0x2e
16242
-GPCMD_SET_SPEED = 0xbb
16243
-GPCMD_PLAYAUDIO_TI = 0x48
16244
-GPCMD_GET_MEDIA_STATUS = 0xda
16245
-GPMODE_R_W_ERROR_PAGE = 0x01
16246
-GPMODE_WRITE_PARMS_PAGE = 0x05
16247
-GPMODE_AUDIO_CTL_PAGE = 0x0e
16248
-GPMODE_POWER_PAGE = 0x1a
16249
-GPMODE_FAULT_FAIL_PAGE = 0x1c
16250
-GPMODE_TO_PROTECT_PAGE = 0x1d
16251
-GPMODE_CAPABILITIES_PAGE = 0x2a
16252
-GPMODE_ALL_PAGES = 0x3f
16253
-GPMODE_CDROM_PAGE = 0x0d
16254
-DVD_STRUCT_PHYSICAL = 0x00
16255
-DVD_STRUCT_COPYRIGHT = 0x01
16256
-DVD_STRUCT_DISCKEY = 0x02
16257
-DVD_STRUCT_BCA = 0x03
16258
-DVD_STRUCT_MANUFACT = 0x04
16260
-DVD_LU_SEND_AGID = 0
16261
-DVD_HOST_SEND_CHALLENGE = 1
16262
-DVD_LU_SEND_KEY1 = 2
16263
-DVD_LU_SEND_CHALLENGE = 3
16264
-DVD_HOST_SEND_KEY2 = 4
16265
-DVD_AUTH_ESTABLISHED = 5
16266
-DVD_AUTH_FAILURE = 6
16267
-DVD_LU_SEND_TITLE_KEY = 7
16268
-DVD_LU_SEND_ASF = 8
16269
-DVD_INVALIDATE_AGID = 9
16270
-DVD_LU_SEND_RPC_STATE = 10
16271
-DVD_HOST_SEND_RPC_STATE = 11
16272
-DVD_CPM_NO_COPYRIGHT = 0
16273
-DVD_CPM_COPYRIGHTED = 1
16274
-DVD_CP_SEC_NONE = 0
16275
-DVD_CP_SEC_EXIST = 1
16276
-DVD_CGMS_UNRESTRICTED = 0
16277
-DVD_CGMS_SINGLE = 2
16278
-DVD_CGMS_RESTRICTED = 3
16280
-CDROM_MAX_SLOTS = 256
16281
diff -r 137e45f15c0b Lib/plat-linux3/DLFCN.py
16282
--- a/Lib/plat-linux3/DLFCN.py
16285
-# Generated by h2py from /usr/include/dlfcn.h
16288
-# Included from features.h
16292
-_ISOC99_SOURCE = 1
16294
-_POSIX_C_SOURCE = 199506
16295
-_XOPEN_SOURCE = 600
16296
-_XOPEN_SOURCE_EXTENDED = 1
16297
-_LARGEFILE64_SOURCE = 1
16304
-_POSIX_C_SOURCE = 2
16305
-_POSIX_C_SOURCE = 199506
16308
-__USE_POSIX199309 = 1
16309
-__USE_POSIX199506 = 1
16311
-__USE_XOPEN_EXTENDED = 1
16313
-_LARGEFILE_SOURCE = 1
16316
-__USE_XOPEN_EXTENDED = 1
16317
-__USE_LARGEFILE = 1
16318
-__USE_LARGEFILE64 = 1
16319
-__USE_FILE_OFFSET64 = 1
16324
-__USE_REENTRANT = 1
16325
-__STDC_IEC_559__ = 1
16326
-__STDC_IEC_559_COMPLEX__ = 1
16327
-__STDC_ISO_10646__ = 200009
16328
-__GNU_LIBRARY__ = 6
16330
-__GLIBC_MINOR__ = 2
16332
-# Included from sys/cdefs.h
16334
-def __PMT(args): return args
16336
-def __P(args): return args
16338
-def __PMT(args): return args
16340
-def __STRING(x): return #x
16346
-def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
16348
-def __attribute__(xyz): return
16350
-def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x)))
16352
-def __attribute_format_arg__(x): return
16354
-__USE_LARGEFILE = 1
16355
-__USE_LARGEFILE64 = 1
16356
-__USE_EXTERN_INLINES = 1
16358
-# Included from gnu/stubs.h
16360
-# Included from bits/dlfcn.h
16361
-RTLD_LAZY = 0x00001
16362
-RTLD_NOW = 0x00002
16363
-RTLD_BINDING_MASK = 0x3
16364
-RTLD_NOLOAD = 0x00004
16365
-RTLD_GLOBAL = 0x00100
16367
-RTLD_NODELETE = 0x01000
16368
diff -r 137e45f15c0b Lib/plat-linux3/IN.py
16369
--- a/Lib/plat-linux3/IN.py
16372
-# Generated by h2py from /usr/include/netinet/in.h
16375
-# Included from features.h
16379
-_ISOC99_SOURCE = 1
16381
-_POSIX_C_SOURCE = 199506
16382
-_XOPEN_SOURCE = 600
16383
-_XOPEN_SOURCE_EXTENDED = 1
16384
-_LARGEFILE64_SOURCE = 1
16391
-_POSIX_C_SOURCE = 2
16392
-_POSIX_C_SOURCE = 199506
16395
-__USE_POSIX199309 = 1
16396
-__USE_POSIX199506 = 1
16398
-__USE_XOPEN_EXTENDED = 1
16400
-_LARGEFILE_SOURCE = 1
16403
-__USE_XOPEN_EXTENDED = 1
16404
-__USE_LARGEFILE = 1
16405
-__USE_LARGEFILE64 = 1
16406
-__USE_FILE_OFFSET64 = 1
16411
-__USE_REENTRANT = 1
16412
-__STDC_IEC_559__ = 1
16413
-__STDC_IEC_559_COMPLEX__ = 1
16414
-__STDC_ISO_10646__ = 200009
16415
-__GNU_LIBRARY__ = 6
16417
-__GLIBC_MINOR__ = 2
16419
-# Included from sys/cdefs.h
16421
-def __PMT(args): return args
16423
-def __P(args): return args
16425
-def __PMT(args): return args
16427
-def __STRING(x): return #x
16433
-def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
16435
-def __attribute__(xyz): return
16437
-def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x)))
16439
-def __attribute_format_arg__(x): return
16441
-__USE_LARGEFILE = 1
16442
-__USE_LARGEFILE64 = 1
16443
-__USE_EXTERN_INLINES = 1
16445
-# Included from gnu/stubs.h
16447
-# Included from stdint.h
16450
-# Included from bits/wchar.h
16452
-__WCHAR_MIN = (-2147483647 - 1)
16453
-__WCHAR_MAX = (2147483647)
16455
-# Included from bits/wordsize.h
16457
-def __INT64_C(c): return c ## L
16459
-def __UINT64_C(c): return c ## UL
16461
-def __INT64_C(c): return c ## LL
16463
-def __UINT64_C(c): return c ## ULL
16466
-INT16_MIN = (-32767-1)
16467
-INT32_MIN = (-2147483647-1)
16468
-INT64_MIN = (-__INT64_C(9223372036854775807)-1)
16470
-INT16_MAX = (32767)
16471
-INT32_MAX = (2147483647)
16472
-INT64_MAX = (__INT64_C(9223372036854775807))
16474
-UINT16_MAX = (65535)
16475
-UINT64_MAX = (__UINT64_C(18446744073709551615))
16476
-INT_LEAST8_MIN = (-128)
16477
-INT_LEAST16_MIN = (-32767-1)
16478
-INT_LEAST32_MIN = (-2147483647-1)
16479
-INT_LEAST64_MIN = (-__INT64_C(9223372036854775807)-1)
16480
-INT_LEAST8_MAX = (127)
16481
-INT_LEAST16_MAX = (32767)
16482
-INT_LEAST32_MAX = (2147483647)
16483
-INT_LEAST64_MAX = (__INT64_C(9223372036854775807))
16484
-UINT_LEAST8_MAX = (255)
16485
-UINT_LEAST16_MAX = (65535)
16486
-UINT_LEAST64_MAX = (__UINT64_C(18446744073709551615))
16487
-INT_FAST8_MIN = (-128)
16488
-INT_FAST16_MIN = (-9223372036854775807-1)
16489
-INT_FAST32_MIN = (-9223372036854775807-1)
16490
-INT_FAST16_MIN = (-2147483647-1)
16491
-INT_FAST32_MIN = (-2147483647-1)
16492
-INT_FAST64_MIN = (-__INT64_C(9223372036854775807)-1)
16493
-INT_FAST8_MAX = (127)
16494
-INT_FAST16_MAX = (9223372036854775807)
16495
-INT_FAST32_MAX = (9223372036854775807)
16496
-INT_FAST16_MAX = (2147483647)
16497
-INT_FAST32_MAX = (2147483647)
16498
-INT_FAST64_MAX = (__INT64_C(9223372036854775807))
16499
-UINT_FAST8_MAX = (255)
16500
-UINT_FAST64_MAX = (__UINT64_C(18446744073709551615))
16501
-INTPTR_MIN = (-9223372036854775807-1)
16502
-INTPTR_MAX = (9223372036854775807)
16503
-INTPTR_MIN = (-2147483647-1)
16504
-INTPTR_MAX = (2147483647)
16505
-INTMAX_MIN = (-__INT64_C(9223372036854775807)-1)
16506
-INTMAX_MAX = (__INT64_C(9223372036854775807))
16507
-UINTMAX_MAX = (__UINT64_C(18446744073709551615))
16508
-PTRDIFF_MIN = (-9223372036854775807-1)
16509
-PTRDIFF_MAX = (9223372036854775807)
16510
-PTRDIFF_MIN = (-2147483647-1)
16511
-PTRDIFF_MAX = (2147483647)
16512
-SIG_ATOMIC_MIN = (-2147483647-1)
16513
-SIG_ATOMIC_MAX = (2147483647)
16514
-WCHAR_MIN = __WCHAR_MIN
16515
-WCHAR_MAX = __WCHAR_MAX
16516
-def INT8_C(c): return c
16518
-def INT16_C(c): return c
16520
-def INT32_C(c): return c
16522
-def INT64_C(c): return c ## L
16524
-def INT64_C(c): return c ## LL
16526
-def UINT8_C(c): return c ## U
16528
-def UINT16_C(c): return c ## U
16530
-def UINT32_C(c): return c ## U
16532
-def UINT64_C(c): return c ## UL
16534
-def UINT64_C(c): return c ## ULL
16536
-def INTMAX_C(c): return c ## L
16538
-def UINTMAX_C(c): return c ## UL
16540
-def INTMAX_C(c): return c ## LL
16542
-def UINTMAX_C(c): return c ## ULL
16545
-# Included from bits/types.h
16547
-__FD_SETSIZE = 1024
16549
-# Included from bits/pthreadtypes.h
16550
-_BITS_PTHREADTYPES_H = 1
16552
-# Included from bits/sched.h
16556
-CSIGNAL = 0x000000ff
16557
-CLONE_VM = 0x00000100
16558
-CLONE_FS = 0x00000200
16559
-CLONE_FILES = 0x00000400
16560
-CLONE_SIGHAND = 0x00000800
16561
-CLONE_PID = 0x00001000
16562
-CLONE_PTRACE = 0x00002000
16563
-CLONE_VFORK = 0x00004000
16564
-__defined_schedparam = 1
16565
-def IN_CLASSA(a): return ((((in_addr_t)(a)) & (-2147483648)) == 0)
16567
-IN_CLASSA_NET = (-16777216)
16568
-IN_CLASSA_NSHIFT = 24
16569
-IN_CLASSA_HOST = ((-1) & ~IN_CLASSA_NET)
16570
-IN_CLASSA_MAX = 128
16571
-def IN_CLASSB(a): return ((((in_addr_t)(a)) & (-1073741824)) == (-2147483648))
16573
-IN_CLASSB_NET = (-65536)
16574
-IN_CLASSB_NSHIFT = 16
16575
-IN_CLASSB_HOST = ((-1) & ~IN_CLASSB_NET)
16576
-IN_CLASSB_MAX = 65536
16577
-def IN_CLASSC(a): return ((((in_addr_t)(a)) & (-536870912)) == (-1073741824))
16579
-IN_CLASSC_NET = (-256)
16580
-IN_CLASSC_NSHIFT = 8
16581
-IN_CLASSC_HOST = ((-1) & ~IN_CLASSC_NET)
16582
-def IN_CLASSD(a): return ((((in_addr_t)(a)) & (-268435456)) == (-536870912))
16584
-def IN_MULTICAST(a): return IN_CLASSD(a)
16586
-def IN_EXPERIMENTAL(a): return ((((in_addr_t)(a)) & (-536870912)) == (-536870912))
16588
-def IN_BADCLASS(a): return ((((in_addr_t)(a)) & (-268435456)) == (-268435456))
16590
-IN_LOOPBACKNET = 127
16591
-INET_ADDRSTRLEN = 16
16592
-INET6_ADDRSTRLEN = 46
16594
-# Included from bits/socket.h
16596
-# Included from limits.h
16597
-_LIBC_LIMITS_H_ = 1
16601
-SCHAR_MIN = (-128)
16605
-CHAR_MAX = UCHAR_MAX
16606
-CHAR_MIN = SCHAR_MIN
16607
-CHAR_MAX = SCHAR_MAX
16608
-SHRT_MIN = (-32768)
16611
-INT_MAX = 2147483647
16612
-LONG_MAX = 9223372036854775807
16613
-LONG_MAX = 2147483647
16614
-LONG_MIN = (-LONG_MAX - 1)
16616
-# Included from bits/posix1_lim.h
16617
-_BITS_POSIX1_LIM_H = 1
16618
-_POSIX_AIO_LISTIO_MAX = 2
16619
-_POSIX_AIO_MAX = 1
16620
-_POSIX_ARG_MAX = 4096
16621
-_POSIX_CHILD_MAX = 6
16622
-_POSIX_DELAYTIMER_MAX = 32
16623
-_POSIX_LINK_MAX = 8
16624
-_POSIX_MAX_CANON = 255
16625
-_POSIX_MAX_INPUT = 255
16626
-_POSIX_MQ_OPEN_MAX = 8
16627
-_POSIX_MQ_PRIO_MAX = 32
16628
-_POSIX_NGROUPS_MAX = 0
16629
-_POSIX_OPEN_MAX = 16
16630
-_POSIX_FD_SETSIZE = _POSIX_OPEN_MAX
16631
-_POSIX_NAME_MAX = 14
16632
-_POSIX_PATH_MAX = 256
16633
-_POSIX_PIPE_BUF = 512
16634
-_POSIX_RTSIG_MAX = 8
16635
-_POSIX_SEM_NSEMS_MAX = 256
16636
-_POSIX_SEM_VALUE_MAX = 32767
16637
-_POSIX_SIGQUEUE_MAX = 32
16638
-_POSIX_SSIZE_MAX = 32767
16639
-_POSIX_STREAM_MAX = 8
16640
-_POSIX_TZNAME_MAX = 6
16642
-_POSIX_HIWAT = _POSIX_PIPE_BUF
16643
-_POSIX_UIO_MAXIOV = 16
16644
-_POSIX_TTY_NAME_MAX = 9
16645
-_POSIX_TIMER_MAX = 32
16646
-_POSIX_LOGIN_NAME_MAX = 9
16647
-_POSIX_CLOCKRES_MIN = 20000000
16649
-# Included from bits/local_lim.h
16651
-# Included from linux/limits.h
16664
-_POSIX_THREAD_KEYS_MAX = 128
16665
-PTHREAD_KEYS_MAX = 1024
16666
-_POSIX_THREAD_DESTRUCTOR_ITERATIONS = 4
16667
-PTHREAD_DESTRUCTOR_ITERATIONS = _POSIX_THREAD_DESTRUCTOR_ITERATIONS
16668
-_POSIX_THREAD_THREADS_MAX = 64
16669
-PTHREAD_THREADS_MAX = 1024
16670
-AIO_PRIO_DELTA_MAX = 20
16671
-PTHREAD_STACK_MIN = 16384
16673
-SSIZE_MAX = LONG_MAX
16674
-NGROUPS_MAX = _POSIX_NGROUPS_MAX
16676
-# Included from bits/posix2_lim.h
16677
-_BITS_POSIX2_LIM_H = 1
16678
-_POSIX2_BC_BASE_MAX = 99
16679
-_POSIX2_BC_DIM_MAX = 2048
16680
-_POSIX2_BC_SCALE_MAX = 99
16681
-_POSIX2_BC_STRING_MAX = 1000
16682
-_POSIX2_COLL_WEIGHTS_MAX = 2
16683
-_POSIX2_EXPR_NEST_MAX = 32
16684
-_POSIX2_LINE_MAX = 2048
16685
-_POSIX2_RE_DUP_MAX = 255
16686
-_POSIX2_CHARCLASS_NAME_MAX = 14
16687
-BC_BASE_MAX = _POSIX2_BC_BASE_MAX
16688
-BC_DIM_MAX = _POSIX2_BC_DIM_MAX
16689
-BC_SCALE_MAX = _POSIX2_BC_SCALE_MAX
16690
-BC_STRING_MAX = _POSIX2_BC_STRING_MAX
16691
-COLL_WEIGHTS_MAX = 255
16692
-EXPR_NEST_MAX = _POSIX2_EXPR_NEST_MAX
16693
-LINE_MAX = _POSIX2_LINE_MAX
16694
-CHARCLASS_NAME_MAX = 2048
16695
-RE_DUP_MAX = (0x7fff)
16697
-# Included from bits/xopen_lim.h
16700
-# Included from bits/stdio_lim.h
16703
-FILENAME_MAX = 4096
16708
-_XOPEN_IOV_MAX = _POSIX_UIO_MAXIOV
16709
-NL_ARGMAX = _POSIX_ARG_MAX
16710
-NL_LANGMAX = _POSIX2_LINE_MAX
16711
-NL_MSGMAX = INT_MAX
16713
-NL_SETMAX = INT_MAX
16714
-NL_TEXTMAX = INT_MAX
16729
-from TYPES import *
16732
-PF_UNIX = PF_LOCAL
16733
-PF_FILE = PF_LOCAL
16749
-PF_ROUTE = PF_NETLINK
16760
-AF_UNSPEC = PF_UNSPEC
16761
-AF_LOCAL = PF_LOCAL
16767
-AF_APPLETALK = PF_APPLETALK
16768
-AF_NETROM = PF_NETROM
16769
-AF_BRIDGE = PF_BRIDGE
16770
-AF_ATMPVC = PF_ATMPVC
16772
-AF_INET6 = PF_INET6
16774
-AF_DECnet = PF_DECnet
16775
-AF_NETBEUI = PF_NETBEUI
16776
-AF_SECURITY = PF_SECURITY
16778
-AF_NETLINK = PF_NETLINK
16779
-AF_ROUTE = PF_ROUTE
16780
-AF_PACKET = PF_PACKET
16782
-AF_ECONET = PF_ECONET
16783
-AF_ATMSVC = PF_ATMSVC
16786
-AF_PPPOX = PF_PPPOX
16787
-AF_WANPIPE = PF_WANPIPE
16788
-AF_BLUETOOTH = PF_BLUETOOTH
16799
-# Included from bits/sockaddr.h
16800
-_BITS_SOCKADDR_H = 1
16801
-def __SOCKADDR_COMMON(sa_prefix): return \
16804
-def CMSG_FIRSTHDR(mhdr): return \
16807
-# Included from asm/socket.h
16809
-# Included from asm/sockios.h
16810
-FIOSETOWN = 0x8901
16811
-SIOCSPGRP = 0x8902
16812
-FIOGETOWN = 0x8903
16813
-SIOCGPGRP = 0x8904
16814
-SIOCATMARK = 0x8905
16815
-SIOCGSTAMP = 0x8906
16837
-SO_SECURITY_AUTHENTICATION = 22
16838
-SO_SECURITY_ENCRYPTION_TRANSPORT = 23
16839
-SO_SECURITY_ENCRYPTION_NETWORK = 24
16840
-SO_BINDTODEVICE = 25
16841
-SO_ATTACH_FILTER = 26
16842
-SO_DETACH_FILTER = 27
16845
-SCM_TIMESTAMP = SO_TIMESTAMP
16846
-SO_ACCEPTCONN = 30
16851
-SOCK_SEQPACKET = 5
16853
-SOCK_MAX = (SOCK_PACKET+1)
16855
-# Included from bits/in.h
16860
-IP_ROUTER_ALERT = 5
16866
-IP_MTU_DISCOVER = 10
16870
-IP_MULTICAST_IF = 32
16871
-IP_MULTICAST_TTL = 33
16872
-IP_MULTICAST_LOOP = 34
16873
-IP_ADD_MEMBERSHIP = 35
16874
-IP_DROP_MEMBERSHIP = 36
16875
-IP_RECVRETOPTS = IP_RETOPTS
16876
-IP_PMTUDISC_DONT = 0
16877
-IP_PMTUDISC_WANT = 1
16878
-IP_PMTUDISC_DO = 2
16880
-IP_DEFAULT_MULTICAST_TTL = 1
16881
-IP_DEFAULT_MULTICAST_LOOP = 1
16882
-IP_MAX_MEMBERSHIPS = 20
16888
-IPV6_PKTOPTIONS = 6
16893
-IPV6_UNICAST_HOPS = 16
16894
-IPV6_MULTICAST_IF = 17
16895
-IPV6_MULTICAST_HOPS = 18
16896
-IPV6_MULTICAST_LOOP = 19
16897
-IPV6_JOIN_GROUP = 20
16898
-IPV6_LEAVE_GROUP = 21
16899
-IPV6_ROUTER_ALERT = 22
16900
-IPV6_MTU_DISCOVER = 23
16903
-IPV6_RXHOPOPTS = IPV6_HOPOPTS
16904
-IPV6_RXDSTOPTS = IPV6_DSTOPTS
16905
-IPV6_ADD_MEMBERSHIP = IPV6_JOIN_GROUP
16906
-IPV6_DROP_MEMBERSHIP = IPV6_LEAVE_GROUP
16907
-IPV6_PMTUDISC_DONT = 0
16908
-IPV6_PMTUDISC_WANT = 1
16909
-IPV6_PMTUDISC_DO = 2
16912
-IPV6_RTHDR_LOOSE = 0
16913
-IPV6_RTHDR_STRICT = 1
16914
-IPV6_RTHDR_TYPE_0 = 0
16916
-# Included from endian.h
16918
-__LITTLE_ENDIAN = 1234
16919
-__BIG_ENDIAN = 4321
16920
-__PDP_ENDIAN = 3412
16922
-# Included from bits/endian.h
16923
-__BYTE_ORDER = __LITTLE_ENDIAN
16924
-__FLOAT_WORD_ORDER = __BYTE_ORDER
16925
-LITTLE_ENDIAN = __LITTLE_ENDIAN
16926
-BIG_ENDIAN = __BIG_ENDIAN
16927
-PDP_ENDIAN = __PDP_ENDIAN
16928
-BYTE_ORDER = __BYTE_ORDER
16930
-# Included from bits/byteswap.h
16931
-_BITS_BYTESWAP_H = 1
16932
-def __bswap_constant_16(x): return \
16934
-def __bswap_16(x): return \
16936
-def __bswap_16(x): return __bswap_constant_16 (x)
16938
-def __bswap_constant_32(x): return \
16940
-def __bswap_32(x): return \
16942
-def __bswap_32(x): return \
16944
-def __bswap_32(x): return __bswap_constant_32 (x)
16946
-def __bswap_constant_64(x): return \
16948
-def __bswap_64(x): return \
16950
-def ntohl(x): return (x)
16952
-def ntohs(x): return (x)
16954
-def htonl(x): return (x)
16956
-def htons(x): return (x)
16958
-def ntohl(x): return __bswap_32 (x)
16960
-def ntohs(x): return __bswap_16 (x)
16962
-def htonl(x): return __bswap_32 (x)
16964
-def htons(x): return __bswap_16 (x)
16966
-def IN6_IS_ADDR_UNSPECIFIED(a): return \
16968
-def IN6_IS_ADDR_LOOPBACK(a): return \
16970
-def IN6_IS_ADDR_LINKLOCAL(a): return \
16972
-def IN6_IS_ADDR_SITELOCAL(a): return \
16974
-def IN6_IS_ADDR_V4MAPPED(a): return \
16976
-def IN6_IS_ADDR_V4COMPAT(a): return \
16978
-def IN6_IS_ADDR_MC_NODELOCAL(a): return \
16980
-def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
16982
-def IN6_IS_ADDR_MC_SITELOCAL(a): return \
16984
-def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
16986
-def IN6_IS_ADDR_MC_GLOBAL(a): return
16987
diff -r 137e45f15c0b Lib/plat-linux3/TYPES.py
16988
--- a/Lib/plat-linux3/TYPES.py
16991
-# Generated by h2py from /usr/include/sys/types.h
16994
-# Included from features.h
16998
-_ISOC99_SOURCE = 1
17000
-_POSIX_C_SOURCE = 199506
17001
-_XOPEN_SOURCE = 600
17002
-_XOPEN_SOURCE_EXTENDED = 1
17003
-_LARGEFILE64_SOURCE = 1
17010
-_POSIX_C_SOURCE = 2
17011
-_POSIX_C_SOURCE = 199506
17014
-__USE_POSIX199309 = 1
17015
-__USE_POSIX199506 = 1
17017
-__USE_XOPEN_EXTENDED = 1
17019
-_LARGEFILE_SOURCE = 1
17022
-__USE_XOPEN_EXTENDED = 1
17023
-__USE_LARGEFILE = 1
17024
-__USE_LARGEFILE64 = 1
17025
-__USE_FILE_OFFSET64 = 1
17030
-__USE_REENTRANT = 1
17031
-__STDC_IEC_559__ = 1
17032
-__STDC_IEC_559_COMPLEX__ = 1
17033
-__STDC_ISO_10646__ = 200009
17034
-__GNU_LIBRARY__ = 6
17036
-__GLIBC_MINOR__ = 2
17038
-# Included from sys/cdefs.h
17040
-def __PMT(args): return args
17042
-def __P(args): return args
17044
-def __PMT(args): return args
17046
-def __STRING(x): return #x
17052
-def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
17054
-def __attribute__(xyz): return
17056
-def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x)))
17058
-def __attribute_format_arg__(x): return
17060
-__USE_LARGEFILE = 1
17061
-__USE_LARGEFILE64 = 1
17062
-__USE_EXTERN_INLINES = 1
17064
-# Included from gnu/stubs.h
17066
-# Included from bits/types.h
17068
-__FD_SETSIZE = 1024
17070
-# Included from bits/pthreadtypes.h
17071
-_BITS_PTHREADTYPES_H = 1
17073
-# Included from bits/sched.h
17077
-CSIGNAL = 0x000000ff
17078
-CLONE_VM = 0x00000100
17079
-CLONE_FS = 0x00000200
17080
-CLONE_FILES = 0x00000400
17081
-CLONE_SIGHAND = 0x00000800
17082
-CLONE_PID = 0x00001000
17083
-CLONE_PTRACE = 0x00002000
17084
-CLONE_VFORK = 0x00004000
17085
-__defined_schedparam = 1
17087
-# Included from time.h
17090
-# Included from bits/time.h
17092
-CLOCKS_PER_SEC = 1000000
17093
-CLOCK_REALTIME = 0
17094
-CLOCK_PROCESS_CPUTIME_ID = 2
17095
-CLOCK_THREAD_CPUTIME_ID = 3
17097
-_STRUCT_TIMEVAL = 1
17098
-CLK_TCK = CLOCKS_PER_SEC
17099
-__clock_t_defined = 1
17100
-__time_t_defined = 1
17101
-__clockid_t_defined = 1
17102
-__timer_t_defined = 1
17103
-__timespec_defined = 1
17104
-def __isleap(year): return \
17106
-__BIT_TYPES_DEFINED__ = 1
17108
-# Included from endian.h
17110
-__LITTLE_ENDIAN = 1234
17111
-__BIG_ENDIAN = 4321
17112
-__PDP_ENDIAN = 3412
17114
-# Included from bits/endian.h
17115
-__BYTE_ORDER = __LITTLE_ENDIAN
17116
-__FLOAT_WORD_ORDER = __BYTE_ORDER
17117
-LITTLE_ENDIAN = __LITTLE_ENDIAN
17118
-BIG_ENDIAN = __BIG_ENDIAN
17119
-PDP_ENDIAN = __PDP_ENDIAN
17120
-BYTE_ORDER = __BYTE_ORDER
17122
-# Included from sys/select.h
17125
-# Included from bits/select.h
17126
-def __FD_ZERO(fdsp): return \
17128
-def __FD_ZERO(set): return \
17131
-# Included from bits/sigset.h
17132
-_SIGSET_H_types = 1
17134
-def __sigmask(sig): return \
17136
-def __sigemptyset(set): return \
17138
-def __sigfillset(set): return \
17140
-def __sigisemptyset(set): return \
17142
-def __FDELT(d): return ((d) / __NFDBITS)
17144
-FD_SETSIZE = __FD_SETSIZE
17145
-def FD_ZERO(fdsetp): return __FD_ZERO (fdsetp)
17148
-# Included from sys/sysmacros.h
17149
-_SYS_SYSMACROS_H = 1
17150
-def major(dev): return ((int)(((dev) >> 8) & 0xff))
17152
-def minor(dev): return ((int)((dev) & 0xff))
17154
-def major(dev): return (((dev).__val[1] >> 8) & 0xff)
17156
-def minor(dev): return ((dev).__val[1] & 0xff)
17158
-def major(dev): return (((dev).__val[0] >> 8) & 0xff)
17160
-def minor(dev): return ((dev).__val[0] & 0xff)
17161
diff -r 137e45f15c0b Lib/plat-linux3/regen
17162
--- a/Lib/plat-linux3/regen
17168
-*) echo Probably not on a Linux system 1>&2
17172
-h2py -i '(u_long)' /usr/include/sys/types.h /usr/include/netinet/in.h /usr/include/dlfcn.h
17173
diff -r 137e45f15c0b Lib/platform.py
17174
--- a/Lib/platform.py
17175
+++ b/Lib/platform.py
17176
@@ -181,7 +181,7 @@
17180
- if soversion > version:
17181
+ if soversion and soversion > version:
17182
version = soversion
17183
if threads and version[-len(threads):] != threads:
17184
version = version + threads
17185
@@ -549,7 +549,7 @@
17187
""" Get additional version information from the Windows Registry
17188
and return a tuple (version,csd,ptype) referring to version
17189
- number, CSD level and OS type (multi/single
17190
+ number, CSD level (service pack), and OS type (multi/single
17193
As a hint: ptype returns 'Uniprocessor Free' on single
17194
diff -r 137e45f15c0b Lib/pty.py
17197
@@ -142,15 +142,21 @@
17199
pty master -> standard output (master_read)
17200
standard input -> pty master (stdin_read)"""
17202
- rfds, wfds, xfds = select(
17203
- [master_fd, STDIN_FILENO], [], [])
17204
+ fds = [master_fd, STDIN_FILENO]
17206
+ rfds, wfds, xfds = select(fds, [], [])
17207
if master_fd in rfds:
17208
data = master_read(master_fd)
17209
- os.write(STDOUT_FILENO, data)
17210
+ if not data: # Reached EOF.
17211
+ fds.remove(master_fd)
17213
+ os.write(STDOUT_FILENO, data)
17214
if STDIN_FILENO in rfds:
17215
data = stdin_read(STDIN_FILENO)
17216
- _writen(master_fd, data)
17218
+ fds.remove(STDIN_FILENO)
17220
+ _writen(master_fd, data)
17222
def spawn(argv, master_read=_read, stdin_read=_read):
17223
"""Create a spawned process."""
17224
diff -r 137e45f15c0b Lib/py_compile.py
17225
--- a/Lib/py_compile.py
17226
+++ b/Lib/py_compile.py
17227
@@ -130,7 +130,9 @@
17229
cfile = imp.cache_from_source(file)
17231
- os.makedirs(os.path.dirname(cfile))
17232
+ dirname = os.path.dirname(cfile)
17234
+ os.makedirs(dirname)
17235
except OSError as error:
17236
if error.errno != errno.EEXIST:
17238
diff -r 137e45f15c0b Lib/pydoc.py
17241
@@ -754,8 +754,15 @@
17244
for name, kind, homecls, value in ok:
17245
- push(self.document(getattr(object, name), name, mod,
17246
- funcs, classes, mdict, object))
17248
+ value = getattr(object, name)
17249
+ except Exception:
17250
+ # Some descriptors may meet a failure in their __get__.
17252
+ push(self._docdescriptor(name, value, mod))
17254
+ push(self.document(value, name, mod,
17255
+ funcs, classes, mdict, object))
17259
@@ -775,7 +782,7 @@
17261
for name, kind, homecls, value in ok:
17262
base = self.docother(getattr(object, name), name, mod)
17263
- if hasattr(value, '__call__') or inspect.isdatadescriptor(value):
17264
+ if callable(value) or inspect.isdatadescriptor(value):
17265
doc = getattr(value, "__doc__", None)
17268
@@ -796,7 +803,12 @@
17270
for key, kind, homecls, value in attrs:
17271
mdict[key] = anchor = '#' + name + '-' + key
17272
- value = getattr(object, key)
17274
+ value = getattr(object, name)
17275
+ except Exception:
17276
+ # Some descriptors may meet a failure in their __get__.
17280
# The value may not be hashable (e.g., a data attr with
17281
# a dict or list value).
17282
@@ -1044,10 +1056,11 @@
17283
if docloc is not None:
17284
result = result + self.section('MODULE REFERENCE', docloc + """
17286
-The following documentation is automatically generated from the Python source
17287
-files. It may be incomplete, incorrect or include features that are considered
17288
-implementation detail and may vary between Python implementations. When in
17289
-doubt, consult the module reference at the location listed above.
17290
+The following documentation is automatically generated from the Python
17291
+source files. It may be incomplete, incorrect or include features that
17292
+are considered implementation detail and may vary between Python
17293
+implementations. When in doubt, consult the module reference at the
17294
+location listed above.
17298
@@ -1179,8 +1192,15 @@
17301
for name, kind, homecls, value in ok:
17302
- push(self.document(getattr(object, name),
17303
- name, mod, object))
17305
+ value = getattr(object, name)
17306
+ except Exception:
17307
+ # Some descriptors may meet a failure in their __get__.
17309
+ push(self._docdescriptor(name, value, mod))
17311
+ push(self.document(value,
17312
+ name, mod, object))
17315
def spilldescriptors(msg, attrs, predicate):
17316
@@ -1198,7 +1218,7 @@
17319
for name, kind, homecls, value in ok:
17320
- if hasattr(value, '__call__') or inspect.isdatadescriptor(value):
17321
+ if callable(value) or inspect.isdatadescriptor(value):
17322
doc = getdoc(value)
17325
diff -r 137e45f15c0b Lib/random.py
17326
--- a/Lib/random.py
17327
+++ b/Lib/random.py
17332
-from __future__ import division
17333
from warnings import warn as _warn
17334
from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethodType
17335
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
17336
diff -r 137e45f15c0b Lib/re.py
17339
@@ -326,7 +326,7 @@
17342
action = self.lexicon[m.lastindex-1][1]
17343
- if hasattr(action, "__call__"):
17344
+ if callable(action):
17346
action = action(self, m.group())
17347
if action is not None:
17348
diff -r 137e45f15c0b Lib/rlcompleter.py
17349
--- a/Lib/rlcompleter.py
17350
+++ b/Lib/rlcompleter.py
17354
def _callable_postfix(self, val, word):
17355
- if hasattr(val, '__call__'):
17356
+ if callable(val):
17360
diff -r 137e45f15c0b Lib/sched.py
17366
It is legal for both the delay function and the action
17367
- function to to modify the queue or to raise an exception;
17368
+ function to modify the queue or to raise an exception;
17369
exceptions are not caught but the scheduler's state remains
17370
well-defined so run() may be called again.
17372
diff -r 137e45f15c0b Lib/shutil.py
17373
--- a/Lib/shutil.py
17374
+++ b/Lib/shutil.py
17375
@@ -398,7 +398,7 @@
17377
if not os.path.exists(archive_dir):
17378
if logger is not None:
17379
- logger.info("creating %s" % archive_dir)
17380
+ logger.info("creating %s", archive_dir)
17382
os.makedirs(archive_dir)
17384
@@ -493,7 +493,6 @@
17386
_ARCHIVE_FORMATS = {
17387
'gztar': (_make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
17388
- 'bztar': (_make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"),
17389
'tar': (_make_tarball, [('compress', None)], "uncompressed tar file"),
17390
'zip': (_make_zipfile, [],"ZIP file")
17392
@@ -523,7 +522,7 @@
17394
if extra_args is None:
17396
- if not isinstance(function, collections.Callable):
17397
+ if not callable(function):
17398
raise TypeError('The %s object is not callable' % function)
17399
if not isinstance(extra_args, (tuple, list)):
17400
raise TypeError('extra_args needs to be a sequence')
17401
@@ -616,7 +615,7 @@
17402
raise RegistryError(msg % (extension,
17403
existing_extensions[extension]))
17405
- if not isinstance(function, collections.Callable):
17406
+ if not callable(function):
17407
raise TypeError('The registered function must be a callable')
17410
diff -r 137e45f15c0b Lib/smtpd.py
17413
@@ -678,6 +678,16 @@
17414
if __name__ == '__main__':
17415
options = parseargs()
17417
+ classname = options.classname
17418
+ if "." in classname:
17419
+ lastdot = classname.rfind(".")
17420
+ mod = __import__(classname[:lastdot], globals(), locals(), [""])
17421
+ classname = classname[lastdot+1:]
17423
+ import __main__ as mod
17424
+ class_ = getattr(mod, classname)
17425
+ proxy = class_((options.localhost, options.localport),
17426
+ (options.remotehost, options.remoteport))
17430
@@ -691,16 +701,6 @@
17431
if e.errno != errno.EPERM: raise
17432
print('Cannot setuid "nobody"; try running with -n option.', file=sys.stderr)
17434
- classname = options.classname
17435
- if "." in classname:
17436
- lastdot = classname.rfind(".")
17437
- mod = __import__(classname[:lastdot], globals(), locals(), [""])
17438
- classname = classname[lastdot+1:]
17440
- import __main__ as mod
17441
- class_ = getattr(mod, classname)
17442
- proxy = class_((options.localhost, options.localport),
17443
- (options.remotehost, options.remoteport))
17446
except KeyboardInterrupt:
17447
diff -r 137e45f15c0b Lib/smtplib.py
17448
--- a/Lib/smtplib.py
17449
+++ b/Lib/smtplib.py
17450
@@ -364,8 +364,10 @@
17453
line = self.file.readline()
17454
- except socket.error:
17456
+ except socket.error as e:
17458
+ raise SMTPServerDisconnected("Connection unexpectedly closed: "
17462
raise SMTPServerDisconnected("Connection unexpectedly closed")
17463
@@ -910,6 +912,7 @@
17465
def prompt(prompt):
17466
sys.stdout.write(prompt + ": ")
17467
+ sys.stdout.flush()
17468
return sys.stdin.readline().strip()
17470
fromaddr = prompt("From")
17471
diff -r 137e45f15c0b Lib/socketserver.py
17472
--- a/Lib/socketserver.py
17473
+++ b/Lib/socketserver.py
17475
data is stored externally (e.g. in the file system), a synchronous
17476
class will essentially render the service "deaf" while one request is
17477
being handled -- which may be for a very long time if a client is slow
17478
-to reqd all the data it has requested. Here a threading or forking
17479
+to read all the data it has requested. Here a threading or forking
17480
server is appropriate.
17482
In some cases, it may be appropriate to process part of a request
17483
@@ -588,8 +588,7 @@
17484
"""Start a new thread to process the request."""
17485
t = threading.Thread(target = self.process_request_thread,
17486
args = (request, client_address))
17487
- if self.daemon_threads:
17489
+ t.daemon = self.daemon_threads
17493
diff -r 137e45f15c0b Lib/sqlite3/dump.py
17494
--- a/Lib/sqlite3/dump.py
17495
+++ b/Lib/sqlite3/dump.py
17497
# Mimic the sqlite3 console shell's .dump command
17498
# Author: Paul Kippes <kippesp@gmail.com>
17500
+# Every identifier in sql is quoted based on a comment in sqlite
17501
+# documentation "SQLite adds new keywords from time to time when it
17502
+# takes on new features. So to prevent your code from being broken by
17503
+# future enhancements, you should normally quote any identifier that
17504
+# is an English language word, even if you do not have to."
17506
def _iterdump(connection):
17508
Returns an iterator to the dump of the database in an SQL text format.
17509
@@ -15,49 +21,49 @@
17511
# sqlite_master table contains the SQL CREATE statements for the database.
17513
- SELECT name, type, sql
17514
- FROM sqlite_master
17515
- WHERE sql NOT NULL AND
17517
+ SELECT "name", "type", "sql"
17518
+ FROM "sqlite_master"
17519
+ WHERE "sql" NOT NULL AND
17520
+ "type" == 'table'
17522
schema_res = cu.execute(q)
17523
- for table_name, type, sql in schema_res.fetchall():
17524
+ for table_name, type, sql in sorted(schema_res.fetchall()):
17525
if table_name == 'sqlite_sequence':
17526
- yield('DELETE FROM sqlite_sequence;')
17527
+ yield('DELETE FROM "sqlite_sequence";')
17528
elif table_name == 'sqlite_stat1':
17529
- yield('ANALYZE sqlite_master;')
17530
+ yield('ANALYZE "sqlite_master";')
17531
elif table_name.startswith('sqlite_'):
17533
# NOTE: Virtual table support not implemented
17534
#elif sql.startswith('CREATE VIRTUAL TABLE'):
17535
# qtable = table_name.replace("'", "''")
17536
# yield("INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"\
17537
- # "VALUES('table','%s','%s',0,'%s');" %
17538
+ # "VALUES('table','{0}','{0}',0,'{1}');".format(
17541
- # sql.replace("''"))
17542
+ # sql.replace("''")))
17544
- yield('%s;' % sql)
17545
+ yield('{0};'.format(sql))
17547
# Build the insert statement for each row of the current table
17548
- res = cu.execute("PRAGMA table_info('%s')" % table_name)
17549
+ table_name_ident = table_name.replace('"', '""')
17550
+ res = cu.execute('PRAGMA table_info("{0}")'.format(table_name_ident))
17551
column_names = [str(table_info[1]) for table_info in res.fetchall()]
17552
- q = "SELECT 'INSERT INTO \"%(tbl_name)s\" VALUES("
17553
- q += ",".join(["'||quote(" + col + ")||'" for col in column_names])
17554
- q += ")' FROM '%(tbl_name)s'"
17555
- query_res = cu.execute(q % {'tbl_name': table_name})
17556
+ q = """SELECT 'INSERT INTO "{0}" VALUES({1})' FROM "{0}";""".format(
17557
+ table_name_ident,
17558
+ ",".join("""'||quote("{0}")||'""".format(col.replace('"', '""')) for col in column_names))
17559
+ query_res = cu.execute(q)
17560
for row in query_res:
17561
- yield("%s;" % row[0])
17562
+ yield("{0};".format(row[0]))
17564
# Now when the type is 'index', 'trigger', or 'view'
17566
- SELECT name, type, sql
17567
- FROM sqlite_master
17568
- WHERE sql NOT NULL AND
17569
- type IN ('index', 'trigger', 'view')
17570
+ SELECT "name", "type", "sql"
17571
+ FROM "sqlite_master"
17572
+ WHERE "sql" NOT NULL AND
17573
+ "type" IN ('index', 'trigger', 'view')
17575
schema_res = cu.execute(q)
17576
for name, type, sql in schema_res.fetchall():
17577
- yield('%s;' % sql)
17578
+ yield('{0};'.format(sql))
17581
diff -r 137e45f15c0b Lib/sqlite3/test/dbapi.py
17582
--- a/Lib/sqlite3/test/dbapi.py
17583
+++ b/Lib/sqlite3/test/dbapi.py
17584
@@ -225,6 +225,13 @@
17585
def CheckExecuteArgString(self):
17586
self.cu.execute("insert into test(name) values (?)", ("Hugo",))
17588
+ def CheckExecuteArgStringWithZeroByte(self):
17589
+ self.cu.execute("insert into test(name) values (?)", ("Hu\x00go",))
17591
+ self.cu.execute("select name from test where id=?", (self.cu.lastrowid,))
17592
+ row = self.cu.fetchone()
17593
+ self.assertEqual(row[0], "Hu\x00go")
17595
def CheckExecuteWrongNoOfArgs1(self):
17596
# too many parameters
17598
diff -r 137e45f15c0b Lib/sqlite3/test/dump.py
17599
--- a/Lib/sqlite3/test/dump.py
17600
+++ b/Lib/sqlite3/test/dump.py
17603
def CheckTableDump(self):
17605
+ """CREATE TABLE "index"("index" blob);"""
17607
+ """INSERT INTO "index" VALUES(X'01');"""
17609
+ """CREATE TABLE "quoted""table"("quoted""field" text);"""
17611
+ """INSERT INTO "quoted""table" VALUES('quoted''value');"""
17613
"CREATE TABLE t1(id integer primary key, s1 text, " \
17614
"t1_i1 integer not null, i2 integer, unique (s1), " \
17615
"constraint t1_idx1 unique (i2));"
17616
diff -r 137e45f15c0b Lib/sqlite3/test/factory.py
17617
--- a/Lib/sqlite3/test/factory.py
17618
+++ b/Lib/sqlite3/test/factory.py
17619
@@ -189,13 +189,48 @@
17620
def tearDown(self):
17623
+class TextFactoryTestsWithEmbeddedZeroBytes(unittest.TestCase):
17625
+ self.con = sqlite.connect(":memory:")
17626
+ self.con.execute("create table test (value text)")
17627
+ self.con.execute("insert into test (value) values (?)", ("a\x00b",))
17629
+ def CheckString(self):
17630
+ # text_factory defaults to str
17631
+ row = self.con.execute("select value from test").fetchone()
17632
+ self.assertIs(type(row[0]), str)
17633
+ self.assertEqual(row[0], "a\x00b")
17635
+ def CheckBytes(self):
17636
+ self.con.text_factory = bytes
17637
+ row = self.con.execute("select value from test").fetchone()
17638
+ self.assertIs(type(row[0]), bytes)
17639
+ self.assertEqual(row[0], b"a\x00b")
17641
+ def CheckBytearray(self):
17642
+ self.con.text_factory = bytearray
17643
+ row = self.con.execute("select value from test").fetchone()
17644
+ self.assertIs(type(row[0]), bytearray)
17645
+ self.assertEqual(row[0], b"a\x00b")
17647
+ def CheckCustom(self):
17648
+ # A custom factory should receive a bytes argument
17649
+ self.con.text_factory = lambda x: x
17650
+ row = self.con.execute("select value from test").fetchone()
17651
+ self.assertIs(type(row[0]), bytes)
17652
+ self.assertEqual(row[0], b"a\x00b")
17654
+ def tearDown(self):
17658
connection_suite = unittest.makeSuite(ConnectionFactoryTests, "Check")
17659
cursor_suite = unittest.makeSuite(CursorFactoryTests, "Check")
17660
row_suite_compat = unittest.makeSuite(RowFactoryTestsBackwardsCompat, "Check")
17661
row_suite = unittest.makeSuite(RowFactoryTests, "Check")
17662
text_suite = unittest.makeSuite(TextFactoryTests, "Check")
17663
- return unittest.TestSuite((connection_suite, cursor_suite, row_suite_compat, row_suite, text_suite))
17664
+ text_zero_bytes_suite = unittest.makeSuite(TextFactoryTestsWithEmbeddedZeroBytes, "Check")
17665
+ return unittest.TestSuite((connection_suite, cursor_suite, row_suite_compat, row_suite, text_suite, text_zero_bytes_suite))
17668
runner = unittest.TextTestRunner()
17669
diff -r 137e45f15c0b Lib/sqlite3/test/regression.py
17670
--- a/Lib/sqlite3/test/regression.py
17671
+++ b/Lib/sqlite3/test/regression.py
17672
@@ -281,6 +281,28 @@
17673
# Lone surrogate cannot be encoded to the default encoding (utf8)
17674
"\uDC80", collation_cb)
17676
+ def CheckRecursiveCursorUse(self):
17678
+ http://bugs.python.org/issue10811
17680
+ Recursively using a cursor, such as when reusing it from a generator led to segfaults.
17681
+ Now we catch recursive cursor usage and raise a ProgrammingError.
17683
+ con = sqlite.connect(":memory:")
17685
+ cur = con.cursor()
17686
+ cur.execute("create table a (bar)")
17687
+ cur.execute("create table b (baz)")
17690
+ cur.execute("insert into a (bar) values (?)", (1,))
17693
+ with self.assertRaises(sqlite.ProgrammingError):
17694
+ cur.executemany("insert into b (baz) values (?)",
17695
+ ((i,) for i in foo()))
17699
regression_suite = unittest.makeSuite(RegressionTests, "Check")
17700
return unittest.TestSuite((regression_suite,))
17701
diff -r 137e45f15c0b Lib/ssl.py
17707
from _ssl import PROTOCOL_SSLv2
17708
+ _SSLv2_IF_EXISTS = PROTOCOL_SSLv2
17709
except ImportError:
17711
+ _SSLv2_IF_EXISTS = None
17713
_PROTOCOL_NAMES[PROTOCOL_SSLv2] = "SSLv2"
17719
+# Disable weak or insecure ciphers by default
17720
+# (OpenSSL's default setting is 'DEFAULT:!aNULL:!eNULL')
17721
+_DEFAULT_CIPHERS = 'DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2'
17724
class CertificateError(ValueError):
17726
@@ -165,7 +170,10 @@
17727
__slots__ = ('protocol',)
17729
def __new__(cls, protocol, *args, **kwargs):
17730
- return _SSLContext.__new__(cls, protocol)
17731
+ self = _SSLContext.__new__(cls, protocol)
17732
+ if protocol != _SSLv2_IF_EXISTS:
17733
+ self.set_ciphers(_DEFAULT_CIPHERS)
17736
def __init__(self, protocol):
17737
self.protocol = protocol
17738
diff -r 137e45f15c0b Lib/subprocess.py
17739
--- a/Lib/subprocess.py
17740
+++ b/Lib/subprocess.py
17741
@@ -429,12 +429,16 @@
17745
+# This lists holds Popen instances for which the underlying process had not
17746
+# exited at the time its __del__ method got called: those processes are wait()ed
17747
+# for synchronously from _cleanup() when a new Popen object is created, to avoid
17748
+# zombie processes.
17752
for inst in _active[:]:
17753
res = inst._internal_poll(_deadstate=sys.maxsize)
17754
- if res is not None and res >= 0:
17755
+ if res is not None:
17757
_active.remove(inst)
17759
@@ -1191,6 +1195,7 @@
17761
errpipe_read, errpipe_write,
17762
restore_signals, start_new_session, preexec_fn)
17763
+ self._child_created = True
17765
# Pure Python implementation: It is not thread safe.
17766
# This implementation may deadlock in the child if your
17767
diff -r 137e45f15c0b Lib/symbol.py
17768
--- a/Lib/symbol.py
17769
+++ b/Lib/symbol.py
17771
# To update the symbols in this file, 'cd' to the top directory of
17772
# the python source tree after building the interpreter and run:
17774
-# python Lib/symbol.py
17775
+# ./python Lib/symbol.py
17777
#--start constants--
17779
diff -r 137e45f15c0b Lib/sysconfig.py
17780
--- a/Lib/sysconfig.py
17781
+++ b/Lib/sysconfig.py
17782
@@ -639,6 +639,11 @@
17783
if release[0] >= "5": # SunOS 5 == Solaris 2
17785
release = "%d.%s" % (int(release[0]) - 3, release[2:])
17786
+ # We can't use "platform.architecture()[0]" because a
17787
+ # bootstrap problem. We use a dict to get an error
17788
+ # if some suspicious happens.
17789
+ bitness = {2147483647:"32bit", 9223372036854775807:"64bit"}
17790
+ machine += ".%s" % bitness[sys.maxsize]
17791
# fall through to standard osname-release-machine representation
17792
elif osname[:4] == "irix": # could be "irix64"!
17793
return "%s-%s" % (osname, release)
17794
diff -r 137e45f15c0b Lib/tarfile.py
17795
--- a/Lib/tarfile.py
17796
+++ b/Lib/tarfile.py
17797
@@ -196,16 +196,18 @@
17799
# There are two possible encodings for a number field, see
17801
- if s[0] != chr(0o200):
17802
+ if s[0] in (0o200, 0o377):
17804
+ for i in range(len(s) - 1):
17807
+ if s[0] == 0o377:
17808
+ n = -(256 ** (len(s) - 1) - n)
17811
n = int(nts(s, "ascii", "strict") or "0", 8)
17813
raise InvalidHeaderError("invalid header")
17816
- for i in range(len(s) - 1):
17818
- n += ord(s[i + 1])
17821
def itn(n, digits=8, format=DEFAULT_FORMAT):
17822
@@ -214,25 +216,26 @@
17823
# POSIX 1003.1-1988 requires numbers to be encoded as a string of
17824
# octal digits followed by a null-byte, this allows values up to
17825
# (8**(digits-1))-1. GNU tar allows storing numbers greater than
17826
- # that if necessary. A leading 0o200 byte indicates this particular
17827
- # encoding, the following digits-1 bytes are a big-endian
17828
- # representation. This allows values up to (256**(digits-1))-1.
17829
+ # that if necessary. A leading 0o200 or 0o377 byte indicate this
17830
+ # particular encoding, the following digits-1 bytes are a big-endian
17831
+ # base-256 representation. This allows values up to (256**(digits-1))-1.
17832
+ # A 0o200 byte indicates a positive number, a 0o377 byte a negative
17834
if 0 <= n < 8 ** (digits - 1):
17835
s = bytes("%0*o" % (digits - 1, n), "ascii") + NUL
17836
+ elif format == GNU_FORMAT and -256 ** (digits - 1) <= n < 256 ** (digits - 1):
17838
+ s = bytearray([0o200])
17840
+ s = bytearray([0o377])
17841
+ n = 256 ** digits + n
17843
+ for i in range(digits - 1):
17844
+ s.insert(1, n & 0o377)
17847
- if format != GNU_FORMAT or n >= 256 ** (digits - 1):
17848
- raise ValueError("overflow in number field")
17849
+ raise ValueError("overflow in number field")
17852
- # XXX We mimic GNU tar's behaviour with negative numbers,
17853
- # this could raise OverflowError.
17854
- n = struct.unpack("L", struct.pack("l", n))[0]
17857
- for i in range(digits - 1):
17858
- s.insert(0, n & 0o377)
17860
- s.insert(0, 0o200)
17863
def calc_chksums(buf):
17864
@@ -624,7 +627,7 @@
17865
def getcomptype(self):
17866
if self.buf.startswith(b"\037\213\010"):
17868
- if self.buf.startswith(b"BZh91"):
17869
+ if self.buf[0:3] == b"BZh" and self.buf[4:10] == b"1AY&SY":
17873
@@ -2348,12 +2351,6 @@
17874
self._extract_member(self._find_link_target(tarinfo),
17876
except symlink_exception:
17877
- if tarinfo.issym():
17878
- linkpath = os.path.join(os.path.dirname(tarinfo.name),
17879
- tarinfo.linkname)
17881
- linkpath = tarinfo.linkname
17884
self._extract_member(self._find_link_target(tarinfo),
17886
@@ -2368,17 +2365,11 @@
17888
g = grp.getgrnam(tarinfo.gname)[2]
17891
- g = grp.getgrgid(tarinfo.gid)[2]
17896
u = pwd.getpwnam(tarinfo.uname)[2]
17899
- u = pwd.getpwuid(tarinfo.uid)[2]
17904
if tarinfo.issym() and hasattr(os, "lchown"):
17905
os.lchown(targetpath, u, g)
17906
diff -r 137e45f15c0b Lib/tempfile.py
17907
--- a/Lib/tempfile.py
17908
+++ b/Lib/tempfile.py
17909
@@ -112,8 +112,13 @@
17911
characters = "abcdefghijklmnopqrstuvwxyz0123456789_"
17913
- def __init__(self):
17914
- self.rng = _Random()
17917
+ cur_pid = _os.getpid()
17918
+ if cur_pid != getattr(self, '_rng_pid', None):
17919
+ self._rng = _Random()
17920
+ self._rng_pid = cur_pid
17923
def __iter__(self):
17925
diff -r 137e45f15c0b Lib/test/lock_tests.py
17926
--- a/Lib/test/lock_tests.py
17927
+++ b/Lib/test/lock_tests.py
17928
@@ -351,6 +351,22 @@
17929
for r, dt in results2:
17932
+ def test_set_and_clear(self):
17933
+ # Issue #13502: check that wait() returns true even when the event is
17934
+ # cleared before the waiting thread is woken up.
17935
+ evt = self.eventtype()
17939
+ results.append(evt.wait(1))
17941
+ b.wait_for_started()
17945
+ b.wait_for_finished()
17946
+ self.assertEqual(results, [True] * N)
17949
class ConditionTests(BaseTestCase):
17951
diff -r 137e45f15c0b Lib/test/mime.types
17953
+++ b/Lib/test/mime.types
17955
+# This is a comment. I love comments. -*- indent-tabs-mode: t -*-
17957
+# This file controls what Internet media types are sent to the client for
17958
+# given file extension(s). Sending the correct media type to the client
17959
+# is important so they know how to handle the content of the file.
17960
+# Extra types can either be added here or by using an AddType directive
17961
+# in your config files. For more information about Internet media types,
17962
+# please read RFC 2045, 2046, 2047, 2048, and 2077. The Internet media type
17963
+# registry is at <http://www.iana.org/assignments/media-types/>.
17967
+# MIME type Extensions
17968
+application/1d-interleaved-parityfec
17969
+application/3gpp-ims+xml
17970
+application/activemessage
17971
+application/andrew-inset ez
17972
+application/applefile
17973
+application/atom+xml atom
17974
+application/atomcat+xml atomcat
17975
+application/atomicmail
17976
+application/atomsvc+xml atomsvc
17977
+application/auth-policy+xml apxml
17978
+application/batch-SMTP
17979
+application/beep+xml
17980
+application/cals-1840
17981
+application/ccxml+xml ccxml
17982
+application/cdmi-capability cdmia
17983
+application/cdmi-container cdmic
17984
+application/cdmi-domain cdmid
17985
+application/cdmi-object cdmio
17986
+application/cdmi-queue cdmiq
17987
+application/cea-2018+xml
17988
+application/cellml+xml cellml cml
17990
+application/cnrp+xml
17991
+application/commonground
17992
+application/conference-info+xml
17993
+application/cpl+xml cpl
17994
+application/csta+xml
17995
+application/CSTAdata+xml
17996
+application/cybercash
17997
+application/davmount+xml davmount
17998
+application/dca-rft
17999
+application/dec-dx
18000
+application/dialog-info+xml
18001
+application/dicom dcm
18003
+application/dskpp+xml xmls
18004
+application/dssc+der dssc
18005
+application/dssc+xml xdssc
18006
+application/dvcs dvc
18007
+application/ecmascript
18008
+application/EDI-Consent
18009
+application/EDI-X12
18010
+application/EDIFACT
18011
+application/emma+xml emma
18012
+application/epp+xml
18014
+application/exi exi
18015
+application/fastinfoset finf
18016
+application/fastsoap
18017
+# fits, fit, fts: image/fits
18019
+application/font-tdpfr pfr
18020
+application/framework-attributes+xml
18022
+application/hal+xml hal
18023
+application/held+xml
18025
+application/hyperstudio stk
18026
+application/ibe-key-request+xml
18027
+application/ibe-pkg-reply+xml
18028
+application/ibe-pp-data
18030
+application/im-iscomposing+xml
18032
+application/index.cmd
18033
+application/index.obj
18034
+application/index.response
18035
+application/index.vnd
18037
+application/ipfix ipfix
18040
+application/javascript js
18041
+application/json json
18042
+application/kpml-request+xml
18043
+application/kpml-response+xml
18044
+application/lost+xml lostxml
18045
+application/mac-binhex40 hqx
18046
+application/macwriteii
18047
+application/mads+xml mads
18048
+application/marc mrc
18049
+application/marcxml+xml mrcx
18050
+application/mathematica nb ma mb
18051
+application/mathml-content+xml
18052
+application/mathml-presentation+xml
18053
+application/mathml+xml mml
18054
+application/mbms-associated-procedure-description+xml
18055
+application/mbms-deregister+xml
18056
+application/mbms-envelope+xml
18057
+application/mbms-msk-response+xml
18058
+application/mbms-msk+xml
18059
+application/mbms-protection-description+xml
18060
+application/mbms-reception-report+xml
18061
+application/mbms-register-response+xml
18062
+application/mbms-register+xml
18063
+application/mbms-user-service-description+xml
18064
+application/mbox mbox
18065
+application/media_control+xml
18066
+application/mediaservercontrol+xml
18067
+application/metalink4+xml meta4
18068
+application/mets+xml mets
18070
+application/mods+xml mods
18071
+application/moss-keys
18072
+application/moss-signature
18073
+application/mosskey-data
18074
+application/mosskey-request
18075
+application/mp21 m21 mp21
18076
+# mp4, mpg4: video/mp4, see RFC 4337
18078
+application/mpeg4-generic
18079
+application/mpeg4-iod
18080
+application/mpeg4-iod-xmt
18081
+application/msc-ivr+xml
18082
+application/msc-mixer+xml
18083
+application/msword doc
18084
+application/mxf mxf
18085
+application/nasdata
18086
+application/news-checkgroups
18087
+application/news-groupinfo
18088
+application/news-transmission
18090
+application/ocsp-request orq
18091
+application/ocsp-response ors
18092
+application/octet-stream bin lha lzh exe class so dll img iso
18093
+application/oda oda
18094
+application/oebps-package+xml opf
18095
+application/ogg ogx
18096
+application/parityfec
18097
+# xer: application/xcap-error+xml
18098
+application/patch-ops-error+xml
18099
+application/pdf pdf
18100
+application/pgp-encrypted
18101
+application/pgp-keys
18102
+application/pgp-signature sig
18103
+application/pidf-diff+xml
18104
+application/pidf+xml
18105
+application/pkcs10 p10
18106
+application/pkcs7-mime p7m p7c
18107
+application/pkcs7-signature p7s
18108
+application/pkcs8 p8
18109
+# ac: application/vnd.nokia.n-gage.ac+xml
18110
+application/pkix-attr-cert
18111
+application/pkix-cert cer
18112
+application/pkix-crl crl
18113
+application/pkix-pkipath pkipath
18114
+application/pkixcmp
18115
+application/pls+xml pls
18116
+application/poc-settings+xml
18117
+application/postscript ps eps ai
18118
+application/prs.alvestrand.titrax-sheet
18119
+application/prs.cww cw cww
18120
+application/prs.nprend rnd rct
18121
+application/prs.plucker
18122
+application/prs.rdf-xml-crypt rdf-crypt
18123
+application/prs.xsf+xml xsf
18124
+application/pskc+xml pskcxml
18126
+application/rdf+xml rdf
18127
+application/reginfo+xml rif
18128
+application/relax-ng-compact-syntax rnc
18129
+application/remote-printing
18130
+application/resource-lists-diff+xml rld
18131
+application/resource-lists+xml rl
18132
+application/riscos
18133
+application/rlmi+xml
18134
+application/rls-services+xml rs
18135
+application/rtf rtf
18137
+application/samlassertion+xml
18138
+application/samlmetadata+xml
18139
+application/sbml+xml
18140
+application/scvp-cv-request scq
18141
+application/scvp-cv-response scs
18142
+application/scvp-vp-request spq
18143
+application/scvp-vp-response spp
18144
+application/sdp sdp
18145
+application/set-payment
18146
+application/set-payment-initiation
18147
+application/set-registration
18148
+application/set-registration-initiation
18150
+application/sgml-open-catalog soc
18151
+application/shf+xml shf
18152
+application/sieve siv sieve
18153
+application/simple-filter+xml cl
18154
+application/simple-message-summary
18155
+application/simpleSymbolContainer
18157
+# obsoleted by application/smil+xml
18158
+application/smil smil smi sml
18159
+# smil, smi: application/smil for now
18160
+application/smil+xml
18161
+application/soap+fastinfoset
18162
+application/soap+xml
18163
+application/sparql-query rq
18164
+application/sparql-results+xml srx
18165
+application/spirits-event+xml
18166
+application/srgs gram
18167
+application/srgs+xml grxml
18168
+application/sru+xml sru
18169
+application/ssml+xml ssml
18170
+application/tamp-apex-update tau
18171
+application/tamp-apex-update-confirm auc
18172
+application/tamp-community-update tcu
18173
+application/tamp-community-update-confirm cuc
18174
+application/tamp-error ter
18175
+application/tamp-sequence-adjust tsa
18176
+application/tamp-sequence-adjust-confirm sac
18177
+# tsq: application/timestamp-query
18178
+application/tamp-status-query
18179
+# tsr: application/timestamp-reply
18180
+application/tamp-status-response
18181
+application/tamp-update tur
18182
+application/tamp-update-confirm tuc
18183
+application/tei+xml tei teiCorpus odd
18184
+application/thraud+xml tfi
18185
+application/timestamp-query tsq
18186
+application/timestamp-reply tsr
18187
+application/timestamped-data tsd
18188
+application/tve-trigger
18189
+application/ulpfec
18191
+application/vnd.3gpp.bsf+xml
18192
+application/vnd.3gpp.pic-bw-large plb
18193
+application/vnd.3gpp.pic-bw-small psb
18194
+application/vnd.3gpp.pic-bw-var pvb
18195
+# sms: application/vnd.3gpp2.sms
18196
+application/vnd.3gpp.sms
18197
+application/vnd.3gpp2.bcmcsinfo+xml
18198
+application/vnd.3gpp2.sms sms
18199
+application/vnd.3gpp2.tcap tcap
18200
+application/vnd.3M.Post-it-Notes pwn
18201
+application/vnd.accpac.simply.aso aso
18202
+application/vnd.accpac.simply.imp imp
18203
+application/vnd.acucobol acu
18204
+application/vnd.acucorp atc acutc
18205
+application/vnd.adobe.fxp fxp fxpl
18206
+application/vnd.adobe.partial-upload
18207
+application/vnd.adobe.xdp+xml xdp
18208
+application/vnd.adobe.xfdf xfdf
18209
+application/vnd.aether.imp
18210
+application/vnd.ah-barcode
18211
+application/vnd.ahead.space ahead
18212
+application/vnd.airzip.filesecure.azf azf
18213
+application/vnd.airzip.filesecure.azs azs
18214
+application/vnd.americandynamics.acc acc
18215
+application/vnd.amiga.ami ami
18216
+application/vnd.amundsen.maze+xml
18217
+application/vnd.anser-web-certificate-issue-initiation cii
18218
+# Not in IANA listing, but is on FTP site?
18219
+application/vnd.anser-web-funds-transfer-initiation fti
18220
+# atx: audio/ATRAC-X
18221
+application/vnd.antix.game-component
18222
+application/vnd.apple.installer+xml dist distz pkg mpkg
18223
+# m3u: application/x-mpegurl for now
18224
+application/vnd.apple.mpegurl m3u8
18225
+application/vnd.aristanetworks.swi swi
18226
+application/vnd.audiograph aep
18227
+application/vnd.autopackage package
18228
+application/vnd.avistar+xml
18229
+application/vnd.blueice.multipass mpm
18230
+application/vnd.bluetooth.ep.oob ep
18231
+application/vnd.bmi bmi
18232
+application/vnd.businessobjects rep
18233
+application/vnd.cab-jscript
18234
+application/vnd.canon-cpdl
18235
+application/vnd.canon-lips
18236
+application/vnd.cendio.thinlinc.clientconf tlclient
18237
+application/vnd.chemdraw+xml cdxml
18238
+application/vnd.chipnuts.karaoke-mmd mmd
18239
+application/vnd.cinderella cdy
18240
+application/vnd.cirpack.isdn-ext
18241
+application/vnd.claymore cla
18242
+application/vnd.cloanto.rp9 rp9
18243
+application/vnd.clonk.c4group c4g c4d c4f c4p c4u
18244
+application/vnd.cluetrust.cartomobile-config c11amc
18245
+application/vnd.cluetrust.cartomobile-config-pkg c11amz
18246
+# icc: application/vnd.iccprofile
18247
+application/vnd.commerce-battelle ica icf icd ic0 ic1 ic2 ic3 ic4 ic5 ic6 ic7 ic8
18248
+application/vnd.commonspace csp cst
18249
+application/vnd.contact.cmsg cdbcmsg
18250
+application/vnd.cosmocaller cmc
18251
+application/vnd.crick.clicker clkx
18252
+application/vnd.crick.clicker.keyboard clkk
18253
+application/vnd.crick.clicker.palette clkp
18254
+application/vnd.crick.clicker.template clkt
18255
+application/vnd.crick.clicker.wordbank clkw
18256
+application/vnd.criticaltools.wbs+xml wbs
18257
+application/vnd.ctc-posml pml
18258
+application/vnd.ctct.ws+xml
18259
+application/vnd.cups-pdf
18260
+application/vnd.cups-postscript
18261
+application/vnd.cups-ppd ppd
18262
+application/vnd.cups-raster
18263
+application/vnd.cups-raw
18264
+application/vnd.curl curl
18265
+application/vnd.cybank
18266
+application/vnd.data-vision.rdz rdz
18267
+application/vnd.dece.data uvf uvvf uvd uvvd
18268
+application/vnd.dece.ttml+xml uvt uvvt
18269
+application/vnd.dece.unspecified uvx uvvx
18270
+application/vnd.denovo.fcselayout-link fe_launch
18271
+application/vnd.dir-bi.plate-dl-nosuffix
18272
+application/vnd.dna dna
18273
+application/vnd.dolby.mobile.1
18274
+application/vnd.dolby.mobile.2
18275
+application/vnd.dpgraph dpg mwc dpgraph
18276
+application/vnd.dreamfactory dfac
18277
+application/vnd.dvb.ait ait
18278
+# class: application/octet-stream
18279
+application/vnd.dvb.dvbj
18280
+application/vnd.dvb.esgcontainer
18281
+application/vnd.dvb.ipdcdftnotifaccess
18282
+application/vnd.dvb.ipdcesgaccess
18283
+application/vnd.dvb.ipdcesgaccess2
18284
+application/vnd.dvb.ipdcesgpdd
18285
+application/vnd.dvb.ipdcroaming
18286
+application/vnd.dvb.iptv.alfec-base
18287
+application/vnd.dvb.iptv.alfec-enhancement
18288
+application/vnd.dvb.notif-aggregate-root+xml
18289
+application/vnd.dvb.notif-container+xml
18290
+application/vnd.dvb.notif-generic+xml
18291
+application/vnd.dvb.notif-ia-msglist+xml
18292
+application/vnd.dvb.notif-ia-registration-request+xml
18293
+application/vnd.dvb.notif-ia-registration-response+xml
18294
+application/vnd.dvb.notif-init+xml
18295
+# pfr: application/font-tdpfr
18296
+application/vnd.dvb.pfr
18297
+application/vnd.dvb.service svc
18298
+# dxr: application/x-director
18299
+application/vnd.dxr
18300
+application/vnd.dynageo geo
18301
+application/vnd.easykaraoke.cdgdownload
18302
+application/vnd.ecdis-update
18303
+application/vnd.ecowin.chart mag
18304
+application/vnd.ecowin.filerequest
18305
+application/vnd.ecowin.fileupdate
18306
+application/vnd.ecowin.series
18307
+application/vnd.ecowin.seriesrequest
18308
+application/vnd.ecowin.seriesupdate
18309
+application/vnd.enliven nml
18310
+application/vnd.epson.esf esf
18311
+application/vnd.epson.msf msf
18312
+application/vnd.epson.quickanime qam
18313
+application/vnd.epson.salt slt
18314
+application/vnd.epson.ssf ssf
18315
+application/vnd.ericsson.quickcall qcall qca
18316
+application/vnd.eszigno3+xml es3 et3
18317
+application/vnd.etsi.aoc+xml
18318
+application/vnd.etsi.cug+xml
18319
+application/vnd.etsi.iptvcommand+xml
18320
+application/vnd.etsi.iptvdiscovery+xml
18321
+application/vnd.etsi.iptvprofile+xml
18322
+application/vnd.etsi.iptvsad-bc+xml
18323
+application/vnd.etsi.iptvsad-cod+xml
18324
+application/vnd.etsi.iptvsad-npvr+xml
18325
+application/vnd.etsi.iptvservice+xml
18326
+application/vnd.etsi.iptvsync+xml
18327
+application/vnd.etsi.iptvueprofile+xml
18328
+application/vnd.etsi.mcid+xml
18329
+application/vnd.etsi.overload-control-policy-dataset+xml
18330
+application/vnd.etsi.sci+xml
18331
+application/vnd.etsi.simservs+xml
18332
+application/vnd.etsi.tsl.der
18333
+application/vnd.etsi.tsl+xml
18334
+application/vnd.eudora.data
18335
+application/vnd.ezpix-album ez2
18336
+application/vnd.ezpix-package ez3
18337
+application/vnd.f-secure.mobile
18338
+application/vnd.fdf fdf
18339
+application/vnd.fdsn.mseed msd mseed
18340
+application/vnd.fdsn.seed seed dataless
18341
+application/vnd.ffsns
18342
+# all extensions: application/vnd.hbci
18343
+application/vnd.fints
18344
+application/vnd.FloGraphIt gph
18345
+application/vnd.fluxtime.clip ftc
18346
+application/vnd.font-fontforge-sfd sfd
18347
+application/vnd.framemaker fm
18348
+application/vnd.frogans.fnc fnc
18349
+application/vnd.frogans.ltf ltf
18350
+application/vnd.fsc.weblaunch fsc
18351
+application/vnd.fujitsu.oasys oas
18352
+application/vnd.fujitsu.oasys2 oa2
18353
+application/vnd.fujitsu.oasys3 oa3
18354
+application/vnd.fujitsu.oasysgp fg5
18355
+application/vnd.fujitsu.oasysprs bh2
18356
+application/vnd.fujixerox.ART-EX
18357
+application/vnd.fujixerox.ART4
18358
+application/vnd.fujixerox.ddd ddd
18359
+application/vnd.fujixerox.docuworks xdw
18360
+application/vnd.fujixerox.docuworks.binder xbd
18361
+application/vnd.fujixerox.HBPL
18362
+application/vnd.fut-misnet
18363
+application/vnd.fuzzysheet fzs
18364
+application/vnd.genomatix.tuxedo txd
18365
+application/vnd.geocube+xml g3 g³
18366
+application/vnd.geogebra.file ggb
18367
+application/vnd.geogebra.tool ggt
18368
+application/vnd.geometry-explorer gex gre
18369
+application/vnd.geonext gxt
18370
+application/vnd.geoplan g2w
18371
+application/vnd.geospace g3w
18372
+application/vnd.globalplatform.card-content-mgt
18373
+application/vnd.globalplatform.card-content-mgt-response
18374
+# application/vnd.gmx deprecated 2009-03-04
18375
+application/vnd.google-earth.kml+xml kml
18376
+application/vnd.google-earth.kmz kmz
18377
+application/vnd.grafeq gqf gqs
18378
+application/vnd.gridmp
18379
+application/vnd.groove-account gac
18380
+application/vnd.groove-help ghf
18381
+application/vnd.groove-identity-message gim
18382
+application/vnd.groove-injector grv
18383
+application/vnd.groove-tool-message gtm
18384
+application/vnd.groove-tool-template tpl
18385
+application/vnd.groove-vcard vcg
18386
+application/vnd.HandHeld-Entertainment+xml zmm
18387
+application/vnd.hbci hbci hbc kom upa pkd bpd
18388
+# rep: application/vnd.businessobjects
18389
+application/vnd.hcl-bireports
18390
+application/vnd.hhe.lesson-player les
18391
+application/vnd.hp-HPGL hpgl
18392
+application/vnd.hp-hpid hpi hpid
18393
+application/vnd.hp-hps hps
18394
+application/vnd.hp-jlyt jlt
18395
+application/vnd.hp-PCL pcl
18396
+application/vnd.hp-PCLXL
18397
+application/vnd.httphone
18398
+application/vnd.hydrostatix.sof-data sfd-hdstx
18399
+application/vnd.hzn-3d-crossword x3d
18400
+application/vnd.ibm.afplinedata
18401
+application/vnd.ibm.electronic-media emm
18402
+application/vnd.ibm.MiniPay mpy
18403
+application/vnd.ibm.modcap list3820 listafp afp pseg3820
18404
+application/vnd.ibm.rights-management irm
18405
+application/vnd.ibm.secure-container sc
18406
+application/vnd.iccprofile icc icm
18407
+application/vnd.igloader igl
18408
+application/vnd.immervision-ivp ivp
18409
+application/vnd.immervision-ivu ivu
18410
+application/vnd.informedcontrol.rms+xml
18411
+# application/vnd.informix-visionary obsoleted by application/vnd.visionary
18412
+application/vnd.infotech.project
18413
+application/vnd.infotech.project+xml
18414
+application/vnd.insors.igm igm
18415
+application/vnd.intercon.formnet xpw xpx
18416
+application/vnd.intergeo i2g
18417
+application/vnd.intertrust.digibox
18418
+application/vnd.intertrust.nncp
18419
+application/vnd.intu.qbo qbo
18420
+application/vnd.intu.qfx qfx
18421
+application/vnd.iptc.g2.conceptitem+xml
18422
+application/vnd.iptc.g2.knowledgeitem+xml
18423
+application/vnd.iptc.g2.newsitem+xml
18424
+application/vnd.iptc.g2.packageitem+xml
18425
+application/vnd.ipunplugged.rcprofile rcprofile
18426
+application/vnd.irepository.package+xml irp
18427
+application/vnd.is-xpr xpr
18428
+application/vnd.isac.fcs fcs
18429
+application/vnd.jam jam
18430
+application/vnd.japannet-directory-service
18431
+application/vnd.japannet-jpnstore-wakeup
18432
+application/vnd.japannet-payment-wakeup
18433
+application/vnd.japannet-registration
18434
+application/vnd.japannet-registration-wakeup
18435
+application/vnd.japannet-setstore-wakeup
18436
+application/vnd.japannet-verification
18437
+application/vnd.japannet-verification-wakeup
18438
+application/vnd.jcp.javame.midlet-rms rms
18439
+application/vnd.jisp jisp
18440
+application/vnd.joost.joda-archive joda
18441
+application/vnd.kahootz ktz ktr
18442
+application/vnd.kde.karbon karbon
18443
+application/vnd.kde.kchart chrt
18444
+application/vnd.kde.kformula kfo
18445
+application/vnd.kde.kivio flw
18446
+application/vnd.kde.kontour kon
18447
+application/vnd.kde.kpresenter kpr kpt
18448
+application/vnd.kde.kspread ksp
18449
+application/vnd.kde.kword kwd kwt
18450
+application/vnd.kenameaapp htke
18451
+application/vnd.kidspiration kia
18452
+application/vnd.Kinar kne knp sdf
18453
+application/vnd.koan skp skd skm skt
18454
+application/vnd.kodak-descriptor sse
18455
+application/vnd.las.las+xml lasxml
18456
+application/vnd.liberty-request+xml
18457
+application/vnd.llamagraphics.life-balance.desktop lbd
18458
+application/vnd.llamagraphics.life-balance.exchange+xml lbe
18459
+application/vnd.lotus-1-2-3 123 wk4 wk3 wk1
18460
+application/vnd.lotus-approach apr vew
18461
+application/vnd.lotus-freelance prz pre
18462
+application/vnd.lotus-notes nsf ntf ndl ns4 ns3 ns2 nsh nsg
18463
+application/vnd.lotus-organizer or3 or2 org
18464
+application/vnd.lotus-screencam scm
18465
+application/vnd.lotus-wordpro lwp sam
18466
+application/vnd.macports.portpkg portpkg
18467
+application/vnd.marlin.drm.actiontoken+xml
18468
+application/vnd.marlin.drm.conftoken+xml
18469
+application/vnd.marlin.drm.license+xml
18470
+application/vnd.marlin.drm.mdcf mdc
18471
+application/vnd.mcd mcd
18472
+application/vnd.medcalcdata mc1
18473
+application/vnd.mediastation.cdkey cdkey
18474
+application/vnd.meridian-slingshot
18475
+application/vnd.MFER mwf
18476
+application/vnd.mfmp mfm
18477
+application/vnd.micrografx.flo flo
18478
+application/vnd.micrografx.igx igx
18479
+application/vnd.mif mif
18480
+application/vnd.minisoft-hp3000-save
18481
+application/vnd.mitsubishi.misty-guard.trustweb
18482
+application/vnd.Mobius.DAF daf
18483
+application/vnd.Mobius.DIS dis
18484
+application/vnd.Mobius.MBK mbk
18485
+application/vnd.Mobius.MQY mqy
18486
+application/vnd.Mobius.MSL msl
18487
+application/vnd.Mobius.PLC plc
18488
+application/vnd.Mobius.TXF txf
18489
+application/vnd.mophun.application mpn
18490
+application/vnd.mophun.certificate mpc
18491
+application/vnd.motorola.flexsuite
18492
+application/vnd.motorola.flexsuite.adsi
18493
+application/vnd.motorola.flexsuite.fis
18494
+application/vnd.motorola.flexsuite.gotap
18495
+application/vnd.motorola.flexsuite.kmr
18496
+application/vnd.motorola.flexsuite.ttc
18497
+application/vnd.motorola.flexsuite.wem
18498
+application/vnd.motorola.iprm
18499
+application/vnd.mozilla.xul+xml xul
18500
+application/vnd.ms-artgalry cil
18501
+application/vnd.ms-asf asf
18502
+application/vnd.ms-cab-compressed cab
18503
+application/vnd.ms-excel xls
18504
+application/vnd.ms-excel.template.macroEnabled.12 xltm
18505
+application/vnd.ms-excel.addin.macroEnabled.12 xlam
18506
+application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
18507
+application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
18508
+application/vnd.ms-fontobject eot
18509
+application/vnd.ms-htmlhelp chm
18510
+application/vnd.ms-ims ims
18511
+application/vnd.ms-lrm lrm
18512
+application/vnd.ms-office.activeX+xml
18513
+application/vnd.ms-officetheme thmx
18514
+application/vnd.ms-playready.initiator+xml
18515
+application/vnd.ms-powerpoint ppt
18516
+application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
18517
+application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
18518
+application/vnd.ms-powerpoint.slide.macroEnabled.12 sldm
18519
+application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
18520
+application/vnd.ms-powerpoint.template.macroEnabled.12 potm
18521
+application/vnd.ms-project mpp
18522
+application/vnd.ms-tnef tnef tnf
18523
+application/vnd.ms-wmdrm.lic-chlg-req
18524
+application/vnd.ms-wmdrm.lic-resp
18525
+application/vnd.ms-wmdrm.meter-chlg-req
18526
+application/vnd.ms-wmdrm.meter-resp
18527
+application/vnd.ms-word.document.macroEnabled.12 docm
18528
+application/vnd.ms-word.template.macroEnabled.12 dotm
18529
+application/vnd.ms-works wcm wdb wks wps
18530
+application/vnd.ms-wpl wpl
18531
+application/vnd.ms-xpsdocument xps
18532
+application/vnd.mseq mseq
18533
+application/vnd.msign
18534
+application/vnd.multiad.creator crtr
18535
+application/vnd.multiad.creator.cif cif
18536
+application/vnd.music-niff
18537
+application/vnd.musician mus
18538
+application/vnd.muvee.style msty
18539
+application/vnd.ncd.control
18540
+application/vnd.ncd.reference
18541
+application/vnd.nervana entity request bkm kcm
18542
+application/vnd.netfpx
18543
+application/vnd.neurolanguage.nlu nlu
18544
+application/vnd.noblenet-directory nnd
18545
+application/vnd.noblenet-sealer nns
18546
+application/vnd.noblenet-web nnw
18547
+application/vnd.nokia.catalogs
18548
+application/vnd.nokia.conml+wbxml
18549
+application/vnd.nokia.conml+xml
18550
+application/vnd.nokia.iptv.config+xml
18551
+application/vnd.nokia.iSDS-radio-presets
18552
+application/vnd.nokia.landmark+wbxml
18553
+application/vnd.nokia.landmark+xml
18554
+application/vnd.nokia.landmarkcollection+xml
18555
+application/vnd.nokia.n-gage.ac+xml ac
18556
+application/vnd.nokia.n-gage.data ngdat
18557
+application/vnd.nokia.n-gage.symbian.install n-gage
18558
+application/vnd.nokia.ncd
18559
+application/vnd.nokia.pcd+wbxml
18560
+application/vnd.nokia.pcd+xml
18561
+application/vnd.nokia.radio-preset rpst
18562
+application/vnd.nokia.radio-presets rpss
18563
+application/vnd.novadigm.EDM edm
18564
+application/vnd.novadigm.EDX edx
18565
+application/vnd.novadigm.EXT ext
18566
+application/vnd.ntt-local.file-transfer
18567
+application/vnd.ntt-local.sip-ta_remote
18568
+application/vnd.ntt-local.sip-ta_tcp_stream
18569
+application/vnd.oasis.opendocument.chart odc
18570
+application/vnd.oasis.opendocument.chart-template otc
18571
+application/vnd.oasis.opendocument.database odb
18572
+application/vnd.oasis.opendocument.formula odf
18573
+application/vnd.oasis.opendocument.formula-template otf
18574
+application/vnd.oasis.opendocument.graphics odg
18575
+application/vnd.oasis.opendocument.graphics-template otg
18576
+application/vnd.oasis.opendocument.image odi
18577
+application/vnd.oasis.opendocument.image-template oti
18578
+application/vnd.oasis.opendocument.presentation odp
18579
+application/vnd.oasis.opendocument.presentation-template otp
18580
+application/vnd.oasis.opendocument.spreadsheet ods
18581
+application/vnd.oasis.opendocument.spreadsheet-template ots
18582
+application/vnd.oasis.opendocument.text odt
18583
+application/vnd.oasis.opendocument.text-master odm
18584
+application/vnd.oasis.opendocument.text-template ott
18585
+application/vnd.oasis.opendocument.text-web oth
18586
+application/vnd.obn
18587
+application/vnd.oipf.contentaccessdownload+xml
18588
+application/vnd.oipf.contentaccessstreaming+xml
18589
+application/vnd.oipf.cspg-hexbinary
18590
+application/vnd.oipf.dae.svg+xml
18591
+application/vnd.oipf.dae.xhtml+xml
18592
+application/vnd.oipf.mippvcontrolmessage+xml
18593
+application/vnd.oipf.pae.gem
18594
+application/vnd.oipf.spdiscovery+xml
18595
+application/vnd.oipf.spdlist+xml
18596
+application/vnd.oipf.ueprofile+xml
18597
+application/vnd.olpc-sugar xo
18598
+application/vnd.oma.bcast.associated-procedure-parameter+xml
18599
+application/vnd.oma.bcast.drm-trigger+xml
18600
+application/vnd.oma.bcast.imd+xml
18601
+application/vnd.oma.bcast.ltkm
18602
+application/vnd.oma.bcast.notification+xml
18603
+application/vnd.oma.bcast.provisioningtrigger
18604
+application/vnd.oma.bcast.sgboot
18605
+application/vnd.oma.bcast.sgdd+xml
18606
+application/vnd.oma.bcast.sgdu
18607
+application/vnd.oma.bcast.simple-symbol-container
18608
+application/vnd.oma.bcast.smartcard-trigger+xml
18609
+application/vnd.oma.bcast.sprov+xml
18610
+application/vnd.oma.bcast.stkm
18611
+application/vnd.oma.cab-address-book+xml
18612
+application/vnd.oma.cab-feature-handler+xml
18613
+application/vnd.oma.cab-pcc+xml
18614
+application/vnd.oma.cab-user-prefs+xml
18615
+application/vnd.oma.dcd
18616
+application/vnd.oma.dcdc
18617
+application/vnd.oma.dd2+xml dd2
18618
+application/vnd.oma.drm.risd+xml
18619
+application/vnd.oma.group-usage-list+xml
18620
+application/vnd.oma.poc.detailed-progress-report+xml
18621
+application/vnd.oma.poc.final-report+xml
18622
+application/vnd.oma.poc.groups+xml
18623
+application/vnd.oma.poc.invocation-descriptor+xml
18624
+application/vnd.oma.poc.optimized-progress-report+xml
18625
+application/vnd.oma.push
18626
+application/vnd.oma.scidm.messages+xml
18627
+application/vnd.oma.xcap-directory+xml
18628
+application/vnd.oma-scws-config
18629
+application/vnd.oma-scws-http-request
18630
+application/vnd.oma-scws-http-response
18631
+application/vnd.omads-email+xml
18632
+application/vnd.omads-file+xml
18633
+application/vnd.omads-folder+xml
18634
+application/vnd.omaloc-supl-init
18635
+application/vnd.openofficeorg.extension oxt
18636
+application/vnd.openxmlformats-officedocument.custom-properties+xml
18637
+application/vnd.openxmlformats-officedocument.customXmlProperties+xml
18638
+application/vnd.openxmlformats-officedocument.drawing+xml
18639
+application/vnd.openxmlformats-officedocument.drawingml.chart+xml
18640
+application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml
18641
+application/vnd.openxmlformats-officedocument.drawingml.diagramColors+xml
18642
+application/vnd.openxmlformats-officedocument.drawingml.diagramData+xml
18643
+application/vnd.openxmlformats-officedocument.drawingml.diagramLayout+xml
18644
+application/vnd.openxmlformats-officedocument.drawingml.diagramStyle+xml
18645
+application/vnd.openxmlformats-officedocument.extended-properties+xml
18646
+application/vnd.openxmlformats-officedocument.presentationml.commentAuthors+xml
18647
+application/vnd.openxmlformats-officedocument.presentationml.comments+xml
18648
+application/vnd.openxmlformats-officedocument.presentationml.handoutMaster+xml
18649
+application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml
18650
+application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml
18651
+application/vnd.openxmlformats-officedocument.presentationml.presProps+xml
18652
+application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
18653
+application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml
18654
+application/vnd.openxmlformats-officedocument.presentationml.slide sldx
18655
+application/vnd.openxmlformats-officedocument.presentationml.slide+xml
18656
+application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml
18657
+application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml
18658
+application/vnd.openxmlformats-officedocument.presentationml.slideUpdateInfo+xml
18659
+application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
18660
+application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml
18661
+application/vnd.openxmlformats-officedocument.presentationml.tableStyles+xml
18662
+application/vnd.openxmlformats-officedocument.presentationml.tags+xml
18663
+application/vnd.openxmlformats-officedocument.presentationml.template potx
18664
+application/vnd.openxmlformats-officedocument.presentationml.template.main+xml
18665
+application/vnd.openxmlformats-officedocument.presentationml.viewProps+xml
18666
+application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml
18667
+application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml
18668
+application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml
18669
+application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml
18670
+application/vnd.openxmlformats-officedocument.spreadsheetml.dialogsheet+xml
18671
+application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml
18672
+application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml
18673
+application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml
18674
+application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml
18675
+application/vnd.openxmlformats-officedocument.spreadsheetml.queryTable+xml
18676
+application/vnd.openxmlformats-officedocument.spreadsheetml.revisionHeaders+xml
18677
+application/vnd.openxmlformats-officedocument.spreadsheetml.revisionLog+xml
18678
+application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml
18679
+application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
18680
+application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml
18681
+application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml
18682
+application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml
18683
+application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml
18684
+application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml
18685
+application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx
18686
+application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml
18687
+application/vnd.openxmlformats-officedocument.spreadsheetml.userNames+xml
18688
+application/vnd.openxmlformats-officedocument.spreadsheetml.volatileDependencies+xml
18689
+application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml
18690
+application/vnd.openxmlformats-officedocument.theme+xml
18691
+application/vnd.openxmlformats-officedocument.themeOverride+xml
18692
+application/vnd.openxmlformats-officedocument.vmlDrawing
18693
+application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml
18694
+application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
18695
+application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml
18696
+application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml
18697
+application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml
18698
+application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml
18699
+application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml
18700
+application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml
18701
+application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml
18702
+application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml
18703
+application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml
18704
+application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
18705
+application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml
18706
+application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml
18707
+application/vnd.openxmlformats-package.core-properties+xml
18708
+application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml
18709
+application/vnd.openxmlformats-package.relationships+xml
18710
+application/vnd.osa.netdeploy ndc
18711
+application/vnd.osgeo.mapguide.package mgp
18712
+# jar: application/x-java-archive
18713
+application/vnd.osgi.bundle
18714
+application/vnd.osgi.dp dp
18715
+application/vnd.otps.ct-kip+xml
18716
+application/vnd.palm prc pdb pqa oprc
18717
+application/vnd.paos+xml
18718
+application/vnd.pawaafile paw
18719
+application/vnd.pg.format str
18720
+application/vnd.pg.osasli ei6
18721
+application/vnd.piaccess.application-license pil
18722
+application/vnd.picsel efif
18723
+application/vnd.pmi.widget wg
18724
+application/vnd.poc.group-advertisement+xml
18725
+application/vnd.pocketlearn plf
18726
+application/vnd.powerbuilder6 pbd
18727
+application/vnd.powerbuilder6-s
18728
+application/vnd.powerbuilder7
18729
+application/vnd.powerbuilder7-s
18730
+application/vnd.powerbuilder75
18731
+application/vnd.powerbuilder75-s
18732
+application/vnd.preminet preminet
18733
+application/vnd.previewsystems.box box vbox
18734
+application/vnd.proteus.magazine mgz
18735
+application/vnd.publishare-delta-tree qps
18736
+# pti: image/prs.pti
18737
+application/vnd.pvi.ptid1 ptid
18738
+application/vnd.pwg-multiplexed
18739
+application/vnd.pwg-xhtml-print+xml
18740
+application/vnd.qualcomm.brew-app-res bar
18741
+application/vnd.Quark.QuarkXPress qxd qxt qwd qwt qxl qxb
18742
+application/vnd.quobject-quoxdocument quox quiz
18743
+application/vnd.radisys.moml+xml
18744
+application/vnd.radisys.msml-audit-conf+xml
18745
+application/vnd.radisys.msml-audit-conn+xml
18746
+application/vnd.radisys.msml-audit-dialog+xml
18747
+application/vnd.radisys.msml-audit-stream+xml
18748
+application/vnd.radisys.msml-audit+xml
18749
+application/vnd.radisys.msml-conf+xml
18750
+application/vnd.radisys.msml-dialog-base+xml
18751
+application/vnd.radisys.msml-dialog-fax-detect+xml
18752
+application/vnd.radisys.msml-dialog-fax-sendrecv+xml
18753
+application/vnd.radisys.msml-dialog-group+xml
18754
+application/vnd.radisys.msml-dialog-speech+xml
18755
+application/vnd.radisys.msml-dialog-transform+xml
18756
+application/vnd.radisys.msml-dialog+xml
18757
+application/vnd.radisys.msml+xml
18758
+application/vnd.rainstor.data tree
18759
+application/vnd.rapid
18760
+application/vnd.realvnc.bed bed
18761
+application/vnd.recordare.musicxml mxl
18762
+application/vnd.recordare.musicxml+xml
18763
+application/vnd.RenLearn.rlprint
18764
+application/vnd.rig.cryptonote cryptonote
18765
+application/vnd.route66.link66+xml link66
18766
+application/vnd.ruckus.download
18767
+application/vnd.s3sms
18768
+application/vnd.sailingtracker.track st
18769
+application/vnd.sbm.cid
18770
+application/vnd.sbm.mid2
18771
+application/vnd.scribus scd sla slaz
18772
+application/vnd.sealed.3df s3df
18773
+application/vnd.sealed.csf scsf
18774
+application/vnd.sealed.doc sdoc sdo s1w
18775
+application/vnd.sealed.eml seml sem
18776
+application/vnd.sealed.mht smht smh
18777
+application/vnd.sealed.net
18778
+# spp: application/scvp-vp-response
18779
+application/vnd.sealed.ppt sppt s1p
18780
+application/vnd.sealed.tiff stif
18781
+application/vnd.sealed.xls sxls sxl s1e
18782
+# stm: audio/x-stm
18783
+application/vnd.sealedmedia.softseal.html stml s1h
18784
+application/vnd.sealedmedia.softseal.pdf spdf spd s1a
18785
+application/vnd.seemail see
18786
+application/vnd.sema sema
18787
+application/vnd.semd semd
18788
+application/vnd.semf semf
18789
+application/vnd.shana.informed.formdata ifm
18790
+application/vnd.shana.informed.formtemplate itp
18791
+application/vnd.shana.informed.interchange iif
18792
+application/vnd.shana.informed.package ipk
18793
+application/vnd.SimTech-MindMapper twd twds
18794
+application/vnd.smaf mmf
18795
+application/vnd.smart.notebook notebook
18796
+application/vnd.smart.teacher teacher
18797
+application/vnd.software602.filler.form+xml fo
18798
+application/vnd.software602.filler.form-xml-zip zfo
18799
+application/vnd.solent.sdkm+xml sdkm sdkd
18800
+application/vnd.spotfire.dxp dxp
18801
+application/vnd.spotfire.sfs sfs
18802
+application/vnd.sss-cod
18803
+application/vnd.sss-dtf
18804
+application/vnd.sss-ntf
18805
+application/vnd.stepmania.stepchart sm
18806
+application/vnd.street-stream
18807
+application/vnd.sun.wadl+xml wadl
18808
+application/vnd.sus-calendar sus susp
18809
+application/vnd.svd
18810
+application/vnd.swiftview-ics
18811
+application/vnd.syncml.dm.notification
18812
+application/vnd.syncml.ds.notification
18813
+application/vnd.syncml.dm+wbxml bdm
18814
+application/vnd.syncml.dm+xml xdm
18815
+application/vnd.syncml+xml xsm
18816
+application/vnd.tao.intent-module-archive tao
18817
+application/vnd.tmobile-livetv tmo
18818
+application/vnd.trid.tpt tpt
18819
+application/vnd.triscape.mxs mxs
18820
+application/vnd.trueapp tra
18821
+application/vnd.truedoc
18822
+# cab: application/vnd.ms-cab-compressed
18823
+application/vnd.ubisoft.webplayer
18824
+application/vnd.ufdl ufdl ufd frm
18825
+application/vnd.uiq.theme utz
18826
+application/vnd.umajin umj
18827
+application/vnd.unity unityweb
18828
+application/vnd.uoml+xml uoml uo
18829
+application/vnd.uplanet.alert
18830
+application/vnd.uplanet.alert-wbxml
18831
+application/vnd.uplanet.bearer-choice
18832
+application/vnd.uplanet.bearer-choice-wbxml
18833
+application/vnd.uplanet.cacheop
18834
+application/vnd.uplanet.cacheop-wbxml
18835
+application/vnd.uplanet.channel
18836
+application/vnd.uplanet.channel-wbxml
18837
+application/vnd.uplanet.list
18838
+application/vnd.uplanet.list-wbxml
18839
+application/vnd.uplanet.listcmd
18840
+application/vnd.uplanet.listcmd-wbxml
18841
+application/vnd.uplanet.signal
18842
+application/vnd.vcx vcx
18843
+# sxi: application/vnd.sun.xml.impress
18844
+application/vnd.vd-study mxi study-inter model-inter
18845
+# mcd: application/vnd.mcd
18846
+application/vnd.vectorworks vwx
18847
+application/vnd.verimatrix.vcas
18848
+application/vnd.vidsoft.vidconference vsc
18849
+application/vnd.visio vsd vst vsw vss
18850
+application/vnd.visionary vis
18851
+# vsc: application/vnd.vidsoft.vidconference
18852
+application/vnd.vividence.scriptfile
18853
+application/vnd.vsf vsf
18854
+application/vnd.wap.sic sic
18855
+application/vnd.wap.slc slc
18856
+application/vnd.wap.wbxml wbxml
18857
+application/vnd.wap.wmlc wmlc
18858
+application/vnd.wap.wmlscriptc wmlsc
18859
+application/vnd.webturbo wtb
18860
+application/vnd.wfa.wsc wsc
18861
+application/vnd.wmc wmc
18862
+application/vnd.wmf.bootstrap
18863
+# nb: application/mathematica for now
18864
+application/vnd.wolfram.mathematica
18865
+application/vnd.wolfram.mathematica.package m
18866
+application/vnd.wolfram.player nbp
18867
+application/vnd.wordperfect wpd
18868
+application/vnd.wqd wqd
18869
+application/vnd.wrq-hp3000-labelled
18870
+application/vnd.wt.stf stf
18871
+application/vnd.wv.csp+xml
18872
+application/vnd.wv.csp+wbxml wv
18873
+application/vnd.wv.ssp+xml
18874
+application/vnd.xara xar
18875
+application/vnd.xfdl xfdl xfd
18876
+application/vnd.xfdl.webform
18877
+application/vnd.xmi+xml
18878
+application/vnd.xmpie.cpkg cpkg
18879
+application/vnd.xmpie.dpkg dpkg
18880
+# dpkg: application/vnd.xmpie.dpkg
18881
+application/vnd.xmpie.plan
18882
+application/vnd.xmpie.ppkg ppkg
18883
+application/vnd.xmpie.xlim xlim
18884
+application/vnd.yamaha.hv-dic hvd
18885
+application/vnd.yamaha.hv-script hvs
18886
+application/vnd.yamaha.hv-voice hvp
18887
+application/vnd.yamaha.openscoreformat osf
18888
+application/vnd.yamaha.openscoreformat.osfpvg+xml
18889
+application/vnd.yamaha.remote-setup
18890
+application/vnd.yamaha.smaf-audio saf
18891
+application/vnd.yamaha.smaf-phrase spf
18892
+application/vnd.yamaha.tunnel-udpencap
18893
+application/vnd.yellowriver-custom-menu cmp
18894
+application/vnd.zul zir zirz
18895
+application/vnd.zzazz.deck+xml zaz
18896
+application/voicexml+xml vxml
18897
+application/vq-rtcp-xr
18898
+application/watcherinfo+xml wif
18899
+application/whoispp-query
18900
+application/whoispp-response
18901
+application/widget wgt
18903
+application/wordperfect5.1
18904
+application/wsdl+xml wsdl
18905
+application/wspolicy+xml wspolicy
18906
+application/x400-bp
18907
+application/xcap-att+xml xav
18908
+application/xcap-caps+xml xca
18909
+application/xcap-diff+xml xdf
18910
+application/xcap-el+xml xel
18911
+application/xcap-error+xml xer
18912
+application/xcap-ns+xml xns
18913
+application/xcon-conference-info-diff+xml
18914
+application/xcon-conference-info+xml
18915
+application/xenc+xml
18916
+application/xhtml+xml xhtml xhtm xht
18917
+# application/xhtml-voice+xml obsoleted by application/xv+xml
18918
+# xml, xsd, rng: text/xml
18920
+# mod: audio/x-mod
18921
+application/xml-dtd dtd
18922
+# ent: text/xml-external-parsed-entity
18923
+application/xml-external-parsed-entity
18924
+application/xmpp+xml
18925
+application/xop+xml xop
18926
+application/xslt+xml xsl xslt
18927
+application/xv+xml mxml xhvml xvml xvm
18928
+application/yang yang
18929
+application/yin+xml yin
18930
+application/zip zip
18931
+audio/1d-interleaved-parityfec
18932
+audio/32kadpcm 726
18933
+# 3gp, 3gpp: video/3gpp
18935
+# 3g2, 3gpp2: video/3gpp2
18942
+# aa3, omg: audio/ATRAC3
18943
+audio/ATRAC-ADVANCED-LOSSLESS aal
18944
+# aa3, omg: audio/ATRAC3
18946
+audio/ATRAC3 at3 aa3 omg
18947
+audio/basic au snd
18954
+audio/dsr-es201108
18955
+audio/dsr-es202050
18956
+audio/dsr-es202211
18957
+audio/dsr-es202212
18961
+# qcp: audio/qcelp
18994
+audio/mobile-xmf mxmf
18995
+# mp4, mpg4: video/mp4, see RFC 4337
19000
+audio/mpeg mp3 mpga mp1 mp2
19001
+audio/mpeg4-generic
19002
+audio/ogg oga ogg spx
19008
+audio/prs.sid sid psid
19011
+audio/rtp-enc-aescm128
19015
+# qcp: audio/qcelp, see RFC 3625
19023
+audio/telephone-event
19029
+audio/vnd.3gpp.iufp
19031
+audio/vnd.audikoz koz
19033
+audio/vnd.cisco.nse
19034
+audio/vnd.cmles.radio-events
19035
+audio/vnd.cns.anp1
19036
+audio/vnd.cns.inf1
19037
+audio/vnd.dece.audio uva uvva
19038
+audio/vnd.digital-winds eol
19039
+audio/vnd.dlna.adts
19040
+audio/vnd.dolby.heaac.1
19041
+audio/vnd.dolby.heaac.2
19042
+audio/vnd.dolby.mlp mlp
19043
+audio/vnd.dolby.mps
19044
+audio/vnd.dolby.pl2
19045
+audio/vnd.dolby.pl2x
19046
+audio/vnd.dolby.pl2z
19047
+audio/vnd.dolby.pulse.1
19049
+# wav: audio/wav, cpt: application/mac-compactpro
19051
+audio/vnd.dts.hd dtshd
19052
+audio/vnd.dvb.file dvb
19053
+audio/vnd.everad.plj plj
19054
+# rm: audio/x-pn-realaudio
19055
+audio/vnd.hns.audio
19056
+audio/vnd.lucent.voice lvp
19057
+audio/vnd.ms-playready.media.pya pya
19058
+# mxmf: audio/mobile-xmf
19059
+audio/vnd.nokia.mobile-xmf
19060
+audio/vnd.nortel.vbk vbk
19061
+audio/vnd.nuera.ecelp4800 ecelp4800
19062
+audio/vnd.nuera.ecelp7470 ecelp7470
19063
+audio/vnd.nuera.ecelp9600 ecelp9600
19064
+audio/vnd.octel.sbc
19065
+# audio/vnd.qcelp deprecated in favour of audio/qcelp
19066
+audio/vnd.rhetorex.32kadpcm
19068
+audio/vnd.sealedmedia.softseal.mpeg smp3 smp s1m
19069
+audio/vnd.vmx.cvsd
19071
+audio/vorbis-config
19073
+image/fits fits fit fts
19077
+image/jp2 jp2 jpg2
19078
+image/jpeg jpg jpeg jpe jfif
19079
+image/jpm jpm jpgm
19084
+image/prs.btif btif btf
19086
+image/svg+xml svg svgz
19088
+image/tiff tiff tif
19090
+image/vnd.adobe.photoshop psd
19091
+image/vnd.cns.inf2
19092
+image/vnd.dece.graphic uvi uvvi uvg uvvg
19093
+image/vnd.djvu djvu djv
19094
+image/vnd.dvb.subtitle sub
19097
+image/vnd.fastbidsheet fbs
19100
+image/vnd.fujixerox.edmics-mmr mmr
19101
+image/vnd.fujixerox.edmics-rlc rlc
19102
+image/vnd.globalgraphics.pgb pgb
19103
+image/vnd.microsoft.icon ico
19105
+image/vnd.ms-modi mdi
19107
+image/vnd.radiance hdr rgbe xyze
19108
+image/vnd.sealed.png spng spn s1n
19109
+image/vnd.sealedmedia.softseal.gif sgif sgi s1g
19110
+image/vnd.sealedmedia.softseal.jpg sjpg sjp s1j
19112
+image/vnd.wap.wbmp wbmp
19113
+image/vnd.xiff xif
19115
+message/delivery-status
19116
+message/disposition-notification
19117
+message/external-body
19118
+message/feedback-report
19119
+message/global u8msg
19120
+message/global-delivery-status u8dsn
19121
+message/global-disposition-notification u8mdn
19122
+message/global-headers u8hdr
19124
+# cl: application/simple-filter+xml
19126
+# message/news obsoleted by message/rfc822
19128
+message/rfc822 eml mail art
19132
+message/tracking-status
19133
+message/vnd.si.simp
19134
+model/iges igs iges
19135
+model/mesh msh mesh silo
19136
+model/vnd.collada+xml dae
19138
+# 3dml, 3dm: text/vnd.in3d.3dml
19139
+model/vnd.flatland.3dml
19140
+model/vnd.gdl gdl gsm win dor lmp rsm msm ism
19143
+model/vnd.moml+xml moml
19145
+model/vnd.parasolid.transmit.binary x_b xmt_bin
19146
+model/vnd.parasolid.transmit.text x_t xmt_txt
19148
+model/vrml wrl vrml
19149
+multipart/alternative
19150
+multipart/appledouble
19151
+multipart/byteranges
19153
+multipart/encrypted
19154
+multipart/form-data
19155
+multipart/header-set
19157
+multipart/parallel
19161
+multipart/voice-message vpm
19162
+text/1d-interleaved-parityfec
19163
+text/calendar ics ifb
19168
+# text/ecmascript obsoleted by application/ecmascript
19170
+text/html html htm
19171
+# text/javascript obsoleted by application/javascript
19174
+text/plain txt asc text pm el c h cc hh cxx hxx f90
19175
+text/prs.fallenstein.rst rst
19176
+text/prs.lines.tag tag dsc
19178
+text/rfc822-headers
19180
+# rtf: application/rtf
19182
+text/rtp-enc-aescm128
19184
+text/sgml sgml sgm
19186
+text/tab-separated-values tsv
19190
+text/uri-list uris uri
19192
+# curl: application/vnd.curl
19194
+text/vnd.DMClientScript dms
19195
+text/vnd.esmertec.theme-descriptor jtd
19197
+text/vnd.fmi.flexstor flx
19198
+text/vnd.graphviz gv dot
19199
+text/vnd.in3d.3dml 3dml 3dm
19200
+text/vnd.in3d.spot spot spo
19201
+text/vnd.IPTC.NewsML
19202
+text/vnd.IPTC.NITF
19204
+text/vnd.motorola.reflex
19205
+text/vnd.ms-mediapackage mpf
19206
+text/vnd.net2phone.commcenter.command ccc
19207
+text/vnd.radisys.msml-basic-layout
19208
+text/vnd.si.uricatalogue uric
19209
+text/vnd.sun.j2me.app-descriptor jad
19210
+text/vnd.trolltech.linguist ts
19211
+text/vnd.wap.si si
19212
+text/vnd.wap.sl sl
19213
+text/vnd.wap.wml wml
19214
+text/vnd.wap.wmlscript wmls
19215
+text/xml xml xsd rng
19216
+text/xml-external-parsed-entity ent
19217
+video/1d-interleaved-parityfec
19218
+video/3gpp 3gp 3gpp
19219
+video/3gpp2 3g2 3gpp2
19234
+video/mj2 mj2 mjp2
19238
+video/mp4 mp4 mpg4
19240
+video/mpeg mpeg mpg mpe
19241
+video/mpeg4-generic
19247
+video/quicktime mov qt
19249
+video/rtp-enc-aescm128
19255
+video/vnd.dece.hd uvh uvvh
19256
+video/vnd.dece.mobile uvm uvvm
19257
+video/vnd.dece.mp4 uvu uvvu
19258
+video/vnd.dece.pd uvp uvvp
19259
+video/vnd.dece.sd uvs uvvs
19260
+video/vnd.dece.video uvv uvvv
19261
+video/vnd.directv.mpeg
19262
+video/vnd.directv.mpeg-tts
19263
+video/vnd.dlna.mpeg-tts
19265
+# rm: audio/x-pn-realaudio
19266
+video/vnd.hns.video
19267
+video/vnd.iptvforum.1dparityfec-1010
19268
+video/vnd.iptvforum.1dparityfec-2005
19269
+video/vnd.iptvforum.2dparityfec-1010
19270
+video/vnd.iptvforum.2dparityfec-2005
19271
+video/vnd.iptvforum.ttsavc
19272
+video/vnd.iptvforum.ttsmpeg2
19273
+video/vnd.motorola.video
19274
+video/vnd.motorola.videop
19275
+video/vnd.mpegurl mxu m4u
19276
+video/vnd.ms-playready.media.pyv pyv
19277
+video/vnd.nokia.interleaved-multimedia nim
19278
+video/vnd.nokia.videovoip
19280
+video/vnd.objectvideo
19281
+video/vnd.sealed.mpeg1 smpg s11
19282
+# smpg: video/vnd.sealed.mpeg1
19283
+video/vnd.sealed.mpeg4 s14
19284
+video/vnd.sealed.swf sswf ssw
19285
+video/vnd.sealedmedia.softseal.mov smov smo s1q
19286
+# uvu, uvvu: video/vnd.dece.mp4
19287
+video/vnd.uvvu.mp4
19292
+application/epub+zip epub
19293
+application/mac-compactpro cpt
19294
+application/metalink+xml metalink
19295
+application/rss+xml rss
19296
+application/vnd.android.package-archive apk
19297
+application/vnd.oma.dd+xml dd
19298
+application/vnd.oma.drm.content dcf
19299
+# odf: application/vnd.oasis.opendocument.formula
19300
+application/vnd.oma.drm.dcf o4a o4v
19301
+application/vnd.oma.drm.message dm
19302
+application/vnd.oma.drm.rights+wbxml drc
19303
+application/vnd.oma.drm.rights+xml dr
19304
+application/vnd.sun.xml.calc sxc
19305
+application/vnd.sun.xml.calc.template stc
19306
+application/vnd.sun.xml.draw sxd
19307
+application/vnd.sun.xml.draw.template std
19308
+application/vnd.sun.xml.impress sxi
19309
+application/vnd.sun.xml.impress.template sti
19310
+application/vnd.sun.xml.math sxm
19311
+application/vnd.sun.xml.writer sxw
19312
+application/vnd.sun.xml.writer.global sxg
19313
+application/vnd.sun.xml.writer.template stw
19314
+application/vnd.symbian.install sis
19315
+application/vnd.wap.mms-message mms
19316
+application/x-annodex anx
19317
+application/x-bcpio bcpio
19318
+application/x-bittorrent torrent
19319
+application/x-bzip2 bz2
19320
+application/x-cdlink vcd
19321
+application/x-chess-pgn pgn
19322
+application/x-cpio cpio
19323
+application/x-csh csh
19324
+application/x-director dcr dir dxr
19325
+application/x-dvi dvi
19326
+application/x-futuresplash spl
19327
+application/x-gtar gtar
19328
+application/x-gzip gz tgz
19329
+application/x-hdf hdf
19330
+application/x-java-archive jar
19331
+application/x-java-jnlp-file jnlp
19332
+application/x-java-pack200 pack
19333
+application/x-killustrator kil
19334
+application/x-latex latex
19335
+application/x-netcdf nc cdf
19336
+application/x-perl pl
19337
+application/x-rpm rpm
19338
+application/x-sh sh
19339
+application/x-shar shar
19340
+application/x-shockwave-flash swf
19341
+application/x-stuffit sit
19342
+application/x-sv4cpio sv4cpio
19343
+application/x-sv4crc sv4crc
19344
+application/x-tar tar
19345
+application/x-tcl tcl
19346
+application/x-tex tex
19347
+application/x-texinfo texinfo texi
19348
+application/x-troff t tr roff
19349
+application/x-troff-man man 1 2 3 4 5 6 7 8
19350
+application/x-troff-me me
19351
+application/x-troff-ms ms
19352
+application/x-ustar ustar
19353
+application/x-wais-source src
19354
+application/x-xpinstall xpi
19355
+application/x-xspf+xml xspf
19356
+application/x-xz xz
19357
+audio/midi mid midi kar
19358
+audio/x-aiff aif aiff aifc
19359
+audio/x-annodex axa
19361
+audio/x-mod mod ult uni m15 mtm 669 med
19362
+audio/x-mpegurl m3u
19363
+audio/x-ms-wax wax
19364
+audio/x-ms-wma wma
19365
+audio/x-pn-realaudio ram rm
19366
+audio/x-realaudio ra
19370
+chemical/x-xyz xyz
19372
+image/x-cmu-raster ras
19373
+image/x-portable-anymap pnm
19374
+image/x-portable-bitmap pbm
19375
+image/x-portable-graymap pgm
19376
+image/x-portable-pixmap ppm
19379
+image/x-xbitmap xbm
19380
+image/x-xpixmap xpm
19381
+image/x-xwindowdump xwd
19382
+text/cache-manifest manifest
19383
+text/html-sandboxed sandboxed
19388
+video/x-annodex axv
19390
+video/x-javafx fxm
19391
+video/x-ms-asf asx
19393
+video/x-ms-wmv wmv
19394
+video/x-ms-wmx wmx
19395
+video/x-ms-wvx wvx
19396
+video/x-msvideo avi
19397
+video/x-sgi-movie movie
19398
+x-conference/x-cooltalk ice
19399
+x-epoc/x-sisx-app sisx
19400
diff -r 137e45f15c0b Lib/test/nokia.pem
19402
+++ b/Lib/test/nokia.pem
19404
+# Certificate for projects.developer.nokia.com:443 (see issue 13034)
19405
+-----BEGIN CERTIFICATE-----
19406
+MIIFLDCCBBSgAwIBAgIQLubqdkCgdc7lAF9NfHlUmjANBgkqhkiG9w0BAQUFADCB
19407
+vDELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
19408
+ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTswOQYDVQQLEzJUZXJtcyBvZiB1c2Ug
19409
+YXQgaHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JwYSAoYykxMDE2MDQGA1UEAxMt
19410
+VmVyaVNpZ24gQ2xhc3MgMyBJbnRlcm5hdGlvbmFsIFNlcnZlciBDQSAtIEczMB4X
19411
+DTExMDkyMTAwMDAwMFoXDTEyMDkyMDIzNTk1OVowcTELMAkGA1UEBhMCRkkxDjAM
19412
+BgNVBAgTBUVzcG9vMQ4wDAYDVQQHFAVFc3BvbzEOMAwGA1UEChQFTm9raWExCzAJ
19413
+BgNVBAsUAkJJMSUwIwYDVQQDFBxwcm9qZWN0cy5kZXZlbG9wZXIubm9raWEuY29t
19414
+MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCr92w1bpHYSYxUEx8N/8Iddda2
19415
+lYi+aXNtQfV/l2Fw9Ykv3Ipw4nLeGTj18FFlAZgMdPRlgrzF/NNXGw/9l3/qKdow
19416
+CypkQf8lLaxb9Ze1E/KKmkRJa48QTOqvo6GqKuTI6HCeGlG1RxDb8YSKcQWLiytn
19417
+yj3Wp4MgRQO266xmMQIDAQABo4IB9jCCAfIwQQYDVR0RBDowOIIccHJvamVjdHMu
19418
+ZGV2ZWxvcGVyLm5va2lhLmNvbYIYcHJvamVjdHMuZm9ydW0ubm9raWEuY29tMAkG
19419
+A1UdEwQCMAAwCwYDVR0PBAQDAgWgMEEGA1UdHwQ6MDgwNqA0oDKGMGh0dHA6Ly9T
19420
+VlJJbnRsLUczLWNybC52ZXJpc2lnbi5jb20vU1ZSSW50bEczLmNybDBEBgNVHSAE
19421
+PTA7MDkGC2CGSAGG+EUBBxcDMCowKAYIKwYBBQUHAgEWHGh0dHBzOi8vd3d3LnZl
19422
+cmlzaWduLmNvbS9ycGEwKAYDVR0lBCEwHwYJYIZIAYb4QgQBBggrBgEFBQcDAQYI
19423
+KwYBBQUHAwIwcgYIKwYBBQUHAQEEZjBkMCQGCCsGAQUFBzABhhhodHRwOi8vb2Nz
19424
+cC52ZXJpc2lnbi5jb20wPAYIKwYBBQUHMAKGMGh0dHA6Ly9TVlJJbnRsLUczLWFp
19425
+YS52ZXJpc2lnbi5jb20vU1ZSSW50bEczLmNlcjBuBggrBgEFBQcBDARiMGChXqBc
19426
+MFowWDBWFglpbWFnZS9naWYwITAfMAcGBSsOAwIaBBRLa7kolgYMu9BSOJsprEsH
19427
+iyEFGDAmFiRodHRwOi8vbG9nby52ZXJpc2lnbi5jb20vdnNsb2dvMS5naWYwDQYJ
19428
+KoZIhvcNAQEFBQADggEBACQuPyIJqXwUyFRWw9x5yDXgMW4zYFopQYOw/ItRY522
19429
+O5BsySTh56BWS6mQB07XVfxmYUGAvRQDA5QHpmY8jIlNwSmN3s8RKo+fAtiNRlcL
19430
+x/mWSfuMs3D/S6ev3D6+dpEMZtjrhOdctsarMKp8n/hPbwhAbg5hVjpkW5n8vz2y
19431
+0KxvvkA1AxpLwpVv7OlK17ttzIHw8bp9HTlHBU5s8bKz4a565V/a5HI0CSEv/+0y
19432
+ko4/ghTnZc1CkmUngKKeFMSah/mT/xAh8XnE2l1AazFa8UKuYki1e+ArHaGZc4ix
19433
+UYOtiRphwfuYQhRZ7qX9q2MMkCMI65XNK/SaFrAbbG0=
19434
+-----END CERTIFICATE-----
19435
diff -r 137e45f15c0b Lib/test/pickletester.py
19436
--- a/Lib/test/pickletester.py
19437
+++ b/Lib/test/pickletester.py
19444
from http.cookies import SimpleCookie
19446
-from test.support import TestFailed, TESTFN, run_with_locale
19447
+from test.support import (
19448
+ TestFailed, TESTFN, run_with_locale,
19449
+ _2G, _4G, bigmemtest,
19452
from pickle import bytes_types
19455
# kind of outer loop.
19456
protocols = range(pickle.HIGHEST_PROTOCOL + 1)
19458
+character_size = 4 if sys.maxunicode > 0xFFFF else 2
19461
# Return True if opcode code appears in the pickle, else False.
19462
def opcode_in_pickle(code, pickle):
19463
@@ -115,6 +121,19 @@
19464
class use_metaclass(object, metaclass=metaclass):
19467
+class pickling_metaclass(type):
19468
+ def __eq__(self, other):
19469
+ return (type(self) == type(other) and
19470
+ self.reduce_args == other.reduce_args)
19472
+ def __reduce__(self):
19473
+ return (create_dynamic_class, self.reduce_args)
19475
+def create_dynamic_class(name, bases):
19476
+ result = pickling_metaclass(name, bases, dict())
19477
+ result.reduce_args = (name, bases)
19480
# DATA0 .. DATA2 are the pickles we expect under the various protocols, for
19481
# the object returned by create_data().
19483
@@ -617,9 +636,15 @@
19485
def test_bytes(self):
19486
for proto in protocols:
19487
- for u in b'', b'xyz', b'xyz'*100:
19488
- p = self.dumps(u)
19489
- self.assertEqual(self.loads(p), u)
19490
+ for s in b'', b'xyz', b'xyz'*100:
19491
+ p = self.dumps(s)
19492
+ self.assertEqual(self.loads(p), s)
19493
+ for s in [bytes([i]) for i in range(256)]:
19494
+ p = self.dumps(s)
19495
+ self.assertEqual(self.loads(p), s)
19496
+ for s in [bytes([i, i]) for i in range(256)]:
19497
+ p = self.dumps(s)
19498
+ self.assertEqual(self.loads(p), s)
19500
def test_ints(self):
19502
@@ -689,6 +714,14 @@
19504
self.assertEqual(a.__class__, b.__class__)
19506
+ def test_dynamic_class(self):
19507
+ a = create_dynamic_class("my_dynamic_class", (object,))
19508
+ copyreg.pickle(pickling_metaclass, pickling_metaclass.__reduce__)
19509
+ for proto in protocols:
19510
+ s = self.dumps(a, proto)
19511
+ b = self.loads(s)
19512
+ self.assertEqual(a, b)
19514
def test_structseq(self):
19517
@@ -1098,6 +1131,117 @@
19518
empty = self.loads(b'\x80\x03U\x00q\x00.', encoding='koi8-r')
19519
self.assertEqual(empty, '')
19521
+ def check_negative_32b_binXXX(self, dumped):
19522
+ if sys.maxsize > 2**32:
19523
+ self.skipTest("test is only meaningful on 32-bit builds")
19524
+ # XXX Pure Python pickle reads lengths as signed and passes
19525
+ # them directly to read() (hence the EOFError)
19526
+ with self.assertRaises((pickle.UnpicklingError, EOFError,
19527
+ ValueError, OverflowError)):
19528
+ self.loads(dumped)
19530
+ def test_negative_32b_binbytes(self):
19531
+ # On 32-bit builds, a BINBYTES of 2**31 or more is refused
19532
+ self.check_negative_32b_binXXX(b'\x80\x03B\xff\xff\xff\xffxyzq\x00.')
19534
+ def test_negative_32b_binunicode(self):
19535
+ # On 32-bit builds, a BINUNICODE of 2**31 or more is refused
19536
+ self.check_negative_32b_binXXX(b'\x80\x03X\xff\xff\xff\xffxyzq\x00.')
19538
+ def test_negative_put(self):
19540
+ dumped = b'Va\np-1\n.'
19541
+ self.assertRaises(ValueError, self.loads, dumped)
19543
+ def test_negative_32b_binput(self):
19545
+ if sys.maxsize > 2**32:
19546
+ self.skipTest("test is only meaningful on 32-bit builds")
19547
+ dumped = b'\x80\x03X\x01\x00\x00\x00ar\xff\xff\xff\xff.'
19548
+ self.assertRaises(ValueError, self.loads, dumped)
19551
+class BigmemPickleTests(unittest.TestCase):
19553
+ # Binary protocols can serialize longs of up to 2GB-1
19555
+ @bigmemtest(size=_2G, memuse=1 + 1, dry_run=False)
19556
+ def test_huge_long_32b(self, size):
19557
+ data = 1 << (8 * size)
19559
+ for proto in protocols:
19562
+ with self.assertRaises((ValueError, OverflowError)):
19563
+ self.dumps(data, protocol=proto)
19567
+ # Protocol 3 can serialize up to 4GB-1 as a bytes object
19568
+ # (older protocols don't have a dedicated opcode for bytes and are
19569
+ # too inefficient)
19571
+ @bigmemtest(size=_2G, memuse=1 + 1, dry_run=False)
19572
+ def test_huge_bytes_32b(self, size):
19573
+ data = b"abcd" * (size // 4)
19575
+ for proto in protocols:
19579
+ pickled = self.dumps(data, protocol=proto)
19580
+ self.assertTrue(b"abcd" in pickled[:15])
19581
+ self.assertTrue(b"abcd" in pickled[-15:])
19587
+ @bigmemtest(size=_4G, memuse=1 + 1, dry_run=False)
19588
+ def test_huge_bytes_64b(self, size):
19589
+ data = b"a" * size
19591
+ for proto in protocols:
19594
+ with self.assertRaises((ValueError, OverflowError)):
19595
+ self.dumps(data, protocol=proto)
19599
+ # All protocols use 1-byte per printable ASCII character; we add another
19600
+ # byte because the encoded form has to be copied into the internal buffer.
19602
+ @bigmemtest(size=_2G, memuse=2 + character_size, dry_run=False)
19603
+ def test_huge_str_32b(self, size):
19604
+ data = "abcd" * (size // 4)
19606
+ for proto in protocols:
19608
+ pickled = self.dumps(data, protocol=proto)
19609
+ self.assertTrue(b"abcd" in pickled[:15])
19610
+ self.assertTrue(b"abcd" in pickled[-15:])
19616
+ # BINUNICODE (protocols 1, 2 and 3) cannot carry more than
19617
+ # 2**32 - 1 bytes of utf-8 encoded unicode.
19619
+ @bigmemtest(size=_4G, memuse=1 + character_size, dry_run=False)
19620
+ def test_huge_str_64b(self, size):
19621
+ data = "a" * size
19623
+ for proto in protocols:
19626
+ with self.assertRaises((ValueError, OverflowError)):
19627
+ self.dumps(data, protocol=proto)
19632
# Test classes for reduce_ex
19634
class REX_one(object):
19635
diff -r 137e45f15c0b Lib/test/regex_tests.py
19636
--- a/Lib/test/regex_tests.py
19639
-# Regex test suite and benchmark suite v1.5a2
19641
-# The 3 possible outcomes for each pattern
19642
-[SUCCEED, FAIL, SYNTAX_ERROR] = range(3)
19644
-# Benchmark suite (needs expansion)
19646
-# The benchmark suite does not test correctness, just speed. The
19647
-# first element of each tuple is the regex pattern; the second is a
19648
-# string to match it against. The benchmarking code will embed the
19649
-# second string inside several sizes of padding, to test how regex
19650
-# matching performs on large strings.
19653
- ('Python', 'Python'), # Simple text literal
19654
- ('.*Python', 'Python'), # Bad text literal
19655
- ('.*Python.*', 'Python'), # Worse text literal
19656
- ('.*\\(Python\\)', 'Python'), # Bad text literal with grouping
19658
- ('(Python\\|Perl\\|Tcl', 'Perl'), # Alternation
19659
- ('\\(Python\\|Perl\\|Tcl\\)', 'Perl'), # Grouped alternation
19660
- ('\\(Python\\)\\1', 'PythonPython'), # Backreference
19661
-# ('\\([0a-z][a-z]*,\\)+', 'a5,b7,c9,'), # Disable the fastmap optimization
19662
- ('\\([a-z][a-z0-9]*,\\)+', 'a5,b7,c9,') # A few sets
19665
-# Test suite (for verifying correctness)
19667
-# The test suite is a list of 5- or 3-tuples. The 5 parts of a
19668
-# complete tuple are:
19669
-# element 0: a string containing the pattern
19670
-# 1: the string to match against the pattern
19671
-# 2: the expected result (SUCCEED, FAIL, SYNTAX_ERROR)
19672
-# 3: a string that will be eval()'ed to produce a test string.
19673
-# This is an arbitrary Python expression; the available
19674
-# variables are "found" (the whole match), and "g1", "g2", ...
19675
-# up to "g10" contain the contents of each group, or the
19676
-# string 'None' if the group wasn't given a value.
19677
-# 4: The expected result of evaluating the expression.
19678
-# If the two don't match, an error is reported.
19680
-# If the regex isn't expected to work, the latter two elements can be omitted.
19683
-('abc', 'abc', SUCCEED,
19685
-('abc', 'xbc', FAIL),
19686
-('abc', 'axc', FAIL),
19687
-('abc', 'abx', FAIL),
19688
-('abc', 'xabcy', SUCCEED,
19690
-('abc', 'ababc', SUCCEED,
19692
-('ab*c', 'abc', SUCCEED,
19694
-('ab*bc', 'abc', SUCCEED,
19696
-('ab*bc', 'abbc', SUCCEED,
19697
- 'found', 'abbc'),
19698
-('ab*bc', 'abbbbc', SUCCEED,
19699
- 'found', 'abbbbc'),
19700
-('ab+bc', 'abbc', SUCCEED,
19701
- 'found', 'abbc'),
19702
-('ab+bc', 'abc', FAIL),
19703
-('ab+bc', 'abq', FAIL),
19704
-('ab+bc', 'abbbbc', SUCCEED,
19705
- 'found', 'abbbbc'),
19706
-('ab?bc', 'abbc', SUCCEED,
19707
- 'found', 'abbc'),
19708
-('ab?bc', 'abc', SUCCEED,
19710
-('ab?bc', 'abbbbc', FAIL),
19711
-('ab?c', 'abc', SUCCEED,
19713
-('^abc$', 'abc', SUCCEED,
19715
-('^abc$', 'abcc', FAIL),
19716
-('^abc', 'abcc', SUCCEED,
19718
-('^abc$', 'aabc', FAIL),
19719
-('abc$', 'aabc', SUCCEED,
19721
-('^', 'abc', SUCCEED,
19722
- 'found+"-"', '-'),
19723
-('$', 'abc', SUCCEED,
19724
- 'found+"-"', '-'),
19725
-('a.c', 'abc', SUCCEED,
19727
-('a.c', 'axc', SUCCEED,
19729
-('a.*c', 'axyzc', SUCCEED,
19730
- 'found', 'axyzc'),
19731
-('a.*c', 'axyzd', FAIL),
19732
-('a[bc]d', 'abc', FAIL),
19733
-('a[bc]d', 'abd', SUCCEED,
19735
-('a[b-d]e', 'abd', FAIL),
19736
-('a[b-d]e', 'ace', SUCCEED,
19738
-('a[b-d]', 'aac', SUCCEED,
19740
-('a[-b]', 'a-', SUCCEED,
19742
-('a[b-]', 'a-', SUCCEED,
19744
-('a[]b', '-', SYNTAX_ERROR),
19745
-('a[', '-', SYNTAX_ERROR),
19746
-('a\\', '-', SYNTAX_ERROR),
19747
-('abc\\)', '-', SYNTAX_ERROR),
19748
-('\\(abc', '-', SYNTAX_ERROR),
19749
-('a]', 'a]', SUCCEED,
19751
-('a[]]b', 'a]b', SUCCEED,
19753
-('a[^bc]d', 'aed', SUCCEED,
19755
-('a[^bc]d', 'abd', FAIL),
19756
-('a[^-b]c', 'adc', SUCCEED,
19758
-('a[^-b]c', 'a-c', FAIL),
19759
-('a[^]b]c', 'a]c', FAIL),
19760
-('a[^]b]c', 'adc', SUCCEED,
19762
-('\\ba\\b', 'a-', SUCCEED,
19764
-('\\ba\\b', '-a', SUCCEED,
19766
-('\\ba\\b', '-a-', SUCCEED,
19768
-('\\by\\b', 'xy', FAIL),
19769
-('\\by\\b', 'yz', FAIL),
19770
-('\\by\\b', 'xyz', FAIL),
19771
-('ab\\|cd', 'abc', SUCCEED,
19773
-('ab\\|cd', 'abcd', SUCCEED,
19775
-('\\(\\)ef', 'def', SUCCEED,
19776
- 'found+"-"+g1', 'ef-'),
19777
-('$b', 'b', FAIL),
19778
-('a(b', 'a(b', SUCCEED,
19779
- 'found+"-"+g1', 'a(b-None'),
19780
-('a(*b', 'ab', SUCCEED,
19782
-('a(*b', 'a((b', SUCCEED,
19783
- 'found', 'a((b'),
19784
-('a\\\\b', 'a\\b', SUCCEED,
19785
- 'found', 'a\\b'),
19786
-('\\(\\(a\\)\\)', 'abc', SUCCEED,
19787
- 'found+"-"+g1+"-"+g2', 'a-a-a'),
19788
-('\\(a\\)b\\(c\\)', 'abc', SUCCEED,
19789
- 'found+"-"+g1+"-"+g2', 'abc-a-c'),
19790
-('a+b+c', 'aabbabc', SUCCEED,
19792
-('\\(a+\\|b\\)*', 'ab', SUCCEED,
19793
- 'found+"-"+g1', 'ab-b'),
19794
-('\\(a+\\|b\\)+', 'ab', SUCCEED,
19795
- 'found+"-"+g1', 'ab-b'),
19796
-('\\(a+\\|b\\)?', 'ab', SUCCEED,
19797
- 'found+"-"+g1', 'a-a'),
19798
-('\\)\\(', '-', SYNTAX_ERROR),
19799
-('[^ab]*', 'cde', SUCCEED,
19801
-('abc', '', FAIL),
19802
-('a*', '', SUCCEED,
19804
-('a\\|b\\|c\\|d\\|e', 'e', SUCCEED,
19806
-('\\(a\\|b\\|c\\|d\\|e\\)f', 'ef', SUCCEED,
19807
- 'found+"-"+g1', 'ef-e'),
19808
-('abcd*efg', 'abcdefg', SUCCEED,
19809
- 'found', 'abcdefg'),
19810
-('ab*', 'xabyabbbz', SUCCEED,
19812
-('ab*', 'xayabbbz', SUCCEED,
19814
-('\\(ab\\|cd\\)e', 'abcde', SUCCEED,
19815
- 'found+"-"+g1', 'cde-cd'),
19816
-('[abhgefdc]ij', 'hij', SUCCEED,
19818
-('^\\(ab\\|cd\\)e', 'abcde', FAIL,
19820
-('\\(abc\\|\\)ef', 'abcdef', SUCCEED,
19821
- 'found+"-"+g1', 'ef-'),
19822
-('\\(a\\|b\\)c*d', 'abcd', SUCCEED,
19823
- 'found+"-"+g1', 'bcd-b'),
19824
-('\\(ab\\|ab*\\)bc', 'abc', SUCCEED,
19825
- 'found+"-"+g1', 'abc-a'),
19826
-('a\\([bc]*\\)c*', 'abc', SUCCEED,
19827
- 'found+"-"+g1', 'abc-bc'),
19828
-('a\\([bc]*\\)\\(c*d\\)', 'abcd', SUCCEED,
19829
- 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),
19830
-('a\\([bc]+\\)\\(c*d\\)', 'abcd', SUCCEED,
19831
- 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),
19832
-('a\\([bc]*\\)\\(c+d\\)', 'abcd', SUCCEED,
19833
- 'found+"-"+g1+"-"+g2', 'abcd-b-cd'),
19834
-('a[bcd]*dcdcde', 'adcdcde', SUCCEED,
19835
- 'found', 'adcdcde'),
19836
-('a[bcd]+dcdcde', 'adcdcde', FAIL),
19837
-('\\(ab\\|a\\)b*c', 'abc', SUCCEED,
19838
- 'found+"-"+g1', 'abc-ab'),
19839
-('\\(\\(a\\)\\(b\\)c\\)\\(d\\)', 'abcd', SUCCEED,
19840
- 'g1+"-"+g2+"-"+g3+"-"+g4', 'abc-a-b-d'),
19841
-('[a-zA-Z_][a-zA-Z0-9_]*', 'alpha', SUCCEED,
19842
- 'found', 'alpha'),
19843
-('^a\\(bc+\\|b[eh]\\)g\\|.h$', 'abh', SUCCEED,
19844
- 'found+"-"+g1', 'bh-None'),
19845
-('\\(bc+d$\\|ef*g.\\|h?i\\(j\\|k\\)\\)', 'effgz', SUCCEED,
19846
- 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),
19847
-('\\(bc+d$\\|ef*g.\\|h?i\\(j\\|k\\)\\)', 'ij', SUCCEED,
19848
- 'found+"-"+g1+"-"+g2', 'ij-ij-j'),
19849
-('\\(bc+d$\\|ef*g.\\|h?i\\(j\\|k\\)\\)', 'effg', FAIL),
19850
-('\\(bc+d$\\|ef*g.\\|h?i\\(j\\|k\\)\\)', 'bcdd', FAIL),
19851
-('\\(bc+d$\\|ef*g.\\|h?i\\(j\\|k\\)\\)', 'reffgz', SUCCEED,
19852
- 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),
19853
-('\\(\\(\\(\\(\\(\\(\\(\\(\\(a\\)\\)\\)\\)\\)\\)\\)\\)\\)', 'a', SUCCEED,
19855
-('multiple words of text', 'uh-uh', FAIL),
19856
-('multiple words', 'multiple words, yeah', SUCCEED,
19857
- 'found', 'multiple words'),
19858
-('\\(.*\\)c\\(.*\\)', 'abcde', SUCCEED,
19859
- 'found+"-"+g1+"-"+g2', 'abcde-ab-de'),
19860
-('(\\(.*\\), \\(.*\\))', '(a, b)', SUCCEED,
19861
- 'g2+"-"+g1', 'b-a'),
19862
-('[k]', 'ab', FAIL),
19863
-('a[-]?c', 'ac', SUCCEED,
19865
-('\\(abc\\)\\1', 'abcabc', SUCCEED,
19867
-('\\([a-c]*\\)\\1', 'abcabc', SUCCEED,
19869
-('^\\(.+\\)?B', 'AB', SUCCEED,
19871
-('\\(a+\\).\\1$', 'aaaaa', SUCCEED,
19872
- 'found+"-"+g1', 'aaaaa-aa'),
19873
-('^\\(a+\\).\\1$', 'aaaa', FAIL),
19874
-('\\(abc\\)\\1', 'abcabc', SUCCEED,
19875
- 'found+"-"+g1', 'abcabc-abc'),
19876
-('\\([a-c]+\\)\\1', 'abcabc', SUCCEED,
19877
- 'found+"-"+g1', 'abcabc-abc'),
19878
-('\\(a\\)\\1', 'aa', SUCCEED,
19879
- 'found+"-"+g1', 'aa-a'),
19880
-('\\(a+\\)\\1', 'aa', SUCCEED,
19881
- 'found+"-"+g1', 'aa-a'),
19882
-('\\(a+\\)+\\1', 'aa', SUCCEED,
19883
- 'found+"-"+g1', 'aa-a'),
19884
-('\\(a\\).+\\1', 'aba', SUCCEED,
19885
- 'found+"-"+g1', 'aba-a'),
19886
-('\\(a\\)ba*\\1', 'aba', SUCCEED,
19887
- 'found+"-"+g1', 'aba-a'),
19888
-('\\(aa\\|a\\)a\\1$', 'aaa', SUCCEED,
19889
- 'found+"-"+g1', 'aaa-a'),
19890
-('\\(a\\|aa\\)a\\1$', 'aaa', SUCCEED,
19891
- 'found+"-"+g1', 'aaa-a'),
19892
-('\\(a+\\)a\\1$', 'aaa', SUCCEED,
19893
- 'found+"-"+g1', 'aaa-a'),
19894
-('\\([abc]*\\)\\1', 'abcabc', SUCCEED,
19895
- 'found+"-"+g1', 'abcabc-abc'),
19896
-('\\(a\\)\\(b\\)c\\|ab', 'ab', SUCCEED,
19897
- 'found+"-"+g1+"-"+g2', 'ab-None-None'),
19898
-('\\(a\\)+x', 'aaax', SUCCEED,
19899
- 'found+"-"+g1', 'aaax-a'),
19900
-('\\([ac]\\)+x', 'aacx', SUCCEED,
19901
- 'found+"-"+g1', 'aacx-c'),
19902
-('\\([^/]*/\\)*sub1/', 'd:msgs/tdir/sub1/trial/away.cpp', SUCCEED,
19903
- 'found+"-"+g1', 'd:msgs/tdir/sub1/-tdir/'),
19904
-('\\([^.]*\\)\\.\\([^:]*\\):[T ]+\\(.*\\)', 'track1.title:TBlah blah blah', SUCCEED,
19905
- 'found+"-"+g1+"-"+g2+"-"+g3', 'track1.title:TBlah blah blah-track1-title-Blah blah blah'),
19906
-('\\([^N]*N\\)+', 'abNNxyzN', SUCCEED,
19907
- 'found+"-"+g1', 'abNNxyzN-xyzN'),
19908
-('\\([^N]*N\\)+', 'abNNxyz', SUCCEED,
19909
- 'found+"-"+g1', 'abNN-N'),
19910
-('\\([abc]*\\)x', 'abcx', SUCCEED,
19911
- 'found+"-"+g1', 'abcx-abc'),
19912
-('\\([abc]*\\)x', 'abc', FAIL),
19913
-('\\([xyz]*\\)x', 'abcx', SUCCEED,
19914
- 'found+"-"+g1', 'x-'),
19915
-('\\(a\\)+b\\|aac', 'aac', SUCCEED,
19916
- 'found+"-"+g1', 'aac-None'),
19917
-('\<a', 'a', SUCCEED, 'found', 'a'),
19918
-('\<a', '!', FAIL),
19919
-('a\<b', 'ab', FAIL),
19920
-('a\>', 'ab', FAIL),
19921
-('a\>', 'a!', SUCCEED, 'found', 'a'),
19922
-('a\>', 'a', SUCCEED, 'found', 'a'),
19924
diff -r 137e45f15c0b Lib/test/regrtest.py
1547
-# Copyright 2001-2010 by Vinay Sajip. All Rights Reserved.
1548
+# Copyright 2001-2012 by Vinay Sajip. All Rights Reserved.
1550
# Permission to use, copy, modify, and distribute this software and its
1551
# documentation for any purpose and without fee is hereby granted,
1555
Logging package for Python. Based on PEP 282 and comments thereto in
1556
-comp.lang.python, and influenced by Apache's log4j system.
1559
-Copyright (C) 2001-2011 Vinay Sajip. All Rights Reserved.
1560
+Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved.
1562
To use, simply 'import logging' and log away!
1564
@@ -917,8 +917,12 @@
1568
- if self.stream and hasattr(self.stream, "flush"):
1569
- self.stream.flush()
1572
+ if self.stream and hasattr(self.stream, "flush"):
1573
+ self.stream.flush()
1577
def emit(self, record):
1579
@@ -969,12 +973,16 @@
1585
- if hasattr(self.stream, "close"):
1586
- self.stream.close()
1587
- StreamHandler.close(self)
1588
- self.stream = None
1593
+ if hasattr(self.stream, "close"):
1594
+ self.stream.close()
1595
+ StreamHandler.close(self)
1596
+ self.stream = None
1602
diff -r 7085403daf43 Lib/logging/handlers.py
1603
--- a/Lib/logging/handlers.py
1604
+++ b/Lib/logging/handlers.py
1606
-# Copyright 2001-2010 by Vinay Sajip. All Rights Reserved.
1607
+# Copyright 2001-2012 by Vinay Sajip. All Rights Reserved.
1609
# Permission to use, copy, modify, and distribute this software and its
1610
# documentation for any purpose and without fee is hereby granted,
1614
Additional handlers for the logging package for Python. The core package is
1615
-based on PEP 282 and comments thereto in comp.lang.python, and influenced by
1616
-Apache's log4j system.
1617
+based on PEP 282 and comments thereto in comp.lang.python.
1619
-Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved.
1620
+Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved.
1622
To use, simply 'import logging.handlers' and log away!
1624
@@ -554,10 +553,14 @@
1631
- logging.Handler.close(self)
1637
+ logging.Handler.close(self)
1641
class DatagramHandler(SocketHandler):
1643
@@ -752,9 +755,13 @@
1647
- if self.unixsocket:
1648
- self.socket.close()
1649
- logging.Handler.close(self)
1652
+ if self.unixsocket:
1653
+ self.socket.close()
1654
+ logging.Handler.close(self)
1658
def mapPriority(self, levelName):
1660
@@ -1095,7 +1102,11 @@
1662
This version just zaps the buffer to empty.
1673
@@ -1145,18 +1156,26 @@
1675
The record buffer is also cleared by this operation.
1678
- for record in self.buffer:
1679
- self.target.handle(record)
1684
+ for record in self.buffer:
1685
+ self.target.handle(record)
1692
Flush, set the target to None and lose the buffer.
1695
- self.target = None
1696
- BufferingHandler.close(self)
1699
+ self.target = None
1700
+ BufferingHandler.close(self)
1705
class QueueHandler(logging.Handler):
1706
diff -r 7085403daf43 Lib/test/regrtest.py
19925
1707
--- a/Lib/test/regrtest.py
19926
1708
+++ b/Lib/test/regrtest.py
19928
-W/--verbose3 -- display test output on failure
19929
-d/--debug -- print traceback for failed tests
19930
-q/--quiet -- no output unless one or more tests fail
19931
--S/--slow -- print the slowest 10 tests
19932
+-o/--slow -- print the slowest 10 tests
19933
--header -- print header with interpreter info
19936
@@ -165,6 +165,7 @@
19944
@@ -271,10 +272,10 @@
19946
support.record_original_stdout(sys.stdout)
19948
- opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:Gm:',
19949
+ opts, args = getopt.getopt(sys.argv[1:], 'hvqxsoS:rf:lu:t:TD:NLR:FdwWM:nj:Gm:',
19950
['help', 'verbose', 'verbose2', 'verbose3', 'quiet',
19951
'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks',
19952
- 'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir',
19953
+ 'use=', 'threshold=', 'coverdir=', 'nocoverdir',
19954
'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=',
19955
'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug',
19956
'start=', 'nowindows', 'header', 'failfast', 'match'])
19957
@@ -311,7 +312,7 @@
19959
elif o in ('-s', '--single'):
19961
- elif o in ('-S', '--slow'):
19962
+ elif o in ('-o', '--slow'):
19964
elif o in ('-r', '--randomize'):
19966
@@ -887,6 +888,7 @@
19967
'os.environ', 'sys.path', 'sys.path_hooks', '__import__',
19968
'warnings.filters', 'asyncore.socket_map',
1709
@@ -677,10 +677,10 @@
1711
print(count(len(bad), "test"), "failed:")
1713
- if environment_changed:
1714
- print("{} altered the execution environment:".format(
1715
- count(len(environment_changed), "test")))
1716
- printlist(environment_changed)
1717
+ if environment_changed:
1718
+ print("{} altered the execution environment:".format(
1719
+ count(len(environment_changed), "test")))
1720
+ printlist(environment_changed)
1721
if skipped and not quiet:
1722
print(count(len(skipped), "test"), "skipped:")
19969
1725
'logging._handlers', 'logging._handlerList',
19970
+ 'shutil.archive_formats', 'shutil.unpack_formats',
1726
'shutil.archive_formats', 'shutil.unpack_formats',
19971
1727
'sys.warnoptions', 'threading._dangling',
19972
'multiprocessing.process._dangling')
19974
@@ -956,6 +958,23 @@
19975
asyncore.close_all(ignore_all=True)
19976
asyncore.socket_map.update(saved_map)
19978
+ def get_shutil_archive_formats(self):
19979
+ # we could call get_archives_formats() but that only returns the
19980
+ # registry keys; we want to check the values too (the functions that
19981
+ # are registered)
19982
+ return shutil._ARCHIVE_FORMATS, shutil._ARCHIVE_FORMATS.copy()
19983
+ def restore_shutil_archive_formats(self, saved):
19984
+ shutil._ARCHIVE_FORMATS = saved[0]
19985
+ shutil._ARCHIVE_FORMATS.clear()
19986
+ shutil._ARCHIVE_FORMATS.update(saved[1])
19988
+ def get_shutil_unpack_formats(self):
19989
+ return shutil._UNPACK_FORMATS, shutil._UNPACK_FORMATS.copy()
19990
+ def restore_shutil_unpack_formats(self, saved):
19991
+ shutil._UNPACK_FORMATS = saved[0]
19992
+ shutil._UNPACK_FORMATS.clear()
19993
+ shutil._UNPACK_FORMATS.update(saved[1])
19995
def get_logging__handlers(self):
19996
# _handlers is a WeakValueDictionary
19997
return id(logging._handlers), logging._handlers, logging._handlers.copy()
19998
@@ -1255,6 +1274,13 @@
19999
filecmp._cache.clear()
20000
struct._clearcache()
20001
doctest.master = None
20004
+ except ImportError:
20005
+ # Don't worry about resetting the cache if ctypes is not supported
20008
+ ctypes._reset_cache()
20010
# Collect cyclic trash.
20012
diff -r 137e45f15c0b Lib/test/string_tests.py
20013
--- a/Lib/test/string_tests.py
20014
+++ b/Lib/test/string_tests.py
20015
@@ -641,6 +641,23 @@
20016
self.checkequal('Aaaa', 'aaaa', 'capitalize')
20017
self.checkequal('Aaaa', 'AaAa', 'capitalize')
20019
+ # check that titlecased chars are lowered correctly
20020
+ # \u1ffc is the titlecased char
20021
+ self.checkequal('\u1ffc\u1ff3\u1ff3\u1ff3',
20022
+ '\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize')
20023
+ # check with cased non-letter chars
20024
+ self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
20025
+ '\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize')
20026
+ self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
20027
+ '\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize')
20028
+ self.checkequal('\u2160\u2171\u2172',
20029
+ '\u2160\u2161\u2162', 'capitalize')
20030
+ self.checkequal('\u2160\u2171\u2172',
20031
+ '\u2170\u2171\u2172', 'capitalize')
20032
+ # check with Ll chars with no upper - nothing changes here
20033
+ self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7',
20034
+ '\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize')
20036
self.checkraises(TypeError, 'hello', 'capitalize', 42)
20038
def test_lower(self):
20039
diff -r 137e45f15c0b Lib/test/support.py
20040
--- a/Lib/test/support.py
20041
+++ b/Lib/test/support.py
20042
@@ -877,6 +877,7 @@
20044
default_gai_errnos = [
20046
+ ('EAI_FAIL', -4),
20047
('EAI_NONAME', -2),
20048
('EAI_NODATA', -5),
20049
# Encountered when trying to resolve IPv6-only hostnames
20050
@@ -1053,45 +1054,54 @@
20051
raise ValueError('Memory limit %r too low to be useful' % (limit,))
20052
max_memuse = memlimit
20054
-def bigmemtest(minsize, memuse):
20055
+def _memory_watchdog(start_evt, finish_evt, period=10.0):
20056
+ """A function which periodically watches the process' memory consumption
20057
+ and prints it out.
20059
+ # XXX: because of the GIL, and because the very long operations tested
20060
+ # in most bigmem tests are uninterruptible, the loop below gets woken up
20061
+ # much less often than expected.
20062
+ # The polling code should be rewritten in raw C, without holding the GIL,
20063
+ # and push results onto an anonymous pipe.
20065
+ page_size = os.sysconf('SC_PAGESIZE')
20066
+ except (ValueError, AttributeError):
20068
+ page_size = os.sysconf('SC_PAGE_SIZE')
20069
+ except (ValueError, AttributeError):
20071
+ procfile = '/proc/{pid}/statm'.format(pid=os.getpid())
20073
+ f = open(procfile, 'rb')
20074
+ except IOError as e:
20075
+ warnings.warn('/proc not available for stats: {}'.format(e),
20077
+ sys.stderr.flush()
20082
+ while not finish_evt.wait(period):
20084
+ statm = f.read().decode('ascii')
20085
+ data = int(statm.split()[5])
20086
+ if data != old_data:
20088
+ print(" ... process data size: {data:.1f}G"
20089
+ .format(data=data * page_size / (1024 ** 3)))
20091
+def bigmemtest(size, memuse, dry_run=True):
20092
"""Decorator for bigmem tests.
20094
'minsize' is the minimum useful size for the test (in arbitrary,
20095
test-interpreted units.) 'memuse' is the number of 'bytes per size' for
20096
the test, or a good estimate of it.
20098
- The decorator tries to guess a good value for 'size' and passes it to
20099
- the decorated test function. If minsize * memuse is more than the
20100
- allowed memory use (as defined by max_memuse), the test is skipped.
20101
- Otherwise, minsize is adjusted upward to use up to max_memuse.
20102
+ if 'dry_run' is False, it means the test doesn't support dummy runs
20103
+ when -M is not specified.
20107
- # Retrieve values in case someone decided to adjust them
20108
- minsize = wrapper.minsize
20109
- memuse = wrapper.memuse
20110
- if not max_memuse:
20111
- # If max_memuse is 0 (the default),
20112
- # we still want to run the tests with size set to a few kb,
20113
- # to make sure they work. We still want to avoid using
20114
- # too much memory, though, but we do that noisily.
20116
- self.assertFalse(maxsize * memuse > 20 * _1M)
20118
- maxsize = int(max_memuse / memuse)
20119
- if maxsize < minsize:
20120
- raise unittest.SkipTest(
20121
- "not enough memory: %.1fG minimum needed"
20122
- % (minsize * memuse / (1024 ** 3)))
20123
- return f(self, maxsize)
20124
- wrapper.minsize = minsize
20125
- wrapper.memuse = memuse
20129
-def precisionbigmemtest(size, memuse):
20130
- def decorator(f):
20131
- def wrapper(self):
20132
size = wrapper.size
20133
memuse = wrapper.memuse
20134
if not real_max_memuse:
20135
@@ -1099,12 +1109,34 @@
20139
- if real_max_memuse and real_max_memuse < maxsize * memuse:
20140
- raise unittest.SkipTest(
20141
- "not enough memory: %.1fG minimum needed"
20142
- % (size * memuse / (1024 ** 3)))
20143
+ if ((real_max_memuse or not dry_run)
20144
+ and real_max_memuse < maxsize * memuse):
20145
+ raise unittest.SkipTest(
20146
+ "not enough memory: %.1fG minimum needed"
20147
+ % (size * memuse / (1024 ** 3)))
20149
- return f(self, maxsize)
20150
+ if real_max_memuse and verbose and threading:
20152
+ print(" ... expected peak memory use: {peak:.1f}G"
20153
+ .format(peak=size * memuse / (1024 ** 3)))
20154
+ sys.stdout.flush()
20155
+ start_evt = threading.Event()
20156
+ finish_evt = threading.Event()
20157
+ t = threading.Thread(target=_memory_watchdog,
20158
+ args=(start_evt, finish_evt, 0.5))
20166
+ return f(self, maxsize)
20172
wrapper.size = size
20173
wrapper.memuse = memuse
20175
diff -r 137e45f15c0b Lib/test/svn_python_org_https_cert.pem
20176
--- a/Lib/test/svn_python_org_https_cert.pem
20179
------BEGIN CERTIFICATE-----
20180
-MIIFQTCCBCmgAwIBAgIQL2qw7lpsHqTLcBh1PVjsaTANBgkqhkiG9w0BAQUFADCB
20181
-lzELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAlVUMRcwFQYDVQQHEw5TYWx0IExha2Ug
20182
-Q2l0eTEeMBwGA1UEChMVVGhlIFVTRVJUUlVTVCBOZXR3b3JrMSEwHwYDVQQLExho
20183
-dHRwOi8vd3d3LnVzZXJ0cnVzdC5jb20xHzAdBgNVBAMTFlVUTi1VU0VSRmlyc3Qt
20184
-SGFyZHdhcmUwHhcNMDcwNDEwMDAwMDAwWhcNMTAwNDA5MjM1OTU5WjCBvjELMAkG
20185
-A1UEBhMCVVMxDjAMBgNVBBETBTAxOTM4MRYwFAYDVQQIEw1NYXNzYWNodXNldHRz
20186
-MREwDwYDVQQHEwhJcHN3aXRjaDEMMAoGA1UECRMDbi9hMQwwCgYDVQQSEwM2NTMx
20187
-IzAhBgNVBAoTGlB5dGhvbiBTb2Z0d2FyZSBGb3VuZGF0aW9uMRowGAYDVQQLExFD
20188
-b21vZG8gSW5zdGFudFNTTDEXMBUGA1UEAxMOc3ZuLnB5dGhvbi5vcmcwgZ8wDQYJ
20189
-KoZIhvcNAQEBBQADgY0AMIGJAoGBAMFOfFeLpiIN9UzTCehCgQ4W3ufaq524qPoX
20190
-00iNDiI/ehd6kC0BXIP5/y9lPoMn7nRsjdjczUaVmlPWG8BhvADK3ZZIm7m/3mZW
20191
-O/+C5vGE9YuOqIKe0VoNz/cZaYkz+C2xmOwDTp6a+ls29jjUfoxMd9gtGtuOp7s+
20192
-IouVD3wZAgMBAAGjggHiMIIB3jAfBgNVHSMEGDAWgBShcl8mGyiYQ5VdBzfVhZad
20193
-S9LDRTAdBgNVHQ4EFgQUkeNAqLbnKq86W/ghBV9xfC+7h9swDgYDVR0PAQH/BAQD
20194
-AgWgMAwGA1UdEwEB/wQCMAAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC
20195
-MBEGCWCGSAGG+EIBAQQEAwIGwDBGBgNVHSAEPzA9MDsGDCsGAQQBsjEBAgEDBDAr
20196
-MCkGCCsGAQUFBwIBFh1odHRwczovL3NlY3VyZS5jb21vZG8ubmV0L0NQUzB7BgNV
20197
-HR8EdDByMDigNqA0hjJodHRwOi8vY3JsLmNvbW9kb2NhLmNvbS9VVE4tVVNFUkZp
20198
-cnN0LUhhcmR3YXJlLmNybDA2oDSgMoYwaHR0cDovL2NybC5jb21vZG8ubmV0L1VU
20199
-Ti1VU0VSRmlyc3QtSGFyZHdhcmUuY3JsMIGGBggrBgEFBQcBAQR6MHgwOwYIKwYB
20200
-BQUHMAKGL2h0dHA6Ly9jcnQuY29tb2RvY2EuY29tL1VUTkFkZFRydXN0U2VydmVy
20201
-Q0EuY3J0MDkGCCsGAQUFBzAChi1odHRwOi8vY3J0LmNvbW9kby5uZXQvVVROQWRk
20202
-VHJ1c3RTZXJ2ZXJDQS5jcnQwDQYJKoZIhvcNAQEFBQADggEBAFBxEOeKr5+vurzE
20203
-6DiP4THhQsp+LA0+tnZ5rkV7RODAmF6strjONl3FKWGSqrucWNnFTo/HMgrgZJHQ
20204
-CunxrJf4J5CVz/CvGlfdBDmCpYz5agc8b7EJhmM2WoWSqC+5CYIXuRzUuYcKWjPt
20205
-3LV312Zil4BaeZ+wv4SKR8cL8jsB/sj8QxLxrZjOGXtVX3J95AnrY7BMDjuCBDxx
20206
-dUUOUJpdJ4undAG1of0ZsPOGJ5viSJYNeJ9iOjSua24mfZ2aQ/mULirnqF8Gkr38
20207
-CMlC8io5ct5NnLgkWmPr0FS5UyalLeWXiopS6hMofvu952VGLyacLgMl7d9S5AaL
20209
------END CERTIFICATE-----
20210
diff -r 137e45f15c0b Lib/test/test_aifc.py
20211
--- a/Lib/test/test_aifc.py
20212
+++ b/Lib/test/test_aifc.py
20214
from test.support import findfile, run_unittest, TESTFN
20221
@@ -109,9 +110,79 @@
20223
self.assertEqual(testfile.closed, True)
20225
+ def test_write_header_comptype_sampwidth(self):
20226
+ for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'):
20227
+ fout = self.fout = aifc.open(io.BytesIO(), 'wb')
20228
+ fout.setnchannels(1)
20229
+ fout.setframerate(1)
20230
+ fout.setcomptype(comptype, b'')
20232
+ self.assertEqual(fout.getsampwidth(), 2)
20233
+ fout.initfp(None)
20235
+ def test_write_markers_values(self):
20236
+ fout = self.fout = aifc.open(io.BytesIO(), 'wb')
20237
+ self.assertEqual(fout.getmarkers(), None)
20238
+ fout.setmark(1, 0, b'foo1')
20239
+ fout.setmark(1, 1, b'foo2')
20240
+ self.assertEqual(fout.getmark(1), (1, 1, b'foo2'))
20241
+ self.assertEqual(fout.getmarkers(), [(1, 1, b'foo2')])
20242
+ fout.initfp(None)
20244
+ def test_read_markers(self):
20245
+ fout = self.fout = aifc.open(TESTFN, 'wb')
20247
+ fout.setparams((1, 1, 1, 1, b'NONE', b''))
20248
+ fout.setmark(1, 0, b'odd')
20249
+ fout.setmark(2, 0, b'even')
20250
+ fout.writeframes(b'\x00')
20252
+ f = self.f = aifc.open(TESTFN, 'rb')
20253
+ self.assertEqual(f.getmarkers(), [(1, 0, b'odd'), (2, 0, b'even')])
20254
+ self.assertEqual(f.getmark(1), (1, 0, b'odd'))
20255
+ self.assertEqual(f.getmark(2), (2, 0, b'even'))
20256
+ self.assertRaises(aifc.Error, f.getmark, 3)
20259
+class AIFCLowLevelTest(unittest.TestCase):
20261
+ def test_read_written(self):
20262
+ def read_written(self, what):
20264
+ getattr(aifc, '_write_' + what)(f, x)
20266
+ return getattr(aifc, '_read_' + what)(f)
20267
+ for x in (-1, 0, 0.1, 1):
20268
+ self.assertEqual(read_written(x, 'float'), x)
20269
+ for x in (float('NaN'), float('Inf')):
20270
+ self.assertEqual(read_written(x, 'float'), aifc._HUGE_VAL)
20271
+ for x in (b'', b'foo', b'a' * 255):
20272
+ self.assertEqual(read_written(x, 'string'), x)
20273
+ for x in (-0x7FFFFFFF, -1, 0, 1, 0x7FFFFFFF):
20274
+ self.assertEqual(read_written(x, 'long'), x)
20275
+ for x in (0, 1, 0xFFFFFFFF):
20276
+ self.assertEqual(read_written(x, 'ulong'), x)
20277
+ for x in (-0x7FFF, -1, 0, 1, 0x7FFF):
20278
+ self.assertEqual(read_written(x, 'short'), x)
20279
+ for x in (0, 1, 0xFFFF):
20280
+ self.assertEqual(read_written(x, 'ushort'), x)
20282
+ def test_read_raises(self):
20283
+ f = io.BytesIO(b'\x00')
20284
+ self.assertRaises(EOFError, aifc._read_ulong, f)
20285
+ self.assertRaises(EOFError, aifc._read_long, f)
20286
+ self.assertRaises(EOFError, aifc._read_ushort, f)
20287
+ self.assertRaises(EOFError, aifc._read_short, f)
20289
+ def test_write_long_string_raises(self):
20291
+ with self.assertRaises(ValueError):
20292
+ aifc._write_string(f, b'too long' * 255)
20296
run_unittest(AIFCTest)
20297
+ run_unittest(AIFCLowLevelTest)
20300
if __name__ == "__main__":
20301
diff -r 137e45f15c0b Lib/test/test_argparse.py
20302
--- a/Lib/test/test_argparse.py
20303
+++ b/Lib/test/test_argparse.py
20304
@@ -1502,6 +1502,8 @@
20305
return self.name == other.name
20308
+@unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
20309
+ "non-root user required")
20310
class TestFileTypeW(TempDirMixin, ParserTestCase):
20311
"""Test the FileType option/argument type for writing files"""
20313
@@ -2168,8 +2170,9 @@
20314
parents = [self.abcd_parent, self.wxyz_parent]
20315
parser = ErrorRaisingArgumentParser(parents=parents)
20316
parser_help = parser.format_help()
20317
+ progname = self.main_program
20318
self.assertEqual(parser_help, textwrap.dedent('''\
20319
- usage: {} [-h] [-b B] [--d D] [--w W] [-y Y] a z
20320
+ usage: {}{}[-h] [-b B] [--d D] [--w W] [-y Y] a z
20322
positional arguments:
20324
@@ -2185,7 +2188,7 @@
20328
- '''.format(self.main_program)))
20329
+ '''.format(progname, ' ' if progname else '' )))
20331
def test_groups_parents(self):
20332
parent = ErrorRaisingArgumentParser(add_help=False)
20333
@@ -2201,8 +2204,9 @@
20334
['-y', 'Y', '-z', 'Z'])
20336
parser_help = parser.format_help()
20337
+ progname = self.main_program
20338
self.assertEqual(parser_help, textwrap.dedent('''\
20339
- usage: {} [-h] [-w W] [-x X] [-y Y | -z Z]
20340
+ usage: {}{}[-h] [-w W] [-x X] [-y Y | -z Z]
20342
optional arguments:
20343
-h, --help show this help message and exit
20344
@@ -2214,7 +2218,7 @@
20348
- '''.format(self.main_program)))
20349
+ '''.format(progname, ' ' if progname else '' )))
20351
# ==============================
20352
# Mutually exclusive group tests
20353
diff -r 137e45f15c0b Lib/test/test_ast.py
20354
--- a/Lib/test/test_ast.py
20355
+++ b/Lib/test/test_ast.py
20356
@@ -290,7 +290,7 @@
20357
self.assertEqual(x.body, body)
20359
def test_nodeclasses(self):
20360
- # Zero arguments constructor explicitely allowed
20361
+ # Zero arguments constructor explicitly allowed
20363
self.assertEqual(x._fields, ('left', 'op', 'right'))
20365
@@ -486,6 +486,17 @@
20366
self.assertEqual(ast.literal_eval('10 + 2j'), 10 + 2j)
20367
self.assertEqual(ast.literal_eval('1.5 - 2j'), 1.5 - 2j)
20369
+ def test_bad_integer(self):
20370
+ # issue13436: Bad error message with invalid numeric values
20371
+ body = [ast.ImportFrom(module='time',
20372
+ names=[ast.alias(name='sleep')],
20374
+ lineno=None, col_offset=None)]
20375
+ mod = ast.Module(body)
20376
+ with self.assertRaises(ValueError) as cm:
20377
+ compile(mod, 'test', 'exec')
20378
+ self.assertIn("invalid integer value: None", str(cm.exception))
20382
support.run_unittest(AST_Tests, ASTHelpers_Test)
20383
diff -r 137e45f15c0b Lib/test/test_audioop.py
20384
--- a/Lib/test/test_audioop.py
20385
+++ b/Lib/test/test_audioop.py
20388
from test.support import run_unittest
20390
+endian = 'big' if audioop.getsample(b'\0\1', 2, 0) == 1 else 'little'
20396
- if audioop.getsample(b'\0\1', 2, 0) == 1:
20397
+ if endian == 'big':
20398
return b'\0\0\0\1\0\2'
20400
return b'\0\0\1\0\2\0'
20403
- if audioop.getsample(b'\0\0\0\1', 4, 0) == 1:
20404
+ if endian == 'big':
20405
return b'\0\0\0\0\0\0\0\1\0\0\0\2'
20407
return b'\0\0\0\0\1\0\0\0\2\0\0\0'
20409
data = [gendata1(), gendata2(), gendata4()]
20423
def test_adpcm2lin(self):
20424
# Very cursory test
20425
- self.assertEqual(audioop.adpcm2lin(b'\0\0', 1, None), (b'\0\0\0\0', (0,0)))
20426
+ self.assertEqual(audioop.adpcm2lin(b'\0\0', 1, None), (b'\0' * 4, (0,0)))
20427
+ self.assertEqual(audioop.adpcm2lin(b'\0\0', 2, None), (b'\0' * 8, (0,0)))
20428
+ self.assertEqual(audioop.adpcm2lin(b'\0\0', 4, None), (b'\0' * 16, (0,0)))
20430
def test_lin2adpcm(self):
20431
# Very cursory test
20432
@@ -109,6 +112,16 @@
20434
d = audioop.lin2alaw(data[0], 1)
20435
self.assertEqual(audioop.alaw2lin(d, 1), data[0])
20436
+ if endian == 'big':
20437
+ self.assertEqual(audioop.alaw2lin(d, 2),
20438
+ b'\x00\x08\x01\x08\x02\x10')
20439
+ self.assertEqual(audioop.alaw2lin(d, 4),
20440
+ b'\x00\x08\x00\x00\x01\x08\x00\x00\x02\x10\x00\x00')
20442
+ self.assertEqual(audioop.alaw2lin(d, 2),
20443
+ b'\x08\x00\x08\x01\x10\x02')
20444
+ self.assertEqual(audioop.alaw2lin(d, 4),
20445
+ b'\x00\x00\x08\x00\x00\x00\x08\x01\x00\x00\x10\x02')
20447
def test_lin2ulaw(self):
20448
self.assertEqual(audioop.lin2ulaw(data[0], 1), b'\xff\xe7\xdb')
20449
@@ -119,6 +132,16 @@
20451
d = audioop.lin2ulaw(data[0], 1)
20452
self.assertEqual(audioop.ulaw2lin(d, 1), data[0])
20453
+ if endian == 'big':
20454
+ self.assertEqual(audioop.ulaw2lin(d, 2),
20455
+ b'\x00\x00\x01\x04\x02\x0c')
20456
+ self.assertEqual(audioop.ulaw2lin(d, 4),
20457
+ b'\x00\x00\x00\x00\x01\x04\x00\x00\x02\x0c\x00\x00')
20459
+ self.assertEqual(audioop.ulaw2lin(d, 2),
20460
+ b'\x00\x00\x04\x01\x0c\x02')
20461
+ self.assertEqual(audioop.ulaw2lin(d, 4),
20462
+ b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x0c\x02')
20464
def test_mul(self):
20466
@@ -195,10 +218,15 @@
20467
self.assertRaises(audioop.error, audioop.lin2lin, data, size, size2)
20468
self.assertRaises(audioop.error, audioop.ratecv, data, size, 1, 1, 1, state)
20469
self.assertRaises(audioop.error, audioop.lin2ulaw, data, size)
20470
+ self.assertRaises(audioop.error, audioop.lin2alaw, data, size)
20471
+ self.assertRaises(audioop.error, audioop.lin2adpcm, data, size, state)
20473
+ def test_wrongsize(self):
20476
+ for size in (-1, 3, 5):
20477
self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
20478
- self.assertRaises(audioop.error, audioop.lin2alaw, data, size)
20479
self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
20480
- self.assertRaises(audioop.error, audioop.lin2adpcm, data, size, state)
20481
self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
20484
diff -r 137e45f15c0b Lib/test/test_bigmem.py
20485
--- a/Lib/test/test_bigmem.py
20486
+++ b/Lib/test/test_bigmem.py
1728
- 'multiprocessing.process._dangling')
1729
+ 'multiprocessing.process._dangling',
1733
def get_sys_argv(self):
1734
return id(sys.argv), sys.argv, sys.argv[:]
1735
@@ -1020,6 +1022,21 @@
1736
multiprocessing.process._dangling.clear()
1737
multiprocessing.process._dangling.update(saved)
1739
+ def get_support_TESTFN(self):
1740
+ if os.path.isfile(support.TESTFN):
1742
+ elif os.path.isdir(support.TESTFN):
1747
+ def restore_support_TESTFN(self, saved_value):
1748
+ if saved_value is None:
1749
+ if os.path.isfile(support.TESTFN):
1750
+ os.unlink(support.TESTFN)
1751
+ elif os.path.isdir(support.TESTFN):
1752
+ shutil.rmtree(support.TESTFN)
1754
def resource_info(self):
1755
for name in self.resources:
1756
method_suffix = name.replace('.', '_')
1757
diff -r 7085403daf43 Lib/test/test_base64.py
1758
--- a/Lib/test/test_base64.py
1759
+++ b/Lib/test/test_base64.py
20488
1761
from test import support
20489
-from test.support import bigmemtest, _1G, _2G, _4G, precisionbigmemtest
20490
+from test.support import bigmemtest, _1G, _2G, _4G
20494
@@ -25,10 +25,10 @@
20495
# a large object, make the subobject of a length that is not a power of
20496
# 2. That way, int-wrapping problems are more easily detected.
20498
-# - While the bigmemtest decorator speaks of 'minsize', all tests will
20499
-# actually be called with a much smaller number too, in the normal
20500
-# test run (5Kb currently.) This is so the tests themselves get frequent
20501
-# testing. Consequently, always make all large allocations based on the
20502
+# - Despite the bigmemtest decorator, all tests will actually be called
20503
+# with a much smaller number too, in the normal test run (5Kb currently.)
20504
+# This is so the tests themselves get frequent testing.
20505
+# Consequently, always make all large allocations based on the
20506
# passed-in 'size', and don't rely on the size being very large. Also,
20507
# memuse-per-size should remain sane (less than a few thousand); if your
20508
# test uses more, adjust 'size' upward, instead.
20513
- @bigmemtest(minsize=_2G, memuse=2)
20514
+ @bigmemtest(size=_2G, memuse=2)
20515
def test_capitalize(self, size):
20516
_ = self.from_latin1
20517
SUBSTR = self.from_latin1(' abc def ghi')
20519
SUBSTR.capitalize())
20520
self.assertEqual(caps.lstrip(_('-')), SUBSTR)
20522
- @bigmemtest(minsize=_2G + 10, memuse=1)
20523
+ @bigmemtest(size=_2G + 10, memuse=1)
20524
def test_center(self, size):
20525
SUBSTR = self.from_latin1(' abc def ghi')
20526
s = SUBSTR.center(size)
20528
self.assertEqual(s[lpadsize:-rpadsize], SUBSTR)
20529
self.assertEqual(s.strip(), SUBSTR.strip())
20531
- @bigmemtest(minsize=_2G, memuse=2)
20532
+ @bigmemtest(size=_2G, memuse=2)
20533
def test_count(self, size):
20534
_ = self.from_latin1
20535
SUBSTR = _(' abc def ghi')
20537
self.assertEqual(s.count(_('i')), 1)
20538
self.assertEqual(s.count(_('j')), 0)
20540
- @bigmemtest(minsize=_2G, memuse=2)
20541
+ @bigmemtest(size=_2G, memuse=2)
20542
def test_endswith(self, size):
20543
_ = self.from_latin1
20544
SUBSTR = _(' abc def ghi')
20546
self.assertFalse(s.endswith(_('a') + SUBSTR))
20547
self.assertFalse(SUBSTR.endswith(s))
20549
- @bigmemtest(minsize=_2G + 10, memuse=2)
20550
+ @bigmemtest(size=_2G + 10, memuse=2)
20551
def test_expandtabs(self, size):
20552
_ = self.from_latin1
20554
@@ -100,7 +100,7 @@
20555
self.assertEqual(len(s), size - remainder)
20556
self.assertEqual(len(s.strip(_(' '))), 0)
20558
- @bigmemtest(minsize=_2G, memuse=2)
20559
+ @bigmemtest(size=_2G, memuse=2)
20560
def test_find(self, size):
20561
_ = self.from_latin1
20562
SUBSTR = _(' abc def ghi')
20563
@@ -117,7 +117,7 @@
20564
sublen + size + SUBSTR.find(_('i')))
20565
self.assertEqual(s.find(_('j')), -1)
20567
- @bigmemtest(minsize=_2G, memuse=2)
20568
+ @bigmemtest(size=_2G, memuse=2)
20569
def test_index(self, size):
20570
_ = self.from_latin1
20571
SUBSTR = _(' abc def ghi')
20572
@@ -134,7 +134,7 @@
20573
sublen + size + SUBSTR.index(_('i')))
20574
self.assertRaises(ValueError, s.index, _('j'))
20576
- @bigmemtest(minsize=_2G, memuse=2)
20577
+ @bigmemtest(size=_2G, memuse=2)
20578
def test_isalnum(self, size):
20579
_ = self.from_latin1
20580
SUBSTR = _('123456')
20581
@@ -143,7 +143,7 @@
20583
self.assertFalse(s.isalnum())
20585
- @bigmemtest(minsize=_2G, memuse=2)
20586
+ @bigmemtest(size=_2G, memuse=2)
20587
def test_isalpha(self, size):
20588
_ = self.from_latin1
20589
SUBSTR = _('zzzzzzz')
20590
@@ -152,7 +152,7 @@
20592
self.assertFalse(s.isalpha())
20594
- @bigmemtest(minsize=_2G, memuse=2)
20595
+ @bigmemtest(size=_2G, memuse=2)
20596
def test_isdigit(self, size):
20597
_ = self.from_latin1
20598
SUBSTR = _('123456')
20599
@@ -161,7 +161,7 @@
20601
self.assertFalse(s.isdigit())
20603
- @bigmemtest(minsize=_2G, memuse=2)
20604
+ @bigmemtest(size=_2G, memuse=2)
20605
def test_islower(self, size):
20606
_ = self.from_latin1
20608
@@ -172,7 +172,7 @@
20610
self.assertFalse(s.islower())
20612
- @bigmemtest(minsize=_2G, memuse=2)
20613
+ @bigmemtest(size=_2G, memuse=2)
20614
def test_isspace(self, size):
20615
_ = self.from_latin1
20616
whitespace = _(' \f\n\r\t\v')
20617
@@ -182,7 +182,7 @@
20619
self.assertFalse(s.isspace())
20621
- @bigmemtest(minsize=_2G, memuse=2)
20622
+ @bigmemtest(size=_2G, memuse=2)
20623
def test_istitle(self, size):
20624
_ = self.from_latin1
20625
SUBSTR = _('123456')
20626
@@ -193,7 +193,7 @@
20628
self.assertFalse(s.istitle())
20630
- @bigmemtest(minsize=_2G, memuse=2)
20631
+ @bigmemtest(size=_2G, memuse=2)
20632
def test_isupper(self, size):
20633
_ = self.from_latin1
20635
@@ -204,7 +204,7 @@
20637
self.assertFalse(s.isupper())
20639
- @bigmemtest(minsize=_2G, memuse=2)
20640
+ @bigmemtest(size=_2G, memuse=2)
20641
def test_join(self, size):
20642
_ = self.from_latin1
20644
@@ -214,7 +214,7 @@
20645
self.assertTrue(x.startswith(_('aaaaaA')))
20646
self.assertTrue(x.endswith(_('Abbbbb')))
20648
- @bigmemtest(minsize=_2G + 10, memuse=1)
20649
+ @bigmemtest(size=_2G + 10, memuse=1)
20650
def test_ljust(self, size):
20651
_ = self.from_latin1
20652
SUBSTR = _(' abc def ghi')
20653
@@ -223,7 +223,7 @@
20654
self.assertEqual(len(s), size)
20655
self.assertEqual(s.strip(), SUBSTR.strip())
20657
- @bigmemtest(minsize=_2G + 10, memuse=2)
20658
+ @bigmemtest(size=_2G + 10, memuse=2)
20659
def test_lower(self, size):
20660
_ = self.from_latin1
20662
@@ -231,7 +231,7 @@
20663
self.assertEqual(len(s), size)
20664
self.assertEqual(s.count(_('a')), size)
20666
- @bigmemtest(minsize=_2G + 10, memuse=1)
20667
+ @bigmemtest(size=_2G + 10, memuse=1)
20668
def test_lstrip(self, size):
20669
_ = self.from_latin1
20670
SUBSTR = _('abc def ghi')
20671
@@ -246,7 +246,7 @@
20672
stripped = s.lstrip()
20673
self.assertTrue(stripped is s)
20675
- @bigmemtest(minsize=_2G + 10, memuse=2)
20676
+ @bigmemtest(size=_2G + 10, memuse=2)
20677
def test_replace(self, size):
20678
_ = self.from_latin1
20679
replacement = _('a')
20680
@@ -259,7 +259,7 @@
20681
self.assertEqual(s.count(replacement), 4)
20682
self.assertEqual(s[-10:], _(' aaaa'))
20684
- @bigmemtest(minsize=_2G, memuse=2)
20685
+ @bigmemtest(size=_2G, memuse=2)
20686
def test_rfind(self, size):
20687
_ = self.from_latin1
20688
SUBSTR = _(' abc def ghi')
20689
@@ -275,7 +275,7 @@
20690
SUBSTR.rfind(_('i')))
20691
self.assertEqual(s.rfind(_('j')), -1)
20693
- @bigmemtest(minsize=_2G, memuse=2)
20694
+ @bigmemtest(size=_2G, memuse=2)
20695
def test_rindex(self, size):
20696
_ = self.from_latin1
20697
SUBSTR = _(' abc def ghi')
20698
@@ -294,7 +294,7 @@
20699
SUBSTR.rindex(_('i')))
20700
self.assertRaises(ValueError, s.rindex, _('j'))
20702
- @bigmemtest(minsize=_2G + 10, memuse=1)
20703
+ @bigmemtest(size=_2G + 10, memuse=1)
20704
def test_rjust(self, size):
20705
_ = self.from_latin1
20706
SUBSTR = _(' abc def ghi')
20707
@@ -303,7 +303,7 @@
20708
self.assertEqual(len(s), size)
20709
self.assertEqual(s.strip(), SUBSTR.strip())
20711
- @bigmemtest(minsize=_2G + 10, memuse=1)
20712
+ @bigmemtest(size=_2G + 10, memuse=1)
20713
def test_rstrip(self, size):
20714
_ = self.from_latin1
20715
SUBSTR = _(' abc def ghi')
20716
@@ -321,7 +321,7 @@
20717
# The test takes about size bytes to build a string, and then about
20718
# sqrt(size) substrings of sqrt(size) in size and a list to
20719
# hold sqrt(size) items. It's close but just over 2x size.
20720
- @bigmemtest(minsize=_2G, memuse=2.1)
20721
+ @bigmemtest(size=_2G, memuse=2.1)
20722
def test_split_small(self, size):
20723
_ = self.from_latin1
20724
# Crudely calculate an estimate so that the result of s.split won't
20725
@@ -347,7 +347,7 @@
20726
# suffer for the list size. (Otherwise, it'd cost another 48 times
20727
# size in bytes!) Nevertheless, a list of size takes
20729
- @bigmemtest(minsize=_2G + 5, memuse=10)
20730
+ @bigmemtest(size=_2G + 5, memuse=10)
20731
def test_split_large(self, size):
20732
_ = self.from_latin1
20733
s = _(' a') * size + _(' ')
20734
@@ -359,7 +359,7 @@
20735
self.assertEqual(len(l), size + 1)
20736
self.assertEqual(set(l), set([_(' ')]))
20738
- @bigmemtest(minsize=_2G, memuse=2.1)
20739
+ @bigmemtest(size=_2G, memuse=2.1)
20740
def test_splitlines(self, size):
20741
_ = self.from_latin1
20742
# Crudely calculate an estimate so that the result of s.split won't
20743
@@ -373,7 +373,7 @@
20745
self.assertEqual(item, expected)
20747
- @bigmemtest(minsize=_2G, memuse=2)
20748
+ @bigmemtest(size=_2G, memuse=2)
20749
def test_startswith(self, size):
20750
_ = self.from_latin1
20751
SUBSTR = _(' abc def ghi')
20752
@@ -382,7 +382,7 @@
20753
self.assertTrue(s.startswith(_('-') * size))
20754
self.assertFalse(s.startswith(SUBSTR))
20756
- @bigmemtest(minsize=_2G, memuse=1)
20757
+ @bigmemtest(size=_2G, memuse=1)
20758
def test_strip(self, size):
20759
_ = self.from_latin1
20760
SUBSTR = _(' abc def ghi ')
20761
@@ -394,7 +394,7 @@
20762
self.assertEqual(len(s), size)
20763
self.assertEqual(s.strip(), SUBSTR.strip())
20765
- @bigmemtest(minsize=_2G, memuse=2)
20766
+ @bigmemtest(size=_2G, memuse=2)
20767
def test_swapcase(self, size):
20768
_ = self.from_latin1
20769
SUBSTR = _("aBcDeFG12.'\xa9\x00")
20770
@@ -406,7 +406,7 @@
20771
self.assertEqual(s[:sublen * 3], SUBSTR.swapcase() * 3)
20772
self.assertEqual(s[-sublen * 3:], SUBSTR.swapcase() * 3)
20774
- @bigmemtest(minsize=_2G, memuse=2)
20775
+ @bigmemtest(size=_2G, memuse=2)
20776
def test_title(self, size):
20777
_ = self.from_latin1
20778
SUBSTR = _('SpaaHAaaAaham')
20779
@@ -415,7 +415,7 @@
20780
self.assertTrue(s.startswith((SUBSTR * 3).title()))
20781
self.assertTrue(s.endswith(SUBSTR.lower() * 3))
20783
- @bigmemtest(minsize=_2G, memuse=2)
20784
+ @bigmemtest(size=_2G, memuse=2)
20785
def test_translate(self, size):
20786
_ = self.from_latin1
20787
SUBSTR = _('aZz.z.Aaz.')
20788
@@ -438,7 +438,7 @@
20789
self.assertEqual(s.count(_('!')), repeats * 2)
20790
self.assertEqual(s.count(_('z')), repeats * 3)
20792
- @bigmemtest(minsize=_2G + 5, memuse=2)
20793
+ @bigmemtest(size=_2G + 5, memuse=2)
20794
def test_upper(self, size):
20795
_ = self.from_latin1
20797
@@ -446,7 +446,7 @@
20798
self.assertEqual(len(s), size)
20799
self.assertEqual(s.count(_('A')), size)
20801
- @bigmemtest(minsize=_2G + 20, memuse=1)
20802
+ @bigmemtest(size=_2G + 20, memuse=1)
20803
def test_zfill(self, size):
20804
_ = self.from_latin1
20805
SUBSTR = _('-568324723598234')
20806
@@ -458,7 +458,7 @@
20808
# This test is meaningful even with size < 2G, as long as the
20809
# doubled string is > 2G (but it tests more if both are > 2G :)
20810
- @bigmemtest(minsize=_1G + 2, memuse=3)
20811
+ @bigmemtest(size=_1G + 2, memuse=3)
20812
def test_concat(self, size):
20813
_ = self.from_latin1
20815
@@ -469,7 +469,7 @@
20817
# This test is meaningful even with size < 2G, as long as the
20818
# repeated string is > 2G (but it tests more if both are > 2G :)
20819
- @bigmemtest(minsize=_1G + 2, memuse=3)
20820
+ @bigmemtest(size=_1G + 2, memuse=3)
20821
def test_repeat(self, size):
20822
_ = self.from_latin1
20824
@@ -478,7 +478,7 @@
20825
self.assertEqual(len(s), size * 2)
20826
self.assertEqual(s.count(_('.')), size * 2)
20828
- @bigmemtest(minsize=_2G + 20, memuse=2)
20829
+ @bigmemtest(size=_2G + 20, memuse=2)
20830
def test_slice_and_getitem(self, size):
20831
_ = self.from_latin1
20832
SUBSTR = _('0123456789')
20833
@@ -512,7 +512,7 @@
20834
self.assertRaises(IndexError, operator.getitem, s, len(s) + 1)
20835
self.assertRaises(IndexError, operator.getitem, s, len(s) + 1<<31)
20837
- @bigmemtest(minsize=_2G, memuse=2)
20838
+ @bigmemtest(size=_2G, memuse=2)
20839
def test_contains(self, size):
20840
_ = self.from_latin1
20841
SUBSTR = _('0123456789')
20842
@@ -526,7 +526,7 @@
20844
self.assertIn(_('a'), s)
20846
- @bigmemtest(minsize=_2G + 10, memuse=2)
20847
+ @bigmemtest(size=_2G + 10, memuse=2)
20848
def test_compare(self, size):
20849
_ = self.from_latin1
20851
@@ -539,7 +539,7 @@
20853
self.assertFalse(s1 == s2)
20855
- @bigmemtest(minsize=_2G + 10, memuse=1)
20856
+ @bigmemtest(size=_2G + 10, memuse=1)
20857
def test_hash(self, size):
20858
# Not sure if we can do any meaningful tests here... Even if we
20859
# start relying on the exact algorithm used, the result will be
20860
@@ -590,46 +590,36 @@
20861
getattr(type(self), name).memuse = memuse
20863
# the utf8 encoder preallocates big time (4x the number of characters)
20864
- @bigmemtest(minsize=_2G + 2, memuse=character_size + 4)
20865
+ @bigmemtest(size=_2G + 2, memuse=character_size + 4)
20866
def test_encode(self, size):
20867
return self.basic_encode_test(size, 'utf-8')
20869
- @precisionbigmemtest(size=_4G // 6 + 2, memuse=character_size + 1)
20870
+ @bigmemtest(size=_4G // 6 + 2, memuse=character_size + 1)
20871
def test_encode_raw_unicode_escape(self, size):
20873
return self.basic_encode_test(size, 'raw_unicode_escape')
20874
except MemoryError:
20875
pass # acceptable on 32-bit
20877
- @precisionbigmemtest(size=_4G // 5 + 70, memuse=character_size + 1)
20878
+ @bigmemtest(size=_4G // 5 + 70, memuse=character_size + 1)
20879
def test_encode_utf7(self, size):
20881
return self.basic_encode_test(size, 'utf7')
20882
except MemoryError:
20883
pass # acceptable on 32-bit
20885
- @precisionbigmemtest(size=_4G // 4 + 5, memuse=character_size + 4)
20886
+ @bigmemtest(size=_4G // 4 + 5, memuse=character_size + 4)
20887
def test_encode_utf32(self, size):
20889
return self.basic_encode_test(size, 'utf32', expectedsize=4*size+4)
20890
except MemoryError:
20891
pass # acceptable on 32-bit
20893
- @precisionbigmemtest(size=_2G - 1, memuse=character_size + 1)
20894
+ @bigmemtest(size=_2G - 1, memuse=character_size + 1)
20895
def test_encode_ascii(self, size):
20896
return self.basic_encode_test(size, 'ascii', c='A')
20898
- @precisionbigmemtest(size=_4G // 5, memuse=character_size * (6 + 1))
20899
- def test_unicode_repr_overflow(self, size):
20901
- s = "\uDCBA"*size
20903
- except MemoryError:
20904
- pass # acceptable on 32-bit
20906
- self.assertTrue(s == eval(r))
20908
- @bigmemtest(minsize=_2G + 10, memuse=character_size * 2)
20909
+ @bigmemtest(size=_2G + 10, memuse=character_size * 2)
20910
def test_format(self, size):
20913
@@ -650,7 +640,7 @@
20914
self.assertEqual(s.count('.'), 3)
20915
self.assertEqual(s.count('-'), size * 2)
20917
- @bigmemtest(minsize=_2G + 10, memuse=character_size * 2)
20918
+ @bigmemtest(size=_2G + 10, memuse=character_size * 2)
20919
def test_repr_small(self, size):
20922
@@ -671,7 +661,7 @@
20923
self.assertEqual(s.count('\\'), size)
20924
self.assertEqual(s.count('0'), size * 2)
20926
- @bigmemtest(minsize=_2G + 10, memuse=character_size * 5)
20927
+ @bigmemtest(size=_2G + 10, memuse=character_size * 5)
20928
def test_repr_large(self, size):
20931
@@ -681,27 +671,46 @@
20932
self.assertEqual(s.count('\\'), size)
20933
self.assertEqual(s.count('0'), size * 2)
20935
- @bigmemtest(minsize=2**32 / 5, memuse=character_size * 7)
20936
+ @bigmemtest(size=_2G // 5 + 1, memuse=character_size * 7)
20937
def test_unicode_repr(self, size):
20938
# Use an assigned, but not printable code point.
20939
# It is in the range of the low surrogates \uDC00-\uDFFF.
20940
- s = "\uDCBA" * size
20941
- for f in (repr, ascii):
20943
- self.assertTrue(len(r) > size)
20944
- self.assertTrue(r.endswith(r"\udcba'"), r[-10:])
20949
+ for f in (repr, ascii):
20951
+ self.assertEqual(len(r), 2 + (len(f(char)) - 2) * size)
20952
+ self.assertTrue(r.endswith(r"\udcba'"), r[-10:])
20957
# The character takes 4 bytes even in UCS-2 builds because it will
20958
# be decomposed into surrogates.
20959
- @bigmemtest(minsize=2**32 / 5, memuse=4 + character_size * 9)
20960
+ @bigmemtest(size=_2G // 5 + 1, memuse=4 + character_size * 9)
20961
def test_unicode_repr_wide(self, size):
20962
- s = "\U0001DCBA" * size
20963
- for f in (repr, ascii):
20965
- self.assertTrue(len(r) > size)
20966
- self.assertTrue(r.endswith(r"\U0001dcba'"), r[-12:])
20968
+ char = "\U0001DCBA"
20971
+ for f in (repr, ascii):
20973
+ self.assertEqual(len(r), 2 + (len(f(char)) - 2) * size)
20974
+ self.assertTrue(r.endswith(r"\U0001dcba'"), r[-12:])
20979
+ @bigmemtest(size=_4G // 5, memuse=character_size * (6 + 1))
20980
+ def _test_unicode_repr_overflow(self, size):
20981
+ # XXX not sure what this test is about
20986
+ self.assertTrue(s == eval(r))
20991
class BytesTest(unittest.TestCase, BaseStrTest):
20992
@@ -709,7 +718,7 @@
20993
def from_latin1(self, s):
20994
return s.encode("latin1")
20996
- @bigmemtest(minsize=_2G + 2, memuse=1 + character_size)
20997
+ @bigmemtest(size=_2G + 2, memuse=1 + character_size)
20998
def test_decode(self, size):
20999
s = self.from_latin1('.') * size
21000
self.assertEqual(len(s.decode('utf-8')), size)
21001
@@ -720,7 +729,7 @@
21002
def from_latin1(self, s):
21003
return bytearray(s.encode("latin1"))
21005
- @bigmemtest(minsize=_2G + 2, memuse=1 + character_size)
21006
+ @bigmemtest(size=_2G + 2, memuse=1 + character_size)
21007
def test_decode(self, size):
21008
s = self.from_latin1('.') * size
21009
self.assertEqual(len(s.decode('utf-8')), size)
21010
@@ -739,7 +748,7 @@
21011
# having more than 2<<31 references to any given object. Hence the
21012
# use of different types of objects as contents in different tests.
21014
- @bigmemtest(minsize=_2G + 2, memuse=16)
21015
+ @bigmemtest(size=_2G + 2, memuse=16)
21016
def test_compare(self, size):
21019
@@ -762,15 +771,15 @@
21021
self.assertEqual(len(t), size * 2)
21023
- @bigmemtest(minsize=_2G // 2 + 2, memuse=24)
21024
+ @bigmemtest(size=_2G // 2 + 2, memuse=24)
21025
def test_concat_small(self, size):
21026
return self.basic_concat_test(size)
21028
- @bigmemtest(minsize=_2G + 2, memuse=24)
21029
+ @bigmemtest(size=_2G + 2, memuse=24)
21030
def test_concat_large(self, size):
21031
return self.basic_concat_test(size)
21033
- @bigmemtest(minsize=_2G // 5 + 10, memuse=8 * 5)
21034
+ @bigmemtest(size=_2G // 5 + 10, memuse=8 * 5)
21035
def test_contains(self, size):
21036
t = (1, 2, 3, 4, 5) * size
21037
self.assertEqual(len(t), size * 5)
21038
@@ -778,7 +787,7 @@
21039
self.assertNotIn((1, 2, 3, 4, 5), t)
21040
self.assertNotIn(0, t)
21042
- @bigmemtest(minsize=_2G + 10, memuse=8)
21043
+ @bigmemtest(size=_2G + 10, memuse=8)
21044
def test_hash(self, size):
21047
@@ -786,7 +795,7 @@
21048
t2 = (0,) * (size + 1)
21049
self.assertFalse(h1 == hash(t2))
21051
- @bigmemtest(minsize=_2G + 10, memuse=8)
21052
+ @bigmemtest(size=_2G + 10, memuse=8)
21053
def test_index_and_slice(self, size):
21055
self.assertEqual(len(t), size)
21056
@@ -811,19 +820,19 @@
21058
self.assertEqual(len(t), size * 2)
21060
- @bigmemtest(minsize=_2G // 2 + 2, memuse=24)
21061
+ @bigmemtest(size=_2G // 2 + 2, memuse=24)
21062
def test_repeat_small(self, size):
21063
return self.basic_test_repeat(size)
21065
- @bigmemtest(minsize=_2G + 2, memuse=24)
21066
+ @bigmemtest(size=_2G + 2, memuse=24)
21067
def test_repeat_large(self, size):
21068
return self.basic_test_repeat(size)
21070
- @bigmemtest(minsize=_1G - 1, memuse=12)
21071
+ @bigmemtest(size=_1G - 1, memuse=12)
21072
def test_repeat_large_2(self, size):
21073
return self.basic_test_repeat(size)
21075
- @precisionbigmemtest(size=_1G - 1, memuse=9)
21076
+ @bigmemtest(size=_1G - 1, memuse=9)
21077
def test_from_2G_generator(self, size):
21078
self.skipTest("test needs much more memory than advertised, see issue5438")
21080
@@ -837,7 +846,7 @@
21082
self.assertEqual(count, size)
21084
- @precisionbigmemtest(size=_1G - 25, memuse=9)
21085
+ @bigmemtest(size=_1G - 25, memuse=9)
21086
def test_from_almost_2G_generator(self, size):
21087
self.skipTest("test needs much more memory than advertised, see issue5438")
21089
@@ -860,11 +869,11 @@
21090
self.assertEqual(s[-5:], '0, 0)')
21091
self.assertEqual(s.count('0'), size)
21093
- @bigmemtest(minsize=_2G // 3 + 2, memuse=8 + 3 * character_size)
21094
+ @bigmemtest(size=_2G // 3 + 2, memuse=8 + 3 * character_size)
21095
def test_repr_small(self, size):
21096
return self.basic_test_repr(size)
21098
- @bigmemtest(minsize=_2G + 2, memuse=8 + 3 * character_size)
21099
+ @bigmemtest(size=_2G + 2, memuse=8 + 3 * character_size)
21100
def test_repr_large(self, size):
21101
return self.basic_test_repr(size)
21103
@@ -875,7 +884,7 @@
21104
# lists hold references to various objects to test their refcount
21107
- @bigmemtest(minsize=_2G + 2, memuse=16)
21108
+ @bigmemtest(size=_2G + 2, memuse=16)
21109
def test_compare(self, size):
21112
@@ -898,11 +907,11 @@
21114
self.assertEqual(len(l), size * 2)
21116
- @bigmemtest(minsize=_2G // 2 + 2, memuse=24)
21117
+ @bigmemtest(size=_2G // 2 + 2, memuse=24)
21118
def test_concat_small(self, size):
21119
return self.basic_test_concat(size)
21121
- @bigmemtest(minsize=_2G + 2, memuse=24)
21122
+ @bigmemtest(size=_2G + 2, memuse=24)
21123
def test_concat_large(self, size):
21124
return self.basic_test_concat(size)
21126
@@ -913,15 +922,15 @@
21127
self.assertTrue(l[0] is l[-1])
21128
self.assertTrue(l[size - 1] is l[size + 1])
21130
- @bigmemtest(minsize=_2G // 2 + 2, memuse=24)
21131
+ @bigmemtest(size=_2G // 2 + 2, memuse=24)
21132
def test_inplace_concat_small(self, size):
21133
return self.basic_test_inplace_concat(size)
21135
- @bigmemtest(minsize=_2G + 2, memuse=24)
21136
+ @bigmemtest(size=_2G + 2, memuse=24)
21137
def test_inplace_concat_large(self, size):
21138
return self.basic_test_inplace_concat(size)
21140
- @bigmemtest(minsize=_2G // 5 + 10, memuse=8 * 5)
21141
+ @bigmemtest(size=_2G // 5 + 10, memuse=8 * 5)
21142
def test_contains(self, size):
21143
l = [1, 2, 3, 4, 5] * size
21144
self.assertEqual(len(l), size * 5)
21145
@@ -929,12 +938,12 @@
21146
self.assertNotIn([1, 2, 3, 4, 5], l)
21147
self.assertNotIn(0, l)
21149
- @bigmemtest(minsize=_2G + 10, memuse=8)
21150
+ @bigmemtest(size=_2G + 10, memuse=8)
21151
def test_hash(self, size):
21153
self.assertRaises(TypeError, hash, l)
21155
- @bigmemtest(minsize=_2G + 10, memuse=8)
21156
+ @bigmemtest(size=_2G + 10, memuse=8)
21157
def test_index_and_slice(self, size):
21159
self.assertEqual(len(l), size)
21160
@@ -998,11 +1007,11 @@
21162
self.assertEqual(len(l), size * 2)
21164
- @bigmemtest(minsize=_2G // 2 + 2, memuse=24)
21165
+ @bigmemtest(size=_2G // 2 + 2, memuse=24)
21166
def test_repeat_small(self, size):
21167
return self.basic_test_repeat(size)
21169
- @bigmemtest(minsize=_2G + 2, memuse=24)
21170
+ @bigmemtest(size=_2G + 2, memuse=24)
21171
def test_repeat_large(self, size):
21172
return self.basic_test_repeat(size)
21174
@@ -1018,11 +1027,11 @@
21175
self.assertEqual(len(l), size * 2)
21176
self.assertTrue(l[size - 1] is l[-1])
21178
- @bigmemtest(minsize=_2G // 2 + 2, memuse=16)
21179
+ @bigmemtest(size=_2G // 2 + 2, memuse=16)
21180
def test_inplace_repeat_small(self, size):
21181
return self.basic_test_inplace_repeat(size)
21183
- @bigmemtest(minsize=_2G + 2, memuse=16)
21184
+ @bigmemtest(size=_2G + 2, memuse=16)
21185
def test_inplace_repeat_large(self, size):
21186
return self.basic_test_inplace_repeat(size)
21188
@@ -1035,17 +1044,17 @@
21189
self.assertEqual(s[-5:], '0, 0]')
21190
self.assertEqual(s.count('0'), size)
21192
- @bigmemtest(minsize=_2G // 3 + 2, memuse=8 + 3 * character_size)
21193
+ @bigmemtest(size=_2G // 3 + 2, memuse=8 + 3 * character_size)
21194
def test_repr_small(self, size):
21195
return self.basic_test_repr(size)
21197
- @bigmemtest(minsize=_2G + 2, memuse=8 + 3 * character_size)
21198
+ @bigmemtest(size=_2G + 2, memuse=8 + 3 * character_size)
21199
def test_repr_large(self, size):
21200
return self.basic_test_repr(size)
21202
# list overallocates ~1/8th of the total size (on first expansion) so
21203
# the single list.append call puts memuse at 9 bytes per size.
21204
- @bigmemtest(minsize=_2G, memuse=9)
21205
+ @bigmemtest(size=_2G, memuse=9)
21206
def test_append(self, size):
21207
l = [object()] * size
21209
@@ -1053,7 +1062,7 @@
21210
self.assertTrue(l[-3] is l[-2])
21211
self.assertFalse(l[-2] is l[-1])
21213
- @bigmemtest(minsize=_2G // 5 + 2, memuse=8 * 5)
21214
+ @bigmemtest(size=_2G // 5 + 2, memuse=8 * 5)
21215
def test_count(self, size):
21216
l = [1, 2, 3, 4, 5] * size
21217
self.assertEqual(l.count(1), size)
21218
@@ -1066,15 +1075,15 @@
21219
self.assertTrue(l[0] is l[-1])
21220
self.assertTrue(l[size - 1] is l[size + 1])
21222
- @bigmemtest(minsize=_2G // 2 + 2, memuse=16)
21223
+ @bigmemtest(size=_2G // 2 + 2, memuse=16)
21224
def test_extend_small(self, size):
21225
return self.basic_test_extend(size)
21227
- @bigmemtest(minsize=_2G + 2, memuse=16)
21228
+ @bigmemtest(size=_2G + 2, memuse=16)
21229
def test_extend_large(self, size):
21230
return self.basic_test_extend(size)
21232
- @bigmemtest(minsize=_2G // 5 + 2, memuse=8 * 5)
21233
+ @bigmemtest(size=_2G // 5 + 2, memuse=8 * 5)
21234
def test_index(self, size):
21235
l = [1, 2, 3, 4, 5] * size
21237
@@ -1085,7 +1094,7 @@
21238
self.assertRaises(ValueError, l.index, 6)
21240
# This tests suffers from overallocation, just like test_append.
21241
- @bigmemtest(minsize=_2G + 10, memuse=9)
21242
+ @bigmemtest(size=_2G + 10, memuse=9)
21243
def test_insert(self, size):
21245
l.insert(size - 1, "A")
21246
@@ -1104,7 +1113,7 @@
21247
self.assertEqual(l[:3], [1.0, "C", 1.0])
21248
self.assertEqual(l[size - 3:], ["A", 1.0, "B"])
21250
- @bigmemtest(minsize=_2G // 5 + 4, memuse=8 * 5)
21251
+ @bigmemtest(size=_2G // 5 + 4, memuse=8 * 5)
21252
def test_pop(self, size):
21253
l = ["a", "b", "c", "d", "e"] * size
21255
@@ -1128,7 +1137,7 @@
21256
self.assertEqual(item, "c")
21257
self.assertEqual(l[-2:], ["b", "d"])
21259
- @bigmemtest(minsize=_2G + 10, memuse=8)
21260
+ @bigmemtest(size=_2G + 10, memuse=8)
21261
def test_remove(self, size):
21263
self.assertEqual(len(l), size)
21264
@@ -1148,7 +1157,7 @@
21265
self.assertEqual(len(l), size)
21266
self.assertEqual(l[-2:], [10, 10])
21268
- @bigmemtest(minsize=_2G // 5 + 2, memuse=8 * 5)
21269
+ @bigmemtest(size=_2G // 5 + 2, memuse=8 * 5)
21270
def test_reverse(self, size):
21271
l = [1, 2, 3, 4, 5] * size
21273
@@ -1156,7 +1165,7 @@
21274
self.assertEqual(l[-5:], [5, 4, 3, 2, 1])
21275
self.assertEqual(l[:5], [5, 4, 3, 2, 1])
21277
- @bigmemtest(minsize=_2G // 5 + 2, memuse=8 * 5)
21278
+ @bigmemtest(size=_2G // 5 + 2, memuse=8 * 5)
21279
def test_sort(self, size):
21280
l = [1, 2, 3, 4, 5] * size
21282
diff -r 137e45f15c0b Lib/test/test_builtin.py
21283
--- a/Lib/test/test_builtin.py
21284
+++ b/Lib/test/test_builtin.py
21295
from test.support import fcmp, TESTFN, unlink, run_unittest, check_warnings
21296
from operator import neg
21298
+ import pty, signal
21299
+except ImportError:
21300
+ pty = signal = None
21304
@@ -988,6 +994,82 @@
21308
+ @unittest.skipUnless(pty, "the pty and signal modules must be available")
21309
+ def check_input_tty(self, prompt, terminal_input, stdio_encoding=None):
21310
+ if not sys.stdin.isatty() or not sys.stdout.isatty():
21311
+ self.skipTest("stdin and stdout must be ttys")
21314
+ pid, fd = pty.fork()
21315
+ except (OSError, AttributeError) as e:
21318
+ self.skipTest("pty.fork() raised {}".format(e))
21322
+ # Make sure we don't get stuck if there's a problem
21325
+ # Check the error handlers are accounted for
21326
+ if stdio_encoding:
21327
+ sys.stdin = io.TextIOWrapper(sys.stdin.detach(),
21328
+ encoding=stdio_encoding,
21329
+ errors='surrogateescape')
21330
+ sys.stdout = io.TextIOWrapper(sys.stdout.detach(),
21331
+ encoding=stdio_encoding,
21332
+ errors='replace')
21333
+ with open(w, "w") as wpipe:
21334
+ print("tty =", sys.stdin.isatty() and sys.stdout.isatty(), file=wpipe)
21335
+ print(ascii(input(prompt)), file=wpipe)
21337
+ traceback.print_exc()
21339
+ # We don't want to return to unittest...
21343
+ os.write(fd, terminal_input + b"\r\n")
21344
+ # Get results from the pipe
21345
+ with open(r, "r") as rpipe:
21348
+ line = rpipe.readline().strip()
21350
+ # The other end was closed => the child exited
21352
+ lines.append(line)
21353
+ # Check the result was got and corresponds to the user's terminal input
21354
+ if len(lines) != 2:
21355
+ # Something went wrong, try to get at stderr
21356
+ with open(fd, "r", encoding="ascii", errors="ignore") as child_output:
21357
+ self.fail("got %d lines in pipe but expected 2, child output was:\n%s"
21358
+ % (len(lines), child_output.read()))
21360
+ # Check we did exercise the GNU readline path
21361
+ self.assertIn(lines[0], {'tty = True', 'tty = False'})
21362
+ if lines[0] != 'tty = True':
21363
+ self.skipTest("standard IO in should have been a tty")
21364
+ input_result = eval(lines[1]) # ascii() -> eval() roundtrip
21365
+ if stdio_encoding:
21366
+ expected = terminal_input.decode(stdio_encoding, 'surrogateescape')
21368
+ expected = terminal_input.decode(sys.stdin.encoding) # what else?
21369
+ self.assertEqual(input_result, expected)
21371
+ def test_input_tty(self):
21372
+ # Test input() functionality when wired to a tty (the code path
21373
+ # is different and invokes GNU readline if available).
21374
+ self.check_input_tty("prompt", b"quux")
21376
+ def test_input_tty_non_ascii(self):
21377
+ # Check stdin/stdout encoding is used when invoking GNU readline
21378
+ self.check_input_tty("prompté", b"quux\xe9", "utf-8")
21380
+ def test_input_tty_non_ascii_unicode_errors(self):
21381
+ # Check stdin/stdout error handler is used when invoking GNU readline
21382
+ self.check_input_tty("prompté", b"quux\xe9", "ascii")
21384
def test_repr(self):
21385
self.assertEqual(repr(''), '\'\'')
21386
self.assertEqual(repr(0), '0')
21387
diff -r 137e45f15c0b Lib/test/test_capi.py
21388
--- a/Lib/test/test_capi.py
21389
+++ b/Lib/test/test_capi.py
21392
from __future__ import with_statement
21396
1766
import subprocess
21398
@@ -137,6 +138,22 @@
21399
self.pendingcalls_submit(l, n)
21400
self.pendingcalls_wait(l, n)
21402
+ def test_subinterps(self):
21403
+ # XXX this test leaks in refleak runs
21407
+ import sys, builtins, pickle
21408
+ with open({:d}, "wb") as f:
21409
+ pickle.dump(id(sys.modules), f)
21410
+ pickle.dump(id(builtins), f)
21412
+ with open(r, "rb") as f:
21413
+ ret = _testcapi.run_in_subinterp(code)
21414
+ self.assertEqual(ret, 0)
21415
+ self.assertNotEqual(pickle.load(f), id(sys.modules))
21416
+ self.assertNotEqual(pickle.load(f), id(builtins))
21419
class Test6012(unittest.TestCase):
21421
diff -r 137e45f15c0b Lib/test/test_cfgparser.py
21422
--- a/Lib/test/test_cfgparser.py
21423
+++ b/Lib/test/test_cfgparser.py
21424
@@ -1474,6 +1474,150 @@
21426
self.assertEqual(repr(parser['section']), '<Section: section>')
21429
+class ExceptionPicklingTestCase(unittest.TestCase):
21430
+ """Tests for issue #13760: ConfigParser exceptions are not picklable."""
21432
+ def test_error(self):
21434
+ e1 = configparser.Error('value')
21435
+ pickled = pickle.dumps(e1)
21436
+ e2 = pickle.loads(pickled)
21437
+ self.assertEqual(e1.message, e2.message)
21438
+ self.assertEqual(repr(e1), repr(e2))
21440
+ def test_nosectionerror(self):
21442
+ e1 = configparser.NoSectionError('section')
21443
+ pickled = pickle.dumps(e1)
21444
+ e2 = pickle.loads(pickled)
21445
+ self.assertEqual(e1.message, e2.message)
21446
+ self.assertEqual(e1.args, e2.args)
21447
+ self.assertEqual(e1.section, e2.section)
21448
+ self.assertEqual(repr(e1), repr(e2))
21450
+ def test_nooptionerror(self):
21452
+ e1 = configparser.NoOptionError('option', 'section')
21453
+ pickled = pickle.dumps(e1)
21454
+ e2 = pickle.loads(pickled)
21455
+ self.assertEqual(e1.message, e2.message)
21456
+ self.assertEqual(e1.args, e2.args)
21457
+ self.assertEqual(e1.section, e2.section)
21458
+ self.assertEqual(e1.option, e2.option)
21459
+ self.assertEqual(repr(e1), repr(e2))
21461
+ def test_duplicatesectionerror(self):
21463
+ e1 = configparser.DuplicateSectionError('section', 'source', 123)
21464
+ pickled = pickle.dumps(e1)
21465
+ e2 = pickle.loads(pickled)
21466
+ self.assertEqual(e1.message, e2.message)
21467
+ self.assertEqual(e1.args, e2.args)
21468
+ self.assertEqual(e1.section, e2.section)
21469
+ self.assertEqual(e1.source, e2.source)
21470
+ self.assertEqual(e1.lineno, e2.lineno)
21471
+ self.assertEqual(repr(e1), repr(e2))
21473
+ def test_duplicateoptionerror(self):
21475
+ e1 = configparser.DuplicateOptionError('section', 'option', 'source',
21477
+ pickled = pickle.dumps(e1)
21478
+ e2 = pickle.loads(pickled)
21479
+ self.assertEqual(e1.message, e2.message)
21480
+ self.assertEqual(e1.args, e2.args)
21481
+ self.assertEqual(e1.section, e2.section)
21482
+ self.assertEqual(e1.option, e2.option)
21483
+ self.assertEqual(e1.source, e2.source)
21484
+ self.assertEqual(e1.lineno, e2.lineno)
21485
+ self.assertEqual(repr(e1), repr(e2))
21487
+ def test_interpolationerror(self):
21489
+ e1 = configparser.InterpolationError('option', 'section', 'msg')
21490
+ pickled = pickle.dumps(e1)
21491
+ e2 = pickle.loads(pickled)
21492
+ self.assertEqual(e1.message, e2.message)
21493
+ self.assertEqual(e1.args, e2.args)
21494
+ self.assertEqual(e1.section, e2.section)
21495
+ self.assertEqual(e1.option, e2.option)
21496
+ self.assertEqual(repr(e1), repr(e2))
21498
+ def test_interpolationmissingoptionerror(self):
21500
+ e1 = configparser.InterpolationMissingOptionError('option', 'section',
21501
+ 'rawval', 'reference')
21502
+ pickled = pickle.dumps(e1)
21503
+ e2 = pickle.loads(pickled)
21504
+ self.assertEqual(e1.message, e2.message)
21505
+ self.assertEqual(e1.args, e2.args)
21506
+ self.assertEqual(e1.section, e2.section)
21507
+ self.assertEqual(e1.option, e2.option)
21508
+ self.assertEqual(e1.reference, e2.reference)
21509
+ self.assertEqual(repr(e1), repr(e2))
21511
+ def test_interpolationsyntaxerror(self):
21513
+ e1 = configparser.InterpolationSyntaxError('option', 'section', 'msg')
21514
+ pickled = pickle.dumps(e1)
21515
+ e2 = pickle.loads(pickled)
21516
+ self.assertEqual(e1.message, e2.message)
21517
+ self.assertEqual(e1.args, e2.args)
21518
+ self.assertEqual(e1.section, e2.section)
21519
+ self.assertEqual(e1.option, e2.option)
21520
+ self.assertEqual(repr(e1), repr(e2))
21522
+ def test_interpolationdeptherror(self):
21524
+ e1 = configparser.InterpolationDepthError('option', 'section',
21526
+ pickled = pickle.dumps(e1)
21527
+ e2 = pickle.loads(pickled)
21528
+ self.assertEqual(e1.message, e2.message)
21529
+ self.assertEqual(e1.args, e2.args)
21530
+ self.assertEqual(e1.section, e2.section)
21531
+ self.assertEqual(e1.option, e2.option)
21532
+ self.assertEqual(repr(e1), repr(e2))
21534
+ def test_parsingerror(self):
21536
+ e1 = configparser.ParsingError('source')
21537
+ e1.append(1, 'line1')
21538
+ e1.append(2, 'line2')
21539
+ e1.append(3, 'line3')
21540
+ pickled = pickle.dumps(e1)
21541
+ e2 = pickle.loads(pickled)
21542
+ self.assertEqual(e1.message, e2.message)
21543
+ self.assertEqual(e1.args, e2.args)
21544
+ self.assertEqual(e1.source, e2.source)
21545
+ self.assertEqual(e1.errors, e2.errors)
21546
+ self.assertEqual(repr(e1), repr(e2))
21547
+ e1 = configparser.ParsingError(filename='filename')
21548
+ e1.append(1, 'line1')
21549
+ e1.append(2, 'line2')
21550
+ e1.append(3, 'line3')
21551
+ pickled = pickle.dumps(e1)
21552
+ e2 = pickle.loads(pickled)
21553
+ self.assertEqual(e1.message, e2.message)
21554
+ self.assertEqual(e1.args, e2.args)
21555
+ self.assertEqual(e1.source, e2.source)
21556
+ self.assertEqual(e1.errors, e2.errors)
21557
+ self.assertEqual(repr(e1), repr(e2))
21559
+ def test_missingsectionheadererror(self):
21561
+ e1 = configparser.MissingSectionHeaderError('filename', 123, 'line')
21562
+ pickled = pickle.dumps(e1)
21563
+ e2 = pickle.loads(pickled)
21564
+ self.assertEqual(e1.message, e2.message)
21565
+ self.assertEqual(e1.args, e2.args)
21566
+ self.assertEqual(e1.line, e2.line)
21567
+ self.assertEqual(e1.source, e2.source)
21568
+ self.assertEqual(e1.lineno, e2.lineno)
21569
+ self.assertEqual(repr(e1), repr(e2))
21573
support.run_unittest(
21574
ConfigParserTestCase,
21575
@@ -1495,4 +1639,5 @@
21576
ConfigParserTestCaseNonStandardDefaultSection,
21578
CoverageOneHundredTestCase,
21579
+ ExceptionPicklingTestCase,
21581
diff -r 137e45f15c0b Lib/test/test_cgi.py
21582
--- a/Lib/test/test_cgi.py
21583
+++ b/Lib/test/test_cgi.py
21584
@@ -348,6 +348,10 @@
21586
cgi.parse_header('attachment; filename="strange;name";size=123;'),
21587
("attachment", {"filename": "strange;name", "size": "123"}))
21588
+ self.assertEqual(
21589
+ cgi.parse_header('form-data; name="files"; filename="fo\\"o;bar"'),
21590
+ ("form-data", {"name": "files", "filename": 'fo"o;bar'}))
21593
BOUNDARY = "---------------------------721837373350705526688164684"
21595
diff -r 137e45f15c0b Lib/test/test_cmd_line.py
21596
--- a/Lib/test/test_cmd_line.py
21597
+++ b/Lib/test/test_cmd_line.py
21598
@@ -272,6 +272,64 @@
21599
self.assertRegex(err.decode('ascii', 'ignore'), 'SyntaxError')
21600
self.assertEqual(b'', out)
21602
+ def test_stdout_flush_at_shutdown(self):
21603
+ # Issue #5319: if stdout.flush() fails at shutdown, an error should
21604
+ # be printed out.
21607
+ sys.stdout.write('x')
21608
+ os.close(sys.stdout.fileno())"""
21609
+ rc, out, err = assert_python_ok('-c', code)
21610
+ self.assertEqual(b'', out)
21611
+ self.assertRegex(err.decode('ascii', 'ignore'),
21612
+ 'Exception IOError: .* ignored')
21614
+ def test_closed_stdout(self):
21615
+ # Issue #13444: if stdout has been explicitly closed, we should
21616
+ # not attempt to flush it at shutdown.
21617
+ code = "import sys; sys.stdout.close()"
21618
+ rc, out, err = assert_python_ok('-c', code)
21619
+ self.assertEqual(b'', err)
21621
+ # Issue #7111: Python should work without standard streams
21623
+ @unittest.skipIf(os.name != 'posix', "test needs POSIX semantics")
21624
+ def _test_no_stdio(self, streams):
21627
+ for i, s in enumerate({streams}):
21628
+ if getattr(sys, s) is not None:
21630
+ os._exit(42)""".format(streams=streams)
21632
+ if 'stdin' in streams:
21634
+ if 'stdout' in streams:
21636
+ if 'stderr' in streams:
21638
+ p = subprocess.Popen(
21639
+ [sys.executable, "-E", "-c", code],
21640
+ stdin=subprocess.PIPE,
21641
+ stdout=subprocess.PIPE,
21642
+ stderr=subprocess.PIPE,
21643
+ preexec_fn=preexec)
21644
+ out, err = p.communicate()
21645
+ self.assertEqual(test.support.strip_python_stderr(err), b'')
21646
+ self.assertEqual(p.returncode, 42)
21648
+ def test_no_stdin(self):
21649
+ self._test_no_stdio(['stdin'])
21651
+ def test_no_stdout(self):
21652
+ self._test_no_stdio(['stdout'])
21654
+ def test_no_stderr(self):
21655
+ self._test_no_stdio(['stderr'])
21657
+ def test_no_std_streams(self):
21658
+ self._test_no_stdio(['stdin', 'stdout', 'stderr'])
21662
test.support.run_unittest(CmdLineTest)
21663
diff -r 137e45f15c0b Lib/test/test_collections.py
21664
--- a/Lib/test/test_collections.py
21665
+++ b/Lib/test/test_collections.py
21666
@@ -893,6 +893,12 @@
21667
c.subtract('aaaabbcce')
21668
self.assertEqual(c, Counter(a=-1, b=0, c=-1, d=1, e=-1))
21670
+ def test_repr_nonsortable(self):
21671
+ c = Counter(a=2, b=None)
21673
+ self.assertIn("'a': 2", r)
21674
+ self.assertIn("'b': None", r)
21676
def test_helper_function(self):
21677
# two paths, one for real dicts and one for other mappings
21678
elems = list('abracadabra')
21679
diff -r 137e45f15c0b Lib/test/test_concurrent_futures.py
21680
--- a/Lib/test/test_concurrent_futures.py
21681
+++ b/Lib/test/test_concurrent_futures.py
21682
@@ -109,6 +109,12 @@
21683
self.assertFalse(err)
21684
self.assertEqual(out.strip(), b"apple")
21686
+ def test_hang_issue12364(self):
21687
+ fs = [self.executor.submit(time.sleep, 0.1) for _ in range(50)]
21688
+ self.executor.shutdown()
21693
class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest):
21694
def _prime_executor(self):
21695
diff -r 137e45f15c0b Lib/test/test_curses.py
21696
--- a/Lib/test/test_curses.py
21697
+++ b/Lib/test/test_curses.py
21698
@@ -183,14 +183,14 @@
21699
win = curses.newwin(5,5)
21700
win = curses.newwin(5,5, 1,1)
21701
curses.nl() ; curses.nl(1)
21702
- curses.putp('abc')
21703
+ curses.putp(b'abc')
21705
curses.raw() ; curses.raw(1)
21707
curses.tigetflag('hc')
21708
curses.tigetnum('co')
21709
curses.tigetstr('cr')
21710
- curses.tparm('cr')
21711
+ curses.tparm(b'cr')
21712
curses.typeahead(sys.__stdin__.fileno())
21714
curses.ungetch('a')
21715
@@ -264,6 +264,11 @@
21716
curses.ungetch(1025)
21719
+def test_issue10570():
21720
+ b = curses.tparm(curses.tigetstr("cup"), 5, 3)
21721
+ assert type(b) is bytes
21727
@@ -272,6 +277,7 @@
21728
test_userptr_without_set(stdscr)
21729
test_resize_term(stdscr)
21730
test_issue6243(stdscr)
21731
+ test_issue10570()
21735
diff -r 137e45f15c0b Lib/test/test_defaultdict.py
21736
--- a/Lib/test/test_defaultdict.py
21737
+++ b/Lib/test/test_defaultdict.py
21738
@@ -172,6 +172,9 @@
21742
+ def test_callable_arg(self):
21743
+ self.assertRaises(TypeError, defaultdict, {})
21745
def test_pickleing(self):
21746
d = defaultdict(int)
21748
diff -r 137e45f15c0b Lib/test/test_descr.py
1768
@@ -227,6 +228,10 @@
1771
class TestMain(unittest.TestCase):
1772
+ def tearDown(self):
1773
+ if os.path.exists(support.TESTFN):
1774
+ os.unlink(support.TESTFN)
1776
def get_output(self, *args, **options):
1777
args = (sys.executable, '-m', 'base64') + args
1778
return subprocess.check_output(args, **options)
1779
diff -r 7085403daf43 Lib/test/test_descr.py
21749
1780
--- a/Lib/test/test_descr.py
21750
1781
+++ b/Lib/test/test_descr.py
21751
@@ -625,6 +625,174 @@
21752
# The most derived metaclass of D is A rather than type.
21755
+ self.assertIs(A, type(D))
21757
+ # issue1294232: correct metaclass calculation
21758
+ new_calls = [] # to check the order of __new__ calls
21759
+ class AMeta(type):
21761
+ def __new__(mcls, name, bases, ns):
21762
+ new_calls.append('AMeta')
21763
+ return super().__new__(mcls, name, bases, ns)
21765
+ def __prepare__(mcls, name, bases):
21768
+ class BMeta(AMeta):
21770
+ def __new__(mcls, name, bases, ns):
21771
+ new_calls.append('BMeta')
21772
+ return super().__new__(mcls, name, bases, ns)
21774
+ def __prepare__(mcls, name, bases):
21775
+ ns = super().__prepare__(name, bases)
21776
+ ns['BMeta_was_here'] = True
21779
+ class A(metaclass=AMeta):
21781
+ self.assertEqual(['AMeta'], new_calls)
21782
+ new_calls[:] = []
21784
+ class B(metaclass=BMeta):
21786
+ # BMeta.__new__ calls AMeta.__new__ with super:
21787
+ self.assertEqual(['BMeta', 'AMeta'], new_calls)
21788
+ new_calls[:] = []
21792
+ # The most derived metaclass is BMeta:
21793
+ self.assertEqual(['BMeta', 'AMeta'], new_calls)
21794
+ new_calls[:] = []
21795
+ # BMeta.__prepare__ should've been called:
21796
+ self.assertIn('BMeta_was_here', C.__dict__)
21798
+ # The order of the bases shouldn't matter:
21801
+ self.assertEqual(['BMeta', 'AMeta'], new_calls)
21802
+ new_calls[:] = []
21803
+ self.assertIn('BMeta_was_here', C2.__dict__)
21805
+ # Check correct metaclass calculation when a metaclass is declared:
21806
+ class D(C, metaclass=type):
21808
+ self.assertEqual(['BMeta', 'AMeta'], new_calls)
21809
+ new_calls[:] = []
21810
+ self.assertIn('BMeta_was_here', D.__dict__)
21812
+ class E(C, metaclass=AMeta):
21814
+ self.assertEqual(['BMeta', 'AMeta'], new_calls)
21815
+ new_calls[:] = []
21816
+ self.assertIn('BMeta_was_here', E.__dict__)
21818
+ # Special case: the given metaclass isn't a class,
21819
+ # so there is no metaclass calculation.
21820
+ marker = object()
21821
+ def func(*args, **kwargs):
21823
+ class X(metaclass=func):
21825
+ class Y(object, metaclass=func):
21827
+ class Z(D, metaclass=func):
21829
+ self.assertIs(marker, X)
21830
+ self.assertIs(marker, Y)
21831
+ self.assertIs(marker, Z)
21833
+ # The given metaclass is a class,
21834
+ # but not a descendant of type.
21835
+ prepare_calls = [] # to track __prepare__ calls
21837
+ def __new__(mcls, *args, **kwargs):
21838
+ new_calls.append('ANotMeta')
21839
+ return super().__new__(mcls)
21841
+ def __prepare__(mcls, name, bases):
21842
+ prepare_calls.append('ANotMeta')
21844
+ class BNotMeta(ANotMeta):
21845
+ def __new__(mcls, *args, **kwargs):
21846
+ new_calls.append('BNotMeta')
21847
+ return super().__new__(mcls)
21849
+ def __prepare__(mcls, name, bases):
21850
+ prepare_calls.append('BNotMeta')
21851
+ return super().__prepare__(name, bases)
21853
+ class A(metaclass=ANotMeta):
21855
+ self.assertIs(ANotMeta, type(A))
21856
+ self.assertEqual(['ANotMeta'], prepare_calls)
21857
+ prepare_calls[:] = []
21858
+ self.assertEqual(['ANotMeta'], new_calls)
21859
+ new_calls[:] = []
21861
+ class B(metaclass=BNotMeta):
21863
+ self.assertIs(BNotMeta, type(B))
21864
+ self.assertEqual(['BNotMeta', 'ANotMeta'], prepare_calls)
21865
+ prepare_calls[:] = []
21866
+ self.assertEqual(['BNotMeta', 'ANotMeta'], new_calls)
21867
+ new_calls[:] = []
21871
+ self.assertIs(BNotMeta, type(C))
21872
+ self.assertEqual(['BNotMeta', 'ANotMeta'], new_calls)
21873
+ new_calls[:] = []
21874
+ self.assertEqual(['BNotMeta', 'ANotMeta'], prepare_calls)
21875
+ prepare_calls[:] = []
21879
+ self.assertIs(BNotMeta, type(C2))
21880
+ self.assertEqual(['BNotMeta', 'ANotMeta'], new_calls)
21881
+ new_calls[:] = []
21882
+ self.assertEqual(['BNotMeta', 'ANotMeta'], prepare_calls)
21883
+ prepare_calls[:] = []
21885
+ # This is a TypeError, because of a metaclass conflict:
21886
+ # BNotMeta is neither a subclass, nor a superclass of type
21887
+ with self.assertRaises(TypeError):
21888
+ class D(C, metaclass=type):
21891
+ class E(C, metaclass=ANotMeta):
21893
+ self.assertIs(BNotMeta, type(E))
21894
+ self.assertEqual(['BNotMeta', 'ANotMeta'], new_calls)
21895
+ new_calls[:] = []
21896
+ self.assertEqual(['BNotMeta', 'ANotMeta'], prepare_calls)
21897
+ prepare_calls[:] = []
21899
+ class F(object(), C):
21901
+ self.assertIs(BNotMeta, type(F))
21902
+ self.assertEqual(['BNotMeta', 'ANotMeta'], new_calls)
21903
+ new_calls[:] = []
21904
+ self.assertEqual(['BNotMeta', 'ANotMeta'], prepare_calls)
21905
+ prepare_calls[:] = []
21907
+ class F2(C, object()):
21909
+ self.assertIs(BNotMeta, type(F2))
21910
+ self.assertEqual(['BNotMeta', 'ANotMeta'], new_calls)
21911
+ new_calls[:] = []
21912
+ self.assertEqual(['BNotMeta', 'ANotMeta'], prepare_calls)
21913
+ prepare_calls[:] = []
21915
+ # TypeError: BNotMeta is neither a
21916
+ # subclass, nor a superclass of int
21917
+ with self.assertRaises(TypeError):
21918
+ class X(C, int()):
21920
+ with self.assertRaises(TypeError):
21921
+ class X(int(), C):
21924
def test_module_subclasses(self):
21925
# Testing Python subclass of module...
21926
diff -r 137e45f15c0b Lib/test/test_doctest.py
21927
--- a/Lib/test/test_doctest.py
21928
+++ b/Lib/test/test_doctest.py
21929
@@ -258,6 +258,21 @@
21930
>>> e = doctest.Example('raise X()', '', exc_msg)
21934
+Compare `Example`:
21935
+ >>> example = doctest.Example('print 1', '1\n')
21936
+ >>> same_example = doctest.Example('print 1', '1\n')
21937
+ >>> other_example = doctest.Example('print 42', '42\n')
21938
+ >>> example == same_example
21940
+ >>> example != same_example
21942
+ >>> hash(example) == hash(same_example)
21944
+ >>> example == other_example
21946
+ >>> example != other_example
21950
def test_DocTest(): r"""
21951
@@ -347,6 +362,50 @@
21952
Traceback (most recent call last):
21953
ValueError: line 2 of the docstring for some_test lacks blank after ...: '...print(1)'
21955
+Compare `DocTest`:
21957
+ >>> docstring = '''
21961
+ >>> test = parser.get_doctest(docstring, globs, 'some_test',
21962
+ ... 'some_test', 20)
21963
+ >>> same_test = parser.get_doctest(docstring, globs, 'some_test',
21964
+ ... 'some_test', 20)
21965
+ >>> test == same_test
21967
+ >>> test != same_test
21969
+ >>> hash(test) == hash(same_test)
21971
+ >>> docstring = '''
21975
+ >>> other_test = parser.get_doctest(docstring, globs, 'other_test',
21976
+ ... 'other_file', 10)
21977
+ >>> test == other_test
21979
+ >>> test != other_test
21982
+Compare `DocTestCase`:
21984
+ >>> DocTestCase = doctest.DocTestCase
21985
+ >>> test_case = DocTestCase(test)
21986
+ >>> same_test_case = DocTestCase(same_test)
21987
+ >>> other_test_case = DocTestCase(other_test)
21988
+ >>> test_case == same_test_case
21990
+ >>> test_case != same_test_case
21992
+ >>> hash(test_case) == hash(same_test_case)
21994
+ >>> test == other_test_case
21996
+ >>> test != other_test_case
22001
def test_DocTestFinder(): r"""
22002
diff -r 137e45f15c0b Lib/test/test_epoll.py
22003
--- a/Lib/test/test_epoll.py
22004
+++ b/Lib/test/test_epoll.py
22006
except IOError as e:
22007
if e.errno == errno.ENOSYS:
22008
raise unittest.SkipTest("kernel doesn't support epoll()")
22011
class TestEPoll(unittest.TestCase):
22013
diff -r 137e45f15c0b Lib/test/test_exceptions.py
1791
from copy import deepcopy
1792
from test import support
1793
@@ -1186,7 +1188,6 @@
1794
self.assertEqual(Counted.counter, 0)
1796
# Test lookup leaks [SF bug 572567]
1798
if hasattr(gc, 'get_objects'):
1800
def __eq__(self, other):
1801
@@ -4380,7 +4381,6 @@
1802
self.assertRaises(AttributeError, getattr, C(), "attr")
1803
self.assertEqual(descr.counter, 4)
1806
class EvilGetattribute(object):
1807
# This used to segfault
1808
def __getattr__(self, name):
1809
@@ -4429,6 +4429,21 @@
1813
+ def test_cycle_through_dict(self):
1814
+ # See bug #1469629
1816
+ def __init__(self):
1817
+ dict.__init__(self)
1818
+ self.__dict__ = self
1821
+ wr = weakref.ref(x)
1823
+ support.gc_collect()
1824
+ self.assertIsNone(wr())
1825
+ for o in gc.get_objects():
1826
+ self.assertIsNot(type(o), X)
1828
class DictProxyTests(unittest.TestCase):
1831
diff -r 7085403daf43 Lib/test/test_dict.py
1832
--- a/Lib/test/test_dict.py
1833
+++ b/Lib/test/test_dict.py
1834
@@ -299,6 +299,26 @@
1836
self.assertRaises(Exc, d.setdefault, x, [])
1838
+ def test_setdefault_atomic(self):
1839
+ # Issue #13521: setdefault() calls __hash__ and __eq__ only once.
1840
+ class Hashed(object):
1841
+ def __init__(self):
1842
+ self.hash_count = 0
1844
+ def __hash__(self):
1845
+ self.hash_count += 1
1847
+ def __eq__(self, other):
1848
+ self.eq_count += 1
1849
+ return id(self) == id(other)
1850
+ hashed1 = Hashed()
1852
+ hashed2 = Hashed()
1853
+ y.setdefault(hashed2, [])
1854
+ self.assertEqual(hashed1.hash_count, 1)
1855
+ self.assertEqual(hashed2.hash_count, 1)
1856
+ self.assertEqual(hashed1.eq_count + hashed2.eq_count, 1)
1858
def test_popitem(self):
1860
for copymode in -1, +1:
1861
diff -r 7085403daf43 Lib/test/test_exceptions.py
22014
1862
--- a/Lib/test/test_exceptions.py
22015
1863
+++ b/Lib/test/test_exceptions.py
22022
from test.support import (TESTFN, unlink, run_unittest, captured_output,
22023
gc_collect, cpython_only)
22024
@@ -607,6 +608,68 @@
22026
self.assertEqual(sys.exc_info(), (None, None, None))
22028
+ def _check_generator_cleanup_exc_state(self, testfunc):
22029
+ # Issue #12791: exception state is cleaned up as soon as a generator
22030
+ # is closed (reference cycles are broken).
22031
+ class MyException(Exception):
22032
+ def __init__(self, obj):
22037
+ def raising_gen():
22039
+ raise MyException(obj)
22040
+ except MyException:
22044
+ wr = weakref.ref(obj)
22045
+ g = raising_gen()
22050
+ self.assertIs(obj, None)
22052
+ def test_generator_throw_cleanup_exc_state(self):
22055
+ g.throw(RuntimeError())
22056
+ except RuntimeError:
22058
+ self._check_generator_cleanup_exc_state(do_throw)
22060
+ def test_generator_close_cleanup_exc_state(self):
22063
+ self._check_generator_cleanup_exc_state(do_close)
22065
+ def test_generator_del_cleanup_exc_state(self):
22068
+ self._check_generator_cleanup_exc_state(do_del)
22070
+ def test_generator_next_cleanup_exc_state(self):
22074
+ except StopIteration:
22077
+ self.fail("should have raised StopIteration")
22078
+ self._check_generator_cleanup_exc_state(do_next)
22080
+ def test_generator_send_cleanup_exc_state(self):
22084
+ except StopIteration:
22087
+ self.fail("should have raised StopIteration")
22088
+ self._check_generator_cleanup_exc_state(do_send)
22090
def test_3114(self):
22091
# Bug #3114: in its destructor, MyObject retrieves a pointer to
22092
# obsolete and/or deallocated objects.
22093
@@ -787,6 +850,13 @@
22094
self.fail("RuntimeError not raised")
22095
self.assertEqual(wr(), None)
22097
+ def test_errno_ENOTDIR(self):
22098
+ # Issue #12802: "not a directory" errors are ENOTDIR even on Windows
22099
+ with self.assertRaises(OSError) as cm:
22100
+ os.listdir(__file__)
22101
+ self.assertEqual(cm.exception.errno, errno.ENOTDIR, cm.exception)
22105
run_unittest(ExceptionTests)
22107
diff -r 137e45f15c0b Lib/test/test_fcntl.py
22108
--- a/Lib/test/test_fcntl.py
22109
+++ b/Lib/test/test_fcntl.py
22114
- if sys.platform in ('netbsd1', 'netbsd2', 'netbsd3',
22115
- 'Darwin1.2', 'darwin',
22116
- 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
22117
- 'freebsd6', 'freebsd7', 'freebsd8',
22118
- 'bsdos2', 'bsdos3', 'bsdos4',
22119
- 'openbsd', 'openbsd2', 'openbsd3', 'openbsd4'):
22120
+ if (sys.platform.startswith(('netbsd', 'freebsd', 'openbsd', 'bsdos'))
22121
+ or sys.platform == 'darwin'):
22122
if struct.calcsize('l') == 8:
22125
diff -r 137e45f15c0b Lib/test/test_fileio.py
22126
--- a/Lib/test/test_fileio.py
22127
+++ b/Lib/test/test_fileio.py
22128
@@ -305,6 +305,11 @@
22132
+ def testConstructorHandlesNULChars(self):
22133
+ fn_with_NUL = 'foo\0bar'
22134
+ self.assertRaises(TypeError, _FileIO, fn_with_NUL, 'w')
22135
+ self.assertRaises(TypeError, _FileIO, bytes(fn_with_NUL, 'ascii'), 'w')
22137
def testInvalidFd(self):
22138
self.assertRaises(ValueError, _FileIO, -10)
22139
self.assertRaises(OSError, _FileIO, make_bad_fd())
22140
diff -r 137e45f15c0b Lib/test/test_float.py
22141
--- a/Lib/test/test_float.py
22142
+++ b/Lib/test/test_float.py
22143
@@ -128,6 +128,12 @@
22144
self.assertRaises(TypeError, float, Foo4(42))
22145
self.assertAlmostEqual(float(FooStr('8')), 9.)
22147
+ def test_is_integer(self):
22148
+ self.assertFalse((1.1).is_integer())
22149
+ self.assertTrue((1.).is_integer())
22150
+ self.assertFalse(float("nan").is_integer())
22151
+ self.assertFalse(float("inf").is_integer())
22153
def test_floatasratio(self):
22156
diff -r 137e45f15c0b Lib/test/test_ftplib.py
22157
--- a/Lib/test/test_ftplib.py
22158
+++ b/Lib/test/test_ftplib.py
22159
@@ -767,7 +767,7 @@
22161
self.evt = threading.Event()
22162
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
22163
- self.sock.settimeout(3)
22164
+ self.sock.settimeout(10)
22165
self.port = support.bind_port(self.sock)
22166
threading.Thread(target=self.server, args=(self.evt,self.sock)).start()
22167
# Wait for the server to be ready.
22168
diff -r 137e45f15c0b Lib/test/test_functools.py
22169
--- a/Lib/test/test_functools.py
22170
+++ b/Lib/test/test_functools.py
22171
@@ -655,6 +655,22 @@
22172
self.assertEqual(fib.cache_info(),
22173
functools._CacheInfo(hits=0, misses=0, maxsize=None, currsize=0))
22175
+ def test_lru_with_exceptions(self):
22176
+ # Verify that user_function exceptions get passed through without
22177
+ # creating a hard-to-read chained exception.
22178
+ # http://bugs.python.org/issue13177
22179
+ for maxsize in (None, 100):
22180
+ @functools.lru_cache(maxsize)
22183
+ self.assertEqual(func(0), 'a')
22184
+ with self.assertRaises(IndexError) as cm:
22186
+ self.assertIsNone(cm.exception.__context__)
22187
+ # Verify that the previous exception did not result in a cached entry
22188
+ with self.assertRaises(IndexError):
22191
def test_main(verbose=None):
22194
diff -r 137e45f15c0b Lib/test/test_gdb.py
22195
--- a/Lib/test/test_gdb.py
22196
+++ b/Lib/test/test_gdb.py
22197
@@ -529,6 +529,8 @@
22199
'Unexpected gdb representation: %r\n%s' % (gdb_output, gdb_output))
22201
+@unittest.skipIf(python_is_optimized(),
22202
+ "Python was compiled with optimizations")
22203
class PyListTests(DebuggerTests):
22204
def assertListing(self, expected, actual):
22205
self.assertEndsWith(actual, expected)
22206
@@ -571,6 +573,8 @@
22208
class StackNavigationTests(DebuggerTests):
22209
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
22210
+ @unittest.skipIf(python_is_optimized(),
22211
+ "Python was compiled with optimizations")
22212
def test_pyup_command(self):
22213
'Verify that the "py-up" command works'
22214
bt = self.get_stack_trace(script=self.get_sample_script(),
22215
@@ -598,6 +602,8 @@
22216
'Unable to find an older python frame\n')
22218
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
22219
+ @unittest.skipIf(python_is_optimized(),
22220
+ "Python was compiled with optimizations")
22221
def test_up_then_down(self):
22222
'Verify "py-up" followed by "py-down"'
22223
bt = self.get_stack_trace(script=self.get_sample_script(),
22224
@@ -611,6 +617,8 @@
22227
class PyBtTests(DebuggerTests):
22228
+ @unittest.skipIf(python_is_optimized(),
22229
+ "Python was compiled with optimizations")
22231
'Verify that the "py-bt" command works'
22232
bt = self.get_stack_trace(script=self.get_sample_script(),
22233
@@ -628,6 +636,8 @@
22237
+ @unittest.skipIf(python_is_optimized(),
22238
+ "Python was compiled with optimizations")
22239
def test_bt_full(self):
22240
'Verify that the "py-bt-full" command works'
22241
bt = self.get_stack_trace(script=self.get_sample_script(),
22242
@@ -639,10 +649,12 @@
22243
#[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 4, in foo \(a=1, b=2, c=3\)
22245
#[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 12, in <module> \(\)
22250
class PyPrintTests(DebuggerTests):
22251
+ @unittest.skipIf(python_is_optimized(),
22252
+ "Python was compiled with optimizations")
22253
def test_basic_command(self):
22254
'Verify that the "py-print" command works'
22255
bt = self.get_stack_trace(script=self.get_sample_script(),
22256
@@ -650,6 +662,8 @@
22257
self.assertMultilineMatches(bt,
22258
r".*\nlocal 'args' = \(1, 2, 3\)\n.*")
22260
+ @unittest.skipIf(python_is_optimized(),
22261
+ "Python was compiled with optimizations")
22262
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
22263
def test_print_after_up(self):
22264
bt = self.get_stack_trace(script=self.get_sample_script(),
22265
@@ -657,12 +671,16 @@
22266
self.assertMultilineMatches(bt,
22267
r".*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*")
22269
+ @unittest.skipIf(python_is_optimized(),
22270
+ "Python was compiled with optimizations")
22271
def test_printing_global(self):
22272
bt = self.get_stack_trace(script=self.get_sample_script(),
22273
cmds_after_breakpoint=['py-print __name__'])
22274
self.assertMultilineMatches(bt,
22275
r".*\nglobal '__name__' = '__main__'\n.*")
22277
+ @unittest.skipIf(python_is_optimized(),
22278
+ "Python was compiled with optimizations")
22279
def test_printing_builtin(self):
22280
bt = self.get_stack_trace(script=self.get_sample_script(),
22281
cmds_after_breakpoint=['py-print len'])
22282
@@ -670,6 +688,8 @@
22283
r".*\nbuiltin 'len' = <built-in method len of module object at remote 0x[0-9a-f]+>\n.*")
22285
class PyLocalsTests(DebuggerTests):
22286
+ @unittest.skipIf(python_is_optimized(),
22287
+ "Python was compiled with optimizations")
22288
def test_basic_command(self):
22289
bt = self.get_stack_trace(script=self.get_sample_script(),
22290
cmds_after_breakpoint=['py-locals'])
22291
@@ -677,6 +697,8 @@
22292
r".*\nargs = \(1, 2, 3\)\n.*")
22294
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
22295
+ @unittest.skipIf(python_is_optimized(),
22296
+ "Python was compiled with optimizations")
22297
def test_locals_after_up(self):
22298
bt = self.get_stack_trace(script=self.get_sample_script(),
22299
cmds_after_breakpoint=['py-up', 'py-locals'])
22300
@@ -684,8 +706,6 @@
22301
r".*\na = 1\nb = 2\nc = 3\n.*")
22304
- if python_is_optimized():
22305
- raise unittest.SkipTest("Python was compiled with optimizations")
22306
run_unittest(PrettyPrintTests,
22308
StackNavigationTests,
22309
diff -r 137e45f15c0b Lib/test/test_generators.py
22310
--- a/Lib/test/test_generators.py
22311
+++ b/Lib/test/test_generators.py
22312
@@ -1673,6 +1673,32 @@
22316
+Plain "raise" inside a generator should preserve the traceback (#13188).
22317
+The traceback should have 3 levels:
22330
+... except ZeroDivisionError as v:
22333
+... except Exception as w:
22334
+... tb = w.__traceback__
22338
+... tb = tb.tb_next
22342
Now let's try closing a generator:
22345
diff -r 137e45f15c0b Lib/test/test_grammar.py
22346
--- a/Lib/test/test_grammar.py
22347
+++ b/Lib/test/test_grammar.py
22348
@@ -493,13 +493,35 @@
22351
assert 1, lambda x:x+1
22355
+ except AssertionError as e:
22356
+ self.fail("'assert True' should not have raised an AssertionError")
22359
+ assert True, 'this should always pass'
22360
+ except AssertionError as e:
22361
+ self.fail("'assert True, msg' should not have "
22362
+ "raised an AssertionError")
22364
+ # these tests fail if python is run with -O, so check __debug__
22365
+ @unittest.skipUnless(__debug__, "Won't work if __debug__ is False")
22366
+ def testAssert2(self):
22369
except AssertionError as e:
22370
self.assertEqual(e.args[0], "msg")
22373
- self.fail("AssertionError not raised by assert 0")
22374
+ self.fail("AssertionError not raised by assert 0")
22378
+ except AssertionError as e:
22379
+ self.assertEqual(len(e.args), 0)
22381
+ self.fail("AssertionError not raised by 'assert False'")
22384
### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
22386
diff -r 137e45f15c0b Lib/test/test_gzip.py
22387
--- a/Lib/test/test_gzip.py
22388
+++ b/Lib/test/test_gzip.py
22389
@@ -323,6 +323,14 @@
22390
self.assertEqual(f.read(100), b'')
22391
self.assertEqual(nread, len(uncompressed))
22393
+ def test_fileobj_from_fdopen(self):
22394
+ # Issue #13781: Opening a GzipFile for writing fails when using a
22395
+ # fileobj created with os.fdopen().
22396
+ fd = os.open(self.filename, os.O_WRONLY | os.O_CREAT)
22397
+ with os.fdopen(fd, "wb") as f:
22398
+ with gzip.GzipFile(fileobj=f, mode="w") as g:
22401
# Testing compress/decompress shortcut functions
22403
def test_compress(self):
22404
diff -r 137e45f15c0b Lib/test/test_hashlib.py
22405
--- a/Lib/test/test_hashlib.py
22406
+++ b/Lib/test/test_hashlib.py
22410
from test import support
22411
-from test.support import _4G, precisionbigmemtest
22412
+from test.support import _4G, bigmemtest
22414
# Were we compiled --with-pydebug or with #define Py_DEBUG?
22415
COMPILED_WITH_PYDEBUG = hasattr(sys, 'gettotalrefcount')
22416
@@ -196,7 +196,7 @@
22417
b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
22418
'd174ab98d277d9f5a5611c2c9f419d9f')
22420
- @precisionbigmemtest(size=_4G + 5, memuse=1)
22421
+ @bigmemtest(size=_4G + 5, memuse=1)
22422
def test_case_md5_huge(self, size):
22423
if size == _4G + 5:
22425
@@ -204,7 +204,7 @@
22426
except OverflowError:
22429
- @precisionbigmemtest(size=_4G - 1, memuse=1)
22430
+ @bigmemtest(size=_4G - 1, memuse=1)
22431
def test_case_md5_uintmax(self, size):
22432
if size == _4G - 1:
22434
diff -r 137e45f15c0b Lib/test/test_htmlparser.py
22435
--- a/Lib/test/test_htmlparser.py
22436
+++ b/Lib/test/test_htmlparser.py
22439
class TestCaseBase(unittest.TestCase):
22441
+ def get_collector(self):
22442
+ raise NotImplementedError
22444
def _run_check(self, source, expected_events, collector=None):
22445
if collector is None:
22446
- collector = EventCollector()
22447
+ collector = self.get_collector()
22451
@@ -90,13 +93,16 @@
22453
def _parse_error(self, source):
22454
def parse(source=source):
22455
- parser = html.parser.HTMLParser()
22456
+ parser = self.get_collector()
22457
parser.feed(source)
22459
self.assertRaises(html.parser.HTMLParseError, parse)
22462
-class HTMLParserTestCase(TestCaseBase):
22463
+class HTMLParserStrictTestCase(TestCaseBase):
22465
+ def get_collector(self):
22466
+ return EventCollector(strict=True)
22468
def test_processing_instruction_only(self):
22469
self._run_check("<?processing instruction>", [
22470
@@ -116,7 +122,7 @@
22471
<Img sRc='Bar' isMAP>sample
22474
-<!--comment2a-- --comment2b--><!>
22475
+<!--comment2a-- --comment2b-->
22479
@@ -151,24 +157,6 @@
22483
- def test_doctype_decl(self):
22486
- <!ELEMENT html - O EMPTY>
22488
- version CDATA #IMPLIED
22489
- profile CDATA 'DublinCore'>
22490
- <!NOTATION datatype SYSTEM 'http://xml.python.org/notations/python-module'>
22491
- <!ENTITY myEntity 'internal parsed entity'>
22492
- <!ENTITY anEntity SYSTEM 'http://xml.python.org/entities/something.xml'>
22493
- <!ENTITY % paramEntity 'name|name|name'>
22497
- self._run_check("<!%s>" % inside, [
22498
- ("decl", inside),
22501
def test_bad_nesting(self):
22502
# Strangely, this *is* supposed to test that overlapping
22503
# elements are allowed. HTMLParser is more geared toward
22504
@@ -190,60 +178,6 @@
22505
("data", "this < text > contains < bare>pointy< brackets"),
22508
- def test_attr_syntax(self):
22510
- ("starttag", "a", [("b", "v"), ("c", "v"), ("d", "v"), ("e", None)])
22512
- self._run_check("""<a b='v' c="v" d=v e>""", output)
22513
- self._run_check("""<a b = 'v' c = "v" d = v e>""", output)
22514
- self._run_check("""<a\nb\n=\n'v'\nc\n=\n"v"\nd\n=\nv\ne>""", output)
22515
- self._run_check("""<a\tb\t=\t'v'\tc\t=\t"v"\td\t=\tv\te>""", output)
22517
- def test_attr_values(self):
22518
- self._run_check("""<a b='xxx\n\txxx' c="yyy\t\nyyy" d='\txyz\n'>""",
22519
- [("starttag", "a", [("b", "xxx\n\txxx"),
22520
- ("c", "yyy\t\nyyy"),
22521
- ("d", "\txyz\n")])
22523
- self._run_check("""<a b='' c="">""", [
22524
- ("starttag", "a", [("b", ""), ("c", "")]),
22526
- # Regression test for SF patch #669683.
22527
- self._run_check("<e a=rgb(1,2,3)>", [
22528
- ("starttag", "e", [("a", "rgb(1,2,3)")]),
22530
- # Regression test for SF bug #921657.
22531
- self._run_check("<a href=mailto:xyz@example.com>", [
22532
- ("starttag", "a", [("href", "mailto:xyz@example.com")]),
22535
- def test_attr_nonascii(self):
22537
- self._run_check("<img src=/foo/bar.png alt=\u4e2d\u6587>", [
22538
- ("starttag", "img", [("src", "/foo/bar.png"),
22539
- ("alt", "\u4e2d\u6587")]),
22541
- self._run_check("<a title='\u30c6\u30b9\u30c8' "
22542
- "href='\u30c6\u30b9\u30c8.html'>", [
22543
- ("starttag", "a", [("title", "\u30c6\u30b9\u30c8"),
22544
- ("href", "\u30c6\u30b9\u30c8.html")]),
22546
- self._run_check('<a title="\u30c6\u30b9\u30c8" '
22547
- 'href="\u30c6\u30b9\u30c8.html">', [
22548
- ("starttag", "a", [("title", "\u30c6\u30b9\u30c8"),
22549
- ("href", "\u30c6\u30b9\u30c8.html")]),
22552
- def test_attr_entity_replacement(self):
22553
- self._run_check("""<a b='&><"''>""", [
22554
- ("starttag", "a", [("b", "&><\"'")]),
22557
- def test_attr_funky_names(self):
22558
- self._run_check("""<a a.b='v' c:d=v e-f=v>""", [
22559
- ("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")]),
22562
def test_illegal_declarations(self):
22563
self._parse_error('<!spacer type="block" height="25">')
22565
@@ -289,13 +223,35 @@
22566
self._parse_error("<a<a>")
22567
self._parse_error("</a<a>")
22568
self._parse_error("<!")
22569
- self._parse_error("<a $>")
22570
self._parse_error("<a")
22571
self._parse_error("<a foo='bar'")
22572
self._parse_error("<a foo='bar")
22573
self._parse_error("<a foo='>'")
22574
self._parse_error("<a foo='>")
22575
- self._parse_error("<a foo=>")
22577
+ def test_valid_doctypes(self):
22578
+ # from http://www.w3.org/QA/2002/04/valid-dtd-list.html
22579
+ dtds = ['HTML', # HTML5 doctype
22580
+ ('HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" '
22581
+ '"http://www.w3.org/TR/html4/strict.dtd"'),
22582
+ ('HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" '
22583
+ '"http://www.w3.org/TR/html4/loose.dtd"'),
22584
+ ('html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '
22585
+ '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"'),
22586
+ ('html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" '
22587
+ '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"'),
22588
+ ('math PUBLIC "-//W3C//DTD MathML 2.0//EN" '
22589
+ '"http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"'),
22590
+ ('html PUBLIC "-//W3C//DTD '
22591
+ 'XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" '
22592
+ '"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"'),
22593
+ ('svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
22594
+ '"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"'),
22595
+ 'html PUBLIC "-//IETF//DTD HTML 2.0//EN"',
22596
+ 'html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"']
22598
+ self._run_check("<!DOCTYPE %s>" % dtd,
22599
+ [('decl', 'DOCTYPE ' + dtd)])
22601
def test_declaration_junk_chars(self):
22602
self._parse_error("<!DOCTYPE foo $ >")
22603
@@ -321,66 +277,434 @@
22604
("starttag_text", s)])
22606
def test_cdata_content(self):
22607
- s = """<script> <!-- not a comment --> ¬-an-entity-ref; </script>"""
22608
- self._run_check(s, [
22609
- ("starttag", "script", []),
22610
- ("data", " <!-- not a comment --> ¬-an-entity-ref; "),
22611
- ("endtag", "script"),
22613
- s = """<script> <not a='start tag'> </script>"""
22614
- self._run_check(s, [
22615
- ("starttag", "script", []),
22616
- ("data", " <not a='start tag'> "),
22617
- ("endtag", "script"),
22620
+ '<!-- not a comment --> ¬-an-entity-ref;',
22621
+ "<not a='start tag'>",
22622
+ '<a href="" /> <p> <span></span>',
22623
+ 'foo = "</scr" + "ipt>";',
22624
+ 'foo = "</SCRIPT" + ">";',
22625
+ 'foo = <\n/script> ',
22626
+ '<!-- document.write("</scr" + "ipt>"); -->',
22627
+ ('\n//<![CDATA[\n'
22628
+ 'document.write(\'<s\'+\'cript type="text/javascript" '
22629
+ 'src="http://www.example.org/r=\'+new '
22630
+ 'Date().getTime()+\'"><\\/s\'+\'cript>\');\n//]]>'),
22631
+ '\n<!-- //\nvar foo = 3.14;\n// -->\n',
22632
+ 'foo = "</sty" + "le>";',
22633
+ '<!-- \u2603 -->',
22634
+ # these two should be invalid according to the HTML 5 spec,
22635
+ # section 8.1.2.2
22636
+ #'foo = </\nscript>',
22637
+ #'foo = </ script>',
22639
+ elements = ['script', 'style', 'SCRIPT', 'STYLE', 'Script', 'Style']
22640
+ for content in contents:
22641
+ for element in elements:
22642
+ element_lower = element.lower()
22643
+ s = '<{element}>{content}</{element}>'.format(element=element,
22645
+ self._run_check(s, [("starttag", element_lower, []),
22646
+ ("data", content),
22647
+ ("endtag", element_lower)])
22649
- def test_entityrefs_in_attributes(self):
22650
- self._run_check("<html foo='€&aa&unsupported;'>", [
22651
- ("starttag", "html", [("foo", "\u20AC&aa&unsupported;")])
22653
+ def test_cdata_with_closing_tags(self):
22654
+ # see issue #13358
22655
+ # make sure that HTMLParser calls handle_data only once for each CDATA.
22656
+ # The normal event collector normalizes the events in get_events,
22657
+ # so we override it to return the original list of events.
22658
+ class Collector(EventCollector):
22659
+ def get_events(self):
22660
+ return self.events
22662
+ content = """<!-- not a comment --> ¬-an-entity-ref;
22663
+ <a href="" /> </p><p> <span></span></style>
22664
+ '</script' + '>'"""
22665
+ for element in [' script', 'script ', ' script ',
22666
+ '\nscript', 'script\n', '\nscript\n']:
22667
+ element_lower = element.lower().strip()
22668
+ s = '<script>{content}</{element}>'.format(element=element,
22670
+ self._run_check(s, [("starttag", element_lower, []),
22671
+ ("data", content),
22672
+ ("endtag", element_lower)],
22673
+ collector=Collector())
22675
-class HTMLParserTolerantTestCase(TestCaseBase):
22676
+ def test_comments(self):
22677
+ html = ("<!-- I'm a valid comment -->"
22681
+ '<!----I have many hyphens---->'
22682
+ '<!-- I have a > in the middle -->'
22683
+ '<!-- and I have -- in the middle! -->')
22684
+ expected = [('comment', " I'm a valid comment "),
22685
+ ('comment', 'me too!'),
22686
+ ('comment', '--'),
22688
+ ('comment', '--I have many hyphens--'),
22689
+ ('comment', ' I have a > in the middle '),
22690
+ ('comment', ' and I have -- in the middle! ')]
22691
+ self._run_check(html, expected)
22694
- self.collector = EventCollector(strict=False)
22695
+ def test_condcoms(self):
22696
+ html = ('<!--[if IE & !(lte IE 8)]>aren\'t<![endif]-->'
22697
+ '<!--[if IE 8]>condcoms<![endif]-->'
22698
+ '<!--[if lte IE 7]>pretty?<![endif]-->')
22699
+ expected = [('comment', "[if IE & !(lte IE 8)]>aren't<![endif]"),
22700
+ ('comment', '[if IE 8]>condcoms<![endif]'),
22701
+ ('comment', '[if lte IE 7]>pretty?<![endif]')]
22702
+ self._run_check(html, expected)
22705
+class HTMLParserTolerantTestCase(HTMLParserStrictTestCase):
22707
+ def get_collector(self):
22708
+ return EventCollector(strict=False)
22710
def test_tolerant_parsing(self):
22711
self._run_check('<html <html>te>>xt&a<<bc</a></html>\n'
22712
'<img src="URL><//img></html</html>', [
22713
- ('data', '<html '),
22714
- ('starttag', 'html', []),
22715
- ('data', 'te>>xt'),
22716
- ('entityref', 'a'),
22717
- ('data', '<<bc'),
22719
- ('endtag', 'html'),
22720
- ('data', '\n<img src="URL><//img></html'),
22721
- ('endtag', 'html')],
22722
- collector = self.collector)
22723
+ ('starttag', 'html', [('<html', None)]),
22724
+ ('data', 'te>>xt'),
22725
+ ('entityref', 'a'),
22726
+ ('data', '<<bc'),
22728
+ ('endtag', 'html'),
22729
+ ('data', '\n<img src="URL>'),
22730
+ ('comment', '/img'),
22731
+ ('endtag', 'html<')])
22733
+ def test_starttag_junk_chars(self):
22734
+ self._run_check("</>", [])
22735
+ self._run_check("</$>", [('comment', '$')])
22736
+ self._run_check("</", [('data', '</')])
22737
+ self._run_check("</a", [('data', '</a')])
22738
+ # XXX this might be wrong
22739
+ self._run_check("<a<a>", [('data', '<a'), ('starttag', 'a', [])])
22740
+ self._run_check("</a<a>", [('endtag', 'a<a')])
22741
+ self._run_check("<!", [('data', '<!')])
22742
+ self._run_check("<a", [('data', '<a')])
22743
+ self._run_check("<a foo='bar'", [('data', "<a foo='bar'")])
22744
+ self._run_check("<a foo='bar", [('data', "<a foo='bar")])
22745
+ self._run_check("<a foo='>'", [('data', "<a foo='>'")])
22746
+ self._run_check("<a foo='>", [('data', "<a foo='>")])
22748
+ def test_declaration_junk_chars(self):
22749
+ self._run_check("<!DOCTYPE foo $ >", [('decl', 'DOCTYPE foo $ ')])
22751
+ def test_illegal_declarations(self):
22752
+ self._run_check('<!spacer type="block" height="25">',
22753
+ [('comment', 'spacer type="block" height="25"')])
22755
+ def test_with_unquoted_attributes(self):
22757
+ html = ("<html><body bgcolor=d0ca90 text='181008'>"
22758
+ "<table cellspacing=0 cellpadding=1 width=100% ><tr>"
22759
+ "<td align=left><font size=-1>"
22760
+ "- <a href=/rabota/><span class=en> software-and-i</span></a>"
22761
+ "- <a href='/1/'><span class=en> library</span></a></table>")
22763
+ ('starttag', 'html', []),
22764
+ ('starttag', 'body', [('bgcolor', 'd0ca90'), ('text', '181008')]),
22765
+ ('starttag', 'table',
22766
+ [('cellspacing', '0'), ('cellpadding', '1'), ('width', '100%')]),
22767
+ ('starttag', 'tr', []),
22768
+ ('starttag', 'td', [('align', 'left')]),
22769
+ ('starttag', 'font', [('size', '-1')]),
22770
+ ('data', '- '), ('starttag', 'a', [('href', '/rabota/')]),
22771
+ ('starttag', 'span', [('class', 'en')]), ('data', ' software-and-i'),
22772
+ ('endtag', 'span'), ('endtag', 'a'),
22773
+ ('data', '- '), ('starttag', 'a', [('href', '/1/')]),
22774
+ ('starttag', 'span', [('class', 'en')]), ('data', ' library'),
22775
+ ('endtag', 'span'), ('endtag', 'a'), ('endtag', 'table')
22777
+ self._run_check(html, expected)
22779
def test_comma_between_attributes(self):
22780
self._run_check('<form action="/xxx.php?a=1&b=2&", '
22781
'method="post">', [
22782
('starttag', 'form',
22783
[('action', '/xxx.php?a=1&b=2&'),
22784
- ('method', 'post')])],
22785
- collector = self.collector)
22786
+ (',', None), ('method', 'post')])])
22788
def test_weird_chars_in_unquoted_attribute_values(self):
22789
self._run_check('<form action=bogus|&#()value>', [
22790
('starttag', 'form',
22791
- [('action', 'bogus|&#()value')])],
22792
- collector = self.collector)
22793
+ [('action', 'bogus|&#()value')])])
22795
+ def test_invalid_end_tags(self):
22796
+ # A collection of broken end tags. <br> is used as separator.
22797
+ # see http://www.w3.org/TR/html5/tokenization.html#end-tag-open-state
22799
+ html = ('<br></label</p><br></div end tmAd-leaderBoard><br></<h4><br>'
22800
+ '</li class="unit"><br></li\r\n\t\t\t\t\t\t</ul><br></><br>')
22801
+ expected = [('starttag', 'br', []),
22802
+ # < is part of the name, / is discarded, p is an attribute
22803
+ ('endtag', 'label<'),
22804
+ ('starttag', 'br', []),
22805
+ # text and attributes are discarded
22806
+ ('endtag', 'div'),
22807
+ ('starttag', 'br', []),
22808
+ # comment because the first char after </ is not a-zA-Z
22809
+ ('comment', '<h4'),
22810
+ ('starttag', 'br', []),
22811
+ # attributes are discarded
22812
+ ('endtag', 'li'),
22813
+ ('starttag', 'br', []),
22814
+ # everything till ul (included) is discarded
22815
+ ('endtag', 'li'),
22816
+ ('starttag', 'br', []),
22818
+ ('starttag', 'br', [])]
22819
+ self._run_check(html, expected)
22821
+ def test_broken_invalid_end_tag(self):
22822
+ # This is technically wrong (the "> shouldn't be included in the 'data')
22823
+ # but is probably not worth fixing it (in addition to all the cases of
22824
+ # the previous test, it would require a full attribute parsing).
22826
+ html = '<b>This</b attr=">"> confuses the parser'
22827
+ expected = [('starttag', 'b', []),
22828
+ ('data', 'This'),
22830
+ ('data', '"> confuses the parser')]
22831
+ self._run_check(html, expected)
22833
+ def test_correct_detection_of_start_tags(self):
22835
+ html = ('<div style="" ><b>The <a href="some_url">rain</a> '
22836
+ '<br /> in <span>Spain</span></b></div>')
22838
+ ('starttag', 'div', [('style', '')]),
22839
+ ('starttag', 'b', []),
22840
+ ('data', 'The '),
22841
+ ('starttag', 'a', [('href', 'some_url')]),
22842
+ ('data', 'rain'),
22845
+ ('startendtag', 'br', []),
22846
+ ('data', ' in '),
22847
+ ('starttag', 'span', []),
22848
+ ('data', 'Spain'),
22849
+ ('endtag', 'span'),
22851
+ ('endtag', 'div')
22853
+ self._run_check(html, expected)
22855
+ html = '<div style="", foo = "bar" ><b>The <a href="some_url">rain</a>'
22857
+ ('starttag', 'div', [('style', ''), (',', None), ('foo', 'bar')]),
22858
+ ('starttag', 'b', []),
22859
+ ('data', 'The '),
22860
+ ('starttag', 'a', [('href', 'some_url')]),
22861
+ ('data', 'rain'),
22864
+ self._run_check(html, expected)
22866
def test_unescape_function(self):
22867
- p = html.parser.HTMLParser()
22868
+ p = self.get_collector()
22869
self.assertEqual(p.unescape('&#bad;'),'&#bad;')
22870
self.assertEqual(p.unescape('&'),'&')
22872
+ self.assertEqual(p.unescape('{ ' * 1050), '{ ' * 1050)
22874
+ def test_broken_comments(self):
22875
+ html = ('<! not really a comment >'
22876
+ '<! not a comment either -->'
22877
+ '<! -- close enough -->'
22878
+ '<!><!<-- this was an empty comment>'
22879
+ '<!!! another bogus comment !!!>')
22881
+ ('comment', ' not really a comment '),
22882
+ ('comment', ' not a comment either --'),
22883
+ ('comment', ' -- close enough --'),
22885
+ ('comment', '<-- this was an empty comment'),
22886
+ ('comment', '!! another bogus comment !!!'),
22888
+ self._run_check(html, expected)
22890
+ def test_broken_condcoms(self):
22891
+ # these condcoms are missing the '--' after '<!' and before the '>'
22892
+ html = ('<![if !(IE)]>broken condcom<![endif]>'
22893
+ '<![if ! IE]><link href="favicon.tiff"/><![endif]>'
22894
+ '<![if !IE 6]><img src="firefox.png" /><![endif]>'
22895
+ '<![if !ie 6]><b>foo</b><![endif]>'
22896
+ '<![if (!IE)|(lt IE 9)]><img src="mammoth.bmp" /><![endif]>')
22897
+ # According to the HTML5 specs sections "8.2.4.44 Bogus comment state"
22898
+ # and "8.2.4.45 Markup declaration open state", comment tokens should
22899
+ # be emitted instead of 'unknown decl', but calling unknown_decl
22900
+ # provides more flexibility.
22901
+ # See also Lib/_markupbase.py:parse_declaration
22903
+ ('unknown decl', 'if !(IE)'),
22904
+ ('data', 'broken condcom'),
22905
+ ('unknown decl', 'endif'),
22906
+ ('unknown decl', 'if ! IE'),
22907
+ ('startendtag', 'link', [('href', 'favicon.tiff')]),
22908
+ ('unknown decl', 'endif'),
22909
+ ('unknown decl', 'if !IE 6'),
22910
+ ('startendtag', 'img', [('src', 'firefox.png')]),
22911
+ ('unknown decl', 'endif'),
22912
+ ('unknown decl', 'if !ie 6'),
22913
+ ('starttag', 'b', []),
22916
+ ('unknown decl', 'endif'),
22917
+ ('unknown decl', 'if (!IE)|(lt IE 9)'),
22918
+ ('startendtag', 'img', [('src', 'mammoth.bmp')]),
22919
+ ('unknown decl', 'endif')
22921
+ self._run_check(html, expected)
22924
+class AttributesStrictTestCase(TestCaseBase):
22926
+ def get_collector(self):
22927
+ return EventCollector(strict=True)
22929
+ def test_attr_syntax(self):
22931
+ ("starttag", "a", [("b", "v"), ("c", "v"), ("d", "v"), ("e", None)])
22933
+ self._run_check("""<a b='v' c="v" d=v e>""", output)
22934
+ self._run_check("""<a b = 'v' c = "v" d = v e>""", output)
22935
+ self._run_check("""<a\nb\n=\n'v'\nc\n=\n"v"\nd\n=\nv\ne>""", output)
22936
+ self._run_check("""<a\tb\t=\t'v'\tc\t=\t"v"\td\t=\tv\te>""", output)
22938
+ def test_attr_values(self):
22939
+ self._run_check("""<a b='xxx\n\txxx' c="yyy\t\nyyy" d='\txyz\n'>""",
22940
+ [("starttag", "a", [("b", "xxx\n\txxx"),
22941
+ ("c", "yyy\t\nyyy"),
22942
+ ("d", "\txyz\n")])])
22943
+ self._run_check("""<a b='' c="">""",
22944
+ [("starttag", "a", [("b", ""), ("c", "")])])
22945
+ # Regression test for SF patch #669683.
22946
+ self._run_check("<e a=rgb(1,2,3)>",
22947
+ [("starttag", "e", [("a", "rgb(1,2,3)")])])
22948
+ # Regression test for SF bug #921657.
22950
+ "<a href=mailto:xyz@example.com>",
22951
+ [("starttag", "a", [("href", "mailto:xyz@example.com")])])
22953
+ def test_attr_nonascii(self):
22956
+ "<img src=/foo/bar.png alt=\u4e2d\u6587>",
22957
+ [("starttag", "img", [("src", "/foo/bar.png"),
22958
+ ("alt", "\u4e2d\u6587")])])
22960
+ "<a title='\u30c6\u30b9\u30c8' href='\u30c6\u30b9\u30c8.html'>",
22961
+ [("starttag", "a", [("title", "\u30c6\u30b9\u30c8"),
22962
+ ("href", "\u30c6\u30b9\u30c8.html")])])
22964
+ '<a title="\u30c6\u30b9\u30c8" href="\u30c6\u30b9\u30c8.html">',
22965
+ [("starttag", "a", [("title", "\u30c6\u30b9\u30c8"),
22966
+ ("href", "\u30c6\u30b9\u30c8.html")])])
22968
+ def test_attr_entity_replacement(self):
22970
+ "<a b='&><"''>",
22971
+ [("starttag", "a", [("b", "&><\"'")])])
22973
+ def test_attr_funky_names(self):
22975
+ "<a a.b='v' c:d=v e-f=v>",
22976
+ [("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")])])
22978
+ def test_entityrefs_in_attributes(self):
22980
+ "<html foo='€&aa&unsupported;'>",
22981
+ [("starttag", "html", [("foo", "\u20AC&aa&unsupported;")])])
22985
+class AttributesTolerantTestCase(AttributesStrictTestCase):
22987
+ def get_collector(self):
22988
+ return EventCollector(strict=False)
22990
+ def test_attr_funky_names2(self):
22992
+ "<a $><b $=%><c \=/>",
22993
+ [("starttag", "a", [("$", None)]),
22994
+ ("starttag", "b", [("$", "%")]),
22995
+ ("starttag", "c", [("\\", "/")])])
22997
+ def test_entities_in_attribute_value(self):
22999
+ for entity in ['&', '&', '&', '&']:
23000
+ self._run_check('<a href="%s">' % entity,
23001
+ [("starttag", "a", [("href", "&")])])
23002
+ self._run_check("<a href='%s'>" % entity,
23003
+ [("starttag", "a", [("href", "&")])])
23004
+ self._run_check("<a href=%s>" % entity,
23005
+ [("starttag", "a", [("href", "&")])])
23007
+ def test_malformed_attributes(self):
23010
+ "<a href=test'style='color:red;bad1'>test - bad1</a>"
23011
+ "<a href=test'+style='color:red;ba2'>test - bad2</a>"
23012
+ "<a href=test' style='color:red;bad3'>test - bad3</a>"
23013
+ "<a href = test' style='color:red;bad4' >test - bad4</a>"
23016
+ ('starttag', 'a', [('href', "test'style='color:red;bad1'")]),
23017
+ ('data', 'test - bad1'), ('endtag', 'a'),
23018
+ ('starttag', 'a', [('href', "test'+style='color:red;ba2'")]),
23019
+ ('data', 'test - bad2'), ('endtag', 'a'),
23020
+ ('starttag', 'a', [('href', "test'\xa0style='color:red;bad3'")]),
23021
+ ('data', 'test - bad3'), ('endtag', 'a'),
23022
+ ('starttag', 'a', [('href', "test'\xa0style='color:red;bad4'")]),
23023
+ ('data', 'test - bad4'), ('endtag', 'a')
23025
+ self._run_check(html, expected)
23027
+ def test_malformed_adjacent_attributes(self):
23029
+ self._run_check('<x><y z=""o"" /></x>',
23030
+ [('starttag', 'x', []),
23031
+ ('startendtag', 'y', [('z', ''), ('o""', None)]),
23032
+ ('endtag', 'x')])
23033
+ self._run_check('<x><y z="""" /></x>',
23034
+ [('starttag', 'x', []),
23035
+ ('startendtag', 'y', [('z', ''), ('""', None)]),
23036
+ ('endtag', 'x')])
23038
+ # see #755670 for the following 3 tests
23039
+ def test_adjacent_attributes(self):
23040
+ self._run_check('<a width="100%"cellspacing=0>',
23041
+ [("starttag", "a",
23042
+ [("width", "100%"), ("cellspacing","0")])])
23044
+ self._run_check('<a id="foo"class="bar">',
23045
+ [("starttag", "a",
23046
+ [("id", "foo"), ("class","bar")])])
23048
+ def test_missing_attribute_value(self):
23049
+ self._run_check('<a v=>',
23050
+ [("starttag", "a", [("v", "")])])
23052
+ def test_javascript_attribute_value(self):
23053
+ self._run_check("<a href=javascript:popup('/popup/help.html')>",
23054
+ [("starttag", "a",
23055
+ [("href", "javascript:popup('/popup/help.html')")])])
23057
+ def test_end_tag_in_attribute_value(self):
23059
+ self._run_check("<a href='http://www.example.org/\">;'>spam</a>",
23060
+ [("starttag", "a",
23061
+ [("href", "http://www.example.org/\">;")]),
23062
+ ("data", "spam"), ("endtag", "a")])
23067
- support.run_unittest(HTMLParserTestCase, HTMLParserTolerantTestCase)
23068
+ support.run_unittest(HTMLParserStrictTestCase, HTMLParserTolerantTestCase,
23069
+ AttributesStrictTestCase, AttributesTolerantTestCase)
23072
if __name__ == "__main__":
23073
diff -r 137e45f15c0b Lib/test/test_httplib.py
23074
--- a/Lib/test/test_httplib.py
23075
+++ b/Lib/test/test_httplib.py
23076
@@ -161,14 +161,16 @@
23077
def test_host_port(self):
23078
# Check invalid host_port
23080
- for hp in ("www.python.org:abc", "www.python.org:"):
23081
+ for hp in ("www.python.org:abc", "user:password@www.python.org"):
23082
self.assertRaises(client.InvalidURL, client.HTTPConnection, hp)
23084
for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000",
23085
"fe80::207:e9ff:fe9b", 8000),
23086
("www.python.org:80", "www.python.org", 80),
23087
+ ("www.python.org:", "www.python.org", 80),
23088
("www.python.org", "www.python.org", 80),
23089
- ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80)):
23090
+ ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80),
23091
+ ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 80)):
23092
c = client.HTTPConnection(hp)
23093
self.assertEqual(h, c.host)
23094
self.assertEqual(p, c.port)
23095
@@ -539,6 +541,26 @@
23096
resp = h.getresponse()
23097
self.assertEqual(resp.status, 404)
23099
+ @unittest.skipIf(not hasattr(client, 'HTTPSConnection'),
23100
+ 'http.client.HTTPSConnection not available')
23101
+ def test_host_port(self):
23102
+ # Check invalid host_port
23104
+ for hp in ("www.python.org:abc", "user:password@www.python.org"):
23105
+ self.assertRaises(client.InvalidURL, client.HTTPSConnection, hp)
23107
+ for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000",
23108
+ "fe80::207:e9ff:fe9b", 8000),
23109
+ ("www.python.org:443", "www.python.org", 443),
23110
+ ("www.python.org:", "www.python.org", 443),
23111
+ ("www.python.org", "www.python.org", 443),
23112
+ ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 443),
23113
+ ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b",
23115
+ c = client.HTTPSConnection(hp)
23116
+ self.assertEqual(h, c.host)
23117
+ self.assertEqual(p, c.port)
23120
class RequestBodyTest(TestCase):
23121
"""Test cases where a request includes a message body."""
23122
@@ -588,6 +610,7 @@
23123
self.assertEqual(b'body\xc1', f.read())
23125
def test_file_body(self):
23126
+ self.addCleanup(support.unlink, support.TESTFN)
23127
with open(support.TESTFN, "w") as f:
23129
with open(support.TESTFN) as f:
23130
@@ -599,6 +622,7 @@
23131
self.assertEqual(b'body', f.read())
23133
def test_binary_file_body(self):
23134
+ self.addCleanup(support.unlink, support.TESTFN)
23135
with open(support.TESTFN, "wb") as f:
23136
f.write(b"body\xc1")
23137
with open(support.TESTFN, "rb") as f:
23138
diff -r 137e45f15c0b Lib/test/test_httpservers.py
23139
--- a/Lib/test/test_httpservers.py
23140
+++ b/Lib/test/test_httpservers.py
23141
@@ -259,8 +259,9 @@
23142
with open(os.path.join(self.tempdir_name, 'index.html'), 'w') as f:
23143
response = self.request('/' + self.tempdir_name + '/')
23144
self.check_status_and_reason(response, 200)
23145
- if os.name == 'posix':
23146
- # chmod won't work as expected on Windows platforms
23147
+ # chmod() doesn't work as expected on Windows, and filesystem
23148
+ # permissions are ignored by root on Unix.
23149
+ if os.name == 'posix' and os.geteuid() != 0:
23150
os.chmod(self.tempdir, 0)
23151
response = self.request(self.tempdir_name + '/')
23152
self.check_status_and_reason(response, 404)
23153
@@ -305,6 +306,9 @@
23154
form.getfirst("bacon")))
23158
+@unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
23159
+ "This test can't be run reliably as root (issue #13308).")
23160
class CGIHTTPServerTestCase(BaseTestCase):
23161
class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler):
23163
diff -r 137e45f15c0b Lib/test/test_import.py
23164
--- a/Lib/test/test_import.py
23165
+++ b/Lib/test/test_import.py
23167
from importlib.test.import_ import util as importlib_util
23179
from test.support import (
23180
EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython,
23181
@@ -106,15 +108,15 @@
23182
open(fname, 'w').close()
23183
os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH |
23184
stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))
23185
+ fn = imp.cache_from_source(fname)
23188
- fn = imp.cache_from_source(fname)
23189
if not os.path.exists(fn):
23190
self.fail("__import__ did not result in creation of "
23191
"either a .pyc or .pyo file")
23193
- self.assertEqual(
23194
- stat.S_IMODE(s.st_mode),
23195
- stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
23197
+ self.assertEqual(stat.S_IMODE(s.st_mode),
23198
+ stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
23201
remove_files(TESTFN)
23202
@@ -139,6 +141,15 @@
23203
self.assertIs(orig_path, new_os.path)
23204
self.assertIsNot(orig_getenv, new_os.getenv)
23206
+ def test_bug7732(self):
23207
+ source = TESTFN + '.py'
23210
+ self.assertRaisesRegex(ImportError, '^No module',
23211
+ imp.find_module, TESTFN, ["."])
23215
def test_module_with_large_stack(self, module='longlist'):
23216
# Regression test for http://bugs.python.org/issue561858.
23217
filename = module + '.py'
23218
@@ -300,6 +311,30 @@
23220
script_helper.assert_python_ok(testfn)
23222
+ def test_timestamp_overflow(self):
23223
+ # A modification timestamp larger than 2**32 should not be a problem
23224
+ # when importing a module (issue #11235).
23225
+ sys.path.insert(0, os.curdir)
23227
+ source = TESTFN + ".py"
23228
+ compiled = imp.cache_from_source(source)
23229
+ with open(source, 'w') as f:
23232
+ os.utime(source, (2 ** 33 - 5, 2 ** 33 - 5))
23233
+ except OverflowError:
23234
+ self.skipTest("cannot set modification time to large integer")
23235
+ except OSError as e:
23236
+ if e.errno != getattr(errno, 'EOVERFLOW', None):
23238
+ self.skipTest("cannot set modification time to large integer ({})".format(e))
23239
+ __import__(TESTFN)
23240
+ # The pyc file was created.
23241
+ os.stat(compiled)
23244
+ remove_files(TESTFN)
23247
class PycRewritingTests(unittest.TestCase):
23248
# Test that the `co_filename` attribute on code objects always points
23249
@@ -537,6 +572,8 @@
23251
@unittest.skipUnless(os.name == 'posix',
23252
"test meaningful only on posix systems")
23253
+ @unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
23254
+ "due to varying filesystem permission semantics (issue #11956)")
23255
def test_unwritable_directory(self):
23256
# When the umask causes the new __pycache__ directory to be
23257
# unwritable, the import still succeeds but no .pyc file is written.
23258
diff -r 137e45f15c0b Lib/test/test_inspect.py
23259
--- a/Lib/test/test_inspect.py
23260
+++ b/Lib/test/test_inspect.py
23261
@@ -425,10 +425,37 @@
23262
def test_class(self):
23263
self.assertSourceEqual(self.fodderModule.X, 1, 2)
23266
+class _BrokenDataDescriptor(object):
23268
+ A broken data descriptor. See bug #1785.
23270
+ def __get__(*args):
23271
+ raise AssertionError("should not __get__ data descriptors")
23273
+ def __set__(*args):
23274
+ raise RuntimeError
23276
+ def __getattr__(*args):
23277
+ raise AssertionError("should not __getattr__ data descriptors")
23280
+class _BrokenMethodDescriptor(object):
23282
+ A broken method descriptor. See bug #1785.
23284
+ def __get__(*args):
23285
+ raise AssertionError("should not __get__ method descriptors")
23287
+ def __getattr__(*args):
23288
+ raise AssertionError("should not __getattr__ method descriptors")
23291
# Helper for testing classify_class_attrs.
23292
def attrs_wo_objs(cls):
23293
return [t[:3] for t in inspect.classify_class_attrs(cls)]
23296
class TestClassesAndFunctions(unittest.TestCase):
23297
def test_newstyle_mro(self):
23298
# The same w/ new-class MRO.
23299
@@ -525,6 +552,9 @@
23303
+ dd = _BrokenDataDescriptor()
23304
+ md = _BrokenMethodDescriptor()
23306
attrs = attrs_wo_objs(A)
23307
self.assertIn(('s', 'static method', A), attrs, 'missing static method')
23308
self.assertIn(('c', 'class method', A), attrs, 'missing class method')
23309
@@ -533,6 +563,8 @@
23310
'missing plain method: %r' % attrs)
23311
self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
23312
self.assertIn(('datablob', 'data', A), attrs, 'missing data')
23313
+ self.assertIn(('md', 'method', A), attrs, 'missing method descriptor')
23314
+ self.assertIn(('dd', 'data', A), attrs, 'missing data descriptor')
23318
@@ -545,6 +577,8 @@
23319
self.assertIn(('m', 'method', B), attrs, 'missing plain method')
23320
self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
23321
self.assertIn(('datablob', 'data', A), attrs, 'missing data')
23322
+ self.assertIn(('md', 'method', A), attrs, 'missing method descriptor')
23323
+ self.assertIn(('dd', 'data', A), attrs, 'missing data descriptor')
23327
@@ -559,6 +593,8 @@
23328
self.assertIn(('m', 'method', C), attrs, 'missing plain method')
23329
self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
23330
self.assertIn(('datablob', 'data', A), attrs, 'missing data')
23331
+ self.assertIn(('md', 'method', A), attrs, 'missing method descriptor')
23332
+ self.assertIn(('dd', 'data', A), attrs, 'missing data descriptor')
23336
@@ -571,6 +607,60 @@
23337
self.assertIn(('m', 'method', B), attrs, 'missing plain method')
23338
self.assertIn(('m1', 'method', D), attrs, 'missing plain method')
23339
self.assertIn(('datablob', 'data', A), attrs, 'missing data')
23340
+ self.assertIn(('md', 'method', A), attrs, 'missing method descriptor')
23341
+ self.assertIn(('dd', 'data', A), attrs, 'missing data descriptor')
23343
+ def test_classify_builtin_types(self):
23344
+ # Simple sanity check that all built-in types can have their
23345
+ # attributes classified.
23346
+ for name in dir(__builtins__):
23347
+ builtin = getattr(__builtins__, name)
23348
+ if isinstance(builtin, type):
23349
+ inspect.classify_class_attrs(builtin)
23351
+ def test_getmembers_descriptors(self):
23353
+ dd = _BrokenDataDescriptor()
23354
+ md = _BrokenMethodDescriptor()
23356
+ def pred_wrapper(pred):
23357
+ # A quick'n'dirty way to discard standard attributes of new-style
23359
+ class Empty(object):
23362
+ if '__name__' in dir(x) and hasattr(Empty, x.__name__):
23367
+ ismethoddescriptor = pred_wrapper(inspect.ismethoddescriptor)
23368
+ isdatadescriptor = pred_wrapper(inspect.isdatadescriptor)
23370
+ self.assertEqual(inspect.getmembers(A, ismethoddescriptor),
23371
+ [('md', A.__dict__['md'])])
23372
+ self.assertEqual(inspect.getmembers(A, isdatadescriptor),
23373
+ [('dd', A.__dict__['dd'])])
23378
+ self.assertEqual(inspect.getmembers(B, ismethoddescriptor),
23379
+ [('md', A.__dict__['md'])])
23380
+ self.assertEqual(inspect.getmembers(B, isdatadescriptor),
23381
+ [('dd', A.__dict__['dd'])])
23383
+ def test_getmembers_method(self):
23388
+ self.assertIn(('f', B.f), inspect.getmembers(B))
23389
+ self.assertNotIn(('f', B.f), inspect.getmembers(B, inspect.ismethod))
23391
+ self.assertIn(('f', b.f), inspect.getmembers(b))
23392
+ self.assertIn(('f', b.f), inspect.getmembers(b, inspect.ismethod))
23395
class TestGetcallargsFunctions(unittest.TestCase):
23397
@@ -1004,6 +1094,28 @@
23398
self.assertEqual(inspect.getattr_static(instance, "spam"), 42)
23399
self.assertFalse(Thing.executed)
23401
+ def test_module(self):
23402
+ sentinel = object()
23403
+ self.assertIsNot(inspect.getattr_static(sys, "version", sentinel),
23406
+ def test_metaclass_with_metaclass_with_dict_as_property(self):
23407
+ class MetaMeta(type):
23409
+ def __dict__(self):
23410
+ self.executed = True
23411
+ return dict(spam=42)
23413
+ class Meta(type, metaclass=MetaMeta):
23416
+ class Thing(metaclass=Meta):
23419
+ with self.assertRaises(AttributeError):
23420
+ inspect.getattr_static(Thing, "spam")
23421
+ self.assertFalse(Thing.executed)
23423
class TestGetGeneratorState(unittest.TestCase):
23426
diff -r 137e45f15c0b Lib/test/test_io.py
23427
--- a/Lib/test/test_io.py
23428
+++ b/Lib/test/test_io.py
23431
except ImportError:
23436
+except ImportError:
23439
def _default_chunk_size():
23440
"""Get the default TextIOWrapper chunk size"""
23441
@@ -242,9 +245,14 @@
1869
+ marshal.loads(b'')
23445
- self._blocker_char = None
23446
- self._write_stack.append(b[:n])
23447
- raise self.BlockingIOError(0, "test blocking", n)
23449
+ # write data up to the first blocker
23450
+ self._write_stack.append(b[:n])
23453
+ # cancel blocker and indicate would block
23454
+ self._blocker_char = None
23456
self._write_stack.append(b)
23459
@@ -355,6 +363,11 @@
23460
self.assertRaises(exc, fp.seek, 1, self.SEEK_CUR)
23461
self.assertRaises(exc, fp.seek, -1, self.SEEK_END)
23463
+ def test_open_handles_NUL_chars(self):
23464
+ fn_with_NUL = 'foo\0bar'
23465
+ self.assertRaises(TypeError, self.open, fn_with_NUL, 'w')
23466
+ self.assertRaises(TypeError, self.open, bytes(fn_with_NUL, 'ascii'), 'w')
23468
def test_raw_file_io(self):
23469
with self.open(support.TESTFN, "wb", buffering=0) as f:
23470
self.assertEqual(f.readable(), False)
23471
@@ -610,6 +623,17 @@
23472
self.assertEqual(rawio.read(2), None)
23473
self.assertEqual(rawio.read(2), b"")
23475
+ def test_types_have_dict(self):
23478
+ self.RawIOBase(),
23479
+ self.TextIOBase(),
23484
+ self.assertTrue(hasattr(obj, "__dict__"))
23486
class CIOTest(IOTest):
23488
def test_IOBase_finalize(self):
23489
@@ -911,6 +935,14 @@
23491
support.unlink(support.TESTFN)
23493
+ def test_unseekable(self):
23494
+ bufio = self.tp(self.MockUnseekableIO(b"A" * 10))
23495
+ self.assertRaises(self.UnsupportedOperation, bufio.tell)
23496
+ self.assertRaises(self.UnsupportedOperation, bufio.seek, 0)
23498
+ self.assertRaises(self.UnsupportedOperation, bufio.seek, 0)
23499
+ self.assertRaises(self.UnsupportedOperation, bufio.tell)
23501
def test_misbehaved_io(self):
23502
rawio = self.MisbehavedRawIO((b"abc", b"d", b"efg"))
23503
bufio = self.tp(rawio)
23504
@@ -1395,15 +1427,18 @@
23506
self.assertEqual(b"asdf", rw.read(4))
23508
- rw.write(b"asdf")
23509
+ rw.write(b"123f")
23511
- self.assertEqual(b"asdfasdfl", rw.read())
23512
+ self.assertEqual(b"asdf123fl", rw.read())
23513
self.assertEqual(9, rw.tell())
23515
self.assertEqual(5, rw.tell())
23517
self.assertEqual(7, rw.tell())
23518
self.assertEqual(b"fl", rw.read(11))
23520
+ self.assertEqual(b"asdf123fl", raw.getvalue())
23522
self.assertRaises(TypeError, rw.seek, 0.0)
23524
def check_flush_and_read(self, read_func):
23525
@@ -1548,6 +1583,43 @@
23526
BufferedReaderTest.test_misbehaved_io(self)
23527
BufferedWriterTest.test_misbehaved_io(self)
23529
+ def test_interleaved_read_write(self):
23530
+ # Test for issue #12213
23531
+ with self.BytesIO(b'abcdefgh') as raw:
23532
+ with self.tp(raw, 100) as f:
23534
+ self.assertEqual(f.read(1), b'b')
23536
+ self.assertEqual(f.read1(1), b'd')
23538
+ buf = bytearray(1)
23540
+ self.assertEqual(buf, b'f')
23542
+ self.assertEqual(f.peek(1), b'h')
23544
+ self.assertEqual(raw.getvalue(), b'1b2d3f4h')
23546
+ with self.BytesIO(b'abc') as raw:
23547
+ with self.tp(raw, 100) as f:
23548
+ self.assertEqual(f.read(1), b'a')
23550
+ self.assertEqual(f.read(1), b'c')
23552
+ self.assertEqual(raw.getvalue(), b'a2c')
23554
+ def test_interleaved_readline_write(self):
23555
+ with self.BytesIO(b'ab\ncdef\ng\n') as raw:
23556
+ with self.tp(raw) as f:
23558
+ self.assertEqual(f.readline(), b'b\n')
23560
+ self.assertEqual(f.readline(), b'def\n')
23562
+ self.assertEqual(f.readline(), b'\n')
23564
+ self.assertEqual(raw.getvalue(), b'1b\n2def\n3\n')
23566
# You can't construct a BufferedRandom over a non-seekable stream.
23567
test_unseekable = None
23569
@@ -2355,6 +2427,21 @@
23570
with self.open(support.TESTFN, "rb") as f:
23571
self.assertEqual(f.read(), b"456def")
23573
+ def test_rwpair_cleared_before_textio(self):
23574
+ # Issue 13070: TextIOWrapper's finalization would crash when called
23575
+ # after the reference to the underlying BufferedRWPair's writer got
23576
+ # cleared by the GC.
23577
+ for i in range(1000):
23578
+ b1 = self.BufferedRWPair(self.MockRawIO(), self.MockRawIO())
23579
+ t1 = self.TextIOWrapper(b1, encoding="ascii")
23580
+ b2 = self.BufferedRWPair(self.MockRawIO(), self.MockRawIO())
23581
+ t2 = self.TextIOWrapper(b2, encoding="ascii")
23582
+ # circular references
23585
+ support.gc_collect()
23588
class PyTextIOWrapperTest(TextIOWrapperTest):
23591
@@ -2669,6 +2756,68 @@
23592
with self.open(support.TESTFN, **kwargs) as f:
23593
self.assertRaises(TypeError, pickle.dumps, f, protocol)
23595
+ @unittest.skipUnless(fcntl, 'fcntl required for this test')
23596
+ def test_nonblock_pipe_write_bigbuf(self):
23597
+ self._test_nonblock_pipe_write(16*1024)
23599
+ @unittest.skipUnless(fcntl, 'fcntl required for this test')
23600
+ def test_nonblock_pipe_write_smallbuf(self):
23601
+ self._test_nonblock_pipe_write(1024)
23603
+ def _set_non_blocking(self, fd):
23604
+ flags = fcntl.fcntl(fd, fcntl.F_GETFL)
23605
+ self.assertNotEqual(flags, -1)
23606
+ res = fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
23607
+ self.assertEqual(res, 0)
23609
+ def _test_nonblock_pipe_write(self, bufsize):
23613
+ self._set_non_blocking(r)
23614
+ self._set_non_blocking(w)
23616
+ # To exercise all code paths in the C implementation we need
23617
+ # to play with buffer sizes. For instance, if we choose a
23618
+ # buffer size less than or equal to _PIPE_BUF (4096 on Linux)
23619
+ # then we will never get a partial write of the buffer.
23620
+ rf = self.open(r, mode='rb', closefd=True, buffering=bufsize)
23621
+ wf = self.open(w, mode='wb', closefd=True, buffering=bufsize)
23624
+ for N in 9999, 73, 7574:
23628
+ msg = bytes([i % 26 + 97]) * N
23633
+ except self.BlockingIOError as e:
23634
+ self.assertEqual(e.args[0], errno.EAGAIN)
23635
+ sent[-1] = sent[-1][:e.characters_written]
23636
+ received.append(rf.read())
23645
+ except self.BlockingIOError as e:
23646
+ self.assertEqual(e.args[0], errno.EAGAIN)
23647
+ self.assertEqual(e.characters_written, 0)
23648
+ received.append(rf.read())
23650
+ received += iter(rf.read, None)
23652
+ sent, received = b''.join(sent), b''.join(received)
23653
+ self.assertTrue(sent == received)
23654
+ self.assertTrue(wf.closed)
23655
+ self.assertTrue(rf.closed)
23657
class CMiscIOTest(MiscIOTest):
23660
@@ -2796,11 +2945,11 @@
23664
- def test_interrupterd_read_retry_buffered(self):
23665
+ def test_interrupted_read_retry_buffered(self):
23666
self.check_interrupted_read_retry(lambda x: x.decode('latin1'),
23669
- def test_interrupterd_read_retry_text(self):
23670
+ def test_interrupted_read_retry_text(self):
23671
self.check_interrupted_read_retry(lambda x: x,
23674
@@ -2859,10 +3008,10 @@
23675
if e.errno != errno.EBADF:
23678
- def test_interrupterd_write_retry_buffered(self):
23679
+ def test_interrupted_write_retry_buffered(self):
23680
self.check_interrupted_write_retry(b"x", mode="wb")
23682
- def test_interrupterd_write_retry_text(self):
23683
+ def test_interrupted_write_retry_text(self):
23684
self.check_interrupted_write_retry("x", mode="w", encoding="latin1")
23687
diff -r 137e45f15c0b Lib/test/test_keywordonlyarg.py
23688
--- a/Lib/test/test_keywordonlyarg.py
23689
+++ b/Lib/test/test_keywordonlyarg.py
23690
@@ -162,6 +162,14 @@
23691
self.assertEqual(Example.f(Example(), k1=1, k2=2), (1, 2))
23692
self.assertRaises(TypeError, Example.f, k1=1, k2=2)
23694
+ def test_issue13343(self):
23695
+ # The Python compiler must scan all symbols of a function to
23696
+ # determine their scope: global, local, cell...
23697
+ # This was not done for the default values of keyword
23698
+ # arguments in a lambda definition, and the following line
23699
+ # used to fail with a SystemError.
23700
+ lambda *, k1=unittest: None
23703
run_unittest(KeywordOnlyArgTestCase)
23705
diff -r 137e45f15c0b Lib/test/test_lib2to3.py
23706
--- a/Lib/test/test_lib2to3.py
23707
+++ b/Lib/test/test_lib2to3.py
23709
# Skipping test_parser and test_all_fixers
23710
# because of running
23711
from lib2to3.tests import (test_fixers, test_pytree, test_util, test_refactor,
23713
test_main as test_main_)
23715
from test.support import run_unittest
23717
tests = unittest.TestSuite()
23718
loader = unittest.TestLoader()
23719
for m in (test_fixers, test_pytree,test_util, test_refactor,
23721
+ test_parser, test_main_):
23722
tests.addTests(loader.loadTestsFromModule(m))
23725
diff -r 137e45f15c0b Lib/test/test_list.py
23726
--- a/Lib/test/test_list.py
23727
+++ b/Lib/test/test_list.py
23729
self.assertRaises((MemoryError, OverflowError), mul, lst, n)
23730
self.assertRaises((MemoryError, OverflowError), imul, lst, n)
23732
+ def test_repr_large(self):
23733
+ # Check the repr of large list objects
23737
+ self.assertEqual(s,
23738
+ '[' + ', '.join(['0'] * n) + ']')
23739
+ check(10) # check our checking code
23743
def test_main(verbose=None):
23744
support.run_unittest(ListTest)
23746
diff -r 137e45f15c0b Lib/test/test_locale.py
23747
--- a/Lib/test/test_locale.py
23748
+++ b/Lib/test/test_locale.py
23750
from test.support import run_unittest, verbose
23751
-from platform import linux_distribution
23755
@@ -392,8 +391,6 @@
23756
# crasher from bug #7419
23757
self.assertRaises(locale.Error, locale.setlocale, 12345)
23759
- @unittest.skipIf(linux_distribution()[0] == 'Fedora', "Fedora setlocale() "
23760
- "bug: https://bugzilla.redhat.com/show_bug.cgi?id=726536")
23761
def test_getsetlocale_issue1813(self):
23762
# Issue #1813: setting and getting the locale under a Turkish locale
23763
oldlocale = locale.setlocale(locale.LC_CTYPE)
23764
@@ -407,6 +404,14 @@
23765
locale.setlocale(locale.LC_CTYPE, loc)
23766
self.assertEqual(loc, locale.getlocale(locale.LC_CTYPE))
23768
+ def test_invalid_locale_format_in_localetuple(self):
23769
+ with self.assertRaises(TypeError):
23770
+ locale.setlocale(locale.LC_ALL, b'fi_FI')
23772
+ def test_invalid_iterable_in_localetuple(self):
23773
+ with self.assertRaises(TypeError):
23774
+ locale.setlocale(locale.LC_ALL, (b'not', b'valid'))
23779
diff -r 137e45f15c0b Lib/test/test_logging.py
23780
--- a/Lib/test/test_logging.py
23781
+++ b/Lib/test/test_logging.py
23782
@@ -293,6 +293,8 @@
23783
('INF.BADPARENT', 'INFO', '4'),
23786
+ def test_invalid_name(self):
23787
+ self.assertRaises(TypeError, logging.getLogger, any)
23789
class BasicFilterTest(BaseTest):
23791
diff -r 137e45f15c0b Lib/test/test_mailbox.py
1873
diff -r 7085403daf43 Lib/test/test_fractions.py
1874
--- a/Lib/test/test_fractions.py
1875
+++ b/Lib/test/test_fractions.py
1882
from copy import copy, deepcopy
1883
from pickle import dumps, loads
1885
def __float__(self):
1886
assert False, "__float__ should not be invoked"
1888
+class DummyFraction(fractions.Fraction):
1889
+ """Dummy Fraction subclass for copy and deepcopy testing."""
1891
class GcdTest(unittest.TestCase):
1894
@@ -286,9 +290,14 @@
1895
self.assertEqual(F(201, 200).limit_denominator(100), F(1))
1896
self.assertEqual(F(201, 200).limit_denominator(101), F(102, 101))
1897
self.assertEqual(F(0).limit_denominator(10000), F(0))
1899
+ self.assertRaisesMessage(
1900
+ ValueError, "max_denominator should be at least 1",
1901
+ F(1).limit_denominator, i)
1903
def testConversions(self):
1904
self.assertTypedEquals(-1, math.trunc(F(-11, 10)))
1905
+ self.assertTypedEquals(1, math.trunc(F(11, 10)))
1906
self.assertTypedEquals(-2, math.floor(F(-11, 10)))
1907
self.assertTypedEquals(-1, math.ceil(F(-11, 10)))
1908
self.assertTypedEquals(-1, math.ceil(F(-10, 10)))
1910
self.assertEqual(F(8, 27), F(2, 3) ** F(3))
1911
self.assertEqual(F(27, 8), F(2, 3) ** F(-3))
1912
self.assertTypedEquals(2.0, F(4) ** F(1, 2))
1913
+ self.assertEqual(F(1, 1), +F(1, 1))
1914
z = pow(F(-1), F(1, 2))
1915
self.assertAlmostEqual(z.real, 0)
1916
self.assertEqual(z.imag, 1)
1917
@@ -395,6 +405,10 @@
1919
"unsupported operand type(s) for +: 'Fraction' and 'Decimal'",
1920
operator.add, F(3,11), Decimal('3.1415926'))
1921
+ self.assertRaisesMessage(
1923
+ "unsupported operand type(s) for +: 'Decimal' and 'Fraction'",
1924
+ operator.add, Decimal('3.1415926'), F(3,11))
1926
def testComparisons(self):
1927
self.assertTrue(F(1, 2) < F(2, 3))
1928
@@ -538,9 +552,12 @@
1929
self.assertEqual("7", str(F(7, 1)))
1932
+ hmod = sys.hash_info.modulus
1933
+ hinf = sys.hash_info.inf
1934
self.assertEqual(hash(2.5), hash(F(5, 2)))
1935
self.assertEqual(hash(10**50), hash(F(10**50)))
1936
self.assertNotEqual(hash(float(10**23)), hash(F(10**23)))
1937
+ self.assertEqual(hinf, hash(F(1, hmod)))
1938
# Check that __hash__ produces the same value as hash(), for
1939
# consistency with int and Decimal. (See issue #10356.)
1940
self.assertEqual(hash(F(-1)), F(-1).__hash__())
1941
@@ -574,9 +591,14 @@
1943
def test_copy_deepcopy_pickle(self):
1945
+ dr = DummyFraction(13, 7)
1946
self.assertEqual(r, loads(dumps(r)))
1947
self.assertEqual(id(r), id(copy(r)))
1948
self.assertEqual(id(r), id(deepcopy(r)))
1949
+ self.assertNotEqual(id(dr), id(copy(dr)))
1950
+ self.assertNotEqual(id(dr), id(deepcopy(dr)))
1951
+ self.assertTypedEquals(dr, copy(dr))
1952
+ self.assertTypedEquals(dr, deepcopy(dr))
1954
def test_slots(self):
1956
diff -r 7085403daf43 Lib/test/test_mailbox.py
23792
1957
--- a/Lib/test/test_mailbox.py
23793
1958
+++ b/Lib/test/test_mailbox.py
23794
@@ -801,6 +801,25 @@
23795
key1: os.path.join('new', key1),
23796
key2: os.path.join('new', key2)})
23798
+ def test_refresh_after_safety_period(self):
23799
+ # Issue #13254: Call _refresh after the "file system safety
23800
+ # period" of 2 seconds has passed; _toc should still be
23801
+ # updated because this is the first call to _refresh.
23802
+ key0 = self._box.add(self._template % 0)
23803
+ key1 = self._box.add(self._template % 1)
23805
+ self._box = self._factory(self._path)
23806
+ self.assertEqual(self._box._toc, {})
23808
+ # Emulate sleeping. Instead of sleeping for 2 seconds, use the
23809
+ # skew factor to make _refresh think that the filesystem
23810
+ # safety period has passed and re-reading the _toc is only
23811
+ # required if mtimes differ.
23812
+ self._box._skewfactor = -3
23814
+ self._box._refresh()
23815
+ self.assertEqual(sorted(self._box._toc.keys()), sorted([key0, key1]))
23817
def test_lookup(self):
23818
# Look up message subpaths in the TOC
23819
self.assertRaises(KeyError, lambda: self._box._lookup('foo'))
23820
@@ -876,6 +895,8 @@
23821
self.assertFalse((perms & 0o111)) # Execute bits should all be off.
23823
def test_reread(self):
23824
+ # Do an initial unconditional refresh
23825
+ self._box._refresh()
23827
# Put the last modified times more than two seconds into the past
23828
# (because mtime may have a two second granularity)
23829
@@ -887,7 +908,12 @@
23830
# refresh is done unconditionally if called for within
23831
# two-second-plus-a-bit of the last one, just in case the mbox has
23832
# changed; so now we have to wait for that interval to expire.
23833
- time.sleep(2.01 + self._box._skewfactor)
23835
+ # Because this is a test, emulate sleeping. Instead of
23836
+ # sleeping for 2 seconds, use the skew factor to make _refresh
23837
+ # think that 2 seconds have passed and re-reading the _toc is
23838
+ # only required if mtimes differ.
23839
+ self._box._skewfactor = -3
23841
# Re-reading causes the ._toc attribute to be assigned a new dictionary
23842
# object, so we'll check that the ._toc attribute isn't a different
23843
@@ -900,7 +926,8 @@
23844
self.assertFalse(refreshed())
23846
# Now, write something into cur and remove it. This changes
23847
- # the mtime and should cause a re-read.
23848
+ # the mtime and should cause a re-read. Note that "sleep
23849
+ # emulation" is still in effect, as skewfactor is -3.
23850
filename = os.path.join(self._path, 'cur', 'stray-file')
23851
f = open(filename, 'w')
23853
@@ -967,28 +994,37 @@
23854
self.assertEqual(contents, f.read())
23855
self._box = self._factory(self._path)
23857
+ @unittest.skipUnless(hasattr(os, 'fork'), "Test needs fork().")
23858
+ @unittest.skipUnless(hasattr(socket, 'socketpair'), "Test needs socketpair().")
23859
def test_lock_conflict(self):
23860
- # Fork off a subprocess that will lock the file for 2 seconds,
23861
- # unlock it, and then exit.
23862
- if not hasattr(os, 'fork'):
23864
+ # Fork off a child process that will lock the mailbox temporarily,
23865
+ # unlock it and exit.
23866
+ c, p = socket.socketpair()
23867
+ self.addCleanup(c.close)
23868
+ self.addCleanup(p.close)
23872
- # In the child, lock the mailbox.
23875
+ # lock the mailbox, and signal the parent it can proceed
23880
+ # wait until the parent is done, and unlock the mailbox
1960
import email.message
1965
from test import support
1968
def _delete_recursively(self, target):
1969
# Delete a file or delete a directory recursively
1970
if os.path.isdir(target):
1971
- for path, dirs, files in os.walk(target, topdown=False):
1972
- for name in files:
1973
- os.remove(os.path.join(path, name))
1975
- os.rmdir(os.path.join(path, name))
1977
+ shutil.rmtree(target)
1978
elif os.path.exists(target):
1981
@@ -2029,6 +2025,10 @@
1983
# create a new maildir mailbox to work with:
1984
self._dir = support.TESTFN
1985
+ if os.path.isdir(self._dir):
1986
+ shutil.rmtree(self._dir)
1987
+ elif os.path.isfile(self._dir):
1988
+ os.unlink(self._dir)
1990
os.mkdir(os.path.join(self._dir, "cur"))
1991
os.mkdir(os.path.join(self._dir, "tmp"))
1992
diff -r 7085403daf43 Lib/test/test_marshal.py
1993
--- a/Lib/test/test_marshal.py
1994
+++ b/Lib/test/test_marshal.py
1996
#!/usr/bin/env python3
1998
from test import support
2003
@@ -137,6 +138,27 @@
2004
for constructor in (set, frozenset):
2005
self.helper(constructor(self.d.keys()))
2008
+class BufferTestCase(unittest.TestCase, HelperMixin):
2010
+ def test_bytearray(self):
2011
+ b = bytearray(b"abc")
2013
+ new = marshal.loads(marshal.dumps(b))
2014
+ self.assertEqual(type(new), bytes)
2016
+ def test_memoryview(self):
2017
+ b = memoryview(b"abc")
2019
+ new = marshal.loads(marshal.dumps(b))
2020
+ self.assertEqual(type(new), bytes)
2022
+ def test_array(self):
2023
+ a = array.array('B', b"abc")
2024
+ new = marshal.loads(marshal.dumps(a))
2025
+ self.assertEqual(new, b"abc")
2028
class BugsTestCase(unittest.TestCase):
2029
def test_bug_5888452(self):
2030
# Simple-minded check for SF 588452: Debug build crashes
2034
def test_loads_recursion(self):
2035
- s = 'c' + ('X' * 4*4) + '{' * 2**20
2036
+ s = b'c' + (b'X' * 4*4) + b'{' * 2**20
2037
self.assertRaises(ValueError, marshal.loads, s)
2039
def test_recursion_limit(self):
2040
@@ -235,6 +257,11 @@
23886
- # In the parent, sleep a bit to give the child time to acquire
23889
+ # In the parent, wait until the child signals it locked the mailbox.
23892
self.assertRaises(mailbox.ExternalClashError,
23895
+ # Signal the child it can now release the lock and exit.
23897
# Wait for child to exit. Locking should now succeed.
23898
exited_pid, status = os.waitpid(pid, 0)
23900
diff -r 137e45f15c0b Lib/test/test_mimetypes.py
23901
--- a/Lib/test/test_mimetypes.py
23902
+++ b/Lib/test/test_mimetypes.py
23912
from test import support
23915
all = self.db.guess_all_extensions('image/jpg', strict=True)
23918
+ def test_encoding(self):
23919
+ getpreferredencoding = locale.getpreferredencoding
23920
+ self.addCleanup(setattr, locale, 'getpreferredencoding',
23921
+ getpreferredencoding)
23922
+ locale.getpreferredencoding = lambda: 'ascii'
23924
+ filename = support.findfile("mime.types")
23925
+ mimes = mimetypes.MimeTypes([filename])
23926
+ exts = mimes.guess_all_extensions('application/vnd.geocube+xml',
23928
+ self.assertEqual(exts, ['.g3', '.g\xb3'])
23931
@unittest.skipUnless(sys.platform.startswith("win"), "Windows only")
23932
class Win32MimeTypesTestCase(unittest.TestCase):
23933
diff -r 137e45f15c0b Lib/test/test_minidom.py
2042
support.unlink(support.TESTFN)
2044
+ def test_loads_reject_unicode_strings(self):
2045
+ # Issue #14177: marshal.loads() should not accept unicode strings
2046
+ unicode_string = 'T'
2047
+ self.assertRaises(TypeError, marshal.loads, unicode_string)
2051
support.run_unittest(IntTestCase,
2059
if __name__ == "__main__":
2060
diff -r 7085403daf43 Lib/test/test_minidom.py
23934
2061
--- a/Lib/test/test_minidom.py
23935
2062
+++ b/Lib/test/test_minidom.py
23936
@@ -446,6 +446,40 @@
23938
self.confirm(domstr == str.replace("\n", "\r\n"))
23940
+ def test_toprettyxml_with_text_nodes(self):
23941
+ # see issue #4147, text nodes are not indented
23942
+ decl = '<?xml version="1.0" ?>\n'
23943
+ self.assertEqual(parseString('<B>A</B>').toprettyxml(),
23944
+ decl + '<B>A</B>\n')
23945
+ self.assertEqual(parseString('<C>A<B>A</B></C>').toprettyxml(),
23946
+ decl + '<C>\n\tA\n\t<B>A</B>\n</C>\n')
23947
+ self.assertEqual(parseString('<C><B>A</B>A</C>').toprettyxml(),
23948
+ decl + '<C>\n\t<B>A</B>\n\tA\n</C>\n')
23949
+ self.assertEqual(parseString('<C><B>A</B><B>A</B></C>').toprettyxml(),
23950
+ decl + '<C>\n\t<B>A</B>\n\t<B>A</B>\n</C>\n')
23951
+ self.assertEqual(parseString('<C><B>A</B>A<B>A</B></C>').toprettyxml(),
23952
+ decl + '<C>\n\t<B>A</B>\n\tA\n\t<B>A</B>\n</C>\n')
23954
+ def test_toprettyxml_with_adjacent_text_nodes(self):
23955
+ # see issue #4147, adjacent text nodes are indented normally
23957
+ elem = dom.createElement('elem')
23958
+ elem.appendChild(dom.createTextNode('TEXT'))
23959
+ elem.appendChild(dom.createTextNode('TEXT'))
23960
+ dom.appendChild(elem)
23961
+ decl = '<?xml version="1.0" ?>\n'
23962
+ self.assertEqual(dom.toprettyxml(),
23963
+ decl + '<elem>\n\tTEXT\n\tTEXT\n</elem>\n')
23965
+ def test_toprettyxml_preserves_content_of_text_node(self):
23966
+ # see issue #4147
23967
+ for str in ('<B>A</B>', '<A><B>C</B></A>'):
23968
+ dom = parseString(str)
23969
+ dom2 = parseString(dom.toprettyxml())
23970
+ self.assertEqual(
23971
+ dom.getElementsByTagName('B')[0].childNodes[0].toxml(),
23972
+ dom2.getElementsByTagName('B')[0].childNodes[0].toxml())
23974
def testProcessingInstruction(self):
23975
dom = parseString('<e><?mypi \t\n data \t\n ?></e>')
23976
pi = dom.documentElement.firstChild
23977
diff -r 137e45f15c0b Lib/test/test_multiprocessing.py
23978
--- a/Lib/test/test_multiprocessing.py
23979
+++ b/Lib/test/test_multiprocessing.py
23980
@@ -38,11 +38,22 @@
23981
from multiprocessing import util
23984
+ from multiprocessing import reduction
23985
+ HAS_REDUCTION = True
23986
+except ImportError:
23987
+ HAS_REDUCTION = False
23990
from multiprocessing.sharedctypes import Value, copy
23991
HAS_SHAREDCTYPES = True
23992
except ImportError:
23993
HAS_SHAREDCTYPES = False
23997
+except ImportError:
24005
WIN32 = (sys.platform == "win32")
24008
+ MAXFD = os.sysconf("SC_OPEN_MAX")
24013
# Some tests require ctypes
24017
c_int = c_double = None
24020
+def check_enough_semaphores():
24021
+ """Check that the system supports enough semaphores to run the test."""
24022
+ # minimum number of semaphores available according to POSIX
24025
+ nsems = os.sysconf("SC_SEM_NSEMS_MAX")
24026
+ except (AttributeError, ValueError):
24027
+ # sysconf not available or setting not available
24029
+ if nsems == -1 or nsems >= nsems_min:
24031
+ raise unittest.SkipTest("The OS doesn't support enough semaphores "
24032
+ "to run the test (required: %d)." % nsems_min)
24036
# Creates a wrapper for a function which records the time it takes to finish
24038
@@ -257,6 +289,7 @@
24039
p = self.Process(target=time.sleep, args=(DELTA,))
24040
self.assertNotIn(p, self.active_children())
24044
self.assertIn(p, self.active_children())
24046
@@ -327,12 +360,36 @@
24048
def test_subclassing(self):
24049
uppercaser = _UpperCaser()
24050
+ uppercaser.daemon = True
24052
self.assertEqual(uppercaser.submit('hello'), 'HELLO')
24053
self.assertEqual(uppercaser.submit('world'), 'WORLD')
24057
+ def test_stderr_flush(self):
24058
+ # sys.stderr is flushed at process shutdown (issue #13812)
24059
+ if self.TYPE == "threads":
24062
+ testfn = test.support.TESTFN
24063
+ self.addCleanup(test.support.unlink, testfn)
24064
+ proc = self.Process(target=self._test_stderr_flush, args=(testfn,))
24067
+ with open(testfn, 'r') as f:
24069
+ # The whole traceback was printed
24070
+ self.assertIn("ZeroDivisionError", err)
24071
+ self.assertIn("test_multiprocessing.py", err)
24072
+ self.assertIn("1/0 # MARKER", err)
24075
+ def _test_stderr_flush(cls, testfn):
24076
+ sys.stderr = open(testfn, 'w')
24083
@@ -505,6 +562,7 @@
24086
p = self.Process(target=self._test_fork, args=(queue,))
24090
# check that all expected items are in the queue
24091
@@ -545,6 +603,7 @@
24098
for i in range(10):
24099
@@ -815,7 +874,9 @@
24101
#self.assertEqual(event.is_set(), False)
24103
- self.Process(target=self._test_event, args=(event,)).start()
24104
+ p = self.Process(target=self._test_event, args=(event,))
24107
self.assertEqual(wait(), True)
24110
@@ -855,6 +916,7 @@
24111
self.assertEqual(sv.value, cv[1])
24113
proc = self.Process(target=self._test, args=(values,))
24114
+ proc.daemon = True
24118
@@ -918,6 +980,7 @@
24121
p = self.Process(target=self.f, args=(arr,))
24126
@@ -1193,6 +1256,20 @@
24130
+ def test_pool_worker_lifetime_early_close(self):
24131
+ # Issue #10332: closing a pool whose workers have limited lifetimes
24132
+ # before all the tasks completed would make join() hang.
24133
+ p = multiprocessing.Pool(3, maxtasksperchild=1)
24135
+ for i in range(6):
24136
+ results.append(p.apply_async(sqr, (i, 0.3)))
24139
+ # check the results
24140
+ for (j, res) in enumerate(results):
24141
+ self.assertEqual(res.get(), sqr(j))
24145
# Test that manager has expected number of shared objects left
24147
@@ -1322,6 +1399,7 @@
24150
p = self.Process(target=self._putter, args=(manager.address, authkey))
24154
manager2 = QueueManager2(
24155
@@ -1363,6 +1441,7 @@
24158
p = self.Process(target=self._putter, args=(manager.address, authkey))
24161
queue = manager.get_queue()
24162
self.assertEqual(queue.get(), 'hello world')
24163
@@ -1495,6 +1574,7 @@
24164
conn, child_conn = self.Pipe()
24166
p = self.Process(target=self._echo, args=(child_conn,))
24169
child_conn.close() # this might complete before child initializes
24171
@@ -1538,6 +1618,100 @@
24173
self.assertRaises(ValueError, a.send_bytes, msg, 4, -1)
24176
+ def _is_fd_assigned(cls, fd):
24179
+ except OSError as e:
24180
+ if e.errno == errno.EBADF:
24187
+ def _writefd(cls, conn, data, create_dummy_fds=False):
24188
+ if create_dummy_fds:
24189
+ for i in range(0, 256):
24190
+ if not cls._is_fd_assigned(i):
24191
+ os.dup2(conn.fileno(), i)
24192
+ fd = reduction.recv_handle(conn)
24194
+ fd = msvcrt.open_osfhandle(fd, os.O_WRONLY)
24195
+ os.write(fd, data)
24198
+ @unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
24199
+ def test_fd_transfer(self):
24200
+ if self.TYPE != 'processes':
24201
+ self.skipTest("only makes sense with processes")
24202
+ conn, child_conn = self.Pipe(duplex=True)
24204
+ p = self.Process(target=self._writefd, args=(child_conn, b"foo"))
24207
+ self.addCleanup(test.support.unlink, test.support.TESTFN)
24208
+ with open(test.support.TESTFN, "wb") as f:
24211
+ fd = msvcrt.get_osfhandle(fd)
24212
+ reduction.send_handle(conn, fd, p.pid)
24214
+ with open(test.support.TESTFN, "rb") as f:
24215
+ self.assertEqual(f.read(), b"foo")
24217
+ @unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
24218
+ @unittest.skipIf(sys.platform == "win32",
24219
+ "test semantics don't make sense on Windows")
24220
+ @unittest.skipIf(MAXFD <= 256,
24221
+ "largest assignable fd number is too small")
24222
+ @unittest.skipUnless(hasattr(os, "dup2"),
24223
+ "test needs os.dup2()")
24224
+ def test_large_fd_transfer(self):
24225
+ # With fd > 256 (issue #11657)
24226
+ if self.TYPE != 'processes':
24227
+ self.skipTest("only makes sense with processes")
24228
+ conn, child_conn = self.Pipe(duplex=True)
24230
+ p = self.Process(target=self._writefd, args=(child_conn, b"bar", True))
24233
+ self.addCleanup(test.support.unlink, test.support.TESTFN)
24234
+ with open(test.support.TESTFN, "wb") as f:
24236
+ for newfd in range(256, MAXFD):
24237
+ if not self._is_fd_assigned(newfd):
24240
+ self.fail("could not find an unassigned large file descriptor")
24241
+ os.dup2(fd, newfd)
24243
+ reduction.send_handle(conn, newfd, p.pid)
24247
+ with open(test.support.TESTFN, "rb") as f:
24248
+ self.assertEqual(f.read(), b"bar")
24251
+ def _send_data_without_fd(self, conn):
24252
+ os.write(conn.fileno(), b"\0")
24254
+ @unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
24255
+ @unittest.skipIf(sys.platform == "win32", "doesn't make sense on Windows")
24256
+ def test_missing_fd_transfer(self):
24257
+ # Check that exception is raised when received data is not
24258
+ # accompanied by a file descriptor in ancillary data.
24259
+ if self.TYPE != 'processes':
24260
+ self.skipTest("only makes sense with processes")
24261
+ conn, child_conn = self.Pipe(duplex=True)
24263
+ p = self.Process(target=self._send_data_without_fd, args=(child_conn,))
24266
+ self.assertRaises(RuntimeError, reduction.recv_handle, conn)
24269
class _TestListenerClient(BaseTestCase):
24271
ALLOWED_TYPES = ('processes', 'threads')
24272
@@ -1608,11 +1782,13 @@
24274
lconn, lconn0 = self.Pipe()
24275
lp = self.Process(target=self._listener, args=(lconn0, families))
24280
rconn, rconn0 = self.Pipe()
24281
rp = self.Process(target=self._remote, args=(rconn0,))
24286
@@ -1750,6 +1926,7 @@
24287
string.value = latin('hello')
24289
p = self.Process(target=self._double, args=(x, y, foo, arr, string))
24294
@@ -1822,6 +1999,7 @@
24295
conn, child_conn = self.Pipe()
24297
p = self.Process(target=self._test_finalize, args=(child_conn,))
24302
@@ -1841,10 +2019,12 @@
24303
'multiprocessing', 'multiprocessing.connection',
24304
'multiprocessing.heap', 'multiprocessing.managers',
24305
'multiprocessing.pool', 'multiprocessing.process',
24306
- 'multiprocessing.reduction',
24307
'multiprocessing.synchronize', 'multiprocessing.util'
24310
+ if HAS_REDUCTION:
24311
+ modules.append('multiprocessing.reduction')
24313
if c_int is not None:
24314
# This module requires _ctypes
24315
modules.append('multiprocessing.sharedctypes')
24316
@@ -1891,12 +2071,16 @@
24317
reader, writer = multiprocessing.Pipe(duplex=False)
24319
logger.setLevel(LEVEL1)
24320
- self.Process(target=self._test_level, args=(writer,)).start()
24321
+ p = self.Process(target=self._test_level, args=(writer,))
24324
self.assertEqual(LEVEL1, reader.recv())
24326
logger.setLevel(logging.NOTSET)
24327
root_logger.setLevel(LEVEL2)
24328
- self.Process(target=self._test_level, args=(writer,)).start()
24329
+ p = self.Process(target=self._test_level, args=(writer,))
24332
self.assertEqual(LEVEL2, reader.recv())
24334
root_logger.setLevel(root_level)
24335
@@ -2082,6 +2266,7 @@
24336
def _TestProcess(q):
24337
queue = multiprocessing.Queue()
24338
subProc = multiprocessing.Process(target=_ThisSubProcess, args=(queue,))
24339
+ subProc.daemon = True
24343
@@ -2148,6 +2333,8 @@
24345
raise unittest.SkipTest("OSError raises on RLock creation, see issue 3111!")
24347
+ check_enough_semaphores()
24350
from test.support import run_unittest as run
24352
diff -r 137e45f15c0b Lib/test/test_nntplib.py
24353
--- a/Lib/test/test_nntplib.py
24354
+++ b/Lib/test/test_nntplib.py
24359
-import collections
24360
from test import support
24361
from nntplib import NNTP, GroupInfo, _have_ssl
24363
@@ -246,7 +245,7 @@
24364
if not name.startswith('test_'):
24366
meth = getattr(cls, name)
24367
- if not isinstance(meth, collections.Callable):
24368
+ if not callable(meth):
24370
# Need to use a closure so that meth remains bound to its current
24372
@@ -365,6 +364,12 @@
24376
+class MockedNNTPWithReaderModeMixin(MockedNNTPTestsMixin):
24379
+ self.make_server(readermode=True)
24382
class NNTPv1Handler:
24383
"""A handler for RFC 977"""
24385
@@ -375,6 +380,8 @@
24386
self.allow_posting = True
24387
self._readline = readline
24388
self._push_data = push_data
24389
+ self._logged_in = False
24390
+ self._user_sent = False
24392
self.handle_welcome()
24394
@@ -667,27 +674,87 @@
24395
self.push_lit(self.sample_body)
24398
+ def handle_AUTHINFO(self, cred_type, data):
24399
+ if self._logged_in:
24400
+ self.push_lit('502 Already Logged In')
24401
+ elif cred_type == 'user':
24402
+ if self._user_sent:
24403
+ self.push_lit('482 User Credential Already Sent')
24405
+ self.push_lit('381 Password Required')
24406
+ self._user_sent = True
24407
+ elif cred_type == 'pass':
24408
+ self.push_lit('281 Login Successful')
24409
+ self._logged_in = True
24411
+ raise Exception('Unknown cred type {}'.format(cred_type))
24414
class NNTPv2Handler(NNTPv1Handler):
24415
"""A handler for RFC 3977 (NNTP "v2")"""
24417
def handle_CAPABILITIES(self):
24418
- self.push_lit("""\
24420
101 Capability list:
24422
- IMPLEMENTATION INN 2.5.1
24424
+ IMPLEMENTATION INN 2.5.1{}
24426
LIST ACTIVE ACTIVE.TIMES DISTRIB.PATS HEADERS NEWSGROUPS OVERVIEW.FMT
24433
+ if not self._logged_in:
24434
+ self.push_lit(fmt.format('\n AUTHINFO USER'))
24436
+ self.push_lit(fmt.format(''))
24438
+ def handle_MODE(self, _):
24439
+ raise Exception('MODE READER sent despite READER has been advertised')
24441
def handle_OVER(self, message_spec=None):
24442
return self.handle_XOVER(message_spec)
24445
+class CapsAfterLoginNNTPv2Handler(NNTPv2Handler):
24446
+ """A handler that allows CAPABILITIES only after login"""
24448
+ def handle_CAPABILITIES(self):
24449
+ if not self._logged_in:
24450
+ self.push_lit('480 You must log in.')
24452
+ super().handle_CAPABILITIES()
24455
+class ModeSwitchingNNTPv2Handler(NNTPv2Handler):
24456
+ """A server that starts in transit mode"""
24458
+ def __init__(self):
24459
+ self._switched = False
24461
+ def handle_CAPABILITIES(self):
24463
+ 101 Capability list:
24465
+ IMPLEMENTATION INN 2.5.1
24467
+ LIST ACTIVE ACTIVE.TIMES DISTRIB.PATS HEADERS NEWSGROUPS OVERVIEW.FMT
24472
+ if self._switched:
24473
+ self.push_lit(fmt.format(''))
24475
+ self.push_lit(fmt.format('MODE-'))
24477
+ def handle_MODE(self, what):
24478
+ assert not self._switched and what == 'reader'
24479
+ self._switched = True
24480
+ self.push_lit('200 Posting allowed')
24483
class NNTPv1v2TestsMixin:
24486
@@ -696,6 +763,14 @@
24487
def test_welcome(self):
24488
self.assertEqual(self.server.welcome, self.handler.welcome)
24490
+ def test_authinfo(self):
24491
+ if self.nntp_version == 2:
24492
+ self.assertIn('AUTHINFO', self.server._caps)
24493
+ self.server.login('testuser', 'testpw')
24494
+ # if AUTHINFO is gone from _caps we also know that getcapabilities()
24495
+ # has been called after login as it should
24496
+ self.assertNotIn('AUTHINFO', self.server._caps)
24498
def test_date(self):
24499
resp, date = self.server.date()
24500
self.assertEqual(resp, "111 20100914001155")
24501
@@ -904,6 +979,26 @@
24502
self.server.head("<non-existent@example.com>")
24503
self.assertEqual(cm.exception.response, "430 No Such Article Found")
24505
+ def test_head_file(self):
24507
+ resp, info = self.server.head(file=f)
24508
+ self.assertEqual(resp, "221 3000237 <45223423@example.com>")
24509
+ art_num, message_id, lines = info
24510
+ self.assertEqual(art_num, 3000237)
24511
+ self.assertEqual(message_id, "<45223423@example.com>")
24512
+ self.assertEqual(lines, [])
24513
+ data = f.getvalue()
24514
+ self.assertTrue(data.startswith(
24515
+ b'From: "Demo User" <nobody@example.net>\r\n'
24516
+ b'Subject: I am just a test article\r\n'
24518
+ self.assertFalse(data.endswith(
24519
+ b'This is just a test article.\r\n'
24520
+ b'.Here is a dot-starting line.\r\n'
24522
+ b'-- Signed by Andr\xc3\xa9.\r\n'
24525
def test_body(self):
24527
resp, info = self.server.body()
24528
@@ -931,6 +1026,26 @@
24529
self.server.body("<non-existent@example.com>")
24530
self.assertEqual(cm.exception.response, "430 No Such Article Found")
24532
+ def test_body_file(self):
24534
+ resp, info = self.server.body(file=f)
24535
+ self.assertEqual(resp, "222 3000237 <45223423@example.com>")
24536
+ art_num, message_id, lines = info
24537
+ self.assertEqual(art_num, 3000237)
24538
+ self.assertEqual(message_id, "<45223423@example.com>")
24539
+ self.assertEqual(lines, [])
24540
+ data = f.getvalue()
24541
+ self.assertFalse(data.startswith(
24542
+ b'From: "Demo User" <nobody@example.net>\r\n'
24543
+ b'Subject: I am just a test article\r\n'
24545
+ self.assertTrue(data.endswith(
24546
+ b'This is just a test article.\r\n'
24547
+ b'.Here is a dot-starting line.\r\n'
24549
+ b'-- Signed by Andr\xc3\xa9.\r\n'
24552
def check_over_xover_resp(self, resp, overviews):
24553
self.assertTrue(resp.startswith("224 "), resp)
24554
self.assertEqual(len(overviews), 3)
24555
@@ -1074,6 +1189,30 @@
24556
self.assertEqual(self.server.nntp_implementation, 'INN 2.5.1')
24559
+class CapsAfterLoginNNTPv2Tests(MockedNNTPTestsMixin, unittest.TestCase):
24560
+ """Tests a probably NNTP v2 server with capabilities only after login."""
24563
+ handler_class = CapsAfterLoginNNTPv2Handler
24565
+ def test_caps_only_after_login(self):
24566
+ self.assertEqual(self.server._caps, {})
24567
+ self.server.login('testuser', 'testpw')
24568
+ self.assertIn('VERSION', self.server._caps)
24571
+class SendReaderNNTPv2Tests(MockedNNTPWithReaderModeMixin,
24572
+ unittest.TestCase):
24573
+ """Same tests as for v2 but we tell NTTP to send MODE READER to a server
24574
+ that isn't in READER mode by default."""
24577
+ handler_class = ModeSwitchingNNTPv2Handler
24579
+ def test_we_are_in_reader_mode_after_connect(self):
24580
+ self.assertIn('READER', self.server._caps)
24583
class MiscTests(unittest.TestCase):
24585
def test_decode_header(self):
24586
@@ -1233,7 +1372,8 @@
24590
- tests = [MiscTests, NNTPv1Tests, NNTPv2Tests, NetworkedNNTPTests]
24591
+ tests = [MiscTests, NNTPv1Tests, NNTPv2Tests, CapsAfterLoginNNTPv2Tests,
24592
+ SendReaderNNTPv2Tests, NetworkedNNTPTests]
24594
tests.append(NetworkedNNTP_SSLTests)
24595
support.run_unittest(*tests)
24596
diff -r 137e45f15c0b Lib/test/test_os.py
24597
--- a/Lib/test/test_os.py
24598
+++ b/Lib/test/test_os.py
24599
@@ -423,6 +423,20 @@
24600
value_str = value.decode(sys.getfilesystemencoding(), 'surrogateescape')
24601
self.assertEqual(os.environ['bytes'], value_str)
24603
+ # On FreeBSD < 7 and OS X < 10.6, unsetenv() doesn't return a value (issue
24605
+ @unittest.skipIf(sys.platform.startswith(('freebsd', 'darwin')),
24606
+ "due to known OS bug: see issue #13415")
24607
+ def test_unset_error(self):
24608
+ if sys.platform == "win32":
24609
+ # an environment variable is limited to 32,767 characters
24610
+ key = 'x' * 50000
24611
+ self.assertRaises(ValueError, os.environ.__delitem__, key)
24613
+ # "=" is not allowed in a variable name
24615
+ self.assertRaises(OSError, os.environ.__delitem__, key)
24617
class WalkTests(unittest.TestCase):
24618
"""Tests for os.walk()."""
24620
@@ -462,7 +476,12 @@
24621
f.write("I'm " + path + " and proud of it. Blame test_os.\n")
24623
if support.can_symlink():
24624
- os.symlink(os.path.abspath(t2_path), link_path)
24625
+ if os.name == 'nt':
24626
+ def symlink_to_dir(src, dest):
24627
+ os.symlink(src, dest, True)
24629
+ symlink_to_dir = os.symlink
24630
+ symlink_to_dir(os.path.abspath(t2_path), link_path)
24631
sub2_tree = (sub2_path, ["link"], ["tmp3"])
24633
sub2_tree = (sub2_path, [], ["tmp3"])
24634
@@ -1092,7 +1111,7 @@
24635
os.remove(self.missing_link)
24637
def test_directory_link(self):
24638
- os.symlink(self.dirlink_target, self.dirlink)
24639
+ os.symlink(self.dirlink_target, self.dirlink, True)
24640
self.assertTrue(os.path.exists(self.dirlink))
24641
self.assertTrue(os.path.isdir(self.dirlink))
24642
self.assertTrue(os.path.islink(self.dirlink))
24643
diff -r 137e45f15c0b Lib/test/test_pep3120.py
24644
--- a/Lib/test/test_pep3120.py
24645
+++ b/Lib/test/test_pep3120.py
24648
import test.badsyntax_pep3120
24649
except SyntaxError as msg:
24651
- self.assertTrue('UTF-8' in msg or 'utf8' in msg)
24652
+ msg = str(msg).lower()
24653
+ self.assertTrue('utf-8' in msg)
24655
self.fail("expected exception didn't occur")
24657
diff -r 137e45f15c0b Lib/test/test_pickle.py
24658
--- a/Lib/test/test_pickle.py
24659
+++ b/Lib/test/test_pickle.py
24661
from test.pickletester import AbstractPickleModuleTests
24662
from test.pickletester import AbstractPersistentPicklerTests
24663
from test.pickletester import AbstractPicklerUnpicklerObjectTests
24664
+from test.pickletester import BigmemPickleTests
24668
@@ -37,13 +38,13 @@
24672
-class InMemoryPickleTests(AbstractPickleTests):
24673
+class InMemoryPickleTests(AbstractPickleTests, BigmemPickleTests):
24675
pickler = pickle._Pickler
24676
unpickler = pickle._Unpickler
24678
- def dumps(self, arg, proto=None):
24679
- return pickle.dumps(arg, proto)
24680
+ def dumps(self, arg, protocol=None):
24681
+ return pickle.dumps(arg, protocol)
24683
def loads(self, buf, **kwds):
24684
return pickle.loads(buf, **kwds)
24685
diff -r 137e45f15c0b Lib/test/test_pkgutil.py
24686
--- a/Lib/test/test_pkgutil.py
24687
+++ b/Lib/test/test_pkgutil.py
24688
@@ -15,11 +15,11 @@
24691
self.dirname = tempfile.mkdtemp()
24692
+ self.addCleanup(shutil.rmtree, self.dirname)
24693
sys.path.insert(0, self.dirname)
24695
def tearDown(self):
24697
- shutil.rmtree(self.dirname)
24699
def test_getdata_filesys(self):
24700
pkg = 'test_getdata_filesys'
24703
del sys.modules[pkg]
24705
+ def test_unreadable_dir_on_syspath(self):
24706
+ # issue7367 - walk_packages failed if unreadable dir on sys.path
24707
+ package_name = "unreadable_package"
24708
+ d = os.path.join(self.dirname, package_name)
24709
+ # this does not appear to create an unreadable dir on Windows
24710
+ # but the test should not fail anyway
24712
+ self.addCleanup(os.rmdir, d)
24713
+ for t in pkgutil.walk_packages(path=[self.dirname]):
24714
+ self.fail("unexpected package found")
24716
class PkgutilPEP302Tests(unittest.TestCase):
24718
class MyTestLoader(object):
24719
diff -r 137e45f15c0b Lib/test/test_poplib.py
24720
--- a/Lib/test/test_poplib.py
24721
+++ b/Lib/test/test_poplib.py
24722
@@ -309,32 +309,34 @@
24724
self.evt = threading.Event()
24725
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
24726
- self.sock.settimeout(3)
24727
+ self.sock.settimeout(60) # Safety net. Look issue 11812
24728
self.port = test_support.bind_port(self.sock)
24729
- threading.Thread(target=self.server, args=(self.evt,self.sock)).start()
24731
+ self.thread = threading.Thread(target=self.server, args=(self.evt,self.sock))
24732
+ self.thread.setDaemon(True)
24733
+ self.thread.start()
24736
def tearDown(self):
24738
+ self.thread.join()
24739
+ del self.thread # Clear out any dangling Thread objects.
24741
def server(self, evt, serv):
24745
conn, addr = serv.accept()
24746
+ conn.send(b"+ Hola mundo\n")
24748
except socket.timeout:
24751
- conn.send(b"+ Hola mundo\n")
24757
def testTimeoutDefault(self):
24758
self.assertTrue(socket.getdefaulttimeout() is None)
24759
socket.setdefaulttimeout(30)
24761
- pop = poplib.POP3("localhost", self.port)
24762
+ pop = poplib.POP3(HOST, self.port)
24764
socket.setdefaulttimeout(None)
24765
self.assertEqual(pop.sock.gettimeout(), 30)
24766
@@ -351,7 +353,7 @@
24769
def testTimeoutValue(self):
24770
- pop = poplib.POP3("localhost", self.port, timeout=30)
24771
+ pop = poplib.POP3(HOST, self.port, timeout=30)
24772
self.assertEqual(pop.sock.gettimeout(), 30)
24775
diff -r 137e45f15c0b Lib/test/test_pty.py
24776
--- a/Lib/test/test_pty.py
24777
+++ b/Lib/test/test_pty.py
2063
@@ -350,13 +350,31 @@
2064
def testGetAttrList(self):
2067
- def testGetAttrValues(self): pass
2068
+ def testGetAttrValues(self):
2071
- def testGetAttrLength(self): pass
2072
+ def testGetAttrLength(self):
2075
- def testGetAttribute(self): pass
2076
+ def testGetAttribute(self):
2078
+ child = dom.appendChild(
2079
+ dom.createElementNS("http://www.python.org", "python:abc"))
2080
+ self.assertEqual(child.getAttribute('missing'), '')
2082
- def testGetAttributeNS(self): pass
2083
+ def testGetAttributeNS(self):
2085
+ child = dom.appendChild(
2086
+ dom.createElementNS("http://www.python.org", "python:abc"))
2087
+ child.setAttributeNS("http://www.w3.org", "xmlns:python",
2088
+ "http://www.python.org")
2089
+ self.assertEqual(child.getAttributeNS("http://www.w3.org", "python"),
2090
+ 'http://www.python.org')
2091
+ self.assertEqual(child.getAttributeNS("http://www.w3.org", "other"),
2093
+ child2 = child.appendChild(dom.createElement('abc'))
2094
+ self.assertEqual(child2.getAttributeNS("http://www.python.org", "missing"),
2097
def testGetAttributeNode(self): pass
2099
diff -r 7085403daf43 Lib/test/test_re.py
2100
--- a/Lib/test/test_re.py
2101
+++ b/Lib/test/test_re.py
2103
-from test.support import verbose, run_unittest
2104
+from test.support import verbose, run_unittest, gc_collect
2107
from re import Scanner
24787
TEST_STRING_1 = b"I wish to buy a fish license.\n"
24788
@@ -194,9 +196,96 @@
24790
# pty.fork() passed.
24793
+class SmallPtyTests(unittest.TestCase):
24794
+ """These tests don't spawn children or hang."""
24797
+ self.orig_stdin_fileno = pty.STDIN_FILENO
24798
+ self.orig_stdout_fileno = pty.STDOUT_FILENO
24799
+ self.orig_pty_select = pty.select
24800
+ self.fds = [] # A list of file descriptors to close.
24801
+ self.select_rfds_lengths = []
24802
+ self.select_rfds_results = []
24804
+ def tearDown(self):
24805
+ pty.STDIN_FILENO = self.orig_stdin_fileno
24806
+ pty.STDOUT_FILENO = self.orig_stdout_fileno
24807
+ pty.select = self.orig_pty_select
24808
+ for fd in self.fds:
24815
+ pipe_fds = os.pipe()
24816
+ self.fds.extend(pipe_fds)
24819
+ def _mock_select(self, rfds, wfds, xfds):
24820
+ # This will raise IndexError when no more expected calls exist.
24821
+ self.assertEqual(self.select_rfds_lengths.pop(0), len(rfds))
24822
+ return self.select_rfds_results.pop(0), [], []
24824
+ def test__copy_to_each(self):
24825
+ """Test the normal data case on both master_fd and stdin."""
24826
+ read_from_stdout_fd, mock_stdout_fd = self._pipe()
24827
+ pty.STDOUT_FILENO = mock_stdout_fd
24828
+ mock_stdin_fd, write_to_stdin_fd = self._pipe()
24829
+ pty.STDIN_FILENO = mock_stdin_fd
24830
+ socketpair = socket.socketpair()
24831
+ masters = [s.fileno() for s in socketpair]
24832
+ self.fds.extend(masters)
24834
+ # Feed data. Smaller than PIPEBUF. These writes will not block.
24835
+ os.write(masters[1], b'from master')
24836
+ os.write(write_to_stdin_fd, b'from stdin')
24838
+ # Expect two select calls, the last one will cause IndexError
24839
+ pty.select = self._mock_select
24840
+ self.select_rfds_lengths.append(2)
24841
+ self.select_rfds_results.append([mock_stdin_fd, masters[0]])
24842
+ self.select_rfds_lengths.append(2)
24844
+ with self.assertRaises(IndexError):
24845
+ pty._copy(masters[0])
24847
+ # Test that the right data went to the right places.
24848
+ rfds = select.select([read_from_stdout_fd, masters[1]], [], [], 0)[0]
24849
+ self.assertEqual([read_from_stdout_fd, masters[1]], rfds)
24850
+ self.assertEqual(os.read(read_from_stdout_fd, 20), b'from master')
24851
+ self.assertEqual(os.read(masters[1], 20), b'from stdin')
24853
+ def test__copy_eof_on_all(self):
24854
+ """Test the empty read EOF case on both master_fd and stdin."""
24855
+ read_from_stdout_fd, mock_stdout_fd = self._pipe()
24856
+ pty.STDOUT_FILENO = mock_stdout_fd
24857
+ mock_stdin_fd, write_to_stdin_fd = self._pipe()
24858
+ pty.STDIN_FILENO = mock_stdin_fd
24859
+ socketpair = socket.socketpair()
24860
+ masters = [s.fileno() for s in socketpair]
24861
+ self.fds.extend(masters)
24863
+ os.close(masters[1])
24864
+ socketpair[1].close()
24865
+ os.close(write_to_stdin_fd)
24867
+ # Expect two select calls, the last one will cause IndexError
24868
+ pty.select = self._mock_select
24869
+ self.select_rfds_lengths.append(2)
24870
+ self.select_rfds_results.append([mock_stdin_fd, masters[0]])
24871
+ # We expect that both fds were removed from the fds list as they
24872
+ # both encountered an EOF before the second select call.
24873
+ self.select_rfds_lengths.append(0)
24875
+ with self.assertRaises(IndexError):
24876
+ pty._copy(masters[0])
24879
def test_main(verbose=None):
24881
- run_unittest(PtyTest)
24882
+ run_unittest(SmallPtyTests, PtyTest)
24886
diff -r 137e45f15c0b Lib/test/test_py_compile.py
2111
class ReTests(unittest.TestCase):
2113
+ def test_keep_buffer(self):
2115
+ b = bytearray(b'x')
2116
+ it = re.finditer(b'a', b)
2117
+ with self.assertRaises(BufferError):
2118
+ b.extend(b'x'*400)
2122
+ b.extend(b'x'*400)
2124
def test_weakref(self):
2126
x = re.compile('ab+c')
2127
@@ -355,6 +367,32 @@
2128
self.assertEqual(re.search(r"\d\D\w\W\s\S",
2129
"1aa! a", re.UNICODE).group(0), "1aa! a")
2131
+ def test_string_boundaries(self):
2132
+ # See http://bugs.python.org/issue10713
2133
+ self.assertEqual(re.search(r"\b(abc)\b", "abc").group(1),
2135
+ # There's a word boundary at the start of a string.
2136
+ self.assertTrue(re.match(r"\b", "abc"))
2137
+ # A non-empty string includes a non-boundary zero-length match.
2138
+ self.assertTrue(re.search(r"\B", "abc"))
2139
+ # There is no non-boundary match at the start of a string.
2140
+ self.assertFalse(re.match(r"\B", "abc"))
2141
+ # However, an empty string contains no word boundaries, and also no
2143
+ self.assertEqual(re.search(r"\B", ""), None)
2144
+ # This one is questionable and different from the perlre behaviour,
2145
+ # but describes current behavior.
2146
+ self.assertEqual(re.search(r"\b", ""), None)
2147
+ # A single word-character string has two boundaries, but no
2148
+ # non-boundary gaps.
2149
+ self.assertEqual(len(re.findall(r"\b", "a")), 2)
2150
+ self.assertEqual(len(re.findall(r"\B", "a")), 0)
2151
+ # If there are no words, there are no boundaries
2152
+ self.assertEqual(len(re.findall(r"\b", " ")), 0)
2153
+ self.assertEqual(len(re.findall(r"\b", " ")), 0)
2154
+ # Can match around the whitespace.
2155
+ self.assertEqual(len(re.findall(r"\B", " ")), 2)
2157
def test_bigcharset(self):
2158
self.assertEqual(re.match("([\u2222\u2223])",
2159
"\u2222").group(1), "\u2222")
2160
diff -r 7085403daf43 Lib/test/test_strptime.py
2161
--- a/Lib/test/test_strptime.py
2162
+++ b/Lib/test/test_strptime.py
2164
comparison = testing[self.time_tuple[tuple_position]]
2165
self.assertIn(strftime_output, testing,
2166
"%s: not found in tuple" % error_msg)
2167
- self.assertTrue(comparison == strftime_output,
2168
- "%s: position within tuple incorrect; %s != %s" %
2169
- (error_msg, comparison, strftime_output))
2170
+ self.assertEqual(comparison, strftime_output,
2171
+ "%s: position within tuple incorrect; %s != %s" %
2172
+ (error_msg, comparison, strftime_output))
2174
def test_weekday(self):
2175
# Make sure that full and abbreviated weekday names are correct in
2177
"AM/PM representation not in tuple")
2178
if self.time_tuple[3] < 12: position = 0
2180
- self.assertTrue(strftime_output == self.LT_ins.am_pm[position],
2181
- "AM/PM representation in the wrong position within the tuple")
2182
+ self.assertEqual(self.LT_ins.am_pm[position], strftime_output,
2183
+ "AM/PM representation in the wrong position within the tuple")
2185
def test_timezone(self):
2186
# Make sure timezone is correct
2189
magic_date = (1999, 3, 17, 22, 44, 55, 2, 76, 0)
2190
strftime_output = time.strftime("%c", magic_date)
2191
- self.assertTrue(strftime_output == time.strftime(self.LT_ins.LC_date_time,
2193
- "LC_date_time incorrect")
2194
+ self.assertEqual(time.strftime(self.LT_ins.LC_date_time, magic_date),
2195
+ strftime_output, "LC_date_time incorrect")
2196
strftime_output = time.strftime("%x", magic_date)
2197
- self.assertTrue(strftime_output == time.strftime(self.LT_ins.LC_date,
2199
- "LC_date incorrect")
2200
+ self.assertEqual(time.strftime(self.LT_ins.LC_date, magic_date),
2201
+ strftime_output, "LC_date incorrect")
2202
strftime_output = time.strftime("%X", magic_date)
2203
- self.assertTrue(strftime_output == time.strftime(self.LT_ins.LC_time,
2205
- "LC_time incorrect")
2206
+ self.assertEqual(time.strftime(self.LT_ins.LC_time, magic_date),
2207
+ strftime_output, "LC_time incorrect")
2208
LT = _strptime.LocaleTime()
2210
self.assertTrue(LT.LC_time, "LocaleTime's LC directives cannot handle "
2213
test_locale = _strptime.LocaleTime()
2214
test_locale.timezone = (frozenset(), frozenset())
2215
- self.assertTrue(_strptime.TimeRE(test_locale).pattern("%Z") == '',
2216
- "with timezone == ('',''), TimeRE().pattern('%Z') != ''")
2217
+ self.assertEqual(_strptime.TimeRE(test_locale).pattern("%Z"), '',
2218
+ "with timezone == ('',''), TimeRE().pattern('%Z') != ''")
2220
def test_matching_with_escapes(self):
2221
# Make sure a format that requires escaping of characters works
2223
# so as to not allow to subpatterns to end up next to each other and
2224
# "steal" characters from each other.
2225
pattern = self.time_re.pattern('%j %H')
2226
- self.assertTrue(not re.match(pattern, "180"))
2227
+ self.assertFalse(re.match(pattern, "180"))
2228
self.assertTrue(re.match(pattern, "18 0"))
2231
diff -r 7085403daf43 Lib/test/test_tools.py
24888
+++ b/Lib/test/test_py_compile.py
2233
+++ b/Lib/test/test_tools.py
2235
+"""Tests for scripts in the Tools directory.
2237
+This file contains regression tests for some of the scripts found in the
2238
+Tools directory of a Python checkout or tarball, such as reindent.py.
24895
2242
+import unittest
24897
+from test import support, script_helper
24899
+class PyCompileTests(unittest.TestCase):
24902
+ self.directory = tempfile.mkdtemp()
24903
+ self.source_path = os.path.join(self.directory, '_test.py')
24904
+ self.pyc_path = self.source_path + 'c'
24905
+ self.cache_path = imp.cache_from_source(self.source_path)
24906
+ self.cwd_drive = os.path.splitdrive(os.getcwd())[0]
24907
+ # In these tests we compute relative paths. When using Windows, the
24908
+ # current working directory path and the 'self.source_path' might be
24909
+ # on different drives. Therefore we need to switch to the drive where
24910
+ # the temporary source file lives.
24911
+ drive = os.path.splitdrive(self.source_path)[0]
24914
+ with open(self.source_path, 'w') as file:
24915
+ file.write('x = 123\n')
24917
+ def tearDown(self):
24918
+ shutil.rmtree(self.directory)
24919
+ if self.cwd_drive:
24920
+ os.chdir(self.cwd_drive)
24922
+ def test_absolute_path(self):
24923
+ py_compile.compile(self.source_path, self.pyc_path)
24924
+ self.assertTrue(os.path.exists(self.pyc_path))
24925
+ self.assertFalse(os.path.exists(self.cache_path))
24927
+ def test_cache_path(self):
24928
+ py_compile.compile(self.source_path)
24929
+ self.assertTrue(os.path.exists(self.cache_path))
24931
+ def test_cwd(self):
24932
+ cwd = os.getcwd()
24933
+ os.chdir(self.directory)
24934
+ py_compile.compile(os.path.basename(self.source_path),
24935
+ os.path.basename(self.pyc_path))
24937
+ self.assertTrue(os.path.exists(self.pyc_path))
24938
+ self.assertFalse(os.path.exists(self.cache_path))
24940
+ def test_relative_path(self):
24941
+ py_compile.compile(os.path.relpath(self.source_path),
24942
+ os.path.relpath(self.pyc_path))
24943
+ self.assertTrue(os.path.exists(self.pyc_path))
24944
+ self.assertFalse(os.path.exists(self.cache_path))
24947
+ support.run_unittest(PyCompileTests)
24949
+if __name__ == "__main__":
24951
diff -r 137e45f15c0b Lib/test/test_pydoc.py
24952
--- a/Lib/test/test_pydoc.py
24953
+++ b/Lib/test/test_pydoc.py
24959
import test.support
24964
from io import StringIO
24965
from collections import namedtuple
24966
-from contextlib import contextmanager
24968
from test.script_helper import assert_python_ok
24969
from test.support import (
24970
- TESTFN, forget, rmtree, EnvironmentVarGuard,
24972
reap_children, reap_threads, captured_output, captured_stdout, unlink
24974
from test import pydoc_mod
24975
@@ -209,7 +206,8 @@
24978
args = args + (module_name,)
24979
- rc, out, err = assert_python_ok(pydoc.__file__, *args, **env)
24980
+ # do not write bytecode files to avoid caching errors
24981
+ rc, out, err = assert_python_ok('-B', pydoc.__file__, *args, **env)
24984
def get_pydoc_html(module):
24985
@@ -291,43 +289,6 @@
24986
self.assertEqual(expected, result,
24987
"documentation for missing module found")
24989
- def test_badimport(self):
24990
- # This tests the fix for issue 5230, where if pydoc found the module
24991
- # but the module had an internal import error pydoc would report no doc
24993
- modname = 'testmod_xyzzy'
24995
- ('i_am_not_here', 'i_am_not_here'),
24996
- ('test.i_am_not_here_either', 'i_am_not_here_either'),
24997
- ('test.i_am_not_here.neither_am_i', 'i_am_not_here.neither_am_i'),
24998
- ('i_am_not_here.{}'.format(modname),
24999
- 'i_am_not_here.{}'.format(modname)),
25000
- ('test.{}'.format(modname), modname),
25004
- def newdirinpath(dir):
25006
- sys.path.insert(0, dir)
25013
- with newdirinpath(TESTFN):
25014
- fullmodname = os.path.join(TESTFN, modname)
25015
- sourcefn = fullmodname + os.extsep + "py"
25016
- for importstring, expectedinmsg in testpairs:
25017
- with open(sourcefn, 'w') as f:
25018
- f.write("import {}\n".format(importstring))
25020
- result = run_pydoc(modname, PYTHONPATH=TESTFN).decode("ascii")
25023
- expected = badimport_pattern % (modname, expectedinmsg)
25024
- self.assertEqual(expected, result)
25026
def test_input_strip(self):
25027
missing_module = " test.i_am_not_here "
25028
result = str(run_pydoc(missing_module), 'ascii')
25029
@@ -403,6 +364,55 @@
25030
self.assertEqual(synopsis, 'line 1: h\xe9')
25033
+class PydocImportTest(unittest.TestCase):
25036
+ self.test_dir = os.mkdir(TESTFN)
25037
+ self.addCleanup(rmtree, TESTFN)
25039
+ def test_badimport(self):
25040
+ # This tests the fix for issue 5230, where if pydoc found the module
25041
+ # but the module had an internal import error pydoc would report no doc
25043
+ modname = 'testmod_xyzzy'
25045
+ ('i_am_not_here', 'i_am_not_here'),
25046
+ ('test.i_am_not_here_either', 'i_am_not_here_either'),
25047
+ ('test.i_am_not_here.neither_am_i', 'i_am_not_here.neither_am_i'),
25048
+ ('i_am_not_here.{}'.format(modname),
25049
+ 'i_am_not_here.{}'.format(modname)),
25050
+ ('test.{}'.format(modname), modname),
25053
+ sourcefn = os.path.join(TESTFN, modname) + os.extsep + "py"
25054
+ for importstring, expectedinmsg in testpairs:
25055
+ with open(sourcefn, 'w') as f:
25056
+ f.write("import {}\n".format(importstring))
25057
+ result = run_pydoc(modname, PYTHONPATH=TESTFN).decode("ascii")
25058
+ expected = badimport_pattern % (modname, expectedinmsg)
25059
+ self.assertEqual(expected, result)
25061
+ def test_apropos_with_bad_package(self):
25062
+ # Issue 7425 - pydoc -k failed when bad package on path
25063
+ pkgdir = os.path.join(TESTFN, "syntaxerr")
25065
+ badsyntax = os.path.join(pkgdir, "__init__") + os.extsep + "py"
25066
+ with open(badsyntax, 'w') as f:
25067
+ f.write("invalid python syntax = $1\n")
25068
+ result = run_pydoc('zqwykjv', '-k', PYTHONPATH=TESTFN)
25069
+ self.assertEqual(b'', result)
25071
+ def test_apropos_with_unreadable_dir(self):
25072
+ # Issue 7367 - pydoc -k failed when unreadable dir on path
25073
+ self.unreadable_dir = os.path.join(TESTFN, "unreadable")
25074
+ os.mkdir(self.unreadable_dir, 0)
25075
+ self.addCleanup(os.rmdir, self.unreadable_dir)
25076
+ # Note, on Windows the directory appears to be still
25077
+ # readable so this is not really testing the issue there
25078
+ result = run_pydoc('zqwykjv', '-k', PYTHONPATH=TESTFN)
25079
+ self.assertEqual(b'', result)
25082
class TestDescriptions(unittest.TestCase):
25084
def test_module(self):
25085
@@ -511,6 +521,7 @@
25088
test.support.run_unittest(PydocDocTest,
25092
PydocUrlHandlerTest,
25093
diff -r 137e45f15c0b Lib/test/test_site.py
25094
--- a/Lib/test/test_site.py
25095
+++ b/Lib/test/test_site.py
25098
raise unittest.SkipTest("importation of site.py suppressed")
25100
-if not os.path.isdir(site.USER_SITE):
25101
+if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE):
25102
# need to add user site directory for tests
25103
os.makedirs(site.USER_SITE)
25104
site.addsitedir(site.USER_SITE)
25105
@@ -157,6 +157,8 @@
25109
+ @unittest.skipUnless(site.ENABLE_USER_SITE, "requires access to PEP 370 "
25110
+ "user-site (site.ENABLE_USER_SITE)")
25111
def test_s_option(self):
25112
usersite = site.USER_SITE
25113
self.assertIn(usersite, sys.path)
25114
@@ -221,7 +223,19 @@
25115
self.assertEqual(len(dirs), 1)
25116
wanted = os.path.join('xoxo', 'Lib', 'site-packages')
25117
self.assertEqual(dirs[0], wanted)
25118
+ elif (sys.platform == "darwin" and
25119
+ sysconfig.get_config_var("PYTHONFRAMEWORK")):
25120
+ # OS X framework builds
25121
+ site.PREFIXES = ['Python.framework']
25122
+ dirs = site.getsitepackages()
25123
+ self.assertEqual(len(dirs), 3)
25124
+ wanted = os.path.join('/Library',
25125
+ sysconfig.get_config_var("PYTHONFRAMEWORK"),
25128
+ self.assertEqual(dirs[2], wanted)
25129
elif os.sep == '/':
25130
+ # OS X non-framwework builds, Linux, FreeBSD, etc
25131
self.assertEqual(len(dirs), 2)
25132
wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
25134
@@ -229,21 +243,12 @@
25135
wanted = os.path.join('xoxo', 'lib', 'site-python')
25136
self.assertEqual(dirs[1], wanted)
25138
+ # other platforms
25139
self.assertEqual(len(dirs), 2)
25140
self.assertEqual(dirs[0], 'xoxo')
25141
wanted = os.path.join('xoxo', 'lib', 'site-packages')
25142
self.assertEqual(dirs[1], wanted)
25144
- # let's try the specific Apple location
25145
- if (sys.platform == "darwin" and
25146
- sysconfig.get_config_var("PYTHONFRAMEWORK")):
25147
- site.PREFIXES = ['Python.framework']
25148
- dirs = site.getsitepackages()
25149
- self.assertEqual(len(dirs), 3)
25150
- wanted = os.path.join('/Library', 'Python', sys.version[:3],
25152
- self.assertEqual(dirs[2], wanted)
25154
class PthFile(object):
25155
"""Helper class for handling testing of .pth files"""
25157
diff -r 137e45f15c0b Lib/test/test_smtpd.py
25158
--- a/Lib/test/test_smtpd.py
25159
+++ b/Lib/test/test_smtpd.py
25161
class SMTPDChannelTest(TestCase):
25163
smtpd.socket = asyncore.socket = mock_socket
25164
+ self.old_debugstream = smtpd.DEBUGSTREAM
25165
self.debug = smtpd.DEBUGSTREAM = io.StringIO()
25166
self.server = DummyServer('a', 'b')
25167
conn, addr = self.server.accept()
25169
def tearDown(self):
25170
asyncore.close_all()
25171
asyncore.socket = smtpd.socket = socket
25172
+ smtpd.DEBUGSTREAM = self.old_debugstream
25174
def write_line(self, line):
25175
self.channel.socket.queue_recv(line)
25176
diff -r 137e45f15c0b Lib/test/test_smtplib.py
25177
--- a/Lib/test/test_smtplib.py
25178
+++ b/Lib/test/test_smtplib.py
25179
@@ -169,7 +169,6 @@
25180
self.output = io.StringIO()
25181
sys.stdout = self.output
25183
- self._threads = support.threading_setup()
25184
self.serv_evt = threading.Event()
25185
self.client_evt = threading.Event()
25186
# Capture SMTPChannel debug output
25187
@@ -194,7 +193,6 @@
25188
# wait for the server thread to terminate
25189
self.serv_evt.wait()
25191
- support.threading_cleanup(*self._threads)
25192
# restore sys.stdout
25193
sys.stdout = self.old_stdout
25194
# restore DEBUGSTREAM
25195
@@ -644,7 +642,6 @@
25197
self.real_getfqdn = socket.getfqdn
25198
socket.getfqdn = mock_socket.getfqdn
25199
- self._threads = support.threading_setup()
25200
self.serv_evt = threading.Event()
25201
self.client_evt = threading.Event()
25202
# Pick a random unused port by passing 0 for the port number
25203
@@ -666,7 +663,6 @@
25204
# wait for the server thread to terminate
25205
self.serv_evt.wait()
25207
- support.threading_cleanup(*self._threads)
25209
def testBasic(self):
25211
@@ -760,6 +756,7 @@
25212
#test infrastructure can support it.
25215
+@support.reap_threads
25216
def test_main(verbose=None):
25217
support.run_unittest(GeneralTests, DebuggingServerTests,
25218
NonConnectingTests,
25219
diff -r 137e45f15c0b Lib/test/test_socket.py
25220
--- a/Lib/test/test_socket.py
25221
+++ b/Lib/test/test_socket.py
25222
@@ -156,8 +156,8 @@
25224
def clientRun(self, test_func):
25225
self.server_ready.wait()
25226
+ self.clientSetUp()
25227
self.client_ready.set()
25228
- self.clientSetUp()
25229
if not hasattr(test_func, '__call__'):
25230
raise TypeError("test_func must be a callable function")
25232
@@ -499,16 +499,30 @@
25233
from socket import inet_aton as f, inet_pton, AF_INET
25234
g = lambda a: inet_pton(AF_INET, a)
25236
+ assertInvalid = lambda func,a: self.assertRaises(
25237
+ (socket.error, ValueError), func, a
25240
self.assertEqual(b'\x00\x00\x00\x00', f('0.0.0.0'))
25241
self.assertEqual(b'\xff\x00\xff\x00', f('255.0.255.0'))
25242
self.assertEqual(b'\xaa\xaa\xaa\xaa', f('170.170.170.170'))
25243
self.assertEqual(b'\x01\x02\x03\x04', f('1.2.3.4'))
25244
self.assertEqual(b'\xff\xff\xff\xff', f('255.255.255.255'))
25245
+ assertInvalid(f, '0.0.0.')
25246
+ assertInvalid(f, '300.0.0.0')
25247
+ assertInvalid(f, 'a.0.0.0')
25248
+ assertInvalid(f, '1.2.3.4.5')
25249
+ assertInvalid(f, '::1')
25251
self.assertEqual(b'\x00\x00\x00\x00', g('0.0.0.0'))
25252
self.assertEqual(b'\xff\x00\xff\x00', g('255.0.255.0'))
25253
self.assertEqual(b'\xaa\xaa\xaa\xaa', g('170.170.170.170'))
25254
self.assertEqual(b'\xff\xff\xff\xff', g('255.255.255.255'))
25255
+ assertInvalid(g, '0.0.0.')
25256
+ assertInvalid(g, '300.0.0.0')
25257
+ assertInvalid(g, 'a.0.0.0')
25258
+ assertInvalid(g, '1.2.3.4.5')
25259
+ assertInvalid(g, '::1')
25261
def testIPv6toString(self):
25262
if not hasattr(socket, 'inet_pton'):
25263
@@ -520,6 +534,9 @@
25264
except ImportError:
25266
f = lambda a: inet_pton(AF_INET6, a)
25267
+ assertInvalid = lambda a: self.assertRaises(
25268
+ (socket.error, ValueError), f, a
25271
self.assertEqual(b'\x00' * 16, f('::'))
25272
self.assertEqual(b'\x00' * 16, f('0::0'))
25273
@@ -528,21 +545,62 @@
25274
b'\x45\xef\x76\xcb\x00\x1a\x56\xef\xaf\xeb\x0b\xac\x19\x24\xae\xae',
25275
f('45ef:76cb:1a:56ef:afeb:bac:1924:aeae')
25277
+ self.assertEqual(
25278
+ b'\xad\x42\x0a\xbc' + b'\x00' * 4 + b'\x01\x27\x00\x00\x02\x54\x00\x02',
25279
+ f('ad42:abc::127:0:254:2')
25281
+ self.assertEqual(b'\x00\x12\x00\x0a' + b'\x00' * 12, f('12:a::'))
25282
+ assertInvalid('0x20::')
25283
+ assertInvalid(':::')
25284
+ assertInvalid('::0::')
25285
+ assertInvalid('1::abc::')
25286
+ assertInvalid('1::abc::def')
25287
+ assertInvalid('1:2:3:4:5:6:')
25288
+ assertInvalid('1:2:3:4:5:6')
25289
+ assertInvalid('1:2:3:4:5:6:7:8:')
25290
+ assertInvalid('1:2:3:4:5:6:7:8:0')
25292
+ self.assertEqual(b'\x00' * 12 + b'\xfe\x2a\x17\x40',
25293
+ f('::254.42.23.64')
25295
+ self.assertEqual(
25296
+ b'\x00\x42' + b'\x00' * 8 + b'\xa2\x9b\xfe\x2a\x17\x40',
25297
+ f('42::a29b:254.42.23.64')
25299
+ self.assertEqual(
25300
+ b'\x00\x42\xa8\xb9\x00\x00\x00\x02\xff\xff\xa2\x9b\xfe\x2a\x17\x40',
25301
+ f('42:a8b9:0:2:ffff:a29b:254.42.23.64')
25303
+ assertInvalid('255.254.253.252')
25304
+ assertInvalid('1::260.2.3.0')
25305
+ assertInvalid('1::0.be.e.0')
25306
+ assertInvalid('1:2:3:4:5:6:7:1.2.3.4')
25307
+ assertInvalid('::1.2.3.4:0')
25308
+ assertInvalid('0.100.200.0:3:4:5:6:7:8')
25310
def testStringToIPv4(self):
25311
if not hasattr(socket, 'inet_ntop'):
25312
return # No inet_ntop() on this platform
25313
from socket import inet_ntoa as f, inet_ntop, AF_INET
25314
g = lambda a: inet_ntop(AF_INET, a)
25315
+ assertInvalid = lambda func,a: self.assertRaises(
25316
+ (socket.error, ValueError), func, a
25319
self.assertEqual('1.0.1.0', f(b'\x01\x00\x01\x00'))
25320
self.assertEqual('170.85.170.85', f(b'\xaa\x55\xaa\x55'))
25321
self.assertEqual('255.255.255.255', f(b'\xff\xff\xff\xff'))
25322
self.assertEqual('1.2.3.4', f(b'\x01\x02\x03\x04'))
25323
+ assertInvalid(f, b'\x00' * 3)
25324
+ assertInvalid(f, b'\x00' * 5)
25325
+ assertInvalid(f, b'\x00' * 16)
25327
self.assertEqual('1.0.1.0', g(b'\x01\x00\x01\x00'))
25328
self.assertEqual('170.85.170.85', g(b'\xaa\x55\xaa\x55'))
25329
self.assertEqual('255.255.255.255', g(b'\xff\xff\xff\xff'))
25330
+ assertInvalid(g, b'\x00' * 3)
25331
+ assertInvalid(g, b'\x00' * 5)
25332
+ assertInvalid(g, b'\x00' * 16)
25334
def testStringToIPv6(self):
25335
if not hasattr(socket, 'inet_ntop'):
25336
@@ -554,6 +612,9 @@
25337
except ImportError:
25339
f = lambda a: inet_ntop(AF_INET6, a)
25340
+ assertInvalid = lambda a: self.assertRaises(
25341
+ (socket.error, ValueError), f, a
25344
self.assertEqual('::', f(b'\x00' * 16))
25345
self.assertEqual('::1', f(b'\x00' * 15 + b'\x01'))
25346
@@ -562,6 +623,10 @@
25347
f(b'\x0a\xef\x0b\x01\x05\x06\x10\x01\xff\xff\x99\x97\x00\x55\x01\x70')
25350
+ assertInvalid(b'\x12' * 15)
25351
+ assertInvalid(b'\x12' * 17)
25352
+ assertInvalid(b'\x12' * 4)
25354
# XXX The following don't test module-level functionality...
25356
def testSockName(self):
25357
@@ -781,6 +846,13 @@
25361
+ @unittest.skipUnless(SUPPORTS_IPV6, 'IPv6 required for this test.')
25362
+ def test_flowinfo(self):
25363
+ self.assertRaises(OverflowError, socket.getnameinfo,
25364
+ ('::1',0, 0xffffffff), 0)
25365
+ with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
25366
+ self.assertRaises(OverflowError, s.bind, ('::1', 0, -10))
25369
@unittest.skipUnless(thread, 'Threading required for this test.')
25370
class BasicTCPTest(SocketConnectedTest):
25371
@@ -1722,7 +1794,7 @@
25372
# no alarm can be pending. Safe to restore old handler.
25373
signal.signal(signal.SIGALRM, old_alarm)
25375
-class UDPTimeoutTest(SocketTCPTest):
25376
+class UDPTimeoutTest(SocketUDPTest):
25378
def testUDPTimeout(self):
25379
def raise_timeout(*args, **kwargs):
25380
@@ -1869,10 +1941,12 @@
25381
print("TIPC module is not loaded, please 'sudo modprobe tipc'")
25384
-class TIPCTest (unittest.TestCase):
25385
+class TIPCTest(unittest.TestCase):
25387
srv = socket.socket(socket.AF_TIPC, socket.SOCK_RDM)
25388
cli = socket.socket(socket.AF_TIPC, socket.SOCK_RDM)
25389
+ self.addCleanup(srv.close)
25390
+ self.addCleanup(cli.close)
25392
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
25393
srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE,
25394
@@ -1889,13 +1963,14 @@
25395
self.assertEqual(msg, MSG)
25398
-class TIPCThreadableTest (unittest.TestCase, ThreadableTest):
25399
+class TIPCThreadableTest(unittest.TestCase, ThreadableTest):
25400
def __init__(self, methodName = 'runTest'):
25401
unittest.TestCase.__init__(self, methodName = methodName)
25402
ThreadableTest.__init__(self)
25405
self.srv = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM)
25406
+ self.addCleanup(self.srv.close)
25407
self.srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
25408
srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE,
25409
TIPC_LOWER, TIPC_UPPER)
25410
@@ -1903,6 +1978,7 @@
25412
self.serverExplicitReady()
25413
self.conn, self.connaddr = self.srv.accept()
25414
+ self.addCleanup(self.conn.close)
25416
def clientSetUp(self):
25417
# The is a hittable race between serverExplicitReady() and the
25418
@@ -1910,6 +1986,7 @@
25419
# we could get an exception
25421
self.cli = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM)
25422
+ self.addCleanup(self.cli.close)
25423
addr = (socket.TIPC_ADDR_NAME, TIPC_STYPE,
25424
TIPC_LOWER + int((TIPC_UPPER - TIPC_LOWER) / 2), 0)
25425
self.cli.connect(addr)
25426
diff -r 137e45f15c0b Lib/test/test_socketserver.py
25427
--- a/Lib/test/test_socketserver.py
25428
+++ b/Lib/test/test_socketserver.py
25429
@@ -123,7 +123,6 @@
25430
self.assertEqual(server.server_address, server.socket.getsockname())
25433
- @unittest.skipUnless(threading, 'Threading required for this test.')
25435
def run_server(self, svrcls, hdlrbase, testfunc):
25436
server = self.make_server(self.pickaddr(svrcls.address_family),
25437
diff -r 137e45f15c0b Lib/test/test_ssl.py
25438
--- a/Lib/test/test_ssl.py
25439
+++ b/Lib/test/test_ssl.py
25441
BADCERT = data_file("badcert.pem")
25442
WRONGCERT = data_file("XXXnonexisting.pem")
25443
BADKEY = data_file("badkey.pem")
25444
+NOKIACERT = data_file("nokia.pem")
25447
def handle_error(prefix):
25448
@@ -117,6 +118,31 @@
25449
p = ssl._ssl._test_decode_cert(CERTFILE)
25450
if support.verbose:
25451
sys.stdout.write("\n" + pprint.pformat(p) + "\n")
25452
+ self.assertEqual(p['issuer'],
25453
+ ((('countryName', 'XY'),),
25454
+ (('localityName', 'Castle Anthrax'),),
25455
+ (('organizationName', 'Python Software Foundation'),),
25456
+ (('commonName', 'localhost'),))
25458
+ self.assertEqual(p['notAfter'], 'Oct 5 23:01:56 2020 GMT')
25459
+ self.assertEqual(p['notBefore'], 'Oct 8 23:01:56 2010 GMT')
25460
+ self.assertEqual(p['serialNumber'], 'D7C7381919AFC24E')
25461
+ self.assertEqual(p['subject'],
25462
+ ((('countryName', 'XY'),),
25463
+ (('localityName', 'Castle Anthrax'),),
25464
+ (('organizationName', 'Python Software Foundation'),),
25465
+ (('commonName', 'localhost'),))
25467
+ self.assertEqual(p['subjectAltName'], (('DNS', 'localhost'),))
25468
+ # Issue #13034: the subjectAltName in some certificates
25469
+ # (notably projects.developer.nokia.com:443) wasn't parsed
25470
+ p = ssl._ssl._test_decode_cert(NOKIACERT)
25471
+ if support.verbose:
25472
+ sys.stdout.write("\n" + pprint.pformat(p) + "\n")
25473
+ self.assertEqual(p['subjectAltName'],
25474
+ (('DNS', 'projects.developer.nokia.com'),
25475
+ ('DNS', 'projects.forum.nokia.com'))
25478
def test_DER_to_PEM(self):
25479
with open(SVN_PYTHON_ORG_ROOT_CERT, 'r') as f:
25480
@@ -736,10 +762,11 @@
25482
self.sslconn = self.server.context.wrap_socket(
25483
self.sock, server_side=True)
25484
- except ssl.SSLError:
25485
+ except ssl.SSLError as e:
25486
# XXX Various errors can have happened here, for example
25487
# a mismatching protocol version, an invalid certificate,
25488
# or a low-level bug. This should be made more discriminating.
25489
+ self.server.conn_errors.append(e)
25490
if self.server.chatty:
25491
handle_error("\n server: bad connection attempt from " + repr(self.addr) + ":\n")
25492
self.running = False
25493
@@ -852,9 +879,19 @@
25494
self.port = support.bind_port(self.sock)
25496
self.active = False
25497
+ self.conn_errors = []
25498
threading.Thread.__init__(self)
25501
+ def __enter__(self):
25502
+ self.start(threading.Event())
25506
+ def __exit__(self, *args):
25510
def start(self, flag=None):
25512
threading.Thread.start(self)
25513
@@ -874,6 +911,7 @@
25514
+ repr(connaddr) + '\n')
25515
handler = self.ConnectionHandler(self, newconn, connaddr)
25518
except socket.timeout:
25520
except KeyboardInterrupt:
25521
@@ -967,6 +1005,21 @@
25523
return "<%s %s>" % (self.__class__.__name__, self.server)
25525
+ def __enter__(self):
25526
+ self.start(threading.Event())
25530
+ def __exit__(self, *args):
25531
+ if support.verbose:
25532
+ sys.stdout.write(" cleanup: stopping server.\n")
25534
+ if support.verbose:
25535
+ sys.stdout.write(" cleanup: joining server thread.\n")
25537
+ if support.verbose:
25538
+ sys.stdout.write(" cleanup: successfully joined.\n")
25540
def start (self, flag=None):
25542
threading.Thread.start(self)
25543
@@ -994,12 +1047,7 @@
25544
certreqs=ssl.CERT_REQUIRED,
25545
cacerts=CERTFILE, chatty=False,
25546
connectionchatty=False)
25547
- flag = threading.Event()
25548
- server.start(flag)
25549
- # wait for it to start
25555
with socket.socket() as sock:
25556
s = ssl.wrap_socket(sock,
25557
@@ -1019,9 +1067,6 @@
25558
sys.stdout.write("\IOError is %s\n" % str(x))
25560
raise AssertionError("Use of invalid cert should have failed!")
25565
def server_params_test(client_context, server_context, indata=b"FOO\n",
25566
chatty=True, connectionchatty=False):
25567
@@ -1032,37 +1077,29 @@
25568
server = ThreadedEchoServer(context=server_context,
25570
connectionchatty=False)
25571
- flag = threading.Event()
25572
- server.start(flag)
25573
- # wait for it to start
25577
- s = client_context.wrap_socket(socket.socket())
25578
- s.connect((HOST, server.port))
25579
- for arg in [indata, bytearray(indata), memoryview(indata)]:
25581
+ with client_context.wrap_socket(socket.socket()) as s:
25582
+ s.connect((HOST, server.port))
25583
+ for arg in [indata, bytearray(indata), memoryview(indata)]:
25584
+ if connectionchatty:
25585
+ if support.verbose:
25586
+ sys.stdout.write(
25587
+ " client: sending %r...\n" % indata)
25589
+ outdata = s.read()
25590
+ if connectionchatty:
25591
+ if support.verbose:
25592
+ sys.stdout.write(" client: read %r\n" % outdata)
25593
+ if outdata != indata.lower():
25594
+ raise AssertionError(
25595
+ "bad data <<%r>> (%d) received; expected <<%r>> (%d)\n"
25596
+ % (outdata[:20], len(outdata),
25597
+ indata[:20].lower(), len(indata)))
25598
+ s.write(b"over\n")
25599
if connectionchatty:
25600
if support.verbose:
25601
- sys.stdout.write(
25602
- " client: sending %r...\n" % indata)
25604
- outdata = s.read()
25605
- if connectionchatty:
25606
- if support.verbose:
25607
- sys.stdout.write(" client: read %r\n" % outdata)
25608
- if outdata != indata.lower():
25609
- raise AssertionError(
25610
- "bad data <<%r>> (%d) received; expected <<%r>> (%d)\n"
25611
- % (outdata[:20], len(outdata),
25612
- indata[:20].lower(), len(indata)))
25613
- s.write(b"over\n")
25614
- if connectionchatty:
25615
- if support.verbose:
25616
- sys.stdout.write(" client: closing connection.\n")
25621
+ sys.stdout.write(" client: closing connection.\n")
25624
def try_protocol_combo(server_protocol, client_protocol, expect_success,
25625
certsreqs=None, server_options=0, client_options=0):
25626
@@ -1131,12 +1168,7 @@
25627
context.load_verify_locations(CERTFILE)
25628
context.load_cert_chain(CERTFILE)
25629
server = ThreadedEchoServer(context=context, chatty=False)
25630
- flag = threading.Event()
25631
- server.start(flag)
25632
- # wait for it to start
25637
s = context.wrap_socket(socket.socket())
25638
s.connect((HOST, server.port))
25639
cert = s.getpeercert()
25640
@@ -1159,9 +1191,6 @@
25641
after = ssl.cert_time_to_seconds(cert['notAfter'])
25642
self.assertLess(before, after)
25648
def test_empty_cert(self):
25649
"""Connecting with an empty cert file"""
25650
@@ -1289,7 +1318,8 @@
25651
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv3, True, ssl.CERT_REQUIRED)
25652
if hasattr(ssl, 'PROTOCOL_SSLv2'):
25653
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv2, False)
25654
- try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv23, False)
25655
+ try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv23, False,
25656
+ client_options=ssl.OP_NO_SSLv3)
25657
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_TLSv1, False)
25658
if no_sslv2_implies_sslv3_hello():
25659
# No SSLv2 => client will use an SSLv3 hello on recent OpenSSLs
25660
@@ -1307,7 +1337,8 @@
25661
if hasattr(ssl, 'PROTOCOL_SSLv2'):
25662
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv2, False)
25663
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv3, False)
25664
- try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv23, False)
25665
+ try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv23, False,
25666
+ client_options=ssl.OP_NO_TLSv1)
25668
def test_starttls(self):
25669
"""Switching from clear text to encrypted and back again."""
25670
@@ -1318,13 +1349,8 @@
25671
starttls_server=True,
25673
connectionchatty=True)
25674
- flag = threading.Event()
25675
- server.start(flag)
25676
- # wait for it to start
25682
s = socket.socket()
25684
s.connect((HOST, server.port))
25685
@@ -1371,9 +1397,6 @@
25693
def test_socketserver(self):
25694
"""Using a SocketServer to create and manage SSL connections."""
25695
@@ -1409,12 +1432,7 @@
25698
server = AsyncoreEchoServer(CERTFILE)
25699
- flag = threading.Event()
25700
- server.start(flag)
25701
- # wait for it to start
25706
s = ssl.wrap_socket(socket.socket())
25707
s.connect(('127.0.0.1', server.port))
25708
if support.verbose:
25709
@@ -1435,15 +1453,6 @@
25711
if support.verbose:
25712
sys.stdout.write(" client: connection closed.\n")
25714
- if support.verbose:
25715
- sys.stdout.write(" cleanup: stopping server.\n")
25717
- if support.verbose:
25718
- sys.stdout.write(" cleanup: joining server thread.\n")
25720
- if support.verbose:
25721
- sys.stdout.write(" cleanup: successfully joined.\n")
25723
def test_recv_send(self):
25724
"""Test recv(), send() and friends."""
25725
@@ -1456,19 +1465,14 @@
25728
connectionchatty=False)
25729
- flag = threading.Event()
25730
- server.start(flag)
25731
- # wait for it to start
25734
- s = ssl.wrap_socket(socket.socket(),
25735
- server_side=False,
25736
- certfile=CERTFILE,
25737
- ca_certs=CERTFILE,
25738
- cert_reqs=ssl.CERT_NONE,
25739
- ssl_version=ssl.PROTOCOL_TLSv1)
25740
- s.connect((HOST, server.port))
25743
+ s = ssl.wrap_socket(socket.socket(),
25744
+ server_side=False,
25745
+ certfile=CERTFILE,
25746
+ ca_certs=CERTFILE,
25747
+ cert_reqs=ssl.CERT_NONE,
25748
+ ssl_version=ssl.PROTOCOL_TLSv1)
25749
+ s.connect((HOST, server.port))
25750
# helper methods for standardising recv* method signatures
25752
b = bytearray(b"\0"*100)
25753
@@ -1553,12 +1557,8 @@
25764
def test_handshake_timeout(self):
25765
# Issue #5103: SSL handshake must respect the socket timeout
25766
@@ -1609,6 +1609,22 @@
25770
+ def test_default_ciphers(self):
25771
+ context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
25773
+ # Force a set of weak ciphers on our client context
25774
+ context.set_ciphers("DES")
25775
+ except ssl.SSLError:
25776
+ self.skipTest("no DES cipher available")
25777
+ with ThreadedEchoServer(CERTFILE,
25778
+ ssl_version=ssl.PROTOCOL_SSLv23,
25779
+ chatty=False) as server:
25780
+ with socket.socket() as sock:
25781
+ s = context.wrap_socket(sock)
25782
+ with self.assertRaises((OSError, ssl.SSLError)):
25783
+ s.connect((HOST, server.port))
25784
+ self.assertIn("no shared cipher", str(server.conn_errors[0]))
25787
def test_main(verbose=False):
25788
if support.verbose:
25789
diff -r 137e45f15c0b Lib/test/test_strlit.py
25790
--- a/Lib/test/test_strlit.py
25791
+++ b/Lib/test/test_strlit.py
25796
+import test.support
25799
TEMPLATE = r"""# coding: %s
25800
@@ -142,7 +143,8 @@
25801
self.check_encoding("latin9")
25805
+ test.support.run_unittest(__name__)
25807
if __name__ == "__main__":
25808
- # Hack so that error messages containing non-ASCII can be printed
25809
- sys.stdout._encoding = sys.stderr._encoding = "utf-8"
25812
diff -r 137e45f15c0b Lib/test/test_subprocess.py
25813
--- a/Lib/test/test_subprocess.py
25814
+++ b/Lib/test/test_subprocess.py
25815
@@ -13,10 +13,12 @@
25824
except ImportError:
25828
mswindows = (sys.platform == "win32")
25830
@@ -732,12 +734,12 @@
25832
def __enter__(self):
25833
"""Try to save previous ulimit, then set it to (0, 0)."""
25836
- self.old_limit = resource.getrlimit(resource.RLIMIT_CORE)
25837
- resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
25838
- except (ImportError, ValueError, resource.error):
25840
+ if resource is not None:
25842
+ self.old_limit = resource.getrlimit(resource.RLIMIT_CORE)
25843
+ resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
25844
+ except (ValueError, resource.error):
25847
if sys.platform == 'darwin':
25848
# Check if the 'Crash Reporter' on OSX was configured
25849
@@ -758,11 +760,11 @@
25850
"""Return core file behavior to default."""
25851
if self.old_limit is None:
25855
- resource.setrlimit(resource.RLIMIT_CORE, self.old_limit)
25856
- except (ImportError, ValueError, resource.error):
25858
+ if resource is not None:
25860
+ resource.setrlimit(resource.RLIMIT_CORE, self.old_limit)
25861
+ except (ValueError, resource.error):
25865
@unittest.skipIf(mswindows, "POSIX specific tests")
25866
@@ -853,7 +855,6 @@
25867
self.fail("Exception raised by preexec_fn did not make it "
25868
"to the parent process.")
25870
- @unittest.skipUnless(gc, "Requires a gc module.")
25871
def test_preexec_gc_module_failure(self):
25872
# This tests the code that disables garbage collection if the child
25873
# process will execute any Python.
25874
@@ -1272,8 +1273,18 @@
25876
self.addCleanup(p1.wait)
25877
self.addCleanup(p2.wait)
25878
- self.addCleanup(p1.terminate)
25879
- self.addCleanup(p2.terminate)
25883
+ except ProcessLookupError:
25888
+ except ProcessLookupError:
25890
+ self.addCleanup(kill_p1)
25891
+ self.addCleanup(kill_p2)
25893
p1.stdin.write(data)
25895
@@ -1294,6 +1305,11 @@
25896
self.addCleanup(os.close, fds[1])
25898
open_fds = set(fds)
25899
+ # add a bunch more fds
25900
+ for _ in range(9):
25901
+ fd = os.open("/dev/null", os.O_RDONLY)
25902
+ self.addCleanup(os.close, fd)
25905
p = subprocess.Popen([sys.executable, fd_status],
25906
stdout=subprocess.PIPE, close_fds=False)
25907
@@ -1312,6 +1328,19 @@
25908
"Some fds were left open")
25909
self.assertIn(1, remaining_fds, "Subprocess failed")
25911
+ # Keep some of the fd's we opened open in the subprocess.
25912
+ # This tests _posixsubprocess.c's proper handling of fds_to_keep.
25913
+ fds_to_keep = set(open_fds.pop() for _ in range(8))
25914
+ p = subprocess.Popen([sys.executable, fd_status],
25915
+ stdout=subprocess.PIPE, close_fds=True,
25917
+ output, ignored = p.communicate()
25918
+ remaining_fds = set(map(int, output.split(b',')))
25920
+ self.assertFalse(remaining_fds & fds_to_keep & open_fds,
25921
+ "Some fds not in pass_fds were left open")
25922
+ self.assertIn(1, remaining_fds, "Subprocess failed")
25924
# Mac OS X Tiger (10.4) has a kernel bug: sometimes, the file
25925
# descriptor of a pipe closed in the parent process is valid in the
25926
# child process according to fstat(), but the mode of the file
25927
@@ -1394,6 +1423,56 @@
25931
+ def test_zombie_fast_process_del(self):
25932
+ # Issue #12650: on Unix, if Popen.__del__() was called before the
25933
+ # process exited, it wouldn't be added to subprocess._active, and would
25934
+ # remain a zombie.
25935
+ # spawn a Popen, and delete its reference before it exits
25936
+ p = subprocess.Popen([sys.executable, "-c",
25937
+ 'import sys, time;'
25938
+ 'time.sleep(0.2)'],
25939
+ stdout=subprocess.PIPE,
25940
+ stderr=subprocess.PIPE)
25941
+ self.addCleanup(p.stdout.close)
25942
+ self.addCleanup(p.stderr.close)
25946
+ # check that p is in the active processes list
25947
+ self.assertIn(ident, [id(o) for o in subprocess._active])
25949
+ def test_leak_fast_process_del_killed(self):
25950
+ # Issue #12650: on Unix, if Popen.__del__() was called before the
25951
+ # process exited, and the process got killed by a signal, it would never
25952
+ # be removed from subprocess._active, which triggered a FD and memory
25954
+ # spawn a Popen, delete its reference and kill it
25955
+ p = subprocess.Popen([sys.executable, "-c",
25957
+ 'time.sleep(3)'],
25958
+ stdout=subprocess.PIPE,
25959
+ stderr=subprocess.PIPE)
25960
+ self.addCleanup(p.stdout.close)
25961
+ self.addCleanup(p.stderr.close)
25965
+ os.kill(pid, signal.SIGKILL)
25966
+ # check that p is in the active processes list
25967
+ self.assertIn(ident, [id(o) for o in subprocess._active])
25969
+ # let some time for the process to exit, and create a new Popen: this
25970
+ # should trigger the wait() of p
25972
+ with self.assertRaises(EnvironmentError) as c:
25973
+ with subprocess.Popen(['nonexisting_i_hope'],
25974
+ stdout=subprocess.PIPE,
25975
+ stderr=subprocess.PIPE) as proc:
25977
+ # p should have been wait()ed on, and removed from the _active list
25978
+ self.assertRaises(OSError, os.waitpid, pid, 0)
25979
+ self.assertNotIn(ident, [id(o) for o in subprocess._active])
25982
@unittest.skipUnless(mswindows, "Windows specific tests")
25983
class Win32ProcessTestCase(BaseTestCase):
25984
diff -r 137e45f15c0b Lib/test/test_symtable.py
25985
--- a/Lib/test/test_symtable.py
25986
+++ b/Lib/test/test_symtable.py
25987
@@ -80,10 +80,10 @@
25989
def test_function_info(self):
25991
- self.assertEqual(func.get_parameters(), ("a", "b", "kw", "var"))
25992
- self.assertEqual(func.get_locals(),
25993
- ("a", "b", "internal", "kw", "var", "x"))
25994
- self.assertEqual(func.get_globals(), ("bar", "glob"))
25995
+ self.assertEqual(sorted(func.get_parameters()), ["a", "b", "kw", "var"])
25996
+ expected = ["a", "b", "internal", "kw", "var", "x"]
25997
+ self.assertEqual(sorted(func.get_locals()), expected)
25998
+ self.assertEqual(sorted(func.get_globals()), ["bar", "glob"])
25999
self.assertEqual(self.internal.get_frees(), ("x",))
26001
def test_globals(self):
26002
diff -r 137e45f15c0b Lib/test/test_sys.py
26003
--- a/Lib/test/test_sys.py
26004
+++ b/Lib/test/test_sys.py
26005
@@ -532,6 +532,9 @@
26006
self.assertEqual(out, b'?')
26008
def test_executable(self):
26009
+ # sys.executable should be absolute
26010
+ self.assertEqual(os.path.abspath(sys.executable), sys.executable)
26012
# Issue #7774: Ensure that sys.executable is an empty string if argv[0]
26013
# has been set to an non existent program name and Python is unable to
26014
# retrieve the real program name
26015
diff -r 137e45f15c0b Lib/test/test_sys_settrace.py
26016
--- a/Lib/test/test_sys_settrace.py
26017
+++ b/Lib/test/test_sys_settrace.py
26018
@@ -282,11 +282,11 @@
26019
self.compare_events(func.__code__.co_firstlineno,
26020
tracer.events, func.events)
26022
- def set_and_retrieve_none(self):
26023
+ def test_set_and_retrieve_none(self):
26025
assert sys.gettrace() is None
26027
- def set_and_retrieve_func(self):
26028
+ def test_set_and_retrieve_func(self):
26032
diff -r 137e45f15c0b Lib/test/test_sysconfig.py
26033
--- a/Lib/test/test_sysconfig.py
26034
+++ b/Lib/test/test_sysconfig.py
26036
-"""Tests for 'site'.
26037
+"""Tests for sysconfig."""
26039
-Tests assume the initial paths in sys.path once the interpreter has begun
26040
-executing have not been removed.
26048
from copy import copy, deepcopy
26050
-from test.support import (run_unittest, TESTFN, unlink, get_attribute,
26051
+from test.support import (run_unittest, TESTFN, unlink,
26052
captured_stdout, skip_unless_symlink)
26055
@@ -261,14 +257,21 @@
26058
def test_user_similar(self):
26059
- # Issue 8759 : make sure the posix scheme for the users
26060
+ # Issue #8759: make sure the posix scheme for the users
26061
# is similar to the global posix_prefix one
26062
base = get_config_var('base')
26063
user = get_config_var('userbase')
26064
+ # the global scheme mirrors the distinction between prefix and
26065
+ # exec-prefix but not the user scheme, so we have to adapt the paths
26066
+ # before comparing (issue #9100)
26067
+ adapt = sys.prefix != sys.exec_prefix
26068
for name in ('stdlib', 'platstdlib', 'purelib', 'platlib'):
26069
global_path = get_path(name, 'posix_prefix')
26071
+ global_path = global_path.replace(sys.exec_prefix, sys.prefix)
26072
+ base = base.replace(sys.exec_prefix, sys.prefix)
26073
user_path = get_path(name, 'posix_user')
26074
- self.assertEqual(user_path, global_path.replace(base, user))
26075
+ self.assertEqual(user_path, global_path.replace(base, user, 1))
26077
def test_main(self):
26078
# just making sure _main() runs and returns things in the stdout
26079
diff -r 137e45f15c0b Lib/test/test_tarfile.py
26080
--- a/Lib/test/test_tarfile.py
26081
+++ b/Lib/test/test_tarfile.py
26082
@@ -529,6 +529,23 @@
26083
def test_detect_fileobj(self):
26084
self._test_modes(self._testfunc_fileobj)
26086
+ def test_detect_stream_bz2(self):
26087
+ # Originally, tarfile's stream detection looked for the string
26088
+ # "BZh91" at the start of the file. This is incorrect because
26089
+ # the '9' represents the blocksize (900kB). If the file was
26090
+ # compressed using another blocksize autodetection fails.
26094
+ with open(tarname, "rb") as fobj:
26095
+ data = fobj.read()
26097
+ # Compress with blocksize 100kB, the file starts with "BZh11".
26098
+ with bz2.BZ2File(tmpname, "wb", compresslevel=1) as fobj:
26101
+ self._testfunc_file(tmpname, "r|*")
26104
class MemberReadTest(ReadTest):
26106
@@ -1582,9 +1599,31 @@
26107
self.assertEqual(tarfile.nts(b"foo\0\0\0\0\0", "ascii", "strict"), "foo")
26108
self.assertEqual(tarfile.nts(b"foo\0bar\0", "ascii", "strict"), "foo")
26110
- def test_number_fields(self):
26111
+ def test_read_number_fields(self):
26112
+ # Issue 13158: Test if GNU tar specific base-256 number fields
26113
+ # are decoded correctly.
26114
+ self.assertEqual(tarfile.nti(b"0000001\x00"), 1)
26115
+ self.assertEqual(tarfile.nti(b"7777777\x00"), 0o7777777)
26116
+ self.assertEqual(tarfile.nti(b"\x80\x00\x00\x00\x00\x20\x00\x00"), 0o10000000)
26117
+ self.assertEqual(tarfile.nti(b"\x80\x00\x00\x00\xff\xff\xff\xff"), 0xffffffff)
26118
+ self.assertEqual(tarfile.nti(b"\xff\xff\xff\xff\xff\xff\xff\xff"), -1)
26119
+ self.assertEqual(tarfile.nti(b"\xff\xff\xff\xff\xff\xff\xff\x9c"), -100)
26120
+ self.assertEqual(tarfile.nti(b"\xff\x00\x00\x00\x00\x00\x00\x00"), -0x100000000000000)
26122
+ def test_write_number_fields(self):
26123
self.assertEqual(tarfile.itn(1), b"0000001\x00")
26124
+ self.assertEqual(tarfile.itn(0o7777777), b"7777777\x00")
26125
+ self.assertEqual(tarfile.itn(0o10000000), b"\x80\x00\x00\x00\x00\x20\x00\x00")
26126
self.assertEqual(tarfile.itn(0xffffffff), b"\x80\x00\x00\x00\xff\xff\xff\xff")
26127
+ self.assertEqual(tarfile.itn(-1), b"\xff\xff\xff\xff\xff\xff\xff\xff")
26128
+ self.assertEqual(tarfile.itn(-100), b"\xff\xff\xff\xff\xff\xff\xff\x9c")
26129
+ self.assertEqual(tarfile.itn(-0x100000000000000), b"\xff\x00\x00\x00\x00\x00\x00\x00")
26131
+ def test_number_field_limits(self):
26132
+ self.assertRaises(ValueError, tarfile.itn, -1, 8, tarfile.USTAR_FORMAT)
26133
+ self.assertRaises(ValueError, tarfile.itn, 0o10000000, 8, tarfile.USTAR_FORMAT)
26134
+ self.assertRaises(ValueError, tarfile.itn, -0x10000000001, 6, tarfile.GNU_FORMAT)
26135
+ self.assertRaises(ValueError, tarfile.itn, 0x10000000000, 6, tarfile.GNU_FORMAT)
26138
class ContextManagerTest(unittest.TestCase):
26139
@@ -1796,11 +1835,8 @@
26141
# Create testtar.tar.bz2 and add bz2-specific tests.
26142
support.unlink(bz2name)
26143
- tar = bz2.BZ2File(bz2name, "wb")
26145
+ with bz2.BZ2File(bz2name, "wb") as tar:
26152
diff -r 137e45f15c0b Lib/test/test_telnetlib.py
26153
--- a/Lib/test/test_telnetlib.py
26154
+++ b/Lib/test/test_telnetlib.py
26155
@@ -15,29 +15,25 @@
26158
conn, addr = serv.accept()
26160
except socket.timeout:
26168
class GeneralTests(TestCase):
26171
self.evt = threading.Event()
26172
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
26173
- self.sock.settimeout(3)
26174
+ self.sock.settimeout(60) # Safety net. Look issue 11812
26175
self.port = support.bind_port(self.sock)
26176
self.thread = threading.Thread(target=server, args=(self.evt,self.sock))
26177
+ self.thread.setDaemon(True)
26178
self.thread.start()
26183
def tearDown(self):
26187
def testBasic(self):
26189
self.assertTrue(socket.getdefaulttimeout() is None)
26190
socket.setdefaulttimeout(30)
26192
- telnet = telnetlib.Telnet("localhost", self.port)
26193
+ telnet = telnetlib.Telnet(HOST, self.port)
26195
socket.setdefaulttimeout(None)
26196
self.assertEqual(telnet.sock.gettimeout(), 30)
26197
@@ -67,13 +63,13 @@
26198
telnet.sock.close()
26200
def testTimeoutValue(self):
26201
- telnet = telnetlib.Telnet("localhost", self.port, timeout=30)
26202
+ telnet = telnetlib.Telnet(HOST, self.port, timeout=30)
26203
self.assertEqual(telnet.sock.gettimeout(), 30)
26204
telnet.sock.close()
26206
def testTimeoutOpen(self):
26207
telnet = telnetlib.Telnet()
26208
- telnet.open("localhost", self.port, timeout=30)
26209
+ telnet.open(HOST, self.port, timeout=30)
26210
self.assertEqual(telnet.sock.gettimeout(), 30)
26211
telnet.sock.close()
26213
diff -r 137e45f15c0b Lib/test/test_tempfile.py
26214
--- a/Lib/test/test_tempfile.py
26215
+++ b/Lib/test/test_tempfile.py
26217
# tempfile.py unit tests.
26224
@@ -135,6 +136,37 @@
26226
self.failOnException("iteration")
26228
+ @unittest.skipUnless(hasattr(os, 'fork'),
26229
+ "os.fork is required for this test")
26230
+ def test_process_awareness(self):
26231
+ # ensure that the random source differs between
26232
+ # child and parent.
26233
+ read_fd, write_fd = os.pipe()
26238
+ os.close(read_fd)
26239
+ os.write(write_fd, next(self.r).encode("ascii"))
26240
+ os.close(write_fd)
26241
+ # bypass the normal exit handlers- leave those to
26244
+ parent_value = next(self.r)
26245
+ child_value = os.read(read_fd, len(parent_value)).decode("ascii")
26248
+ # best effort to ensure the process can't bleed out
26249
+ # via any bugs above
26251
+ os.kill(pid, signal.SIGKILL)
26252
+ except EnvironmentError:
26254
+ os.close(read_fd)
26255
+ os.close(write_fd)
26256
+ self.assertNotEqual(child_value, parent_value)
26259
test_classes.append(test__RandomNameSequence)
26262
diff -r 137e45f15c0b Lib/test/test_threading.py
26263
--- a/Lib/test/test_threading.py
26264
+++ b/Lib/test/test_threading.py
26265
@@ -666,6 +666,30 @@
26266
rc, out, err = assert_python_ok('-c', script)
26267
self.assertFalse(err)
26269
+ @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()")
26270
+ @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug")
26271
+ def test_reinit_tls_after_fork(self):
26272
+ # Issue #13817: fork() would deadlock in a multithreaded program with
26273
+ # the ad-hoc TLS implementation.
26275
+ def do_fork_and_wait():
26276
+ # just fork a child process and wait it
26279
+ os.waitpid(pid, 0)
26283
+ # start a bunch of threads that will fork() child processes
26285
+ for i in range(16):
26286
+ t = threading.Thread(target=do_fork_and_wait)
26287
+ threads.append(t)
26290
+ for t in threads:
26294
class ThreadingExceptionTests(BaseTestCase):
26295
# A RuntimeError should be raised if Thread.start() is called
26296
@@ -726,6 +750,7 @@
26297
class PyRLockTests(lock_tests.RLockTests):
26298
locktype = staticmethod(threading._PyRLock)
26300
+@unittest.skipIf(threading._CRLock is None, 'RLock not implemented in C')
26301
class CRLockTests(lock_tests.RLockTests):
26302
locktype = staticmethod(threading._CRLock)
26304
diff -r 137e45f15c0b Lib/test/test_time.py
26305
--- a/Lib/test/test_time.py
26306
+++ b/Lib/test/test_time.py
26307
@@ -206,7 +206,12 @@
26308
environ['TZ'] = victoria
26310
self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002))
26311
- self.assertTrue(time.tzname[0] == 'AEST', str(time.tzname[0]))
26313
+ # Issue #11886: Australian Eastern Standard Time (UTC+10) is called
26314
+ # "EST" (as Eastern Standard Time, UTC-5) instead of "AEST" on some
26315
+ # operating systems (e.g. FreeBSD), which is wrong. See for example
26316
+ # this bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=93810
26317
+ self.assertIn(time.tzname[0], ('AEST' 'EST'), time.tzname[0])
26318
self.assertTrue(time.tzname[1] == 'AEDT', str(time.tzname[1]))
26319
self.assertEqual(len(time.tzname), 2)
26320
self.assertEqual(time.daylight, 1)
26321
diff -r 137e45f15c0b Lib/test/test_tuple.py
26322
--- a/Lib/test/test_tuple.py
26323
+++ b/Lib/test/test_tuple.py
26324
@@ -154,6 +154,16 @@
26325
# Trying to untrack an unfinished tuple could crash Python
26326
self._not_tracked(tuple(gc.collect() for i in range(101)))
26328
+ def test_repr_large(self):
26329
+ # Check the repr of large list objects
26333
+ self.assertEqual(s,
26334
+ '(' + ', '.join(['0'] * n) + ')')
26335
+ check(10) # check our checking code
26339
support.run_unittest(TupleTest)
26341
diff -r 137e45f15c0b Lib/test/test_unicode.py
26342
--- a/Lib/test/test_unicode.py
26343
+++ b/Lib/test/test_unicode.py
26345
from test import support, string_tests
26348
+# decorator to skip tests on narrow builds
26349
+requires_wide_build = unittest.skipIf(sys.maxunicode == 65535,
26350
+ 'requires wide build')
26352
# Error handling (bad decoder return)
26353
def search_function(encoding):
26354
def decode1(input, errors="strict"):
26355
@@ -170,6 +174,7 @@
26356
self.checkequalnofix(0, 'aaa', 'count', 'a', 0, -10)
26358
def test_find(self):
26359
+ string_tests.CommonTest.test_find(self)
26360
self.checkequalnofix(0, 'abcdefghiabc', 'find', 'abc')
26361
self.checkequalnofix(9, 'abcdefghiabc', 'find', 'abc', 1)
26362
self.checkequalnofix(-1, 'abcdefghiabc', 'find', 'def', 4)
26363
@@ -345,26 +350,69 @@
26364
def test_islower(self):
26365
string_tests.MixinStrUnicodeUserStringTest.test_islower(self)
26366
self.checkequalnofix(False, '\u1FFc', 'islower')
26367
+ # non-BMP, uppercase
26368
+ self.assertFalse('\U00010401'.islower())
26369
+ self.assertFalse('\U00010427'.islower())
26370
+ # non-BMP, lowercase
26371
+ self.assertTrue('\U00010429'.islower())
26372
+ self.assertTrue('\U0001044E'.islower())
26373
+ # non-BMP, non-cased
26374
+ self.assertFalse('\U0001F40D'.islower())
26375
+ self.assertFalse('\U0001F46F'.islower())
26377
def test_isupper(self):
26378
string_tests.MixinStrUnicodeUserStringTest.test_isupper(self)
26379
if not sys.platform.startswith('java'):
26380
self.checkequalnofix(False, '\u1FFc', 'isupper')
26381
+ # non-BMP, uppercase
26382
+ self.assertTrue('\U00010401'.isupper())
26383
+ self.assertTrue('\U00010427'.isupper())
26384
+ # non-BMP, lowercase
26385
+ self.assertFalse('\U00010429'.isupper())
26386
+ self.assertFalse('\U0001044E'.isupper())
26387
+ # non-BMP, non-cased
26388
+ self.assertFalse('\U0001F40D'.isupper())
26389
+ self.assertFalse('\U0001F46F'.isupper())
26391
def test_istitle(self):
26392
- string_tests.MixinStrUnicodeUserStringTest.test_title(self)
26393
+ string_tests.MixinStrUnicodeUserStringTest.test_istitle(self)
26394
self.checkequalnofix(True, '\u1FFc', 'istitle')
26395
self.checkequalnofix(True, 'Greek \u1FFcitlecases ...', 'istitle')
26397
+ # non-BMP, uppercase + lowercase
26398
+ self.assertTrue('\U00010401\U00010429'.istitle())
26399
+ self.assertTrue('\U00010427\U0001044E'.istitle())
26400
+ # apparently there are no titlecased (Lt) non-BMP chars in Unicode 6
26401
+ for ch in ['\U00010429', '\U0001044E', '\U0001F40D', '\U0001F46F']:
26402
+ self.assertFalse(ch.istitle(), '{!a} is not title'.format(ch))
26404
def test_isspace(self):
26405
string_tests.MixinStrUnicodeUserStringTest.test_isspace(self)
26406
self.checkequalnofix(True, '\u2000', 'isspace')
26407
self.checkequalnofix(True, '\u200a', 'isspace')
26408
self.checkequalnofix(False, '\u2014', 'isspace')
26409
+ # apparently there are no non-BMP spaces chars in Unicode 6
26410
+ for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E',
26411
+ '\U0001F40D', '\U0001F46F']:
26412
+ self.assertFalse(ch.isspace(), '{!a} is not space.'.format(ch))
26414
+ def test_isalnum(self):
26415
+ string_tests.MixinStrUnicodeUserStringTest.test_isalnum(self)
26416
+ for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E',
26417
+ '\U0001D7F6', '\U00011066', '\U000104A0', '\U0001F107']:
26418
+ self.assertTrue(ch.isalnum(), '{!a} is alnum.'.format(ch))
26420
def test_isalpha(self):
26421
string_tests.MixinStrUnicodeUserStringTest.test_isalpha(self)
26422
self.checkequalnofix(True, '\u1FFc', 'isalpha')
26424
+ self.assertTrue('\U00010401'.isalpha())
26425
+ self.assertTrue('\U00010427'.isalpha())
26426
+ self.assertTrue('\U00010429'.isalpha())
26427
+ self.assertTrue('\U0001044E'.isalpha())
26428
+ # non-BMP, non-cased
26429
+ self.assertFalse('\U0001F40D'.isalpha())
26430
+ self.assertFalse('\U0001F46F'.isalpha())
26432
def test_isdecimal(self):
26433
self.checkequalnofix(False, '', 'isdecimal')
26434
@@ -378,12 +426,24 @@
26436
self.checkraises(TypeError, 'abc', 'isdecimal', 42)
26438
+ for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E',
26439
+ '\U0001F40D', '\U0001F46F', '\U00011065', '\U0001F107']:
26440
+ self.assertFalse(ch.isdecimal(), '{!a} is not decimal.'.format(ch))
26441
+ for ch in ['\U0001D7F6', '\U00011066', '\U000104A0']:
26442
+ self.assertTrue(ch.isdecimal(), '{!a} is decimal.'.format(ch))
26444
def test_isdigit(self):
26445
string_tests.MixinStrUnicodeUserStringTest.test_isdigit(self)
26446
self.checkequalnofix(True, '\u2460', 'isdigit')
26447
self.checkequalnofix(False, '\xbc', 'isdigit')
26448
self.checkequalnofix(True, '\u0660', 'isdigit')
26450
+ for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E',
26451
+ '\U0001F40D', '\U0001F46F', '\U00011065']:
26452
+ self.assertFalse(ch.isdigit(), '{!a} is not a digit.'.format(ch))
26453
+ for ch in ['\U0001D7F6', '\U00011066', '\U000104A0', '\U0001F107']:
26454
+ self.assertTrue(ch.isdigit(), '{!a} is a digit.'.format(ch))
26456
def test_isnumeric(self):
26457
self.checkequalnofix(False, '', 'isnumeric')
26458
self.checkequalnofix(False, 'a', 'isnumeric')
26459
@@ -396,6 +456,13 @@
26461
self.assertRaises(TypeError, "abc".isnumeric, 42)
26463
+ for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E',
26464
+ '\U0001F40D', '\U0001F46F']:
26465
+ self.assertFalse(ch.isnumeric(), '{!a} is not numeric.'.format(ch))
26466
+ for ch in ['\U00011065', '\U0001D7F6', '\U00011066',
26467
+ '\U000104A0', '\U0001F107']:
26468
+ self.assertTrue(ch.isnumeric(), '{!a} is numeric.'.format(ch))
26470
def test_isidentifier(self):
26471
self.assertTrue("a".isidentifier())
26472
self.assertTrue("Z".isidentifier())
26473
@@ -423,6 +490,100 @@
26474
# single surrogate character
26475
self.assertFalse("\ud800".isprintable())
26477
+ self.assertTrue('\U0001F46F'.isprintable())
26478
+ self.assertFalse('\U000E0020'.isprintable())
26480
+ def test_surrogates(self):
26481
+ for s in ('a\uD800b\uDFFF', 'a\uDFFFb\uD800',
26482
+ 'a\uD800b\uDFFFa', 'a\uDFFFb\uD800a'):
26483
+ self.assertTrue(s.islower())
26484
+ self.assertFalse(s.isupper())
26485
+ self.assertFalse(s.istitle())
26486
+ for s in ('A\uD800B\uDFFF', 'A\uDFFFB\uD800',
26487
+ 'A\uD800B\uDFFFA', 'A\uDFFFB\uD800A'):
26488
+ self.assertFalse(s.islower())
26489
+ self.assertTrue(s.isupper())
26490
+ self.assertTrue(s.istitle())
26492
+ for meth_name in ('islower', 'isupper', 'istitle'):
26493
+ meth = getattr(str, meth_name)
26494
+ for s in ('\uD800', '\uDFFF', '\uD800\uD800', '\uDFFF\uDFFF'):
26495
+ self.assertFalse(meth(s), '%a.%s() is False' % (s, meth_name))
26497
+ for meth_name in ('isalpha', 'isalnum', 'isdigit', 'isspace',
26498
+ 'isdecimal', 'isnumeric',
26499
+ 'isidentifier', 'isprintable'):
26500
+ meth = getattr(str, meth_name)
26501
+ for s in ('\uD800', '\uDFFF', '\uD800\uD800', '\uDFFF\uDFFF',
26502
+ 'a\uD800b\uDFFF', 'a\uDFFFb\uD800',
26503
+ 'a\uD800b\uDFFFa', 'a\uDFFFb\uD800a'):
26504
+ self.assertFalse(meth(s), '%a.%s() is False' % (s, meth_name))
26507
+ @requires_wide_build
26508
+ def test_lower(self):
26509
+ string_tests.CommonTest.test_lower(self)
26510
+ self.assertEqual('\U00010427'.lower(), '\U0001044F')
26511
+ self.assertEqual('\U00010427\U00010427'.lower(),
26512
+ '\U0001044F\U0001044F')
26513
+ self.assertEqual('\U00010427\U0001044F'.lower(),
26514
+ '\U0001044F\U0001044F')
26515
+ self.assertEqual('X\U00010427x\U0001044F'.lower(),
26516
+ 'x\U0001044Fx\U0001044F')
26518
+ @requires_wide_build
26519
+ def test_upper(self):
26520
+ string_tests.CommonTest.test_upper(self)
26521
+ self.assertEqual('\U0001044F'.upper(), '\U00010427')
26522
+ self.assertEqual('\U0001044F\U0001044F'.upper(),
26523
+ '\U00010427\U00010427')
26524
+ self.assertEqual('\U00010427\U0001044F'.upper(),
26525
+ '\U00010427\U00010427')
26526
+ self.assertEqual('X\U00010427x\U0001044F'.upper(),
26527
+ 'X\U00010427X\U00010427')
26529
+ @requires_wide_build
26530
+ def test_capitalize(self):
26531
+ string_tests.CommonTest.test_capitalize(self)
26532
+ self.assertEqual('\U0001044F'.capitalize(), '\U00010427')
26533
+ self.assertEqual('\U0001044F\U0001044F'.capitalize(),
26534
+ '\U00010427\U0001044F')
26535
+ self.assertEqual('\U00010427\U0001044F'.capitalize(),
26536
+ '\U00010427\U0001044F')
26537
+ self.assertEqual('\U0001044F\U00010427'.capitalize(),
26538
+ '\U00010427\U0001044F')
26539
+ self.assertEqual('X\U00010427x\U0001044F'.capitalize(),
26540
+ 'X\U0001044Fx\U0001044F')
26542
+ @requires_wide_build
26543
+ def test_title(self):
26544
+ string_tests.MixinStrUnicodeUserStringTest.test_title(self)
26545
+ self.assertEqual('\U0001044F'.title(), '\U00010427')
26546
+ self.assertEqual('\U0001044F\U0001044F'.title(),
26547
+ '\U00010427\U0001044F')
26548
+ self.assertEqual('\U0001044F\U0001044F \U0001044F\U0001044F'.title(),
26549
+ '\U00010427\U0001044F \U00010427\U0001044F')
26550
+ self.assertEqual('\U00010427\U0001044F \U00010427\U0001044F'.title(),
26551
+ '\U00010427\U0001044F \U00010427\U0001044F')
26552
+ self.assertEqual('\U0001044F\U00010427 \U0001044F\U00010427'.title(),
26553
+ '\U00010427\U0001044F \U00010427\U0001044F')
26554
+ self.assertEqual('X\U00010427x\U0001044F X\U00010427x\U0001044F'.title(),
26555
+ 'X\U0001044Fx\U0001044F X\U0001044Fx\U0001044F')
26557
+ @requires_wide_build
26558
+ def test_swapcase(self):
26559
+ string_tests.CommonTest.test_swapcase(self)
26560
+ self.assertEqual('\U0001044F'.swapcase(), '\U00010427')
26561
+ self.assertEqual('\U00010427'.swapcase(), '\U0001044F')
26562
+ self.assertEqual('\U0001044F\U0001044F'.swapcase(),
26563
+ '\U00010427\U00010427')
26564
+ self.assertEqual('\U00010427\U0001044F'.swapcase(),
26565
+ '\U0001044F\U00010427')
26566
+ self.assertEqual('\U0001044F\U00010427'.swapcase(),
26567
+ '\U00010427\U0001044F')
26568
+ self.assertEqual('X\U00010427x\U0001044F'.swapcase(),
26569
+ 'x\U0001044FX\U00010427')
26571
def test_contains(self):
26572
# Testing Unicode contains method
26573
self.assertIn('a', 'abdb')
26574
@@ -930,10 +1091,18 @@
26575
for (x, y) in utfTests:
26576
self.assertEqual(x.encode('utf-7'), y)
26578
- # Unpaired surrogates not supported
26579
- self.assertRaises(UnicodeError, str, b'+3ADYAA-', 'utf-7')
26580
+ # Unpaired surrogates are passed through
26581
+ self.assertEqual('\uD801'.encode('utf-7'), b'+2AE-')
26582
+ self.assertEqual('\uD801x'.encode('utf-7'), b'+2AE-x')
26583
+ self.assertEqual('\uDC01'.encode('utf-7'), b'+3AE-')
26584
+ self.assertEqual('\uDC01x'.encode('utf-7'), b'+3AE-x')
26585
+ self.assertEqual(b'+2AE-'.decode('utf-7'), '\uD801')
26586
+ self.assertEqual(b'+2AE-x'.decode('utf-7'), '\uD801x')
26587
+ self.assertEqual(b'+3AE-'.decode('utf-7'), '\uDC01')
26588
+ self.assertEqual(b'+3AE-x'.decode('utf-7'), '\uDC01x')
26590
- self.assertEqual(str(b'+3ADYAA-', 'utf-7', 'replace'), '\ufffd\ufffd')
26591
+ self.assertEqual('\uD801\U000abcde'.encode('utf-7'), b'+2AHab9ze-')
26592
+ self.assertEqual(b'+2AHab9ze-'.decode('utf-7'), '\uD801\U000abcde')
26594
# Issue #2242: crash on some Windows/MSVC versions
26595
self.assertEqual(b'+\xc1'.decode('utf-7'), '\xc1')
26596
@@ -1598,6 +1767,42 @@
26598
self.assertRaises(TypeError, _string.formatter_field_name_split, 1)
26600
+ def test_encode_decimal(self):
26601
+ from _testcapi import unicode_encodedecimal
26602
+ self.assertEqual(unicode_encodedecimal('123'),
26604
+ self.assertEqual(unicode_encodedecimal('\u0663.\u0661\u0664'),
26606
+ self.assertEqual(unicode_encodedecimal("\N{EM SPACE}3.14\N{EN SPACE}"),
26608
+ self.assertRaises(UnicodeEncodeError,
26609
+ unicode_encodedecimal, "123\u20ac", "strict")
26610
+ self.assertEqual(unicode_encodedecimal("123\u20ac", "replace"),
26612
+ self.assertEqual(unicode_encodedecimal("123\u20ac", "ignore"),
26614
+ self.assertEqual(unicode_encodedecimal("123\u20ac", "xmlcharrefreplace"),
26616
+ self.assertEqual(unicode_encodedecimal("123\u20ac", "backslashreplace"),
26618
+ self.assertEqual(unicode_encodedecimal("123\u20ac\N{EM SPACE}", "replace"),
26620
+ self.assertEqual(unicode_encodedecimal("123\u20ac\u20ac", "replace"),
26622
+ self.assertEqual(unicode_encodedecimal("123\u20ac\u0660", "replace"),
26625
+ def test_transform_decimal(self):
26626
+ from _testcapi import unicode_transformdecimaltoascii as transform_decimal
26627
+ self.assertEqual(transform_decimal('123'),
26629
+ self.assertEqual(transform_decimal('\u0663.\u0661\u0664'),
26631
+ self.assertEqual(transform_decimal("\N{EM SPACE}3.14\N{EN SPACE}"),
26632
+ "\N{EM SPACE}3.14\N{EN SPACE}")
26633
+ self.assertEqual(transform_decimal('123\u20ac'),
26638
support.run_unittest(__name__)
26639
diff -r 137e45f15c0b Lib/test/test_urllib.py
26640
--- a/Lib/test/test_urllib.py
26641
+++ b/Lib/test/test_urllib.py
26646
+from base64 import b64encode
26648
def hexescape(char):
26649
"""Escape char as RFC 2396 specifies"""
26650
hex_repr = hex(ord(char))[2:].upper()
26653
return opener.open(url, data)
26656
+class FakeHTTPMixin(object):
26657
+ def fakehttp(self, fakedata):
26658
+ class FakeSocket(io.BytesIO):
26661
+ def sendall(self, data):
26662
+ FakeHTTPConnection.buf = data
26664
+ def makefile(self, *args, **kwds):
26665
+ self.io_refs += 1
26668
+ def read(self, amt=None):
26671
+ return io.BytesIO.read(self, amt)
26673
+ def readline(self, length=None):
26676
+ return io.BytesIO.readline(self, length)
26679
+ self.io_refs -= 1
26680
+ if self.io_refs == 0:
26681
+ io.BytesIO.close(self)
26683
+ class FakeHTTPConnection(http.client.HTTPConnection):
26685
+ # buffer to store data for verification in urlopen tests.
26688
+ def connect(self):
26689
+ self.sock = FakeSocket(fakedata)
26691
+ self._connection_class = http.client.HTTPConnection
26692
+ http.client.HTTPConnection = FakeHTTPConnection
26694
+ def unfakehttp(self):
26695
+ http.client.HTTPConnection = self._connection_class
26698
class urlopen_FileTests(unittest.TestCase):
26699
"""Test urlopen() opening a temporary file.
26701
@@ -115,6 +160,9 @@
26702
for line in self.returned_obj:
26703
self.assertEqual(line, self.text)
26705
+ def test_relativelocalfile(self):
26706
+ self.assertRaises(ValueError,urllib.request.urlopen,'./' + self.pathname)
26708
class ProxyTests(unittest.TestCase):
26711
@@ -139,35 +187,9 @@
26712
self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com')
26713
self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com'))
26715
-class urlopen_HttpTests(unittest.TestCase):
26716
+class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin):
26717
"""Test urlopen() opening a fake http connection."""
26719
- def fakehttp(self, fakedata):
26720
- class FakeSocket(io.BytesIO):
26722
- def sendall(self, str): pass
26723
- def makefile(self, *args, **kwds):
26724
- self.io_refs += 1
26726
- def read(self, amt=None):
26727
- if self.closed: return b""
26728
- return io.BytesIO.read(self, amt)
26729
- def readline(self, length=None):
26730
- if self.closed: return b""
26731
- return io.BytesIO.readline(self, length)
26733
- self.io_refs -= 1
26734
- if self.io_refs == 0:
26735
- io.BytesIO.close(self)
26736
- class FakeHTTPConnection(http.client.HTTPConnection):
26737
- def connect(self):
26738
- self.sock = FakeSocket(fakedata)
26739
- self._connection_class = http.client.HTTPConnection
26740
- http.client.HTTPConnection = FakeHTTPConnection
26742
- def unfakehttp(self):
26743
- http.client.HTTPConnection = self._connection_class
26745
def check_read(self, ver):
26746
self.fakehttp(b"HTTP/" + ver + b" 200 OK\r\n\r\nHello!")
26748
@@ -256,6 +278,25 @@
26752
+ def test_userpass_inurl_w_spaces(self):
26753
+ self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!")
26755
+ userpass = "a b:c d"
26756
+ url = "http://{}@python.org/".format(userpass)
26757
+ fakehttp_wrapper = http.client.HTTPConnection
26758
+ authorization = ("Authorization: Basic %s\r\n" %
26759
+ b64encode(userpass.encode("ASCII")).decode("ASCII"))
26760
+ fp = urlopen(url)
26761
+ # The authorization header must be in place
26762
+ self.assertIn(authorization, fakehttp_wrapper.buf.decode("UTF-8"))
26763
+ self.assertEqual(fp.readline(), b"Hello!")
26764
+ self.assertEqual(fp.readline(), b"")
26765
+ # the spaces are quoted in URL so no match
26766
+ self.assertNotEqual(fp.geturl(), url)
26767
+ self.assertEqual(fp.getcode(), 200)
26769
+ self.unfakehttp()
26771
class urlretrieve_FileTests(unittest.TestCase):
26772
"""Test urllib.urlretrieve() on local files"""
26774
@@ -394,6 +435,48 @@
26775
self.assertEqual(report[0][1], 8192)
26776
self.assertEqual(report[0][2], 8193)
26779
+class urlretrieve_HttpTests(unittest.TestCase, FakeHTTPMixin):
26780
+ """Test urllib.urlretrieve() using fake http connections"""
26782
+ def test_short_content_raises_ContentTooShortError(self):
26783
+ self.fakehttp(b'''HTTP/1.1 200 OK
26784
+Date: Wed, 02 Jan 2008 03:03:54 GMT
26785
+Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
26787
+Content-Length: 100
26788
+Content-Type: text/html; charset=iso-8859-1
26793
+ def _reporthook(par1, par2, par3):
26796
+ with self.assertRaises(urllib.error.ContentTooShortError):
26798
+ urllib.request.urlretrieve('http://example.com/',
26799
+ reporthook=_reporthook)
26801
+ self.unfakehttp()
26803
+ def test_short_content_raises_ContentTooShortError_without_reporthook(self):
26804
+ self.fakehttp(b'''HTTP/1.1 200 OK
26805
+Date: Wed, 02 Jan 2008 03:03:54 GMT
26806
+Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
26808
+Content-Length: 100
26809
+Content-Type: text/html; charset=iso-8859-1
26813
+ with self.assertRaises(urllib.error.ContentTooShortError):
26815
+ urllib.request.urlretrieve('http://example.com/')
26817
+ self.unfakehttp()
26820
class QuotingTests(unittest.TestCase):
26821
"""Tests for urllib.quote() and urllib.quote_plus()
26823
@@ -490,6 +573,7 @@
26824
result = urllib.parse.quote(partial_quote)
26825
self.assertEqual(expected, result,
26826
"using quote(): %r != %r" % (expected, result))
26827
+ result = urllib.parse.quote_plus(partial_quote)
26828
self.assertEqual(expected, result,
26829
"using quote_plus(): %r != %r" % (expected, result))
26831
@@ -1056,6 +1140,13 @@
26832
self.assertEqual(('user', 'a\fb'),urllib.parse.splitpasswd('user:a\fb'))
26833
self.assertEqual(('user', 'a\vb'),urllib.parse.splitpasswd('user:a\vb'))
26834
self.assertEqual(('user', 'a:b'),urllib.parse.splitpasswd('user:a:b'))
26835
+ self.assertEqual(('user', 'a b'),urllib.parse.splitpasswd('user:a b'))
26836
+ self.assertEqual(('user 2', 'ab'),urllib.parse.splitpasswd('user 2:ab'))
26837
+ self.assertEqual(('user+1', 'a+b'),urllib.parse.splitpasswd('user+1:a+b'))
26839
+ def test_thishost(self):
26840
+ """Test the urllib.request.thishost utility function returns a tuple"""
26841
+ self.assertIsInstance(urllib.request.thishost(), tuple)
26844
class URLopener_Tests(unittest.TestCase):
26845
@@ -1159,6 +1250,7 @@
26848
urlretrieve_FileTests,
26849
+ urlretrieve_HttpTests,
26853
diff -r 137e45f15c0b Lib/test/test_urllib2.py
26854
--- a/Lib/test/test_urllib2.py
26855
+++ b/Lib/test/test_urllib2.py
26856
@@ -878,7 +878,7 @@
26857
def test_http_doubleslash(self):
26858
# Checks the presence of any unnecessary double slash in url does not
26859
# break anything. Previously, a double slash directly after the host
26860
- # could could cause incorrect parsing.
26861
+ # could cause incorrect parsing.
26862
h = urllib.request.AbstractHTTPHandler()
26863
o = h.parent = MockOpener()
26865
@@ -1059,6 +1059,19 @@
26866
MockHeaders({"location": valid_url}))
26867
self.assertEqual(o.req.get_full_url(), valid_url)
26869
+ def test_relative_redirect(self):
26870
+ from_url = "http://example.com/a.html"
26871
+ relative_url = "/b.html"
26872
+ h = urllib.request.HTTPRedirectHandler()
26873
+ o = h.parent = MockOpener()
26874
+ req = Request(from_url)
26875
+ req.timeout = socket._GLOBAL_DEFAULT_TIMEOUT
26877
+ valid_url = urllib.parse.urljoin(from_url,relative_url)
26878
+ h.http_error_302(req, MockFile(), 302, "That's fine",
26879
+ MockHeaders({"location": valid_url}))
26880
+ self.assertEqual(o.req.get_full_url(), valid_url)
26882
def test_cookie_redirect(self):
26883
# cookies shouldn't leak into redirected requests
26884
from http.cookiejar import CookieJar
26885
@@ -1409,6 +1422,17 @@
26887
self.assertEqual(req.get_full_url(), url)
26889
+def test_HTTPError_interface():
26891
+ Issue 13211 reveals that HTTPError didn't implement the URLError
26892
+ interface even though HTTPError is a subclass of URLError.
26894
+ >>> err = urllib.error.HTTPError(msg='something bad happened', url=None, code=None, hdrs=None, fp=None)
26895
+ >>> assert hasattr(err, 'reason')
26897
+ 'something bad happened'
26900
def test_main(verbose=None):
26901
from test import test_urllib2
26902
support.run_doctest(test_urllib2, verbose)
26903
diff -r 137e45f15c0b Lib/test/test_urllib2net.py
26904
--- a/Lib/test/test_urllib2net.py
26905
+++ b/Lib/test/test_urllib2net.py
26906
@@ -125,6 +125,8 @@
26910
+ self.assertRaises(ValueError, urllib.request.urlopen,'./relative_path/to/file')
26912
# XXX Following test depends on machine configurations that are internal
26913
# to CNRI. Need to set up a public server with the right authentication
26914
# configuration for test purposes.
26915
diff -r 137e45f15c0b Lib/test/test_urlparse.py
26916
--- a/Lib/test/test_urlparse.py
26917
+++ b/Lib/test/test_urlparse.py
26919
RFC3986_BASE = 'http://a/b/c/d;p?q'
26920
SIMPLE_BASE = 'http://a/b/c/d'
26922
-# A list of test cases. Each test case is a a two-tuple that contains
26923
+# A list of test cases. Each test case is a two-tuple that contains
26924
# a string with the query and a dictionary with the expected result.
26926
parse_qsl_test_cases = [
26927
diff -r 137e45f15c0b Lib/test/test_xml_etree.py
26928
--- a/Lib/test/test_xml_etree.py
26929
+++ b/Lib/test/test_xml_etree.py
26930
@@ -754,6 +754,7 @@
26931
... print(action, elem.tag)
26932
... except ET.ParseError as v:
26935
junk after document element: line 1, column 12
26938
diff -r 137e45f15c0b Lib/test/test_xml_etree_c.py
26939
--- a/Lib/test/test_xml_etree_c.py
26940
+++ b/Lib/test/test_xml_etree_c.py
26942
# xml.etree test for cElementTree
26944
from test import support
26945
-from test.support import precisionbigmemtest, _2G
26946
+from test.support import bigmemtest, _2G
26949
cET = support.import_module('xml.etree.cElementTree')
26952
class MiscTests(unittest.TestCase):
26954
- @support.precisionbigmemtest(size=support._2G + 100, memuse=1)
26955
+ @support.bigmemtest(size=support._2G + 100, memuse=1)
26956
def test_length_overflow(self, size):
26957
if size < support._2G + 100:
26958
self.skipTest("not enough free memory, need at least 2 GB")
26959
diff -r 137e45f15c0b Lib/test/test_xmlrpc.py
26960
--- a/Lib/test/test_xmlrpc.py
26961
+++ b/Lib/test/test_xmlrpc.py
26963
(newdt,), m = xmlrpclib.loads(s, use_datetime=0)
26964
self.assertEqual(newdt, xmlrpclib.DateTime('00010210T11:41:23'))
26966
- def test_cmp_datetime_DateTime(self):
26967
- now = datetime.datetime.now()
26968
- dt = xmlrpclib.DateTime(now.timetuple())
26969
- self.assertTrue(dt == now)
26970
- self.assertTrue(now == dt)
26971
- then = now + datetime.timedelta(seconds=4)
26972
- self.assertTrue(then >= dt)
26973
- self.assertTrue(dt < then)
26975
def test_bug_1164912 (self):
26976
d = xmlrpclib.DateTime()
26977
((new_d,), dummy) = xmlrpclib.loads(xmlrpclib.dumps((d,),
26978
@@ -149,6 +140,9 @@
26980
[('Authorization', 'Basic dXNlcg==')], {}))
26982
+ def test_dump_bytes(self):
26983
+ self.assertRaises(TypeError, xmlrpclib.dumps, (b"my dog has fleas",))
26985
def test_ssl_presence(self):
26988
@@ -186,7 +180,7 @@
26989
self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, s)
26991
def test_dotted_attribute(self):
26992
- # this will raise AttirebuteError because code don't want us to use
26993
+ # this will raise AttributeError because code don't want us to use
26995
self.assertRaises(AttributeError,
26996
xmlrpc.server.resolve_dotted_attribute, str, '__add')
26997
@@ -233,6 +227,45 @@
26998
t2 = xmlrpclib._datetime(d)
26999
self.assertEqual(t1, tref)
27001
+ def test_comparison(self):
27002
+ now = datetime.datetime.now()
27003
+ dtime = xmlrpclib.DateTime(now.timetuple())
27005
+ # datetime vs. DateTime
27006
+ self.assertTrue(dtime == now)
27007
+ self.assertTrue(now == dtime)
27008
+ then = now + datetime.timedelta(seconds=4)
27009
+ self.assertTrue(then >= dtime)
27010
+ self.assertTrue(dtime < then)
27012
+ # str vs. DateTime
27013
+ dstr = now.strftime("%Y%m%dT%H:%M:%S")
27014
+ self.assertTrue(dtime == dstr)
27015
+ self.assertTrue(dstr == dtime)
27016
+ dtime_then = xmlrpclib.DateTime(then.timetuple())
27017
+ self.assertTrue(dtime_then >= dstr)
27018
+ self.assertTrue(dstr < dtime_then)
27020
+ # some other types
27021
+ dbytes = dstr.encode('ascii')
27022
+ dtuple = now.timetuple()
27023
+ with self.assertRaises(TypeError):
27025
+ with self.assertRaises(TypeError):
27027
+ with self.assertRaises(TypeError):
27028
+ dtime == bytearray(dbytes)
27029
+ with self.assertRaises(TypeError):
27031
+ with self.assertRaises(TypeError):
27032
+ dtime < float(1970)
27033
+ with self.assertRaises(TypeError):
27035
+ with self.assertRaises(TypeError):
27036
+ dtime <= bytearray(dbytes)
27037
+ with self.assertRaises(TypeError):
27040
class BinaryTestCase(unittest.TestCase):
27042
# XXX What should str(Binary(b"\xff")) return? I'm chosing "\xff"
27043
@@ -295,7 +328,7 @@
27044
global ADDR, PORT, URL
27045
ADDR, PORT = serv.socket.getsockname()
27046
#connect to IP address directly. This avoids socket.create_connection()
27047
- #trying to connect to to "localhost" using all address families, which
27048
+ #trying to connect to "localhost" using all address families, which
27049
#causes slowdown e.g. on vista which supports AF_INET6. The server listens
27051
URL = "http://%s:%d"%(ADDR, PORT)
27052
@@ -346,6 +379,10 @@
27053
class MyRequestHandler(requestHandler):
27056
+ class BrokenDispatcher:
27057
+ def _marshaled_dispatch(self, data, dispatch_method=None, path=None):
27058
+ raise RuntimeError("broken dispatcher")
27060
serv = MyXMLRPCServer(("localhost", 0), MyRequestHandler,
27061
logRequests=False, bind_and_activate=False)
27062
serv.socket.settimeout(3)
27063
@@ -354,7 +391,7 @@
27064
global ADDR, PORT, URL
27065
ADDR, PORT = serv.socket.getsockname()
27066
#connect to IP address directly. This avoids socket.create_connection()
27067
- #trying to connect to to "localhost" using all address families, which
27068
+ #trying to connect to "localhost" using all address families, which
27069
#causes slowdown e.g. on vista which supports AF_INET6. The server listens
27071
URL = "http://%s:%d"%(ADDR, PORT)
27072
@@ -366,6 +403,7 @@
27073
d.register_multicall_functions()
27074
serv.get_dispatcher(paths[0]).register_function(pow)
27075
serv.get_dispatcher(paths[1]).register_function(lambda x,y: x+y, 'add')
27076
+ serv.add_dispatcher("/is/broken", BrokenDispatcher())
27079
# handle up to 'numrequests' requests
27080
@@ -584,6 +622,10 @@
27081
# This avoids waiting for the socket timeout.
27082
self.test_simple1()
27084
+ def test_unicode_host(self):
27085
+ server = xmlrpclib.ServerProxy("http://%s:%d/RPC2" % (ADDR, PORT))
27086
+ self.assertEqual(server.add("a", "\xe9"), "a\xe9")
27088
class MultiPathServerTestCase(BaseServerTestCase):
27089
threadFunc = staticmethod(http_multi_server)
27091
@@ -591,11 +633,16 @@
27092
p = xmlrpclib.ServerProxy(URL+"/foo")
27093
self.assertEqual(p.pow(6,8), 6**8)
27094
self.assertRaises(xmlrpclib.Fault, p.add, 6, 8)
27096
def test_path2(self):
27097
p = xmlrpclib.ServerProxy(URL+"/foo/bar")
27098
self.assertEqual(p.add(6,8), 6+8)
27099
self.assertRaises(xmlrpclib.Fault, p.pow, 6, 8)
27101
+ def test_path3(self):
27102
+ p = xmlrpclib.ServerProxy(URL+"/is/broken")
27103
+ self.assertRaises(xmlrpclib.Fault, p.add, 6, 8)
27105
#A test case that verifies that a server using the HTTP/1.1 keep-alive mechanism
27106
#does indeed serve subsequent requests on the same connection
27107
class BaseKeepaliveServerTestCase(BaseServerTestCase):
27108
diff -r 137e45f15c0b Lib/test/test_xmlrpc_net.py
27109
--- a/Lib/test/test_xmlrpc_net.py
27110
+++ b/Lib/test/test_xmlrpc_net.py
27112
def test_current_time(self):
27113
# Get the current time from xmlrpc.com. This code exercises
27114
# the minimal HTTP functionality in xmlrpclib.
27115
+ self.skipTest("time.xmlrpc.com is unreliable")
27116
server = xmlrpclib.ServerProxy("http://time.xmlrpc.com/RPC2")
27118
t0 = server.currentTime.getCurrentTime()
27119
@@ -38,13 +39,13 @@
27120
def test_python_builders(self):
27121
# Get the list of builders from the XMLRPC buildbot interface at
27123
- self.skipTest("XMLRPC interface removed in Buildbot 0.8.2")
27124
server = xmlrpclib.ServerProxy("http://www.python.org/dev/buildbot/all/xmlrpc/")
27126
builders = server.getAllBuilders()
27127
except socket.error as e:
27128
self.skipTest("network error: %s" % e)
27130
+ self.addCleanup(lambda: server('close')())
27132
# Perform a minimal sanity check on the result, just to be sure
27133
# the request means what we think it means.
27134
diff -r 137e45f15c0b Lib/test/test_zipfile.py
27135
--- a/Lib/test/test_zipfile.py
27136
+++ b/Lib/test/test_zipfile.py
27137
@@ -507,6 +507,13 @@
27138
except zipfile.BadZipFile:
27139
self.assertTrue(zipfp2.fp is None, 'zipfp is not closed')
27141
+ def test_add_file_before_1980(self):
27142
+ # Set atime and mtime to 1970-01-01
27143
+ os.utime(TESTFN, (0, 0))
27144
+ with zipfile.ZipFile(TESTFN2, "w") as zipfp:
27145
+ self.assertRaises(ValueError, zipfp.write, TESTFN)
27148
@skipUnless(zlib, "requires zlib")
27149
def test_unicode_filenames(self):
27151
@@ -1053,6 +1060,10 @@
27153
self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, TESTFN, 'r')
27155
+ def test_create_zipinfo_before_1980(self):
27156
+ self.assertRaises(ValueError,
27157
+ zipfile.ZipInfo, 'seventies', (1979, 1, 1, 0, 0, 0))
27159
def tearDown(self):
27162
diff -r 137e45f15c0b Lib/test/test_zlib.py
2244
+from test import support
2245
+from test.script_helper import assert_python_ok
2247
+if not sysconfig.is_python_build():
2248
+ # XXX some installers do contain the tools, should we detect that
2249
+ # and run the tests in that case too?
2250
+ raise unittest.SkipTest('test irrelevant for an installed Python')
2252
+srcdir = sysconfig.get_config_var('projectbase')
2253
+basepath = os.path.join(os.getcwd(), srcdir, 'Tools')
2256
+class ReindentTests(unittest.TestCase):
2257
+ script = os.path.join(basepath, 'scripts', 'reindent.py')
2259
+ def test_noargs(self):
2260
+ assert_python_ok(self.script)
2262
+ def test_help(self):
2263
+ rc, out, err = assert_python_ok(self.script, '-h')
2264
+ self.assertEqual(out, b'')
2265
+ self.assertGreater(err, b'')
2269
+ support.run_unittest(ReindentTests)
2272
+if __name__ == '__main__':
2274
diff -r 7085403daf43 Lib/test/test_weakref.py
2275
--- a/Lib/test/test_weakref.py
2276
+++ b/Lib/test/test_weakref.py
2277
@@ -812,11 +812,71 @@
2279
return hash(self.arg)
2282
+ def __init__(self):
2286
class MappingTestCase(TestBase):
2290
+ def check_len_cycles(self, dict_type, cons):
2292
+ items = [RefCycle() for i in range(N)]
2293
+ dct = dict_type(cons(o) for o in items)
2294
+ # Keep an iterator alive
2298
+ except StopIteration:
2306
+ # one item may be kept alive inside the iterator
2307
+ self.assertIn(n1, (0, 1))
2308
+ self.assertEqual(n2, 0)
2310
+ def test_weak_keyed_len_cycles(self):
2311
+ self.check_len_cycles(weakref.WeakKeyDictionary, lambda k: (k, 1))
2313
+ def test_weak_valued_len_cycles(self):
2314
+ self.check_len_cycles(weakref.WeakValueDictionary, lambda k: (1, k))
2316
+ def check_len_race(self, dict_type, cons):
2317
+ # Extended sanity checks for len() in the face of cyclic collection
2318
+ self.addCleanup(gc.set_threshold, *gc.get_threshold())
2319
+ for th in range(1, 100):
2322
+ gc.set_threshold(th, th, th)
2323
+ items = [RefCycle() for i in range(N)]
2324
+ dct = dict_type(cons(o) for o in items)
2326
+ # All items will be collected at next garbage collection pass
2330
+ except StopIteration:
2335
+ self.assertGreaterEqual(n1, 0)
2336
+ self.assertLessEqual(n1, N)
2337
+ self.assertGreaterEqual(n2, 0)
2338
+ self.assertLessEqual(n2, n1)
2340
+ def test_weak_keyed_len_race(self):
2341
+ self.check_len_race(weakref.WeakKeyDictionary, lambda k: (k, 1))
2343
+ def test_weak_valued_len_race(self):
2344
+ self.check_len_race(weakref.WeakValueDictionary, lambda k: (1, k))
2346
def test_weak_values(self):
2348
# This exercises d.copy(), d.items(), d[], del d[], len(d).
2349
diff -r 7085403daf43 Lib/test/test_weakset.py
2350
--- a/Lib/test/test_weakset.py
2351
+++ b/Lib/test/test_weakset.py
2357
+ def __init__(self):
2361
class TestWeakSet(unittest.TestCase):
2364
# need to keep references to them
2365
self.items = [ustr(c) for c in ('a', 'b', 'c')]
2366
self.items2 = [ustr(c) for c in ('x', 'y', 'z')]
2367
+ self.ab_items = [ustr(c) for c in 'ab']
2368
+ self.abcde_items = [ustr(c) for c in 'abcde']
2369
+ self.def_items = [ustr(c) for c in 'def']
2370
+ self.ab_weakset = WeakSet(self.ab_items)
2371
+ self.abcde_weakset = WeakSet(self.abcde_items)
2372
+ self.def_weakset = WeakSet(self.def_items)
2373
self.letters = [ustr(c) for c in string.ascii_letters]
2374
self.s = WeakSet(self.items)
2375
self.d = dict.fromkeys(self.items)
2377
x = WeakSet(self.items + self.items2)
2379
self.assertEqual(self.s.union(c), x)
2381
+ self.assertEqual(len(u), len(self.items) + len(self.items2))
2384
+ self.assertEqual(len(u), len(self.items) + len(self.items2))
2387
i = self.s.union(self.items2)
2389
self.assertEqual(self.s | frozenset(self.items2), i)
2391
def test_intersection(self):
2392
- i = self.s.intersection(self.items2)
2393
+ s = WeakSet(self.letters)
2394
+ i = s.intersection(self.items2)
2395
for c in self.letters:
2396
- self.assertEqual(c in i, c in self.d and c in self.items2)
2397
- self.assertEqual(self.s, WeakSet(self.items))
2398
+ self.assertEqual(c in i, c in self.items2 and c in self.letters)
2399
+ self.assertEqual(s, WeakSet(self.letters))
2400
self.assertEqual(type(i), WeakSet)
2401
for C in set, frozenset, dict.fromkeys, list, tuple:
2403
- self.assertEqual(self.s.intersection(C(self.items2)), x)
2404
+ self.assertEqual(i.intersection(C(self.items)), x)
2405
+ self.assertEqual(len(i), len(self.items2))
2408
+ self.assertEqual(len(i), len(self.items2))
2410
def test_isdisjoint(self):
2411
self.assertTrue(self.s.isdisjoint(WeakSet(self.items2)))
2412
@@ -112,6 +132,10 @@
2413
self.assertEqual(self.s, WeakSet(self.items))
2414
self.assertEqual(type(i), WeakSet)
2415
self.assertRaises(TypeError, self.s.symmetric_difference, [[]])
2416
+ self.assertEqual(len(i), len(self.items) + len(self.items2))
2419
+ self.assertEqual(len(i), len(self.items) + len(self.items2))
2422
i = self.s.symmetric_difference(self.items2)
2423
@@ -119,22 +143,28 @@
2424
self.assertEqual(self.s ^ frozenset(self.items2), i)
2426
def test_sub_and_super(self):
2427
- pl, ql, rl = map(lambda s: [ustr(c) for c in s], ['ab', 'abcde', 'def'])
2428
- p, q, r = map(WeakSet, (pl, ql, rl))
2429
- self.assertTrue(p < q)
2430
- self.assertTrue(p <= q)
2431
- self.assertTrue(q <= q)
2432
- self.assertTrue(q > p)
2433
- self.assertTrue(q >= p)
2434
- self.assertFalse(q < r)
2435
- self.assertFalse(q <= r)
2436
- self.assertFalse(q > r)
2437
- self.assertFalse(q >= r)
2438
+ self.assertTrue(self.ab_weakset <= self.abcde_weakset)
2439
+ self.assertTrue(self.abcde_weakset <= self.abcde_weakset)
2440
+ self.assertTrue(self.abcde_weakset >= self.ab_weakset)
2441
+ self.assertFalse(self.abcde_weakset <= self.def_weakset)
2442
+ self.assertFalse(self.abcde_weakset >= self.def_weakset)
2443
self.assertTrue(set('a').issubset('abc'))
2444
self.assertTrue(set('abc').issuperset('a'))
2445
self.assertFalse(set('a').issubset('cbs'))
2446
self.assertFalse(set('cbs').issuperset('a'))
2448
+ def test_lt(self):
2449
+ self.assertTrue(self.ab_weakset < self.abcde_weakset)
2450
+ self.assertFalse(self.abcde_weakset < self.def_weakset)
2451
+ self.assertFalse(self.ab_weakset < self.ab_weakset)
2452
+ self.assertFalse(WeakSet() < WeakSet())
2454
+ def test_gt(self):
2455
+ self.assertTrue(self.abcde_weakset > self.ab_weakset)
2456
+ self.assertFalse(self.abcde_weakset > self.def_weakset)
2457
+ self.assertFalse(self.ab_weakset > self.ab_weakset)
2458
+ self.assertFalse(WeakSet() > WeakSet())
2461
# Create a nest of cycles to exercise overall ref count check
2462
s = WeakSet(Foo() for i in range(1000))
2463
@@ -359,6 +389,49 @@
2465
self.assertEqual(len(s), 0)
2467
+ def test_len_cycles(self):
2469
+ items = [RefCycle() for i in range(N)]
2470
+ s = WeakSet(items)
2475
+ except StopIteration:
2482
+ # one item may be kept alive inside the iterator
2483
+ self.assertIn(n1, (0, 1))
2484
+ self.assertEqual(n2, 0)
2486
+ def test_len_race(self):
2487
+ # Extended sanity checks for len() in the face of cyclic collection
2488
+ self.addCleanup(gc.set_threshold, *gc.get_threshold())
2489
+ for th in range(1, 100):
2492
+ gc.set_threshold(th, th, th)
2493
+ items = [RefCycle() for i in range(N)]
2494
+ s = WeakSet(items)
2496
+ # All items will be collected at next garbage collection pass
2500
+ except StopIteration:
2505
+ self.assertGreaterEqual(n1, 0)
2506
+ self.assertLessEqual(n1, N)
2507
+ self.assertGreaterEqual(n2, 0)
2508
+ self.assertLessEqual(n2, n1)
2511
def test_main(verbose=None):
2512
support.run_unittest(TestWeakSet)
2513
diff -r 7085403daf43 Lib/test/test_zlib.py
27163
2514
--- a/Lib/test/test_zlib.py
27164
2515
+++ b/Lib/test/test_zlib.py
27169
-from test.support import precisionbigmemtest, _1G, _4G
27170
+from test.support import bigmemtest, _1G, _4G
27172
zlib = support.import_module('zlib')
27174
@@ -177,16 +177,16 @@
27176
# Memory use of the following functions takes into account overallocation
27178
- @precisionbigmemtest(size=_1G + 1024 * 1024, memuse=3)
27179
+ @bigmemtest(size=_1G + 1024 * 1024, memuse=3)
27180
def test_big_compress_buffer(self, size):
27181
compress = lambda s: zlib.compress(s, 1)
27182
self.check_big_compress_buffer(size, compress)
27184
- @precisionbigmemtest(size=_1G + 1024 * 1024, memuse=2)
27185
+ @bigmemtest(size=_1G + 1024 * 1024, memuse=2)
27186
def test_big_decompress_buffer(self, size):
27187
self.check_big_decompress_buffer(size, zlib.decompress)
27189
- @precisionbigmemtest(size=_4G + 100, memuse=1)
27190
+ @bigmemtest(size=_4G + 100, memuse=1)
27191
def test_length_overflow(self, size):
27192
if size < _4G + 100:
27193
self.skipTest("not enough free memory, need at least 4 GB")
27194
@@ -511,19 +511,19 @@
27196
# Memory use of the following functions takes into account overallocation
27198
- @precisionbigmemtest(size=_1G + 1024 * 1024, memuse=3)
27199
+ @bigmemtest(size=_1G + 1024 * 1024, memuse=3)
27200
def test_big_compress_buffer(self, size):
27201
c = zlib.compressobj(1)
27202
compress = lambda s: c.compress(s) + c.flush()
27203
self.check_big_compress_buffer(size, compress)
27205
- @precisionbigmemtest(size=_1G + 1024 * 1024, memuse=2)
27206
+ @bigmemtest(size=_1G + 1024 * 1024, memuse=2)
27207
def test_big_decompress_buffer(self, size):
27208
d = zlib.decompressobj()
27209
decompress = lambda s: d.decompress(s) + d.flush()
27210
self.check_big_decompress_buffer(size, decompress)
27212
- @precisionbigmemtest(size=_4G + 100, memuse=1)
27213
+ @bigmemtest(size=_4G + 100, memuse=1)
27214
def test_length_overflow(self, size):
27215
if size < _4G + 100:
27216
self.skipTest("not enough free memory, need at least 4 GB")
27217
diff -r 137e45f15c0b Lib/threading.py
27218
--- a/Lib/threading.py
27219
+++ b/Lib/threading.py
27222
from time import time as _time, sleep as _sleep
27223
from traceback import format_exc as _format_exc
27224
-from collections import deque
27225
from _weakrefset import WeakSet
27227
# Note regarding PEP 8 compliant names
27228
@@ -418,9 +417,10 @@
27229
def wait(self, timeout=None):
27230
self._cond.acquire()
27232
- if not self._flag:
27233
- self._cond.wait(timeout)
27234
- return self._flag
27235
+ signaled = self._flag
27237
+ signaled = self._cond.wait(timeout)
27240
self._cond.release()
27242
@@ -435,7 +435,7 @@
27243
# to be cyclic. Threads are not allowed into it until it has fully drained
27244
# since the previous cycle. In addition, a 'resetting' state exists which is
27245
# similar to 'draining' except that threads leave with a BrokenBarrierError,
27246
-# and a 'broken' state in which all threads get get the exception.
27247
+# and a 'broken' state in which all threads get the exception.
27248
class Barrier(_Verbose):
27250
Barrier. Useful for synchronizing a fixed number of threads
27251
@@ -1068,21 +1068,18 @@
27252
current = current_thread()
27253
with _active_limbo_lock:
27254
for thread in _active.values():
27255
+ # Any lock/condition variable may be currently locked or in an
27256
+ # invalid state, so we reinitialize them.
27257
+ thread._reset_internal_locks()
27258
if thread is current:
27259
# There is only one active thread. We reset the ident to
27260
# its new value since it can have changed.
27261
ident = _get_ident()
27262
thread._ident = ident
27263
- # Any condition variables hanging off of the active thread may
27264
- # be in an invalid state, so we reinitialize them.
27265
- thread._reset_internal_locks()
27266
new_active[ident] = thread
27268
# All the others are already stopped.
27269
- # We don't call _Thread__stop() because it tries to acquire
27270
- # thread._Thread__block which could also have been held while
27272
- thread._stopped = True
27277
diff -r 137e45f15c0b Lib/timeit.py
27278
--- a/Lib/timeit.py
27279
+++ b/Lib/timeit.py
27280
@@ -127,7 +127,7 @@
27281
if isinstance(setup, str):
27282
setup = reindent(setup, 4)
27283
src = template % {'stmt': stmt, 'setup': setup}
27284
- elif hasattr(setup, '__call__'):
27285
+ elif callable(setup):
27286
src = template % {'stmt': stmt, 'setup': '_setup()'}
27287
ns['_setup'] = setup
27289
@@ -136,13 +136,13 @@
27290
code = compile(src, dummy_src_name, "exec")
27291
exec(code, globals(), ns)
27292
self.inner = ns["inner"]
27293
- elif hasattr(stmt, '__call__'):
27294
+ elif callable(stmt):
27296
if isinstance(setup, str):
27299
exec(_setup, globals(), ns)
27300
- elif not hasattr(setup, '__call__'):
27301
+ elif not callable(setup):
27302
raise ValueError("setup is neither a string nor callable")
27303
self.inner = _template_func(setup, stmt)
27305
diff -r 137e45f15c0b Lib/tkinter/__init__.py
27306
--- a/Lib/tkinter/__init__.py
27307
+++ b/Lib/tkinter/__init__.py
27308
@@ -1039,7 +1039,7 @@
27309
for k, v in cnf.items():
27311
if k[-1] == '_': k = k[:-1]
27312
- if hasattr(v, '__call__'):
27314
v = self._register(v)
27315
elif isinstance(v, (tuple, list)):
27317
@@ -1608,7 +1608,7 @@
27318
"""Bind function FUNC to command NAME for this widget.
27319
Return the function bound to NAME if None is given. NAME could be
27320
e.g. "WM_SAVE_YOURSELF" or "WM_DELETE_WINDOW"."""
27321
- if hasattr(func, '__call__'):
27322
+ if callable(func):
27323
command = self._register(func)
27326
@@ -3178,7 +3178,7 @@
27329
for k, v in cnf.items():
27330
- if hasattr(v, '__call__'):
27332
v = self._register(v)
27333
options = options + ('-'+k, v)
27334
self.tk.call(('image', 'create', imgtype, name,) + options)
27335
@@ -3201,7 +3201,7 @@
27336
for k, v in _cnfmerge(kw).items():
27338
if k[-1] == '_': k = k[:-1]
27339
- if hasattr(v, '__call__'):
27341
v = self._register(v)
27342
res = res + ('-'+k, v)
27343
self.tk.call((self.name, 'config') + res)
27344
diff -r 137e45f15c0b Lib/tkinter/tix.py
27345
--- a/Lib/tkinter/tix.py
27346
+++ b/Lib/tkinter/tix.py
27347
@@ -405,7 +405,7 @@
27350
for k, v in cnf.items():
27351
- if hasattr(v, '__call__'):
27353
v = self._register(v)
27354
options = options + ('-'+k, v)
27355
return master.tk.call(('image', 'create', imgtype,) + options)
27356
@@ -1554,8 +1554,8 @@
27357
'''This command is used to indicate whether the entry given by
27358
entryPath has children entries and whether the children are visible. mode
27359
must be one of open, close or none. If mode is set to open, a (+)
27360
- indicator is drawn next the the entry. If mode is set to close, a (-)
27361
- indicator is drawn next the the entry. If mode is set to none, no
27362
+ indicator is drawn next the entry. If mode is set to close, a (-)
27363
+ indicator is drawn next the entry. If mode is set to none, no
27364
indicators will be drawn for this entry. The default mode is none. The
27365
open mode indicates the entry has hidden children and this entry can be
27366
opened by the user. The close mode indicates that all the children of the
27367
@@ -1873,13 +1873,13 @@
27368
return self.tk.call(self, 'info', 'bbox', x, y)
27370
def move_column(self, from_, to, offset):
27371
- """Moves the the range of columns from position FROM through TO by
27372
+ """Moves the range of columns from position FROM through TO by
27373
the distance indicated by OFFSET. For example, move_column(2, 4, 1)
27374
moves the columns 2,3,4 to columns 3,4,5."""
27375
self.tk.call(self, 'move', 'column', from_, to, offset)
27377
def move_row(self, from_, to, offset):
27378
- """Moves the the range of rows from position FROM through TO by
27379
+ """Moves the range of rows from position FROM through TO by
27380
the distance indicated by OFFSET.
27381
For example, move_row(2, 4, 1) moves the rows 2,3,4 to rows 3,4,5."""
27382
self.tk.call(self, 'move', 'row', from_, to, offset)
27383
@@ -1938,7 +1938,7 @@
27385
Specifies the paddings to the top of a row.
27387
- Specifies the paddings to the the bottom of a row.
27388
+ Specifies the paddings to the bottom of a row.
27390
Specifies the height of a row.
27391
Val may be: "auto" -- the height of the row is set the
27392
diff -r 137e45f15c0b Lib/tkinter/ttk.py
27393
--- a/Lib/tkinter/ttk.py
27394
+++ b/Lib/tkinter/ttk.py
27397
tilelib = os.environ.get('TILE_LIBRARY')
27399
- # append custom tile path to the the list of directories that
27400
+ # append custom tile path to the list of directories that
27401
# Tcl uses when attempting to resolve packages with the package
27404
diff -r 137e45f15c0b Lib/token.py
27408
# To update the symbols in this file, 'cd' to the top directory of
27409
# the python source tree after building the interpreter and run:
27411
-# python Lib/token.py
27412
+# ./python Lib/token.py
27414
#--start constants--
27416
@@ -35,36 +35,36 @@
27438
-CIRCUMFLEXEQUAL = 44
27439
-LEFTSHIFTEQUAL = 45
27440
-RIGHTSHIFTEQUAL = 46
27441
-DOUBLESTAREQUAL = 47
27443
-DOUBLESLASHEQUAL = 49
27468
+CIRCUMFLEXEQUAL = 43
27469
+LEFTSHIFTEQUAL = 44
27470
+RIGHTSHIFTEQUAL = 45
27471
+DOUBLESTAREQUAL = 46
27473
+DOUBLESLASHEQUAL = 48
27483
diff -r 137e45f15c0b Lib/turtle.py
27484
--- a/Lib/turtle.py
27485
+++ b/Lib/turtle.py
27487
docstrings to disc, so it can serve as a template for translations.
27489
Behind the scenes there are some features included with possible
27490
-extensions in in mind. These will be commented and documented elsewhere.
27491
+extensions in mind. These will be commented and documented elsewhere.
27495
@@ -905,7 +905,7 @@
27496
>>> poly = ((0,0),(10,-5),(0,10),(-10,-5))
27497
>>> s = Shape("compound")
27498
>>> s.addcomponent(poly, "red", "blue")
27499
- ### .. add more components and then use register_shape()
27500
+ >>> # .. add more components and then use register_shape()
27502
if self._type != "compound":
27503
raise TurtleGraphicsError("Cannot add component to %s Shape"
27504
@@ -1003,7 +1003,7 @@
27505
no backgroundimage, no eventbindings and tracing on.
27507
Example (for a TurtleScreen instance named screen):
27509
+ >>> screen.clear()
27511
Note: this method is not available as function.
27513
@@ -1077,8 +1077,8 @@
27514
Example (for a TurtleScreen instance named screen):
27515
>>> screen.setworldcoordinates(-10,-0.5,50,1.5)
27516
>>> for _ in range(36):
27522
if self.mode() != "world":
27524
@@ -1182,7 +1182,7 @@
27525
>>> screen.colormode()
27527
>>> screen.colormode(255)
27528
- >>> turtle.pencolor(240,160,80)
27529
+ >>> pencolor(240,160,80)
27532
return self._colormode
27533
@@ -1250,9 +1250,9 @@
27534
>>> screen.tracer(8, 25)
27536
>>> for i in range(200):
27545
return self._tracing
27546
@@ -1279,7 +1279,7 @@
27547
self._delayvalue = int(delay)
27549
def _incrementudc(self):
27550
- "Increment upadate counter."""
27551
+ """Increment upadate counter."""
27552
if not TurtleScreen._RUNNING:
27553
TurtleScreen._RUNNNING = True
27555
@@ -1347,16 +1347,12 @@
27556
clicked point on the canvas.
27557
num -- the number of the mouse-button, defaults to 1
27559
- Example (for a TurtleScreen instance named screen
27560
- and a Turtle instance named turtle):
27562
- >>> screen.onclick(turtle.goto)
27564
- ### Subsequently clicking into the TurtleScreen will
27565
- ### make the turtle move to the clicked point.
27566
+ Example (for a TurtleScreen instance named screen)
27568
+ >>> screen.onclick(goto)
27569
+ >>> # Subsequently clicking into the TurtleScreen will
27570
+ >>> # make the turtle move to the clicked point.
27571
>>> screen.onclick(None)
27573
- ### event-binding will be removed
27575
self._onscreenclick(fun, btn, add)
27577
@@ -1370,20 +1366,18 @@
27578
In order to be able to register key-events, TurtleScreen
27579
must have focus. (See method listen.)
27581
- Example (for a TurtleScreen instance named screen
27582
- and a Turtle instance named turtle):
27583
+ Example (for a TurtleScreen instance named screen):
27593
>>> screen.onkey(f, "Up")
27594
>>> screen.listen()
27596
- ### Subsequently the turtle can be moved by
27597
- ### repeatedly pressing the up-arrow key,
27598
- ### consequently drawing a hexagon
27599
+ Subsequently the turtle can be moved by repeatedly pressing
27600
+ the up-arrow key, consequently drawing a hexagon
27604
if key in self._keys:
27605
@@ -1407,16 +1401,15 @@
27606
and a Turtle instance named turtle):
27612
- >>> screen.onkey(f, "Up")
27616
+ >>> screen.onkeypress(f, "Up")
27617
>>> screen.listen()
27619
- ### Subsequently the turtle can be moved by
27620
- ### repeatedly pressing the up-arrow key,
27621
- ### or by keeping pressed the up-arrow key.
27622
- ### consequently drawing a hexagon.
27623
+ Subsequently the turtle can be moved by repeatedly pressing
27624
+ the up-arrow key, or by keeping pressed the up-arrow key.
27625
+ consequently drawing a hexagon.
27628
if key in self._keys:
27629
@@ -1448,12 +1441,12 @@
27636
- screen.ontimer(f, 250)
27638
- >>> f() ### makes the turtle marching around
27642
+ ... screen.ontimer(f, 250)
27644
+ >>> f() # makes the turtle marching around
27645
>>> running = False
27647
self._ontimer(fun, t)
27648
@@ -1497,7 +1490,7 @@
27650
Example (for a Turtle instance named turtle):
27651
>>> turtle.screensize(2000,1500)
27652
- ### e. g. to search for an erroneously escaped turtle ;-)
27653
+ >>> # e.g. to search for an erroneously escaped turtle ;-)
27655
return self._resize(canvwidth, canvheight, bg)
27657
@@ -2085,7 +2078,7 @@
27658
Example (for a Turtle instance named turtle):
27659
>>> turtle.pensize()
27661
- turtle.pensize(10) # from here on lines of width 10 are drawn
27662
+ >>> turtle.pensize(10) # from here on lines of width 10 are drawn
27665
return self._pensize
27666
@@ -2560,7 +2553,7 @@
27667
"""Delete the turtle's drawings and restore its default values.
27672
Delete the turtle's drawings from the screen, re-center the turtle
27673
and set variables to the default values.
27675
@@ -2607,7 +2600,7 @@
27677
Example (for a Turtle instance named turtle):
27678
>>> while undobufferentries():
27682
if self.undobuffer is None:
27684
@@ -2683,9 +2676,9 @@
27685
>>> turtle.tracer(8, 25)
27687
>>> for i in range(200):
27691
+ ... turtle.fd(dist)
27692
+ ... turtle.rt(90)
27695
return self.screen.tracer(flag, delay)
27697
@@ -2883,7 +2876,6 @@
27698
>>> turtle.shapesize(5,2)
27699
>>> turtle.tilt(45)
27700
>>> turtle.tiltangle()
27704
tilt = -self._tilt * (180.0/math.pi) * self._angleOrient
27705
@@ -2928,7 +2920,7 @@
27706
>>> turtle.shapesize(4,2)
27707
>>> turtle.shearfactor(-0.5)
27708
>>> turtle.shapetransform()
27709
- >>> (4.0, -1.0, -0.0, 2.0)
27710
+ (4.0, -1.0, -0.0, 2.0)
27712
if t11 is t12 is t21 is t22 is None:
27713
return self._shapetrafo
27714
@@ -3126,7 +3118,7 @@
27716
Example (for a Turtle instance named turtle):
27717
>>> for i in range(8):
27718
- turtle.stamp(); turtle.fd(30)
27719
+ ... turtle.stamp(); turtle.fd(30)
27721
>>> turtle.clearstamps(2)
27722
>>> turtle.clearstamps(-2)
27723
@@ -3302,9 +3294,9 @@
27724
Example (for a Turtle instance named turtle):
27725
>>> turtle.begin_fill()
27726
>>> if turtle.filling():
27727
- turtle.pensize(5)
27729
- turtle.pensize(3)
27730
+ ... turtle.pensize(5)
27732
+ ... turtle.pensize(3)
27734
return isinstance(self._fillpath, list)
27736
@@ -3534,9 +3526,9 @@
27737
Example for the anonymous turtle, i. e. the procedural way:
27739
>>> def turn(x, y):
27742
- >>> onclick(turn) # Now clicking into the turtle will turn it.
27745
+ >>> onclick(turn) # Now clicking into the turtle will turn it.
27746
>>> onclick(None) # event-binding will be removed
27748
self.screen._onclick(self.turtle._item, fun, btn, add)
27749
@@ -3552,16 +3544,17 @@
27751
Example (for a MyTurtle instance named joe):
27752
>>> class MyTurtle(Turtle):
27753
- def glow(self,x,y):
27754
- self.fillcolor("red")
27755
- def unglow(self,x,y):
27756
- self.fillcolor("")
27758
+ ... def glow(self,x,y):
27759
+ ... self.fillcolor("red")
27760
+ ... def unglow(self,x,y):
27761
+ ... self.fillcolor("")
27763
>>> joe = MyTurtle()
27764
>>> joe.onclick(joe.glow)
27765
>>> joe.onrelease(joe.unglow)
27766
- ### clicking on joe turns fillcolor red,
27767
- ### unclicking turns it to transparent.
27769
+ Clicking on joe turns fillcolor red, unclicking turns it to
27772
self.screen._onrelease(self.turtle._item, fun, btn, add)
27774
@@ -3580,9 +3573,9 @@
27775
Example (for a Turtle instance named turtle):
27776
>>> turtle.ondrag(turtle.goto)
27778
- ### Subsequently clicking and dragging a Turtle will
27779
- ### move it across the screen thereby producing handdrawings
27780
- ### (if pen is down).
27781
+ Subsequently clicking and dragging a Turtle will move it
27782
+ across the screen thereby producing handdrawings (if pen is
27785
self.screen._ondrag(self.turtle._item, fun, btn, add)
27787
@@ -3630,10 +3623,11 @@
27789
Example (for a Turtle instance named turtle):
27790
>>> for i in range(4):
27791
- turtle.fd(50); turtle.lt(80)
27793
+ ... turtle.fd(50); turtle.lt(80)
27795
>>> for i in range(8):
27797
+ ... turtle.undo()
27800
if self.undobuffer is None:
27802
diff -r 137e45f15c0b Lib/unittest/loader.py
27803
--- a/Lib/unittest/loader.py
27804
+++ b/Lib/unittest/loader.py
27805
@@ -113,7 +113,7 @@
27806
return self.suiteClass([inst])
27807
elif isinstance(obj, suite.TestSuite):
27809
- if hasattr(obj, '__call__'):
27810
+ if callable(obj):
27812
if isinstance(test, suite.TestSuite):
27814
@@ -138,9 +138,8 @@
27815
def isTestMethod(attrname, testCaseClass=testCaseClass,
27816
prefix=self.testMethodPrefix):
27817
return attrname.startswith(prefix) and \
27818
- hasattr(getattr(testCaseClass, attrname), '__call__')
27819
- testFnNames = testFnNames = list(filter(isTestMethod,
27820
- dir(testCaseClass)))
27821
+ callable(getattr(testCaseClass, attrname))
27822
+ testFnNames = list(filter(isTestMethod, dir(testCaseClass)))
27823
if self.sortTestMethodsUsing:
27824
testFnNames.sort(key=functools.cmp_to_key(self.sortTestMethodsUsing))
27826
diff -r 137e45f15c0b Lib/unittest/suite.py
27827
--- a/Lib/unittest/suite.py
27828
+++ b/Lib/unittest/suite.py
27831
def addTest(self, test):
27833
- if not hasattr(test, '__call__'):
27834
+ if not callable(test):
27835
raise TypeError("{} is not callable".format(repr(test)))
27836
if isinstance(test, type) and issubclass(test,
27837
(case.TestCase, TestSuite)):
27838
diff -r 137e45f15c0b Lib/urllib/error.py
27839
--- a/Lib/urllib/error.py
27840
+++ b/Lib/urllib/error.py
27843
return 'HTTP Error %s: %s' % (self.code, self.msg)
27845
+ # since URLError specifies a .reason attribute, HTTPError should also
27846
+ # provide this attribute. See issue13211 for discussion.
27848
+ def reason(self):
27851
# exception raised when downloaded size does not match content-length
27852
class ContentTooShortError(URLError):
27853
def __init__(self, message, content):
27854
diff -r 137e45f15c0b Lib/urllib/request.py
27855
--- a/Lib/urllib/request.py
27856
+++ b/Lib/urllib/request.py
27857
@@ -552,12 +552,11 @@
27858
# For security reasons we don't allow redirection to anything other
27859
# than http, https or ftp.
27861
- if not urlparts.scheme in ('http', 'https', 'ftp'):
27862
- raise HTTPError(newurl, code,
27864
- " - Redirection to url '%s' is not allowed" %
27867
+ if urlparts.scheme not in ('http', 'https', 'ftp', ''):
27870
+ "%s - Redirection to url '%s' is not allowed" % (msg, newurl),
27873
if not urlparts.path:
27874
urlparts = list(urlparts)
27875
@@ -722,7 +721,7 @@
27876
# uri could be a single URI or a sequence
27877
if isinstance(uri, str):
27879
- if not realm in self.passwd:
27880
+ if realm not in self.passwd:
27881
self.passwd[realm] = {}
27882
for default_port in True, False:
27883
reduced_uri = tuple(
27884
@@ -1590,9 +1589,9 @@
27888
+ if "content-length" in headers:
27889
+ size = int(headers["Content-Length"])
27891
- if "content-length" in headers:
27892
- size = int(headers["Content-Length"])
27893
reporthook(blocknum, bs, size)
27895
block = fp.read(bs)
27896
@@ -1662,13 +1661,13 @@
27897
if not host: raise IOError('http error', 'no host given')
27901
+ proxy_passwd = unquote(proxy_passwd)
27902
proxy_auth = base64.b64encode(proxy_passwd.encode()).decode('ascii')
27908
+ user_passwd = unquote(user_passwd)
27909
auth = base64.b64encode(user_passwd.encode()).decode('ascii')
27912
@@ -1733,7 +1732,6 @@
27914
def http_error_default(self, url, fp, errcode, errmsg, headers):
27915
"""Default error handler: close the connection and raise IOError."""
27918
raise HTTPError(url, errcode, errmsg, headers, None)
27920
@@ -1783,6 +1781,8 @@
27922
if file[:1] == '/':
27923
urlfile = 'file://' + file
27924
+ elif file[:2] == './':
27925
+ raise ValueError("local file url may start with / or file:. Unknown url of type: %s" % url)
27926
return addinfourl(open(localname, 'rb'), headers, urlfile)
27927
raise URLError('local file error', 'not on local host')
27929
@@ -1823,7 +1823,7 @@
27930
del self.ftpcache[k]
27933
- if not key in self.ftpcache:
27934
+ if key not in self.ftpcache:
27935
self.ftpcache[key] = \
27936
ftpwrapper(user, passwd, host, port, dirs)
27937
if not file: type = 'D'
27938
@@ -1873,7 +1873,6 @@
27939
time.gmtime(time.time())))
27940
msg.append('Content-type: %s' % type)
27941
if encoding == 'base64':
27943
# XXX is this encoding/decoding ok?
27944
data = base64.decodebytes(data.encode('ascii')).decode('latin1')
27946
@@ -1924,7 +1923,6 @@
27947
newurl = headers['uri']
27953
# In case the server sent a relative URL, join with original:
27954
@@ -1938,7 +1936,7 @@
27955
# We are using newer HTTPError with older redirect_internal method
27956
# This older method will get deprecated in 3.3
27958
- if not urlparts.scheme in ('http', 'https', 'ftp'):
27959
+ if urlparts.scheme not in ('http', 'https', 'ftp', ''):
27960
raise HTTPError(newurl, errcode,
27962
" Redirection to url '%s' is not allowed." % newurl,
27963
@@ -1965,7 +1963,7 @@
27965
"""Error 401 -- authentication required.
27966
This function supports Basic authentication only."""
27967
- if not 'www-authenticate' in headers:
27968
+ if 'www-authenticate' not in headers:
27969
URLopener.http_error_default(self, url, fp,
27970
errcode, errmsg, headers)
27971
stuff = headers['www-authenticate']
27972
@@ -1991,7 +1989,7 @@
27974
"""Error 407 -- proxy authentication required.
27975
This function supports Basic authentication only."""
27976
- if not 'proxy-authenticate' in headers:
27977
+ if 'proxy-authenticate' not in headers:
27978
URLopener.http_error_default(self, url, fp,
27979
errcode, errmsg, headers)
27980
stuff = headers['proxy-authenticate']
27981
@@ -2116,7 +2114,7 @@
27982
"""Return the IP addresses of the current host."""
27984
if _thishost is None:
27985
- _thishost = tuple(socket.gethostbyname_ex(socket.gethostname()[2]))
27986
+ _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2])
27990
diff -r 137e45f15c0b Lib/warnings.py
27991
--- a/Lib/warnings.py
27992
+++ b/Lib/warnings.py
27993
@@ -259,7 +259,7 @@
27994
raise RuntimeError(
27995
"Unrecognized action (%r) in warnings.filters:\n %s" %
27997
- if not hasattr(showwarning, "__call__"):
27998
+ if not callable(showwarning):
27999
raise TypeError("warnings.showwarning() must be set to a "
28000
"function or method")
28001
# Print message and context
28002
diff -r 137e45f15c0b Lib/xml/dom/minidom.py
28003
--- a/Lib/xml/dom/minidom.py
28004
+++ b/Lib/xml/dom/minidom.py
28005
@@ -836,10 +836,16 @@
28006
_write_data(writer, attrs[a_name].value)
28008
if self.childNodes:
28009
- writer.write(">%s"%(newl))
28010
- for node in self.childNodes:
28011
- node.writexml(writer,indent+addindent,addindent,newl)
28012
- writer.write("%s</%s>%s" % (indent,self.tagName,newl))
28013
+ writer.write(">")
28014
+ if (len(self.childNodes) == 1 and
28015
+ self.childNodes[0].nodeType == Node.TEXT_NODE):
28016
+ self.childNodes[0].writexml(writer, '', '', '')
28018
+ writer.write(newl)
28019
+ for node in self.childNodes:
28020
+ node.writexml(writer, indent+addindent, addindent, newl)
28021
+ writer.write(indent)
28022
+ writer.write("</%s>%s" % (self.tagName, newl))
28024
writer.write("/>%s"%(newl))
28026
@@ -1061,7 +1067,7 @@
28029
def writexml(self, writer, indent="", addindent="", newl=""):
28030
- _write_data(writer, "%s%s%s"%(indent, self.data, newl))
28031
+ _write_data(writer, "%s%s%s" % (indent, self.data, newl))
28033
# DOM Level 3 (WD 9 April 2002)
28035
diff -r 137e45f15c0b Lib/xml/etree/ElementTree.py
28036
--- a/Lib/xml/etree/ElementTree.py
28037
+++ b/Lib/xml/etree/ElementTree.py
28038
@@ -1250,6 +1250,7 @@
28039
self._close_file = close_source
28042
+ self._error = None
28043
self.root = self._root = None
28044
self._parser = parser
28045
# wire up the parser for event reporting
28046
@@ -1291,24 +1292,31 @@
28049
item = self._events[self._index]
28053
- if self._parser is None:
28054
- self.root = self._root
28055
- if self._close_file:
28056
- self._file.close()
28057
- raise StopIteration
28058
- # load event buffer
28059
- del self._events[:]
28061
- data = self._file.read(16384)
28066
+ self._error = None
28068
+ if self._parser is None:
28069
+ self.root = self._root
28070
+ if self._close_file:
28071
+ self._file.close()
28072
+ raise StopIteration
28073
+ # load event buffer
28074
+ del self._events[:]
28076
+ data = self._file.read(16384)
28079
self._parser.feed(data)
28081
- self._root = self._parser.close()
28082
- self._parser = None
28083
+ except SyntaxError as exc:
28084
+ self._error = exc
28086
- self._index = self._index + 1
28088
+ self._root = self._parser.close()
28089
+ self._parser = None
28091
def __iter__(self):
28093
diff -r 137e45f15c0b Lib/xmlrpc/client.py
28094
--- a/Lib/xmlrpc/client.py
28095
+++ b/Lib/xmlrpc/client.py
28097
# OF THIS SOFTWARE.
28098
# --------------------------------------------------------------------
28101
-# things to look into some day:
28103
-# TODO: sort out True/False/boolean issues for Python 2.3
28106
An XML-RPC client interface for Python.
28108
@@ -120,8 +115,7 @@
28110
Exported constants:
28116
Exported functions:
28118
@@ -133,7 +127,8 @@
28119
name (None if not present).
28122
-import re, time, operator
28126
from xml.parsers import expat
28128
@@ -230,7 +225,7 @@
28130
# Indicates an XML-RPC fault response package. This exception is
28131
# raised by the unmarshalling layer, if the XML-RPC response contains
28132
-# a fault string. This exception can also used as a class, to
28133
+# a fault string. This exception can also be used as a class, to
28134
# generate a fault XML-RPC message.
28136
# @param faultCode The XML-RPC fault code.
28137
@@ -243,10 +238,7 @@
28138
self.faultCode = faultCode
28139
self.faultString = faultString
28140
def __repr__(self):
28142
- "<Fault %s: %s>" %
28143
- (self.faultCode, repr(self.faultString))
28145
+ return "<Fault %s: %r>" % (self.faultCode, self.faultString)
28147
# --------------------------------------------------------------------
28149
@@ -302,7 +294,7 @@
28150
elif datetime and isinstance(other, datetime.datetime):
28152
o = other.strftime("%Y%m%dT%H:%M:%S")
28153
- elif isinstance(other, (str, unicode)):
28154
+ elif isinstance(other, str):
28157
elif hasattr(other, "timetuple"):
28158
@@ -352,7 +344,7 @@
28161
def __repr__(self):
28162
- return "<DateTime %s at %x>" % (repr(self.value), id(self))
28163
+ return "<DateTime %r at %x>" % (self.value, id(self))
28165
def decode(self, data):
28166
self.value = str(data).strip()
28167
@@ -378,9 +370,6 @@
28169
# @param data An 8-bit string containing arbitrary data.
28175
"""Wrapper for binary data."""
28177
@@ -514,9 +503,7 @@
28178
f = self.dispatch[type(value)]
28180
# check if this object can be marshalled as a structure
28184
+ if not hasattr(value, '__dict__'):
28185
raise TypeError("cannot marshal %s objects" % type(value))
28186
# check if this class is a sub-class of a basic type,
28187
# because we don't know how to marshal these types
28188
@@ -564,12 +551,6 @@
28189
write("</double></value>\n")
28190
dispatch[float] = dump_double
28192
- def dump_string(self, value, write, escape=escape):
28193
- write("<value><string>")
28194
- write(escape(value))
28195
- write("</string></value>\n")
28196
- dispatch[bytes] = dump_string
28198
def dump_unicode(self, value, write, escape=escape):
28199
write("<value><string>")
28200
write(escape(value))
28201
@@ -1198,7 +1179,6 @@
28202
auth, host = urllib.parse.splituser(host)
28206
auth = urllib.parse.unquote_to_bytes(auth)
28207
auth = base64.encodebytes(auth).decode("utf-8")
28208
auth = "".join(auth.split()) # get rid of whitespace
28209
diff -r 137e45f15c0b Lib/xmlrpc/server.py
2517
# Issue #10276 - check that inputs >=4GB are handled correctly.
2518
class ChecksumBigBufferTestCase(unittest.TestCase):
2521
- with open(support.TESTFN, "wb+") as f:
2525
- self.mapping = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
2527
- def tearDown(self):
2528
- self.mapping.close()
2529
- support.unlink(support.TESTFN)
2531
- @unittest.skipUnless(mmap, "mmap() is not available.")
2532
- @unittest.skipUnless(sys.maxsize > _4G, "Can't run on a 32-bit system.")
2533
- @unittest.skipUnless(support.is_resource_enabled("largefile"),
2534
- "May use lots of disk space.")
2535
- def test_big_buffer(self):
2536
- self.assertEqual(zlib.crc32(self.mapping), 3058686908)
2537
- self.assertEqual(zlib.adler32(self.mapping), 82837919)
2538
+ @bigmemtest(size=_4G + 4, memuse=1, dry_run=False)
2539
+ def test_big_buffer(self, size):
2540
+ data = b"nyan" * (_1G + 1)
2541
+ self.assertEqual(zlib.crc32(data), 1044521549)
2542
+ self.assertEqual(zlib.adler32(data), 2256789997)
2545
class ExceptionTestCase(unittest.TestCase):
2546
diff -r 7085403daf43 Lib/weakref.py
2547
--- a/Lib/weakref.py
2548
+++ b/Lib/weakref.py
2553
- return sum(wr() is not None for wr in self.data.values())
2554
+ return len(self.data) - len(self._pending_removals)
2556
def __contains__(self, key):
2559
return self.data[ref(key)]
2562
- return len(self.data)
2563
+ return len(self.data) - len(self._pending_removals)
2566
return "<WeakKeyDictionary at %s>" % id(self)
2567
diff -r 7085403daf43 Lib/xmlrpc/server.py
28210
2568
--- a/Lib/xmlrpc/server.py
28211
2569
+++ b/Lib/xmlrpc/server.py
28212
@@ -149,7 +149,7 @@
28214
return [member for member in dir(obj)
28215
if not member.startswith('_') and
28216
- hasattr(getattr(obj, member), '__call__')]
28217
+ callable(getattr(obj, member))]
28219
class SimpleXMLRPCDispatcher:
28220
"""Mix-in class that dispatches XML-RPC requests.
28221
@@ -329,7 +329,6 @@
28226
return pydoc.getdoc(method)
28228
def system_multicall(self, call_list):
28229
@@ -560,7 +559,7 @@
28230
Simple XML-RPC server that allows functions and a single instance
28231
to be installed to handle requests. The default implementation
28232
attempts to dispatch XML-RPC calls to the functions or instance
28233
- installed in the server. Override the _dispatch method inhereted
28234
+ installed in the server. Override the _dispatch method inherited
28235
from SimpleXMLRPCDispatcher to change this behavior.
28238
@@ -602,7 +601,7 @@
28239
encoding, bind_and_activate)
28240
self.dispatchers = {}
28241
self.allow_none = allow_none
28242
- self.encoding = encoding
28243
+ self.encoding = encoding or 'utf-8'
28245
def add_dispatcher(self, path, dispatcher):
28246
self.dispatchers[path] = dispatcher
28247
@@ -620,9 +619,10 @@
28248
# (each dispatcher should have handled their own
28250
exc_type, exc_value = sys.exc_info()[:2]
28251
- response = xmlrpclib.dumps(
28252
- xmlrpclib.Fault(1, "%s:%s" % (exc_type, exc_value)),
28253
+ response = dumps(
28254
+ Fault(1, "%s:%s" % (exc_type, exc_value)),
28255
encoding=self.encoding, allow_none=self.allow_none)
28256
+ response = response.encode(self.encoding)
28259
class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher):
28260
diff -r 137e45f15c0b Lib/zipfile.py
28261
--- a/Lib/zipfile.py
28262
+++ b/Lib/zipfile.py
28263
@@ -300,6 +300,10 @@
28265
self.filename = filename # Normalized file name
28266
self.date_time = date_time # year, month, day, hour, min, sec
28268
+ if date_time[0] < 1980:
28269
+ raise ValueError('ZIP does not support timestamps before 1980')
28272
self.compress_type = ZIP_STORED # Type of compression for the file
28273
self.comment = b"" # Comment for each file
28274
diff -r 137e45f15c0b Mac/IDLE/IDLE.app/Contents/Info.plist
28275
--- a/Mac/IDLE/IDLE.app/Contents/Info.plist
28276
+++ b/Mac/IDLE/IDLE.app/Contents/Info.plist
28278
<key>CFBundleExecutable</key>
28279
<string>IDLE</string>
28280
<key>CFBundleGetInfoString</key>
28281
- <string>%version%, © 2001-2011 Python Software Foundation</string>
28282
+ <string>%version%, © 2001-2012 Python Software Foundation</string>
28283
<key>CFBundleIconFile</key>
28284
<string>IDLE.icns</string>
28285
<key>CFBundleIdentifier</key>
28286
diff -r 137e45f15c0b Mac/PythonLauncher/Info.plist.in
28287
--- a/Mac/PythonLauncher/Info.plist.in
28288
+++ b/Mac/PythonLauncher/Info.plist.in
28290
<key>CFBundleExecutable</key>
28291
<string>PythonLauncher</string>
28292
<key>CFBundleGetInfoString</key>
28293
- <string>%VERSION%, © 2001-2011 Python Software Foundation</string>
28294
+ <string>%VERSION%, © 2001-2012 Python Software Foundation</string>
28295
<key>CFBundleIconFile</key>
28296
<string>PythonLauncher.icns</string>
28297
<key>CFBundleIdentifier</key>
28298
diff -r 137e45f15c0b Mac/Resources/app/Info.plist.in
28299
--- a/Mac/Resources/app/Info.plist.in
28300
+++ b/Mac/Resources/app/Info.plist.in
28302
<key>CFBundleExecutable</key>
28303
<string>Python</string>
28304
<key>CFBundleGetInfoString</key>
28305
- <string>%version%, (c) 2004-2011 Python Software Foundation.</string>
28306
+ <string>%version%, (c) 2004-2012 Python Software Foundation.</string>
28307
<key>CFBundleHelpBookFolder</key>
28309
<string>Documentation</string>
28311
<key>CFBundleInfoDictionaryVersion</key>
28312
<string>6.0</string>
28313
<key>CFBundleLongVersionString</key>
28314
- <string>%version%, (c) 2004-2011 Python Software Foundation.</string>
28315
+ <string>%version%, (c) 2004-2012 Python Software Foundation.</string>
28316
<key>CFBundleName</key>
28317
<string>Python</string>
28318
<key>CFBundlePackageType</key>
28320
<key>NSAppleScriptEnabled</key>
28322
<key>NSHumanReadableCopyright</key>
28323
- <string>(c) 2011 Python Software Foundation.</string>
28324
+ <string>(c) 2012 Python Software Foundation.</string>
28327
diff -r 137e45f15c0b Mac/Resources/framework/Info.plist.in
28328
--- a/Mac/Resources/framework/Info.plist.in
28329
+++ b/Mac/Resources/framework/Info.plist.in
28331
<key>CFBundlePackageType</key>
28332
<string>FMWK</string>
28333
<key>CFBundleShortVersionString</key>
28334
- <string>%VERSION%, (c) 2004-2011 Python Software Foundation.</string>
28335
+ <string>%VERSION%, (c) 2004-2012 Python Software Foundation.</string>
28336
<key>CFBundleLongVersionString</key>
28337
- <string>%VERSION%, (c) 2004-2011 Python Software Foundation.</string>
28338
+ <string>%VERSION%, (c) 2004-2012 Python Software Foundation.</string>
28339
<key>CFBundleSignature</key>
28340
<string>????</string>
28341
<key>CFBundleVersion</key>
28342
diff -r 137e45f15c0b Makefile.pre.in
28343
--- a/Makefile.pre.in
28344
+++ b/Makefile.pre.in
28345
@@ -342,6 +342,7 @@
28348
Objects/abstract.o \
28350
Objects/boolobject.o \
28351
Objects/bytes_methods.o \
28352
Objects/bytearrayobject.o \
28353
@@ -641,6 +642,9 @@
28354
Objects/unicodeobject.o: $(srcdir)/Objects/unicodeobject.c \
28357
+Objects/dictobject.o: $(srcdir)/Objects/stringlib/eq.h
28358
+Objects/setobject.o: $(srcdir)/Objects/stringlib/eq.h
28360
$(OPCODETARGETS_H): $(OPCODETARGETGEN_FILES)
28361
$(OPCODETARGETGEN) $(OPCODETARGETS_H)
28363
@@ -661,6 +665,7 @@
28364
Include/Python-ast.h \
28366
Include/abstract.h \
28370
Include/bltinmodule.h \
28371
@@ -1226,8 +1231,8 @@
28372
# Sanitation targets -- clean leaves libraries, executables and tags
28373
# files, which clobber removes as well
28375
+ -find $(srcdir) -depth -name '__pycache__' -exec rm -rf {} ';'
28376
-find $(srcdir) -name '*.py[co]' -exec rm -f {} ';'
28377
- -find $(srcdir) -name '__pycache__' -exec rmdir {} '+'
28380
-rm -f *BAD *GOOD *SKIPPED
28381
@@ -1247,6 +1252,7 @@
28382
find build -name 'fficonfig.h' -exec rm -f {} ';' || true
28383
find build -name 'fficonfig.py' -exec rm -f {} ';' || true
28384
-rm -f Lib/lib2to3/*Grammar*.pickle
28385
+ -rm -f Modules/_testembed
28388
find . -name '*.gc??' -exec rm -f {} ';'
28389
diff -r 137e45f15c0b Misc/ACKS
2571
-"""XML-RPC Servers.
2572
+r"""XML-RPC Servers.
2574
This module can be used to create simple XML-RPC servers
2575
by creating a server and either installing functions, a
2576
diff -r 7085403daf43 Misc/ACKS
28390
2577
--- a/Misc/ACKS
28391
2578
+++ b/Misc/ACKS
28402
Michel Van den Bergh
28408
@@ -124,6 +126,7 @@
28411
Francisco Martín Brugué
28416
@@ -136,6 +139,7 @@
28424
@@ -164,6 +168,7 @@
28432
@@ -254,6 +259,7 @@
28440
@@ -284,6 +290,7 @@
28442
Sebastian Fernandez
28447
Jeffrey Finkelstein
28448
@@ -346,6 +353,7 @@
28452
+Philipp Hagemeister
28456
@@ -409,6 +417,7 @@
28464
@@ -436,6 +445,7 @@
28470
Flemming Kjær Jensen
28472
@@ -443,6 +453,7 @@
28480
@@ -467,6 +478,7 @@
28488
@@ -485,11 +497,13 @@
28502
@@ -498,6 +512,7 @@
28510
@@ -550,6 +565,7 @@
28518
@@ -596,6 +612,7 @@
28526
@@ -628,6 +645,7 @@
28529
Charles-François Natali
28534
@@ -649,6 +667,7 @@
2583
+Guilherme Gonçalves
28535
2592
Michal Nowikowski
28536
2593
Steffen Daode Nurpmeso
28541
Pascal Oberndoerfer
28542
@@ -661,6 +680,7 @@
28550
@@ -701,13 +721,16 @@
28553
Jean-François Piéronne
28567
@@ -715,6 +738,7 @@
28575
@@ -744,6 +768,7 @@
28576
Juan M. Bello Rivas
28583
@@ -772,6 +797,7 @@
28591
@@ -781,11 +807,14 @@
28606
@@ -804,7 +833,7 @@
28615
@@ -857,7 +886,6 @@
28623
@@ -876,6 +904,7 @@
28631
@@ -889,6 +918,7 @@
28639
@@ -896,6 +926,7 @@
28647
@@ -925,6 +956,8 @@
28656
@@ -965,7 +998,6 @@
28659
Jean-Claude Wippler
28664
@@ -988,6 +1020,7 @@
28672
diff -r 137e45f15c0b Misc/NEWS
2595
diff -r 7085403daf43 Misc/NEWS
28673
2596
--- a/Misc/NEWS
28674
2597
+++ b/Misc/NEWS
28679
+What's New in Python 3.2.3?
28680
+===========================
2602
+What's New in Python 3.2.4
2603
+==========================
28682
+*Release date: XX-XXX-2011*
2605
+*Release date: XX-XX-XXXX*
28684
2607
+Core and Builtins
28685
2608
+-----------------
28687
+- Issue #13020: Fix a reference leak when allocating a structsequence object
28688
+ fails. Patch by Suman Saha.
28690
+- Issue #13908: Ready types returned from PyType_FromSpec.
28692
+- Issue #11235: Fix OverflowError when trying to import a source file whose
28693
+ modification time doesn't fit in a 32-bit timestamp.
28695
+- Fix the builtin module initialization code to store the init function for
28696
+ future reinitialization.
28698
+- Issue #8052: The posix subprocess module would take a long time closing
28699
+ all possible file descriptors in the child process rather than just open
28700
+ file descriptors. It now closes only the open fds if possible for the
28701
+ default close_fds=True behavior.
28703
+- Issue #13629: Renumber the tokens in token.h so that they match the indexes
28704
+ into _PyParser_TokenNames.
28706
+- Fix the fix for issue #12149: it was incorrect, although it had the side
28707
+ effect of appearing to resolve the issue. Thanks to Mark Shannon for
28710
+- Issue #13505: Pickle bytes objects in a way that is compatible with
28711
+ Python 2 when using protocols <= 2.
28713
+- Issue #11147: Fix an unused argument in _Py_ANNOTATE_MEMORY_ORDER. (Fix
28714
+ given by Campbell Barton).
28716
+- Issue #7111: Python can now be run without a stdin, stdout or stderr
28717
+ stream. It was already the case with Python 2. However, the corresponding
28718
+ sys module entries are now set to None (instead of an unusable file object).
28720
+- Issue #13436: Fix a bogus error message when an AST object was passed
28721
+ an invalid integer value.
28723
+- Issue #13338: Handle all enumerations in _Py_ANNOTATE_MEMORY_ORDER
28724
+ to allow compiling extension modules with -Wswitch-enum on gcc.
28725
+ Initial patch by Floris Bruynooghe.
28727
+- Issue #13333: The UTF-7 decoder now accepts lone surrogates (the encoder
28728
+ already accepts them).
28730
+- Issue #13342: input() used to ignore sys.stdin's and sys.stdout's unicode
28731
+ error handler in interactive mode (when calling into PyOS_Readline()).
28733
+- Issue #13343: Fix a SystemError when a lambda expression uses a global
28734
+ variable in the default value of a keyword-only argument:
28735
+ (lambda *, arg=GLOBAL_NAME: None)
28737
+- Issue #10519: Avoid unnecessary recursive function calls in
28740
+- Issue #10363: Deallocate global locks in Py_Finalize().
28742
+- Issue #13018: Fix reference leaks in error paths in dictobject.c.
28743
+ Patch by Suman Saha.
28745
+- Issue #1294232: In a few cases involving metaclass inheritance, the
28746
+ interpreter would sometimes invoke the wrong metaclass when building a new
28747
+ class object. These cases now behave correctly. Patch by Daniel Urban.
28749
+- Issue #12604: VTRACE macro expanded to no-op in _sre.c to avoid compiler
28750
+ warnings. Patch by Josh Triplett and Petri Lehtinen.
28752
+- Issue #13188: When called without an explicit traceback argument,
28753
+ generator.throw() now gets the traceback from the passed exception's
28754
+ ``__traceback__`` attribute. Patch by Petri Lehtinen.
28756
+- Issue #7833: Extension modules built using distutils on Windows will no
28757
+ longer include a "manifest" to prevent them failing at import time in some
28758
+ embedded situations.
28760
+- Issue #13063: the Windows error ERROR_NO_DATA (numbered 232 and described
28761
+ as "The pipe is being closed") is now mapped to POSIX errno EPIPE
28762
+ (previously EINVAL).
28764
+- Issue #12911: Fix memory consumption when calculating the repr() of huge
28767
+- Issue #7732: Don't open a directory as a file anymore while importing a
28768
+ module. Ignore the direcotry if its name matchs the module name (e.g.
28769
+ "__init__.py") and raise a ImportError instead.
28771
+- Issue #13021: Missing decref on an error path. Thanks to Suman Saha for
28772
+ finding the bug and providing a patch.
28774
+- Issue #12973: Fix overflow checks that relied on undefined behaviour in
28775
+ list_repeat (listobject.c) and islice_next (itertoolsmodule.c). These bugs
28776
+ caused test failures with recent versions of Clang.
28778
+- Issue #12802: the Windows error ERROR_DIRECTORY (numbered 267) is now
28779
+ mapped to POSIX errno ENOTDIR (previously EINVAL).
28781
+- Issue #9200: The str.is* methods now work with strings that contain non-BMP
28782
+ characters even in narrow Unicode builds.
28784
+- Issue #12791: Break reference cycles early when a generator exits with
28787
+- Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase
28788
+ titlecased and cased non-letter characters.
2610
+- Issue #1469629: Allow cycles through an object's __dict__ slot to be
2611
+ collected. (For example if ``x.__dict__ is x``).
2613
+- Issue #14172: Fix reference leak when marshalling a buffer-like object
2614
+ (other than a bytes object).
2616
+- Issue #13521: dict.setdefault() now does only one lookup for the given key,
2617
+ making it "atomic" for many purposes. Patch by Filip Gruszczyński.
28793
+- Issue #2489: pty.spawn could consume 100% cpu when it encountered an EOF.
28795
+- Issue #13014: Fix a possible reference leak in SSLSocket.getpeercert().
28797
+- Issue #13015: Fix a possible reference leak in defaultdict.__repr__.
28798
+ Patch by Suman Saha.
28800
+- Issue #1326113: distutils' build_ext command --libraries option now
28801
+ correctly parses multiple values separated by whitespace or commas.
28803
+- Issue #10287: nntplib now queries the server's CAPABILITIES first before
28804
+ sending MODE READER, and only sends it if not already in READER mode.
28805
+ Patch by Hynek Schlawack.
28807
+- Issue #13979: A bug in ctypes.util.find_library that caused
28808
+ the wrong library name to be returned has been fixed.
28810
+- Issue #13993: HTMLParser is now able to handle broken end tags when
28813
+- Issue #9750: Fix sqlite3.Connection.iterdump on tables and fields
28814
+ with a name that is a keyword or contains quotes. Patch by Marko
28817
+- Issue #10287: nntplib now queries the server's CAPABILITIES again after
28818
+ authenticating (since the result may change, according to RFC 4643).
28819
+ Patch by Hynek Schlawack.
28821
+- Issue #13989: Document that GzipFile does not support text mode, and give a
28822
+ more helpful error message when opened with an invalid mode string.
28824
+- Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
28825
+ Distutils-based packages with C extension modules may fail because
28826
+ Apple has removed gcc-4.2, the version used to build python.org
28827
+ 64-bit/32-bit Pythons. If the user does not explicitly override
28828
+ the default C compiler by setting the CC environment variable,
28829
+ Distutils will now attempt to compile extension modules with clang
28830
+ if gcc-4.2 is required but not found. Also as a convenience, if
28831
+ the user does explicitly set CC, substitute its value as the default
28832
+ compiler in the Distutils LDSHARED configuration variable for OS X.
28833
+ (Note, the python.org 32-bit-only Pythons use gcc-4.0 and the 10.4u
28834
+ SDK, neither of which are available in Xcode 4. This change does not
28835
+ attempt to override settings to support their use with Xcode 4.)
28837
+- Issue #13960: HTMLParser is now able to handle broken comments when
28840
+- Issue #9021: Add an introduction to the copy module documentation.
28842
+- Issue #6005: Examples in the socket library documentation use sendall, where
28843
+ relevant, instead send method.
28845
+- Issue #10811: Fix recursive usage of cursors. Instead of crashing,
28846
+ raise a ProgrammingError now.
28848
+- Issue #10881: Fix test_site failure with OS X framework builds.
28850
+- Issue #964437: Make IDLE help window non-modal.
28851
+ Patch by Guilherme Polo and Roger Serwy.
28853
+- Issue #2945: Make the distutils upload command aware of bdist_rpm products.
28855
+- Issue #13933: IDLE auto-complete did not work with some imported
28856
+ module, like hashlib. (Patch by Roger Serwy)
28858
+- Issue #13901: Prevent test_distutils failures on OS X with --enable-shared.
28860
+- Issue #13676: Handle strings with embedded zeros correctly in sqlite3.
28862
+- Issue #13506: Add '' to path for IDLE Shell when started and restarted with Restart Shell.
28863
+ Original patches by Marco Scataglini and Roger Serwy.
28865
+- Issue #13848: open() and the FileIO constructor now check for NUL
28866
+ characters in the file name. Patch by Hynek Schlawack.
28868
+- Issue #13806: The size check in audioop decompression functions was too
28869
+ strict and could reject valid compressed data. Patch by Oleg Plakhotnyuk.
28871
+- Issue #13812: When a multiprocessing Process child raises an exception,
28872
+ flush stderr after printing the exception traceback.
28874
+- Issue #13885: CVE-2011-3389: the _ssl module would always disable the CBC
28875
+ IV attack countermeasure.
28877
+- Issue #13772: In os.symlink() under Windows, do not try to guess the link
28878
+ target's type (file or directory). The detection was buggy and made the
28879
+ call non-atomic (therefore prone to race conditions).
28881
+- Issue #6631: Disallow relative file paths in urllib urlopen methods.
28883
+- Issue #13722: Avoid silencing ImportErrors when initializing the codecs
28886
+- Issue #13781: Fix GzipFile bug that caused an exception to be raised when
28887
+ opening for writing using a fileobj returned by os.fdopen().
28889
+- Issue #13803: Under Solaris, distutils doesn't include bitness
28890
+ in the directory name.
28892
+- Issue #13589: Fix some serialization primitives in the aifc module.
28893
+ Patch by Oleg Plakhotnyuk.
28895
+- Issue #13642: Unquote before b64encoding user:password during Basic
28896
+ Authentication. Patch contributed by Joonas Kuorilehto.
28898
+- Issue #13726: Fix the ambiguous -S flag in regrtest. It is -o/--slow for slow
28901
+- Issue #12364: Fix a hang in concurrent.futures.ProcessPoolExecutor.
28902
+ The hang would occur when retrieving the result of a scheduled future after
28903
+ the executor had been shut down.
28905
+- Issue #13502: threading: Fix a race condition in Event.wait() that made it
28906
+ return False when the event was set and cleared right after.
28908
+- Issue #12926: Fix a bug in tarfile's link extraction.
28910
+- Issue #13696: Fix the 302 Relative URL Redirection problem.
28912
+- Issue #13636: Weak ciphers are now disabled by default in the ssl module
28913
+ (except when SSLv2 is explicitly asked for).
28915
+- Issue #12798: Updated the mimetypes documentation.
28917
+- Issue #11006: Don't issue low level warning in subprocess when pipe2() fails.
28919
+- Issue #11829: Fix code execution holes in inspect.getattr_static for
28920
+ metaclasses with metaclasses. Patch by Andreas Stührk.
28922
+- Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
28924
+- Issue #11813: Fix inspect.getattr_static for modules. Patch by Andreas
28927
+- Issue #7502: Fix equality comparison for DocTestCase instances. Patch by
28930
+- Issue #11870: threading: Properly reinitialize threads internal locks and
28931
+ condition variables to avoid deadlocks in child processes.
28933
+- Issue #8035: urllib: Fix a bug where the client could remain stuck after a
28934
+ redirection or an error.
28936
+- Issue #10350: Read and save errno before calling a function which might
28937
+ overwrite it. Original patch by Hallvard B Furuseth.
28939
+- Issue #13591: A bug in importlib has been fixed that caused import_module
28940
+ to load a module twice.
28942
+- Issue #4625: If IDLE cannot write to its recent file or breakpoint
28943
+ files, display a message popup and continue rather than crash.
28944
+ (original patch by Roger Serwy)
28946
+- Issue #5905: time.strftime() is now using the locale encoding, instead of
28947
+ UTF-8, if the wcsftime() function is not available.
28949
+- Issue #8641: Update IDLE 3 syntax coloring to recognize b".." and not u"..".
28950
+ Patch by Tal Einat.
28952
+- tarfile.py: Correctly detect bzip2 compressed streams with blocksizes
28955
+- Issue #13439: Fix many errors in turtle docstrings.
28957
+- Issue #13487: Make inspect.getmodule robust against changes done to
28958
+ sys.modules while it is iterating over it.
28960
+- Issue #12618: Fix a bug that prevented py_compile from creating byte
28961
+ compiled files in the current directory. Initial patch by Sjoerd de Vries.
28963
+- Issue #13444: When stdout has been closed explicitly, we should not attempt
28964
+ to flush it at shutdown and print an error.
28966
+- Issue #12856: Ensure child processes do not inherit the parent's random
28967
+ seed for filename generation in the tempfile module. Patch by Brian
28970
+- Issue #13458: Fix a memory leak in the ssl module when decoding a
28971
+ certificate with a subjectAltName. Patch by Robert Xiao.
28973
+- Issue #13415: os.unsetenv() doesn't ignore errors anymore.
28975
+- Issue #13322: Fix BufferedWriter.write() to ensure that BlockingIOError is
28976
+ raised when the wrapped raw file is non-blocking and the write would block.
28977
+ Previous code assumed that the raw write() would raise BlockingIOError, but
28978
+ RawIOBase.write() is defined to returned None when the call would block.
28981
+- Issue #13358: HTMLParser now calls handle_data only once for each CDATA.
28983
+- Issue #4147: minidom's toprettyxml no longer adds whitespace around a text
28984
+ node when it is the only child of an element. Initial patch by Dan
28987
+- Issues #1745761, #755670, #13357, #12629, #1200313: HTMLParser now correctly
28988
+ handles non-valid attributes, including adjacent and unquoted attributes.
28990
+- Issue #13193: Fix distutils.filelist.FileList under Windows.
28992
+- Issue #13384: Remove unnecessary __future__ import in Lib/random.py
28994
+- Issue #13373: multiprocessing.Queue.get() could sometimes block indefinitely
28995
+ when called with a timeout. Patch by Arnaud Ysmal.
28997
+- Issue #13254: Fix Maildir initialization so that maildir contents
28998
+ are read correctly.
29000
+- Issue #3067: locale.setlocale() now raises TypeError if the second
29001
+ argument is an invalid iterable. Its documentation and docstring
29002
+ were also updated. Initial patch by Jyrki Pulliainen.
29004
+- Issue #13140: Fix the daemon_threads attribute of ThreadingMixIn.
29006
+- Issue #13339: Fix compile error in posixmodule.c due to missing semicolon.
29007
+ Thanks to Robert Xiao.
29009
+- Issue #10570: curses.putp() and curses.tparm() are now expecting a byte
29010
+ string, instead of a Unicode string.
29012
+- Issue #2892: preserve iterparse events in case of SyntaxError.
29014
+- Issue #670664: Fix HTMLParser to correctly handle the content of
29015
+ ``<script>...</script>`` and ``<style>...</style>``.
29017
+- Issue #10817: Fix urlretrieve function to raise ContentTooShortError even
29018
+ when reporthook is None. Patch by Jyrki Pulliainen.
29020
+- Issue #13296: Fix IDLE to clear compile __future__ flags on shell restart.
29021
+ (Patch by Roger Serwy)
29023
+- Issue #13293: Better error message when trying to marshal bytes using
29026
+- Issue #13291: NameError in xmlrpc package.
29028
+- Issue #13258: Use callable() built-in in the standard library.
29030
+- Issue #13273: fix a bug that prevented HTMLParser to properly detect some
29031
+ tags when strict=False.
29033
+- Issue #10332: multiprocessing: fix a race condition when a Pool is closed
29034
+ before all tasks have completed.
29036
+- Issue #13255: wrong docstrings in array module.
29038
+- Issue #9168: now smtpd is able to bind privileged port.
29040
+- Issue #12529: fix cgi.parse_header issue on strings with double-quotes and
29041
+ semicolons together. Patch by Ben Darnell and Petri Lehtinen.
29043
+- Issue #12448: smtplib now flushes stdout while running ``python -m smtplib``
29044
+ in order to display the prompt correctly.
29046
+- Issue #6090: zipfile raises a ValueError when a document with a timestamp
29047
+ earlier than 1980 is provided. Patch contributed by Petri Lehtinen.
29049
+- Issue #13194: zlib.compressobj().copy() and zlib.decompressobj().copy() are
29050
+ now available on Windows.
29052
+- Issue #13158: Fix decoding and encoding of GNU tar specific base-256 number
29053
+ fields in tarfile.
29055
+- Issue #13177: Functools lru_cache() no longer calls the original function
29056
+ inside an exception handler. This makes tracebacks easier to read because
29057
+ chained exceptions are avoided.
29059
+- Issue #13025: mimetypes is now reading MIME types using the UTF-8 encoding,
29060
+ instead of the locale encoding.
29062
+- Issue #10653: On Windows, use strftime() instead of wcsftime() because
29063
+ wcsftime() doesn't format time zone correctly.
29065
+- Issue #11171: Fix distutils.sysconfig.get_makefile_filename when Python was
29066
+ configured with different prefix and exec-prefix.
29068
+- Issue #11254: Teach distutils to compile .pyc and .pyo files in
29069
+ PEP 3147-compliant __pycache__ directories.
29071
+- Issue #11250: Back port fix from 3.3 branch, so that 2to3 can handle files
29072
+ with line feeds. This was ported from the sandbox to the 3.3 branch, but
29073
+ didn't make it into 3.2.
29075
+- Issue #7367: Fix pkgutil.walk_paths to skip directories whose
29076
+ contents cannot be read.
29078
+- Issue #13099: Fix sqlite3.Cursor.lastrowid under a Turkish locale.
29079
+ Reported and diagnosed by Thomas Kluyver.
29081
+- Issue #13087: BufferedReader.seek() now always raises UnsupportedOperation
29082
+ if the underlying raw stream is unseekable, even if the seek could be
29083
+ satisfied using the internal buffer. Patch by John O'Connor.
29085
+- Issue #7689: Allow pickling of dynamically created classes when their
29086
+ metaclass is registered with copyreg. Patch by Nicolas M. Thiéry and Craig
29089
+- Issue #4147: minidom's toprettyxml no longer adds whitespace to text nodes.
29091
+- Issue #13034: When decoding some SSL certificates, the subjectAltName
29092
+ extension could be unreported.
29094
+- Issue #9871: Prevent IDLE 3 crash when given byte stings
29095
+ with invalid hex escape sequences, like b'\x0'.
29096
+ (Original patch by Claudiu Popa.)
29098
+- Issue #8933: distutils' PKG-INFO files will now correctly report
29099
+ Metadata-Version: 1.1 instead of 1.0 if a Classifier or Download-URL field is
29102
+- Issue #9561: distutils now reads and writes egg-info files using UTF-8,
29103
+ instead of the locale encoding.
29105
+- Issue #12888: Fix a bug in HTMLParser.unescape that prevented it to escape
29106
+ more than 128 entities. Patch by Peter Otten.
29108
+- Issue #12878: Expose a __dict__ attribute on io.IOBase and its subclasses.
29110
+- Issue #12636: IDLE reads the coding cookie when executing a Python script.
29112
+- Issue #12847: Fix a crash with negative PUT and LONG_BINPUT arguments in
29113
+ the C pickle implementation.
29115
+- Issue #11564: Avoid crashes when trying to pickle huge objects or containers
29116
+ (more than 2**31 items). Instead, in most cases, an OverflowError is raised.
29118
+- Issue #12287: Fix a stack corruption in ossaudiodev module when the FD is
29119
+ greater than FD_SETSIZE.
29121
+- Issue #11657: Fix sending file descriptors over 255 over a multiprocessing
29124
+- Issue #13007: whichdb should recognize gdbm 1.9 magic numbers.
29126
+- Issue #12213: Fix a buffering bug with interleaved reads and writes that
29127
+ could appear on BufferedRandom streams.
29129
+- Issue #12650: Fix a race condition where a subprocess.Popen could leak
29130
+ resources (FD/zombie) when killed at the wrong time.
29132
+- Issue #10860: http.client now correctly handles an empty port after port
29133
+ delimiter in URLs.
29138
+- Issue #13326: Clean __pycache__ directories correctly on OpenBSD.
29143
+- Issue #13930: 2to3 is now able to write its converted output files to another
29144
+ directory tree as well as copying unchanged files and altering the file
29145
+ suffix. See its new -o, -W and --add-suffix options. This makes it more
29146
+ useful in many automated code translation workflows.
29148
+- Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
29149
+ traceback if Python is optimized.
29154
+- Issue #13786: Remove unimplemented 'trace' long option from regrtest.py.
29156
+- Issue #13725: Fix regrtest to recognize the documented -d flag.
29157
+ Patch by Erno Tukia.
29159
+- Issue #13304: Skip test case if user site-packages disabled (-s or
29160
+ PYTHONNOUSERSITE). (Patch by Carl Meyer)
29162
+- Issue #13218: Fix test_ssl failures on Debian/Ubuntu.
29164
+- Issue #12821: Fix test_fcntl failures on OpenBSD 5.
29166
+- Re-enable lib2to3's test_parser.py tests, though with an expected failure
29167
+ (see issue 13125).
2622
+- Issue #14195: An issue that caused weakref.WeakSet instances to incorrectly
2623
+ return True for a WeakSet instance 'a' in both 'a < a' and 'a > a' has been
2626
+- Issue #14177: marshal.loads() now raises TypeError when given an unicode
2627
+ string. Patch by Guilherme Gonçalves.
2629
+- Issue #14159: Fix the len() of weak containers (WeakSet, WeakKeyDictionary,
2630
+ WeakValueDictionary) to return a better approximation when some objects
2631
+ are dead or dying. Moreover, the implementation is now O(1) rather than
2634
+- Issue #13125: Silence spurious test_lib2to3 output when in non-verbose mode.
2635
+ Patch by Mikhail Novikov.
2637
+- Issue #13447: Add a test file to host regression tests for bugs in the
2638
+ scripts found in the Tools directory.
2640
+- Issue #6884: Fix long-standing bugs with MANIFEST.in parsing in distutils
2643
+- Issue #8033: sqlite3: Fix 64-bit integer handling in user functions
2644
+ on 32-bit architectures. Initial patch by Philippe Devalkeneer.
29169
2646
+Extension Modules
29170
2647
+-----------------
29172
+- Issue #13840: The error message produced by ctypes.create_string_buffer
29173
+ when given a Unicode string has been fixed.
29175
+- Issue #9975: socket: Fix incorrect use of flowinfo and scope_id. Patch by
29178
+- Issue #13159: FileIO and BZ2File now use a linear-time buffer growth
29179
+ strategy instead of a quadratic-time one.
29181
+- Issue #13070: Fix a crash when a TextIOWrapper caught in a reference cycle
29182
+ would be finalized after the reference to its underlying BufferedRWPair's
29183
+ writer got cleared by the GC.
29185
+- Issue #12881: ctypes: Fix segfault with large structure field names.
29187
+- Issue #13058: ossaudiodev: fix a file descriptor leak on error. Patch by
29190
+- Issue #13013: ctypes: Fix a reference leak in PyCArrayType_from_ctype.
29191
+ Thanks to Suman Saha for finding the bug and providing a patch.
29193
+- Issue #13022: Fix: _multiprocessing.recvfd() doesn't check that
29194
+ file descriptor was actually received.
29196
+- Issue #12483: ctypes: Fix a crash when the destruction of a callback
29197
+ object triggers the garbage collector.
29199
+- Issue #12950: Fix passing file descriptors in multiprocessing, under
29200
+ OpenIndiana/Illumos.
29205
+- Issue #13491: Fix many errors in sqlite3 documentation. Initial
29206
+ patch by Johannes Vogel.
29208
+- Issue #13402: Document absoluteness of sys.executable.
29210
+- Issue #13883: PYTHONCASEOK also used on OS X and OS/2.
29212
+- Issue #12949: Document the kwonlyargcount argument for the PyCode_New
29215
+- Issue #2134: The tokenize documentation has been clarified to explain why
29216
+ all operator and delimiter tokens are treated as token.OP tokens.
29218
+- Issue #13513: Fix io.IOBase documentation to correctly link to the
29219
+ io.IOBase.readline method instead of the readline module.
29221
+- Issue #13237: Reorganise subprocess documentation to emphasise convenience
29222
+ functions and the most commonly needed arguments to Popen.
29224
+- Issue #13141: Demonstrate recommended style for socketserver examples.
29227
What's New in Python 3.2.2?
29228
===========================
2649
+- Issue #14212: The re module didn't retain a reference to buffers it was
2650
+ scanning, resulting in segfaults.
2653
What's New in Python 3.2.3 release candidate 1?
2654
===============================================
29230
@@ -19,6 +567,14 @@
29234
+- Issue #8286: The distutils command sdist will print a warning message instead
29235
+ of crashing when an invalid path is given in the manifest template.
29237
+- Issue #12841: tarfile unnecessarily checked the existence of numerical user
29238
+ and group ids on extraction. If one of them did not exist the respective id
29239
+ of the current user (i.e. root) was used for the file and ownership
29240
+ information was lost.
29242
- Issue #10946: The distutils commands bdist_dumb, bdist_wininst and bdist_msi
29243
now respect a --skip-build option given to bdist.
29246
- Issue #11627: Fix segfault when __new__ on a exception returns a
29247
non-exception class.
29249
+- Issue #12149: Update the method cache after a type's dictionary gets
29250
cleared by the garbage collector. This fixes a segfault when an instance
29251
and its type get caught in a reference cycle, and the instance's
29252
deallocator calls one of the methods on the type (e.g. when subclassing
29253
@@ -163,6 +719,11 @@
29257
+- Issue #12764: Fix a crash in ctypes when the name of a Structure field is not
29260
+- Issue #11241: subclasses of ctypes.Array can now be subclassed.
29262
- Issue #10309: Define _GNU_SOURCE so that mremap() gets the proper
29263
signature. Without this, architectures where sizeof void* != sizeof int are
29264
broken. Patch given by Hallvard B Furuseth.
29265
@@ -251,6 +812,11 @@
29266
- Skip network tests when getaddrinfo() returns EAI_AGAIN, meaning a temporary
29267
failure in name resolution.
29269
+- Issue #11812: Solve transient socket failure to connect to 'localhost'
29270
+ in test_telnetlib.py.
29272
+- Solved a potential deadlock in test_telnetlib.py. Related to issue #11812.
29274
- Avoid failing in test_urllibnet.test_bad_address when some overzealous
29275
DNS service (e.g. OpenDNS) resolves a non-existent domain name. The test
29276
is now skipped instead.
29277
diff -r 137e45f15c0b Misc/build.sh
29278
--- a/Misc/build.sh
29283
-## Script to build and test the latest python from svn. It basically
29285
-## svn up ; ./configure ; make ; make test ; make install ; cd Doc ; make
29287
-## Logs are kept and rsync'ed to the webhost. If there are test failure(s),
29288
-## information about the failure(s) is mailed.
29290
-## The user must be a member of the webmaster group locally and on webhost.
29292
-## This script is run on the PSF's machine as user neal via crontab.
29294
-## Yes, this script would probably be easier in python, but then
29295
-## there's a bootstrap problem. What if Python doesn't build?
29297
-## This script should be fairly clean Bourne shell, ie not too many
29298
-## bash-isms. We should try to keep it portable to other Unixes.
29299
-## Even though it will probably only run on Linux. I'm sure there are
29300
-## several GNU-isms currently (date +%s and readlink).
29302
-## Perhaps this script should be broken up into 2 (or more) components.
29303
-## Building doc is orthogonal to the rest of the python build/test.
29306
-## FIXME: we should detect test hangs (eg, if they take more than 45 minutes)
29308
-## FIXME: we should run valgrind
29309
-## FIXME: we should run code coverage
29311
-## Utilities invoked in this script include:
29312
-## basename, date, dirname, expr, grep, readlink, uname
29313
-## cksum, make, mutt, rsync, svn
29315
-## remember where did we started from
29317
-if [ "$DIR" = "" ]; then
29321
-## make directory absolute
29322
-DIR=`readlink -f $DIR`
29323
-FULLPATHNAME="$DIR/`basename $0`"
29324
-## we want Misc/..
29325
-DIR=`dirname $DIR`
29327
-## Configurable options
29329
-FAILURE_SUBJECT="Python Regression Test Failures"
29330
-#FAILURE_MAILTO="YOUR_ACCOUNT@gmail.com"
29331
-FAILURE_MAILTO="python-checkins@python.org"
29332
-#FAILURE_CC="optional--uncomment and set to desired address"
29334
-REMOTE_SYSTEM="neal@dinsdale.python.org"
29335
-REMOTE_DIR="/data/ftp.python.org/pub/docs.python.org/dev/py3k"
29336
-RESULT_FILE="$DIR/build/index.html"
29337
-INSTALL_DIR="/tmp/python-test-3.2/local"
29338
-RSYNC_OPTS="-C -e ssh -rlogD"
29340
-# Always run the installed version of Python.
29341
-PYTHON=$INSTALL_DIR/bin/python
29343
-# Python options and regression test program that should always be run.
29344
-REGRTEST_ARGS="-E $INSTALL_DIR/lib/python3.0/test/regrtest.py"
29346
-REFLOG="build/reflog.txt.out"
29347
-# These tests are not stable and falsely report leaks sometimes.
29348
-# The entire leak report will be mailed if any test not in this list leaks.
29349
-# Note: test_XXX (none currently) really leak, but are disabled
29350
-# so we don't send spam. Any test which really leaks should only
29351
-# be listed here if there are also test cases under Lib/test/leakers.
29352
-LEAKY_TESTS="test_(asynchat|cmd_line|docxmlrpc|dumbdbm|file|ftplib|httpservers|imaplib|popen2|socket|smtplib|sys|telnetlib|threadedtempfile|threading|threadsignals|xmlrpc)"
29354
-# These tests always fail, so skip them so we don't get false positives.
29356
-ALWAYS_SKIP="-x $_ALWAYS_SKIP"
29358
-# Skip these tests altogether when looking for leaks. These tests
29359
-# do not need to be stored above in LEAKY_TESTS too.
29360
-# test_logging causes hangs, skip it.
29361
-# KBK 21Apr09: test_httpservers causes hangs, skip for now.
29362
-LEAKY_SKIPS="-x test_compiler test_logging test_httpservers"
29364
-# Change this flag to "yes" for old releases to only update/build the docs.
29365
-BUILD_DISABLED="no"
29367
-## utility functions
29373
- now=`current_time`
29374
- time=`expr $now - $3`
29375
- echo "<li><a href=\"$2\">$1</a> <font size=\"-1\">($time seconds)</font></li>" >> $RESULT_FILE
29378
-place_summary_first() {
29380
- sed -n '/^[0-9][0-9]* tests OK\./,$p' < $testf \
29381
- | egrep -v '\[[0-9]+ refs\]' > $testf.tmp
29382
- echo "" >> $testf.tmp
29383
- cat $testf >> $testf.tmp
29384
- mv $testf.tmp $testf
29387
-count_failures () {
29389
- n=`grep -ic " failed:" $testf`
29390
- if [ $n -eq 1 ] ; then
29391
- n=`grep " failed:" $testf | sed -e 's/ .*//'`
29396
-mail_on_failure() {
29397
- if [ "$NUM_FAILURES" != "0" ]; then
29398
- dest=$FAILURE_MAILTO
29399
- # FAILURE_CC is optional.
29400
- if [ "$FAILURE_CC" != "" ]; then
29401
- dest="$dest -c $FAILURE_CC"
29403
- if [ "x$3" != "x" ] ; then
29404
- (echo "More important issues:"
29405
- echo "----------------------"
29406
- egrep -v "$3" < $2
29408
- echo "Less important issues:"
29409
- echo "----------------------"
29413
- fi | mutt -s "$FAILURE_SUBJECT $1 ($NUM_FAILURES)" $dest
29419
-make clobber > /dev/null 2>&1
29420
-cp -p Modules/Setup.dist Modules/Setup
29421
-# But maybe there was no Makefile - we are only building docs. Clear build:
29424
-rm -rf $INSTALL_DIR
29425
-## get the path we are building
29426
-repo_path=$(grep "url=" .svn/entries | sed -e s/\\W*url=// -e s/\"//g)
29428
-## create results file
29429
-TITLE="Automated Python Build Results"
29430
-echo "<html>" >> $RESULT_FILE
29431
-echo " <head>" >> $RESULT_FILE
29432
-echo " <title>$TITLE</title>" >> $RESULT_FILE
29433
-echo " <meta http-equiv=\"refresh\" content=\"43200\">" >> $RESULT_FILE
29434
-echo " </head>" >> $RESULT_FILE
29435
-echo "<body>" >> $RESULT_FILE
29436
-echo "<h2>Automated Python Build Results</h2>" >> $RESULT_FILE
29437
-echo "<table>" >> $RESULT_FILE
29438
-echo " <tr>" >> $RESULT_FILE
29439
-echo " <td>Built on:</td><td>`date`</td>" >> $RESULT_FILE
29440
-echo " </tr><tr>" >> $RESULT_FILE
29441
-echo " <td>Hostname:</td><td>`uname -n`</td>" >> $RESULT_FILE
29442
-echo " </tr><tr>" >> $RESULT_FILE
29443
-echo " <td>Platform:</td><td>`uname -srmpo`</td>" >> $RESULT_FILE
29444
-echo " </tr><tr>" >> $RESULT_FILE
29445
-echo " <td>URL:</td><td>$repo_path</td>" >> $RESULT_FILE
29446
-echo " </tr>" >> $RESULT_FILE
29447
-echo "</table>" >> $RESULT_FILE
29448
-echo "<ul>" >> $RESULT_FILE
29450
-## update, build, and test
29451
-ORIG_CHECKSUM=`cksum $FULLPATHNAME`
29453
-start=`current_time`
29454
-svn update >& build/$F
29456
-update_status "Updating" "$F" $start
29457
-if [ $err = 0 -a "$BUILD_DISABLED" != "yes" ]; then
29458
- ## FIXME: we should check if this file has changed.
29459
- ## If it has changed, we should re-run the script to pick up changes.
29460
- if [ "$ORIG_CHECKSUM" != "$ORIG_CHECKSUM" ]; then
29461
- exec $FULLPATHNAME $@
29465
- start=`current_time`
29466
- svn stat >& build/$F
29467
- ## ignore some of the diffs
29468
- NUM_DIFFS=`egrep -vc '^. (@test|db_home|Lib/test/(regrtest\.py|db_home))$' build/$F`
29469
- update_status "svn stat ($NUM_DIFFS possibly important diffs)" "$F" $start
29472
- start=`current_time`
29473
- ./configure --prefix=$INSTALL_DIR --with-pydebug >& build/$F
29475
- update_status "Configuring" "$F" $start
29476
- if [ $err = 0 ]; then
29478
- start=`current_time`
29481
- warnings=`grep warning build/$F | egrep -vc "te?mpnam(_r|)' is dangerous,"`
29482
- update_status "Building ($warnings warnings)" "$F" $start
29483
- if [ $err = 0 ]; then
29485
- F=make-install.out
29486
- start=`current_time`
29487
- make install >& build/$F
29488
- update_status "Installing" "$F" $start
29490
- if [ ! -x $PYTHON ]; then
29491
- ln -s ${PYTHON}3.* $PYTHON
29494
- ## make and run basic tests
29496
- start=`current_time`
29497
- $PYTHON $REGRTEST_ARGS -W -u urlfetch >& build/$F
29498
- NUM_FAILURES=`count_failures build/$F`
29499
- place_summary_first build/$F
29500
- update_status "Testing basics ($NUM_FAILURES failures)" "$F" $start
29501
- mail_on_failure "basics" build/$F
29503
- F=make-test-opt.out
29504
- start=`current_time`
29505
- $PYTHON -O $REGRTEST_ARGS -W -u urlfetch >& build/$F
29506
- NUM_FAILURES=`count_failures build/$F`
29507
- place_summary_first build/$F
29508
- update_status "Testing opt ($NUM_FAILURES failures)" "$F" $start
29509
- mail_on_failure "opt" build/$F
29511
- ## run the tests looking for leaks
29512
- F=make-test-refleak.out
29513
- start=`current_time`
29514
- ## ensure that the reflog exists so the grep doesn't fail
29516
- $PYTHON $REGRTEST_ARGS -R 4:3:$REFLOG -u network $LEAKY_SKIPS >& build/$F
29517
- LEAK_PAT="($LEAKY_TESTS|sum=0)"
29518
- NUM_FAILURES=`egrep -vc "$LEAK_PAT" $REFLOG`
29519
- place_summary_first build/$F
29520
- update_status "Testing refleaks ($NUM_FAILURES failures)" "$F" $start
29521
- mail_on_failure "refleak" $REFLOG "$LEAK_PAT"
29523
- ## now try to run all the tests
29524
- F=make-testall.out
29525
- start=`current_time`
29526
- ## skip curses when running from cron since there's no terminal
29527
- ## skip sound since it's not setup on the PSF box (/dev/dsp)
29528
- $PYTHON $REGRTEST_ARGS -W -uall -x test_curses test_linuxaudiodev test_ossaudiodev &_ALWAYS_SKIP >& build/$F
29529
- NUM_FAILURES=`count_failures build/$F`
29530
- place_summary_first build/$F
29531
- update_status "Testing all except curses and sound ($NUM_FAILURES failures)" "$F" $start
29532
- mail_on_failure "all" build/$F
29541
-start=`current_time`
29542
-make clean > ../build/$F 2>&1
29543
-make checkout html >> ../build/$F 2>&1
29545
-update_status "Making doc" "$F" $start
29546
-if [ $err != 0 ]; then
29548
- mail_on_failure "doc" ../build/$F
29551
-echo "</ul>" >> $RESULT_FILE
29552
-echo "</body>" >> $RESULT_FILE
29553
-echo "</html>" >> $RESULT_FILE
29556
-## (not used anymore, the daily build is now done directly on the server)
29557
-#chgrp -R webmaster build/html
29558
-#chmod -R g+w build/html
29559
-#rsync $RSYNC_OPTS build/html/* $REMOTE_SYSTEM:$REMOTE_DIR
29561
-#rsync $RSYNC_OPTS index.html *.out $REMOTE_SYSTEM:$REMOTE_DIR/results/
29562
diff -r 137e45f15c0b Misc/python.man
29563
--- a/Misc/python.man
29564
+++ b/Misc/python.man
29565
@@ -420,7 +420,7 @@
29567
Documentation: http://docs.python.org/py3k/
29569
-Developer resources: http://www.python.org/dev/
29570
+Developer resources: http://docs.python.org/devguide/
29572
Downloads: http://python.org/download/
29574
diff -r 137e45f15c0b Modules/Setup.dist
29575
--- a/Modules/Setup.dist
29576
+++ b/Modules/Setup.dist
29577
@@ -291,7 +291,7 @@
29578
#syslog syslogmodule.c # syslog daemon interface
29581
-# Curses support, requring the System V version of curses, often
29582
+# Curses support, requiring the System V version of curses, often
29583
# provided by the ncurses library. e.g. on Linux, link with -lncurses
29584
# instead of -lcurses).
29586
diff -r 137e45f15c0b Modules/_collectionsmodule.c
29587
--- a/Modules/_collectionsmodule.c
29588
+++ b/Modules/_collectionsmodule.c
29589
@@ -1401,8 +1401,10 @@
29591
int status = Py_ReprEnter(dd->default_factory);
29594
+ if (status < 0) {
29595
+ Py_DECREF(baserepr);
29598
defrepr = PyUnicode_FromString("...");
29601
diff -r 137e45f15c0b Modules/_ctypes/_ctypes.c
29602
--- a/Modules/_ctypes/_ctypes.c
29603
+++ b/Modules/_ctypes/_ctypes.c
29604
@@ -1096,7 +1096,7 @@
29606
if (!PyBytes_Check(value)) {
29607
PyErr_Format(PyExc_TypeError,
29608
- "str/bytes expected instead of %s instance",
29609
+ "bytes expected instead of %s instance",
29610
Py_TYPE(value)->tp_name);
29613
@@ -1256,49 +1256,57 @@
29614
PyTypeObject *result;
29615
StgDictObject *stgdict;
29616
StgDictObject *itemdict;
29618
- PyObject *typedict;
29619
+ PyObject *length_attr, *type_attr;
29622
Py_ssize_t itemsize, itemalign;
29625
- typedict = PyTuple_GetItem(args, 2);
29627
+ /* create the new instance (which is a class,
29628
+ since we are a metatype!) */
29629
+ result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds);
29630
+ if (result == NULL)
29633
- proto = PyDict_GetItemString(typedict, "_length_"); /* Borrowed ref */
29634
- if (!proto || !PyLong_Check(proto)) {
29635
+ /* Initialize these variables to NULL so that we can simplify error
29636
+ handling by using Py_XDECREF. */
29638
+ type_attr = NULL;
29640
+ length_attr = PyObject_GetAttrString((PyObject *)result, "_length_");
29641
+ if (!length_attr || !PyLong_Check(length_attr)) {
29642
PyErr_SetString(PyExc_AttributeError,
29643
"class must define a '_length_' attribute, "
29644
"which must be a positive integer");
29647
- length = PyLong_AsLongAndOverflow(proto, &overflow);
29648
+ Py_XDECREF(length_attr);
29651
+ length = PyLong_AsLongAndOverflow(length_attr, &overflow);
29653
PyErr_SetString(PyExc_OverflowError,
29654
"The '_length_' attribute is too large");
29658
- proto = PyDict_GetItemString(typedict, "_type_"); /* Borrowed ref */
29660
+ Py_DECREF(length_attr);
29663
+ Py_DECREF(length_attr);
29665
+ type_attr = PyObject_GetAttrString((PyObject *)result, "_type_");
29666
+ if (!type_attr) {
29667
PyErr_SetString(PyExc_AttributeError,
29668
"class must define a '_type_' attribute");
29673
stgdict = (StgDictObject *)PyObject_CallObject(
29674
(PyObject *)&PyCStgDict_Type, NULL);
29678
- itemdict = PyType_stgdict(proto);
29681
+ itemdict = PyType_stgdict(type_attr);
29683
PyErr_SetString(PyExc_TypeError,
29684
"_type_ must have storage info");
29685
- Py_DECREF((PyObject *)stgdict);
29690
assert(itemdict->format);
29691
@@ -1309,16 +1317,12 @@
29692
sprintf(buf, "(%ld)", length);
29693
stgdict->format = _ctypes_alloc_format_string(buf, itemdict->format);
29695
- if (stgdict->format == NULL) {
29696
- Py_DECREF((PyObject *)stgdict);
29699
+ if (stgdict->format == NULL)
29701
stgdict->ndim = itemdict->ndim + 1;
29702
stgdict->shape = PyMem_Malloc(sizeof(Py_ssize_t *) * stgdict->ndim);
29703
- if (stgdict->shape == NULL) {
29704
- Py_DECREF((PyObject *)stgdict);
29707
+ if (stgdict->shape == NULL)
29709
stgdict->shape[0] = length;
29710
memmove(&stgdict->shape[1], itemdict->shape,
29711
sizeof(Py_ssize_t) * (stgdict->ndim - 1));
29712
@@ -1327,7 +1331,7 @@
29713
if (length * itemsize < 0) {
29714
PyErr_SetString(PyExc_OverflowError,
29715
"array too large");
29720
itemalign = itemdict->align;
29721
@@ -1338,26 +1342,16 @@
29722
stgdict->size = itemsize * length;
29723
stgdict->align = itemalign;
29724
stgdict->length = length;
29725
- Py_INCREF(proto);
29726
- stgdict->proto = proto;
29727
+ stgdict->proto = type_attr;
29729
stgdict->paramfunc = &PyCArrayType_paramfunc;
29731
/* Arrays are passed as pointers to function calls. */
29732
stgdict->ffi_type_pointer = ffi_type_pointer;
29734
- /* create the new instance (which is a class,
29735
- since we are a metatype!) */
29736
- result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds);
29737
- if (result == NULL)
29740
/* replace the class dict by our updated spam dict */
29741
- if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) {
29742
- Py_DECREF(result);
29743
- Py_DECREF((PyObject *)stgdict);
29746
+ if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict))
29748
Py_DECREF(result->tp_dict);
29749
result->tp_dict = (PyObject *)stgdict;
29751
@@ -1366,15 +1360,20 @@
29753
if (itemdict->getfunc == _ctypes_get_fielddesc("c")->getfunc) {
29754
if (-1 == add_getset(result, CharArray_getsets))
29757
#ifdef CTYPES_UNICODE
29758
} else if (itemdict->getfunc == _ctypes_get_fielddesc("u")->getfunc) {
29759
if (-1 == add_getset(result, WCharArray_getsets))
29765
return (PyObject *)result;
29767
+ Py_XDECREF((PyObject*)stgdict);
29768
+ Py_XDECREF(type_attr);
29769
+ Py_DECREF(result);
29773
PyTypeObject PyCArrayType_Type = {
29774
@@ -4475,6 +4474,7 @@
29775
if (!PyType_Check(itemtype)) {
29776
PyErr_SetString(PyExc_TypeError,
29777
"Expected a type object");
29782
diff -r 137e45f15c0b Modules/_ctypes/callbacks.c
29783
--- a/Modules/_ctypes/callbacks.c
29784
+++ b/Modules/_ctypes/callbacks.c
29786
CThunkObject_dealloc(PyObject *_self)
29788
CThunkObject *self = (CThunkObject *)_self;
29789
+ PyObject_GC_UnTrack(self);
29790
Py_XDECREF(self->converters);
29791
Py_XDECREF(self->callable);
29792
Py_XDECREF(self->restype);
29793
diff -r 137e45f15c0b Modules/_ctypes/cfield.c
29794
--- a/Modules/_ctypes/cfield.c
29795
+++ b/Modules/_ctypes/cfield.c
29796
@@ -1372,7 +1372,7 @@
29799
PyErr_Format(PyExc_TypeError,
29800
- "string or integer address expected instead of %s instance",
29801
+ "bytes or integer address expected instead of %s instance",
29802
value->ob_type->tp_name);
29805
diff -r 137e45f15c0b Modules/_ctypes/stgdict.c
29806
--- a/Modules/_ctypes/stgdict.c
29807
+++ b/Modules/_ctypes/stgdict.c
29808
@@ -482,14 +482,33 @@
29809
char *fieldfmt = dict->format ? dict->format : "B";
29810
char *fieldname = _PyUnicode_AsString(name);
29812
- Py_ssize_t len = strlen(fieldname) + strlen(fieldfmt);
29813
- char *buf = alloca(len + 2 + 1);
29817
+ if (fieldname == NULL)
29819
+ PyErr_Format(PyExc_TypeError,
29820
+ "structure field name must be string not %s",
29821
+ name->ob_type->tp_name);
29827
+ len = strlen(fieldname) + strlen(fieldfmt);
29829
+ buf = PyMem_Malloc(len + 2 + 1);
29830
+ if (buf == NULL) {
29832
+ PyErr_NoMemory();
29835
sprintf(buf, "%s:%s:", fieldfmt, fieldname);
29837
ptr = stgdict->format;
29838
stgdict->format = _ctypes_alloc_format_string(stgdict->format, buf);
29842
if (stgdict->format == NULL) {
29844
diff -r 137e45f15c0b Modules/_cursesmodule.c
29845
--- a/Modules/_cursesmodule.c
29846
+++ b/Modules/_cursesmodule.c
29847
@@ -2379,7 +2379,8 @@
29851
- if (!PyArg_ParseTuple(args,"s;str", &str)) return NULL;
29852
+ if (!PyArg_ParseTuple(args,"y;str", &str))
29854
return PyCursesCheckERR(putp(str), "putp");
29857
@@ -2600,7 +2601,7 @@
29859
PyCursesSetupTermCalled;
29861
- if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
29862
+ if (!PyArg_ParseTuple(args, "y|iiiiiiiii:tparm",
29863
&fmt, &i1, &i2, &i3, &i4,
29864
&i5, &i6, &i7, &i8, &i9)) {
29866
diff -r 137e45f15c0b Modules/_elementtree.c
29867
--- a/Modules/_elementtree.c
29868
+++ b/Modules/_elementtree.c
29869
@@ -3000,6 +3000,7 @@
29870
" self._file = file\n"
29871
" self._events = []\n"
29872
" self._index = 0\n"
29873
+ " self._error = None\n"
29874
" self.root = self._root = None\n"
29875
" b = cElementTree.TreeBuilder()\n"
29876
" self._parser = cElementTree.XMLParser(b)\n"
29877
@@ -3008,24 +3009,31 @@
29880
" item = self._events[self._index]\n"
29881
+ " self._index += 1\n"
29883
" except IndexError:\n"
29884
- " if self._parser is None:\n"
29885
- " self.root = self._root\n"
29886
- " if self._close_file:\n"
29887
- " self._file.close()\n"
29888
- " raise StopIteration\n"
29889
- " # load event buffer\n"
29890
- " del self._events[:]\n"
29891
- " self._index = 0\n"
29892
- " data = self._file.read(16384)\n"
29895
+ " if self._error:\n"
29896
+ " e = self._error\n"
29897
+ " self._error = None\n"
29899
+ " if self._parser is None:\n"
29900
+ " self.root = self._root\n"
29901
+ " if self._close_file:\n"
29902
+ " self._file.close()\n"
29903
+ " raise StopIteration\n"
29904
+ " # load event buffer\n"
29905
+ " del self._events[:]\n"
29906
+ " self._index = 0\n"
29907
+ " data = self._file.read(16384)\n"
29910
" self._parser.feed(data)\n"
29912
- " self._root = self._parser.close()\n"
29913
- " self._parser = None\n"
29914
+ " except SyntaxError as exc:\n"
29915
+ " self._error = exc\n"
29917
- " self._index = self._index + 1\n"
29919
+ " self._root = self._parser.close()\n"
29920
+ " self._parser = None\n"
29921
" def __iter__(self):\n"
29923
"cElementTree.iterparse = iterparse\n"
29924
diff -r 137e45f15c0b Modules/_io/_iomodule.c
2660
-- Issue #8033: sqlite3: Fix 64-bit integer handling in user functions
2661
- on 32-bit architectures. Initial patch by Philippe Devalkeneer.
2663
- HTMLParser is now able to handle slashes in the start tag.
2665
- Issue #14001: CVE-2012-0845: xmlrpc: Fix an endless loop in
2666
diff -r 7085403daf43 Modules/_io/_iomodule.c
29925
2667
--- a/Modules/_io/_iomodule.c
29926
2668
+++ b/Modules/_io/_iomodule.c
29927
@@ -741,58 +741,46 @@
29928
ADD_TYPE(&PyIncrementalNewlineDecoder_Type, "IncrementalNewlineDecoder");
29930
/* Interned strings */
29931
- if (!(_PyIO_str_close = PyUnicode_InternFromString("close")))
29932
+#define ADD_INTERNED(name) \
29933
+ if (!_PyIO_str_ ## name && \
29934
+ !(_PyIO_str_ ## name = PyUnicode_InternFromString(# name))) \
29936
- if (!(_PyIO_str_closed = PyUnicode_InternFromString("closed")))
29938
+ ADD_INTERNED(close)
29939
+ ADD_INTERNED(closed)
29940
+ ADD_INTERNED(decode)
29941
+ ADD_INTERNED(encode)
29942
+ ADD_INTERNED(fileno)
29943
+ ADD_INTERNED(flush)
29944
+ ADD_INTERNED(getstate)
29945
+ ADD_INTERNED(isatty)
29946
+ ADD_INTERNED(newlines)
29947
+ ADD_INTERNED(read)
29948
+ ADD_INTERNED(read1)
29949
+ ADD_INTERNED(readable)
29950
+ ADD_INTERNED(readinto)
29951
+ ADD_INTERNED(readline)
29952
+ ADD_INTERNED(reset)
29953
+ ADD_INTERNED(seek)
29954
+ ADD_INTERNED(seekable)
29955
+ ADD_INTERNED(setstate)
29956
+ ADD_INTERNED(tell)
29957
+ ADD_INTERNED(truncate)
29958
+ ADD_INTERNED(write)
29959
+ ADD_INTERNED(writable)
29961
+ if (!_PyIO_str_nl &&
29962
+ !(_PyIO_str_nl = PyUnicode_InternFromString("\n")))
29964
- if (!(_PyIO_str_decode = PyUnicode_InternFromString("decode")))
29966
+ if (!_PyIO_empty_str &&
29967
+ !(_PyIO_empty_str = PyUnicode_FromStringAndSize(NULL, 0)))
29969
- if (!(_PyIO_str_encode = PyUnicode_InternFromString("encode")))
29970
+ if (!_PyIO_empty_bytes &&
29971
+ !(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0)))
29973
- if (!(_PyIO_str_fileno = PyUnicode_InternFromString("fileno")))
29975
- if (!(_PyIO_str_flush = PyUnicode_InternFromString("flush")))
29977
- if (!(_PyIO_str_getstate = PyUnicode_InternFromString("getstate")))
29979
- if (!(_PyIO_str_isatty = PyUnicode_InternFromString("isatty")))
29981
- if (!(_PyIO_str_newlines = PyUnicode_InternFromString("newlines")))
29983
- if (!(_PyIO_str_nl = PyUnicode_InternFromString("\n")))
29985
- if (!(_PyIO_str_read = PyUnicode_InternFromString("read")))
29987
- if (!(_PyIO_str_read1 = PyUnicode_InternFromString("read1")))
29989
- if (!(_PyIO_str_readable = PyUnicode_InternFromString("readable")))
29991
- if (!(_PyIO_str_readinto = PyUnicode_InternFromString("readinto")))
29993
- if (!(_PyIO_str_readline = PyUnicode_InternFromString("readline")))
29995
- if (!(_PyIO_str_reset = PyUnicode_InternFromString("reset")))
29997
- if (!(_PyIO_str_seek = PyUnicode_InternFromString("seek")))
29999
- if (!(_PyIO_str_seekable = PyUnicode_InternFromString("seekable")))
30001
- if (!(_PyIO_str_setstate = PyUnicode_InternFromString("setstate")))
30003
- if (!(_PyIO_str_tell = PyUnicode_InternFromString("tell")))
30005
- if (!(_PyIO_str_truncate = PyUnicode_InternFromString("truncate")))
30007
- if (!(_PyIO_str_write = PyUnicode_InternFromString("write")))
30009
- if (!(_PyIO_str_writable = PyUnicode_InternFromString("writable")))
30012
- if (!(_PyIO_empty_str = PyUnicode_FromStringAndSize(NULL, 0)))
30014
- if (!(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0)))
30016
- if (!(_PyIO_zero = PyLong_FromLong(0L)))
30017
+ if (!_PyIO_zero &&
30018
+ !(_PyIO_zero = PyLong_FromLong(0L)))
30021
state->initialized = 1;
30022
diff -r 137e45f15c0b Modules/_io/bufferedio.c
30023
--- a/Modules/_io/bufferedio.c
30024
+++ b/Modules/_io/bufferedio.c
30025
@@ -581,7 +581,7 @@
30027
/* Forward decls */
30029
-_bufferedwriter_flush_unlocked(buffered *, int);
30030
+_bufferedwriter_flush_unlocked(buffered *);
30032
_bufferedreader_fill_buffer(buffered *self);
30034
@@ -602,6 +602,18 @@
30038
+/* Sets the current error to BlockingIOError */
30040
+_set_BlockingIOError(char *msg, Py_ssize_t written)
30043
+ err = PyObject_CallFunction(PyExc_BlockingIOError, "isn",
30044
+ errno, msg, written);
30046
+ PyErr_SetObject(PyExc_BlockingIOError, err);
30050
/* Returns the address of the `written` member if a BlockingIOError was
30051
raised, NULL otherwise. The error is always re-raised. */
30052
static Py_ssize_t *
30053
@@ -752,6 +764,28 @@
30057
+buffered_flush_and_rewind_unlocked(buffered *self)
30061
+ res = _bufferedwriter_flush_unlocked(self);
30066
+ if (self->readable) {
30067
+ /* Rewind the raw stream so that its position corresponds to
30068
+ the current logical position. */
30070
+ n = _buffered_raw_seek(self, -RAW_OFFSET(self), 1);
30071
+ _bufferedreader_reset_buf(self);
30079
buffered_flush(buffered *self, PyObject *args)
30082
@@ -761,16 +795,7 @@
30084
if (!ENTER_BUFFERED(self))
30086
- res = _bufferedwriter_flush_unlocked(self, 0);
30087
- if (res != NULL && self->readable) {
30088
- /* Rewind the raw stream so that its position corresponds to
30089
- the current logical position. */
30091
- n = _buffered_raw_seek(self, -RAW_OFFSET(self), 1);
30094
- _bufferedreader_reset_buf(self);
30096
+ res = buffered_flush_and_rewind_unlocked(self);
30097
LEAVE_BUFFERED(self)
30100
@@ -791,7 +816,7 @@
30103
if (self->writable) {
30104
- res = _bufferedwriter_flush_unlocked(self, 1);
30105
+ res = buffered_flush_and_rewind_unlocked(self);
30109
@@ -826,19 +851,18 @@
30110
if (!ENTER_BUFFERED(self))
30112
res = _bufferedreader_read_all(self);
30113
- LEAVE_BUFFERED(self)
30116
res = _bufferedreader_read_fast(self, n);
30117
- if (res == Py_None) {
30119
- if (!ENTER_BUFFERED(self))
30121
- res = _bufferedreader_read_generic(self, n);
30122
- LEAVE_BUFFERED(self)
30124
+ if (res != Py_None)
30127
+ if (!ENTER_BUFFERED(self))
30129
+ res = _bufferedreader_read_generic(self, n);
30132
+ LEAVE_BUFFERED(self)
30136
@@ -864,13 +888,6 @@
30137
if (!ENTER_BUFFERED(self))
30140
- if (self->writable) {
30141
- res = _bufferedwriter_flush_unlocked(self, 1);
30147
/* Return up to n bytes. If at least one byte is buffered, we
30148
only return buffered bytes. Otherwise, we do one raw read. */
30150
@@ -890,6 +907,13 @@
30154
+ if (self->writable) {
30155
+ res = buffered_flush_and_rewind_unlocked(self);
30161
/* Fill the buffer from the raw stream, and copy it to the result. */
30162
_bufferedreader_reset_buf(self);
30163
r = _bufferedreader_fill_buffer(self);
30164
@@ -912,24 +936,10 @@
30166
buffered_readinto(buffered *self, PyObject *args)
30168
- PyObject *res = NULL;
30170
CHECK_INITIALIZED(self)
30172
- /* TODO: use raw.readinto() instead! */
30173
- if (self->writable) {
30174
- if (!ENTER_BUFFERED(self))
30176
- res = _bufferedwriter_flush_unlocked(self, 0);
30177
- LEAVE_BUFFERED(self)
30182
- res = bufferediobase_readinto((PyObject *)self, args);
30186
+ /* TODO: use raw.readinto() (or a direct copy from our buffer) instead! */
30187
+ return bufferediobase_readinto((PyObject *)self, args);
30191
@@ -967,12 +977,6 @@
30194
/* Now we try to get some more from the raw stream */
30195
- if (self->writable) {
30196
- res = _bufferedwriter_flush_unlocked(self, 1);
30201
chunks = PyList_New(0);
30202
if (chunks == NULL)
30204
@@ -986,9 +990,16 @@
30212
+ if (self->writable) {
30213
+ PyObject *r = buffered_flush_and_rewind_unlocked(self);
30220
_bufferedreader_reset_buf(self);
30221
@@ -1087,6 +1098,9 @@
30223
CHECK_CLOSED(self, "seek of closed file")
30225
+ if (_PyIOBase_check_seekable(self->raw, Py_True) == NULL)
30228
target = PyNumber_AsOff_t(targetobj, PyExc_ValueError);
30229
if (target == -1 && PyErr_Occurred())
30231
@@ -1119,7 +1133,7 @@
30233
/* Fallback: invoke raw seek() method and clear buffer */
30234
if (self->writable) {
30235
- res = _bufferedwriter_flush_unlocked(self, 0);
30236
+ res = _bufferedwriter_flush_unlocked(self);
30240
@@ -1157,20 +1171,11 @@
30243
if (self->writable) {
30244
- res = _bufferedwriter_flush_unlocked(self, 0);
30245
+ res = buffered_flush_and_rewind_unlocked(self);
30250
- if (self->readable) {
30251
- if (pos == Py_None) {
30252
- /* Rewind the raw stream so that its position corresponds to
30253
- the current logical position. */
30254
- if (_buffered_raw_seek(self, -RAW_OFFSET(self), 1) == -1)
30257
- _bufferedreader_reset_buf(self);
30259
res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_truncate, pos, NULL);
30262
@@ -1367,17 +1372,18 @@
30266
+ self->pos += current_size;
30268
- _bufferedreader_reset_buf(self);
30269
/* We're going past the buffer's bounds, flush it */
30270
if (self->writable) {
30271
- res = _bufferedwriter_flush_unlocked(self, 1);
30272
+ res = buffered_flush_and_rewind_unlocked(self);
30279
+ _bufferedreader_reset_buf(self);
30282
if (PyList_Append(chunks, data) < 0) {
30283
@@ -1460,6 +1466,14 @@
30284
memcpy(out, self->buffer + self->pos, current_size);
30285
remaining -= current_size;
30286
written += current_size;
30287
+ self->pos += current_size;
30289
+ /* Flush the write buffer if necessary */
30290
+ if (self->writable) {
30291
+ PyObject *r = buffered_flush_and_rewind_unlocked(self);
30296
_bufferedreader_reset_buf(self);
30297
while (remaining > 0) {
30298
@@ -1712,6 +1726,7 @@
30300
PyObject *memobj, *res;
30303
/* NOTE: the buffer needn't be released as its object is NULL. */
30304
if (PyBuffer_FillInfo(&buf, NULL, start, len, 1, PyBUF_CONTIG_RO) == -1)
30306
@@ -1724,11 +1739,21 @@
30307
raised (see issue #10956).
30311
res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_write, memobj, NULL);
30313
} while (res == NULL && _trap_eintr());
30317
+ if (res == Py_None) {
30318
+ /* Non-blocking stream would have blocked. Special return code!
30319
+ Being paranoid we reset errno in case it is changed by code
30320
+ triggered by a decref. errno is used by _set_BlockingIOError(). */
30325
n = PyNumber_AsSsize_t(res, PyExc_ValueError);
30327
if (n < 0 || n > len) {
30328
@@ -1745,7 +1770,7 @@
30329
/* `restore_pos` is 1 if we need to restore the raw stream position at
30330
the end, 0 otherwise. */
30332
-_bufferedwriter_flush_unlocked(buffered *self, int restore_pos)
30333
+_bufferedwriter_flush_unlocked(buffered *self)
30335
Py_ssize_t written = 0;
30336
Py_off_t n, rewind;
30337
@@ -1767,14 +1792,11 @@
30338
Py_SAFE_DOWNCAST(self->write_end - self->write_pos,
30339
Py_off_t, Py_ssize_t));
30341
- Py_ssize_t *w = _buffered_check_blocking_error();
30344
- self->write_pos += *w;
30345
- self->raw_pos = self->write_pos;
30348
- /* Already re-raised */
30351
+ else if (n == -2) {
30352
+ _set_BlockingIOError("write could not complete without blocking",
30356
self->write_pos += n;
30357
@@ -1787,16 +1809,6 @@
30361
- if (restore_pos) {
30362
- Py_off_t forward = rewind - written;
30363
- if (forward != 0) {
30364
- n = _buffered_raw_seek(self, forward, 1);
30368
- self->raw_pos += forward;
30371
_bufferedwriter_reset_buf(self);
30374
@@ -1849,7 +1861,7 @@
30377
/* First write the current buffer */
30378
- res = _bufferedwriter_flush_unlocked(self, 0);
30379
+ res = _bufferedwriter_flush_unlocked(self);
30381
Py_ssize_t *w = _buffered_check_blocking_error();
30383
@@ -1872,14 +1884,19 @@
30385
memcpy(self->buffer + self->write_end, buf.buf, buf.len);
30386
self->write_end += buf.len;
30387
+ self->pos += buf.len;
30391
/* Buffer as much as possible. */
30392
memcpy(self->buffer + self->write_end, buf.buf, avail);
30393
self->write_end += avail;
30394
- /* Already re-raised */
30396
+ self->pos += avail;
30397
+ /* XXX Modifying the existing exception e using the pointer w
30398
+ will change e.characters_written but not e.args[2].
30399
+ Therefore we just replace with a new error. */
30400
+ _set_BlockingIOError("write could not complete without blocking",
30405
@@ -1904,11 +1921,9 @@
30406
Py_ssize_t n = _bufferedwriter_raw_write(
30407
self, (char *) buf.buf + written, buf.len - written);
30409
- Py_ssize_t *w = _buffered_check_blocking_error();
30415
+ } else if (n == -2) {
30416
+ /* Write failed because raw file is non-blocking */
30417
if (remaining > self->buffer_size) {
30418
/* Can't buffer everything, still buffer as much as possible */
30419
memcpy(self->buffer,
30420
@@ -1916,8 +1931,9 @@
30422
ADJUST_POSITION(self, self->buffer_size);
30423
self->write_end = self->buffer_size;
30424
- *w = written + self->buffer_size;
30425
- /* Already re-raised */
30426
+ written += self->buffer_size;
30427
+ _set_BlockingIOError("write could not complete without "
30428
+ "blocking", written);
30432
@@ -2210,6 +2226,11 @@
30434
bufferedrwpair_closed_get(rwpair *self, void *context)
30436
+ if (self->writer == NULL) {
30437
+ PyErr_SetString(PyExc_RuntimeError,
30438
+ "the BufferedRWPair object is being garbage-collected");
30441
return PyObject_GetAttr((PyObject *) self->writer, _PyIO_str_closed);
30444
diff -r 137e45f15c0b Modules/_io/fileio.c
30445
--- a/Modules/_io/fileio.c
30446
+++ b/Modules/_io/fileio.c
30448
#define SMALLCHUNK BUFSIZ
30451
-#if SIZEOF_INT < 4
30452
-#define BIGCHUNK (512 * 32)
30454
-#define BIGCHUNK (512 * 1024)
30460
@@ -259,34 +253,23 @@
30464
- if (PyUnicode_Check(nameobj))
30465
+ if (PyUnicode_Check(nameobj)) {
30466
+ int rv = _PyUnicode_HasNULChars(nameobj);
30469
+ PyErr_SetString(PyExc_TypeError, "embedded NUL character");
30472
widename = PyUnicode_AS_UNICODE(nameobj);
30474
if (widename == NULL)
30478
- if (PyBytes_Check(nameobj) || PyByteArray_Check(nameobj)) {
30479
- Py_ssize_t namelen;
30480
- if (PyObject_AsCharBuffer(nameobj, &name, &namelen) < 0)
30482
+ if (!PyUnicode_FSConverter(nameobj, &stringobj)) {
30486
- PyObject *u = PyUnicode_FromObject(nameobj);
30491
- stringobj = PyUnicode_EncodeFSDefault(u);
30493
- if (stringobj == NULL)
30495
- if (!PyBytes_Check(stringobj)) {
30496
- PyErr_SetString(PyExc_TypeError,
30497
- "encoder failed to return bytes");
30500
- name = PyBytes_AS_STRING(stringobj);
30502
+ name = PyBytes_AS_STRING(stringobj);
30506
@@ -512,6 +495,7 @@
30513
return err_closed();
30514
@@ -535,10 +519,12 @@
30515
Py_END_ALLOW_THREADS
30519
PyBuffer_Release(&pbuf);
30521
- if (errno == EAGAIN)
30522
+ if (err == EAGAIN)
30525
PyErr_SetFromErrno(PyExc_IOError);
30528
@@ -565,15 +551,10 @@
30532
- if (currentsize > SMALLCHUNK) {
30533
- /* Keep doubling until we reach BIGCHUNK;
30534
- then keep adding BIGCHUNK. */
30535
- if (currentsize <= BIGCHUNK)
30536
- return currentsize + currentsize;
30538
- return currentsize + BIGCHUNK;
30540
- return currentsize + SMALLCHUNK;
30541
+ /* Expand the buffer by an amount proportional to the current size,
30542
+ giving us amortized linear-time behavior. Use a less-than-double
30543
+ growth factor to avoid excessive allocation. */
30544
+ return currentsize + (currentsize >> 3) + 6;
30548
@@ -686,9 +667,11 @@
30554
- if (errno == EAGAIN)
30555
+ if (err == EAGAIN)
30558
PyErr_SetFromErrno(PyExc_IOError);
30561
@@ -708,6 +691,7 @@
30568
return err_closed();
30569
@@ -738,12 +722,14 @@
30570
Py_END_ALLOW_THREADS
30575
PyBuffer_Release(&pbuf);
30578
- if (errno == EAGAIN)
30579
+ if (err == EAGAIN)
30582
PyErr_SetFromErrno(PyExc_IOError);
30585
diff -r 137e45f15c0b Modules/_io/iobase.c
30586
--- a/Modules/_io/iobase.c
30587
+++ b/Modules/_io/iobase.c
30588
@@ -156,6 +156,19 @@
30589
return PyBool_FromLong(IS_CLOSED(self));
30593
+iobase_get_dict(PyObject *self)
30595
+ PyObject **dictptr = _PyObject_GetDictPtr(self);
30599
+ if (dict == NULL)
30600
+ dict = *dictptr = PyDict_New();
30601
+ Py_XINCREF(dict);
30606
_PyIOBase_check_closed(PyObject *self, PyObject *args)
30608
@@ -691,6 +704,7 @@
30611
static PyGetSetDef iobase_getset[] = {
30612
+ {"__dict__", (getter)iobase_get_dict, NULL, NULL},
30613
{"closed", (getter)iobase_closed_get, NULL, NULL},
30616
diff -r 137e45f15c0b Modules/_multiprocessing/multiprocessing.c
30617
--- a/Modules/_multiprocessing/multiprocessing.c
30618
+++ b/Modules/_multiprocessing/multiprocessing.c
30621
#include "multiprocessing.h"
30624
+#if (defined(CMSG_LEN) && defined(SCM_RIGHTS))
30625
#define HAVE_FD_TRANSFER 1
30627
#define HAVE_FD_TRANSFER 0
30628
@@ -97,32 +97,38 @@
30629
/* Functions for transferring file descriptors between processes.
30630
Reimplements some of the functionality of the fdcred
30631
module at http://www.mca-ltd.com/resources/fdcred_1.tgz. */
30632
+/* Based in http://resin.csoft.net/cgi-bin/man.cgi?section=3&topic=CMSG_DATA */
30635
multiprocessing_sendfd(PyObject *self, PyObject *args)
30638
+ struct iovec dummy_iov;
30640
- char buf[CMSG_SPACE(sizeof(int))];
30641
- struct msghdr msg = {0};
30642
- struct iovec dummy_iov;
30643
+ struct msghdr msg;
30644
struct cmsghdr *cmsg;
30646
+ struct cmsghdr hdr;
30647
+ unsigned char buf[CMSG_SPACE(sizeof(int))];
30650
if (!PyArg_ParseTuple(args, "ii", &conn, &fd))
30653
dummy_iov.iov_base = &dummy_char;
30654
dummy_iov.iov_len = 1;
30655
- msg.msg_control = buf;
30656
- msg.msg_controllen = sizeof(buf);
30658
+ memset(&msg, 0, sizeof(msg));
30659
+ msg.msg_control = &cmsgbuf.buf;
30660
+ msg.msg_controllen = sizeof(cmsgbuf.buf);
30661
msg.msg_iov = &dummy_iov;
30662
msg.msg_iovlen = 1;
30664
cmsg = CMSG_FIRSTHDR(&msg);
30665
+ cmsg->cmsg_len = CMSG_LEN(sizeof(int));
30666
cmsg->cmsg_level = SOL_SOCKET;
30667
cmsg->cmsg_type = SCM_RIGHTS;
30668
- cmsg->cmsg_len = CMSG_LEN(sizeof(int));
30669
- msg.msg_controllen = cmsg->cmsg_len;
30670
- *CMSG_DATA(cmsg) = fd;
30671
+ * (int *) CMSG_DATA(cmsg) = fd;
30673
Py_BEGIN_ALLOW_THREADS
30674
res = sendmsg(conn, &msg, 0);
30675
@@ -138,20 +144,26 @@
30679
- char buf[CMSG_SPACE(sizeof(int))];
30680
+ struct iovec dummy_iov;
30681
struct msghdr msg = {0};
30682
- struct iovec dummy_iov;
30683
struct cmsghdr *cmsg;
30685
+ struct cmsghdr hdr;
30686
+ unsigned char buf[CMSG_SPACE(sizeof(int))];
30689
if (!PyArg_ParseTuple(args, "i", &conn))
30692
dummy_iov.iov_base = &dummy_char;
30693
dummy_iov.iov_len = 1;
30694
- msg.msg_control = buf;
30695
- msg.msg_controllen = sizeof(buf);
30697
+ memset(&msg, 0, sizeof(msg));
30698
+ msg.msg_control = &cmsgbuf.buf;
30699
+ msg.msg_controllen = sizeof(cmsgbuf.buf);
30700
msg.msg_iov = &dummy_iov;
30701
msg.msg_iovlen = 1;
30703
cmsg = CMSG_FIRSTHDR(&msg);
30704
cmsg->cmsg_level = SOL_SOCKET;
30705
cmsg->cmsg_type = SCM_RIGHTS;
30706
@@ -165,7 +177,18 @@
30708
return PyErr_SetFromErrno(PyExc_OSError);
30710
- fd = *CMSG_DATA(cmsg);
30711
+ if (msg.msg_controllen < CMSG_LEN(sizeof(int)) ||
30712
+ (cmsg = CMSG_FIRSTHDR(&msg)) == NULL ||
30713
+ cmsg->cmsg_level != SOL_SOCKET ||
30714
+ cmsg->cmsg_type != SCM_RIGHTS ||
30715
+ cmsg->cmsg_len < CMSG_LEN(sizeof(int))) {
30716
+ /* If at least one control message is present, there should be
30717
+ no room for any further data in the buffer. */
30718
+ PyErr_SetString(PyExc_RuntimeError, "No file descriptor received");
30722
+ fd = * (int *) CMSG_DATA(cmsg);
30723
return Py_BuildValue("i", fd);
30726
diff -r 137e45f15c0b Modules/_multiprocessing/semaphore.c
30727
--- a/Modules/_multiprocessing/semaphore.c
30728
+++ b/Modules/_multiprocessing/semaphore.c
30729
@@ -267,7 +267,7 @@
30731
semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds)
30733
- int blocking = 1, res;
30734
+ int blocking = 1, res, err = 0;
30736
PyObject *timeout_obj = Py_None;
30737
struct timespec deadline = {0};
30738
@@ -313,11 +313,13 @@
30740
res = sem_timedwait(self->handle, &deadline);
30741
Py_END_ALLOW_THREADS
30743
if (res == MP_EXCEPTION_HAS_BEEN_SET)
30745
} while (res < 0 && errno == EINTR && !PyErr_CheckSignals());
30749
if (errno == EAGAIN || errno == ETIMEDOUT)
30751
else if (errno == EINTR)
30752
diff -r 137e45f15c0b Modules/_pickle.c
30753
--- a/Modules/_pickle.c
30754
+++ b/Modules/_pickle.c
30755
@@ -153,7 +153,7 @@
30757
Pdata_dealloc(Pdata *self)
30759
- int i = Py_SIZE(self);
30760
+ Py_ssize_t i = Py_SIZE(self);
30762
Py_DECREF(self->data[i]);
30764
@@ -190,9 +190,9 @@
30765
* number of items, this is a (non-erroneous) NOP.
30768
-Pdata_clear(Pdata *self, int clearto)
30770
- int i = Py_SIZE(self);
30771
+Pdata_clear(Pdata *self, Py_ssize_t clearto)
30773
+ Py_ssize_t i = Py_SIZE(self);
30776
return stack_underflow();
30777
@@ -303,7 +303,7 @@
30782
+ Py_ssize_t me_value;
30786
@@ -328,7 +328,7 @@
30787
Py_ssize_t max_output_len; /* Allocation size of output_buffer. */
30788
int proto; /* Pickle protocol number, >= 0 */
30789
int bin; /* Boolean, true if proto > 0 */
30790
- int buf_size; /* Size of the current buffered pickle data */
30791
+ Py_ssize_t buf_size; /* Size of the current buffered pickle data */
30792
int fast; /* Enable fast mode if set to a true value.
30793
The fast mode disable the usage of memo,
30794
therefore speeding the pickling process by
30795
@@ -369,7 +369,7 @@
30796
char *errors; /* Name of errors handling scheme to used when
30797
decoding strings. The default value is
30799
- int *marks; /* Mark stack, used for unpickling container
30800
+ Py_ssize_t *marks; /* Mark stack, used for unpickling container
30802
Py_ssize_t num_marks; /* Number of marks in the mark stack. */
30803
Py_ssize_t marks_size; /* Current allocated size of the mark stack. */
30804
@@ -556,7 +556,7 @@
30807
/* Returns NULL on failure, a pointer to the value otherwise. */
30809
+static Py_ssize_t *
30810
PyMemoTable_Get(PyMemoTable *self, PyObject *key)
30812
PyMemoEntry *entry = _PyMemoTable_Lookup(self, key);
30813
@@ -567,7 +567,7 @@
30815
/* Returns -1 on failure, 0 on success. */
30817
-PyMemoTable_Set(PyMemoTable *self, PyObject *key, long value)
30818
+PyMemoTable_Set(PyMemoTable *self, PyObject *key, Py_ssize_t value)
30820
PyMemoEntry *entry;
30822
@@ -700,7 +700,7 @@
30823
return (result == NULL) ? -1 : 0;
30828
_Pickler_Write(PicklerObject *self, const char *s, Py_ssize_t n)
30830
Py_ssize_t i, required;
30831
@@ -735,7 +735,7 @@
30835
- self->max_output_len = (self->output_len + n) * 2;
30836
+ self->max_output_len = (self->output_len + n) / 2 * 3;
30837
if (_PyBytes_Resize(&self->output_buffer, self->max_output_len) < 0)
30840
@@ -1219,9 +1219,9 @@
30842
memo_get(PicklerObject *self, PyObject *key)
30845
+ Py_ssize_t *value;
30850
value = PyMemoTable_Get(self->memo, key);
30851
if (value == NULL) {
30852
@@ -1231,8 +1231,9 @@
30856
- PyOS_snprintf(pdata + 1, sizeof(pdata) - 1, "%ld\n", *value);
30857
- len = (int)strlen(pdata);
30858
+ PyOS_snprintf(pdata + 1, sizeof(pdata) - 1,
30859
+ "%" PY_FORMAT_SIZE_T "d\n", *value);
30860
+ len = strlen(pdata);
30863
if (*value < 256) {
30864
@@ -1266,9 +1267,9 @@
30866
memo_put(PicklerObject *self, PyObject *obj)
30876
@@ -1280,7 +1281,8 @@
30880
- PyOS_snprintf(pdata + 1, sizeof(pdata) - 1, "%ld\n", x);
30881
+ PyOS_snprintf(pdata + 1, sizeof(pdata) - 1,
30882
+ "%" PY_FORMAT_SIZE_T "d\n", x);
30883
len = strlen(pdata);
30886
@@ -1482,7 +1484,7 @@
30887
save_int(PicklerObject *self, long x)
30891
+ Py_ssize_t len = 0;
30894
#if SIZEOF_LONG > 4
30895
@@ -1609,7 +1611,7 @@
30899
- size = (int)nbytes;
30900
+ size = (Py_ssize_t) nbytes;
30901
for (i = 1; i < 5; i++) {
30902
header[i] = (unsigned char)(size & 0xff);
30904
@@ -1698,34 +1700,66 @@
30905
if (self->proto < 3) {
30906
/* Older pickle protocols do not have an opcode for pickling bytes
30907
objects. Therefore, we need to fake the copy protocol (i.e.,
30908
- the __reduce__ method) to permit bytes object unpickling. */
30909
+ the __reduce__ method) to permit bytes object unpickling.
30911
+ Here we use a hack to be compatible with Python 2. Since in Python
30912
+ 2 'bytes' is just an alias for 'str' (which has different
30913
+ parameters than the actual bytes object), we use codecs.encode
30914
+ to create the appropriate 'str' object when unpickled using
30915
+ Python 2 *and* the appropriate 'bytes' object when unpickled
30916
+ using Python 3. Again this is a hack and we don't need to do this
30917
+ with newer protocols. */
30918
+ static PyObject *codecs_encode = NULL;
30919
PyObject *reduce_value = NULL;
30920
- PyObject *bytelist = NULL;
30923
- bytelist = PySequence_List(obj);
30924
- if (bytelist == NULL)
30925
+ if (codecs_encode == NULL) {
30926
+ PyObject *codecs_module = PyImport_ImportModule("codecs");
30927
+ if (codecs_module == NULL) {
30930
+ codecs_encode = PyObject_GetAttrString(codecs_module, "encode");
30931
+ Py_DECREF(codecs_module);
30932
+ if (codecs_encode == NULL) {
30937
+ if (PyBytes_GET_SIZE(obj) == 0) {
30938
+ reduce_value = Py_BuildValue("(O())", (PyObject*)&PyBytes_Type);
30941
+ static PyObject *latin1 = NULL;
30942
+ PyObject *unicode_str =
30943
+ PyUnicode_DecodeLatin1(PyBytes_AS_STRING(obj),
30944
+ PyBytes_GET_SIZE(obj),
30946
+ if (unicode_str == NULL)
30948
+ if (latin1 == NULL) {
30949
+ latin1 = PyUnicode_InternFromString("latin1");
30950
+ if (latin1 == NULL)
30953
+ reduce_value = Py_BuildValue("(O(OO))",
30954
+ codecs_encode, unicode_str, latin1);
30955
+ Py_DECREF(unicode_str);
30958
+ if (reduce_value == NULL)
30961
- reduce_value = Py_BuildValue("(O(O))", (PyObject *)&PyBytes_Type,
30963
- if (reduce_value == NULL) {
30964
- Py_DECREF(bytelist);
30968
/* save_reduce() will memoize the object automatically. */
30969
status = save_reduce(self, reduce_value, obj);
30970
Py_DECREF(reduce_value);
30971
- Py_DECREF(bytelist);
30979
- size = PyBytes_Size(obj);
30982
+ size = PyBytes_GET_SIZE(obj);
30986
@@ -1743,6 +1777,8 @@
30990
+ PyErr_SetString(PyExc_OverflowError,
30991
+ "cannot serialize a bytes object larger than 4GB");
30992
return -1; /* string too large */
30995
@@ -1867,8 +1903,11 @@
30998
size = PyBytes_GET_SIZE(encoded);
30999
- if (size < 0 || size > 0xffffffffL)
31000
+ if (size > 0xffffffffL) {
31001
+ PyErr_SetString(PyExc_OverflowError,
31002
+ "cannot serialize a string larger than 4GB");
31003
goto error; /* string too large */
31006
pdata[0] = BINUNICODE;
31007
pdata[1] = (unsigned char)(size & 0xff);
31008
@@ -1913,9 +1952,9 @@
31010
/* A helper for save_tuple. Push the len elements in tuple t on the stack. */
31012
-store_tuple_elements(PicklerObject *self, PyObject *t, int len)
31015
+store_tuple_elements(PicklerObject *self, PyObject *t, Py_ssize_t len)
31019
assert(PyTuple_Size(t) == len);
31021
@@ -1940,7 +1979,7 @@
31023
save_tuple(PicklerObject *self, PyObject *obj)
31026
+ Py_ssize_t len, i;
31028
const char mark_op = MARK;
31029
const char tuple_op = TUPLE;
31030
@@ -2163,7 +2202,7 @@
31031
batch_list_exact(PicklerObject *self, PyObject *obj)
31033
PyObject *item = NULL;
31034
- int this_batch, total;
31035
+ Py_ssize_t this_batch, total;
31037
const char append_op = APPEND;
31038
const char appends_op = APPENDS;
31039
@@ -2208,7 +2247,7 @@
31040
save_list(PicklerObject *self, PyObject *obj)
31047
if (self->fast && !fast_save_enter(self, obj))
31048
@@ -2468,7 +2507,7 @@
31050
PyObject *items, *iter;
31056
if (self->fast && !fast_save_enter(self, obj))
31057
@@ -2603,7 +2642,7 @@
31058
PyObject *code_obj; /* extension code as Python object */
31059
long code; /* extension code as C value */
31064
PyTuple_SET_ITEM(two_tuple, 0, module_name);
31065
PyTuple_SET_ITEM(two_tuple, 1, global_name);
31066
@@ -2626,9 +2665,10 @@
31068
code = PyLong_AS_LONG(code_obj);
31069
if (code <= 0 || code > 0x7fffffffL) {
31070
- PyErr_Format(PicklingError,
31071
- "Can't pickle %R: extension code %ld is out of range",
31073
+ if (!PyErr_Occurred())
31074
+ PyErr_Format(PicklingError,
31075
+ "Can't pickle %R: extension code %ld is out of range",
31080
@@ -3133,10 +3173,6 @@
31081
status = save_global(self, obj, NULL);
31084
- else if (PyType_IsSubtype(type, &PyType_Type)) {
31085
- status = save_global(self, obj, NULL);
31089
/* XXX: This part needs some unit tests. */
31091
@@ -3155,6 +3191,10 @@
31093
reduce_value = _Pickler_FastCall(self, reduce_func, obj);
31095
+ else if (PyType_IsSubtype(type, &PyType_Type)) {
31096
+ status = save_global(self, obj, NULL);
31100
static PyObject *reduce_str = NULL;
31101
static PyObject *reduce_ex_str = NULL;
31102
@@ -3477,7 +3517,7 @@
31103
PyObject *key, *value;
31105
key = PyLong_FromVoidPtr(entry.me_key);
31106
- value = Py_BuildValue("lO", entry.me_value, entry.me_key);
31107
+ value = Py_BuildValue("nO", entry.me_value, entry.me_key);
31109
if (key == NULL || value == NULL) {
31111
@@ -3638,7 +3678,7 @@
31114
while (PyDict_Next(obj, &i, &key, &value)) {
31116
+ Py_ssize_t memo_id;
31117
PyObject *memo_obj;
31119
if (!PyTuple_Check(value) || Py_SIZE(value) != 2) {
31120
@@ -3646,7 +3686,7 @@
31121
"'memo' values must be 2-item tuples");
31124
- memo_id = PyLong_AsLong(PyTuple_GET_ITEM(value, 0));
31125
+ memo_id = PyLong_AsSsize_t(PyTuple_GET_ITEM(value, 0));
31126
if (memo_id == -1 && PyErr_Occurred())
31128
memo_obj = PyTuple_GET_ITEM(value, 1);
31129
@@ -3777,7 +3817,7 @@
31130
module_name, global_name);
31135
marker(UnpicklerObject *self)
31137
if (self->num_marks < 1) {
31138
@@ -3855,6 +3895,28 @@
31142
+/* s contains x bytes of an unsigned little-endian integer. Return its value
31143
+ * as a C Py_ssize_t, or -1 if it's higher than PY_SSIZE_T_MAX.
31146
+calc_binsize(char *bytes, int size)
31148
+ unsigned char *s = (unsigned char *)bytes;
31151
+ assert(size == 4);
31153
+ x = (size_t) s[0];
31154
+ x |= (size_t) s[1] << 8;
31155
+ x |= (size_t) s[2] << 16;
31156
+ x |= (size_t) s[3] << 24;
31158
+ if (x > PY_SSIZE_T_MAX)
31161
+ return (Py_ssize_t) x;
31164
/* s contains x bytes of a little-endian integer. Return its value as a
31165
* C int. Obscure: when x is 1 or 2, this is an unsigned little-endian
31166
* int, but when x is 4 it's a signed one. This is an historical source
31167
@@ -4099,16 +4161,18 @@
31168
load_binbytes(UnpicklerObject *self)
31175
if (_Unpickler_Read(self, &s, 4) < 0)
31178
- x = calc_binint(s, 4);
31179
+ x = calc_binsize(s, 4);
31181
- PyErr_SetString(UnpicklingError,
31182
- "BINBYTES pickle has negative byte count");
31183
+ PyErr_Format(PyExc_OverflowError,
31184
+ "BINBYTES exceeds system's maximum size of %zd bytes",
31190
@@ -4126,7 +4190,7 @@
31191
load_short_binbytes(UnpicklerObject *self)
31198
if (_Unpickler_Read(self, &s, 1) < 0)
31199
@@ -4149,7 +4213,7 @@
31200
load_binstring(UnpicklerObject *self)
31207
if (_Unpickler_Read(self, &s, 4) < 0)
31208
@@ -4178,7 +4242,7 @@
31209
load_short_binstring(UnpicklerObject *self)
31216
if (_Unpickler_Read(self, &s, 1) < 0)
31217
@@ -4222,19 +4286,22 @@
31218
load_binunicode(UnpicklerObject *self)
31225
if (_Unpickler_Read(self, &s, 4) < 0)
31228
- size = calc_binint(s, 4);
31229
+ size = calc_binsize(s, 4);
31231
- PyErr_SetString(UnpicklingError,
31232
- "BINUNICODE pickle has negative byte count");
31233
+ PyErr_Format(PyExc_OverflowError,
31234
+ "BINUNICODE exceeds system's maximum size of %zd bytes",
31241
if (_Unpickler_Read(self, &s, size) < 0)
31244
@@ -4250,7 +4317,7 @@
31245
load_tuple(UnpicklerObject *self)
31251
if ((i = marker(self)) < 0)
31253
@@ -4309,7 +4376,7 @@
31254
load_list(UnpicklerObject *self)
31260
if ((i = marker(self)) < 0)
31262
@@ -4325,7 +4392,7 @@
31263
load_dict(UnpicklerObject *self)
31265
PyObject *dict, *key, *value;
31267
+ Py_ssize_t i, j, k;
31269
if ((i = marker(self)) < 0)
31271
@@ -4369,7 +4436,7 @@
31272
load_obj(UnpicklerObject *self)
31274
PyObject *cls, *args, *obj = NULL;
31278
if ((i = marker(self)) < 0)
31280
@@ -4400,7 +4467,7 @@
31281
PyObject *module_name;
31282
PyObject *class_name;
31288
if ((i = marker(self)) < 0)
31289
@@ -4594,7 +4661,7 @@
31291
load_pop(UnpicklerObject *self)
31293
- int len = Py_SIZE(self->stack);
31294
+ Py_ssize_t len = Py_SIZE(self->stack);
31296
/* Note that we split the (pickle.py) stack into two stacks,
31297
* an object stack and a mark stack. We have to be clever and
31298
@@ -4618,7 +4685,7 @@
31300
load_pop_mark(UnpicklerObject *self)
31305
if ((i = marker(self)) < 0)
31307
@@ -4632,7 +4699,7 @@
31308
load_dup(UnpicklerObject *self)
31314
if ((len = Py_SIZE(self->stack)) <= 0)
31315
return stack_underflow();
31316
@@ -4711,10 +4778,7 @@
31317
if (_Unpickler_Read(self, &s, 4) < 0)
31320
- idx = (long)Py_CHARMASK(s[0]);
31321
- idx |= (long)Py_CHARMASK(s[1]) << 8;
31322
- idx |= (long)Py_CHARMASK(s[2]) << 16;
31323
- idx |= (long)Py_CHARMASK(s[3]) << 24;
31324
+ idx = calc_binsize(s, 4);
31326
value = _Unpickler_MemoGet(self, idx);
31327
if (value == NULL) {
31328
@@ -4821,8 +4885,12 @@
31330
idx = PyLong_AsSsize_t(key);
31332
- if (idx == -1 && PyErr_Occurred())
31334
+ if (!PyErr_Occurred())
31335
+ PyErr_SetString(PyExc_ValueError,
31336
+ "negative PUT argument");
31340
return _Unpickler_MemoPut(self, idx, value);
31342
@@ -4860,20 +4928,22 @@
31343
return stack_underflow();
31344
value = self->stack->data[Py_SIZE(self->stack) - 1];
31346
- idx = (long)Py_CHARMASK(s[0]);
31347
- idx |= (long)Py_CHARMASK(s[1]) << 8;
31348
- idx |= (long)Py_CHARMASK(s[2]) << 16;
31349
- idx |= (long)Py_CHARMASK(s[3]) << 24;
31350
+ idx = calc_binsize(s, 4);
31352
+ PyErr_SetString(PyExc_ValueError,
31353
+ "negative LONG_BINPUT argument");
31357
return _Unpickler_MemoPut(self, idx, value);
31361
-do_append(UnpicklerObject *self, int x)
31362
+do_append(UnpicklerObject *self, Py_ssize_t x)
31367
+ Py_ssize_t len, i;
31369
len = Py_SIZE(self->stack);
31370
if (x > len || x <= 0)
31371
@@ -4886,14 +4956,15 @@
31372
if (PyList_Check(list)) {
31374
Py_ssize_t list_len;
31377
slice = Pdata_poplist(self->stack, x);
31380
list_len = PyList_GET_SIZE(list);
31381
- i = PyList_SetSlice(list, list_len, list_len, slice);
31382
+ ret = PyList_SetSlice(list, list_len, list_len, slice);
31388
PyObject *append_func;
31389
@@ -4932,11 +5003,11 @@
31393
-do_setitems(UnpicklerObject *self, int x)
31394
+do_setitems(UnpicklerObject *self, Py_ssize_t x)
31396
PyObject *value, *key;
31399
+ Py_ssize_t len, i;
31402
len = Py_SIZE(self->stack);
31403
@@ -5104,20 +5175,21 @@
31405
if ((self->num_marks + 1) >= self->marks_size) {
31408
+ Py_ssize_t *marks;
31410
/* Use the size_t type to check for overflow. */
31411
alloc = ((size_t)self->num_marks << 1) + 20;
31412
- if (alloc > PY_SSIZE_T_MAX ||
31413
+ if (alloc > (PY_SSIZE_T_MAX / sizeof(Py_ssize_t)) ||
31414
alloc <= ((size_t)self->num_marks + 1)) {
31419
if (self->marks == NULL)
31420
- marks = (int *)PyMem_Malloc(alloc * sizeof(int));
31421
+ marks = (Py_ssize_t *) PyMem_Malloc(alloc * sizeof(Py_ssize_t));
31423
- marks = (int *)PyMem_Realloc(self->marks, alloc * sizeof(int));
31424
+ marks = (Py_ssize_t *) PyMem_Realloc(self->marks,
31425
+ alloc * sizeof(Py_ssize_t));
31426
if (marks == NULL) {
31429
@@ -5258,13 +5330,12 @@
31434
- PyErr_SetNone(PyExc_EOFError);
31438
- PyErr_Format(UnpicklingError,
31439
- "invalid load key, '%c'.", s[0]);
31440
+ if (s[0] == '\0')
31441
+ PyErr_SetNone(PyExc_EOFError);
31443
+ PyErr_Format(UnpicklingError,
31444
+ "invalid load key, '%c'.", s[0]);
31448
diff -r 137e45f15c0b Modules/_posixsubprocess.c
31449
--- a/Modules/_posixsubprocess.c
31450
+++ b/Modules/_posixsubprocess.c
31452
/* Authors: Gregory P. Smith & Jeffrey Yasskin */
31453
#include "Python.h"
31455
-#define _GNU_SOURCE
31456
+#if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE)
31457
+# define _GNU_SOURCE
31459
#include <unistd.h>
31461
+#ifdef HAVE_SYS_TYPES_H
31462
+#include <sys/types.h>
31464
+#if defined(HAVE_SYS_STAT_H) && defined(__FreeBSD__)
31465
+#include <sys/stat.h>
31467
+#ifdef HAVE_SYS_SYSCALL_H
31468
+#include <sys/syscall.h>
31470
+#ifdef HAVE_DIRENT_H
31471
+#include <dirent.h>
31475
+/* readdir64 is used to work around Solaris 9 bug 6395699. */
31476
+# define readdir readdir64
31477
+# define dirent dirent64
31478
+# if !defined(HAVE_DIRFD)
31479
+/* Some versions of Solaris lack dirfd(). */
31480
+# define dirfd(dirp) ((dirp)->dd_fd)
31481
+# define HAVE_DIRFD
31485
+#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(__MACH__))
31486
+# define FD_DIR "/dev/fd"
31488
+# define FD_DIR "/proc/self/fd"
31491
#define POSIX_CALL(call) if ((call) == -1) goto error
31496
/* Given the gc module call gc.enable() and return 0 on success. */
31497
-static int _enable_gc(PyObject *gc_module)
31499
+_enable_gc(PyObject *gc_module)
31502
result = PyObject_CallMethod(gc_module, "enable", NULL);
31503
@@ -26,6 +55,261 @@
31507
+/* Convert ASCII to a positive int, no libc call. no overflow. -1 on error. */
31509
+_pos_int_from_ascii(char *name)
31512
+ while (*name >= '0' && *name <= '9') {
31513
+ num = num * 10 + (*name - '0');
31517
+ return -1; /* Non digit found, not a number. */
31522
+#if defined(__FreeBSD__)
31523
+/* When /dev/fd isn't mounted it is often a static directory populated
31524
+ * with 0 1 2 or entries for 0 .. 63 on FreeBSD, NetBSD and OpenBSD.
31525
+ * NetBSD and OpenBSD have a /proc fs available (though not necessarily
31526
+ * mounted) and do not have fdescfs for /dev/fd. MacOS X has a devfs
31527
+ * that properly supports /dev/fd.
31530
+_is_fdescfs_mounted_on_dev_fd()
31532
+ struct stat dev_stat;
31533
+ struct stat dev_fd_stat;
31534
+ if (stat("/dev", &dev_stat) != 0)
31536
+ if (stat(FD_DIR, &dev_fd_stat) != 0)
31538
+ if (dev_stat.st_dev == dev_fd_stat.st_dev)
31539
+ return 0; /* / == /dev == /dev/fd means it is static. #fail */
31545
+/* Returns 1 if there is a problem with fd_sequence, 0 otherwise. */
31547
+_sanity_check_python_fd_sequence(PyObject *fd_sequence)
31549
+ Py_ssize_t seq_idx, seq_len = PySequence_Length(fd_sequence);
31550
+ long prev_fd = -1;
31551
+ for (seq_idx = 0; seq_idx < seq_len; ++seq_idx) {
31552
+ PyObject* py_fd = PySequence_Fast_GET_ITEM(fd_sequence, seq_idx);
31553
+ long iter_fd = PyLong_AsLong(py_fd);
31554
+ if (iter_fd < 0 || iter_fd < prev_fd || iter_fd > INT_MAX) {
31555
+ /* Negative, overflow, not a Long, unsorted, too big for a fd. */
31563
+/* Is fd found in the sorted Python Sequence? */
31565
+_is_fd_in_sorted_fd_sequence(int fd, PyObject *fd_sequence)
31567
+ /* Binary search. */
31568
+ Py_ssize_t search_min = 0;
31569
+ Py_ssize_t search_max = PySequence_Length(fd_sequence) - 1;
31570
+ if (search_max < 0)
31573
+ long middle = (search_min + search_max) / 2;
31574
+ long middle_fd = PyLong_AsLong(
31575
+ PySequence_Fast_GET_ITEM(fd_sequence, middle));
31576
+ if (fd == middle_fd)
31578
+ if (fd > middle_fd)
31579
+ search_min = middle + 1;
31581
+ search_max = middle - 1;
31582
+ } while (search_min <= search_max);
31587
+/* Close all file descriptors in the range start_fd inclusive to
31588
+ * end_fd exclusive except for those in py_fds_to_keep. If the
31589
+ * range defined by [start_fd, end_fd) is large this will take a
31590
+ * long time as it calls close() on EVERY possible fd.
31593
+_close_fds_by_brute_force(int start_fd, int end_fd, PyObject *py_fds_to_keep)
31595
+ Py_ssize_t num_fds_to_keep = PySequence_Length(py_fds_to_keep);
31596
+ Py_ssize_t keep_seq_idx;
31598
+ /* As py_fds_to_keep is sorted we can loop through the list closing
31599
+ * fds inbetween any in the keep list falling within our range. */
31600
+ for (keep_seq_idx = 0; keep_seq_idx < num_fds_to_keep; ++keep_seq_idx) {
31601
+ PyObject* py_keep_fd = PySequence_Fast_GET_ITEM(py_fds_to_keep,
31603
+ int keep_fd = PyLong_AsLong(py_keep_fd);
31604
+ if (keep_fd < start_fd)
31606
+ for (fd_num = start_fd; fd_num < keep_fd; ++fd_num) {
31607
+ while (close(fd_num) < 0 && errno == EINTR);
31609
+ start_fd = keep_fd + 1;
31611
+ if (start_fd <= end_fd) {
31612
+ for (fd_num = start_fd; fd_num < end_fd; ++fd_num) {
31613
+ while (close(fd_num) < 0 && errno == EINTR);
31619
+#if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)
31620
+/* It doesn't matter if d_name has room for NAME_MAX chars; we're using this
31621
+ * only to read a directory of short file descriptor number names. The kernel
31622
+ * will return an error if we didn't give it enough space. Highly Unlikely.
31623
+ * This structure is very old and stable: It will not change unless the kernel
31624
+ * chooses to break compatibility with all existing binaries. Highly Unlikely.
31626
+struct linux_dirent {
31627
+ unsigned long d_ino; /* Inode number */
31628
+ unsigned long d_off; /* Offset to next linux_dirent */
31629
+ unsigned short d_reclen; /* Length of this linux_dirent */
31630
+ char d_name[256]; /* Filename (null-terminated) */
31633
+/* Close all open file descriptors in the range start_fd inclusive to end_fd
31634
+ * exclusive. Do not close any in the sorted py_fds_to_keep list.
31636
+ * This version is async signal safe as it does not make any unsafe C library
31637
+ * calls, malloc calls or handle any locks. It is _unfortunate_ to be forced
31638
+ * to resort to making a kernel system call directly but this is the ONLY api
31639
+ * available that does no harm. opendir/readdir/closedir perform memory
31640
+ * allocation and locking so while they usually work they are not guaranteed
31641
+ * to (especially if you have replaced your malloc implementation). A version
31642
+ * of this function that uses those can be found in the _maybe_unsafe variant.
31644
+ * This is Linux specific because that is all I am ready to test it on. It
31645
+ * should be easy to add OS specific dirent or dirent64 structures and modify
31646
+ * it with some cpp #define magic to work on other OSes as well if you want.
31649
+_close_open_fd_range_safe(int start_fd, int end_fd, PyObject* py_fds_to_keep)
31652
+ if (start_fd >= end_fd)
31654
+ fd_dir_fd = open(FD_DIR, O_RDONLY | O_CLOEXEC, 0);
31655
+ if (fd_dir_fd == -1) {
31656
+ /* No way to get a list of open fds. */
31657
+ _close_fds_by_brute_force(start_fd, end_fd, py_fds_to_keep);
31660
+ char buffer[sizeof(struct linux_dirent)];
31662
+ while ((bytes = syscall(SYS_getdents, fd_dir_fd,
31663
+ (struct linux_dirent *)buffer,
31664
+ sizeof(buffer))) > 0) {
31665
+ struct linux_dirent *entry;
31667
+ for (offset = 0; offset < bytes; offset += entry->d_reclen) {
31669
+ entry = (struct linux_dirent *)(buffer + offset);
31670
+ if ((fd = _pos_int_from_ascii(entry->d_name)) < 0)
31671
+ continue; /* Not a number. */
31672
+ if (fd != fd_dir_fd && fd >= start_fd && fd < end_fd &&
31673
+ !_is_fd_in_sorted_fd_sequence(fd, py_fds_to_keep)) {
31674
+ while (close(fd) < 0 && errno == EINTR);
31678
+ close(fd_dir_fd);
31682
+#define _close_open_fd_range _close_open_fd_range_safe
31684
+#else /* NOT (defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)) */
31687
+/* Close all open file descriptors in the range start_fd inclusive to end_fd
31688
+ * exclusive. Do not close any in the sorted py_fds_to_keep list.
31690
+ * This function violates the strict use of async signal safe functions. :(
31691
+ * It calls opendir(), readdir() and closedir(). Of these, the one most
31692
+ * likely to ever cause a problem is opendir() as it performs an internal
31693
+ * malloc(). Practically this should not be a problem. The Java VM makes the
31694
+ * same calls between fork and exec in its own UNIXProcess_md.c implementation.
31696
+ * readdir_r() is not used because it provides no benefit. It is typically
31697
+ * implemented as readdir() followed by memcpy(). See also:
31698
+ * http://womble.decadent.org.uk/readdir_r-advisory.html
31701
+_close_open_fd_range_maybe_unsafe(int start_fd, int end_fd,
31702
+ PyObject* py_fds_to_keep)
31704
+ DIR *proc_fd_dir;
31705
+#ifndef HAVE_DIRFD
31706
+ while (_is_fd_in_sorted_fd_sequence(start_fd, py_fds_to_keep) &&
31707
+ (start_fd < end_fd)) {
31710
+ if (start_fd >= end_fd)
31712
+ /* Close our lowest fd before we call opendir so that it is likely to
31713
+ * reuse that fd otherwise we might close opendir's file descriptor in
31714
+ * our loop. This trick assumes that fd's are allocated on a lowest
31715
+ * available basis. */
31716
+ while (close(start_fd) < 0 && errno == EINTR);
31719
+ if (start_fd >= end_fd)
31722
+#if defined(__FreeBSD__)
31723
+ if (!_is_fdescfs_mounted_on_dev_fd())
31724
+ proc_fd_dir = NULL;
31727
+ proc_fd_dir = opendir(FD_DIR);
31728
+ if (!proc_fd_dir) {
31729
+ /* No way to get a list of open fds. */
31730
+ _close_fds_by_brute_force(start_fd, end_fd, py_fds_to_keep);
31732
+ struct dirent *dir_entry;
31734
+ int fd_used_by_opendir = dirfd(proc_fd_dir);
31736
+ int fd_used_by_opendir = start_fd - 1;
31739
+ while ((dir_entry = readdir(proc_fd_dir))) {
31741
+ if ((fd = _pos_int_from_ascii(dir_entry->d_name)) < 0)
31742
+ continue; /* Not a number. */
31743
+ if (fd != fd_used_by_opendir && fd >= start_fd && fd < end_fd &&
31744
+ !_is_fd_in_sorted_fd_sequence(fd, py_fds_to_keep)) {
31745
+ while (close(fd) < 0 && errno == EINTR);
31750
+ /* readdir error, revert behavior. Highly Unlikely. */
31751
+ _close_fds_by_brute_force(start_fd, end_fd, py_fds_to_keep);
31753
+ closedir(proc_fd_dir);
31757
+#define _close_open_fd_range _close_open_fd_range_maybe_unsafe
31759
+#endif /* else NOT (defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)) */
31763
* This function is code executed in the child process immediately after fork
31764
* to set things up and call exec().
31765
@@ -37,21 +321,22 @@
31766
* This restriction is documented at
31767
* http://www.opengroup.org/onlinepubs/009695399/functions/fork.html.
31769
-static void child_exec(char *const exec_array[],
31770
- char *const argv[],
31771
- char *const envp[],
31773
- int p2cread, int p2cwrite,
31774
- int c2pread, int c2pwrite,
31775
- int errread, int errwrite,
31776
- int errpipe_read, int errpipe_write,
31777
- int close_fds, int restore_signals,
31778
- int call_setsid, Py_ssize_t num_fds_to_keep,
31779
- PyObject *py_fds_to_keep,
31780
- PyObject *preexec_fn,
31781
- PyObject *preexec_fn_args_tuple)
31783
+child_exec(char *const exec_array[],
31784
+ char *const argv[],
31785
+ char *const envp[],
31787
+ int p2cread, int p2cwrite,
31788
+ int c2pread, int c2pwrite,
31789
+ int errread, int errwrite,
31790
+ int errpipe_read, int errpipe_write,
31791
+ int close_fds, int restore_signals,
31793
+ PyObject *py_fds_to_keep,
31794
+ PyObject *preexec_fn,
31795
+ PyObject *preexec_fn_args_tuple)
31797
- int i, saved_errno, fd_num;
31798
+ int i, saved_errno, unused;
31800
const char* err_msg = "";
31801
/* Buffer large enough to hold a hex integer. We can't malloc. */
31802
@@ -113,32 +398,15 @@
31803
POSIX_CALL(close(errwrite));
31806
- /* close() is intentionally not checked for errors here as we are closing */
31807
- /* a large range of fds, some of which may be invalid. */
31809
- Py_ssize_t keep_seq_idx;
31810
- int start_fd = 3;
31811
- for (keep_seq_idx = 0; keep_seq_idx < num_fds_to_keep; ++keep_seq_idx) {
31812
- PyObject* py_keep_fd = PySequence_Fast_GET_ITEM(py_fds_to_keep,
31814
- int keep_fd = PyLong_AsLong(py_keep_fd);
31815
- if (keep_fd < 0) { /* Negative number, overflow or not a Long. */
31816
- err_msg = "bad value in fds_to_keep.";
31817
- errno = 0; /* We don't want to report an OSError. */
31820
- if (keep_fd < start_fd)
31822
- for (fd_num = start_fd; fd_num < keep_fd; ++fd_num) {
31825
- start_fd = keep_fd + 1;
31827
- if (start_fd <= max_fd) {
31828
- for (fd_num = start_fd; fd_num < max_fd; ++fd_num) {
31832
+ int local_max_fd = max_fd;
31833
+#if defined(__NetBSD__)
31834
+ local_max_fd = fcntl(0, F_MAXFD);
31835
+ if (local_max_fd < 0)
31836
+ local_max_fd = max_fd;
31838
+ /* TODO HP-UX could use pstat_getproc() if anyone cares about it. */
31839
+ _close_open_fd_range(3, local_max_fd, py_fds_to_keep);
31843
@@ -189,22 +457,25 @@
31845
saved_errno = errno;
31846
/* Report the posix error to our parent process. */
31847
+ /* We ignore all write() return values as the total size of our writes is
31848
+ * less than PIPEBUF and we cannot do anything about an error anyways. */
31851
- write(errpipe_write, "OSError:", 8);
31852
+ unused = write(errpipe_write, "OSError:", 8);
31853
cur = hex_errno + sizeof(hex_errno);
31854
while (saved_errno != 0 && cur > hex_errno) {
31855
*--cur = "0123456789ABCDEF"[saved_errno % 16];
31858
- write(errpipe_write, cur, hex_errno + sizeof(hex_errno) - cur);
31859
- write(errpipe_write, ":", 1);
31860
+ unused = write(errpipe_write, cur, hex_errno + sizeof(hex_errno) - cur);
31861
+ unused = write(errpipe_write, ":", 1);
31862
/* We can't call strerror(saved_errno). It is not async signal safe.
31863
* The parent process will look the error message up. */
31865
- write(errpipe_write, "RuntimeError:0:", 15);
31866
- write(errpipe_write, err_msg, strlen(err_msg));
31867
+ unused = write(errpipe_write, "RuntimeError:0:", 15);
31868
+ unused = write(errpipe_write, err_msg, strlen(err_msg));
31870
+ if (unused) return; /* silly? yes! avoids gcc compiler warning. */
31874
@@ -224,7 +495,7 @@
31876
int need_to_reenable_gc = 0;
31877
char *const *exec_array, *const *argv = NULL, *const *envp = NULL;
31878
- Py_ssize_t arg_num, num_fds_to_keep;
31879
+ Py_ssize_t arg_num;
31881
if (!PyArg_ParseTuple(
31882
args, "OOOOOOiiiiiiiiiiO:fork_exec",
31883
@@ -240,9 +511,12 @@
31884
PyErr_SetString(PyExc_ValueError, "errpipe_write must be >= 3");
31887
- num_fds_to_keep = PySequence_Length(py_fds_to_keep);
31888
- if (num_fds_to_keep < 0) {
31889
- PyErr_SetString(PyExc_ValueError, "bad fds_to_keep");
31890
+ if (PySequence_Length(py_fds_to_keep) < 0) {
31891
+ PyErr_SetString(PyExc_ValueError, "cannot get length of fds_to_keep");
31894
+ if (_sanity_check_python_fd_sequence(py_fds_to_keep)) {
31895
+ PyErr_SetString(PyExc_ValueError, "bad value(s) in fds_to_keep");
31899
@@ -345,8 +619,7 @@
31900
p2cread, p2cwrite, c2pread, c2pwrite,
31901
errread, errwrite, errpipe_read, errpipe_write,
31902
close_fds, restore_signals, call_setsid,
31903
- num_fds_to_keep, py_fds_to_keep,
31904
- preexec_fn, preexec_fn_args_tuple);
31905
+ py_fds_to_keep, preexec_fn, preexec_fn_args_tuple);
31907
return NULL; /* Dead code to avoid a potential compiler warning. */
31909
@@ -437,12 +710,6 @@
31910
Py_END_ALLOW_THREADS
31911
if (res != 0 && errno == ENOSYS)
31913
- if (PyErr_WarnEx(
31914
- PyExc_RuntimeWarning,
31915
- "pipe2 set errno ENOSYS; falling "
31916
- "back to non-atomic pipe+fcntl.", 1) != 0) {
31921
/* We hold the GIL which offers some protection from other code calling
31922
diff -r 137e45f15c0b Modules/_sqlite/cursor.c
31923
--- a/Modules/_sqlite/cursor.c
31924
+++ b/Modules/_sqlite/cursor.c
31929
- while (isalpha(*src) && dst - buf < sizeof(buf) - 2) {
31930
- *dst++ = tolower(*src++);
31931
+ while (Py_ISALPHA(*src) && dst - buf < sizeof(buf) - 2) {
31932
+ *dst++ = Py_TOLOWER(*src++);
31936
@@ -268,9 +268,9 @@
31940
-PyObject* pysqlite_unicode_from_string(const char* val_str, int optimize)
31941
+PyObject* pysqlite_unicode_from_string(const char* val_str, Py_ssize_t size, int optimize)
31943
- return PyUnicode_FromString(val_str);
31944
+ return PyUnicode_FromStringAndSize(val_str, size);
31948
@@ -355,10 +355,11 @@
31949
converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i));
31950
} else if (coltype == SQLITE_TEXT) {
31951
val_str = (const char*)sqlite3_column_text(self->statement->st, i);
31952
+ nbytes = sqlite3_column_bytes(self->statement->st, i);
31953
if ((self->connection->text_factory == (PyObject*)&PyUnicode_Type)
31954
|| (self->connection->text_factory == pysqlite_OptimizedUnicode)) {
31956
- converted = pysqlite_unicode_from_string(val_str,
31957
+ converted = pysqlite_unicode_from_string(val_str, nbytes,
31958
self->connection->text_factory == pysqlite_OptimizedUnicode ? 1 : 0);
31961
@@ -383,11 +384,11 @@
31964
} else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) {
31965
- converted = PyBytes_FromString(val_str);
31966
+ converted = PyBytes_FromStringAndSize(val_str, nbytes);
31967
} else if (self->connection->text_factory == (PyObject*)&PyByteArray_Type) {
31968
- converted = PyByteArray_FromStringAndSize(val_str, strlen(val_str));
31969
+ converted = PyByteArray_FromStringAndSize(val_str, nbytes);
31971
- converted = PyObject_CallFunction(self->connection->text_factory, "y", val_str);
31972
+ converted = PyObject_CallFunction(self->connection->text_factory, "y#", val_str, nbytes);
31975
/* coltype == SQLITE_BLOB */
31976
@@ -432,9 +433,14 @@
31978
PyErr_SetString(pysqlite_ProgrammingError, "Cannot operate on a closed cursor.");
31981
- return pysqlite_check_thread(cur->connection) && pysqlite_check_connection(cur->connection);
31984
+ if (cur->locked) {
31985
+ PyErr_SetString(pysqlite_ProgrammingError, "Recursive use of cursors not allowed.");
31989
+ return pysqlite_check_thread(cur->connection) && pysqlite_check_connection(cur->connection);
31992
PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args)
31993
@@ -457,9 +463,10 @@
31994
int allow_8bit_chars;
31996
if (!check_cursor(self)) {
32001
+ self->locked = 1;
32004
/* Make shooting yourself in the foot with not utf-8 decodable 8-bit-strings harder */
32005
@@ -472,12 +479,12 @@
32007
/* executemany() */
32008
if (!PyArg_ParseTuple(args, "OO", &operation, &second_argument)) {
32013
if (!PyUnicode_Check(operation)) {
32014
PyErr_SetString(PyExc_ValueError, "operation parameter must be str");
32019
if (PyIter_Check(second_argument)) {
32020
@@ -488,23 +495,23 @@
32022
parameters_iter = PyObject_GetIter(second_argument);
32023
if (!parameters_iter) {
32030
if (!PyArg_ParseTuple(args, "O|O", &operation, &second_argument)) {
32035
if (!PyUnicode_Check(operation)) {
32036
PyErr_SetString(PyExc_ValueError, "operation parameter must be str");
32041
parameters_list = PyList_New(0);
32042
if (!parameters_list) {
32047
if (second_argument == NULL) {
32048
@@ -744,7 +751,8 @@
32049
* ROLLBACK could have happened */
32050
#ifdef SQLITE_VERSION_NUMBER
32051
#if SQLITE_VERSION_NUMBER >= 3002002
32052
- self->connection->inTransaction = !sqlite3_get_autocommit(self->connection->db);
32053
+ if (self->connection && self->connection->db)
32054
+ self->connection->inTransaction = !sqlite3_get_autocommit(self->connection->db);
32058
@@ -752,6 +760,8 @@
32059
Py_XDECREF(parameters_iter);
32060
Py_XDECREF(parameters_list);
32062
+ self->locked = 0;
32064
if (PyErr_Occurred()) {
32065
self->rowcount = -1L;
32067
diff -r 137e45f15c0b Modules/_sqlite/cursor.h
32068
--- a/Modules/_sqlite/cursor.h
32069
+++ b/Modules/_sqlite/cursor.h
32071
pysqlite_Statement* statement;
32077
/* the next row to be returned, NULL if no next row available */
32078
diff -r 137e45f15c0b Modules/_sqlite/statement.c
32079
--- a/Modules/_sqlite/statement.c
32080
+++ b/Modules/_sqlite/statement.c
32081
@@ -129,9 +129,9 @@
32082
rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
32085
- string = _PyUnicode_AsString(parameter);
32086
+ string = _PyUnicode_AsStringAndSize(parameter, &buflen);
32087
if (string != NULL)
32088
- rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
32089
+ rc = sqlite3_bind_text(self->st, pos, string, buflen, SQLITE_TRANSIENT);
32093
diff -r 137e45f15c0b Modules/_sre.c
2671
"At the top of the I/O hierarchy is the abstract base class IOBase. It\n"
2672
"defines the basic interface to a stream. Note, however, that there is no\n"
2673
-"seperation between reading and writing to streams; implementations are\n"
2674
+"separation between reading and writing to streams; implementations are\n"
2675
"allowed to throw an IOError if they do not support a given operation.\n"
2677
"Extending IOBase is RawIOBase which deals simply with the reading and\n"
2678
diff -r 7085403daf43 Modules/_io/textio.c
2679
--- a/Modules/_io/textio.c
2680
+++ b/Modules/_io/textio.c
2682
"enabled. With this enabled, on input, the lines endings '\\n', '\\r',\n"
2683
"or '\\r\\n' are translated to '\\n' before being returned to the\n"
2684
"caller. Conversely, on output, '\\n' is translated to the system\n"
2685
- "default line seperator, os.linesep. If newline is any other of its\n"
2686
+ "default line separator, os.linesep. If newline is any other of its\n"
2687
"legal values, that newline becomes the newline when the file is read\n"
2688
"and it is returned untranslated. On output, '\\n' is converted to the\n"
2690
diff -r 7085403daf43 Modules/_sre.c
32094
2691
--- a/Modules/_sre.c
32095
2692
+++ b/Modules/_sre.c
32096
@@ -2760,7 +2760,7 @@
32097
#if defined(VVERBOSE)
32098
#define VTRACE(v) printf v
32101
+#define VTRACE(v) do {} while(0) /* do nothing */
32104
/* Report failure */
32105
diff -r 137e45f15c0b Modules/_ssl.c
32106
--- a/Modules/_ssl.c
32107
+++ b/Modules/_ssl.c
32108
@@ -519,15 +519,20 @@
32111
/* now, there's typically a dangling RDN */
32112
- if ((rdn != NULL) && (PyList_Size(rdn) > 0)) {
32113
- rdnt = PyList_AsTuple(rdn);
32115
- if (rdnt == NULL)
32117
- retcode = PyList_Append(dn, rdnt);
32121
+ if (rdn != NULL) {
32122
+ if (PyList_GET_SIZE(rdn) > 0) {
32123
+ rdnt = PyList_AsTuple(rdn);
32125
+ if (rdnt == NULL)
32127
+ retcode = PyList_Append(dn, rdnt);
32137
/* convert list to tuple */
32138
@@ -578,7 +583,7 @@
32139
/* get a memory buffer */
32140
biobuf = BIO_new(BIO_s_mem());
32144
while ((i = X509_get_ext_by_NID(
32145
certificate, NID_subject_alt_name, i)) >= 0) {
32147
@@ -679,6 +684,7 @@
32151
+ sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free);
32154
if (peer_alt_names != Py_None) {
32155
@@ -1023,10 +1029,8 @@
32158
/* Guard against socket too large for select*/
32159
-#ifndef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
32160
- if (s->sock_fd >= FD_SETSIZE)
32161
+ if (!_PyIsSelectable_fd(s->sock_fd))
32162
return SOCKET_TOO_LARGE_FOR_SELECT;
32165
/* Construct the arguments to select */
32166
tv.tv_sec = (int)s->sock_timeout;
32167
@@ -1482,7 +1486,8 @@
32170
SSL_CTX_set_verify(self->ctx, SSL_VERIFY_NONE, NULL);
32171
- SSL_CTX_set_options(self->ctx, SSL_OP_ALL);
32172
+ SSL_CTX_set_options(self->ctx,
32173
+ SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS);
32175
#define SID_CTX "Python"
32176
SSL_CTX_set_session_id_context(self->ctx, (const unsigned char *) SID_CTX,
32177
@@ -2144,7 +2149,8 @@
32178
PY_SSL_VERSION_TLS1);
32180
/* protocol options */
32181
- PyModule_AddIntConstant(m, "OP_ALL", SSL_OP_ALL);
32182
+ PyModule_AddIntConstant(m, "OP_ALL",
32183
+ SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS);
32184
PyModule_AddIntConstant(m, "OP_NO_SSLv2", SSL_OP_NO_SSLv2);
32185
PyModule_AddIntConstant(m, "OP_NO_SSLv3", SSL_OP_NO_SSLv3);
32186
PyModule_AddIntConstant(m, "OP_NO_TLSv1", SSL_OP_NO_TLSv1);
32187
diff -r 137e45f15c0b Modules/_testcapimodule.c
32188
--- a/Modules/_testcapimodule.c
32189
+++ b/Modules/_testcapimodule.c
32190
@@ -1438,6 +1438,51 @@
2693
@@ -1664,7 +1664,7 @@
32194
+unicode_encodedecimal(PyObject *self, PyObject *args)
32196
+ Py_UNICODE *unicode;
32197
+ Py_ssize_t length;
32198
+ char *errors = NULL;
32199
+ PyObject *decimal;
32200
+ Py_ssize_t decimal_length, new_length;
32203
+ if (!PyArg_ParseTuple(args, "u#|s", &unicode, &length, &errors))
32206
+ decimal_length = length * 7; /* len('€') */
32207
+ decimal = PyBytes_FromStringAndSize(NULL, decimal_length);
32208
+ if (decimal == NULL)
32211
+ res = PyUnicode_EncodeDecimal(unicode, length,
32212
+ PyBytes_AS_STRING(decimal),
32215
+ Py_DECREF(decimal);
32219
+ new_length = strlen(PyBytes_AS_STRING(decimal));
32220
+ assert(new_length <= decimal_length);
32221
+ res = _PyBytes_Resize(&decimal, new_length);
32229
+unicode_transformdecimaltoascii(PyObject *self, PyObject *args)
32231
+ Py_UNICODE *unicode;
32232
+ Py_ssize_t length;
32233
+ if (!PyArg_ParseTuple(args, "u#|s", &unicode, &length))
32235
+ return PyUnicode_TransformDecimalToASCII(unicode, length);
32239
getargs_w_star(PyObject *self, PyObject *args)
2697
-getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize)
2698
+getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize, Py_buffer *view)
32242
@@ -2255,6 +2300,32 @@
32246
+/* To run some code in a sub-interpreter. */
32248
+run_in_subinterp(PyObject *self, PyObject *args)
32250
+ const char *code;
32252
+ PyThreadState *substate, *mainstate;
32254
+ if (!PyArg_ParseTuple(args, "s:run_in_subinterp",
32258
+ mainstate = PyThreadState_Get();
32260
+ PyThreadState_Swap(NULL);
32262
+ substate = Py_NewInterpreter();
32263
+ r = PyRun_SimpleString(code);
32264
+ Py_EndInterpreter(substate);
32266
+ PyThreadState_Swap(mainstate);
32268
+ return PyLong_FromLong(r);
32272
static PyMethodDef TestMethods[] = {
32273
{"raise_exception", raise_exception, METH_VARARGS},
32274
{"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS},
32275
@@ -2320,8 +2391,10 @@
32276
{"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
32277
{"test_Z_code", (PyCFunction)test_Z_code, METH_NOARGS},
32278
{"test_widechar", (PyCFunction)test_widechar, METH_NOARGS},
32279
- {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS},
32280
- {"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS},
32281
+ {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS},
32282
+ {"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS},
32283
+ {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS},
32284
+ {"unicode_transformdecimaltoascii", unicode_transformdecimaltoascii, METH_VARARGS},
32286
{"_test_thread_state", test_thread_state, METH_VARARGS},
32287
{"_pending_threadfunc", pending_threadfunc, METH_VARARGS},
32288
@@ -2338,6 +2411,7 @@
32289
{"make_memoryview_from_NULL_pointer", (PyCFunction)make_memoryview_from_NULL_pointer,
32291
{"crash_no_current_thread", (PyCFunction)crash_no_current_thread, METH_NOARGS},
32292
+ {"run_in_subinterp", run_in_subinterp, METH_VARARGS},
32293
{NULL, NULL} /* sentinel */
32296
diff -r 137e45f15c0b Modules/_tkinter.c
32297
--- a/Modules/_tkinter.c
32298
+++ b/Modules/_tkinter.c
32299
@@ -661,8 +661,8 @@
32302
strcpy(argv0, className);
32303
- if (isupper(Py_CHARMASK(argv0[0])))
32304
- argv0[0] = tolower(Py_CHARMASK(argv0[0]));
32305
+ if (Py_ISUPPER(Py_CHARMASK(argv0[0])))
32306
+ argv0[0] = Py_TOLOWER(Py_CHARMASK(argv0[0]));
32307
Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY);
32310
@@ -993,8 +993,10 @@
32311
for (i = 0; i < size; i++) {
32312
if (inbuf[i] >= 0x10000) {
32313
/* Tcl doesn't do UTF-16, yet. */
32314
- PyErr_SetString(PyExc_ValueError,
32315
- "unsupported character");
32316
+ PyErr_Format(PyExc_ValueError,
32317
+ "character U+%x is above the range "
32318
+ "(U+0000-U+FFFF) allowed by Tcl",
32320
ckfree(FREECAST outbuf);
32323
diff -r 137e45f15c0b Modules/arraymodule.c
32324
--- a/Modules/arraymodule.c
32325
+++ b/Modules/arraymodule.c
32326
@@ -1484,7 +1484,7 @@
32328
Extends this array with data from the unicode string ustr.\n\
32329
The array must be a unicode type array; otherwise a ValueError\n\
32330
-is raised. Use array.frombytes(ustr.decode(...)) to\n\
32331
+is raised. Use array.frombytes(ustr.encode(...)) to\n\
32332
append Unicode data to an array of some other type.");
32335
@@ -1506,7 +1506,7 @@
32337
Convert the array to a unicode string. The array must be\n\
32338
a unicode type array; otherwise a ValueError is raised. Use\n\
32339
-array.tostring().decode() to obtain a unicode string from\n\
32340
+array.tobytes().decode() to obtain a unicode string from\n\
32341
an array of some other type.");
32344
@@ -2543,7 +2543,7 @@
32346
Return a new array whose items are restricted by typecode, and\n\
32347
initialized from the optional initializer value, which must be a list,\n\
32348
-string. or iterable over elements of the appropriate type.\n\
32349
+string or iterable over elements of the appropriate type.\n\
32351
Arrays represent basic values and behave very much like lists, except\n\
32352
the type of objects stored in them is constrained.\n\
32353
@@ -2557,7 +2557,7 @@
32354
extend() -- extend array by appending multiple elements from an iterable\n\
32355
fromfile() -- read items from a file object\n\
32356
fromlist() -- append items from the list\n\
32357
-fromstring() -- append items from the string\n\
32358
+frombytes() -- append items from the string\n\
32359
index() -- return index of first occurrence of an object\n\
32360
insert() -- insert a new item into the array at a provided position\n\
32361
pop() -- remove and return item (default last)\n\
32362
@@ -2565,7 +2565,7 @@
32363
reverse() -- reverse the order of the items in the array\n\
32364
tofile() -- write all items to a file object\n\
32365
tolist() -- return the array converted to an ordinary list\n\
32366
-tostring() -- return the array converted to a string\n\
32367
+tobytes() -- return the array converted to a string\n\
32371
diff -r 137e45f15c0b Modules/audioop.c
32372
--- a/Modules/audioop.c
32373
+++ b/Modules/audioop.c
32374
@@ -1313,7 +1313,7 @@
32375
&cp, &len, &size) )
32378
- if (!audioop_check_parameters(len, size))
32379
+ if (!audioop_check_size(size))
32382
if (len > PY_SSIZE_T_MAX/size) {
32383
@@ -1382,7 +1382,7 @@
32384
&cp, &len, &size) )
32387
- if (!audioop_check_parameters(len, size))
32388
+ if (!audioop_check_size(size))
32391
if (len > PY_SSIZE_T_MAX/size) {
32392
@@ -1527,7 +1527,7 @@
32393
&cp, &len, &size, &state) )
32396
- if (!audioop_check_parameters(len, size))
32397
+ if (!audioop_check_size(size))
32400
/* Decode state, should have (value, step) */
32401
diff -r 137e45f15c0b Modules/binascii.c
32402
--- a/Modules/binascii.c
32403
+++ b/Modules/binascii.c
32404
@@ -1102,8 +1102,8 @@
2700
/* given a python object, return a data pointer, a length (in
2701
characters), and a character size. return NULL if the object
2702
@@ -1674,7 +1674,6 @@
2703
Py_ssize_t size, bytes;
2708
/* Unicode objects do not support the buffer API. So, get the data
2709
directly instead. */
2710
@@ -1686,26 +1685,21 @@
2713
/* get pointer to string buffer */
2716
buffer = Py_TYPE(string)->tp_as_buffer;
2717
if (!buffer || !buffer->bf_getbuffer ||
2718
- (*buffer->bf_getbuffer)(string, &view, PyBUF_SIMPLE) < 0) {
2719
+ (*buffer->bf_getbuffer)(string, view, PyBUF_SIMPLE) < 0) {
2720
PyErr_SetString(PyExc_TypeError, "expected string or buffer");
2724
/* determine buffer size */
2728
- /* Release the buffer immediately --- possibly dangerous
2729
- but doing something else would require some re-factoring
2731
- PyBuffer_Release(&view);
2732
+ bytes = view->len;
2736
PyErr_SetString(PyExc_TypeError, "buffer has negative size");
2741
/* determine character size */
2742
@@ -1719,7 +1713,7 @@
32410
+ if (Py_ISUPPER(c))
32411
+ c = Py_TOLOWER(c);
32412
if (c >= 'a' && c <= 'f')
32413
return c - 'a' + 10;
32415
diff -r 137e45f15c0b Modules/bz2module.c
32416
--- a/Modules/bz2module.c
32417
+++ b/Modules/bz2module.c
32418
@@ -218,25 +218,14 @@
32419
#define SMALLCHUNK BUFSIZ
32422
-#if SIZEOF_INT < 4
32423
-#define BIGCHUNK (512 * 32)
32425
-#define BIGCHUNK (512 * 1024)
32428
/* This is a hacked version of Python's fileobject.c:new_buffersize(). */
32430
Util_NewBufferSize(size_t currentsize)
32432
- if (currentsize > SMALLCHUNK) {
32433
- /* Keep doubling until we reach BIGCHUNK;
32434
- then keep adding BIGCHUNK. */
32435
- if (currentsize <= BIGCHUNK)
32436
- return currentsize + currentsize;
32438
- return currentsize + BIGCHUNK;
32440
- return currentsize + SMALLCHUNK;
32441
+ /* Expand the buffer by an amount proportional to the current size,
32442
+ giving us amortized linear-time behavior. Use a less-than-double
32443
+ growth factor to avoid excessive allocation. */
32444
+ return currentsize + (currentsize >> 3) + 6;
32447
/* This is a hacked version of Python's fileobject.c:get_line(). */
32448
diff -r 137e45f15c0b Modules/itertoolsmodule.c
32449
--- a/Modules/itertoolsmodule.c
32450
+++ b/Modules/itertoolsmodule.c
32451
@@ -1234,7 +1234,9 @@
32454
oldnext = lz->next;
32455
- lz->next += lz->step;
32456
+ /* The (size_t) cast below avoids the danger of undefined
32457
+ behaviour from signed integer overflow. */
32458
+ lz->next += (size_t)lz->step;
32459
if (lz->next < oldnext || (stop != -1 && lz->next > stop))
32462
diff -r 137e45f15c0b Modules/main.c
32463
--- a/Modules/main.c
32464
+++ b/Modules/main.c
32465
@@ -654,13 +654,14 @@
32467
char *cfilename_buffer;
32468
const char *cfilename;
32470
cfilename_buffer = _Py_wchar2char(filename, NULL);
32471
if (cfilename_buffer != NULL)
32472
cfilename = cfilename_buffer;
32474
cfilename = "<unprintable file name>";
32475
fprintf(stderr, "%ls: can't open file '%s': [Errno %d] %s\n",
32476
- argv[0], cfilename, errno, strerror(errno));
32477
+ argv[0], cfilename, err, strerror(err));
32478
if (cfilename_buffer)
32479
PyMem_Free(cfilename_buffer);
32481
diff -r 137e45f15c0b Modules/ossaudiodev.c
32482
--- a/Modules/ossaudiodev.c
32483
+++ b/Modules/ossaudiodev.c
32484
@@ -129,6 +129,7 @@
32487
if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
32489
PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
32492
@@ -425,6 +426,11 @@
32493
if (!PyArg_ParseTuple(args, "y#:write", &cp, &size))
32496
+ if (!_PyIsSelectable_fd(self->fd)) {
32497
+ PyErr_SetString(PyExc_ValueError,
32498
+ "file descriptor out of range for select");
32501
/* use select to wait for audio device to be available */
32502
FD_ZERO(&write_set_fds);
32503
FD_SET(self->fd, &write_set_fds);
32504
diff -r 137e45f15c0b Modules/posixmodule.c
32505
--- a/Modules/posixmodule.c
32506
+++ b/Modules/posixmodule.c
32507
@@ -4001,7 +4001,7 @@
32509
posix_spawnvpe(PyObject *self, PyObject *args)
32514
PyObject *argv, *env;
32516
@@ -5330,7 +5330,6 @@
32517
PyObject *src, *dest;
32518
int target_is_directory = 0;
32520
- WIN32_FILE_ATTRIBUTE_DATA src_info;
32522
if (!check_CreateSymbolicLinkW())
32524
@@ -5351,16 +5350,6 @@
32528
- /* if src is a directory, ensure target_is_directory==1 */
32530
- GetFileAttributesExW(
32531
- PyUnicode_AsUnicode(src), GetFileExInfoStandard, &src_info
32534
- target_is_directory = target_is_directory ||
32535
- (src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
32538
Py_BEGIN_ALLOW_THREADS
32539
res = Py_CreateSymbolicLinkW(
32540
PyUnicode_AsUnicode(dest),
32541
@@ -5687,7 +5676,8 @@
32543
PyDoc_STRVAR(posix_lseek__doc__,
32544
"lseek(fd, pos, how) -> newpos\n\n\
32545
-Set the current position of a file descriptor.");
32546
+Set the current position of a file descriptor.\n\
32547
+Return the new cursor position in bytes, starting from the beginning.");
32550
posix_lseek(PyObject *self, PyObject *args)
32551
@@ -6106,6 +6096,12 @@
32552
PyBytes_FromStringAndSize does not count that */
32554
len = wcslen(s1) + wcslen(s2) + 2;
32555
+ if (_MAX_ENV < (len - 1)) {
32556
+ PyErr_Format(PyExc_ValueError,
32557
+ "the environment variable is longer than %u characters",
32561
newstr = PyUnicode_FromUnicode(NULL, (int)len - 1);
32563
len = PyBytes_GET_SIZE(os1) + PyBytes_GET_SIZE(os2) + 2;
32564
@@ -6177,42 +6173,38 @@
32566
posix_unsetenv(PyObject *self, PyObject *args)
32571
- if (!PyArg_ParseTuple(args, "s:unsetenv", &s1))
2745
PyErr_SetString(PyExc_TypeError, "buffer size mismatch");
32572
2746
- return NULL;
32576
+#ifndef HAVE_BROKEN_UNSETENV
32580
if (!PyArg_ParseTuple(args, "O&:unsetenv",
32581
PyUnicode_FSConverter, &os1))
32583
s1 = PyBytes_AsString(os1);
32587
+#ifdef HAVE_BROKEN_UNSETENV
32590
+ err = unsetenv(s1);
32593
+ return posix_error();
32597
/* Remove the key from posix_putenv_garbage;
32598
* this will cause it to be collected. This has to
32599
* happen after the real unsetenv() call because the
32600
* old value was still accessible until then.
32602
- if (PyDict_DelItem(posix_putenv_garbage,
32604
- PyTuple_GET_ITEM(args, 0)
32609
+ if (PyDict_DelItem(posix_putenv_garbage, os1)) {
32610
/* really not much we can do; just leak */
32614
-#ifndef MS_WINDOWS
32619
#endif /* unsetenv */
32620
diff -r 137e45f15c0b Modules/python.c
32621
--- a/Modules/python.c
32622
+++ b/Modules/python.c
32625
argv_copy[i] = _Py_char2wchar(argv[i], NULL);
32627
- if (!argv_copy[i])
32628
+ if (!argv_copy[i]) {
32629
+ fprintf(stderr, "Fatal Python error: "
32630
+ "unable to decode the command line argument #%i\n",
32634
argv_copy2[i] = argv_copy[i];
32636
setlocale(LC_ALL, oldloc);
32637
diff -r 137e45f15c0b Modules/readline.c
32638
--- a/Modules/readline.c
32639
+++ b/Modules/readline.c
32640
@@ -154,6 +154,7 @@
32642
PyObject *filename_obj = Py_None, *filename_bytes;
32645
if (!PyArg_ParseTuple(args, "|O:write_history_file", &filename_obj))
32647
if (filename_obj != Py_None) {
32648
@@ -164,10 +165,11 @@
32649
filename_bytes = NULL;
32652
- errno = write_history(filename);
32653
- if (!errno && _history_length >= 0)
32654
+ errno = err = write_history(filename);
32655
+ if (!err && _history_length >= 0)
32656
history_truncate_file(filename, _history_length);
32657
Py_XDECREF(filename_bytes);
32660
return PyErr_SetFromErrno(PyExc_IOError);
32662
@@ -970,7 +972,7 @@
32663
completed_input_string = not_done_reading;
32665
while (completed_input_string == not_done_reading) {
32666
- int has_input = 0;
32667
+ int has_input = 0, err = 0;
32670
{ struct timeval timeout = {0, 100000}; /* 0.1 seconds */
32671
@@ -984,13 +986,14 @@
32672
/* select resets selectset if no input was available */
32673
has_input = select(fileno(rl_instream) + 1, &selectset,
32674
NULL, NULL, timeoutp);
32676
if(PyOS_InputHook) PyOS_InputHook();
32679
- if(has_input > 0) {
32680
+ if (has_input > 0) {
32681
rl_callback_read_char();
32683
- else if (errno == EINTR) {
32684
+ else if (err == EINTR) {
32687
PyEval_RestoreThread(_PyOS_ReadlineTState);
32688
diff -r 137e45f15c0b Modules/selectmodule.c
32689
--- a/Modules/selectmodule.c
32690
+++ b/Modules/selectmodule.c
32691
@@ -110,7 +110,7 @@
32692
#if defined(_MSC_VER)
32693
max = 0; /* not used for Win32 */
32694
#else /* !_MSC_VER */
32695
- if (v < 0 || v >= FD_SETSIZE) {
32696
+ if (!_PyIsSelectable_fd(v)) {
2751
@@ -1728,8 +1722,13 @@
32697
2753
PyErr_SetString(PyExc_ValueError,
32698
"filedescriptor out of range in select()");
32700
@@ -160,13 +160,6 @@
32701
for (j = 0; fd2obj[j].sentinel >= 0; j++) {
32703
if (FD_ISSET(fd, set)) {
32705
- if (fd > FD_SETSIZE) {
32706
- PyErr_SetString(PyExc_SystemError,
32707
- "filedescriptor out of range returned in select()");
32712
fd2obj[j].obj = NULL;
32713
/* transfer ownership */
32714
diff -r 137e45f15c0b Modules/signalmodule.c
32715
--- a/Modules/signalmodule.c
32716
+++ b/Modules/signalmodule.c
32717
@@ -991,11 +991,13 @@
32718
PyOS_AfterFork(void)
32721
+ /* PyThread_ReInitTLS() must be called early, to make sure that the TLS API
32722
+ * can be called safely. */
32723
+ PyThread_ReInitTLS();
32724
_PyGILState_Reinit();
32725
PyEval_ReInitThreads();
32726
main_thread = PyThread_get_thread_ident();
32727
main_pid = getpid();
32728
_PyImport_ReInitLock();
32729
- PyThread_ReInitTLS();
32732
diff -r 137e45f15c0b Modules/socketmodule.c
32733
--- a/Modules/socketmodule.c
32734
+++ b/Modules/socketmodule.c
32735
@@ -455,18 +455,14 @@
32736
#include <sys/poll.h>
32739
-#ifdef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
32740
-/* Platform can select file descriptors beyond FD_SETSIZE */
32741
-#define IS_SELECTABLE(s) 1
32742
-#elif defined(HAVE_POLL)
32744
/* Instead of select(), we'll use poll() since poll() works on any fd. */
32745
#define IS_SELECTABLE(s) 1
32746
/* Can we call select() with this socket without a buffer overrun? */
32748
-/* POSIX says selecting file descriptors beyond FD_SETSIZE
32749
- has undefined behaviour. If there's no timeout left, we don't have to
32750
- call select, so it's a safe, little white lie. */
32751
-#define IS_SELECTABLE(s) ((s)->sock_fd < FD_SETSIZE || s->sock_timeout <= 0.0)
32752
+/* If there's no timeout left, we don't have to call select, so it's a safe,
32753
+ * little white lie. */
32754
+#define IS_SELECTABLE(s) (_PyIsSelectable_fd((s)->sock_fd) || (s)->sock_timeout <= 0.0)
32758
@@ -1069,10 +1065,10 @@
32759
PyObject *ret = NULL;
32761
a = (struct sockaddr_in6 *)addr;
32762
- ret = Py_BuildValue("Oiii",
32763
+ ret = Py_BuildValue("OiII",
32765
ntohs(a->sin6_port),
32766
- a->sin6_flowinfo,
32767
+ ntohl(a->sin6_flowinfo),
32769
Py_DECREF(addrobj);
32771
@@ -1323,7 +1319,8 @@
32773
struct sockaddr_in6* addr;
32775
- int port, flowinfo, scope_id, result;
32776
+ int port, result;
32777
+ unsigned int flowinfo, scope_id;
32778
flowinfo = scope_id = 0;
32779
if (!PyTuple_Check(args)) {
32781
@@ -1333,7 +1330,7 @@
32782
Py_TYPE(args)->tp_name);
32785
- if (!PyArg_ParseTuple(args, "eti|ii",
32786
+ if (!PyArg_ParseTuple(args, "eti|II",
32787
"idna", &host, &port, &flowinfo,
32790
@@ -1350,9 +1347,15 @@
32791
"getsockaddrarg: port must be 0-65535.");
32794
+ if (flowinfo < 0 || flowinfo > 0xfffff) {
32796
+ PyExc_OverflowError,
32797
+ "getsockaddrarg: flowinfo must be 0-1048575.");
2759
+ PyBuffer_Release(view);
2765
@@ -1747,20 +1746,21 @@
2766
state->lastmark = -1;
2767
state->lastindex = -1;
2769
- ptr = getstring(string, &length, &charsize);
2770
+ state->buffer.buf = NULL;
2771
+ ptr = getstring(string, &length, &charsize, &state->buffer);
2775
- if (charsize == 1 && pattern->charsize > 1) {
2776
- PyErr_SetString(PyExc_TypeError,
2779
+ if (charsize == 1 && pattern->charsize > 1) {
2780
+ PyErr_SetString(PyExc_TypeError,
2781
"can't use a string pattern on a bytes-like object");
2784
- if (charsize > 1 && pattern->charsize == 1) {
2785
- PyErr_SetString(PyExc_TypeError,
2788
+ if (charsize > 1 && pattern->charsize == 1) {
2789
+ PyErr_SetString(PyExc_TypeError,
2790
"can't use a bytes pattern on a string-like object");
2796
/* adjust boundaries */
2798
@@ -1797,11 +1797,17 @@
2799
state->lower = sre_lower;
2803
+ if (state->buffer.buf)
2804
+ PyBuffer_Release(&state->buffer);
2809
state_fini(SRE_STATE* state)
2811
+ if (state->buffer.buf)
2812
+ PyBuffer_Release(&state->buffer);
2813
Py_XDECREF(state->string);
2814
data_stack_dealloc(state);
2816
@@ -1863,6 +1869,8 @@
2818
if (self->weakreflist != NULL)
2819
PyObject_ClearWeakRefs((PyObject *) self);
2820
+ if (self->view.buf)
2821
+ PyBuffer_Release(&self->view);
2822
Py_XDECREF(self->pattern);
2823
Py_XDECREF(self->groupindex);
2824
Py_XDECREF(self->indexgroup);
2825
@@ -2297,6 +2305,7 @@
2828
int filter_is_callable;
2831
if (PyCallable_Check(ptemplate)) {
2832
/* sub/subn takes either a function or a template */
2833
@@ -2306,7 +2315,8 @@
2835
/* if not callable, check if it's a literal string */
2837
- ptr = getstring(ptemplate, &n, &bint);
2839
+ ptr = getstring(ptemplate, &n, &bint, &view);
2843
@@ -2320,6 +2330,8 @@
2848
+ PyBuffer_Release(&view);
2852
@@ -2661,6 +2673,7 @@
2853
Py_ssize_t groups = 0;
2854
PyObject* groupindex = NULL;
2855
PyObject* indexgroup = NULL;
2857
if (!PyArg_ParseTuple(args, "OiO!|nOO", &pattern, &flags,
2858
&PyList_Type, &code, &groups,
2859
&groupindex, &indexgroup))
2860
@@ -2675,6 +2688,7 @@
2861
self->pattern = NULL;
2862
self->groupindex = NULL;
2863
self->indexgroup = NULL;
2864
+ self->view.buf = NULL;
2868
@@ -2694,15 +2708,15 @@
2872
- if (pattern == Py_None)
2873
- self->charsize = -1;
2875
- Py_ssize_t p_length;
2876
- if (!getstring(pattern, &p_length, &self->charsize)) {
2881
+ if (pattern == Py_None)
2882
+ self->charsize = -1;
2884
+ Py_ssize_t p_length;
2885
+ if (!getstring(pattern, &p_length, &self->charsize, &self->view)) {
32800
addr->sin6_family = s->sock_family;
32801
addr->sin6_port = htons((short)port);
32802
- addr->sin6_flowinfo = flowinfo;
32803
+ addr->sin6_flowinfo = htonl(flowinfo);
32804
addr->sin6_scope_id = scope_id;
32805
*len_ret = sizeof *addr;
32807
@@ -4108,7 +4111,8 @@
32808
PyObject *sa = (PyObject *)NULL;
32811
- int port, flowinfo, scope_id;
32813
+ unsigned int flowinfo, scope_id;
32814
char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
32815
struct addrinfo hints, *res = NULL;
32817
@@ -4122,9 +4126,14 @@
32818
"getnameinfo() argument 1 must be a tuple");
32821
- if (!PyArg_ParseTuple(sa, "si|ii",
32822
+ if (!PyArg_ParseTuple(sa, "si|II",
32823
&hostp, &port, &flowinfo, &scope_id))
32825
+ if (flowinfo < 0 || flowinfo > 0xfffff) {
32826
+ PyErr_SetString(PyExc_OverflowError,
32827
+ "getsockaddrarg: flowinfo must be 0-1048575.");
32830
PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
32831
memset(&hints, 0, sizeof(hints));
32832
hints.ai_family = AF_UNSPEC;
32833
@@ -4159,7 +4168,7 @@
32835
struct sockaddr_in6 *sin6;
32836
sin6 = (struct sockaddr_in6 *)res->ai_addr;
32837
- sin6->sin6_flowinfo = flowinfo;
32838
+ sin6->sin6_flowinfo = htonl(flowinfo);
32839
sin6->sin6_scope_id = scope_id;
32842
diff -r 137e45f15c0b Modules/timemodule.c
2892
self->pattern = pattern;
2893
diff -r 7085403daf43 Modules/sre.h
2897
int flags; /* flags used when compiling pattern source */
2898
PyObject *weakreflist; /* List of weak references */
2899
int charsize; /* pattern charsize (or -1) */
2902
Py_ssize_t codesize;
2906
size_t data_stack_size;
2907
size_t data_stack_base;
2909
/* current repeat context */
2912
diff -r 7085403daf43 Modules/timemodule.c
32843
2913
--- a/Modules/timemodule.c
32844
2914
+++ b/Modules/timemodule.c
32846
#include "Python.h"
32849
-#define TZNAME_ENCODING "utf-8"
32853
#ifdef HAVE_SYS_TYPES_H
32855
#if defined(MS_WINDOWS) && !defined(__BORLANDC__)
32856
/* Win32 has better clock replacement; we have our own version below. */
32858
-#undef TZNAME_ENCODING
32859
-#define TZNAME_ENCODING "mbcs"
32860
#endif /* MS_WINDOWS && !defined(__BORLANDC__) */
32862
#if defined(PYOS_OS2)
32863
@@ -431,6 +427,11 @@
32868
+ /* wcsftime() doesn't format correctly time zones, see issue #10653 */
32869
+# undef HAVE_WCSFTIME
32872
#ifdef HAVE_STRFTIME
32873
#ifdef HAVE_WCSFTIME
32874
#define time_char wchar_t
32875
@@ -497,22 +498,22 @@
32878
/* Convert the unicode string to an ascii one */
32879
- format = PyUnicode_AsEncodedString(format_arg, TZNAME_ENCODING, NULL);
32880
+ format = PyUnicode_EncodeFSDefault(format_arg);
32881
if (format == NULL)
32883
2916
fmt = PyBytes_AS_STRING(format);
32886
-#if defined(MS_WINDOWS) && defined(HAVE_WCSFTIME)
32887
+#if defined(MS_WINDOWS)
2919
-#if defined(MS_WINDOWS)
2920
+#if defined(MS_WINDOWS) && !defined(HAVE_WCSFTIME)
32888
2921
/* check that the format string contains only valid directives */
32889
- for(outbuf = wcschr(fmt, L'%');
32890
+ for(outbuf = strchr(fmt, '%');
2922
for(outbuf = strchr(fmt, '%');
32891
2923
outbuf != NULL;
32892
- outbuf = wcschr(outbuf+2, L'%'))
32893
+ outbuf = strchr(outbuf+2, '%'))
32895
if (outbuf[1]=='#')
32896
++outbuf; /* not documented by python, */
32897
if (outbuf[1]=='\0' ||
32898
- !wcschr(L"aAbBcdHIjmMpSUwWxXyYzZ%", outbuf[1]))
32899
+ !strchr("aAbBcdHIjmMpSUwWxXyYzZ%", outbuf[1]))
2925
!strchr("aAbBcdHIjmMpSUwWxXyYzZ%", outbuf[1]))
32901
2927
PyErr_SetString(PyExc_ValueError, "Invalid format string");
32903
@@ -526,12 +527,18 @@
32904
* will be ahead of time...
32906
for (i = 1024; ; i += i) {
32907
+#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
32910
outbuf = (time_char *)PyMem_Malloc(i*sizeof(time_char));
32911
if (outbuf == NULL) {
32915
buflen = format_time(outbuf, i, fmt, &buf);
32916
+#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
32919
if (buflen > 0 || i >= 256 * fmtlen) {
32920
/* If the buffer is 256 times as long as the format,
32921
it's probably not failing for lack of room!
32922
@@ -541,8 +548,7 @@
32923
#ifdef HAVE_WCSFTIME
32924
ret = PyUnicode_FromWideChar(outbuf, buflen);
32926
- ret = PyUnicode_Decode(outbuf, buflen,
32927
- TZNAME_ENCODING, NULL);
32928
+ ret = PyUnicode_DecodeFSDefaultAndSize(outbuf, buflen);
32930
PyMem_Free(outbuf);
32932
@@ -550,7 +556,7 @@
32933
PyMem_Free(outbuf);
32934
#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
32935
/* VisualStudio .NET 2005 does this properly */
32936
- if (buflen == 0 && errno == EINVAL) {
32937
+ if (buflen == 0 && err == EINVAL) {
32938
PyErr_SetString(PyExc_ValueError, "Invalid format string");
32941
@@ -784,8 +790,8 @@
32942
#endif /* PYOS_OS2 */
32944
PyModule_AddIntConstant(m, "daylight", daylight);
32945
- otz0 = PyUnicode_Decode(tzname[0], strlen(tzname[0]), TZNAME_ENCODING, NULL);
32946
- otz1 = PyUnicode_Decode(tzname[1], strlen(tzname[1]), TZNAME_ENCODING, NULL);
32947
+ otz0 = PyUnicode_DecodeFSDefaultAndSize(tzname[0], strlen(tzname[0]));
32948
+ otz1 = PyUnicode_DecodeFSDefaultAndSize(tzname[1], strlen(tzname[1]));
32949
PyModule_AddObject(m, "tzname", Py_BuildValue("(NN)", otz0, otz1));
32950
#else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
32951
#ifdef HAVE_STRUCT_TM_TM_ZONE
32952
diff -r 137e45f15c0b Modules/unicodedata.c
32953
--- a/Modules/unicodedata.c
32954
+++ b/Modules/unicodedata.c
32956
/* ------------------------------------------------------------------------
32958
- unicodedata -- Provides access to the Unicode 5.2 data base.
32959
+ unicodedata -- Provides access to the Unicode database.
32961
- Data was extracted from the Unicode 5.2 UnicodeData.txt file.
32962
+ Data was extracted from the UnicodeData.txt file.
32963
+ The current version number is reported in the unidata_version constant.
32965
Written by Marc-Andre Lemburg (mal@lemburg.com).
32966
Modified for Python 2.0 by Fredrik Lundh (fredrik@pythonware.com)
32967
@@ -830,7 +831,7 @@
32968
unsigned long h = 0;
32970
for (i = 0; i < len; i++) {
32971
- h = (h * scale) + (unsigned char) toupper(Py_CHARMASK(s[i]));
32972
+ h = (h * scale) + (unsigned char) Py_TOUPPER(Py_CHARMASK(s[i]));
32973
ix = h & 0xff000000;
32975
h = (h ^ ((ix>>24) & 0xff)) & 0x00ffffff;
32976
@@ -980,7 +981,7 @@
32977
if (!_getucname(self, code, buffer, sizeof(buffer)))
32979
for (i = 0; i < namelen; i++) {
32980
- if (toupper(Py_CHARMASK(name[i])) != buffer[i])
32981
+ if (Py_TOUPPER(Py_CHARMASK(name[i])) != buffer[i])
32984
return buffer[namelen] == '\0';
32985
@@ -1241,11 +1242,11 @@
32986
"This module provides access to the Unicode Character Database which\n\
32987
defines character properties for all Unicode characters. The data in\n\
32988
this database is based on the UnicodeData.txt file version\n\
32989
-5.2.0 which is publically available from ftp://ftp.unicode.org/.\n\
32990
+6.0.0 which is publically available from ftp://ftp.unicode.org/.\n\
32992
The module uses the same names and symbols as defined by the\n\
32993
-UnicodeData File Format 5.2.0 (see\n\
32994
-http://www.unicode.org/reports/tr44/tr44-4.html).");
32995
+UnicodeData File Format 6.0.0 (see\n\
32996
+http://www.unicode.org/reports/tr44/tr44-6.html).");
32999
static struct PyModuleDef unicodedatamodule = {
33000
diff -r 137e45f15c0b Modules/zipimport.c
33001
--- a/Modules/zipimport.c
33002
+++ b/Modules/zipimport.c
33003
@@ -714,15 +714,16 @@
33004
PyObject *files = NULL;
33006
unsigned short flags;
33007
- long compress, crc, data_size, file_size, file_offset, date, time;
33008
- long header_offset, name_size, header_size, header_position;
33009
+ short compress, time, date, name_size;
33010
+ long crc, data_size, file_size, header_size;
33011
+ Py_ssize_t file_offset, header_position, header_offset;
33014
Py_UNICODE path[MAXPATHLEN + 5];
33015
char name[MAXPATHLEN + 5];
33016
PyObject *nameobj = NULL;
33017
char *p, endof_central_dir[22];
33018
- long arc_offset; /* offset from beginning of file to start of zip-archive */
33019
+ Py_ssize_t arc_offset; /* Absolute offset to start of the zip-archive. */
33021
const char *charset;
33023
@@ -736,7 +737,8 @@
33025
fp = _Py_fopen(archive_obj, "rb");
33027
- PyErr_Format(ZipImportError, "can't open Zip file: '%U'", archive_obj);
33028
+ if (!PyErr_Occurred())
33029
+ PyErr_Format(ZipImportError, "can't open Zip file: '%U'", archive_obj);
33032
fseek(fp, -22, SEEK_END);
33033
@@ -831,7 +833,7 @@
33034
pathobj = PyUnicode_FromUnicode(path, Py_UNICODE_strlen(path));
33035
if (pathobj == NULL)
33037
- t = Py_BuildValue("Niiiiiii", pathobj, compress, data_size,
33038
+ t = Py_BuildValue("Nhllnhhl", pathobj, compress, data_size,
33039
file_size, file_offset, time, date, crc);
33042
@@ -909,8 +911,9 @@
33044
fp = _Py_fopen(archive, "rb");
33046
- PyErr_Format(PyExc_IOError,
33047
- "zipimport: can not open file %U", archive);
33048
+ if (!PyErr_Occurred())
33049
+ PyErr_Format(PyExc_IOError,
33050
+ "zipimport: can not open file %U", archive);
33054
diff -r 137e45f15c0b Objects/accu.c
33056
+++ b/Objects/accu.c
33058
+/* Accumulator struct implementation */
33060
+#include "Python.h"
33063
+join_list_unicode(PyObject *lst)
33065
+ /* return ''.join(lst) */
33066
+ PyObject *sep, *ret;
33067
+ sep = PyUnicode_FromStringAndSize("", 0);
33068
+ ret = PyUnicode_Join(sep, lst);
33074
+_PyAccu_Init(_PyAccu *acc)
33076
+ /* Lazily allocated */
33077
+ acc->large = NULL;
33078
+ acc->small = PyList_New(0);
33079
+ if (acc->small == NULL)
33085
+flush_accumulator(_PyAccu *acc)
33087
+ Py_ssize_t nsmall = PyList_GET_SIZE(acc->small);
33090
+ PyObject *joined;
33091
+ if (acc->large == NULL) {
33092
+ acc->large = PyList_New(0);
33093
+ if (acc->large == NULL)
33096
+ joined = join_list_unicode(acc->small);
33097
+ if (joined == NULL)
33099
+ if (PyList_SetSlice(acc->small, 0, nsmall, NULL)) {
33100
+ Py_DECREF(joined);
33103
+ ret = PyList_Append(acc->large, joined);
33104
+ Py_DECREF(joined);
33111
+_PyAccu_Accumulate(_PyAccu *acc, PyObject *unicode)
33113
+ Py_ssize_t nsmall;
33114
+ assert(PyUnicode_Check(unicode));
33116
+ if (PyList_Append(acc->small, unicode))
33118
+ nsmall = PyList_GET_SIZE(acc->small);
33119
+ /* Each item in a list of unicode objects has an overhead (in 64-bit
33121
+ * - 8 bytes for the list slot
33122
+ * - 56 bytes for the header of the unicode object
33123
+ * that is, 64 bytes. 100000 such objects waste more than 6MB
33124
+ * compared to a single concatenated string.
33126
+ if (nsmall < 100000)
33128
+ return flush_accumulator(acc);
33132
+_PyAccu_FinishAsList(_PyAccu *acc)
33137
+ ret = flush_accumulator(acc);
33138
+ Py_CLEAR(acc->small);
33140
+ Py_CLEAR(acc->large);
33143
+ res = acc->large;
33144
+ acc->large = NULL;
33149
+_PyAccu_Finish(_PyAccu *acc)
33151
+ PyObject *list, *res;
33152
+ if (acc->large == NULL) {
33153
+ list = acc->small;
33154
+ acc->small = NULL;
33157
+ list = _PyAccu_FinishAsList(acc);
2929
+ Py_DECREF(format);
33159
2930
+ return NULL;
33161
+ res = join_list_unicode(list);
33167
+_PyAccu_Destroy(_PyAccu *acc)
33169
+ Py_CLEAR(acc->small);
33170
+ Py_CLEAR(acc->large);
33172
diff -r 137e45f15c0b Objects/bytearrayobject.c
33173
--- a/Objects/bytearrayobject.c
33174
+++ b/Objects/bytearrayobject.c
33175
@@ -2797,18 +2797,16 @@
33176
PyDoc_STRVAR(bytearray_doc,
33177
"bytearray(iterable_of_ints) -> bytearray\n\
33178
bytearray(string, encoding[, errors]) -> bytearray\n\
33179
-bytearray(bytes_or_bytearray) -> mutable copy of bytes_or_bytearray\n\
33180
-bytearray(memory_view) -> bytearray\n\
33181
+bytearray(bytes_or_buffer) -> mutable copy of bytes_or_buffer\n\
33182
+bytearray(int) -> bytes array of size given by the parameter initialized with null bytes\n\
33183
+bytearray() -> empty bytes array\n\
33185
Construct an mutable bytearray object from:\n\
33186
- an iterable yielding integers in range(256)\n\
33187
- a text string encoded using the specified encoding\n\
33188
- - a bytes or a bytearray object\n\
33189
+ - a bytes or a buffer object\n\
33190
- any object implementing the buffer API.\n\
33192
-bytearray(int) -> bytearray\n\
33194
-Construct a zero-initialized bytearray of the given length.");
33198
static PyObject *bytearray_iter(PyObject *seq);
33199
diff -r 137e45f15c0b Objects/bytesobject.c
33200
--- a/Objects/bytesobject.c
33201
+++ b/Objects/bytesobject.c
33202
@@ -881,7 +881,7 @@
33203
p = (unsigned char *) a->ob_sval;
33206
- x = (1000003*x) ^ *p++;
33207
+ x = (_PyHASH_MULTIPLIER*x) ^ *p++;
33211
@@ -1437,7 +1437,7 @@
33212
"B.strip([bytes]) -> bytes\n\
33214
Strip leading and trailing bytes contained in the argument.\n\
33215
-If the argument is omitted, strip trailing ASCII whitespace.");
33216
+If the argument is omitted, strip leading and trailing ASCII whitespace.");
33218
bytes_strip(PyBytesObject *self, PyObject *args)
33220
@@ -2721,13 +2721,14 @@
33221
"bytes(iterable_of_ints) -> bytes\n\
33222
bytes(string, encoding[, errors]) -> bytes\n\
33223
bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer\n\
33224
-bytes(memory_view) -> bytes\n\
33225
+bytes(int) -> bytes object of size given by the parameter initialized with null bytes\n\
33226
+bytes() -> empty bytes object\n\
33228
Construct an immutable array of bytes from:\n\
33229
- an iterable yielding integers in range(256)\n\
33230
- a text string encoded using the specified encoding\n\
33231
- - a bytes or a buffer object\n\
33232
- - any object implementing the buffer API.");
33233
+ - any object implementing the buffer API.\n\
33236
static PyObject *bytes_iter(PyObject *seq);
33238
diff -r 137e45f15c0b Objects/descrobject.c
33239
--- a/Objects/descrobject.c
33240
+++ b/Objects/descrobject.c
33241
@@ -846,16 +846,13 @@
33242
/* This has no reason to be in this file except that adding new files is a
33246
-static PyTypeObject wrappertype;
33250
PyWrapperDescrObject *descr;
33254
-#define Wrapper_Check(v) (Py_TYPE(v) == &wrappertype)
33255
+#define Wrapper_Check(v) (Py_TYPE(v) == &_PyMethodWrapper_Type)
33258
wrapper_dealloc(wrapperobject *wp)
33259
@@ -1021,7 +1018,7 @@
33263
-static PyTypeObject wrappertype = {
33264
+PyTypeObject _PyMethodWrapper_Type = {
33265
PyVarObject_HEAD_INIT(&PyType_Type, 0)
33266
"method-wrapper", /* tp_name */
33267
sizeof(wrapperobject), /* tp_basicsize */
33268
@@ -1070,7 +1067,7 @@
33269
assert(_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
33270
(PyObject *)PyDescr_TYPE(descr)));
33272
- wp = PyObject_GC_New(wrapperobject, &wrappertype);
33273
+ wp = PyObject_GC_New(wrapperobject, &_PyMethodWrapper_Type);
33277
diff -r 137e45f15c0b Objects/dictobject.c
2934
diff -r 7085403daf43 Objects/dictobject.c
33278
2935
--- a/Objects/dictobject.c
33279
2936
+++ b/Objects/dictobject.c
33280
@@ -1314,14 +1314,18 @@
33284
- if (dictresize(mp, Py_SIZE(seq)))
33285
+ if (dictresize(mp, Py_SIZE(seq))) {
33290
while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) {
33293
- if (insertdict(mp, key, hash, value))
33294
+ if (insertdict(mp, key, hash, value)) {
33301
@@ -1332,14 +1336,18 @@
33305
- if (dictresize(mp, PySet_GET_SIZE(seq)))
33306
+ if (dictresize(mp, PySet_GET_SIZE(seq))) {
33311
while (_PySet_NextEntry(seq, &pos, &key, &hash)) {
33314
- if (insertdict(mp, key, hash, value))
33315
+ if (insertdict(mp, key, hash, value)) {
33322
@@ -1965,9 +1973,9 @@
33323
2-tuple; but raise KeyError if D is empty.");
33325
PyDoc_STRVAR(update__doc__,
33326
-"D.update(E, **F) -> None. Update D from dict/iterable E and F.\n"
33327
-"If E has a .keys() method, does: for k in E: D[k] = E[k]\n\
33328
-If E lacks .keys() method, does: for (k, v) in E: D[k] = v\n\
33329
+"D.update([E, ]**F) -> None. Update D from dict/iterable E and F.\n"
33330
+"If E present and has a .keys() method, does: for k in E: D[k] = E[k]\n\
33331
+If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v\n\
33332
In either case, this is followed by: for k in F: D[k] = F[k]");
33334
PyDoc_STRVAR(fromkeys__doc__,
33335
diff -r 137e45f15c0b Objects/exceptions.c
33336
--- a/Objects/exceptions.c
33337
+++ b/Objects/exceptions.c
33338
@@ -213,7 +213,8 @@
33341
seq = PySequence_Tuple(val);
33342
- if (!seq) return -1;
33345
Py_CLEAR(self->args);
33348
@@ -252,7 +253,8 @@
33350
BaseException_get_context(PyObject *self) {
33351
PyObject *res = PyException_GetContext(self);
33352
- if (res) return res; /* new reference already returned above */
33354
+ return res; /* new reference already returned above */
33358
@@ -278,7 +280,8 @@
33360
BaseException_get_cause(PyObject *self) {
33361
PyObject *res = PyException_GetCause(self);
33362
- if (res) return res; /* new reference already returned above */
33364
+ return res; /* new reference already returned above */
33368
@@ -672,7 +675,8 @@
33369
* file name given to EnvironmentError. */
33370
if (PyTuple_GET_SIZE(args) == 2 && self->filename) {
33371
args = PyTuple_New(3);
33372
- if (!args) return NULL;
33376
tmp = PyTuple_GET_ITEM(self->args, 0);
33378
@@ -894,7 +898,8 @@
33379
if (lenargs == 2) {
33380
info = PyTuple_GET_ITEM(args, 1);
33381
info = PySequence_Tuple(info);
33382
- if (!info) return -1;
33386
if (PyTuple_GET_SIZE(info) != 4) {
33387
/* not a very good error message, but it's what Python 2.4 gives */
33388
@@ -1959,10 +1964,14 @@
2937
@@ -510,27 +510,16 @@
2938
_PyObject_GC_UNTRACK(op);
2943
-Internal routine to insert a new item into the table.
2944
-Used both by the internal resize routine and by the public insert routine.
2945
-Eats a reference to key and one to value.
2946
-Returns -1 if an error occurred, or 0 on success.
2947
+Internal routine to insert a new item into the table when you have entry object.
2948
+Used by insertdict.
33390
PyObject *PyExc_RecursionErrorInst = NULL;
33392
-#define PRE_INIT(TYPE) if (PyType_Ready(&_PyExc_ ## TYPE) < 0) \
33393
- Py_FatalError("exceptions bootstrapping error.");
33394
+#define PRE_INIT(TYPE) \
33395
+ if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \
33396
+ if (PyType_Ready(&_PyExc_ ## TYPE) < 0) \
33397
+ Py_FatalError("exceptions bootstrapping error."); \
33398
+ Py_INCREF(PyExc_ ## TYPE); \
33401
-#define POST_INIT(TYPE) Py_INCREF(PyExc_ ## TYPE); \
33402
+#define POST_INIT(TYPE) \
33403
if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \
33404
Py_FatalError("Module dictionary insertion problem.");
33406
@@ -2093,29 +2102,30 @@
33408
preallocate_memerrors();
33410
- PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL);
33411
- if (!PyExc_RecursionErrorInst)
33412
- Py_FatalError("Cannot pre-allocate RuntimeError instance for "
33413
- "recursion errors");
33415
- PyBaseExceptionObject *err_inst =
33416
- (PyBaseExceptionObject *)PyExc_RecursionErrorInst;
33417
- PyObject *args_tuple;
33418
- PyObject *exc_message;
33419
- exc_message = PyUnicode_FromString("maximum recursion depth exceeded");
33420
- if (!exc_message)
33421
- Py_FatalError("cannot allocate argument for RuntimeError "
33422
- "pre-allocation");
33423
- args_tuple = PyTuple_Pack(1, exc_message);
33425
- Py_FatalError("cannot allocate tuple for RuntimeError "
33426
- "pre-allocation");
33427
- Py_DECREF(exc_message);
33428
- if (BaseException_init(err_inst, args_tuple, NULL))
33429
- Py_FatalError("init of pre-allocated RuntimeError failed");
33430
- Py_DECREF(args_tuple);
33431
+ if (!PyExc_RecursionErrorInst) {
33432
+ PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL);
33433
+ if (!PyExc_RecursionErrorInst)
33434
+ Py_FatalError("Cannot pre-allocate RuntimeError instance for "
33435
+ "recursion errors");
33437
+ PyBaseExceptionObject *err_inst =
33438
+ (PyBaseExceptionObject *)PyExc_RecursionErrorInst;
33439
+ PyObject *args_tuple;
33440
+ PyObject *exc_message;
33441
+ exc_message = PyUnicode_FromString("maximum recursion depth exceeded");
33442
+ if (!exc_message)
33443
+ Py_FatalError("cannot allocate argument for RuntimeError "
33444
+ "pre-allocation");
33445
+ args_tuple = PyTuple_Pack(1, exc_message);
33447
+ Py_FatalError("cannot allocate tuple for RuntimeError "
33448
+ "pre-allocation");
33449
+ Py_DECREF(exc_message);
33450
+ if (BaseException_init(err_inst, args_tuple, NULL))
33451
+ Py_FatalError("init of pre-allocated RuntimeError failed");
33452
+ Py_DECREF(args_tuple);
33456
Py_DECREF(bltinmod);
33459
diff -r 137e45f15c0b Objects/floatobject.c
33460
--- a/Objects/floatobject.c
33461
+++ b/Objects/floatobject.c
33462
@@ -919,9 +919,12 @@
33463
char *buf, *buf_end, shortbuf[100], *mybuf=shortbuf;
33465
PyObject *result = NULL;
33466
+ _Py_SET_53BIT_PRECISION_HEADER;
33468
/* round to a decimal string */
33469
+ _Py_SET_53BIT_PRECISION_START;
33470
buf = _Py_dg_dtoa(x, 3, ndigits, &decpt, &sign, &buf_end);
33471
+ _Py_SET_53BIT_PRECISION_END;
2951
-insertdict(register PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value)
2952
+insertdict_by_entry(register PyDictObject *mp, PyObject *key, Py_hash_t hash,
2953
+ PyDictEntry *ep, PyObject *value)
2955
PyObject *old_value;
2956
- register PyDictEntry *ep;
2957
- typedef PyDictEntry *(*lookupfunc)(PyDictObject *, PyObject *, Py_hash_t);
2959
- assert(mp->ma_lookup != NULL);
2960
- ep = mp->ma_lookup(mp, key, hash);
2966
MAINTAIN_TRACKING(mp, key, value);
2967
if (ep->me_value != NULL) {
2968
old_value = ep->me_value;
2969
@@ -553,6 +542,28 @@
2975
+Internal routine to insert a new item into the table.
2976
+Used both by the internal resize routine and by the public insert routine.
2977
+Eats a reference to key and one to value.
2978
+Returns -1 if an error occurred, or 0 on success.
2981
+insertdict(register PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value)
2983
+ register PyDictEntry *ep;
2985
+ assert(mp->ma_lookup != NULL);
2986
+ ep = mp->ma_lookup(mp, key, hash);
2992
+ return insertdict_by_entry(mp, key, hash, ep, value);
2996
Internal routine used by dictresize() to insert an item which is
2997
known to be absent from the dict. This routine also assumes that
2998
@@ -776,39 +787,26 @@
2999
return ep->me_value;
3002
-/* CAUTION: PyDict_SetItem() must guarantee that it won't resize the
3003
- * dictionary if it's merely replacing the value for an existing key.
3004
- * This means that it's safe to loop over a dictionary with PyDict_Next()
3005
- * and occasionally replace a value -- but you can't insert new keys or
3009
-PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value)
3011
+dict_set_item_by_hash_or_entry(register PyObject *op, PyObject *key,
3012
+ Py_hash_t hash, PyDictEntry *ep, PyObject *value)
3014
register PyDictObject *mp;
3015
- register Py_hash_t hash;
3016
register Py_ssize_t n_used;
3018
- if (!PyDict_Check(op)) {
3019
- PyErr_BadInternalCall();
3024
mp = (PyDictObject *)op;
3025
- if (!PyUnicode_CheckExact(key) ||
3026
- (hash = ((PyUnicodeObject *) key)->hash) == -1)
3028
- hash = PyObject_Hash(key);
3032
assert(mp->ma_fill <= mp->ma_mask); /* at least one empty slot */
3033
n_used = mp->ma_used;
3036
- if (insertdict(mp, key, hash, value) != 0)
3039
+ if (insertdict(mp, key, hash, value) != 0)
3043
+ if (insertdict_by_entry(mp, key, hash, ep, value) != 0)
3046
/* If we added a key, we can safely resize. Otherwise just return!
3047
* If fill >= 2/3 size, adjust size. Normally, this doubles or
3048
* quaduples the size, but it's also possible for the dict to shrink
3049
@@ -828,6 +826,36 @@
3050
return dictresize(mp, (mp->ma_used > 50000 ? 2 : 4) * mp->ma_used);
3053
+/* CAUTION: PyDict_SetItem() must guarantee that it won't resize the
3054
+ * dictionary if it's merely replacing the value for an existing key.
3055
+ * This means that it's safe to loop over a dictionary with PyDict_Next()
3056
+ * and occasionally replace a value -- but you can't insert new keys or
3060
+PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value)
3062
+ register Py_hash_t hash;
3064
+ if (!PyDict_Check(op)) {
3065
+ PyErr_BadInternalCall();
3070
+ if (PyUnicode_CheckExact(key)) {
3071
+ hash = ((PyUnicodeObject *) key)->hash;
3073
+ hash = PyObject_Hash(key);
3076
+ hash = PyObject_Hash(key);
3080
+ return dict_set_item_by_hash_or_entry(op, key, hash, NULL, value);
3084
PyDict_DelItem(PyObject *op, PyObject *key)
3086
@@ -1797,9 +1825,9 @@
33475
@@ -944,7 +947,9 @@
33477
/* and convert the resulting string back to a double */
33479
+ _Py_SET_53BIT_PRECISION_START;
33480
rounded = _Py_dg_strtod(mybuf, NULL);
33481
+ _Py_SET_53BIT_PRECISION_END;
33482
if (errno == ERANGE && fabs(rounded) >= 1.)
33483
PyErr_SetString(PyExc_OverflowError,
33484
"rounded value too large to represent");
33485
diff -r 137e45f15c0b Objects/genobject.c
33486
--- a/Objects/genobject.c
33487
+++ b/Objects/genobject.c
33488
@@ -100,6 +100,17 @@
33490
if (!result || f->f_stacktop == NULL) {
33491
/* generator can't be rerun, so release the frame */
33492
+ /* first clean reference cycle through stored exception traceback */
33493
+ PyObject *t, *v, *tb;
33494
+ t = f->f_exc_type;
33495
+ v = f->f_exc_value;
33496
+ tb = f->f_exc_traceback;
33497
+ f->f_exc_type = NULL;
33498
+ f->f_exc_value = NULL;
33499
+ f->f_exc_traceback = NULL;
33504
gen->gi_frame = NULL;
3091
- if (PyDict_SetItem((PyObject*)mp, key, failobj))
3093
+ if (dict_set_item_by_hash_or_entry((PyObject*)mp, key, hash, ep,
33506
@@ -221,8 +232,9 @@
33508
/* First, check the traceback argument, replacing None with
33510
- if (tb == Py_None)
33511
+ if (tb == Py_None) {
33514
else if (tb != NULL && !PyTraceBack_Check(tb)) {
33515
PyErr_SetString(PyExc_TypeError,
33516
"throw() third argument must be a traceback object");
33517
@@ -233,9 +245,8 @@
33518
3097
Py_XINCREF(val);
33521
- if (PyExceptionClass_Check(typ)) {
33522
+ if (PyExceptionClass_Check(typ))
33523
PyErr_NormalizeException(&typ, &val, &tb);
33526
else if (PyExceptionInstance_Check(typ)) {
33527
/* Raising an instance. The value should be a dummy. */
33528
@@ -250,6 +261,10 @@
33530
typ = PyExceptionInstance_Class(typ);
33534
+ /* Returns NULL if there's no traceback */
33535
+ tb = PyException_GetTraceback(val);
33539
diff -r 137e45f15c0b Objects/listobject.c
33540
--- a/Objects/listobject.c
33541
+++ b/Objects/listobject.c
33545
items = self->ob_item;
33546
- if (new_allocated <= ((~(size_t)0) / sizeof(PyObject *)))
33547
+ if (new_allocated <= (PY_SIZE_MAX / sizeof(PyObject *)))
33548
PyMem_RESIZE(items, PyObject *, new_allocated);
33551
@@ -321,70 +321,59 @@
33552
list_repr(PyListObject *v)
33555
- PyObject *s, *temp;
33556
- PyObject *pieces = NULL, *result = NULL;
33557
+ PyObject *s = NULL;
33559
+ static PyObject *sep = NULL;
33561
+ if (Py_SIZE(v) == 0) {
33562
+ return PyUnicode_FromString("[]");
33565
+ if (sep == NULL) {
33566
+ sep = PyUnicode_FromString(", ");
33571
i = Py_ReprEnter((PyObject*)v);
33573
return i > 0 ? PyUnicode_FromString("[...]") : NULL;
33576
- if (Py_SIZE(v) == 0) {
33577
- result = PyUnicode_FromString("[]");
33580
+ if (_PyAccu_Init(&acc))
33583
- pieces = PyList_New(0);
33584
- if (pieces == NULL)
33586
+ s = PyUnicode_FromString("[");
33587
+ if (s == NULL || _PyAccu_Accumulate(&acc, s))
33591
/* Do repr() on each element. Note that this may mutate the list,
33592
so must refetch the list size on each iteration. */
33593
for (i = 0; i < Py_SIZE(v); ++i) {
33595
if (Py_EnterRecursiveCall(" while getting the repr of a list"))
33598
s = PyObject_Repr(v->ob_item[i]);
33599
Py_LeaveRecursiveCall();
33602
- status = PyList_Append(pieces, s);
33603
- Py_DECREF(s); /* append created a new ref */
33606
+ if (i > 0 && _PyAccu_Accumulate(&acc, sep))
33608
+ if (s == NULL || _PyAccu_Accumulate(&acc, s))
33612
+ s = PyUnicode_FromString("]");
33613
+ if (s == NULL || _PyAccu_Accumulate(&acc, s))
33617
- /* Add "[]" decorations to the first and last items. */
33618
- assert(PyList_GET_SIZE(pieces) > 0);
33619
- s = PyUnicode_FromString("[");
33622
- temp = PyList_GET_ITEM(pieces, 0);
33623
- PyUnicode_AppendAndDel(&s, temp);
33624
- PyList_SET_ITEM(pieces, 0, s);
33627
+ Py_ReprLeave((PyObject *)v);
33628
+ return _PyAccu_Finish(&acc);
33630
- s = PyUnicode_FromString("]");
33633
- temp = PyList_GET_ITEM(pieces, PyList_GET_SIZE(pieces) - 1);
33634
- PyUnicode_AppendAndDel(&temp, s);
33635
- PyList_SET_ITEM(pieces, PyList_GET_SIZE(pieces) - 1, temp);
33636
- if (temp == NULL)
33639
- /* Paste them all together with ", " between. */
33640
- s = PyUnicode_FromString(", ");
33643
- result = PyUnicode_Join(s, pieces);
33647
- Py_XDECREF(pieces);
33649
+ _PyAccu_Destroy(&acc);
33651
Py_ReprLeave((PyObject *)v);
33657
@@ -510,9 +499,9 @@
33661
+ if (n > 0 && Py_SIZE(a) > PY_SSIZE_T_MAX / n)
33662
+ return PyErr_NoMemory();
33663
size = Py_SIZE(a) * n;
33664
- if (n && size/n != Py_SIZE(a))
33665
- return PyErr_NoMemory();
33667
return PyList_New(0);
33668
np = (PyListObject *) PyList_New(size);
33669
diff -r 137e45f15c0b Objects/longobject.c
33670
--- a/Objects/longobject.c
33671
+++ b/Objects/longobject.c
33672
@@ -525,8 +525,8 @@
33676
-/* Get a C unsigned long int from a long int object.
33677
- Returns -1 and sets an error condition if overflow occurs. */
33678
+/* Get a C size_t from a long int object. Returns (size_t)-1 and sets
33679
+ an error condition if overflow occurs. */
33682
PyLong_AsSize_t(PyObject *vv)
33683
@@ -562,7 +562,7 @@
33684
if ((x >> PyLong_SHIFT) != prev) {
33685
PyErr_SetString(PyExc_OverflowError,
33686
"Python int too large to convert to C size_t");
33687
- return (unsigned long) -1;
33688
+ return (size_t) -1;
33692
diff -r 137e45f15c0b Objects/object.c
33693
--- a/Objects/object.c
33694
+++ b/Objects/object.c
33695
@@ -1625,6 +1625,9 @@
33696
if (PyType_Ready(&PyWrapperDescr_Type) < 0)
33697
Py_FatalError("Can't initialize wrapper type");
33699
+ if (PyType_Ready(&_PyMethodWrapper_Type) < 0)
33700
+ Py_FatalError("Can't initialize method wrapper type");
33702
if (PyType_Ready(&PyEllipsis_Type) < 0)
33703
Py_FatalError("Can't initialize ellipsis type");
33705
diff -r 137e45f15c0b Objects/setobject.c
33706
--- a/Objects/setobject.c
33707
+++ b/Objects/setobject.c
33708
@@ -1877,7 +1877,7 @@
33709
tmpkey = make_new_set(&PyFrozenSet_Type, key);
33710
if (tmpkey == NULL)
33712
- rv = set_contains(so, tmpkey);
33713
+ rv = set_contains_key(so, tmpkey);
33717
@@ -1931,7 +1931,7 @@
33719
set_discard(PySetObject *so, PyObject *key)
33721
- PyObject *tmpkey, *result;
33722
+ PyObject *tmpkey;
33725
rv = set_discard_key(so, key);
33726
@@ -1942,9 +1942,10 @@
33727
tmpkey = make_new_set(&PyFrozenSet_Type, key);
33728
if (tmpkey == NULL)
33730
- result = set_discard(so, tmpkey);
33731
+ rv = set_discard_key(so, tmpkey);
33739
diff -r 137e45f15c0b Objects/sliceobject.c
33740
--- a/Objects/sliceobject.c
33741
+++ b/Objects/sliceobject.c
33742
@@ -320,9 +320,13 @@
33745
t1 = PyTuple_New(3);
33748
t2 = PyTuple_New(3);
33749
- if (t1 == NULL || t2 == NULL)
33750
+ if (t2 == NULL) {
33755
PyTuple_SET_ITEM(t1, 0, ((PySliceObject *)v)->start);
33756
PyTuple_SET_ITEM(t1, 1, ((PySliceObject *)v)->stop);
33757
diff -r 137e45f15c0b Objects/structseq.c
33758
--- a/Objects/structseq.c
33759
+++ b/Objects/structseq.c
33760
@@ -103,32 +103,33 @@
33761
if (min_len != max_len) {
33762
if (len < min_len) {
33763
PyErr_Format(PyExc_TypeError,
33764
- "%.500s() takes an at least %zd-sequence (%zd-sequence given)",
33765
- type->tp_name, min_len, len);
33768
+ "%.500s() takes an at least %zd-sequence (%zd-sequence given)",
33769
+ type->tp_name, min_len, len);
33774
if (len > max_len) {
33775
PyErr_Format(PyExc_TypeError,
33776
- "%.500s() takes an at most %zd-sequence (%zd-sequence given)",
33777
- type->tp_name, max_len, len);
33780
+ "%.500s() takes an at most %zd-sequence (%zd-sequence given)",
33781
+ type->tp_name, max_len, len);
33787
if (len != min_len) {
33788
PyErr_Format(PyExc_TypeError,
33789
- "%.500s() takes a %zd-sequence (%zd-sequence given)",
33790
- type->tp_name, min_len, len);
33793
+ "%.500s() takes a %zd-sequence (%zd-sequence given)",
33794
+ type->tp_name, min_len, len);
33800
res = (PyStructSequence*) PyStructSequence_New(type);
33805
for (i = 0; i < len; ++i) {
33806
diff -r 137e45f15c0b Objects/tupleobject.c
33807
--- a/Objects/tupleobject.c
33808
+++ b/Objects/tupleobject.c
33809
@@ -240,13 +240,20 @@
33810
tuplerepr(PyTupleObject *v)
33813
- PyObject *s, *temp;
33814
- PyObject *pieces, *result = NULL;
33815
+ PyObject *s = NULL;
33817
+ static PyObject *sep = NULL;
33821
return PyUnicode_FromString("()");
33823
+ if (sep == NULL) {
33824
+ sep = PyUnicode_FromString(", ");
33829
/* While not mutable, it is still possible to end up with a cycle in a
33830
tuple through an object that stores itself within a tuple (and thus
33831
infinitely asks for the repr of itself). This should only be
33832
@@ -256,52 +263,42 @@
33833
return i > 0 ? PyUnicode_FromString("(...)") : NULL;
33836
- pieces = PyTuple_New(n);
33837
- if (pieces == NULL)
33839
+ if (_PyAccu_Init(&acc))
33842
+ s = PyUnicode_FromString("(");
33843
+ if (s == NULL || _PyAccu_Accumulate(&acc, s))
33847
/* Do repr() on each element. */
33848
for (i = 0; i < n; ++i) {
33849
if (Py_EnterRecursiveCall(" while getting the repr of a tuple"))
33852
s = PyObject_Repr(v->ob_item[i]);
33853
Py_LeaveRecursiveCall();
33856
- PyTuple_SET_ITEM(pieces, i, s);
33857
+ if (i > 0 && _PyAccu_Accumulate(&acc, sep))
33859
+ if (s == NULL || _PyAccu_Accumulate(&acc, s))
33864
+ s = PyUnicode_FromString(")");
33866
+ s = PyUnicode_FromString(",)");
33867
+ if (s == NULL || _PyAccu_Accumulate(&acc, s))
33871
- /* Add "()" decorations to the first and last items. */
33873
- s = PyUnicode_FromString("(");
33876
- temp = PyTuple_GET_ITEM(pieces, 0);
33877
- PyUnicode_AppendAndDel(&s, temp);
33878
- PyTuple_SET_ITEM(pieces, 0, s);
33881
+ Py_ReprLeave((PyObject *)v);
33882
+ return _PyAccu_Finish(&acc);
33884
- s = PyUnicode_FromString(n == 1 ? ",)" : ")");
33887
- temp = PyTuple_GET_ITEM(pieces, n-1);
33888
- PyUnicode_AppendAndDel(&temp, s);
33889
- PyTuple_SET_ITEM(pieces, n-1, temp);
33890
- if (temp == NULL)
33893
- /* Paste them all together with ", " between. */
33894
- s = PyUnicode_FromString(", ");
33897
- result = PyUnicode_Join(s, pieces);
33901
- Py_DECREF(pieces);
33903
+ _PyAccu_Destroy(&acc);
33905
Py_ReprLeave((PyObject *)v);
33910
/* The addend 82520, was selected from the range(0, 1000000) for
33911
@@ -318,7 +315,7 @@
33912
register Py_hash_t x, y;
33913
register Py_ssize_t len = Py_SIZE(v);
33914
register PyObject **p;
33915
- Py_hash_t mult = 1000003L;
33916
+ Py_hash_t mult = _PyHASH_MULTIPLIER;
33919
while (--len >= 0) {
33920
diff -r 137e45f15c0b Objects/typeobject.c
3099
diff -r 7085403daf43 Objects/typeobject.c
33921
3100
--- a/Objects/typeobject.c
33922
3101
+++ b/Objects/typeobject.c
33923
@@ -967,8 +967,6 @@
33924
assert(basedealloc);
33927
- PyType_Modified(type);
33929
/* Can't reference self beyond this point */
33932
@@ -1912,53 +1910,20 @@
33933
return type->tp_flags;
33937
-type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
33939
- PyObject *name, *bases, *dict;
33940
- static char *kwlist[] = {"name", "bases", "dict", 0};
33941
- PyObject *slots, *tmp, *newslots;
33942
- PyTypeObject *type, *base, *tmptype, *winner;
33943
- PyHeapTypeObject *et;
33945
- Py_ssize_t i, nbases, nslots, slotoffset, add_dict, add_weak;
33946
- int j, may_add_dict, may_add_weak;
33948
- assert(args != NULL && PyTuple_Check(args));
33949
- assert(kwds == NULL || PyDict_Check(kwds));
33951
- /* Special case: type(x) should return x->ob_type */
33953
- const Py_ssize_t nargs = PyTuple_GET_SIZE(args);
33954
- const Py_ssize_t nkwds = kwds == NULL ? 0 : PyDict_Size(kwds);
33956
- if (PyType_CheckExact(metatype) && nargs == 1 && nkwds == 0) {
33957
- PyObject *x = PyTuple_GET_ITEM(args, 0);
33958
- Py_INCREF(Py_TYPE(x));
33959
- return (PyObject *) Py_TYPE(x);
33962
- /* SF bug 475327 -- if that didn't trigger, we need 3
33963
- arguments. but PyArg_ParseTupleAndKeywords below may give
33964
- a msg saying type() needs exactly 3. */
33965
- if (nargs + nkwds != 3) {
33966
- PyErr_SetString(PyExc_TypeError,
33967
- "type() takes 1 or 3 arguments");
33972
- /* Check arguments: (name, bases, dict) */
33973
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "UO!O!:type", kwlist,
33975
- &PyTuple_Type, &bases,
33976
- &PyDict_Type, &dict))
33978
+/* Determine the most derived metatype. */
33980
+_PyType_CalculateMetaclass(PyTypeObject *metatype, PyObject *bases)
33982
+ Py_ssize_t i, nbases;
33983
+ PyTypeObject *winner;
33985
+ PyTypeObject *tmptype;
33987
/* Determine the proper metatype to deal with this,
33988
and check for metatype conflicts while we're at it.
33989
Note that if some other metatype wins to contract,
33990
it's possible that its instances are not types. */
33992
nbases = PyTuple_GET_SIZE(bases);
33994
for (i = 0; i < nbases; i++) {
33995
@@ -1970,6 +1935,7 @@
34000
PyErr_SetString(PyExc_TypeError,
34001
"metaclass conflict: "
34002
"the metaclass of a derived class "
34003
@@ -1977,6 +1943,58 @@
34004
"of the metaclasses of all its bases");
34011
+type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
34013
+ PyObject *name, *bases, *dict;
34014
+ static char *kwlist[] = {"name", "bases", "dict", 0};
34015
+ PyObject *slots, *tmp, *newslots;
34016
+ PyTypeObject *type, *base, *tmptype, *winner;
34017
+ PyHeapTypeObject *et;
34019
+ Py_ssize_t i, nbases, nslots, slotoffset, add_dict, add_weak;
34020
+ int j, may_add_dict, may_add_weak;
34022
+ assert(args != NULL && PyTuple_Check(args));
34023
+ assert(kwds == NULL || PyDict_Check(kwds));
34025
+ /* Special case: type(x) should return x->ob_type */
34027
+ const Py_ssize_t nargs = PyTuple_GET_SIZE(args);
34028
+ const Py_ssize_t nkwds = kwds == NULL ? 0 : PyDict_Size(kwds);
34030
+ if (PyType_CheckExact(metatype) && nargs == 1 && nkwds == 0) {
34031
+ PyObject *x = PyTuple_GET_ITEM(args, 0);
34032
+ Py_INCREF(Py_TYPE(x));
34033
+ return (PyObject *) Py_TYPE(x);
34036
+ /* SF bug 475327 -- if that didn't trigger, we need 3
34037
+ arguments. but PyArg_ParseTupleAndKeywords below may give
34038
+ a msg saying type() needs exactly 3. */
34039
+ if (nargs + nkwds != 3) {
34040
+ PyErr_SetString(PyExc_TypeError,
34041
+ "type() takes 1 or 3 arguments");
34046
+ /* Check arguments: (name, bases, dict) */
34047
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "UO!O!:type", kwlist,
34049
+ &PyTuple_Type, &bases,
34050
+ &PyDict_Type, &dict))
34053
+ /* Determine the proper metatype to deal with this: */
34054
+ winner = _PyType_CalculateMetaclass(metatype, bases);
34055
+ if (winner == NULL) {
34059
if (winner != metatype) {
34060
if (winner->tp_new != type_new) /* Pass it to the winner */
34061
return winner->tp_new(winner, args, kwds);
34062
@@ -1984,6 +2002,7 @@
34065
/* Adjust for empty tuple bases */
34066
+ nbases = PyTuple_GET_SIZE(bases);
34068
bases = PyTuple_Pack(1, &PyBaseObject_Type);
34070
@@ -2093,8 +2112,10 @@
34071
PyUnicode_CompareWithASCIIString(tmp, "__weakref__") == 0))
34073
tmp =_Py_Mangle(name, tmp);
34076
+ Py_DECREF(newslots);
34079
PyList_SET_ITEM(newslots, j, tmp);
34082
@@ -2326,7 +2347,8 @@
34083
#include "typeslots.inc"
34086
-PyObject* PyType_FromSpec(PyType_Spec *spec)
34088
+PyType_FromSpec(PyType_Spec *spec)
34090
PyHeapTypeObject *res = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, 0);
34091
char *res_start = (char*)res;
34092
@@ -2364,6 +2386,9 @@
34096
+ if (PyType_Ready(&res->ht_type) < 0)
34099
return (PyObject*)res;
34102
@@ -2622,15 +2647,16 @@
34104
assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
34106
- /* The only field we need to clear is tp_mro, which is part of a
34107
- hard cycle (its first element is the class itself) that won't
34108
- be broken otherwise (it's a tuple and tuples don't have a
34109
+ /* We need to invalidate the method cache carefully before clearing
34110
+ the dict, so that other objects caught in a reference cycle
34111
+ don't start calling destroyed methods.
34113
+ Otherwise, the only field we need to clear is tp_mro, which is
34114
+ part of a hard cycle (its first element is the class itself) that
34115
+ won't be broken otherwise (it's a tuple and tuples don't have a
34116
tp_clear handler). None of the other fields need to be
34117
cleared, and here's why:
34120
- It is a dict, so the collector will call its tp_clear.
34123
Not used; if it were, it would be a dict.
34125
@@ -2647,6 +2673,9 @@
34126
A tuple of strings can't be part of a cycle.
34129
+ PyType_Modified(type);
34130
+ if (type->tp_dict)
34131
+ PyDict_Clear(type->tp_dict);
34132
Py_CLEAR(type->tp_mro);
34135
@@ -5533,25 +5562,25 @@
34136
NBSLOT("__index__", nb_index, slot_nb_index, wrap_unaryfunc,
34137
"x[y:z] <==> x[y.__index__():z.__index__()]"),
34138
IBSLOT("__iadd__", nb_inplace_add, slot_nb_inplace_add,
34139
- wrap_binaryfunc, "+"),
34140
+ wrap_binaryfunc, "+="),
34141
IBSLOT("__isub__", nb_inplace_subtract, slot_nb_inplace_subtract,
34142
- wrap_binaryfunc, "-"),
34143
+ wrap_binaryfunc, "-="),
34144
IBSLOT("__imul__", nb_inplace_multiply, slot_nb_inplace_multiply,
34145
- wrap_binaryfunc, "*"),
34146
+ wrap_binaryfunc, "*="),
34147
IBSLOT("__imod__", nb_inplace_remainder, slot_nb_inplace_remainder,
34148
- wrap_binaryfunc, "%"),
34149
+ wrap_binaryfunc, "%="),
34150
IBSLOT("__ipow__", nb_inplace_power, slot_nb_inplace_power,
34151
- wrap_binaryfunc, "**"),
34152
+ wrap_binaryfunc, "**="),
34153
IBSLOT("__ilshift__", nb_inplace_lshift, slot_nb_inplace_lshift,
34154
- wrap_binaryfunc, "<<"),
34155
+ wrap_binaryfunc, "<<="),
34156
IBSLOT("__irshift__", nb_inplace_rshift, slot_nb_inplace_rshift,
34157
- wrap_binaryfunc, ">>"),
34158
+ wrap_binaryfunc, ">>="),
34159
IBSLOT("__iand__", nb_inplace_and, slot_nb_inplace_and,
34160
- wrap_binaryfunc, "&"),
34161
+ wrap_binaryfunc, "&="),
34162
IBSLOT("__ixor__", nb_inplace_xor, slot_nb_inplace_xor,
34163
- wrap_binaryfunc, "^"),
34164
+ wrap_binaryfunc, "^="),
34165
IBSLOT("__ior__", nb_inplace_or, slot_nb_inplace_or,
34166
- wrap_binaryfunc, "|"),
34167
+ wrap_binaryfunc, "|="),
34168
BINSLOT("__floordiv__", nb_floor_divide, slot_nb_floor_divide, "//"),
34169
RBINSLOT("__rfloordiv__", nb_floor_divide, slot_nb_floor_divide, "//"),
34170
BINSLOT("__truediv__", nb_true_divide, slot_nb_true_divide, "/"),
34171
diff -r 137e45f15c0b Objects/unicodeobject.c
34172
--- a/Objects/unicodeobject.c
34173
+++ b/Objects/unicodeobject.c
34174
@@ -1187,12 +1187,12 @@
34175
/* Helper function for PyUnicode_AsWideChar() and PyUnicode_AsWideCharString():
34176
convert a Unicode object to a wide character string.
34178
- - If w is NULL: return the number of wide characters (including the nul
34179
+ - If w is NULL: return the number of wide characters (including the null
34180
character) required to convert the unicode object. Ignore size argument.
34182
- - Otherwise: return the number of wide characters (excluding the nul
34183
+ - Otherwise: return the number of wide characters (excluding the null
34184
character) written into w. Write at most size wide characters (including
34185
- the nul character). */
34186
+ the null character). */
34188
unicode_aswidechar(PyUnicodeObject *unicode,
34190
@@ -1240,7 +1240,7 @@
34194
- nchar = 1; /* nul character at the end */
34195
+ nchar = 1; /* null character at the end */
34196
while (u != uend) {
34197
if (0xD800 <= u[0] && u[0] <= 0xDBFF
34198
&& 0xDC00 <= u[1] && u[1] <= 0xDFFF)
34199
@@ -1278,7 +1278,7 @@
34203
- nchar = 1; /* nul character */
34204
+ nchar = 1; /* null character */
34205
while (u != uend) {
34208
@@ -1867,6 +1867,19 @@
34212
+_PyUnicode_HasNULChars(PyObject* s)
34214
+ static PyObject *nul = NULL;
34217
+ nul = PyUnicode_FromStringAndSize("\0", 1);
34220
+ return PyUnicode_Contains(s, nul);
34225
PyUnicode_FSConverter(PyObject* arg, void* addr)
34227
PyObject *output = NULL;
34228
@@ -2282,21 +2295,17 @@
34235
+ *p++ = surrogate;
34237
- errmsg = "second surrogate missing";
34241
- else if (outCh >= 0xD800 && outCh <= 0xDBFF) {
34242
+ if (outCh >= 0xD800 && outCh <= 0xDBFF) {
34243
/* first surrogate */
34246
- else if (outCh >= 0xDC00 && outCh <= 0xDFFF) {
34247
- errmsg = "unexpected second surrogate";
34253
@@ -2306,8 +2315,8 @@
34257
- errmsg = "second surrogate missing at end of shift sequence";
34259
+ *p++ = surrogate;
34262
if (base64bits > 0) { /* left-over bits */
34263
if (base64bits >= 6) {
34264
@@ -2754,7 +2763,7 @@
34265
outpos = p-PyUnicode_AS_UNICODE(unicode);
34266
if (unicode_decode_call_errorhandler(
34267
errors, &errorHandler,
34270
&starts, &e, &startinpos, &endinpos, &exc, &s,
34271
&unicode, &outpos, &p))
34273
@@ -6327,11 +6336,10 @@
34275
/* All other characters are considered unencodable */
34278
- while (collend < end) {
34279
+ for (collend = p+1; collend < end; collend++) {
34280
if ((0 < *collend && *collend < 256) ||
34281
- !Py_UNICODE_ISSPACE(*collend) ||
34282
- Py_UNICODE_TODECIMAL(*collend))
34283
+ Py_UNICODE_ISSPACE(*collend) ||
34284
+ 0 <= Py_UNICODE_TODECIMAL(*collend))
34287
/* cache callback name lookup
34288
@@ -6442,6 +6450,37 @@
34292
+/* _Py_UNICODE_NEXT is a private macro used to retrieve the character pointed
34293
+ * by 'ptr', possibly combining surrogate pairs on narrow builds.
34294
+ * 'ptr' and 'end' must be Py_UNICODE*, with 'ptr' pointing at the character
34295
+ * that should be returned and 'end' pointing to the end of the buffer.
34296
+ * ('end' is used on narrow builds to detect a lone surrogate at the
34297
+ * end of the buffer that should be returned unchanged.)
34298
+ * The ptr and end arguments should be side-effect free and ptr must an lvalue.
34299
+ * The type of the returned char is always Py_UCS4.
34301
+ * Note: the macro advances ptr to next char, so it might have side-effects
34302
+ * (especially if used with other macros).
34305
+/* helper macros used by _Py_UNICODE_NEXT */
34306
+#define _Py_UNICODE_IS_HIGH_SURROGATE(ch) (0xD800 <= ch && ch <= 0xDBFF)
34307
+#define _Py_UNICODE_IS_LOW_SURROGATE(ch) (0xDC00 <= ch && ch <= 0xDFFF)
34308
+/* Join two surrogate characters and return a single Py_UCS4 value. */
34309
+#define _Py_UNICODE_JOIN_SURROGATES(high, low) \
34310
+ (((((Py_UCS4)(high) & 0x03FF) << 10) | \
34311
+ ((Py_UCS4)(low) & 0x03FF)) + 0x10000)
34313
+#ifdef Py_UNICODE_WIDE
34314
+#define _Py_UNICODE_NEXT(ptr, end) *(ptr)++
34316
+#define _Py_UNICODE_NEXT(ptr, end) \
34317
+ (((_Py_UNICODE_IS_HIGH_SURROGATE(*(ptr)) && (ptr) < (end)) && \
34318
+ _Py_UNICODE_IS_LOW_SURROGATE((ptr)[1])) ? \
34319
+ ((ptr) += 2,_Py_UNICODE_JOIN_SURROGATES((ptr)[-2], (ptr)[-1])) : \
34320
+ (Py_UCS4)*(ptr)++)
34323
Py_ssize_t PyUnicode_Count(PyObject *str,
34326
@@ -6658,13 +6697,13 @@
34330
- if (Py_UNICODE_ISLOWER(*s)) {
34331
+ if (!Py_UNICODE_ISUPPER(*s)) {
34332
*s = Py_UNICODE_TOUPPER(*s);
34336
while (--len > 0) {
34337
- if (Py_UNICODE_ISUPPER(*s)) {
34338
+ if (!Py_UNICODE_ISLOWER(*s)) {
34339
*s = Py_UNICODE_TOLOWER(*s);
34342
@@ -6977,7 +7016,7 @@
34346
- Py_ssize_t n, i, j, e;
34347
+ Py_ssize_t n, i, j;
34348
Py_ssize_t product, new_size, delta;
34351
@@ -7009,7 +7048,6 @@
34355
- e = self->length - str1->length;
34356
if (str1->length > 0) {
34358
/* look for next match */
34359
@@ -7641,7 +7679,7 @@
34363
- x = (1000003*x) ^ *p++;
34364
+ x = (_PyHASH_MULTIPLIER*x) ^ *p++;
34365
x ^= Py_SIZE(self);
34368
@@ -7705,8 +7743,8 @@
34370
e = p + PyUnicode_GET_SIZE(self);
34372
- for (; p < e; p++) {
34373
- register const Py_UNICODE ch = *p;
34375
+ const Py_UCS4 ch = _Py_UNICODE_NEXT(p, e);
34377
if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch))
34378
return PyBool_FromLong(0);
34379
@@ -7739,8 +7777,8 @@
34381
e = p + PyUnicode_GET_SIZE(self);
34383
- for (; p < e; p++) {
34384
- register const Py_UNICODE ch = *p;
34386
+ const Py_UCS4 ch = _Py_UNICODE_NEXT(p, e);
34388
if (Py_UNICODE_ISLOWER(ch) || Py_UNICODE_ISTITLE(ch))
34389
return PyBool_FromLong(0);
34390
@@ -7777,8 +7815,8 @@
34391
e = p + PyUnicode_GET_SIZE(self);
34393
previous_is_cased = 0;
34394
- for (; p < e; p++) {
34395
- register const Py_UNICODE ch = *p;
34397
+ const Py_UCS4 ch = _Py_UNICODE_NEXT(p, e);
34399
if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch)) {
34400
if (previous_is_cased)
34401
@@ -7820,8 +7858,9 @@
34402
return PyBool_FromLong(0);
34404
e = p + PyUnicode_GET_SIZE(self);
34405
- for (; p < e; p++) {
34406
- if (!Py_UNICODE_ISSPACE(*p))
34408
+ const Py_UCS4 ch = _Py_UNICODE_NEXT(p, e);
34409
+ if (!Py_UNICODE_ISSPACE(ch))
34410
return PyBool_FromLong(0);
34412
return PyBool_FromLong(1);
34413
@@ -7849,8 +7888,8 @@
34414
return PyBool_FromLong(0);
34416
e = p + PyUnicode_GET_SIZE(self);
34417
- for (; p < e; p++) {
34418
- if (!Py_UNICODE_ISALPHA(*p))
34420
+ if (!Py_UNICODE_ISALPHA(_Py_UNICODE_NEXT(p, e)))
34421
return PyBool_FromLong(0);
34423
return PyBool_FromLong(1);
34424
@@ -7878,8 +7917,9 @@
34425
return PyBool_FromLong(0);
34427
e = p + PyUnicode_GET_SIZE(self);
34428
- for (; p < e; p++) {
34429
- if (!Py_UNICODE_ISALNUM(*p))
34431
+ const Py_UCS4 ch = _Py_UNICODE_NEXT(p, e);
34432
+ if (!Py_UNICODE_ISALNUM(ch))
34433
return PyBool_FromLong(0);
34435
return PyBool_FromLong(1);
34436
@@ -7907,8 +7947,8 @@
34437
return PyBool_FromLong(0);
34439
e = p + PyUnicode_GET_SIZE(self);
34440
- for (; p < e; p++) {
34441
- if (!Py_UNICODE_ISDECIMAL(*p))
34443
+ if (!Py_UNICODE_ISDECIMAL(_Py_UNICODE_NEXT(p, e)))
34444
return PyBool_FromLong(0);
34446
return PyBool_FromLong(1);
34447
@@ -7936,8 +7976,8 @@
34448
return PyBool_FromLong(0);
34450
e = p + PyUnicode_GET_SIZE(self);
34451
- for (; p < e; p++) {
34452
- if (!Py_UNICODE_ISDIGIT(*p))
34454
+ if (!Py_UNICODE_ISDIGIT(_Py_UNICODE_NEXT(p, e)))
34455
return PyBool_FromLong(0);
34457
return PyBool_FromLong(1);
34458
@@ -7965,37 +8005,22 @@
34459
return PyBool_FromLong(0);
34461
e = p + PyUnicode_GET_SIZE(self);
34462
- for (; p < e; p++) {
34463
- if (!Py_UNICODE_ISNUMERIC(*p))
34465
+ if (!Py_UNICODE_ISNUMERIC(_Py_UNICODE_NEXT(p, e)))
34466
return PyBool_FromLong(0);
34468
return PyBool_FromLong(1);
34472
-decode_ucs4(const Py_UNICODE *s, Py_ssize_t *i, Py_ssize_t size)
34475
- assert(*i < size);
34477
-#ifndef Py_UNICODE_WIDE
34478
- if ((ch & 0xfffffc00) == 0xd800 &&
34480
- && (s[*i] & 0xFFFFFC00) == 0xDC00)
34481
- ch = ((Py_UCS4)ch << 10UL) + (Py_UCS4)(s[(*i)++]) - 0x35fdc00;
34487
PyUnicode_IsIdentifier(PyObject *self)
34489
- Py_ssize_t i = 0, size = PyUnicode_GET_SIZE(self);
34490
+ const Py_UNICODE *p = PyUnicode_AS_UNICODE((PyUnicodeObject*)self);
34491
+ const Py_UNICODE *e;
34493
- const Py_UNICODE *p = PyUnicode_AS_UNICODE((PyUnicodeObject*)self);
34495
/* Special case for empty strings */
34497
+ if (PyUnicode_GET_SIZE(self) == 0)
34500
/* PEP 3131 says that the first character must be in
34501
@@ -8006,12 +8031,13 @@
34502
definition of XID_Start and XID_Continue, it is sufficient
34503
to check just for these, except that _ must be allowed
34504
as starting an identifier. */
34505
- first = decode_ucs4(p, &i, size);
34506
+ e = p + PyUnicode_GET_SIZE(self);
34507
+ first = _Py_UNICODE_NEXT(p, e);
34508
if (!_PyUnicode_IsXidStart(first) && first != 0x5F /* LOW LINE */)
34512
- if (!_PyUnicode_IsXidContinue(decode_ucs4(p, &i, size)))
34514
+ if (!_PyUnicode_IsXidContinue(_Py_UNICODE_NEXT(p, e)))
34518
@@ -8046,8 +8072,8 @@
34521
e = p + PyUnicode_GET_SIZE(self);
34522
- for (; p < e; p++) {
34523
- if (!Py_UNICODE_ISPRINTABLE(*p)) {
34525
+ if (!Py_UNICODE_ISPRINTABLE(_Py_UNICODE_NEXT(p, e))) {
34529
@@ -8875,9 +8901,13 @@
34530
/* create entries for translating chars in x to those in y */
34531
for (i = 0; i < PyUnicode_GET_SIZE(x); i++) {
34532
key = PyLong_FromLong(PyUnicode_AS_UNICODE(x)[i]);
34535
value = PyLong_FromLong(PyUnicode_AS_UNICODE(y)[i]);
34536
- if (!key || !value)
34541
res = PyDict_SetItem(new, key, value);
34544
diff -r 137e45f15c0b PC/VC6/pythoncore.dsp
34545
--- a/PC/VC6/pythoncore.dsp
34546
+++ b/PC/VC6/pythoncore.dsp
34547
@@ -205,6 +205,10 @@
34549
# Begin Source File
34551
+SOURCE=..\..\Objects\accu.c
34553
+# Begin Source File
34555
SOURCE=..\..\Parser\acceler.c
34557
# Begin Source File
34558
diff -r 137e45f15c0b PC/VS7.1/pythoncore.vcproj
34559
--- a/PC/VS7.1/pythoncore.vcproj
34560
+++ b/PC/VS7.1/pythoncore.vcproj
34561
@@ -445,6 +445,9 @@
34562
RelativePath="..\..\Objects\abstract.c">
34565
+ RelativePath="..\..\Objects\accu.c">
34568
RelativePath="..\..\Parser\acceler.c">
34571
diff -r 137e45f15c0b PC/VS8.0/pythoncore.vcproj
34572
--- a/PC/VS8.0/pythoncore.vcproj
34573
+++ b/PC/VS8.0/pythoncore.vcproj
34574
@@ -635,6 +635,10 @@
34578
+ RelativePath="..\..\Include\accu.h"
34582
RelativePath="..\..\Include\asdl.h"
34585
@@ -1447,6 +1451,10 @@
34589
+ RelativePath="..\..\Objects\accu.c"
34593
RelativePath="..\..\Objects\boolobject.c"
34596
diff -r 137e45f15c0b PC/errmap.h
34600
case 202: return 8;
34601
case 206: return 2;
34602
case 215: return 11;
34603
+ case 232: return 32;
34604
+ case 267: return 20;
34605
case 1816: return 12;
34606
default: return EINVAL;
34608
diff -r 137e45f15c0b PC/generrmap.c
34609
--- a/PC/generrmap.c
34610
+++ b/PC/generrmap.c
34612
+#include <windows.h>
34613
+#include <fcntl.h>
34622
+ _setmode(fileno(stdout), O_BINARY);
34623
printf("/* Generated file. Do not edit. */\n");
34624
printf("int winerror_to_errno(int winerror)\n");
34625
- printf("{\n\tswitch(winerror) {\n");
34626
+ printf("{\n switch(winerror) {\n");
34627
for(i=1; i < 65000; i++) {
34629
- if (errno == EINVAL)
34631
- printf("\t\tcase %d: return %d;\n", i, errno);
34632
+ if (errno == EINVAL) {
34633
+ /* Issue #12802 */
34634
+ if (i == ERROR_DIRECTORY)
34636
+ /* Issue #13063 */
34637
+ else if (i == ERROR_NO_DATA)
34642
+ printf(" case %d: return %d;\n", i, errno);
34644
- printf("\t\tdefault: return EINVAL;\n");
34645
- printf("\t}\n}\n");
34646
+ printf(" default: return EINVAL;\n");
34647
+ printf(" }\n}\n");
34649
diff -r 137e45f15c0b PC/pyconfig.h
34650
--- a/PC/pyconfig.h
34651
+++ b/PC/pyconfig.h
34652
@@ -648,6 +648,9 @@
34653
#define HAVE_WCSXFRM 1
34656
+/* Define if the zlib library has inflateCopy */
34657
+#define HAVE_ZLIB_COPY 1
34659
/* Define if you have the <dlfcn.h> header file. */
34660
/* #undef HAVE_DLFCN_H */
34662
diff -r 137e45f15c0b PCbuild/pythoncore.vcproj
34663
--- a/PCbuild/pythoncore.vcproj
34664
+++ b/PCbuild/pythoncore.vcproj
34665
@@ -635,6 +635,10 @@
34669
+ RelativePath="..\Include\accu.h"
34673
RelativePath="..\Include\asdl.h"
34676
@@ -1447,6 +1451,10 @@
34680
+ RelativePath="..\Objects\accu.c"
34684
RelativePath="..\Objects\boolobject.c"
34687
diff -r 137e45f15c0b Parser/asdl_c.py
34688
--- a/Parser/asdl_c.py
34689
+++ b/Parser/asdl_c.py
34690
@@ -816,11 +816,7 @@
34693
if (!PyLong_Check(obj)) {
34694
- PyObject *s = PyObject_Repr(obj);
34695
- if (s == NULL) return 1;
34696
- PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
34697
- PyBytes_AS_STRING(s));
34699
+ PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
34703
diff -r 137e45f15c0b Parser/myreadline.c
34704
--- a/Parser/myreadline.c
34705
+++ b/Parser/myreadline.c
34707
my_fgets(char *buf, int len, FILE *fp)
34712
if (PyOS_InputHook != NULL)
34713
(void)(PyOS_InputHook)();
34715
p = fgets(buf, len, fp);
34717
return 0; /* No error */
34720
/* In the case of a Ctrl+C or some other external event
34721
interrupting the operation:
34723
return -1; /* EOF */
34726
- if (errno == EINTR) {
34727
+ if (err == EINTR) {
34730
PyEval_RestoreThread(_PyOS_ReadlineTState);
34731
diff -r 137e45f15c0b Parser/parsetok.c
34732
--- a/Parser/parsetok.c
34733
+++ b/Parser/parsetok.c
34734
@@ -183,11 +183,13 @@
34735
if (type == NOTEQUAL) {
34736
if (!(ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) &&
34737
strcmp(str, "!=")) {
34738
+ PyObject_FREE(str);
34739
err_ret->error = E_SYNTAX;
34742
else if ((ps->p_flags & CO_FUTURE_BARRY_AS_BDFL) &&
34743
strcmp(str, "<>")) {
34744
+ PyObject_FREE(str);
34745
err_ret->text = "with Barry as BDFL, use '<>' "
34747
err_ret->error = E_SYNTAX;
34748
diff -r 137e45f15c0b Python/Python-ast.c
34749
--- a/Python/Python-ast.c
34750
+++ b/Python/Python-ast.c
34751
@@ -622,11 +622,7 @@
34754
if (!PyLong_Check(obj)) {
34755
- PyObject *s = PyObject_Repr(obj);
34756
- if (s == NULL) return 1;
34757
- PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
34758
- PyBytes_AS_STRING(s));
34760
+ PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
34764
diff -r 137e45f15c0b Python/_warnings.c
34765
--- a/Python/_warnings.c
34766
+++ b/Python/_warnings.c
34767
@@ -888,7 +888,6 @@
34771
- /* Don't silence DeprecationWarning if -3 was used. */
34772
PyObject *filters = PyList_New(5);
34773
unsigned int pos = 0; /* Post-incremented in each use. */
34775
diff -r 137e45f15c0b Python/bltinmodule.c
34776
--- a/Python/bltinmodule.c
34777
+++ b/Python/bltinmodule.c
34780
builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
34782
- PyObject *func, *name, *bases, *mkw, *meta, *prep, *ns, *cell;
34783
+ PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns, *cell;
34784
PyObject *cls = NULL;
34785
- Py_ssize_t nargs, nbases;
34786
+ Py_ssize_t nargs;
34789
assert(args != NULL);
34790
if (!PyTuple_Check(args)) {
34792
bases = PyTuple_GetSlice(args, 2, nargs);
34795
- nbases = nargs - 2;
34797
if (kwds == NULL) {
34799
@@ -82,17 +82,42 @@
34803
+ /* metaclass is explicitly given, check if it's indeed a class */
34804
+ isclass = PyType_Check(meta);
34807
if (meta == NULL) {
34808
- if (PyTuple_GET_SIZE(bases) == 0)
34809
+ /* if there are no bases, use type: */
34810
+ if (PyTuple_GET_SIZE(bases) == 0) {
34811
meta = (PyObject *) (&PyType_Type);
34813
+ /* else get the type of the first base */
34815
PyObject *base0 = PyTuple_GET_ITEM(bases, 0);
34816
meta = (PyObject *) (base0->ob_type);
34819
+ isclass = 1; /* meta is really a class */
34822
+ /* meta is really a class, so check for a more derived
34823
+ metaclass, or possible metaclass conflicts: */
34824
+ winner = (PyObject *)_PyType_CalculateMetaclass((PyTypeObject *)meta,
34826
+ if (winner == NULL) {
34829
+ Py_DECREF(bases);
34832
+ if (winner != meta) {
34838
+ /* else: meta is not a class, so we cannot do the metaclass
34839
+ calculation, so we will use the explicitly given object as it is */
34840
prep = PyObject_GetAttrString(meta, "__prepare__");
34841
if (prep == NULL) {
34842
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
34843
@@ -469,7 +494,7 @@
34844
PyObject *format_spec = NULL;
34846
if (!PyArg_ParseTuple(args, "O|U:format", &value, &format_spec))
34850
return PyObject_Format(value, format_spec);
34852
@@ -1477,10 +1502,8 @@
34853
PyObject *sep = NULL, *end = NULL, *file = NULL;
34856
- if (dummy_args == NULL) {
34857
- if (!(dummy_args = PyTuple_New(0)))
34858
+ if (dummy_args == NULL && !(dummy_args = PyTuple_New(0)))
34861
if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:print",
34862
kwlist, &sep, &end, &file))
34864
@@ -1615,76 +1638,65 @@
34866
/* If we're interactive, use (GNU) readline */
34869
+ PyObject *po = NULL;
34872
- PyObject *stdin_encoding;
34873
- char *stdin_encoding_str;
34875
+ PyObject *stdin_encoding = NULL, *stdin_errors = NULL;
34876
+ PyObject *stdout_encoding = NULL, *stdout_errors = NULL;
34877
+ char *stdin_encoding_str, *stdin_errors_str;
34881
stdin_encoding = PyObject_GetAttrString(fin, "encoding");
34882
- if (!stdin_encoding)
34883
+ stdin_errors = PyObject_GetAttrString(fin, "errors");
34884
+ if (!stdin_encoding || !stdin_errors)
34885
/* stdin is a text stream, so it must have an
34888
+ goto _readline_errors;
34889
stdin_encoding_str = _PyUnicode_AsString(stdin_encoding);
34890
- if (stdin_encoding_str == NULL) {
34891
- Py_DECREF(stdin_encoding);
34894
+ stdin_errors_str = _PyUnicode_AsString(stdin_errors);
34895
+ if (!stdin_encoding_str || !stdin_errors_str)
34896
+ goto _readline_errors;
34897
tmp = PyObject_CallMethod(fout, "flush", "");
34902
if (promptarg != NULL) {
34903
+ /* We have a prompt, encode it as stdout would */
34904
+ char *stdout_encoding_str, *stdout_errors_str;
34905
PyObject *stringpo;
34906
- PyObject *stdout_encoding;
34907
- char *stdout_encoding_str;
34908
stdout_encoding = PyObject_GetAttrString(fout, "encoding");
34909
- if (stdout_encoding == NULL) {
34910
- Py_DECREF(stdin_encoding);
34913
+ stdout_errors = PyObject_GetAttrString(fout, "errors");
34914
+ if (!stdout_encoding || !stdout_errors)
34915
+ goto _readline_errors;
34916
stdout_encoding_str = _PyUnicode_AsString(stdout_encoding);
34917
- if (stdout_encoding_str == NULL) {
34918
- Py_DECREF(stdin_encoding);
34919
- Py_DECREF(stdout_encoding);
34922
+ stdout_errors_str = _PyUnicode_AsString(stdout_errors);
34923
+ if (!stdout_encoding_str || !stdout_errors_str)
34924
+ goto _readline_errors;
34925
stringpo = PyObject_Str(promptarg);
34926
- if (stringpo == NULL) {
34927
- Py_DECREF(stdin_encoding);
34928
- Py_DECREF(stdout_encoding);
34931
+ if (stringpo == NULL)
34932
+ goto _readline_errors;
34933
po = PyUnicode_AsEncodedString(stringpo,
34934
- stdout_encoding_str, NULL);
34935
- Py_DECREF(stdout_encoding);
34936
- Py_DECREF(stringpo);
34937
- if (po == NULL) {
34938
- Py_DECREF(stdin_encoding);
34941
+ stdout_encoding_str, stdout_errors_str);
34942
+ Py_CLEAR(stdout_encoding);
34943
+ Py_CLEAR(stdout_errors);
34944
+ Py_CLEAR(stringpo);
34946
+ goto _readline_errors;
34947
prompt = PyBytes_AsString(po);
34948
- if (prompt == NULL) {
34949
- Py_DECREF(stdin_encoding);
34953
+ if (prompt == NULL)
34954
+ goto _readline_errors;
34960
s = PyOS_Readline(stdin, stdout, prompt);
34963
if (!PyErr_Occurred())
34964
PyErr_SetNone(PyExc_KeyboardInterrupt);
34965
- Py_DECREF(stdin_encoding);
34967
+ goto _readline_errors;
34971
@@ -1702,12 +1714,22 @@
34972
len--; /* strip trailing '\n' */
34973
if (len != 0 && s[len-1] == '\r')
34974
len--; /* strip trailing '\r' */
34975
- result = PyUnicode_Decode(s, len, stdin_encoding_str, NULL);
34976
+ result = PyUnicode_Decode(s, len, stdin_encoding_str,
34977
+ stdin_errors_str);
34980
Py_DECREF(stdin_encoding);
34981
+ Py_DECREF(stdin_errors);
34985
+ _readline_errors:
34986
+ Py_XDECREF(stdin_encoding);
34987
+ Py_XDECREF(stdout_encoding);
34988
+ Py_XDECREF(stdin_errors);
34989
+ Py_XDECREF(stdout_errors);
34994
/* Fallback if we're not interactive */
34995
diff -r 137e45f15c0b Python/codecs.c
34996
--- a/Python/codecs.c
34997
+++ b/Python/codecs.c
34998
@@ -1067,15 +1067,6 @@
35000
mod = PyImport_ImportModuleNoBlock("encodings");
35002
- if (PyErr_ExceptionMatches(PyExc_ImportError)) {
35003
- /* Ignore ImportErrors... this is done so that
35004
- distributions can disable the encodings package. Note
35005
- that other errors are not masked, e.g. SystemErrors
35006
- raised to inform the user of an error in the Python
35007
- configuration are still reported back to the user. */
35014
diff -r 137e45f15c0b Python/getcopyright.c
35015
--- a/Python/getcopyright.c
35016
+++ b/Python/getcopyright.c
35019
static char cprt[] =
35021
-Copyright (c) 2001-2011 Python Software Foundation.\n\
35022
+Copyright (c) 2001-2012 Python Software Foundation.\n\
35023
All Rights Reserved.\n\
35025
Copyright (c) 2000 BeOpen.com.\n\
35026
diff -r 137e45f15c0b Python/graminit.c
35027
--- a/Python/graminit.c
35028
+++ b/Python/graminit.c
35029
@@ -1978,7 +1978,7 @@
35038
@@ -1990,7 +1990,7 @@
35047
@@ -1999,7 +1999,7 @@
35056
@@ -2016,6 +2016,7 @@
35064
@@ -2026,8 +2027,7 @@
35074
@@ -2046,7 +2046,7 @@
35083
@@ -2088,38 +2088,38 @@
35131
diff -r 137e45f15c0b Python/import.c
35132
--- a/Python/import.c
35133
+++ b/Python/import.c
35134
@@ -252,16 +252,6 @@
35135
Py_DECREF(path_hooks);
35139
-_PyImport_Fini(void)
35141
- Py_XDECREF(extensions);
35142
- extensions = NULL;
35143
- PyMem_DEL(_PyImport_Filetab);
35144
- _PyImport_Filetab = NULL;
35148
/* Locking primitives to prevent parallel imports of the same module
35149
in different threads to return with a partially loaded module.
35150
These calls are serialized by the global interpreter lock. */
35151
@@ -374,6 +364,21 @@
35156
+_PyImport_Fini(void)
35158
+ Py_XDECREF(extensions);
35159
+ extensions = NULL;
35160
+ PyMem_DEL(_PyImport_Filetab);
35161
+ _PyImport_Filetab = NULL;
35162
+#ifdef WITH_THREAD
35163
+ if (import_lock != NULL) {
35164
+ PyThread_free_lock(import_lock);
35165
+ import_lock = NULL;
35171
imp_modules_reloading_clear(void)
35173
@@ -1221,9 +1226,9 @@
35174
(void) unlink(cpathname);
35177
- /* Now write the true mtime */
35178
+ /* Now write the true mtime (as a 32-bit field) */
35180
- assert(mtime < LONG_MAX);
35181
+ assert(mtime <= 0xFFFFFFFF);
35182
PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
35185
@@ -1297,17 +1302,14 @@
35189
-#if SIZEOF_TIME_T > 4
35190
- /* Python's .pyc timestamp handling presumes that the timestamp fits
35191
- in 4 bytes. This will be fine until sometime in the year 2038,
35192
- when a 4-byte signed time_t will overflow.
35194
- if (st.st_mtime >> 32) {
35195
- PyErr_SetString(PyExc_OverflowError,
35196
- "modification time overflows a 4 byte field");
35198
+ if (sizeof st.st_mtime > 4) {
35199
+ /* Python's .pyc timestamp handling presumes that the timestamp fits
35200
+ in 4 bytes. Since the code only does an equality comparison,
35201
+ ordering is not important and we can safely ignore the higher bits
35202
+ (collisions are extremely unlikely).
35204
+ st.st_mtime &= 0xFFFFFFFF;
35207
cpathname = make_compiled_pathname(
35208
pathname, buf, (size_t)MAXPATHLEN + 1, !Py_OptimizeFlag);
35209
if (cpathname != NULL &&
35210
@@ -1591,7 +1593,7 @@
35212
meta_path = PySys_GetObject("meta_path");
35213
if (meta_path == NULL || !PyList_Check(meta_path)) {
35214
- PyErr_SetString(PyExc_ImportError,
35215
+ PyErr_SetString(PyExc_RuntimeError,
35216
"sys.meta_path must be a list of "
35219
@@ -1641,14 +1643,14 @@
35222
if (path == NULL || !PyList_Check(path)) {
35223
- PyErr_SetString(PyExc_ImportError,
35224
+ PyErr_SetString(PyExc_RuntimeError,
35225
"sys.path must be a list of directory names");
35229
path_hooks = PySys_GetObject("path_hooks");
35230
if (path_hooks == NULL || !PyList_Check(path_hooks)) {
35231
- PyErr_SetString(PyExc_ImportError,
35232
+ PyErr_SetString(PyExc_RuntimeError,
35233
"sys.path_hooks must be a list of "
35236
@@ -1656,7 +1658,7 @@
35237
path_importer_cache = PySys_GetObject("path_importer_cache");
35238
if (path_importer_cache == NULL ||
35239
!PyDict_Check(path_importer_cache)) {
35240
- PyErr_SetString(PyExc_ImportError,
35241
+ PyErr_SetString(PyExc_RuntimeError,
35242
"sys.path_importer_cache must be a dict");
35245
@@ -1763,6 +1765,7 @@
35246
saved_namelen = namelen;
35247
#endif /* PYOS_OS2 */
35248
for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
35249
+ struct stat statbuf;
35250
#if defined(PYOS_OS2) && defined(HAVE_DYNAMIC_LOADING)
35251
/* OS/2 limits DLLs to 8 character names (w/o
35253
@@ -1791,10 +1794,16 @@
35254
strcpy(buf+len, fdp->suffix);
35255
if (Py_VerboseFlag > 1)
35256
PySys_WriteStderr("# trying %s\n", buf);
35258
filemode = fdp->mode;
35259
if (filemode[0] == 'U')
35260
filemode = "r" PY_STDIOTEXTMODE;
35261
- fp = fopen(buf, filemode);
35263
+ if (stat(buf, &statbuf) == 0 && S_ISDIR(statbuf.st_mode))
35264
+ /* it's a directory */
35267
+ fp = fopen(buf, filemode);
35269
if (case_ok(buf, len, namelen, name))
35271
@@ -2157,6 +2166,7 @@
35273
for (p = PyImport_Inittab; p->name != NULL; p++) {
35275
+ PyModuleDef *def;
35276
if (strcmp(name, p->name) == 0) {
35277
if (p->initfunc == NULL) {
35278
PyErr_Format(PyExc_ImportError,
35279
@@ -2169,6 +2179,9 @@
35280
mod = (*p->initfunc)();
35283
+ /* Remember pointer to module init function. */
35284
+ def = PyModule_GetDef(mod);
35285
+ def->m_base.m_init = p->initfunc;
35286
if (_PyImport_FixupBuiltin(mod, name) < 0)
35288
/* FixupExtension has put the module into sys.modules,
35289
@@ -2349,7 +2362,9 @@
35293
+#ifdef WITH_THREAD
35297
/* Try to get the module from sys.modules[name] */
35298
modules = PyImport_GetModuleDict();
35299
@@ -3520,7 +3535,8 @@
35302
PyDoc_STRVAR(doc_cache_from_source,
35303
-"Given the path to a .py file, return the path to its .pyc/.pyo file.\n\
35304
+"cache_from_source(path, [debug_override]) -> path\n\
35305
+Given the path to a .py file, return the path to its .pyc/.pyo file.\n\
35307
The .py file does not need to exist; this simply returns the path to the\n\
35308
.pyc/.pyo file calculated as if the .py file were imported. The extension\n\
35309
@@ -3555,7 +3571,8 @@
35312
PyDoc_STRVAR(doc_source_from_cache,
35313
-"Given the path to a .pyc./.pyo file, return the path to its .py file.\n\
35314
+"source_from_cache(path) -> path\n\
35315
+Given the path to a .pyc./.pyo file, return the path to its .py file.\n\
35317
The .pyc/.pyo file does not need to exist; this simply returns the path to\n\
35318
the .py file calculated to correspond to the .pyc/.pyo file. If path\n\
35319
diff -r 137e45f15c0b Python/pystate.c
35320
--- a/Python/pystate.c
35321
+++ b/Python/pystate.c
35322
@@ -150,6 +150,12 @@
35326
+#ifdef WITH_THREAD
35327
+ if (interp_head == NULL && head_mutex != NULL) {
35328
+ PyThread_free_lock(head_mutex);
35329
+ head_mutex = NULL;
35335
@@ -586,9 +592,9 @@
35336
autoInterpreterState = NULL;
35339
-/* Reset the TLS key - called by PyOS_AfterFork.
35340
+/* Reset the TLS key - called by PyOS_AfterFork().
35341
* This should not be necessary, but some - buggy - pthread implementations
35342
- * don't flush TLS on fork, see issue #10517.
35343
+ * don't reset TLS upon fork(), see issue #10517.
35346
_PyGILState_Reinit(void)
35347
@@ -598,8 +604,9 @@
35348
if ((autoTLSkey = PyThread_create_key()) == -1)
35349
Py_FatalError("Could not allocate TLS entry");
35351
- /* re-associate the current thread state with the new key */
35352
- if (PyThread_set_key_value(autoTLSkey, (void *)tstate) < 0)
35353
+ /* If the thread had an associated auto thread state, reassociate it with
35354
+ * the new key. */
35355
+ if (tstate && PyThread_set_key_value(autoTLSkey, (void *)tstate) < 0)
35356
Py_FatalError("Couldn't create autoTLSkey mapping");
35359
diff -r 137e45f15c0b Python/pythonrun.c
35360
--- a/Python/pythonrun.c
35361
+++ b/Python/pythonrun.c
35362
@@ -332,6 +332,22 @@
35364
/* Flush stdout and stderr */
35367
+file_is_closed(PyObject *fobj)
35370
+ PyObject *tmp = PyObject_GetAttrString(fobj, "closed");
35371
+ if (tmp == NULL) {
35375
+ r = PyObject_IsTrue(tmp);
35383
flush_std_files(void)
35385
@@ -339,7 +355,7 @@
35386
PyObject *ferr = PySys_GetObject("stderr");
35389
- if (fout != NULL && fout != Py_None) {
35390
+ if (fout != NULL && fout != Py_None && !file_is_closed(fout)) {
35391
tmp = PyObject_CallMethod(fout, "flush", "");
35393
PyErr_WriteUnraisable(fout);
35394
@@ -347,7 +363,7 @@
35398
- if (ferr != NULL && ferr != Py_None) {
35399
+ if (ferr != NULL && ferr != Py_None && !file_is_closed(ferr)) {
35400
tmp = PyObject_CallMethod(ferr, "flush", "");
35403
@@ -876,6 +892,19 @@
35408
+is_valid_fd(int fd)
35411
+ if (fd < 0 || !_PyVerify_fd(fd))
35413
+ dummy_fd = dup(fd);
35414
+ if (dummy_fd < 0)
35420
/* Initialize sys.stdin, stdout, stderr and builtins.open */
35423
@@ -935,13 +964,9 @@
35424
* and fileno() may point to an invalid file descriptor. For example
35425
* GUI apps don't have valid standard streams by default.
35429
+ if (!is_valid_fd(fd)) {
35437
std = create_stdio(iomod, fd, 0, "<stdin>", encoding, errors);
35438
@@ -954,13 +979,9 @@
35440
/* Set sys.stdout */
35441
fd = fileno(stdout);
35444
+ if (!is_valid_fd(fd)) {
35452
std = create_stdio(iomod, fd, 1, "<stdout>", encoding, errors);
35453
@@ -974,13 +995,9 @@
35454
#if 1 /* Disable this if you have trouble debugging bootstrap stuff */
35455
/* Set sys.stderr, replaces the preliminary stderr */
35456
fd = fileno(stderr);
35459
+ if (!is_valid_fd(fd)) {
35467
std = create_stdio(iomod, fd, 1, "<stderr>", encoding, "backslashreplace");
35468
@@ -995,7 +1012,8 @@
35469
const char * encoding;
35470
encoding = _PyUnicode_AsString(encoding_attr);
35471
if (encoding != NULL) {
35472
- _PyCodec_Lookup(encoding);
35473
+ PyObject *codec_info = _PyCodec_Lookup(encoding);
35474
+ Py_XDECREF(codec_info);
35476
Py_DECREF(encoding_attr);
35478
@@ -1241,8 +1259,10 @@
35482
- if (PyDict_SetItemString(d, "__cached__", Py_None) < 0)
35483
+ if (PyDict_SetItemString(d, "__cached__", Py_None) < 0) {
35490
diff -r 137e45f15c0b Python/symtable.c
35491
--- a/Python/symtable.c
35492
+++ b/Python/symtable.c
35493
@@ -1334,6 +1334,9 @@
35495
if (e->v.Lambda.args->defaults)
35496
VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
35497
+ if (e->v.Lambda.args->kw_defaults)
35498
+ VISIT_KWONLYDEFAULTS(st,
35499
+ e->v.Lambda.args->kw_defaults);
35500
if (!symtable_enter_block(st, lambda,
35501
FunctionBlock, (void *)e, e->lineno,
35503
diff -r 137e45f15c0b Python/sysmodule.c
35504
--- a/Python/sysmodule.c
35505
+++ b/Python/sysmodule.c
35506
@@ -1263,7 +1263,7 @@
35507
hexversion -- version information encoded as a single integer\n\
35508
copyright -- copyright notice pertaining to this interpreter\n\
35509
platform -- platform identifier\n\
35510
-executable -- pathname of this Python interpreter\n\
35511
+executable -- absolute path of the executable binary of the Python interpreter\n\
35512
prefix -- prefix used to find the Python library\n\
35513
exec_prefix -- prefix used to find the machine-specific Python library\n\
35514
float_repr_style -- string indicating the style of repr() output for floats\n\
35515
diff -r 137e45f15c0b README
35519
This is Python version 3.2.2
35520
============================
35522
-Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
35523
-Python Software Foundation. All rights reserved.
35524
+Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
35525
+2012 Python Software Foundation. All rights reserved.
35527
Python 3.x is a new version of the language, which is incompatible with the 2.x
35528
line of releases. The language is mostly the same, but many details, especially
35529
diff -r 137e45f15c0b Tools/gdb/libpython.py
35530
--- a/Tools/gdb/libpython.py
35531
+++ b/Tools/gdb/libpython.py
35533
_type_char_ptr = gdb.lookup_type('char').pointer() # char*
35534
_type_unsigned_char_ptr = gdb.lookup_type('unsigned char').pointer() # unsigned char*
35535
_type_void_ptr = gdb.lookup_type('void').pointer() # void*
35536
-_type_size_t = gdb.lookup_type('size_t')
35538
SIZEOF_VOID_P = _type_void_ptr.sizeof
35540
@@ -435,11 +434,15 @@
35543
def _PyObject_VAR_SIZE(typeobj, nitems):
35544
+ if _PyObject_VAR_SIZE._type_size_t is None:
35545
+ _PyObject_VAR_SIZE._type_size_t = gdb.lookup_type('size_t')
35547
return ( ( typeobj.field('tp_basicsize') +
35548
nitems * typeobj.field('tp_itemsize') +
35549
(SIZEOF_VOID_P - 1)
35550
) & ~(SIZEOF_VOID_P - 1)
35551
- ).cast(_type_size_t)
35552
+ ).cast(_PyObject_VAR_SIZE._type_size_t)
35553
+_PyObject_VAR_SIZE._type_size_t = None
35555
class HeapTypeObjectPtr(PyObjectPtr):
35556
_typename = 'PyObject'
35557
@@ -806,7 +809,7 @@
35558
class PyFrameObjectPtr(PyObjectPtr):
35559
_typename = 'PyFrameObject'
35561
- def __init__(self, gdbval, cast_to):
35562
+ def __init__(self, gdbval, cast_to=None):
35563
PyObjectPtr.__init__(self, gdbval, cast_to)
35565
if not self.is_optimized_out():
35566
@@ -840,7 +843,7 @@
35567
the global variables of this frame
35569
if self.is_optimized_out():
35573
pyop_globals = self.pyop_field('f_globals')
35574
return pyop_globals.iteritems()
35575
@@ -851,7 +854,7 @@
35576
the builtin variables
35578
if self.is_optimized_out():
35582
pyop_builtins = self.pyop_field('f_builtins')
35583
return pyop_builtins.iteritems()
35584
@@ -938,6 +941,7 @@
35585
def print_traceback(self):
35586
if self.is_optimized_out():
35587
sys.stdout.write(' (frame information optimized out)\n')
35590
sys.stdout.write(' File "%s", line %i, in %s\n'
35591
% (self.co_filename.proxyval(visited),
35592
@@ -1403,7 +1407,20 @@
35593
def get_pyop(self):
35595
f = self._gdbframe.read_var('f')
35596
- return PyFrameObjectPtr.from_pyobject_ptr(f)
35597
+ frame = PyFrameObjectPtr.from_pyobject_ptr(f)
35598
+ if not frame.is_optimized_out():
35600
+ # gdb is unable to get the "f" argument of PyEval_EvalFrameEx()
35601
+ # because it was "optimized out". Try to get "f" from the frame
35602
+ # of the caller, PyEval_EvalCodeEx().
35603
+ orig_frame = frame
35604
+ caller = self._gdbframe.older()
35606
+ f = caller.read_var('f')
35607
+ frame = PyFrameObjectPtr.from_pyobject_ptr(f)
35608
+ if not frame.is_optimized_out():
35610
+ return orig_frame
35614
@@ -1434,9 +1451,10 @@
35616
line = pyop.get_truncated_repr(MAX_OUTPUT_LEN)
35617
write_unicode(sys.stdout, '#%i %s\n' % (self.get_index(), line))
35618
- line = pyop.current_line()
35619
- if line is not None:
35620
- sys.stdout.write(line)
35621
+ if not pyop.is_optimized_out():
35622
+ line = pyop.current_line()
35623
+ if line is not None:
35624
+ sys.stdout.write(' %s\n' % line.strip())
35626
sys.stdout.write('#%i (unable to read python frame information)\n' % self.get_index())
35628
@@ -1447,9 +1465,10 @@
35629
pyop = self.get_pyop()
35631
pyop.print_traceback()
35632
- line = pyop.current_line()
35633
- if line is not None:
35634
- sys.stdout.write(' %s\n' % line.strip())
35635
+ if not pyop.is_optimized_out():
35636
+ line = pyop.current_line()
35637
+ if line is not None:
35638
+ sys.stdout.write(' %s\n' % line.strip())
35640
sys.stdout.write(' (unable to read python frame information)\n')
35642
@@ -1495,7 +1514,7 @@
35645
pyop = frame.get_pyop()
35647
+ if not pyop or pyop.is_optimized_out():
35648
print 'Unable to read information on python frame'
35651
diff -r 137e45f15c0b Tools/iobench/iobench.py
35652
--- a/Tools/iobench/iobench.py
35653
+++ b/Tools/iobench/iobench.py
35654
@@ -358,7 +358,7 @@
35655
with text_open(name, "r") as f:
35657
run_test_family(modify_tests, "b", text_files,
35658
- lambda fn: open(fn, "r+"), make_test_source)
35659
+ lambda fn: text_open(fn, "r+"), make_test_source)
35662
def prepare_files():
35663
diff -r 137e45f15c0b Tools/msi/uuids.py
35664
--- a/Tools/msi/uuids.py
35665
+++ b/Tools/msi/uuids.py
35667
'3.2.1121':'{4f90de4a-83dd-4443-b625-ca130ff361dd}', # 3.2.1rc1
35668
'3.2.1122':'{dc5eb04d-ff8a-4bed-8f96-23942fd59e5f}', # 3.2.1rc2
35669
'3.2.1150':'{34b2530c-6349-4292-9dc3-60bda4aed93c}', # 3.2.1
35670
+ '3.2.2121':'{DFB29A53-ACC4-44e6-85A6-D0DA26FE8E4E}', # 3.2.2rc1
35671
+ '3.2.2150':'{4CDE3168-D060-4b7c-BC74-4D8F9BB01AFD}', # 3.2.2
35672
+ '3.2.3121':'{B8E8CFF7-E4C6-4a7c-9F06-BB3A8B75DDA8}', # 3.2.3rc1
35673
+ '3.2.3150':'{789C9644-9F82-44d3-B4CA-AC31F46F5882}', # 3.2.3
35676
diff -r 137e45f15c0b configure.in
35679
@@ -926,6 +926,13 @@
35680
if "$CC" -v --help 2>/dev/null |grep -- -fwrapv > /dev/null; then
35684
+ # Clang also needs -fwrapv
35686
+ *clang*) WRAP="-fwrapv"
35690
case $ac_cv_prog_cc_g in
35692
if test "$Py_DEBUG" = 'true' ; then
35693
@@ -1334,7 +1341,7 @@
35694
sys/audioio.h sys/bsdtty.h sys/epoll.h sys/event.h sys/file.h sys/loadavg.h \
35695
sys/lock.h sys/mkdev.h sys/modem.h \
35696
sys/param.h sys/poll.h sys/select.h sys/socket.h sys/statvfs.h sys/stat.h \
35697
-sys/termio.h sys/time.h \
35698
+sys/syscall.h sys/termio.h sys/time.h \
35699
sys/times.h sys/types.h sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h \
35700
sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \
35701
bluetooth/bluetooth.h linux/tipc.h spawn.h util.h)
35702
@@ -2594,6 +2601,12 @@
35703
truncate uname unsetenv utimes waitpid wait3 wait4 \
35704
wcscoll wcsftime wcsxfrm _getpty)
35706
+AC_CHECK_DECL(dirfd,
35707
+ AC_DEFINE(HAVE_DIRFD, 1,
35708
+ Define if you have the 'dirfd' function or macro.), ,
35709
+ [#include <sys/types.h>
35710
+ #include <dirent.h>])
35712
# For some functions, having a definition is not sufficient, since
35713
# we want to take their address.
35714
AC_MSG_CHECKING(for chroot)
35715
@@ -2690,6 +2703,15 @@
35719
+AC_MSG_CHECKING(for broken unsetenv)
35720
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
35721
+#include <stdlib.h>
35722
+]], [[int res = unsetenv("DUMMY")]])],
35723
+ [AC_MSG_RESULT(no)],
35724
+ [AC_DEFINE(HAVE_BROKEN_UNSETENV, 1, Define if `unsetenv` does not return an int.)
35725
+ AC_MSG_RESULT(yes)
35729
AC_CHECK_PROGS(TRUE, true, /bin/true)
35731
diff -r 137e45f15c0b pyconfig.h.in
35732
--- a/pyconfig.h.in
35733
+++ b/pyconfig.h.in
35735
/* define to 1 if your sem_getvalue is broken. */
35736
#undef HAVE_BROKEN_SEM_GETVALUE
35738
+/* Define if `unsetenv` does not return an int. */
35739
+#undef HAVE_BROKEN_UNSETENV
35741
/* Define this if you have the type _Bool. */
35742
#undef HAVE_C99_BOOL
35744
@@ -175,6 +178,9 @@
35746
#undef HAVE_DIRENT_H
35748
+/* Define if you have the 'dirfd' function or macro. */
35751
/* Define to 1 if you have the <dlfcn.h> header file. */
35752
#undef HAVE_DLFCN_H
35754
@@ -783,6 +789,9 @@
35755
/* Define to 1 if you have the <sys/stat.h> header file. */
35756
#undef HAVE_SYS_STAT_H
35758
+/* Define to 1 if you have the <sys/syscall.h> header file. */
35759
+#undef HAVE_SYS_SYSCALL_H
35761
/* Define to 1 if you have the <sys/termio.h> header file. */
35762
#undef HAVE_SYS_TERMIO_H
3102
@@ -830,8 +830,13 @@
3106
- /* There's no need to clear the instance dict (if any);
3107
- the collector will call its tp_clear handler. */
3108
+ /* Clear the instance dict (if any), to break cycles involving only
3109
+ __dict__ slots (as in the case 'self.__dict__ is self'). */
3110
+ if (type->tp_dictoffset != base->tp_dictoffset) {
3111
+ PyObject **dictptr = _PyObject_GetDictPtr(self);
3112
+ if (dictptr && *dictptr)
3113
+ Py_CLEAR(*dictptr);
3117
return baseclear(self);
3118
diff -r 7085403daf43 Python/marshal.c
3119
--- a/Python/marshal.c
3120
+++ b/Python/marshal.c
3121
@@ -411,11 +411,12 @@
3122
else if (PyObject_CheckBuffer(v)) {
3123
/* Write unknown buffer-style objects as a string */
3125
- PyBufferProcs *pb = v->ob_type->tp_as_buffer;
3127
- if ((*pb->bf_getbuffer)(v, &view, PyBUF_SIMPLE) != 0) {
3128
+ if (PyObject_GetBuffer(v, &view, PyBUF_SIMPLE) != 0) {
3129
w_byte(TYPE_UNKNOWN, p);
3131
p->error = WFERR_UNMARSHALLABLE;
3134
w_byte(TYPE_STRING, p);
3139
w_string(s, (int)n, p);
3140
- if (pb->bf_releasebuffer != NULL)
3141
- (*pb->bf_releasebuffer)(v, &view);
3142
+ PyBuffer_Release(&view);
3145
w_byte(TYPE_UNKNOWN, p);
3146
@@ -1383,7 +1383,7 @@
3150
- if (!PyArg_ParseTuple(args, "s*:loads", &p))
3151
+ if (!PyArg_ParseTuple(args, "y*:loads", &p))
3155
@@ -1400,10 +1400,10 @@
3158
PyDoc_STRVAR(loads_doc,
3162
-Convert the string to a value. If no valid value is found, raise\n\
3163
-EOFError, ValueError or TypeError. Extra characters in the string are\n\
3164
+Convert the bytes object to a value. If no valid value is found, raise\n\
3165
+EOFError, ValueError or TypeError. Extra characters in the input are\n\
3168
static PyMethodDef marshal_methods[] = {
3169
diff -r 7085403daf43 Tools/msi/msi.py
3170
--- a/Tools/msi/msi.py
3171
+++ b/Tools/msi/msi.py
3172
@@ -1021,6 +1021,7 @@
3173
lib.add_file("check_soundcard.vbs")
3174
lib.add_file("empty.vbs")
3175
lib.add_file("Sine-1000Hz-300ms.aif")
3176
+ lib.add_file("mime.types")
3180
diff -r 7085403daf43 setup.py
3185
# Python header files
3186
headers = [sysconfig.get_config_h_filename()]
3187
- headers += glob(os.path.join(sysconfig.get_path('platinclude'), "*.h"))
3188
+ headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
3190
for ext in self.extensions[:]:
3191
ext.sources = [ find_module_file(filename, moddirlist)