Movatterモバイル変換


[0]ホーム

URL:


Wayback Machine
155 captures
06 May 2012 - 02 Jul 2025
DecMARJun
Previous capture31Next capture
201620172018
success
fail
COLLECTED BY
Organization:Archive Team
Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

History is littered with hundreds of conflicts over the future of a community, group, location or business that were "resolved" when one of the parties stepped ahead and destroyed what was there. With the original point of contention destroyed, the debates would fall to the wayside. Archive Team believes that by duplicated condemned data, the conversation and debate can continue, as well as the richness and insight gained by keeping the materials. Our projects have ranged in size from a single volunteer downloading the data to a small-but-critical site, to over 100 volunteers stepping forward to acquire terabytes of user-created data to save for future generations.

The main site for Archive Team is atarchiveteam.org and contains up to the date information on various projects, manifestos, plans and walkthroughs.

This collection contains the output of many Archive Team projects, both ongoing and completed. Thanks to the generous providing of disk space by the Internet Archive, multi-terabyte datasets can be made available, as well as in use by theWayback Machine, providing a path back to lost websites and work.

Our collection has grown to the point of having sub-collections for the type of data we acquire. If you are seeking to browse the contents of these collections, the Wayback Machine is the best first stop. Otherwise, you are free to dig into the stacks to see what you may find.

The Archive Team Panic Downloads are full pulldowns of currently extant websites, meant to serve as emergency backups for needed sites that are in danger of closing, or which will be missed dearly if suddenly lost due to hard drive crashes or server failures.

ArchiveBot is an IRC bot designed to automate the archival of smaller websites (e.g. up to a few hundred thousand URLs). You give it a URL to start at, and it grabs all content under that URL, records it in a WARC, and then uploads that WARC to ArchiveTeam servers for eventual injection into the Internet Archive (or other archive sites).

To use ArchiveBot, drop by #archivebot on EFNet. To interact with ArchiveBot, you issue commands by typing it into the channel. Note you will need channel operator permissions in order to issue archiving jobs. The dashboard shows the sites being downloaded currently.

There is a dashboard running for the archivebot process athttp://www.archivebot.com.

ArchiveBot's source code can be found athttps://github.com/ArchiveTeam/ArchiveBot.

TIMESTAMPS
loading
The Wayback Machine - https://web.archive.org/web/20170331141021/https://docs.python.org/3.3/whatsnew/3.3.html

Navigation

What’s New In Python 3.3

This article explains the new features in Python 3.3, compared to 3.2.Python 3.3 was released on September 29, 2012. For full details,see thechangelog.

See also

PEP 398 - Python 3.3 Release Schedule

Summary – Release highlights

New syntax features:

New library modules:

New built-in features:

Implementation improvements:

Significantly Improved Library Modules:

Security improvements:

  • Hash randomization is switched on by default.

Please read on for a comprehensive list of user-facing changes.

PEP 405: Virtual Environments

Virtual environments help create separate Python setups while sharing asystem-wide base install, for ease of maintenance. Virtual environmentshave their own set of private site packages (i.e. locally-installedlibraries), and are optionally segregated from the system-wide sitepackages. Their concept and implementation are inspired by the popularvirtualenv third-party package, but benefit from tighter integrationwith the interpreter core.

This PEP adds thevenv module for programmatic access, and thepyvenv script for command-line access andadministration. The Python interpreter checks for apyvenv.cfg,file whose existence signals the base of a virtual environment’s directorytree.

See also

PEP 405 - Python Virtual Environments
PEP written by Carl Meyer; implementation by Carl Meyer and Vinay Sajip

PEP 420: Implicit Namespace Packages

Native support for package directories that don’t require__init__.pymarker files and can automatically span multiple path segments (inspired byvarious third party approaches to namespace packages, as described inPEP 420)

See also

PEP 420 - Implicit Namespace Packages
PEP written by Eric V. Smith; implementation by Eric V. Smithand Barry Warsaw

PEP 3118: New memoryview implementation and buffer protocol documentation

The implementation ofPEP 3118 has been significantly improved.

The new memoryview implementation comprehensively fixes all ownership andlifetime issues of dynamically allocated fields in the Py_buffer structthat led to multiple crash reports. Additionally, several functions thatcrashed or returned incorrect results for non-contiguous or multi-dimensionalinput have been fixed.

The memoryview object now has a PEP-3118 compliant getbufferproc()that checks the consumer’s request type. Many new features have beenadded, most of them work in full generality for non-contiguous arraysand arrays with suboffsets.

The documentation has been updated, clearly spelling out responsibilitiesfor both exporters and consumers. Buffer request flags are grouped intobasic and compound flags. The memory layout of non-contiguous andmulti-dimensional NumPy-style arrays is explained.

Features

  • All native single character format specifiers in struct module syntax(optionally prefixed with ‘@’) are now supported.
  • With some restrictions, the cast() method allows changing of format andshape of C-contiguous arrays.
  • Multi-dimensional list representations are supported for any array type.
  • Multi-dimensional comparisons are supported for any array type.
  • One-dimensional memoryviews of hashable (read-only) types with formats B,b or c are now hashable. (Contributed by Antoine Pitrou inissue 13411)
  • Arbitrary slicing of any 1-D arrays type is supported. For example, itis now possible to reverse a memoryview in O(1) by using a negative step.

API changes

  • The maximum number of dimensions is officially limited to 64.
  • The representation of empty shape, strides and suboffsets is nowan empty tuple instead of None.
  • Accessing a memoryview element with format ‘B’ (unsigned bytes)now returns an integer (in accordance with the struct module syntax).For returning a bytes object the view must be cast to ‘c’ first.
  • memoryview comparisons now use the logical structure of the operandsand compare all array elements by value. All format strings in structmodule syntax are supported. Views with unrecognised format stringsare still permitted, but will always compare as unequal, regardlessof view contents.
  • For further changes seeBuild and C API Changes andPorting C code.

(Contributed by Stefan Krah inissue 10181)

See also

PEP 3118 - Revising the Buffer Protocol

PEP 393: Flexible String Representation

The Unicode string type is changed to support multiple internalrepresentations, depending on the character with the largest Unicode ordinal(1, 2, or 4 bytes) in the represented string. This allows a space-efficientrepresentation in common cases, but gives access to full UCS-4 on allsystems. For compatibility with existing APIs, several representations mayexist in parallel; over time, this compatibility should be phased out.

On the Python side, there should be no downside to this change.

On the C API side, PEP 393 is fully backward compatible. The legacy APIshould remain available at least five years. Applications using the legacyAPI will not fully benefit of the memory reduction, or - worse - may usea bit more memory, because Python may have to maintain two versions of eachstring (in the legacy format and in the new efficient storage).

Functionality

Changes introduced byPEP 393 are the following:

  • Python now always supports the full range of Unicode codepoints, includingnon-BMP ones (i.e. fromU+0000 toU+10FFFF). The distinction betweennarrow and wide builds no longer exists and Python now behaves like a widebuild, even under Windows.
  • With the death of narrow builds, the problems specific to narrow builds havealso been fixed, for example:
    • len() now always returns 1 for non-BMP characters,solen('\U0010FFFF')==1;
    • surrogate pairs are not recombined in string literals,so'\uDBFF\uDFFF'!='\U0010FFFF';
    • indexing or slicing non-BMP characters returns the expected value,so'\U0010FFFF'[0] now returns'\U0010FFFF' and not'\uDBFF';
    • all other functions in the standard library now correctly handlenon-BMP codepoints.
  • The value ofsys.maxunicode is now always1114111 (0x10FFFFin hexadecimal). ThePyUnicode_GetMax() function still returnseither0xFFFF or0x10FFFF for backward compatibility, and it shouldnot be used with the new Unicode API (seeissue 13054).
  • The./configure flag--with-wide-unicode has been removed.

