File: response.py

package info (click to toggle)
python-web-poet 0.23.2-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 908 kB
  • sloc: python: 6,112; makefile: 19
file content (31 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (3)
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
30
31
import attrs

from web_poet.mixins import SelectableMixin, UrlShortcutsMixin
from web_poet.page_inputs.browser import BrowserResponse
from web_poet.page_inputs.http import HttpResponse
from web_poet.page_inputs.url import ResponseUrl


@attrs.define
class AnyResponse(SelectableMixin, UrlShortcutsMixin):
    """A container that holds either :class:`~.BrowserResponse` or :class:`~.HttpResponse`."""

    response: BrowserResponse | HttpResponse

    @property
    def url(self) -> ResponseUrl:
        """URL of the response."""
        return self.response.url

    @property
    def text(self) -> str:
        """Text or HTML contents of the response."""
        return self.response.text

    @property
    def status(self) -> int | None:
        """The int status code of the HTTP response, if available."""
        return self.response.status

    def _selector_input(self) -> str:
        return self.text