[web] Add asserts to the raw header conversion functions

This API is terrible, but at least this might help us catch some errors in our conversion definitions.

authorJulien Cristau <julien.cristau@logilab.fr>
changeset8905267dc7ae
branchdefault
phasepublic
hiddenno
parent revision#2614362be11e [view] Delete dead(?) code from ReloadableMixIn
child revision#33f6ad4c75a5 [web/ajax] don't override any status code with 500 in ajax_error_handler
files modified by this revision
web/http_headers.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1394791888 -3600
# Fri Mar 14 11:11:28 2014 +0100
# Node ID 8905267dc7ae05acaeb903f6e009cabd41f27680
# Parent 2614362be11e7faff3639b76240f38b67ff8bc83
[web] Add asserts to the raw header conversion functions

This API is terrible, but at least this might help us catch some errors
in our conversion definitions.

diff --git a/web/http_headers.py b/web/http_headers.py
@@ -1322,10 +1322,13 @@
1 
2      def _toRaw(self, name):
3          h = self._headers.get(name, None)
4          r = self.handler.generate(name, h)
5          if r is not None:
6 +            assert isinstance(r, list)
7 +            for v in r:
8 +                assert isinstance(v, str)
9              self._raw_headers[name] = r
10          return r
11 
12      def __contains__(self, name):
13          """Does a header with the given name exist?"""
@@ -1360,10 +1363,13 @@
14      def setRawHeaders(self, name, value):
15          """Sets the raw representation of the given header.
16          Value should be a list of strings, each being one header of the
17          given name.
18          """
19 +        assert isinstance(value, list)
20 +        for v in value:
21 +            assert isinstance(v, str)
22          name = name.lower()
23          self._raw_headers[name] = value
24          self._headers[name] = _RecalcNeeded
25 
26      def setHeader(self, name, value):