Performance and resource usage

The storage of Unicode strings now depends on the highest codepoint in the string:

  • pure ASCII and Latin1 strings (U+0000-U+00FF) use 1 byte per codepoint;
  • BMP strings (U+0000-U+FFFF) use 2 bytes per codepoint;
  • non-BMP strings (U+10000-U+10FFFF) use 4 bytes per codepoint.

The net effect is that for most applications, memory usage of stringstorage should decrease significantly - especially compared to formerwide unicode builds - as, in many cases, strings will be pure ASCIIeven in international contexts (because many strings store non-humanlanguage data, such as XML fragments, HTTP headers, JSON-encoded data,etc.). We also hope that it will, for the same reasons, increase CPUcache efficiency on non-trivial applications. The memory usage ofPython 3.3 is two to three times smaller than Python 3.2, and a littlebit better than Python 2.7, on a Django benchmark (see the PEP fordetails).

See also

PEP 393 - Flexible String Representation
PEP written by Martin von Löwis; implementation by Torsten Beckerand Martin von Löwis.

PEP 397: Python Launcher for Windows

The Python 3.3 Windows installer now includes apy launcher applicationthat can be used to launch Python applications in a version independentfashion.

This launcher is invoked implicitly when double-clicking*.py files.If only a single Python version is installed on the system, that versionwill be used to run the file. If multiple versions are installed, the mostrecent version is used by default, but this can be overridden by includinga Unix-style “shebang line” in the Python script.

The launcher can also be used explicitly from the command line as thepyapplication. Runningpy follows the same version selection rules asimplicitly launching scripts, but a more specific version can be selectedby passing appropriate arguments (such as-3 to request Python 3 whenPython 2 is also installed, or-2.6 to specifclly request an earlierPython version when a more recent version is installed).

In addition to the launcher, the Windows installer now includes anoption to add the newly installed Python to the system PATH (contributedby Brian Curtin inissue 3561).

See also

PEP 397 - Python Launcher for Windows
PEP written by Mark Hammond and Martin v. Löwis; implementation byVinay Sajip.

Launcher documentation:Python Launcher for Windows

Installer PATH modification:Finding the Python executable

PEP 3151: Reworking the OS and IO exception hierarchy

The hierarchy of exceptions raised by operating system errors is now bothsimplified and finer-grained.

You don’t have to worry anymore about choosing the appropriate exceptiontype betweenOSError,IOError,EnvironmentError,WindowsError,mmap.error,socket.error orselect.error. All these exception types are now only one:OSError. The other names are kept as aliases for compatibilityreasons.

Also, it is now easier to catch a specific error condition. Instead ofinspecting theerrno attribute (orargs[0]) for a particularconstant from theerrno module, you can catch the adequateOSError subclass. The available subclasses are the following:

And theConnectionError itself has finer-grained subclasses:

Thanks to the new exceptions, common usages of theerrno can now beavoided. For example, the following code written for Python 3.2:

fromerrnoimportENOENT,EACCES,EPERMtry:withopen("document.txt")asf:content=f.read()exceptIOErroraserr:iferr.errno==ENOENT:print("document.txt file is missing")eliferr.errnoin(EACCES,EPERM):print("You are not allowed to read document.txt")else:raise

can now be written without theerrno import and without manualinspection of exception attributes:

try:withopen("document.txt")asf:content=f.read()exceptFileNotFoundError:print("document.txt file is missing")exceptPermissionError:print("You are not allowed to read document.txt")

See also

PEP 3151 - Reworking the OS and IO Exception Hierarchy
PEP written and implemented by Antoine Pitrou

PEP 380: Syntax for Delegating to a Subgenerator

PEP 380 adds theyieldfrom expression, allowing agenerator todelegatepart of its operations to another generator. This allows a section of codecontainingyield to be factored out and placed in another generator.Additionally, the subgenerator is allowed to return with a value, and thevalue is made available to the delegating generator.

While designed primarily for use in delegating to a subgenerator, theyieldfrom expression actually allows delegation to arbitrary subiterators.

For simple iterators,yieldfromiterable is essentially just a shortenedform offoriteminiterable:yielditem:

>>>defg(x):...yield fromrange(x,0,-1)...yield fromrange(x)...>>>list(g(5))[5, 4, 3, 2, 1, 0, 1, 2, 3, 4]

However, unlike an ordinary loop,yieldfrom allows subgenerators toreceive sent and thrown values directly from the calling scope, andreturn a final value to the outer generator:

>>>defaccumulate():...tally=0...while1:...next=yield...ifnextisNone:...returntally...tally+=next...>>>defgather_tallies(tallies):...while1:...tally=yield fromaccumulate()...tallies.append(tally)...>>>tallies=[]>>>acc=gather_tallies(tallies)>>>next(acc)# Ensure the accumulator is ready to accept values>>>foriinrange(4):...acc.send(i)...>>>acc.send(None)# Finish the first tally>>>foriinrange(5):...acc.send(i)...>>>acc.send(None)# Finish the second tally>>>tallies[6, 10]

The main principle driving this change is to allow even generators that aredesigned to be used with thesend andthrow methods to be split intomultiple subgenerators as easily as a single large function can be split intomultiple subfunctions.

See also

PEP 380 - Syntax for Delegating to a Subgenerator
PEP written by Greg Ewing; implementation by Greg Ewing, integrated into3.3 by Renaud Blanch, Ryan Kelly and Nick Coghlan; documentation byZbigniew Jędrzejewski-Szmek and Nick Coghlan

PEP 409: Suppressing exception context

PEP 409 introduces new syntax that allows the display of the chainedexception context to be disabled. This allows cleaner error messages inapplications that convert between exception types:

>>>classD:...def__init__(self,extra):...self._extra_attributes=extra...def__getattr__(self,attr):...try:...returnself._extra_attributes[attr]...exceptKeyError:...raiseAttributeError(attr)fromNone...>>>D({}).xTraceback (most recent call last):  File"<stdin>", line1, in<module>  File"<stdin>", line8, in__getattr__AttributeError:x

Without thefromNone suffix to suppress the cause, the originalexception would be displayed by default:

>>>classC:...def__init__(self,extra):...self._extra_attributes=extra...def__getattr__(self,attr):...try:...returnself._extra_attributes[attr]...exceptKeyError:...raiseAttributeError(attr)...>>>C({}).xTraceback (most recent call last):  File"<stdin>", line6, in__getattr__KeyError:'x'During handling of the above exception, another exception occurred:Traceback (most recent call last):  File"<stdin>", line1, in<module>  File"<stdin>", line8, in__getattr__AttributeError:x

No debugging capability is lost, as the original exception context remainsavailable if needed (for example, if an intervening library has incorrectlysuppressed valuable underlying details):

>>>try:...D({}).x...exceptAttributeErrorasexc:...print(repr(exc.__context__))...KeyError('x',)

See also

PEP 409 - Suppressing exception context
PEP written by Ethan Furman; implemented by Ethan Furman and NickCoghlan.

PEP 414: Explicit Unicode literals

To ease the transition from Python 2 for Unicode aware Python applicationsthat make heavy use of Unicode literals, Python 3.3 once again supports the“u” prefix for string literals. This prefix has no semantic significancein Python 3, it is provided solely to reduce the number of purely mechanicalchanges in migrating to Python 3, making it easier for developers to focus onthe more significant semantic changes (such as the stricter defaultseparation of binary and text data).

See also

PEP 414 - Explicit Unicode literals
PEP written by Armin Ronacher.

PEP 3155: Qualified name for classes and functions

