[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>
changeset57dd73194dfe
branchdefault
phasedraft
hiddenyes
parent revision#e8b9a3d23ad9 [web/request] deprecate user_callback
child revision<not specified>
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 57dd73194dfe176d99db22864c9410b697426748
# Parent e8b9a3d23ad93e47391fe566012812245f2a751b
[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
@@ -1285,10 +1285,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?"""
@@ -1323,10 +1326,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):