def test_03_content_type_only_xml_vs_rdf_with_q(self): accept = "application/atom+xml;q=0.6, application/rdf+xml;q=0.9" server = [ AcceptParameters(ContentType("application/rdf+xml")), AcceptParameters(ContentType("application/atom+xml")) ] cn = ContentNegotiator(acceptable=server) ap = cn.negotiate(accept=accept) assert ap.content_type.mimetype() == "application/rdf+xml"
def test_10_content_type_full_wildcard(self): accept = "*/*" server = [ AcceptParameters(ContentType("text/plain")), AcceptParameters(ContentType("image/png")), AcceptParameters(ContentType("image/jpeg")) ] cn = ContentNegotiator(acceptable=server) ap = cn.negotiate(accept=accept) assert ap.content_type.mimetype() == "text/plain"
def test_07_content_type_only_atom_vs_rdf_html_mixed_q_preferred_available( self): accept = "application/atom+xml;q=0.6, application/rdf+xml;q=0.9, text/html" server = [ AcceptParameters(ContentType("application/rdf+xml")), AcceptParameters(ContentType("text/html")) ] cn = ContentNegotiator(acceptable=server) ap = cn.negotiate(accept=accept) assert ap.content_type.mimetype() == "text/html"
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_34_content_types_packaging_weights(self): weights = {'content_type': 2.0, 'packaging': 0.5} accept = "application/zip, application/tar" accept_packaging = "packaging:BagIt" server = [ AcceptParameters(ContentType("application/tar"), packaging=accept_packaging), AcceptParameters(ContentType("application/zip"), packaging="http://other/") ] cn = ContentNegotiator(acceptable=server) ap = cn.negotiate(accept=accept, accept_packaging=accept_packaging) assert ap.content_type.mimetype() == "application/tar" assert ap.packaging == "packaging:BagIt"
def test_08_content_type_with_param_supported(self): accept = "application/atom+xml;type=feed" server = [ AcceptParameters(ContentType("application/atom+xml;type=feed")) ] cn = ContentNegotiator(acceptable=server) ap = cn.negotiate(accept=accept) assert ap.content_type.mimetype() == "application/atom+xml;type=feed"
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_33_content_types_packaging(self): accept = "application/zip, application/tar" accept_packaging = "packaging:BagIt" server = [ AcceptParameters(ContentType("application/tar"), packaging=accept_packaging) ] cn = ContentNegotiator(acceptable=server) ap = cn.negotiate(accept=accept, accept_packaging=accept_packaging) assert ap.content_type.mimetype() == "application/tar" assert ap.packaging == "packaging:BagIt"
def interpret_path(self, path): accept_parameters = None silo = None dataset = None # first figure out the accept parameters from the path suffix and chomp # the path down to size if path.endswith("rdf"): accept_parameters = AcceptParameters( ContentType("application/rdf+xml")) path = path[:-4] elif path.endswith("atom"): accept_parameters = AcceptParameters( ContentType("application/atom+xml;type=feed")) path = path[:-5] # check to see if this has a / separator if "/" in path: # deconstruct the path into silo/dataset (if possible) silo, dataset_id = path.split("/", 1) else: silo = path return silo, dataset_id, accept_parameters
def test_05_content_type_only_text_plain_unsupported(self): accept = "text/plain" server = [AcceptParameters(ContentType("text/html"))] cn = ContentNegotiator(acceptable=server) ap = cn.negotiate(accept=accept) assert ap is None
def test_01_content_type_only_text_plain(self): accept = "text/plain" server = [AcceptParameters(ContentType("text/plain"))] cn = ContentNegotiator(acceptable=server) ap = cn.negotiate(accept=accept) assert ap.content_type.mimetype() == "text/plain"