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

collective / sphinxcontrib-httpexample / 14160435020

30 Mar 2025 10:10PM UTC coverage: 96.087% (+2.1%) from 94.03%
14160435020

push

github

datakurre
Add support for custom builders

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%)

2.88 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
3✔
3
from importlib import resources
3✔
4
from urllib.parse import parse_qsl
3✔
5
from urllib.parse import ParseResult
3✔
6
from urllib.parse import unquote
3✔
7
from urllib.parse import urlencode
3✔
8
from urllib.parse import urlparse
3✔
9
import os
3✔
10

11

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

17

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

29

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

43

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

54

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

58

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

62

63
def is_json(content_type):
3✔
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(";")}
3✔
72
    if "application/json" in parts:
3✔
73
        return True
3✔
74

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

79
    return False
3✔
80

81

82
def add_url_params(url, params):
3✔
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)
3✔
95
    parsed_url = urlparse(url)
3✔
96
    new_params = parse_qsl(parsed_url.query) + params
3✔
97
    new_params_encoded = urlencode(new_params, doseq=True)
3✔
98
    new_url = ParseResult(
3✔
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
3✔
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