3
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
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
199
--- a/Doc/howto/logging-cookbook.rst
200
+++ b/Doc/howto/logging-cookbook.rst
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
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.
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
614
--- a/Doc/library/logging.rst
615
+++ b/Doc/library/logging.rst
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 @@
626
If *capture* is ``True``, warnings issued by the :mod:`warnings` module will
627
be redirected to the logging system. Specifically, a warning will be
628
formatted using :func:`warnings.formatwarning` and the resulting string
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`.
632
If *capture* is ``False``, the redirection of warnings to the logging system
633
will stop, and warnings will be redirected to their original destinations
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
653
--- a/Doc/library/operator.rst
654
+++ b/Doc/library/operator.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
665
--- a/Doc/library/re.rst
666
+++ b/Doc/library/re.rst
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.
699
three digits in length.
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
826
--- a/Doc/library/sqlite3.rst
827
+++ b/Doc/library/sqlite3.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
899
--- a/Doc/library/stdtypes.rst
900
+++ b/Doc/library/stdtypes.rst
901
@@ -1437,8 +1437,13 @@
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
936
--- a/Doc/tools/sphinxext/layout.html
937
+++ b/Doc/tools/sphinxext/layout.html
940
{% block extrahead %}
941
<link rel="shortcut icon" type="image/png" href="{{ pathto('_static/py.png', 1) }}" />
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 %}
947
diff -r 7085403daf43 Doc/tutorial/classes.rst
948
--- a/Doc/tutorial/classes.rst
949
+++ b/Doc/tutorial/classes.rst
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):
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)
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
1092
--- a/Lib/distutils/filelist.py
1093
+++ b/Lib/distutils/filelist.py
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:
1124
# ditch end of pattern character
1125
empty_pattern = glob_to_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))
1134
else: # no prefix -- respect anchor flag
1136
pattern_re = "^" + pattern_re
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."""
1146
from test.support import run_unittest
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,
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()
1167
return unittest.makeSuite(BDistMSITestCase)
1169
diff -r 7085403daf43 Lib/distutils/tests/test_filelist.py
1170
--- a/Lib/distutils/tests/test_filelist.py
1171
+++ b/Lib/distutils/tests/test_filelist.py
1173
"""Tests for distutils.filelist."""
1177
from distutils import debug
1179
from test.support import captured_stdout, run_unittest
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,
1208
def test_glob_to_re(self):
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
1399
--- a/Lib/distutils/tests/test_sdist.py
1400
+++ b/Lib/distutils/tests/test_sdist.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
1494
--- a/Lib/lib2to3/tests/test_parser.py
1495
+++ b/Lib/lib2to3/tests/test_parser.py
1498
from . import support
1499
from .support import driver, test_dir
1500
+from test.support import verbose
1510
from lib2to3.pgen2 import tokenize
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))
1520
- if diff(filepath, new):
1521
+ x = diff(filepath, new)
1523
self.fail("Idempotency failed: %s" % filepath)
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))
1537
fn = fn.replace('"', '\\"')
1538
- return os.system('diff -u "%s" @' % fn)
1539
+ return subprocess.call(['diff', '-u', fn, '@'], stdout=(subprocess.DEVNULL if verbose < 1 else None))
1543
diff -r 7085403daf43 Lib/logging/__init__.py
1544
--- a/Lib/logging/__init__.py
1545
+++ b/Lib/logging/__init__.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
1707
--- a/Lib/test/regrtest.py
1708
+++ b/Lib/test/regrtest.py
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:")
1725
'logging._handlers', 'logging._handlerList',
1726
'shutil.archive_formats', 'shutil.unpack_formats',
1727
'sys.warnoptions', 'threading._dangling',
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
1761
from test import support
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
1780
--- a/Lib/test/test_descr.py
1781
+++ b/Lib/test/test_descr.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
1862
--- a/Lib/test/test_exceptions.py
1863
+++ b/Lib/test/test_exceptions.py
1869
+ marshal.loads(b'')
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
1957
--- a/Lib/test/test_mailbox.py
1958
+++ b/Lib/test/test_mailbox.py
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 @@
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
2061
--- a/Lib/test/test_minidom.py
2062
+++ b/Lib/test/test_minidom.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
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
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.
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
2514
--- a/Lib/test/test_zlib.py
2515
+++ b/Lib/test/test_zlib.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
2568
--- a/Lib/xmlrpc/server.py
2569
+++ b/Lib/xmlrpc/server.py
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
2583
+Guilherme Gonçalves
2593
Steffen Daode Nurpmeso
2595
diff -r 7085403daf43 Misc/NEWS
2602
+What's New in Python 3.2.4
2603
+==========================
2605
+*Release date: XX-XX-XXXX*
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.
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.
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
===============================================
2660
- on 32-bit architectures. Initial patch by Philippe Devalkeneer.
2662
- HTMLParser is now able to handle slashes in the start tag.
2664
- Issue #14001: CVE-2012-0845: xmlrpc: Fix an endless loop in
2665
diff -r 7085403daf43 Modules/_io/_iomodule.c
2666
--- a/Modules/_io/_iomodule.c
2667
+++ b/Modules/_io/_iomodule.c
2670
"At the top of the I/O hierarchy is the abstract base class IOBase. It\n"
2671
"defines the basic interface to a stream. Note, however, that there is no\n"
2672
-"seperation between reading and writing to streams; implementations are\n"
2673
+"separation between reading and writing to streams; implementations are\n"
2674
"allowed to throw an IOError if they do not support a given operation.\n"
2676
"Extending IOBase is RawIOBase which deals simply with the reading and\n"
2677
diff -r 7085403daf43 Modules/_io/textio.c
2678
--- a/Modules/_io/textio.c
2679
+++ b/Modules/_io/textio.c
2681
"enabled. With this enabled, on input, the lines endings '\\n', '\\r',\n"
2682
"or '\\r\\n' are translated to '\\n' before being returned to the\n"
2683
"caller. Conversely, on output, '\\n' is translated to the system\n"
2684
- "default line seperator, os.linesep. If newline is any other of its\n"
2685
+ "default line separator, os.linesep. If newline is any other of its\n"
2686
"legal values, that newline becomes the newline when the file is read\n"
2687
"and it is returned untranslated. On output, '\\n' is converted to the\n"
2689
diff -r 7085403daf43 Modules/_sre.c
2690
--- a/Modules/_sre.c
2691
+++ b/Modules/_sre.c
2692
@@ -1664,7 +1664,7 @@
2696
-getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize)
2697
+getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize, Py_buffer *view)
2699
/* given a python object, return a data pointer, a length (in
2700
characters), and a character size. return NULL if the object
2701
@@ -1674,7 +1674,6 @@
2702
Py_ssize_t size, bytes;
2707
/* Unicode objects do not support the buffer API. So, get the data
2708
directly instead. */
2709
@@ -1686,26 +1685,21 @@
2712
/* get pointer to string buffer */
2715
buffer = Py_TYPE(string)->tp_as_buffer;
2716
if (!buffer || !buffer->bf_getbuffer ||
2717
- (*buffer->bf_getbuffer)(string, &view, PyBUF_SIMPLE) < 0) {
2718
+ (*buffer->bf_getbuffer)(string, view, PyBUF_SIMPLE) < 0) {
2719
PyErr_SetString(PyExc_TypeError, "expected string or buffer");
2723
/* determine buffer size */
2727
- /* Release the buffer immediately --- possibly dangerous
2728
- but doing something else would require some re-factoring
2730
- PyBuffer_Release(&view);
2731
+ bytes = view->len;
2735
PyErr_SetString(PyExc_TypeError, "buffer has negative size");
2740
/* determine character size */
2741
@@ -1719,7 +1713,7 @@
2744
PyErr_SetString(PyExc_TypeError, "buffer size mismatch");
2750
@@ -1728,8 +1722,13 @@
2752
PyErr_SetString(PyExc_ValueError,
2758
+ PyBuffer_Release(view);
2764
@@ -1747,20 +1746,21 @@
2765
state->lastmark = -1;
2766
state->lastindex = -1;
2768
- ptr = getstring(string, &length, &charsize);
2769
+ state->buffer.buf = NULL;
2770
+ ptr = getstring(string, &length, &charsize, &state->buffer);
2774
- if (charsize == 1 && pattern->charsize > 1) {
2775
- PyErr_SetString(PyExc_TypeError,
2778
+ if (charsize == 1 && pattern->charsize > 1) {
2779
+ PyErr_SetString(PyExc_TypeError,
2780
"can't use a string pattern on a bytes-like object");
2783
- if (charsize > 1 && pattern->charsize == 1) {
2784
- PyErr_SetString(PyExc_TypeError,
2787
+ if (charsize > 1 && pattern->charsize == 1) {
2788
+ PyErr_SetString(PyExc_TypeError,
2789
"can't use a bytes pattern on a string-like object");
2795
/* adjust boundaries */
2797
@@ -1797,11 +1797,17 @@
2798
state->lower = sre_lower;
2802
+ if (state->buffer.buf)
2803
+ PyBuffer_Release(&state->buffer);
2808
state_fini(SRE_STATE* state)
2810
+ if (state->buffer.buf)
2811
+ PyBuffer_Release(&state->buffer);
2812
Py_XDECREF(state->string);
2813
data_stack_dealloc(state);
2815
@@ -1863,6 +1869,8 @@
2817
if (self->weakreflist != NULL)
2818
PyObject_ClearWeakRefs((PyObject *) self);
2819
+ if (self->view.buf)
2820
+ PyBuffer_Release(&self->view);
2821
Py_XDECREF(self->pattern);
2822
Py_XDECREF(self->groupindex);
2823
Py_XDECREF(self->indexgroup);
2824
@@ -2297,6 +2305,7 @@
2827
int filter_is_callable;
2830
if (PyCallable_Check(ptemplate)) {
2831
/* sub/subn takes either a function or a template */
2832
@@ -2306,7 +2315,8 @@
2834
/* if not callable, check if it's a literal string */
2836
- ptr = getstring(ptemplate, &n, &bint);
2838
+ ptr = getstring(ptemplate, &n, &bint, &view);
2842
@@ -2320,6 +2330,8 @@
2847
+ PyBuffer_Release(&view);
2851
@@ -2661,6 +2673,7 @@
2852
Py_ssize_t groups = 0;
2853
PyObject* groupindex = NULL;
2854
PyObject* indexgroup = NULL;
2856
if (!PyArg_ParseTuple(args, "OiO!|nOO", &pattern, &flags,
2857
&PyList_Type, &code, &groups,
2858
&groupindex, &indexgroup))
2859
@@ -2675,6 +2688,7 @@
2860
self->pattern = NULL;
2861
self->groupindex = NULL;
2862
self->indexgroup = NULL;
2863
+ self->view.buf = NULL;
2867
@@ -2694,15 +2708,15 @@
2871
- if (pattern == Py_None)
2872
- self->charsize = -1;
2874
- Py_ssize_t p_length;
2875
- if (!getstring(pattern, &p_length, &self->charsize)) {
2880
+ if (pattern == Py_None)
2881
+ self->charsize = -1;
2883
+ Py_ssize_t p_length;
2884
+ if (!getstring(pattern, &p_length, &self->charsize, &self->view)) {
2891
self->pattern = pattern;
2892
diff -r 7085403daf43 Modules/sre.h
2896
int flags; /* flags used when compiling pattern source */
2897
PyObject *weakreflist; /* List of weak references */
2898
int charsize; /* pattern charsize (or -1) */
2901
Py_ssize_t codesize;
2905
size_t data_stack_size;
2906
size_t data_stack_base;
2908
/* current repeat context */
2911
diff -r 7085403daf43 Modules/timemodule.c
2912
--- a/Modules/timemodule.c
2913
+++ b/Modules/timemodule.c
2915
fmt = PyBytes_AS_STRING(format);
2918
-#if defined(MS_WINDOWS)
2919
+#if defined(MS_WINDOWS) && !defined(HAVE_WCSFTIME)
2920
/* check that the format string contains only valid directives */
2921
for(outbuf = strchr(fmt, '%');
2924
!strchr("aAbBcdHIjmMpSUwWxXyYzZ%", outbuf[1]))
2926
PyErr_SetString(PyExc_ValueError, "Invalid format string");
2928
+ Py_DECREF(format);
2933
diff -r 7085403daf43 Objects/dictobject.c
2934
--- a/Objects/dictobject.c
2935
+++ b/Objects/dictobject.c
2936
@@ -510,27 +510,16 @@
2937
_PyObject_GC_UNTRACK(op);
2942
-Internal routine to insert a new item into the table.
2943
-Used both by the internal resize routine and by the public insert routine.
2944
-Eats a reference to key and one to value.
2945
-Returns -1 if an error occurred, or 0 on success.
2946
+Internal routine to insert a new item into the table when you have entry object.
2947
+Used by insertdict.
2950
-insertdict(register PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value)
2951
+insertdict_by_entry(register PyDictObject *mp, PyObject *key, Py_hash_t hash,
2952
+ PyDictEntry *ep, PyObject *value)
2954
PyObject *old_value;
2955
- register PyDictEntry *ep;
2956
- typedef PyDictEntry *(*lookupfunc)(PyDictObject *, PyObject *, Py_hash_t);
2958
- assert(mp->ma_lookup != NULL);
2959
- ep = mp->ma_lookup(mp, key, hash);
2965
MAINTAIN_TRACKING(mp, key, value);
2966
if (ep->me_value != NULL) {
2967
old_value = ep->me_value;
2968
@@ -553,6 +542,28 @@
2974
+Internal routine to insert a new item into the table.
2975
+Used both by the internal resize routine and by the public insert routine.
2976
+Eats a reference to key and one to value.
2977
+Returns -1 if an error occurred, or 0 on success.
2980
+insertdict(register PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value)
2982
+ register PyDictEntry *ep;
2984
+ assert(mp->ma_lookup != NULL);
2985
+ ep = mp->ma_lookup(mp, key, hash);
2991
+ return insertdict_by_entry(mp, key, hash, ep, value);
2995
Internal routine used by dictresize() to insert an item which is
2996
known to be absent from the dict. This routine also assumes that
2997
@@ -776,39 +787,26 @@
2998
return ep->me_value;
3001
-/* CAUTION: PyDict_SetItem() must guarantee that it won't resize the
3002
- * dictionary if it's merely replacing the value for an existing key.
3003
- * This means that it's safe to loop over a dictionary with PyDict_Next()
3004
- * and occasionally replace a value -- but you can't insert new keys or
3008
-PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value)
3010
+dict_set_item_by_hash_or_entry(register PyObject *op, PyObject *key,
3011
+ Py_hash_t hash, PyDictEntry *ep, PyObject *value)
3013
register PyDictObject *mp;
3014
- register Py_hash_t hash;
3015
register Py_ssize_t n_used;
3017
- if (!PyDict_Check(op)) {
3018
- PyErr_BadInternalCall();
3023
mp = (PyDictObject *)op;
3024
- if (!PyUnicode_CheckExact(key) ||
3025
- (hash = ((PyUnicodeObject *) key)->hash) == -1)
3027
- hash = PyObject_Hash(key);
3031
assert(mp->ma_fill <= mp->ma_mask); /* at least one empty slot */
3032
n_used = mp->ma_used;
3035
- if (insertdict(mp, key, hash, value) != 0)
3038
+ if (insertdict(mp, key, hash, value) != 0)
3042
+ if (insertdict_by_entry(mp, key, hash, ep, value) != 0)
3045
/* If we added a key, we can safely resize. Otherwise just return!
3046
* If fill >= 2/3 size, adjust size. Normally, this doubles or
3047
* quaduples the size, but it's also possible for the dict to shrink
3048
@@ -828,6 +826,36 @@
3049
return dictresize(mp, (mp->ma_used > 50000 ? 2 : 4) * mp->ma_used);
3052
+/* CAUTION: PyDict_SetItem() must guarantee that it won't resize the
3053
+ * dictionary if it's merely replacing the value for an existing key.
3054
+ * This means that it's safe to loop over a dictionary with PyDict_Next()
3055
+ * and occasionally replace a value -- but you can't insert new keys or
3059
+PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value)
3061
+ register Py_hash_t hash;
3063
+ if (!PyDict_Check(op)) {
3064
+ PyErr_BadInternalCall();
3069
+ if (PyUnicode_CheckExact(key)) {
3070
+ hash = ((PyUnicodeObject *) key)->hash;
3072
+ hash = PyObject_Hash(key);
3075
+ hash = PyObject_Hash(key);
3079
+ return dict_set_item_by_hash_or_entry(op, key, hash, NULL, value);
3083
PyDict_DelItem(PyObject *op, PyObject *key)
3085
@@ -1797,9 +1825,9 @@
3090
- if (PyDict_SetItem((PyObject*)mp, key, failobj))
3092
+ if (dict_set_item_by_hash_or_entry((PyObject*)mp, key, hash, ep,
3098
diff -r 7085403daf43 Objects/typeobject.c
3099
--- a/Objects/typeobject.c
3100
+++ b/Objects/typeobject.c
3101
@@ -830,8 +830,13 @@
3105
- /* There's no need to clear the instance dict (if any);
3106
- the collector will call its tp_clear handler. */
3107
+ /* Clear the instance dict (if any), to break cycles involving only
3108
+ __dict__ slots (as in the case 'self.__dict__ is self'). */
3109
+ if (type->tp_dictoffset != base->tp_dictoffset) {
3110
+ PyObject **dictptr = _PyObject_GetDictPtr(self);
3111
+ if (dictptr && *dictptr)
3112
+ Py_CLEAR(*dictptr);
3116
return baseclear(self);
3117
diff -r 7085403daf43 Python/marshal.c
3118
--- a/Python/marshal.c
3119
+++ b/Python/marshal.c
3120
@@ -411,11 +411,12 @@
3121
else if (PyObject_CheckBuffer(v)) {
3122
/* Write unknown buffer-style objects as a string */
3124
- PyBufferProcs *pb = v->ob_type->tp_as_buffer;
3126
- if ((*pb->bf_getbuffer)(v, &view, PyBUF_SIMPLE) != 0) {
3127
+ if (PyObject_GetBuffer(v, &view, PyBUF_SIMPLE) != 0) {
3128
w_byte(TYPE_UNKNOWN, p);
3130
p->error = WFERR_UNMARSHALLABLE;
3133
w_byte(TYPE_STRING, p);
3138
w_string(s, (int)n, p);
3139
- if (pb->bf_releasebuffer != NULL)
3140
- (*pb->bf_releasebuffer)(v, &view);
3141
+ PyBuffer_Release(&view);
3144
w_byte(TYPE_UNKNOWN, p);
3145
@@ -1383,7 +1383,7 @@
3149
- if (!PyArg_ParseTuple(args, "s*:loads", &p))
3150
+ if (!PyArg_ParseTuple(args, "y*:loads", &p))
3154
@@ -1400,10 +1400,10 @@
3157
PyDoc_STRVAR(loads_doc,
3161
-Convert the string to a value. If no valid value is found, raise\n\
3162
-EOFError, ValueError or TypeError. Extra characters in the string are\n\
3163
+Convert the bytes object to a value. If no valid value is found, raise\n\
3164
+EOFError, ValueError or TypeError. Extra characters in the input are\n\
3167
static PyMethodDef marshal_methods[] = {
3168
diff -r 7085403daf43 Tools/msi/msi.py
3169
--- a/Tools/msi/msi.py
3170
+++ b/Tools/msi/msi.py
3171
@@ -1021,6 +1021,7 @@
3172
lib.add_file("check_soundcard.vbs")
3173
lib.add_file("empty.vbs")
3174
lib.add_file("Sine-1000Hz-300ms.aif")
3175
+ lib.add_file("mime.types")
3179
diff -r 7085403daf43 setup.py
3184
# Python header files
3185
headers = [sysconfig.get_config_h_filename()]
3186
- headers += glob(os.path.join(sysconfig.get_path('platinclude'), "*.h"))
3187
+ headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))
3189
for ext in self.extensions[:]:
3190
ext.sources = [ find_module_file(filename, moddirlist)