def __init__(self, response=None, status=200, headers=None, mimetype=None, content_type=None): """ Response can be any kind of iterable or string. If it's a string it's considered being an iterable with one item which is the string passed. headers can be a list of tuples or a `Headers` object. Special note for `mimetype` and `content_type`. For most mime types `mimetype` and `content_type` work the same, the difference affects only 'text' mimetypes. If the mimetype passed with `mimetype` is a mimetype starting with `text/` it becomes a charset parameter defined with the charset of the response object. In constrast the `content_type` parameter is always added as header unmodified. """ if response is None: self.response = [] elif isinstance(response, basestring): self.response = [response] else: self.response = iter(response) if not headers: self.headers = Headers() elif isinstance(headers, Headers): self.headers = headers else: self.headers = Headers(headers) if content_type is None: if mimetype is None and 'Content-Type' not in self.headers: mimetype = self.default_mimetype if mimetype is not None and mimetype.startswith('text/'): mimetype += '; charset=' + self.charset content_type = mimetype if content_type is not None: self.headers['Content-Type'] = content_type if isinstance(status, (int, long)): self.status_code = status else: self.status = status