def test_22_language_wildcard_alone(self):
     accept = "*"
     server = [
         AcceptParameters(language=Language("no")),
         AcceptParameters(language=Language("de"))
     ]
     cn = ContentNegotiator(acceptable=server)
     ap = cn.negotiate(accept_language=accept)
     assert ap.language == "no"
 def test_24_language_en_plus_wildcard_primary_supported(self):
     accept = "en, *"
     server = [
         AcceptParameters(language=Language("en")),
         AcceptParameters(language=Language("de"))
     ]
     cn = ContentNegotiator(acceptable=server)
     ap = cn.negotiate(accept_language=accept)
     assert ap.language == "en"
 def test_17_language_en_vs_no_vs_de_mixed_q_preferred_available(self):
     accept = "en;q=0.6, no;q=0.9, de"
     server = [
         AcceptParameters(language=Language("no")),
         AcceptParameters(language=Language("de"))
     ]
     cn = ContentNegotiator(acceptable=server)
     ap = cn.negotiate(accept_language=accept)
     assert ap.language == "de"
 def test_13_language_fr_vs_no_with_q(self):
     accept = "fr;q=0.7, no;q=0.8"
     server = [
         AcceptParameters(language=Language("fr")),
         AcceptParameters(language=Language("no"))
     ]
     cn = ContentNegotiator(acceptable=server)
     ap = cn.negotiate(accept_language=accept)
     assert ap.language == "no"
 def test_12_language_en_vs_de_no_q(self):
     accept = "en, de"
     server = [
         AcceptParameters(language=Language("en")),
         AcceptParameters(language=Language("de"))
     ]
     cn = ContentNegotiator(acceptable=server)
     ap = cn.negotiate(accept_language=accept)
     assert ap.language == "en"
 def test_14_language_en_vs_de_vs_fr_mixed_q(self):
     accept = "en;q=0.6, de;q=0.9, fr"
     server = [
         AcceptParameters(language=Language("en")),
         AcceptParameters(language=Language("de")),
         AcceptParameters(language=Language("fr"))
     ]
     cn = ContentNegotiator(acceptable=server)
     ap = cn.negotiate(accept_language=accept)
     assert ap.language == "fr"
 def test_30_content_types_languages(self):
     accept = "text/html, text/plain"
     accept_lang = "en, de"
     server = [
         AcceptParameters(ContentType("text/html"), Language("de")),
         AcceptParameters(ContentType("text/plain"), Language("en"))
     ]
     cn = ContentNegotiator(acceptable=server)
     ap = cn.negotiate(accept=accept, accept_language=accept_lang)
     assert ap.language == "de"
     assert ap.content_type.mimetype() == "text/html"
 def test_20_language_en_gb_supported_by_language_variant(self):
     accept = "en-gb"
     server = [AcceptParameters(language=Language("en"))]
     cn = ContentNegotiator(acceptable=server,
                            ignore_language_variants=True)
     ap = cn.negotiate(accept_language=accept)
     assert ap.language == "en"
 def test_19_language_en_gb_unsupported(self):
     accept = "en-gb"
     server = [AcceptParameters(language=Language("en"))]
     cn = ContentNegotiator(acceptable=server,
                            ignore_language_variants=False)
     ap = cn.negotiate(accept_language=accept)
     assert ap is None
 def test_15_language_en_unsupported(self):
     accept = "en;q=0.6, de;q=0.9, fr"
     accept = "en"
     server = [AcceptParameters(language=Language("de"))]
     cn = ContentNegotiator(acceptable=server)
     ap = cn.negotiate(accept_language=accept)
     assert ap is None
 def test_31_content_types_language_weights(self):
     weights = {
         'content_type': 2.0,
         'language': 1.0,
         'charset': 1.0,
         'encoding': 1.0
     }
     accept = "text/html, text/plain"
     accept_lang = "en"
     server = [
         AcceptParameters(ContentType("text/html"), Language("de")),
         AcceptParameters(ContentType("text/plain"), Language("en"))
     ]
     cn = ContentNegotiator(acceptable=server, weights=weights)
     ap = cn.negotiate(accept=accept, accept_language=accept_lang)
     assert ap.language == "en"
     assert ap.content_type.mimetype() == "text/plain"
 def test_21_language_en_partially_supported(self):
     accept = "en"
     server = [AcceptParameters(language=Language("en-gb"))]
     cn = ContentNegotiator(acceptable=server)
     ap = cn.negotiate(accept_language=accept)
     assert ap.language == "en-gb"
 def test_11_language_en(self):
     accept_language = "en"
     server = [AcceptParameters(language=Language("en"))]
     cn = ContentNegotiator(acceptable=server)
     ap = cn.negotiate(accept_language=accept_language)
     assert ap.language == "en"