New Werkzeug and Flask Releases

I’m very happy to announce that after a long break there are finally newreleases for Werkzeug and Flask. These releases took their fair amount oftime and I will ensure the process is quicker next time around. There ishowever a good reason it took this long: they come with support for Python3 and we had to do some API changes in the process.

What’s going to break for you

Let’s start with the unfortunate things first: we probably (slightly)broke your code in Werkzeug. This was necessary because somefunctionality just does not map well to the updated PEP 3333 specification. Thisbackwards incompatible breakage is mostly limited to the werkzeug.urlsmodule as well as the Headers and EnvironHeaders data structures.You will notice that headers are now coming back in unicode at all times,decoded from latin1 and the URLs module now transparently unifies URI andIRI representation of URLs.

The Headers object also lost the ability to modify WSGI headersin-place through the old linked classmethod. This was necessary as wecould not replace the logic for PEP 3333 with acceptable performance andnot producing a too complex implementation.

Flask itself should not break that much, but what do you know. We cleanedup some internal implementations. Primarily you will notice that the|tojson filter in Flask now uses different JSON serialization and HTMLsafety rules. If you have some tests that rely on that old behavior youwill need to adjust.

Goodbye Python 2.5

Bad news for you if you’re on 2.5: support for your Python version isgone. That was necessary to make the Python 3 port go forward. Python2.5 by now is nearly 7 years old, it’s time to move on.

Hello Python 3

On the flip-side support for Python 3 is in. To be more exact: Python 3.3and higher. For Werkzeug applications porting to Python 3 might be not astrivial but Flask applications should actually work mostly out of the boxassuming their extensions are ported. For instance all of the Flaskexamples work out of the box on 2.x and 3.x and with the exception ofunit tests no modifications were necessary to their code.

Notable Changes

Other than that, here are some changes that you will hopefully enjoy:

Werkzeug:

Werkzeug now pastes traceback into private github gists.

Some smaller improvements to make the HTTP exception classes inWerkzeug more useful. They can now carry some payload and abortingwith exceptions is streamlined.

Werkzeug’s URL module now gained vastly improved IRI support andcan properly parse and join URLs. This support is currentlyintentionally in violation with the RFC to cover real-world casesbetter and to support parsing of unknown schemes.

This makes it possible for you to parse things likesqlite:///foo.db without being surprised by the behavior.

Werkzeug gained a lot of utility functions to support bridging thedifferences between PEP 333/PEP 3333 and WSGI on 2.x and 3.x. Thisincludes access to the streams and URLs.

Werkzeug’s internal form parsing got vastly improved which now makesit possible to access the stream in all cases. It also no longerrelies on content length which makes it possible to finally deal withchunked request bodies assuming the WSGI server provides support forit.

Introduced get_data methods as future proof replacement for theold .data descriptor on requests and responses. This allowsgreater flexibility on dealing with form data. In the future we willremove support for .data at which point attribute access on therequest and response objects is largely side-effect free.

Flask:

Flask gained a json module which unifies JSON support for 2.x and3.x and extends it with useful helpers. It provides safe methods todump JSON for script blocks in HTML and also automatically serializessome common types like UUIDs and datetime objects.

Further work has been done to make the application context moreprominent. Templates can now be rendered from the application contextonly and flask.g is now bound to the application context as well.

This change might seem tiny but actually simplifies working with Flaskfrom outside web environments. You can now easier maintain databaseconnections that are not bound to a HTTP request’s lifetime.

The documentation also has started to shift to this new mode ofworking.

Flask’s internal error handling has been improved to make respondingto error cases more consistent. This also has the added benefit ofmaking the “commit on success, rollback on error” finally fullyreliable. Previously the test client would suppress the errorinformation in some cases.

Introduced a get_json method on the request to go in line withWerkzeug’s new get_data method. The plan here is to removesupport for the .json descriptor at one point.

Added a few configuration options to change defaults for JSONserialization. This includes pretty-printing and ordering of keys.By default JSON objects are now ordered by keys to solve issues withinvalidating HTTP caches due to Python’s new randomized hash seed.

Changes to the Process

Going into the future there will be a new process for releases. Thetarget is to have much more frequent releases instead of large ones.Werkzeug is now getting to the point where it’s possible to do releasesoften without breaking people’s code as the API gets more stable. (Thisrelease being the notable exception due to the Python 3 support)

A Thank You Note

Lastly I want to thank the community for making this release possible. Ahuge amount of the work for these releases has been done on a sprintonline on a weekend in May. Special thanks go to DasIch, Thomas Waldmann,untitaker, Ronny Pfannschmidt, mgax, puzzlet, ThiefMaster and everybodyelse who contributed.

In this release the number of commits skyrocketed. While the totalchangelog might not look all that impressive, the underlying improvementsand code cleanups are substantial.

New Werkzeug and Flask Releases

相关文章:

你感兴趣的文章:

标签云: