[PATCH] [utils] Add the possibility to add elements in the head of an UStringIO list

Philippe Pepiot philippe.pepiot at logilab.fr
Tue Feb 11 17:35:48 CET 2020


On 10/02/2020, Guillaume Vandevelde wrote:
> # HG changeset patch
> # User Guillaume Vandevelde <gvandevelde at logilab.fr>
> # Date 1581094414 -3600
> #      Fri Feb 07 17:53:34 2020 +0100
> # Node ID 9d62d9fed7859b47401b88ed27c959a65e190c10
> # Parent  8fa3d2b0252d869ab00f17ea0a6f981d7878f0d2
> [utils] Add the possibility to add elements in the head of an UStringIO list

Like Nicola say, we cannot guess what you're trying to do without a
commit message explaining "why and how".

> 
> diff -r 8fa3d2b0252d -r 9d62d9fed785 cubicweb/utils.py
> --- a/cubicweb/utils.py	Fri Feb 07 17:09:59 2020 +0100
> +++ b/cubicweb/utils.py	Fri Feb 07 17:53:34 2020 +0100
> @@ -181,6 +181,19 @@
>          self._size -= 1
>  
>  
> +def handle_writing_constraints(method):

Always decorate wrapper function with functools.wraps(method). This
copies metadata from decorated function and help debugging.

> +    def wrapper(self, value):
> +        if self.tracewrites:
> +            from traceback import format_stack
> +            stack = format_stack(None)[:-1]
> +            escaped_stack = xml_escape(json_dumps(u'\n'.join(stack)))
> +            escaped_html = xml_escape(value).replace('\n', '<br/>\n')
> +            tpl = u'<span onclick="alert(%s)">%s</span>'
> +            value = tpl % (escaped_stack, escaped_html)
> +        method(self, value)

I'd "return method(self, value)" in case of a decorated function with
return value.

> +    return wrapper



More information about the cubicweb-devel mailing list