mirror of
https://github.com/koxudaxi/datamodel-code-generator.git
synced 2024-03-18 14:54:37 +03:00
25 lines
590 B
Python
25 lines
590 B
Python
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,
|
|
) -> str:
|
|
return httpx.get(
|
|
url, headers=headers, verify=not ignore_tls, follow_redirects=True
|
|
).text
|
|
|
|
|
|
def join_url(url: str, ref: str = '.') -> str:
|
|
return str(httpx.URL(url).join(ref))
|