Ticket #2489: HttpResponse_headers.patch
File HttpResponse_headers.patch, 1.6 KB (added by , 18 years ago) |
---|
-
__init__.py
166 166 else: 167 167 self._iterator = [content] 168 168 self._is_string = True 169 self. headers = {'Content-Type': mimetype}169 self._headers = {'Content-Type': mimetype} 170 170 self.cookies = SimpleCookie() 171 171 self.status_code = 200 172 172 … … 177 177 + '\n\n' + self.content 178 178 179 179 def __setitem__(self, header, value): 180 self. headers[header] = value180 self._headers[header] = value 181 181 182 182 def __delitem__(self, header): 183 183 try: 184 del self. headers[header]184 del self._headers[header] 185 185 except KeyError: 186 186 pass 187 187 188 188 def __getitem__(self, header): 189 return self.headers[header] 189 value = self._headers[header] 190 if isinstance(value, unicode): 191 value = value.encode(self._charset) 190 192 193 return value 194 195 def _get_headers(self): 196 headers = {} 197 for key, value in self._headers.items(): 198 if isinstance(value, unicode): 199 headers[key] = value.encode(self._charset) 200 else: 201 headers[key] = value 202 203 return headers 204 205 headers = property(_get_headers) 206 191 207 def has_header(self, header): 192 208 "Case-insensitive check for a header" 193 209 header = header.lower() 194 for key in self. headers.keys():210 for key in self._headers.keys(): 195 211 if key.lower() == header: 196 212 return True 197 213 return False