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.
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.
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
New syntax features:
New library modules:
New built-in features:
Implementation improvements:
Significantly Improved Library Modules:
Security improvements:
Please read on for a comprehensive list of user-facing changes.
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
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
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.
(Contributed by Stefan Krah inissue 10181)
See also
PEP 3118 - Revising the Buffer Protocol
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).
Changes introduced byPEP 393 are the following:
The storage of Unicode strings now depends on the highest codepoint in the string:
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
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
Launcher documentation:Python Launcher for Windows
Installer PATH modification:Finding the Python executable
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 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 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
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
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
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
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
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.
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
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.
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.
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)
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.)
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.)
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
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)
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 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.
- abc.abstractproperty has been deprecated, usepropertywithabc.abstractmethod() instead.
- abc.abstractclassmethod has been deprecated, useclassmethod withabc.abstractmethod() instead.
- abc.abstractstaticmethod has been deprecated, usestaticmethod withabc.abstractmethod() instead.
(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).
Thearray module supports thelonglong type usingq andQ type codes.
(Contributed by Oren Tirosh and Hirokazu Yamamoto inissue 1172711)
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.)
In addition to the binary objects they normally accept, thea2b_ functionsnow all also accept ASCII-only strings as input. (Contributed by AntoinePitrou inissue 13637.)
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.
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.
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.
Theunicode_internal codec has been deprecated.
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.)
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).
Addition of salt and modular crypt format (hashing method) and themksalt()function to thecrypt module.
- 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)
- Equality comparisons between naive and awaredatetimeinstances now returnFalse instead of raisingTypeError(issue 15006).
- Newdatetime.datetime.timestamp() method: Return POSIX timestampcorresponding to thedatetime instance.
- Thedatetime.datetime.strftime() method supports formatting yearsolder than 1000.
- Thedatetime.datetime.astimezone() method can now becalled without arguments to convert datetime instance to the systemtimezone.
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 _decimal speedup pi 42.02s 0.345s 120x telco 172.19s 5.68s 30x psycopg 3.57s 0.29s 12x
The C module has the following context limits, depending on the machinearchitecture:
32-bit 64-bit MAX_PREC 425000000 999999999999999999 MAX_EMAX 425000000 999999999999999999 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.
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_length The maximum length, excluding the linesep character(s),individual lines may have when aMessage isserialized. Defaults to 78. linesep The character used to separate individual lines when aMessage is serialized. Defaults to\n. cte_type 7bit 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_defect Causes 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.
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_source Controls 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_factory A 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.
NewBytesHeaderParser, added to theparsermodule to complementHeaderParser and complete the BytesAPI.
New utility functions:
- format_datetime(): given adatetime,produce a string formatted for use in an email header.
- parsedate_to_datetime(): given a date string froman email header, convert it into an awaredatetime,or a naivedatetime if the offset is-0000.
- localtime(): With no argument, returns thecurrent local time as an awaredatetime using the localtimezone. Given an awaredatetime,converts it into an awaredatetime using thelocaltimezone.
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.)
It is now possible to register callbacks invoked by the garbage collectorbefore and after collection using the newcallbacks list.
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.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.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)
TheIMAP4_SSL constructor now accepts an SSLContextparameter to control parameters of the secure channel.
(Contributed by Sijin Joseph inissue 8808)
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)
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.
accumulate() now takes an optionalfunc argument forproviding a user-supplied binary function.
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.
Themath module has a new function,log2(), which returnsthe base-2 logarithm ofx.
(Written by Mark Dickinson inissue 11888).
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.)
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.)
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)
Theos module has a newpipe2() function that makes itpossible to create a pipe withO_CLOEXEC orO_NONBLOCK flags set atomically. This is especially useful toavoid race conditions in multi-threaded programs.
Theos module has a newsendfile() function which providesan efficent “zero-copy” way for copying data from one file (or socket)descriptor to another. The phrase “zero-copy” refers to the fact that all ofthe copying of data between the two descriptors is done entirely by thekernel, with no copying of data into userspace buffers.sendfile()can be used to efficiently copy data from a file on disk to a network socket,e.g. for downloading a file.
(Patch submitted by Ross Lagerwall and Giampaolo Rodolà inissue 10882.)
To avoid race conditions like symlink attacks and issues with temporaryfiles and directories, it is more reliable (and also faster) to manipulatefile descriptors instead of file names. Python 3.3 enhances existing functionsand introduces new functions to work on file descriptors (issue 4761,issue 10755 andissue 14626).
access() accepts aneffective_ids keyword argument to turn onusing the effective uid/gid rather than the real uid/gid in the access check.Platform support for this can be checked via thesupports_effective_ids set.
Theos module has two new functions:getpriority() andsetpriority(). They can be used to get or set processniceness/priority in a fashion similar toos.nice() but extended to allprocesses instead of just the current one.
(Patch submitted by Giampaolo Rodolà inissue 10784.)
The newos.replace() function allows cross-platform renaming of afile with overwriting the destination. Withos.rename(), an existingdestination file is overwritten under POSIX, but raises an error underWindows.(Contributed by Antoine Pitrou inissue 8828.)
The stat family of functions (stat(),fstat(),andlstat()) now support reading a file’s timestampswith nanosecond precision. Symmetrically,utime()can now write file timestamps with nanosecond precision. (Contributed byLarry Hastings inissue 14127.)
The newos.get_terminal_size() function queries the size of theterminal attached to a file descriptor. See alsoshutil.get_terminal_size().(Contributed by Zbigniew Jędrzejewski-Szmek inissue 13609.)
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.Pickler objects now have an optionaldispatch_table attribute allowing to set per-picklerreduction functions.
(Contributed by Richard Oudkerk inissue 14166.)
The Tk GUI and theserve() function have been removed from thepydoc module:pydoc-g andserve() have been deprecatedin Python 3.2.
str regular expressions now support\u and\U escapes.
(Contributed by Serhiy Storchaka inissue 3665.)
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.)
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.
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)
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)
Thesocket class now exposes additional methods to processancillary data when supported by the underlying platform:
(Contributed by David Watson inissue 6560, based on an earlier patch byHeiko Wundram)
Thesocket class now supports the PF_CAN protocol family(http://en.wikipedia.org/wiki/Socketcan), on Linux(http://lwn.net/Articles/253425).
(Contributed by Matthias Fuchs, updated by Tiago Gonçalves inissue 10141)
Thesocket class now supports the PF_RDS protocol family(http://en.wikipedia.org/wiki/Reliable_Datagram_Sockets andhttp://oss.oracle.com/projects/rds/).
Thesocket class now supports thePF_SYSTEM protocolfamily on OS X. (Contributed by Michael Goderbauer inissue 13777.)
New functionsethostname() allows the hostname to be seton unix systems if the calling process has sufficient privileges.(Contributed by Ross Lagerwall inissue 10866.)
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.)
Newsqlite3.Connection methodset_trace_callback() can be used to capture a trace ofall sql commands processed by sqlite. (Contributed by Torsten Landschoffinissue 11688.)
Thessl module has two new random generation functions:
(Contributed by Victor Stinner inissue 12049)
Thessl module now exposes a finer-grained exception hierarchyin order to make it easier to inspect the various kinds of errors.(Contributed by Antoine Pitrou inissue 11183)
load_cert_chain() now accepts apassword argumentto be used if the private key is encrypted.(Contributed by Adam Simpkins inissue 12803)
Diffie-Hellman key exchange, both regular and Elliptic Curve-based, isnow supported through theload_dh_params() andset_ecdh_curve() methods.(Contributed by Antoine Pitrou inissue 13626 andissue 13627)
SSL sockets have a newget_channel_binding() methodallowing the implementation of certain authentication mechanisms such asSCRAM-SHA-1-PLUS. (Contributed by Jacek Konieczny inissue 12551)
You can query the SSL compression algorithm used by an SSL socket, thanksto its newcompression() method. The new attributeOP_NO_COMPRESSION can be used to disable compression.(Contributed by Antoine Pitrou inissue 13634)
Support has been added for the Next Procotol Negotiation extension usingthessl.SSLContext.set_npn_protocols() method.(Contributed by Colin Marc inissue 14204)
SSL errors can now be introspected more easily thanks tolibrary andreason attributes.(Contributed by Antoine Pitrou inissue 14837)
Theget_server_certificate() function now supports IPv6.(Contributed by Charles-François Natali inissue 11811.)
New attributeOP_CIPHER_SERVER_PREFERENCE allows settingSSLv3 server sockets to use the server’s cipher ordering preference ratherthan the client’s (issue 13635).
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)
Thestruct module now supportsssize_t andsize_t via thenew codesn andN, respectively. (Contributed by Antoine Pitrouinissue 3163.)
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.)
Thesys module has a newthread_infostructsequence holding informations about the thread implementation(issue 11223).
tarfile now supportslzma encoding via thelzma module.(Contributed by Lars Gustäbel inissue 5689.)
tempfile.SpooledTemporaryFile‘struncate() method now acceptsasize parameter. (Contributed by Ryan Kelly inissue 9957.)
Thetextwrap module has a newindent() that makesit straightforward to add a common prefix to selected lines in a blockof text (issue 13857).
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.
ThePEP 418 added new functions to thetime module:
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.
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)
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.
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'))
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)
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.
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.)
Major performance enhancements have been added:
Thanks toPEP 393, some operations on Unicode strings have been optimized:
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.)
Changes to Python’s build process and to the C API include:
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.
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:
Thearray module’s'u' format code is now deprecated and will beremoved in Python 4 together with the rest of the (Py_UNICODE) API.
This section lists previously described changes and other bugfixesthat may require changes to your 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.
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.)
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.)
Enter search terms or a module, class or function name.