Functions and class objects have a new__qualname__ attribute representingthe “path” from the module top-level to their definition. For global functionsand classes, this is the same as__name__. For other functions and classes,it provides better information about where they were actually defined, andhow they might be accessible from the global scope.

Example with (non-bound) methods:

>>>classC:...defmeth(self):...pass>>>C.meth.__name__'meth'>>>C.meth.__qualname__'C.meth'

Example with nested classes:

>>>classC:...classD:...defmeth(self):...pass...>>>C.D.__name__'D'>>>C.D.__qualname__'C.D'>>>C.D.meth.__name__'meth'>>>C.D.meth.__qualname__'C.D.meth'

Example with nested functions:

>>>defouter():...definner():...pass...returninner...>>>outer().__name__'inner'>>>outer().__qualname__'outer.<locals>.inner'

The string representation of those objects is also changed to include thenew, more precise information:

>>>str(C.D)"<class '__main__.C.D'>">>>str(C.D.meth)'<function C.D.meth at 0x7f46b9fe31e0>'

See also

PEP 3155 - Qualified name for classes and functions
PEP written and implemented by Antoine Pitrou.

PEP 412: Key-Sharing Dictionary

Dictionaries used for the storage of objects’ attributes are now able toshare part of their internal storage between each other (namely, the partwhich stores the keys and their respective hashes). This reduces the memoryconsumption of programs creating many instances of non-builtin types.

See also

PEP 412 - Key-Sharing Dictionary
PEP written and implemented by Mark Shannon.

PEP 362: Function Signature Object

A new functioninspect.signature() makes introspection of pythoncallables easy and straightforward. A broad range of callables is supported:python functions, decorated or not, classes, andfunctools.partial()objects. New classesinspect.Signature,inspect.Parameterandinspect.BoundArguments hold information about the call signatures,such as, annotations, default values, parameters kinds, and bound arguments,which considerably simplifies writing decorators and any code that validatesor amends calling signatures or arguments.

See also

PEP 362: - Function Signature Object
PEP written by Brett Cannon, Yury Selivanov, Larry Hastings, Jiwon Seo;implemented by Yury Selivanov.

PEP 421: Adding sys.implementation

A new attribute on thesys module exposes details specific to theimplementation of the currently running interpreter. The initial set ofattributes onsys.implementation arename,version,hexversion, andcache_tag.

The intention ofsys.implementation is to consolidate into one namespacethe implementation-specific data used by the standard library. This allowsdifferent Python implementations to share a single standard library code basemuch more easily. In its initial state,sys.implementation holds only asmall portion of the implementation-specific data. Over time that ratio willshift in order to make the standard library more portable.

One example of improved standard library portability iscache_tag. As ofPython 3.3,sys.implementation.cache_tag is used byimportlib tosupportPEP 3147 compliance. Any Python implementation that usesimportlib for its built-in import system may usecache_tag to controlthe caching behavior for modules.

SimpleNamespace

The implementation ofsys.implementation also introduces a new type toPython:types.SimpleNamespace. In contrast to a mapping-basednamespace, likedict,SimpleNamespace is attribute-based, likeobject. However, unlikeobject,SimpleNamespace instancesare writable. This means that you can add, remove, and modify the namespacethrough normal attribute access.

See also

PEP 421 - Adding sys.implementation
PEP written and implemented by Eric Snow.

Using importlib as the Implementation of Import

issue 2377 - Replace __import__ w/ importlib.__import__issue 13959 - Re-implement parts ofimp in pure Pythonissue 14605 - Make import machinery explicitissue 14646 - Require loaders set __loader__ and __package__

The__import__() function is now powered byimportlib.__import__().This work leads to the completion of “phase 2” ofPEP 302. There aremultiple benefits to this change. First, it has allowed for more of themachinery powering import to be exposed instead of being implicit and hiddenwithin the C code. It also provides a single implementation for all Python VMssupporting Python 3.3 to use, helping to end any VM-specific deviations inimport semantics. And finally it eases the maintenance of import, allowing forfuture growth to occur.

For the common user, there should be no visible change in semantics. Forthose whose code currently manipulates import or calls importprogrammatically, the code changes that might possibly be required are coveredin thePorting Python code section of this document.

New APIs

One of the large benefits of this work is the exposure of what goes intomaking the import statement work. That means the various importers that wereonce implicit are now fully exposed as part of theimportlib package.

The abstract base classes defined inimportlib.abc have been expandedto properly delineate betweenmeta path findersandpath entry finders by introducingimportlib.abc.MetaPathFinder andimportlib.abc.PathEntryFinder, respectively. The old ABC ofimportlib.abc.Finder is now only provided for backwards-compatibilityand does not enforce any method requirements.

In terms of finders,importlib.machinery.FileFinder exposes themechanism used to search for source and bytecode files of a module. Previouslythis class was an implicit member ofsys.path_hooks.

For loaders, the new abstract base classimportlib.abc.FileLoader helpswrite a loader that uses the file system as the storage mechanism for a module’scode. The loader for source files(importlib.machinery.SourceFileLoader), sourceless bytecode files(importlib.machinery.SourcelessFileLoader), and extension modules(importlib.machinery.ExtensionFileLoader) are now available fordirect use.

ImportError now hasname andpath attributes which are set whenthere is relevant data to provide. The message for failed imports will alsoprovide the full name of the module now instead of just the tail end of themodule’s name.

Theimportlib.invalidate_caches() function will now call the method withthe same name on all finders cached insys.path_importer_cache to helpclean up any stored state as necessary.

Visible Changes

For potential required changes to code, see thePorting Python codesection.

Beyond the expanse of whatimportlib now exposes, there are othervisible changes to import. The biggest is thatsys.meta_path andsys.path_hooks now store all of the meta path finders and path entryhooks used by import. Previously the finders were implicit and hidden withinthe C code of import instead of being directly exposed. This means that one cannow easily remove or change the order of the various finders to fit one’s needs.

Another change is that all modules have a__loader__ attribute, storing theloader used to create the module.PEP 302 has been updated to make thisattribute mandatory for loaders to implement, so in the future once 3rd-partyloaders have been updated people will be able to rely on the existence of theattribute. Until such time, though, import is setting the module post-load.

Loaders are also now expected to set the__package__ attribute fromPEP 366. Once again, import itself is already setting this on all loadersfromimportlib and import itself is setting the attribute post-load.

None is now inserted intosys.path_importer_cache when no findercan be found onsys.path_hooks. Sinceimp.NullImporter is notdirectly exposed onsys.path_hooks it could no longer be relied upon toalways be available to use as a value representing no finder found.

All other changes relate to semantic changes which should be taken intoconsideration when updating code for Python 3.3, and thus should be read aboutin thePorting Python code section of this document.

(Implementation by Brett Cannon)

Other Language Changes

Some smaller changes made to the core Python language are:

  • Added support for Unicode name aliases and named sequences.Bothunicodedata.lookup() and'\N{...}' now resolve name aliases,andunicodedata.lookup() resolves named sequences too.

    (Contributed by Ezio Melotti inissue 12753)

  • Unicode database updated to UCD version 6.1.0

  • Equality comparisons onrange() objects now return a result reflectingthe equality of the underlying sequences generated by those range objects.(issue 13201)

  • Thecount(),find(),rfind(),index() andrindex()methods ofbytes andbytearray objects now accept aninteger between 0 and 255 as their first argument.

    (Contributed by Petri Lehtinen inissue 12170)

  • Therjust(),ljust(), andcenter() methods ofbytesandbytearray now accept abytearray for thefillargument. (Contributed by Petri Lehtinen inissue 12380.)

  • New methods have been added tolist andbytearray:copy() andclear() (issue 10516). Consequently,MutableSequence now also defines aclear() method (issue 11388).

  • Raw bytes literals can now be writtenrb"..." as well asbr"...".

    (Contributed by Antoine Pitrou inissue 13748.)

  • dict.setdefault() now does only one lookup for the given key, makingit atomic when used with built-in types.

    (Contributed by Filip Gruszczyński inissue 13521.)

  • The error messages produced when a function call does not match the functionsignature have been significantly improved.

    (Contributed by Benjamin Peterson.)

