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
|