• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

deepset-ai / haystack / 16442527952

22 Jul 2025 11:08AM UTC coverage: 90.638% (+0.05%) from 90.588%
16442527952

push

github

web-flow
feat: Add DocumentTypeRouter (#9634)

* Add DocumentTypeRouter

* PR comments

* Turn off isort for one line so pylint will pass

12325 of 13598 relevant lines covered (90.64%)

0.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.76
haystack/utils/misc.py
1
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
2
#
3
# SPDX-License-Identifier: Apache-2.0
4

5
import mimetypes
1✔
6
from pathlib import Path
1✔
7
from typing import Any, List, Optional, Union, overload
1✔
8

9
from numpy import exp, ndarray
1✔
10

11
CUSTOM_MIMETYPES = {
1✔
12
    # we add markdown because it is not added by the mimetypes module
13
    # see https://github.com/python/cpython/pull/17995
14
    ".md": "text/markdown",
15
    ".markdown": "text/markdown",
16
    # we add msg because it is not added by the mimetypes module
17
    ".msg": "application/vnd.ms-outlook",
18
}
19

20

21
def expand_page_range(page_range: List[Union[str, int]]) -> List[int]:
1✔
22
    """
23
    Takes a list of page numbers and ranges and expands them into a list of page numbers.
24

25
    For example, given a page_range=['1-3', '5', '8', '10-12'] the function will return [1, 2, 3, 5, 8, 10, 11, 12]
26

27
    :param page_range: List of page numbers and ranges
28
    :returns:
29
        An expanded list of page integers
30

31
    """
32
    expanded_page_range = []
1✔
33

34
    for page in page_range:
1✔
35
        if isinstance(page, int):
1✔
36
            # check if it's a range wrongly passed as an integer expression
37
            if "-" in str(page):
×
38
                msg = "range must be a string in the format 'start-end'"
×
39
                raise ValueError(f"Invalid page range: {page} - {msg}")
×
40
            expanded_page_range.append(page)
×
41

42
        elif isinstance(page, str) and page.isdigit():
1✔
43
            expanded_page_range.append(int(page))
×
44

45
        elif isinstance(page, str) and "-" in page:
1✔
46
            start, end = page.split("-")
1✔
47
            expanded_page_range.extend(range(int(start), int(end) + 1))
1✔
48

49
        else:
50
            msg = "range must be a string in the format 'start-end' or an integer"
×
51
            raise ValueError(f"Invalid page range: {page} - {msg}")
×
52

53
    if not expanded_page_range:
1✔
54
        raise ValueError("No valid page numbers or ranges found in the input list")
×
55

56
    return expanded_page_range
1✔
57

58

59
@overload
1✔
60
def expit(x: float) -> float: ...
1✔
61
@overload
1✔
62
def expit(x: ndarray[Any, Any]) -> ndarray[Any, Any]: ...
1✔
63
def expit(x: Union[float, ndarray[Any, Any]]) -> Union[float, ndarray[Any, Any]]:
1✔
64
    """
65
    Compute logistic sigmoid function. Maps input values to a range between 0 and 1
66

67
    :param x: input value. Can be a scalar or a numpy array.
68
    """
69
    return 1 / (1 + exp(-x))
1✔
70

71

72
def _guess_mime_type(path: Path) -> Optional[str]:
1✔
73
    """
74
    Guess the MIME type of the provided file path.
75

76
    :param path: The file path to get the MIME type for.
77

78
    :returns: The MIME type of the provided file path, or `None` if the MIME type cannot be determined.
79
    """
80
    extension = path.suffix.lower()
1✔
81
    mime_type = mimetypes.guess_type(path.as_posix())[0]
1✔
82
    # lookup custom mappings if the mime type is not found
83
    return CUSTOM_MIMETYPES.get(extension, mime_type)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc