File: http.py

package info (click to toggle)
python-datamodel-code-generator 0.26.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 712 kB
  • sloc: python: 9,525; makefile: 14
file content (29 lines) | stat: -rw-r--r-- 714 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from __future__ import annotations

from typing import Optional, Sequence, Tuple

try:
    import httpx
except ImportError:  # pragma: no cover
    raise Exception(
        "Please run `$pip install 'datamodel-code-generator[http]`' to resolve URL Reference"
    )


def get_body(
    url: str,
    headers: Optional[Sequence[Tuple[str, str]]] = None,
    ignore_tls: bool = False,
    query_parameters: Optional[Sequence[Tuple[str, str]]] = None,
) -> str:
    return httpx.get(
        url,
        headers=headers,
        verify=not ignore_tls,
        follow_redirects=True,
        params=query_parameters,
    ).text


def join_url(url: str, ref: str = '.') -> str:
    return str(httpx.URL(url).join(ref))