def check_expected(request): if status is not None: self.assertEqual(request.code, status) if content is not None: self.assertEqual(request.content.getvalue(), content) if (mime is not None) or (encoding is not None): content_type = http.DEFAULT_MIMETYPE charset = compat.http2python(http.DEFAULT_ENCODING) if "content-type" in request.response_headers: header = request.response_headers["content-type"] content_type, charset = http.parse_content_type(header) if mime is not None: self.assertEqual(content_type, mime) if encoding is not None: self.assertEqual(charset, encoding) if language is not None: content_language = http.DEFAULT_LANGUAGE if "content-language" in request.response_headers: header = request.response_headers["content-language"] content_language = header self.assertEqual(content_language, language) if allowed_encodings is not None: self.assertTrue("allow-charset" in request.response_headers) header = request.response_headers["allow-charset"] values = [e.strip() for e in header.split(",")] self.assertEqual(tuple(values), allowed_encodings) if allowed_languages is not None: self.assertTrue("allow-language" in request.response_headers) header = request.response_headers["allow-language"] values = [e.strip() for e in header.split(",")] self.assertEqual(tuple(values), allowed_languages) if allowed_methods is not None: self.assertTrue("allow" in request.response_headers) header = request.response_headers["allow"] values = [e.strip() for e in header.split(",")] self.assertEqual(tuple(values), allowed_methods) if www_auth is not None: self.assertTrue("www-authenticate" in request.response_headers) header = request.response_headers["www-authenticate"] self.assertEqual(header, www_auth) if location is not None: self.assertTrue("location" in request.response_headers) header = request.response_headers["location"] self.assertEqual(header, location)
def parse_accepted_charset(value): type, params = _split_http_definition(value) if type: type = compat.http2python(type) priority = float(params.get("q", DEFAULT_PRIORITY)) return type, priority
def parse_content_type(value): type, params = _split_http_definition(value) charset = params.get("charset", DEFAULT_ENCODING) type = type or DEFAULT_MIMETYPE return type, compat.http2python(charset)