A Finer-Grained Import Lock

Previous versions of CPython have always relied on a global import lock.This led to unexpected annoyances, such as deadlocks when importing a modulewould trigger code execution in a different thread as a side-effect.Clumsy workarounds were sometimes employed, such as thePyImport_ImportModuleNoBlock() C API function.

In Python 3.3, importing a module takes a per-module lock. This correctlyserializes importation of a given module from multiple threads (preventingthe exposure of incompletely initialized modules), while eliminating theaforementioned annoyances.

(Contributed by Antoine Pitrou inissue 9260.)

Builtin functions and types

  • open() gets a newopener parameter: the underlying file descriptorfor the file object is then obtained by callingopener with (file,flags). It can be used to use custom flags likeos.O_CLOEXEC forexample. The'x' mode was added: open for exclusive creation, failing ifthe file already exists.
  • print(): added theflush keyword argument. If theflush keywordargument is true, the stream is forcibly flushed.
  • hash(): hash randomization is enabled by default, seeobject.__hash__() andPYTHONHASHSEED.
  • Thestr type gets a newcasefold() method: return acasefolded copy of the string, casefolded strings may be used for caselessmatching. For example,'ß'.casefold() returns'ss'.
  • The sequence documentation has been substantially rewritten to betterexplain the binary/text sequence distinction and to provide specificdocumentation sections for the individual builtin sequence types(issue 4966)

New Modules

faulthandler

This new debug modulefaulthandler contains functions to dump Python tracebacks explicitly,on a fault (a crash like a segmentation fault), after a timeout, or on a usersignal. Callfaulthandler.enable() to install fault handlers for theSIGSEGV,SIGFPE,SIGABRT,SIGBUS, andSIGILL signals. You can also enable them at startup by setting thePYTHONFAULTHANDLER environment variable or by using-Xfaulthandler command line option.

Example of a segmentation fault on Linux:

$ python -q -X faulthandler>>> import ctypes>>> ctypes.string_at(0)Fatal Python error: Segmentation faultCurrent thread 0x00007fb899f39700:  File "/home/python/cpython/Lib/ctypes/__init__.py", line 486 in string_at  File "<stdin>", line 1 in <module>Segmentation fault

ipaddress

The newipaddress module provides tools for creating and manipulatingobjects representing IPv4 and IPv6 addresses, networks and interfaces (i.e.an IP address associated with a specific IP subnet).

(Contributed by Google and Peter Moody inPEP 3144)

lzma

The newly-addedlzma module provides data compression and decompressionusing the LZMA algorithm, including support for the.xz and.lzmafile formats.

(Contributed by Nadeem Vawda and Per Øyvind Karlsen inissue 6715)

Improved Modules

abc

Improved support for abstract base classes containing descriptors composed withabstract methods. The recommended approach to declaring abstract descriptors isnow to provide__isabstractmethod__ as a dynamically updatedproperty. The built-in descriptors have been updated accordingly.

(Contributed by Darren Dale inissue 11610)

abc.ABCMeta.register() now returns the registered subclass, which meansit can now be used as a class decorator (issue 10868).

array

Thearray module supports thelonglong type usingq andQ type codes.

(Contributed by Oren Tirosh and Hirokazu Yamamoto inissue 1172711)

base64

ASCII-only Unicode strings are now accepted by the decoding functions of thebase64 modern interface. For example,base64.b64decode('YWJj')returnsb'abc'. (Contributed by Catalin Iacob inissue 13641.)

binascii

In addition to the binary objects they normally accept, thea2b_ functionsnow all also accept ASCII-only strings as input. (Contributed by AntoinePitrou inissue 13637.)

bz2

Thebz2 module has been rewritten from scratch. In the process, severalnew features have been added:

  • Newbz2.open() function: open a bzip2-compressed file in binary ortext mode.

  • bz2.BZ2File can now read from and write to arbitrary file-likeobjects, by means of its constructor’sfileobj argument.

    (Contributed by Nadeem Vawda inissue 5863)

  • bz2.BZ2File andbz2.decompress() can now decompressmulti-stream inputs (such as those produced by thepbzip2 tool).bz2.BZ2File can now also be used to create this type of file, usingthe'a' (append) mode.

    (Contributed by Nir Aides inissue 1625)

  • bz2.BZ2File now implements all of theio.BufferedIOBase API,except for thedetach() andtruncate() methods.

codecs

Thembcs codec has been rewritten to handle correctlyreplace andignore error handlers on all Windows versions. Thembcs codec now supports all error handlers, instead of onlyreplace to encode andignore to decode.

A new Windows-only codec has been added:cp65001 (issue 13216). It is theWindows code page 65001 (Windows UTF-8,CP_UTF8). For example, it is usedbysys.stdout if the console output code page is set to cp65001 (e.g., usingchcp65001 command).

Multibyte CJK decoders now resynchronize faster. They only ignore the firstbyte of an invalid byte sequence. For example,b'\xff\n'.decode('gb2312','replace') now returns a\n after the replacement character.

(issue 12016)

Incremental CJK codec encoders are no longer reset at each call to theirencode() methods. For example:

$ ./python -q>>> import codecs>>> encoder = codecs.getincrementalencoder('hz')('strict')>>> b''.join(encoder.encode(x) for x in '\u52ff\u65bd\u65bc\u4eba\u3002 Bye.')b'~{NpJ)l6HK!#~} Bye.'

This example givesb'~{Np~}~{J)~}~{l6~}~{HK~}~{!#~}Bye.' with older Pythonversions.

(issue 12100)

Theunicode_internal codec has been deprecated.

collections

Addition of a newChainMap class to allow treating anumber of mappings as a single unit. (Written by Raymond Hettinger forissue 11089, made public inissue 11297)

The abstract base classes have been moved in a newcollections.abcmodule, to better differentiate between the abstract and the concretecollections classes. Aliases for ABCs are still present in thecollections module to preserve existing imports. (issue 11085)

TheCounter class now supports the unary+ and-operators, as well as the in-place operators+=,-=,|=, and&=. (Contributed by Raymond Hettinger inissue 13121.)

contextlib

ExitStack now provides a solid foundation forprogrammatic manipulation of context managers and similar cleanupfunctionality. Unlike the previouscontextlib.nested API (which wasdeprecated and removed), the new API is designed to work correctlyregardless of whether context managers acquire their resources intheir__init__ method (for example, file objects) or in their__enter__ method (for example, synchronisation objects from thethreading module).

(issue 13585)

crypt

Addition of salt and modular crypt format (hashing method) and themksalt()function to thecrypt module.

(issue 10924)

curses

  • If thecurses module is linked to the ncursesw library, use Unicodefunctions when Unicode strings or characters are passed (e.g.waddwstr()), and bytes functions otherwise (e.g.waddstr()).
  • Use the locale encoding instead ofutf-8 to encode Unicode strings.
  • curses.window has a newcurses.window.encoding attribute.
  • Thecurses.window class has a newget_wch()method to get a wide character
  • Thecurses module has a newunget_wch() function topush a wide character so the nextget_wch() will returnit

(Contributed by Iñigo Serna inissue 6755)

datetime

decimal

issue 7652 - integrate fast native decimal arithmetic.
C-module and libmpdec written by Stefan Krah.

