Skip to content

intel

dandy.http.intelligence.intel

HttpResponseIntel

Bases: BaseIntel

status_code instance-attribute

reason = None class-attribute instance-attribute

text = None class-attribute instance-attribute

json_data = None class-attribute instance-attribute

json_str property

from_requests_response classmethod

Source code in dandy/http/intelligence/intel.py
@classmethod
def from_requests_response(cls, requests_response: requests.Response) -> Self:
    try:
        json_data = requests_response.json()
    except ValueError:
        json_data = {}

    return HttpResponseIntel(
        status_code=requests_response.status_code,
        reason=requests_response.reason,
        text=requests_response.text,
        json_data=json_data
    )

HttpRequestIntel

Bases: BaseIntel

method instance-attribute

url instance-attribute

params = None class-attribute instance-attribute

headers = None class-attribute instance-attribute

cookies = None class-attribute instance-attribute

data = None class-attribute instance-attribute

files = None class-attribute instance-attribute

json_data = None class-attribute instance-attribute

bearer_token = None class-attribute instance-attribute

json_str property

model_post_init

Source code in dandy/http/intelligence/intel.py
def model_post_init(self, __context: Any, /):
    self.generate_headers()

as_requests_request

Source code in dandy/http/intelligence/intel.py
def as_requests_request(self) -> requests.Request:
    if isinstance(self.url, Url):
        self.url = self.url.to_str()

    return requests.Request(
        method=self.method,
        url=self.url,
        params=self.params,
        headers=self.headers,
        cookies=self.cookies,
        data=self.data,
        files=self.files,
        json=self.json_data,
    )

to_http_response_intel

Source code in dandy/http/intelligence/intel.py
def to_http_response_intel(self) -> HttpResponseIntel:
    url = self.url.to_str() if isinstance(self.url, Url) else self.url

    response = requests.request(
        method=self.method,
        url=url,
        headers=self.headers,
        json=self.json_data,
        timeout=settings.HTTP_CONNECTION_TIMEOUT_SECONDS,
    )

    return HttpResponseIntel.from_requests_response(response)

generate_headers

Source code in dandy/http/intelligence/intel.py
def generate_headers(self):
    if self.bearer_token is not None:
        if self.headers is None:
            self.headers = {}

        self.headers['Authorization'] = f'Bearer {self.bearer_token}'