Skip to content

Commit

Permalink
Fix generic types.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalkrupinski committed Aug 25, 2024
1 parent 68e04f3 commit 886ad08
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions mimeparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__license__ = 'MIT License'
__credits__ = ''

from collections.abc import Generator, Iterable
from typing import Dict, Generator, Iterable, Tuple


class MimeTypeParseException(ValueError):
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 886ad08

Please sign in to comment.