def holster_url_value_preprocessor(endpoint, values): """ Figure out which MIME type should be returned, and prepare the value for later processing. """ # Check to see if this has already happened, e.g. in a blueprint. if hasattr(g, "_holster_mime"): return accept = request.accept_mimetypes # If the file extension was in there, then prefer a type based on the # extension. if values and "ext" in values: ext = values.pop("ext") accept = preferring(guess_type(ext), accept) g._holster_mime = accept
def test_preferring_ahead(self): t = "text/plain" a = MIMEAccept([("text/plain", 1), ("text/xml", 1)]) a = preferring(t, a) self.assertEqual(a.best, t)
def test_preferring_new(self): t = "text/plain" a = MIMEAccept([("text/xml", 1), ("image/png", 0.9)]) a = preferring(t, a) self.assertEqual(a.best, t)
def test_preferring_quality_behind(self): t = "text/plain" a = MIMEAccept([("text/xml", 1), ("text/plain", 0.9)]) a = preferring(t, a) self.assertEqual(a.best, t)