From 886ad08b50be8df19b1583e38746abfc522e9d43 Mon Sep 17 00:00:00 2001 From: Raphael Krupinski Date: Sun, 25 Aug 2024 16:59:02 +0200 Subject: [PATCH] Fix generic types. --- mimeparse.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mimeparse.py b/mimeparse.py index e579e27..7ba28e3 100644 --- a/mimeparse.py +++ b/mimeparse.py @@ -4,7 +4,7 @@ __license__ = 'MIT License' __credits__ = '' -from collections.abc import Generator, Iterable +from typing import Dict, Generator, Iterable, Tuple class MimeTypeParseException(ValueError): @@ -28,7 +28,7 @@ def _parseparam(s: str) -> Generator[str, None, None]: # Vendored version of cgi.parse_header from Python 3.11 (deprecated and slated # for removal in 3.13) -def _parse_header(line: str) -> tuple[str, dict[str, str]]: +def _parse_header(line: str) -> Tuple[str, Dict[str, str]]: """Parse a Content-type like header. Return the main content-type and a dictionary of options. @@ -49,10 +49,10 @@ def _parse_header(line: str) -> tuple[str, dict[str, str]]: return key, pdict -def parse_mime_type(mime_type: str) -> tuple[str, str, dict[str, str]]: +def parse_mime_type(mime_type: str) -> Tuple[str, str, Dict[str, str]]: """Parses a mime-type into its component parts. - Carves up a mime-type and returns a tuple of the (type, subtype, params) + Carves up a mime-type and returns a Tuple of the (type, subtype, params) where 'params' is a dictionary of all the parameters for the media range. For example, the media range 'application/xhtml;q=0.5' would get parsed into: @@ -75,10 +75,10 @@ def parse_mime_type(mime_type: str) -> tuple[str, str, dict[str, str]]: return (type.strip(), subtype.strip(), params) -def parse_media_range(range: str) -> tuple[str, str, dict[str, str]]: +def parse_media_range(range: str) -> Tuple[str, str, Dict[str, str]]: """Parse a media-range into its component parts. - Carves up a media range and returns a tuple of the (type, subtype, + Carves up a media range and returns a Tuple of the (type, subtype, params) where 'params' is a dictionary of all the parameters for the media range. For example, the media range 'application/*;q=0.5' would get parsed into: @@ -102,12 +102,12 @@ def parse_media_range(range: str) -> tuple[str, str, dict[str, str]]: def quality_and_fitness_parsed( mime_type: str, - parsed_ranges: Iterable[tuple[str, str, dict[str, str]]], -) -> tuple[float, float]: + parsed_ranges: Iterable[Tuple[str, str, Dict[str, str]]], +) -> Tuple[float, float]: """Find the best match for a mime-type amongst parsed media-ranges. Find the best match for a given mime-type against a list of media_ranges - that have already been parsed by parse_media_range(). Returns a tuple of + that have already been parsed by parse_media_range(). Returns a Tuple of the fitness value and the value of the 'q' quality parameter of the best match, or (-1, 0) if no match was found. Just as for quality_parsed(), 'parsed_ranges' must be a list of parsed media ranges. @@ -150,7 +150,7 @@ def quality_and_fitness_parsed( return float(best_fit_q), best_fitness -def quality_parsed(mime_type: str, parsed_ranges: Iterable[tuple[str, str, dict[str, str]]]) -> float: +def quality_parsed(mime_type: str, parsed_ranges: Iterable[Tuple[str, str, Dict[str, str]]]) -> float: """Find the best match for a mime-type amongst parsed media-ranges. Find the best match for a given mime-type against a list of media_ranges