Skip to content

Commit

Permalink
Rename SavedResponseData to _SavedResponseData.
Browse files Browse the repository at this point in the history
  • Loading branch information
wRAR committed Feb 15, 2023
1 parent 95d5069 commit 89d8da6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from web_poet import HttpClient, HttpRequest, HttpResponse, WebPage
from web_poet.exceptions import HttpResponseError
from web_poet.page_inputs.client import SavedResponseData
from web_poet.page_inputs.client import _SavedResponseData
from web_poet.testing import Fixture
from web_poet.testing.fixture import INPUT_DIR_NAME, META_FILE_NAME, OUTPUT_FILE_NAME
from web_poet.utils import get_fq_class_name
Expand Down Expand Up @@ -266,8 +266,8 @@ def test_httpclient(pytester, book_list_html_response) -> None:
request2 = HttpRequest(url2, method="POST", body=b"post")
response2 = HttpResponse(url=url2, body=b"body2", encoding="utf-8")
responses = [
SavedResponseData(request1, response1),
SavedResponseData(request2, response2),
_SavedResponseData(request1, response1),
_SavedResponseData(request2, response2),
]
client = HttpClient(responses=responses)

Expand All @@ -294,7 +294,7 @@ def test_httpclient_no_response(pytester, book_list_html_response) -> None:
request = HttpRequest(url)
response = HttpResponse(url=url, body=b"body1", encoding="utf-8")
responses = [
SavedResponseData(request, response),
_SavedResponseData(request, response),
]
client = HttpClient(responses=responses)

Expand Down Expand Up @@ -330,7 +330,7 @@ def test_httpclient_exception(pytester, book_list_html_response) -> None:
request = HttpRequest(url)
response = HttpResponse(url=url, body=b"body1", status=404, encoding="utf-8")
responses = [
SavedResponseData(request, response),
_SavedResponseData(request, response),
]
client = HttpClient(responses=responses)

Expand Down
10 changes: 5 additions & 5 deletions web_poet/page_inputs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


@dataclass
class SavedResponseData:
class _SavedResponseData:
"""Class for storing a request and its result."""

request: HttpRequest
Expand Down Expand Up @@ -60,12 +60,12 @@ def __init__(
*,
save_responses: bool = False,
return_only_saved_responses: bool = False,
responses: Optional[Iterable[SavedResponseData]] = None,
responses: Optional[Iterable[_SavedResponseData]] = None,
):
self._request_downloader = request_downloader or _perform_request
self.save_responses = save_responses
self.return_only_saved_responses = return_only_saved_responses
self._saved_responses: Dict[str, SavedResponseData] = {
self._saved_responses: Dict[str, _SavedResponseData] = {
data.fingerprint(): data for data in responses or []
}

Expand Down Expand Up @@ -205,7 +205,7 @@ async def execute(

response = await self._request_downloader(request)
if self.save_responses:
self._saved_responses[request_fingerprint(request)] = SavedResponseData(
self._saved_responses[request_fingerprint(request)] = _SavedResponseData(
request, response
)
self._handle_status(response, request, allow_status=allow_status)
Expand Down Expand Up @@ -250,6 +250,6 @@ async def batch_execute(
)
return responses

def get_saved_responses(self) -> Iterable[SavedResponseData]:
def get_saved_responses(self) -> Iterable[_SavedResponseData]:
"""Return saved requests and responses."""
return self._saved_responses.values()
6 changes: 3 additions & 3 deletions web_poet/serialization/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict, List, Type

from .. import HttpClient, HttpRequest, HttpRequestBody, HttpResponse, HttpResponseBody
from ..page_inputs.client import SavedResponseData
from ..page_inputs.client import _SavedResponseData
from ..page_inputs.url import _Url
from .api import (
SerializedLeafData,
Expand Down Expand Up @@ -115,7 +115,7 @@ def _serialize_HttpClient(o: HttpClient) -> SerializedLeafData:
def _deserialize_HttpClient(
cls: Type[HttpClient], data: SerializedLeafData
) -> HttpClient:
responses: List[SavedResponseData] = []
responses: List[_SavedResponseData] = []

serialized_requests: Dict[str, SerializedLeafData] = {}
serialized_responses: Dict[str, SerializedLeafData] = {}
Expand All @@ -134,7 +134,7 @@ def _deserialize_HttpClient(
continue
request = deserialize_leaf(HttpRequest, serialized_request)
response = deserialize_leaf(HttpResponse, serialized_response)
responses.append(SavedResponseData(request, response))
responses.append(_SavedResponseData(request, response))

return cls(return_only_saved_responses=True, responses=responses)

Expand Down

0 comments on commit 89d8da6

Please sign in to comment.