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

collective / sphinxcontrib-httpexample / 19827076457

01 Dec 2025 03:00PM UTC coverage: 96.087% (+2.1%) from 94.03%
19827076457

Pull #113

github

datakurre
ci: Add Python 312 and Sphinx 9.0.0
Pull Request #113: draft: Python 3 only

144 of 148 new or added lines in 5 files covered. (97.3%)

1 existing line in 1 file now uncovered.

442 of 460 relevant lines covered (96.09%)

0.96 hits per line

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

96.49
/src/sphinxcontrib/httpexample/utils.py
1
# -*- coding: utf-8 -*-
2
from collections import OrderedDict
1✔
3
from importlib import resources
1✔
4
from urllib.parse import parse_qsl
1✔
5
from urllib.parse import ParseResult
1✔
6
from urllib.parse import unquote
1✔
7
from urllib.parse import urlencode
1✔
8
from urllib.parse import urlparse
1✔
9
import os
1✔
10

11

12
def merge_dicts(a, b):
1✔
13
    c = a.copy()
1✔
14
    c.update(b)
1✔
15
    return c
1✔
16

17

18
def resolve_path(spec, cwd=""):
1✔
19
    if os.path.isfile(os.path.normpath(os.path.join(cwd, spec))):
1✔
20
        return os.path.normpath(os.path.join(cwd, spec))
1✔
21
    elif spec.count(":"):
1✔
22
        package, resource = spec.split(":", 1)
1✔
23
        resource_path = resources.files(package) / resource
1✔
24
        if resource_path.exists():
1✔
25
            return str(resource_path)
1✔
26
    else:
27
        return spec
1✔
28

29

30
def maybe_str(v):
1✔
31
    """Convert any strings to local 'str' instances"""
32
    if isinstance(v, str) and isinstance(v, bytes):
1✔
33
        return v  # Python 2 encoded
×
34
    elif str(type(v)) == "<type 'unicode'>":
1✔
NEW
35
        return v.encode("utf-8")  # Python 2 unicode
×
36
    elif isinstance(v, bytes):
1✔
37
        return v.decode("utf-8")  # Python 3 encoded
1✔
38
    elif isinstance(v, str):
1✔
39
        return v  # Python 3 unicode
1✔
40
    else:
41
        return v  # not a string
1✔
42

43

44
def ordered(dict_):
1✔
45
    if isinstance(dict_, dict):
1✔
46
        # http://stackoverflow.com/a/22721724
47
        results = OrderedDict()
1✔
48
        for k, v in sorted(dict_.items()):
1✔
49
            results[k] = ordered(v)
1✔
50
    else:
51
        results = dict_
1✔
52
    return results
1✔
53

54

55
def capitalize(s):
1✔
56
    return "-".join(map(str.capitalize, s.split("-")))
1✔
57

58

59
def capitalize_keys(d):
1✔
60
    return dict([(capitalize(k), v) for k, v in d.items()])
1✔
61

62

63
def is_json(content_type):
1✔
64
    """Checks if the given content type should be treated as JSON.
65

66
    The primary use cases to be recognized as JSON are
67

68
    - `application/json` mimetype
69
    - `+json` structured syntax suffix
70
    """
71
    parts = {part.strip() for part in content_type.lower().strip().split(";")}
1✔
72
    if "application/json" in parts:
1✔
73
        return True
1✔
74

75
    for p in parts:
1✔
76
        if p.endswith("+json"):
1✔
77
            return True
1✔
78

79
    return False
1✔
80

81

82
def add_url_params(url, params):
1✔
83
    """Add GET query parameters to provided URL.
84

85
    https://stackoverflow.com/a/25580545/1262843
86

87
    Args:
88
        url (str): target URL
89
        params (list of tuples): query parameters to be added
90

91
    Returns:
92
        new_url (str): updated URL
93
    """
94
    url = unquote(url)
1✔
95
    parsed_url = urlparse(url)
1✔
96
    new_params = parse_qsl(parsed_url.query) + params
1✔
97
    new_params_encoded = urlencode(new_params, doseq=True)
1✔
98
    new_url = ParseResult(
1✔
99
        parsed_url.scheme,
100
        parsed_url.netloc,
101
        parsed_url.path,
102
        parsed_url.params,
103
        new_params_encoded,
104
        parsed_url.fragment,
105
    ).geturl()
106

107
    return new_url
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