def get_best_handler(cls, mimetype): """Return the Review UI and score that that best fit the mimetype. Args: mimetype (unicode): The mimetype to find a Review UI for. Returns: tuple: A tuple of ``(best_score, review_ui)``, or ``(0, None)`` if one could not be found. """ best_score = 0 best_fit = None for review_ui in _file_attachment_review_uis: for mt in review_ui.supported_mimetypes: try: score = score_match(mimeparse.parse_mime_type(mt), mimetype) if score > best_score: best_score = score best_fit = review_ui except ValueError: continue return best_score, best_fit
def get_best_handler(cls, mimetype): """Return the Review UI and score that that best fit the mimetype. Args: mimetype (unicode): The mimetype to find a Review UI for. Returns: tuple: A tuple of ``(best_score, review_ui)``, or ``(0, None)`` if one could not be found. """ best_score = 0 best_fit = None for review_ui in _file_attachment_review_uis: for mt in review_ui.supported_mimetypes: try: score = score_match(mimeparse.parse_mime_type(mt), mimetype) if score > best_score: best_score = score best_fit = review_ui except ValueError: continue return best_score, best_fit
def get_best_handler(cls, mimetype): """Return the Review UI and score that that best fit the mimetype. Args: mimetype (tuple): A parsed mimetype to find the best review UI for. This is a 3-tuple of the type, subtype, and parameters as returned by :py:func:`mimeparse.parse_mime_type`. Returns: tuple: A tuple of ``(best_score, review_ui)``, or ``(0, None)`` if one could not be found. """ best_score = 0 best_fit = None for review_ui in _file_attachment_review_uis: for mt in review_ui.supported_mimetypes: try: score = score_match(mimeparse.parse_mime_type(mt), mimetype) if score > best_score: best_score = score best_fit = review_ui except ValueError: continue return best_score, best_fit
def get_best_handler(cls, mimetype): """Returns the handler and score that that best fit the mimetype.""" best_score = 0 best_fit = None for review_ui in _file_attachment_review_uis: for mt in review_ui.supported_mimetypes: try: score = score_match(mimeparse.parse_mime_type(mt), mimetype) if score > best_score: best_score = score best_fit = review_ui except ValueError: continue return best_score, best_fit
def get_best_handler(cls, mimetype): """Returns the handler and score that that best fit the mimetype.""" best_score = 0 best_fit = None for review_ui in _file_attachment_review_uis: for mt in review_ui.supported_mimetypes: try: score = score_match(mimeparse.parse_mime_type(mt), mimetype) if score > best_score: best_score = score best_fit = review_ui except ValueError: continue return best_score, best_fit
def get_best_handler(cls, mimetype): """Returns the handler and score that that best fit the mimetype.""" best_score, best_fit = (0, None) for mt in cls.supported_mimetypes: try: score = score_match(mimeparse.parse_mime_type(mt), mimetype) if score > best_score: best_score, best_fit = (score, cls) except ValueError: continue for handler in cls.__subclasses__(): score, best_handler = handler.get_best_handler(mimetype) if score > best_score: best_score, best_fit = (score, best_handler) return (best_score, best_fit)
def assert_score(pattern, test, score): self.assertAlmostEqual( score_match(mimeparse.parse_mime_type(pattern), mimeparse.parse_mime_type(test)), score)
def assert_score(pattern, test, score): self.assertAlmostEqual( score_match(mimeparse.parse_mime_type(pattern), mimeparse.parse_mime_type(test)), score)