The new C version of the decimal module integrates the high speed libmpdeclibrary for arbitrary precision correctly-rounded decimal floating pointarithmetic. libmpdec conforms to IBM’s General Decimal Arithmetic Specification.

Performance gains range from 10x for database applications to 100x fornumerically intensive applications. These numbers are expected gainsfor standard precisions used in decimal floating point arithmetic. Sincethe precision is user configurable, the exact figures may vary. For example,in integer bignum arithmetic the differences can be significantly higher.

The following table is meant as an illustration. Benchmarks are availableathttp://www.bytereef.org/mpdecimal/quickstart.html.

 decimal.py_decimalspeedup
pi42.02s0.345s120x
telco172.19s5.68s30x
psycopg3.57s0.29s12x

Features

  • TheFloatOperation signal optionally enables strictersemantics for mixing floats and Decimals.
  • If Python is compiled without threads, the C version automaticallydisables the expensive thread local context machinery. In this case,the variableHAVE_THREADS is set toFalse.

API changes

  • The C module has the following context limits, depending on the machinearchitecture:

     32-bit64-bit
    MAX_PREC425000000999999999999999999
    MAX_EMAX425000000999999999999999999
    MIN_EMIN-425000000-999999999999999999
  • In the context templates (DefaultContext,BasicContext andExtendedContext)the magnitude ofEmax andEmin has changed to999999.

  • TheDecimal constructor in decimal.py does not observethe context limits and converts values with arbitrary exponents or precisionexactly. Since the C version has internal limits, the following scheme isused: If possible, values are converted exactly, otherwiseInvalidOperation is raised and the result is NaN. In thelatter case it is always possible to usecreate_decimal()in order to obtain a rounded or inexact value.

  • The power function in decimal.py is always correctly-rounded. In theC version, it is defined in terms of the correctly-roundedexp() andln() functions,but the final result is only “almost always correctly rounded”.

  • In the C version, the context dictionary containing the signals is aMutableMapping. For speed reasons,flags andtraps alwaysrefer to the sameMutableMapping that the contextwas initialized with. If a new signal dictionary is assigned,flags andtrapsare updated with the new values, but they do not reference the RHSdictionary.

  • Pickling aContext produces a different output in orderto have a common interchange format for the Python and C versions.

  • The order of arguments in theContext constructor has beenchanged to match the order displayed byrepr().

  • Thewatchexp parameter in thequantize() methodis deprecated.

email

Policy Framework

The email package now has apolicy framework. APolicy is an object with several methods and propertiesthat control how the email package behaves. The primary policy for Python 3.3is theCompat32 policy, which provides backwardcompatibility with the email package in Python 3.2. Apolicy can bespecified when an email message is parsed by aparser, or when aMessage object is created, or when an email isserialized using agenerator. Unless overridden, a policy passedto aparser is inherited by all theMessage object and sub-objectscreated by theparser. By default agenerator will use the policy oftheMessage object it is serializing. The default policy iscompat32.

The minimum set of controls implemented by allpolicy objects are:

max_line_lengthThe maximum length, excluding the linesep character(s),individual lines may have when aMessage isserialized. Defaults to 78.
linesepThe character used to separate individual lines when aMessage is serialized. Defaults to\n.
cte_type7bit or8bit.8bit applies only to aBytesgenerator, and means that non-ASCII maybe used where allowed by the protocol (or where itexists in the original input).
raise_on_defectCauses aparser to raise error when defects areencountered instead of adding them to theMessageobject’sdefects list.

A new policy instance, with new settings, is created using theclone() method of policy objects.clone takesany of the above controls as keyword arguments. Any control not specified inthe call retains its default value. Thus you can create a policy that uses\r\n linesep characters like this:

mypolicy=compat32.clone(linesep='\r\n')

Policies can be used to make the generation of messages in the format needed byyour application simpler. Instead of having to remember to specifylinesep='\r\n' in all the places you call agenerator, you can specifyit once, when you set the policy used by theparser or theMessage,whichever your program uses to createMessage objects. On the other hand,if you need to generate messages in multiple forms, you can still specify theparameters in the appropriategenerator call. Or you can have custompolicy instances for your different cases, and pass those in when you createthegenerator.

Provisional Policy with New Header API

While the policy framework is worthwhile all by itself, the main motivation forintroducing it is to allow the creation of new policies that implement newfeatures for the email package in a way that maintains backward compatibilityfor those who do not use the new policies. Because the new policies introduce anew API, we are releasing them in Python 3.3 as aprovisional policy. Backwards incompatible changes (up to and includingremoval of the code) may occur if deemed necessary by the core developers.

The new policies are instances ofEmailPolicy,and add the following additional controls:

refold_sourceControls whether or not headers parsed by aparser are refolded by thegenerator. It can benone,long,orall. The default islong, which means thatsource headers with a line longer thanmax_line_length get refolded.none means noline get refolded, andall means that all linesget refolded.
header_factoryA callable that take aname andvalue andproduces a custom header object.

Theheader_factory is the key to the new features provided by the newpolicies. When one of the new policies is used, any header retrieved fromaMessage object is an object produced by theheader_factory, and anytime you set a header on aMessage it becomes an object produced byheader_factory. All such header objects have aname attribute equalto the header name. Address and Date headers have additional attributesthat give you access to the parsed data of the header. This means you can nowdo things like this:

>>>m=Message(policy=SMTP)>>>m['To']='Éric <foo@example.com>'>>>m['to']'Éric <foo@example.com>'>>>m['to'].addresses(Address(display_name='Éric', username='foo', domain='example.com'),)>>>m['to'].addresses[0].username'foo'>>>m['to'].addresses[0].display_name'Éric'>>>m['Date']=email.utils.localtime()>>>m['Date'].datetimedatetime.datetime(2012, 5, 25, 21, 39, 24, 465484, tzinfo=datetime.timezone(datetime.timedelta(-1, 72000), 'EDT'))>>>m['Date']'Fri, 25 May 2012 21:44:27 -0400'>>>print(m)To: =?utf-8?q?=C3=89ric?= <foo@example.com>Date: Fri, 25 May 2012 21:44:27 -0400

You will note that the unicode display name is automatically encoded asutf-8 when the message is serialized, but that when the header is accesseddirectly, you get the unicode version. This eliminates any need to deal withtheemail.headerdecode_header() ormake_header() functions.

You can also create addresses from parts:

>>>m['cc']=[Group('pals',[Address('Bob','bob','example.com'),...Address('Sally','sally','example.com')]),...Address('Bonzo',addr_spec='bonz@laugh.com')]>>>print(m)To: =?utf-8?q?=C3=89ric?= <foo@example.com>Date: Fri, 25 May 2012 21:44:27 -0400cc: pals: Bob <bob@example.com>, Sally <sally@example.com>;, Bonzo <bonz@laugh.com>

Decoding to unicode is done automatically:

>>>m2=message_from_string(str(m))>>>m2['to']'Éric <foo@example.com>'

When you parse a message, you can use theaddresses andgroupsattributes of the header objects to access the groups and individualaddresses:

