From 1d2ee524d897fd010ef6a401fdf7d7ca6c82928f Mon Sep 17 00:00:00 2001 From: David Fischer Date: Fri, 1 Mar 2013 23:21:08 -0800 Subject: [PATCH 1/4] Initial docs patch for migrating from pre 1.0 --- docs/api.rst | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/docs/api.rst b/docs/api.rst index f22530bf..a3c68a03 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -104,3 +104,73 @@ Classes .. autoclass:: requests.Session :inherited-members: + +Migrating to 1.x +---------------- + +This section details the main differences between 0.x and 1.x and is meant +to ease the pain of upgrading. + + +API Changes +~~~~~~~~~~~ + +* ``Response.json`` is now a callable and not a property of a response. + + :: + + import requests + r = requests.get('https://github.com/timeline.json') + r.json() # This *call* raises an exception if JSON decoding fails + +* The ``Session`` API has changed. Sessions objects no longer take parameters. + ``Session`` is also now capitalized, but it can still be + instantiated with a lowercase ``session`` for backwards compatibility. + + :: + + with requests.session() as s: # formerly, session took parameters + s.auth = auth + s.headers.update(headers) + +* All request hooks have been removed except 'response'. + +* Authentication helpers have been broken out into separate modules. See + requests-oauthlib_ and requests-kerberos_. + +.. _requests-oauthlib: https://github.com/requests/requests-oauthlib +.. _requests-kerberos: https://github.com/requests/requests-kerberos + +* The parameter for streaming requests was changed from ``prefetch`` to + ``stream``. In addition, the stream parameter is required for raw response + reading. + + :: + + # in 0.x, the "stream" parameter was called "prefetch" + r = requests.get('https://github.com/timeline.json', stream=True) + r.raw.read(10) + +* The ``config`` parameter to the requests method has been removed. Some of + these options are now configured on a ``Session`` such as keep-alive and + maximum number of redirects. The verbosity option should be handled by + configuring logging. + + :: + + # Verbosity should now be configured with logging + my_config = {'verbose': sys.stderr} + requests.get('http://httpbin.org/headers', config=my_config) # bad! + + +Licensing +~~~~~~~~~ + +One key difference that has nothing to do with the API is a change in the +license from the ISC_ license to the `Apache 2.0`_ license. The Apache 2.0 +license ensures that contributions to requests are also covered by the Apache +2.0 license. + +.. _ISC: http://opensource.org/licenses/ISC +.. _Apache 2.0: http://opensource.org/licenses/Apache-2.0 + From 7eba5ffe48add27bc677ae6421b8d6d98dd4f9ef Mon Sep 17 00:00:00 2001 From: David Fischer Date: Sat, 2 Mar 2013 08:44:14 -0800 Subject: [PATCH 2/4] Logic on streaming responses was changed in 1.0 * prefetch=False in 0.x is now stream=True --- docs/api.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index a3c68a03..2309e93d 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -142,12 +142,12 @@ API Changes .. _requests-kerberos: https://github.com/requests/requests-kerberos * The parameter for streaming requests was changed from ``prefetch`` to - ``stream``. In addition, the stream parameter is required for raw response - reading. + ``stream`` and the logic was inverted. In addition, ``stream`` is now + required for raw response reading. :: - # in 0.x, the "stream" parameter was called "prefetch" + # in 0.x, passing prefetch=False would accomplish the same thing r = requests.get('https://github.com/timeline.json', stream=True) r.raw.read(10) From 73abf84ace955e681d07cacf047263d95c540440 Mon Sep 17 00:00:00 2001 From: David Fischer Date: Sat, 2 Mar 2013 08:51:55 -0800 Subject: [PATCH 3/4] Capitalize s in Session --- docs/api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api.rst b/docs/api.rst index 2309e93d..4bd35e24 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -129,7 +129,7 @@ API Changes :: - with requests.session() as s: # formerly, session took parameters + with requests.Session() as s: # formerly, session took parameters s.auth = auth s.headers.update(headers) From 7e7c275504b8f757439e5cb82650705598225bfe Mon Sep 17 00:00:00 2001 From: David Fischer Date: Sat, 2 Mar 2013 08:59:19 -0800 Subject: [PATCH 4/4] Session isn't advertised as a context manager --- docs/api.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 4bd35e24..8e7eacd3 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -129,9 +129,10 @@ API Changes :: - with requests.Session() as s: # formerly, session took parameters - s.auth = auth - s.headers.update(headers) + s = requests.Session() # formerly, session took parameters + s.auth = auth + s.headers.update(headers) + r = s.get('http://httpbin.org/headers') * All request hooks have been removed except 'response'.