What’s New in WebOb 1.7

Compatibility

  • WebOb is no longer supported on Python 2.6 and PyPy3. PyPy3 support will be re-introduced as soon as it supports a Python version higher than 3.2 and pip fully supports the platform again.

    If you would like Python 2.6 support, please pin to WebOb 1.6, which still has Python 2.6 support.

Backwards Incompatibility

  • Response.content_type removes all existing Content-Type parameters, and if the new Content-Type is “texty” it adds a new charset (unless already provided) using the default_charset, to emulate the old behaviour you may use the following:

    1. res = Response(content_type='text/html', charset='UTF-8')
    2. assert res.content_type == 'text/html'
    3. assert res.charset == 'UTF-8'
    4. params = res.content_type_params
    5. # Change the Content-Type
    6. res.content_type = 'application/unknown'
    7. assert res.content_type == 'application/unknown'
    8. assert res.charset == None
    9. # This will add the ``charset=UTF-8`` parameter to the Content-Type
    10. res.content_type_params = params
    11. assert res.headers['Content-Type'] == 'application/unknown; charset=UTF-8'

    See https://github.com/Pylons/webob/pull/301 for more information.

  • Response no longer treats application/json as a special case that may also be treated as text. This means the following may no longer be used:

    1. res = Response(json.dumps({}), content_type='application/json')

    Since application/json does not have a charset, this will now raise an error.

    Replacements are:

    1. res = Response(json_body={})

    This will create a new Response that automatically sets up the the Content-Type and converts the dictionary to a JSON object internally.

    If you want WebOb to the encoding but do the conversion to JSON yourself, the following would also work:

    1. res = Response(text=json.dumps({}), content_type='application/json')

    This uses default_body_encoding to encode the text.

  • Response.set_cookie no longer accepts a key argument. This was deprecated in WebOb 1.5 and as mentioned in the deprecation, is being removed in 1.7

    Use:

    1. res = Response()
    2. res.set_cookie(name='cookie_name', value='val')
    3. # or
    4. res.set_cookie('cookie_name', 'val')

    Instead of:

    1. res = Response()
    2. res.set_cookie(key='cookie_name', value='val')
  • Response.__init__ will no longer set the default Content-Type, nor Content-Length on Responses that don’t have a body. This allows WebOb to return proper responses for things like Response(status=’204 No Content’).

  • Response.text will no longer raise if the Content-Type does not have a charset, it will fall back to using the new default_body_encoding. To get the old behaviour back please sub-class Response and set default_body_encoding to None. See https://github.com/Pylons/webob/pull/287

    An example of a Response class that has the old behaviour:

    1. class MyResponse(Response):
    2. default_body_encoding = None
    3. res = MyResponse(content_type='application/json')
    4. # This will raise as application/json doesn't have a charset
    5. res.text = 'sometext'
  • WebOb no longer supports Chunked Encoding, this means that if you are using WebOb and need Chunked Encoding you will be required to have a proxy that unchunks the request for you. Please read https://github.com/Pylons/webob/issues/279 for more background.

    This changes the behaviour of request.is_body_readable, it will no longer assume that a request has a body just because it is a particular HTTP verb. This change also allows any HTTP verb to be able to contain a body, which allows for example a HTTP body on DELETE or even GET.

Feature

Bugfix