>>>m2['cc'].addresses(Address(display_name='Bob', username='bob', domain='example.com'), Address(display_name='Sally', username='sally', domain='example.com'), Address(display_name='Bonzo', username='bonz', domain='laugh.com'))>>>m2['cc'].groups(Group(display_name='pals', addresses=(Address(display_name='Bob', username='bob', domain='example.com'), Address(display_name='Sally', username='sally', domain='example.com')), Group(display_name=None, addresses=(Address(display_name='Bonzo', username='bonz', domain='laugh.com'),))

In summary, if you use one of the new policies, header manipulation works theway it ought to: your application works with unicode strings, and the emailpackage transparently encodes and decodes the unicode to and from the RFCstandard Content Transfer Encodings.

Other API Changes

NewBytesHeaderParser, added to theparsermodule to complementHeaderParser and complete the BytesAPI.

New utility functions:

ftplib

  • ftplib.FTP now accepts asource_address keyword argument tospecify the(host,port) to use as the source address in the bind callwhen creating the outgoing socket. (Contributed by Giampaolo Rodolàinissue 8594.)
  • TheFTP_TLS class now provides a newccc() function to revert control channel back toplaintext. This can be useful to take advantage of firewalls that know howto handle NAT with non-secure FTP without opening fixed ports. (Contributedby Giampaolo Rodolà inissue 12139)
  • Addedftplib.FTP.mlsd() method which provides a parsable directorylisting format and deprecatesftplib.FTP.nlst() andftplib.FTP.dir(). (Contributed by Giampaolo Rodolà inissue 11072)

functools

Thefunctools.lru_cache() decorator now accepts atyped keywordargument (that defaults toFalse to ensure that it caches values ofdifferent types that compare equal in separate cache slots. (Contributedby Raymond Hettinger inissue 13227.)

gc

It is now possible to register callbacks invoked by the garbage collectorbefore and after collection using the newcallbacks list.

hmac

A newcompare_digest() function has been added to prevent sidechannel attacks on digests through timing analysis. (Contributed by NickCoghlan and Christian Heimes inissue 15061)

http

http.server.BaseHTTPRequestHandler now buffers the headers and writesthem all at once whenend_headers() iscalled. A new methodflush_headers()can be used to directly manage when the accumlated headers are sent.(Contributed by Andrew Schaaf inissue 3709.)

http.server now produces validHTML4.01strict output.(Contributed by Ezio Melotti inissue 13295.)

http.client.HTTPResponse now has areadinto() method, which means it can be usedas aio.RawIOBase class. (Contributed by John Kuhn inissue 13464.)

html

html.parser.HTMLParser is now able to parse broken markup withoutraising errors, therefore thestrict argument of the constructor and theHTMLParseError exception are now deprecated.The ability to parse broken markup is the result of a number of bug fixes thatare also available on the latest bug fix releases of Python 2.7/3.2.(Contributed by Ezio Melotti inissue 15114, andissue 14538,issue 13993,issue 13960,issue 13358,issue 1745761,issue 755670,issue 13357,issue 12629,issue 1200313,issue 670664,issue 13273,issue 12888,issue 7311)

A newhtml5 dictionary that maps HTML5 named characterreferences to the equivalent Unicode character(s) (e.g.html5['gt;']=='>') has been added to thehtml.entities module. The dictionary isnow also used byHTMLParser. (Contributed by EzioMelotti inissue 11113 andissue 15156)

imaplib

TheIMAP4_SSL constructor now accepts an SSLContextparameter to control parameters of the secure channel.

(Contributed by Sijin Joseph inissue 8808)

inspect

A newgetclosurevars() function has been added. This functionreports the current binding of all names referenced from the function body andwhere those names were resolved, making it easier to verify correct internalstate when testing code that relies on stateful closures.

(Contributed by Meador Inge and Nick Coghlan inissue 13062)

A newgetgeneratorlocals() function has been added. Thisfunction reports the current binding of local variables in the generator’sstack frame, making it easier to verify correct internal state when testinggenerators.

(Contributed by Meador Inge inissue 15153)

io

Theopen() function has a new'x' mode that can be used toexclusively create a new file, and raise aFileExistsError if the filealready exists. It is based on the C11 ‘x’ mode to fopen().

(Contributed by David Townshend inissue 12760)

The constructor of theTextIOWrapper class has a newwrite_through optional argument. Ifwrite_through isTrue, calls towrite() are guaranteed not to be buffered: any datawritten on theTextIOWrapper object is immediately handled to itsunderlying binary buffer.

itertools

accumulate() now takes an optionalfunc argument forproviding a user-supplied binary function.

logging

ThebasicConfig() function now supports an optionalhandlersargument taking an iterable of handlers to be added to the root logger.

A class level attributeappend_nul hasbeen added toSysLogHandler to allow control of theappending of theNUL (\000) byte to syslog records, since for somedeamons it is required while for others it is passed through to the log.

math

Themath module has a new function,log2(), which returnsthe base-2 logarithm ofx.

(Written by Mark Dickinson inissue 11888).

mmap

Theread() method is now more compatible with other file-likeobjects: if the argument is omitted or specified asNone, it returns thebytes from the current file position to the end of the mapping. (Contributedby Petri Lehtinen inissue 12021.)

multiprocessing

The newmultiprocessing.connection.wait() function allows to pollmultiple objects (such as connections, sockets and pipes) with a timeout.(Contributed by Richard Oudkerk inissue 12328.)

multiprocessing.Connection objects can now be transferred overmultiprocessing connections.(Contributed by Richard Oudkerk inissue 4892.)

multiprocessing.Process now accepts adaemon keyword argumentto override the default behavior of inheriting thedaemon flag fromthe parent process (issue 6064).

New attribute attributemultiprocessing.Process.sentinel allows aprogram to wait on multipleProcess objects at onetime using the appropriate OS primitives (for example,select onposix systems).

New methodsmultiprocessing.pool.Pool.starmap() andstarmap_async() provideitertools.starmap() equivalents to the existingmultiprocessing.pool.Pool.map() andmap_async() functions. (Contributed by HynekSchlawack inissue 12708.)

nntplib

Thenntplib.NNTP class now supports the context manager protocol tounconditionally consumesocket.error exceptions and to close the NNTPconnection when done:

>>>fromnntplibimportNNTP>>>withNNTP('news.gmane.org')asn:...n.group('gmane.comp.python.committers')...('211 1755 1 1755 gmane.comp.python.committers', 1755, 1, 1755, 'gmane.comp.python.committers')>>>

(Contributed by Giampaolo Rodolà inissue 9795)

os

pdb

Tab-completion is now available not only for command names, but also theirarguments. For example, for thebreak command, function and file namesare completed.

(Contributed by Georg Brandl inissue 14210)

pickle

pickle.Pickler objects now have an optionaldispatch_table attribute allowing to set per-picklerreduction functions.

(Contributed by Richard Oudkerk inissue 14166.)

pydoc

The Tk GUI and theserve() function have been removed from thepydoc module:pydoc-g andserve() have been deprecatedin Python 3.2.

re

str regular expressions now support\u and\U escapes.

(Contributed by Serhiy Storchaka inissue 3665.)

sched

  • run() now accepts ablocking parameter which whenset to False makes the method execute the scheduled events due to expiresoonest (if any) and then return immediately.This is useful in case you want to use thescheduler innon-blocking applications. (Contributed by Giampaolo Rodolà inissue 13449)
  • scheduler class can now be safely used in multi-threadedenvironments. (Contributed by Josiah Carlson and Giampaolo Rodolà inissue 8684)
  • timefunc anddelayfunct parameters ofscheduler classconstructor are now optional and defaults totime.time() andtime.sleep() respectively. (Contributed by Chris Clark inissue 13245)
  • enter() andenterabs()argument parameter is now optional. (Contributed by Chris Clark inissue 13245)
  • enter() andenterabs()now accept akwargs parameter. (Contributed by Chris Clark inissue 13245)

select

Solaris and derivative platforms have a new classselect.devpollfor high performance asynchronous sockets via/dev/poll.(Contributed by Jesús Cea Avión inissue 6397.)

shlex

The previously undocumented helper functionquote from thepipes modules has been moved to theshlex module anddocumented.quote() properly escapes all characters in a stringthat might be otherwise given special meaning by the shell.

shutil

  • New functions:
    • disk_usage(): provides total, used and free disk spacestatistics. (Contributed by Giampaolo Rodolà inissue 12442)
    • chown(): allows one to change user and/or group of the givenpath also specifying the user/group names and not only their numericids. (Contributed by Sandro Tosi inissue 12191)
    • shutil.get_terminal_size(): returns the size of the terminal windowto which the interpreter is attached. (Contributed by ZbigniewJędrzejewski-Szmek inissue 13609.)
  • copy2() andcopystat() now preserve filetimestamps with nanosecond precision on platforms that support it.They also preserve file “extended attributes” on Linux. (Contributedby Larry Hastings inissue 14127 andissue 15238.)
  • Several functions now take an optionalsymlinks argument: when thatparameter is true, symlinks aren’t dereferenced and the operation insteadacts on the symlink itself (or creates one, if relevant).(Contributed by Hynek Schlawack inissue 12715.)
  • When copying files to a different file system,move() nowhandles symlinks the way the posixmv command does, recreating thesymlink rather than copying the target file contents. (Contributed byJonathan Niehof inissue 9993.)move() now also returnsthedst argument as its result.
  • rmtree() is now resistant to symlink attacks on platformswhich support the newdir_fd parameter inos.open() andos.unlink(). (Contributed by Martin von Löwis and Hynek Schlawackinissue 4489.)

signal

smtpd

Thesmtpd module now supportsRFC 5321 (extended SMTP) andRFC 1870(size extension). Per the standard, these extensions are enabled if and onlyif the client initiates the session with anEHLO command.

(InitialELHO support by Alberto Trevino. Size extension by JuhanaJauhiainen. Substantial additional work on the patch contributed by MicheleOrrù and Dan Boswell.issue 8739)

smtplib

TheSMTP,SMTP_SSL, andLMTP classes now accept asource_address keyword argumentto specify the(host,port) to use as the source address in the bind callwhen creating the outgoing socket. (Contributed by Paulo Scardine inissue 11281.)

SMTP now supports the context manager protocol, allowing anSMTP instance to be used in awith statement. (Contributedby Giampaolo Rodolà inissue 11289.)

TheSMTP_SSL constructor and thestarttls()method now accept an SSLContext parameter to control parameters of the securechannel. (Contributed by Kasun Herath inissue 8809)

socket

socketserver

BaseServer now has an overridable methodservice_actions() that is called by theserve_forever() method in the service loop.ForkingMixIn now uses this to clean up zombiechild proceses. (Contributed by Justin Warkentin inissue 11109.)

sqlite3

Newsqlite3.Connection methodset_trace_callback() can be used to capture a trace ofall sql commands processed by sqlite. (Contributed by Torsten Landschoffinissue 11688.)

ssl

stat

The undocumented tarfile.filemode function has been moved tostat.filemode(). It can be used to convert a file’s mode to a string ofthe form ‘-rwxrwxrwx’.

(Contributed by Giampaolo Rodolà inissue 14807)

struct

Thestruct module now supportsssize_t andsize_t via thenew codesn andN, respectively. (Contributed by Antoine Pitrouinissue 3163.)

subprocess

Command strings can now be bytes objects on posix platforms. (Contributed byVictor Stinner inissue 8513.)

A new constantDEVNULL allows suppressing output in aplatform-independent fashion. (Contributed by Ross Lagerwall inissue 5870.)

sys

Thesys module has a newthread_infostructsequence holding informations about the thread implementation(issue 11223).

tarfile

tarfile now supportslzma encoding via thelzma module.(Contributed by Lars Gustäbel inissue 5689.)

tempfile

tempfile.SpooledTemporaryFile‘struncate() method now acceptsasize parameter. (Contributed by Ryan Kelly inissue 9957.)

textwrap

Thetextwrap module has a newindent() that makesit straightforward to add a common prefix to selected lines in a blockof text (issue 13857).

threading

threading.Condition,threading.Semaphore,threading.BoundedSemaphore,threading.Event, andthreading.Timer, all of which used to be factory functions returning aclass instance, are now classes and may be subclassed. (Contributed by ÉricAraujo inissue 10968).

Thethreading.Thread constructor now accepts adaemon keywordargument to override the default behavior of inheriting thedeamon flagvalue from the parent thread (issue 6064).

The formerly private function_thread.get_ident is now available as thepublic functionthreading.get_ident(). This eliminates several cases ofdirect access to the_thread module in the stdlib. Third party code thatused_thread.get_ident should likewise be changed to use the new publicinterface.

time

ThePEP 418 added new functions to thetime module:

  • get_clock_info(): Get information on a clock.
  • monotonic(): Monotonic clock (cannot go backward), not affectedby system clock updates.
  • perf_counter(): Performance counter with the highest availableresolution to measure a short duration.
  • process_time(): Sum of the system and user CPU time of thecurrent process.

Other new functions:

To improve cross platform consistency,sleep() now raises aValueError when passed a negative sleep value. Previously this was anerror on posix, but produced an infinite sleep on Windows.

types

Add a newtypes.MappingProxyType class: Read-only proxy of a mapping.(issue 14386)

The new functionstypes.new_class andtypes.prepare_class provide supportfor PEP 3115 compliant dynamic type creation. (issue 14588)

unittest

assertRaises(),assertRaisesRegex(),assertWarns(), andassertWarnsRegex() now accept a keyword argumentmsg when used ascontext managers. (Contributed by Ezio Melotti and Winston Ewert inissue 10775)

unittest.TestCase.run() now returns theTestResultobject.

urllib

TheRequest class, now accepts amethod argumentused byget_method() to determine what HTTP methodshould be used. For example, this will send a'HEAD' request:

>>>urlopen(Request('http://www.python.org',method='HEAD'))

(issue 1673007)

webbrowser

Thewebbrowser module supports more “browsers”: Google Chrome (namedchrome,chromium,chrome-browser orchromium-browser depending on the version and operating system),and the generic launchersxdg-open, from the FreeDesktop.orgproject, andgvfs-open, which is the default URI handler for GNOME3. (The former contributed by Arnaud Calmettes inissue 13620, the latterby Matthias Klose inissue 14493)

xml.etree.ElementTree

Thexml.etree.ElementTree module now imports its C accelerator bydefault; there is no longer a need to explicitly importxml.etree.cElementTree (this module stays for backwards compatibility,but is now deprecated). In addition, theiter family of methods ofElement has been optimized (rewritten in C).The module’s documentation has also been greatly improved with added examplesand a more detailed reference.

zlib

New attributezlib.Decompress.eof makes it possible to distinguishbetween a properly-formed compressed stream and an incomplete or truncated one.(Contributed by Nadeem Vawda inissue 12646.)

New attributezlib.ZLIB_RUNTIME_VERSION reports the version string ofthe underlyingzlib library that is loaded at runtime. (Contributed byTorsten Landschoff inissue 12306.)

Optimizations

Major performance enhancements have been added:

  • Thanks toPEP 393, some operations on Unicode strings have been optimized:

    • the memory footprint is divided by 2 to 4 depending on the text
    • encode an ASCII string to UTF-8 doesn’t need to encode characters anymore,the UTF-8 representation is shared with the ASCII representation
    • the UTF-8 encoder has been optimized
    • repeating a single ASCII letter and getting a substring of a ASCII stringsis 4 times faster
  • UTF-8 is now 2x to 4x faster. UTF-16 encoding is now up to 10x faster.

    (contributed by Serhiy Storchaka,issue 14624,issue 14738 andissue 15026.)

Build and C API Changes

Changes to Python’s build process and to the C API include:

Deprecated

Unsupported Operating Systems

OS/2 and VMS are no longer supported due to the lack of a maintainer.

Windows 2000 and Windows platforms which setCOMSPEC tocommand.comare no longer supported due to maintenance burden.

OSF support, which was deprecated in 3.2, has been completely removed.

Deprecated Python modules, functions and methods

Deprecated functions and types of the C API

ThePy_UNICODE has been deprecated byPEP 393 and will beremoved in Python 4. All functions using this type are deprecated:

Unicode functions and methods usingPy_UNICODE andPy_UNICODE* types:

Functions and macros manipulating Py_UNICODE* strings:

Encoders:

Deprecated features

Thearray module’s'u' format code is now deprecated and will beremoved in Python 4 together with the rest of the (Py_UNICODE) API.

Porting to Python 3.3

This section lists previously described changes and other bugfixesthat may require changes to your code.

Porting Python code

  • Hash randomization is enabled by default. Set thePYTHONHASHSEEDenvironment variable to0 to disable hash randomization. See also theobject.__hash__() method.
  • issue 12326: On Linux, sys.platform doesn’t contain the major versionanymore. It is now always ‘linux’, instead of ‘linux2’ or ‘linux3’ dependingon the Linux version used to build Python. Replace sys.platform == ‘linux2’with sys.platform.startswith(‘linux’), or directly sys.platform == ‘linux’ ifyou don’t need to support older Python versions.
  • issue 13847,issue 14180:time anddatetime:OverflowError is now raised instead ofValueError if atimestamp is out of range.OSError is now raised if C functionsgmtime() orlocaltime() failed.
  • The default finders used by import now utilize a cache of what is containedwithin a specific directory. If you create a Python source file or sourcelessbytecode file, make sure to callimportlib.invalidate_caches() to clearout the cache for the finders to notice the new file.
  • ImportError now uses the full name of the module that was attemped tobe imported. Doctests that check ImportErrors’ message will need to beupdated to use the full name of the module instead of just the tail of thename.
  • Theindex argument to__import__() now defaults to 0 instead of -1and no longer support negative values. It was an oversight whenPEP 328 wasimplemented that the default value remained -1. If you need to continue toperform a relative import followed by an absolute import, then perform therelative import using an index of 1, followed by another import using anindex of 0. It is preferred, though, that you useimportlib.import_module() rather than call__import__() directly.
  • __import__() no longer allows one to use an index value other than 0for top-level modules. E.g.__import__('sys',level=1) is now an error.
  • Becausesys.meta_path andsys.path_hooks now have finders onthem by default, you will most likely want to uselist.insert() insteadoflist.append() to add to those lists.
  • BecauseNone is now inserted intosys.path_importer_cache, if youare clearing out entries in the dictionary of paths that do not have afinder, you will need to remove keys paired with values ofNoneandimp.NullImporter to be backwards-compatible. This will lead to extraoverhead on older versions of Python that re-insertNone intosys.path_importer_cache where it repesents the use of implicitfinders, but semantically it should not change anything.
  • importlib.abc.Finder no longer specifies afind_module() abstractmethod that must be implemented. If you were relying on subclasses toimplement that method, make sure to check for the method’s existence first.You will probably want to check forfind_loader() first, though, in thecase of working withpath entry finders.
  • pkgutil has been converted to useimportlib internally. Thiseliminates many edge cases where the old behaviour of the PEP 302 importemulation failed to match the behaviour of the real import system. Theimport emulation itself is still present, but is now deprecated. Thepkgutil.iter_importers() andpkgutil.walk_packages() functionsspecial case the standard import hooks so they are still supported eventhough they do not provide the non-standarditer_modules() method.
  • A longstanding RFC-compliance bug (issue 1079) in the parsing done byemail.header.decode_header() has been fixed. Code that uses thestandard idiom to convert encoded headers into unicode(str(make_header(decode_header(h))) will see no change, but code thatlooks at the individual tuples returned by decode_header will see thatwhitespace that precedes or followsASCII sections is now included in theASCII section. Code that builds headers usingmake_header shouldalso continue to work without change, sincemake_header continues to addwhitespace betweenASCII and non-ASCII sections if it is not alreadypresent in the input strings.
  • email.utils.formataddr() now does the correct content transferencoding when passed non-ASCII display names. Any code that depended onthe previous buggy behavior that preserved the non-ASCII unicode in theformatted output string will need to be changed (issue 1690608).
  • poplib.POP3.quit() may now raise protocol errors like all otherpoplib methods. Code that assumesquit does not raisepoplib.error_proto errors may need to be changed if errors onquitare encountered by a particular application (issue 11291).
  • Thestrict argument toemail.parser.Parser, deprecated sincePython 2.4, has finally been removed.
  • The deprecated methodunittest.TestCase.assertSameElements has beenremoved.
  • The deprecated variabletime.accept2dyear has been removed.
  • The deprecatedContext._clamp attribute has been removed from thedecimal module. It was previously replaced by the public attributeclamp. (Seeissue 8540.)
  • The undocumented internal helper classSSLFakeFile has been removedfromsmtplib, since its functionality has long been provided directlybysocket.socket.makefile().
  • Passing a negative value totime.sleep() on Windows now raises anerror instead of sleeping forever. It has always raised an error on posix.
  • Theast.__version__ constant has been removed. If you need tomake decisions affected by the AST version, usesys.version_infoto make the decision.
  • Code that used to work around the fact that thethreading module usedfactory functions by subclassing the private classes will need to change tosubclass the now-public classes.
  • The undocumented debugging machinery in the threading module has beenremoved, simplifying the code. This should have no effect on productioncode, but is mentioned here in case any application debug frameworks wereinteracting with it (issue 13550).

Porting C code

  • In the course of changes to the buffer API the undocumentedsmalltable member of thePy_buffer structure has been removed and thelayout of thePyMemoryViewObject has changed.

    All extensions relying on the relevant parts inmemoryobject.horobject.h must be rebuilt.

  • Due toPEP 393, thePy_UNICODE type and allfunctions using this type are deprecated (but will stay available forat least five years). If you were using low-level Unicode APIs toconstruct and access unicode objects and you want to benefit of thememory footprint reduction provided by PEP 393, you have to convertyour code to the newUnicode API.

    However, if you only have been using high-level functions such asPyUnicode_Concat(),PyUnicode_Join() orPyUnicode_FromFormat(), your code will automatically takeadvantage of the new unicode representations.

  • PyImport_GetMagicNumber() now returns -1 upon failure.

  • As a negative value for thelevel argument to__import__() is nolonger valid, the same now holds forPyImport_ImportModuleLevel().This also means that the value oflevel used byPyImport_ImportModuleEx() is now 0 instead of -1.

Building C extensions

  • The range of possible file names for C extensions has been narrowed.Very rarely used spellings have been suppressed: under POSIX, filesnamedxxxmodule.so,xxxmodule.abi3.so andxxxmodule.cpython-*.so are no longer recognized as implementingthexxx module. If you had been generating such files, you haveto switch to the other spellings (i.e., remove themodule stringfrom the file names).

    (implemented inissue 14040.)

Command Line Switch Changes

  • The -Q command-line flag and related artifacts have been removed. Codechecking sys.flags.division_warning will need updating.

    (issue 10998, contributed by Éric Araujo.)

  • Whenpython is started with-S,importsitewill no longer add site-specific paths to the module search paths. Inprevious versions, it did.

    (issue 11591, contributed by Carl Meyer with editions by Éric Araujo.)

Table Of Contents

Previous topic

What’s New in Python

Next topic

What’s New In Python 3.2

This Page

Quick search

Enter search terms or a module, class or function name.

Navigation

©Copyright 1990-2014, Python Software Foundation.
The Python Software Foundation is a non-profit corporation.Please donate.
Last updated on Oct 12, 2014.Found a bug?
Created usingSphinx 1.2.

[8]ページ先頭

©2009-2025 Movatter.jp