[PATCH 2 of 2 rqlcontroller] Narrow try/except ValueError block in RqlIOController.json()

Olivier Giorgis olivier.giorgis at logilab.fr
Mon Jun 11 15:40:14 CEST 2018


LGTM but cannot apply

On 11/06/2018 14:09, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde at logilab.fr>
> # Date 1528718773 -7200
> #      Mon Jun 11 14:06:13 2018 +0200
> # Node ID e2d1e84cea287d1dfa0693b961ee6db59e55b95b
> # Parent  15247c11de9dd43273b5615141f589a5b8836b0b
> # Available At http://hg.logilab.org/review/cubes/rqlcontroller
> #              hg pull http://hg.logilab.org/review/cubes/rqlcontroller -r e2d1e84cea28
> # EXP-Topic py3
> Narrow try/except ValueError block in RqlIOController.json()
>
> The ValueError only concerns json.loads() call.
>
> diff --git a/views.py b/views.py
> --- a/views.py
> +++ b/views.py
> @@ -103,17 +103,17 @@ class RqlIOController(Controller):
>                     match_form_params('version'))
>   
>       def json(self):
> +        contenttype = self._cw.get_header('Content-Type', raw=False)
> +        if (contenttype.mediaType, contenttype.mediaSubtype) == ('application', 'json'):  # noqa: E501
> +            encoding = contenttype.params.get('charset', 'utf-8')
> +            content = self._cw.content
> +        else:
> +            # Multipart content is usually built by
> +            # cubicweb.multipart.parse_form_data() which encodes using
> +            # "utf-8" by default.
> +            encoding = 'utf-8'
> +            content = self._cw.form['json'][1]
>           try:
> -            contenttype = self._cw.get_header('Content-Type', raw=False)
> -            if (contenttype.mediaType, contenttype.mediaSubtype) == ('application', 'json'):  # noqa: E501
> -                encoding = contenttype.params.get('charset', 'utf-8')
> -                content = self._cw.content
> -            else:
> -                # Multipart content is usually built by
> -                # cubicweb.multipart.parse_form_data() which encodes using
> -                # "utf-8" by default.
> -                encoding = 'utf-8'
> -                content = self._cw.form['json'][1]
>               args = json.loads(content.getvalue().decode(encoding))
>           except ValueError as exc:
>               raise RemoteCallFailed(exc_message(exc, self._cw.encoding))


-- 
Olivier GIORGIS
Logilab         http://www.logilab.fr


More information about the cubicweb-devel mailing list