Skip to content

Commit fea7f61

Browse files
committed
update impit to 0.7.3
1 parent 10d6b7b commit fea7f61

File tree

17 files changed

+72
-87
lines changed

17 files changed

+72
-87
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ keywords = ["apify", "api", "client", "automation", "crawling", "scraping"]
2626
dependencies = [
2727
"apify-shared>=2.1.0,<3.0.0",
2828
"colorama>=0.4.0",
29-
"impit>=0.5.3",
29+
"impit>=0.7.3",
3030
"more_itertools>=10.0.0",
3131
]
3232

src/apify_client/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def maybe_parse_response(response: Response) -> Any:
262262

263263
try:
264264
if is_content_type_json(content_type):
265-
response_data = jsonlib.loads(response.text)
265+
response_data = response.json()
266266
elif is_content_type_xml(content_type) or is_content_type_text(content_type):
267267
response_data = response.text
268268
else:

src/apify_client/clients/base/actor_job_base_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import asyncio
4-
import json as jsonlib
54
import math
65
import time
76
from datetime import datetime, timezone
@@ -38,7 +37,7 @@ def _wait_for_finish(self, wait_secs: int | None = None) -> dict | None:
3837
method='GET',
3938
params=self._params(waitForFinish=wait_for_finish),
4039
)
41-
job = parse_date_fields(pluck_data(jsonlib.loads(response.text)))
40+
job = parse_date_fields(pluck_data(response.json()))
4241

4342
seconds_elapsed = math.floor((datetime.now(timezone.utc) - started_at).total_seconds())
4443
if ActorJobStatus(job['status']).is_terminal or (
@@ -69,7 +68,7 @@ def _abort(self, *, gracefully: bool | None = None) -> dict:
6968
method='POST',
7069
params=self._params(gracefully=gracefully),
7170
)
72-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
71+
return parse_date_fields(pluck_data(response.json()))
7372

7473

7574
class ActorJobBaseClientAsync(ResourceClientAsync):
@@ -92,7 +91,7 @@ async def _wait_for_finish(self, wait_secs: int | None = None) -> dict | None:
9291
method='GET',
9392
params=self._params(waitForFinish=wait_for_finish),
9493
)
95-
job = parse_date_fields(pluck_data(jsonlib.loads(response.text)))
94+
job = parse_date_fields(pluck_data(response.json()))
9695

9796
seconds_elapsed = math.floor((datetime.now(timezone.utc) - started_at).total_seconds())
9897
if ActorJobStatus(job['status']).is_terminal or (
@@ -123,4 +122,4 @@ async def _abort(self, *, gracefully: bool | None = None) -> dict:
123122
method='POST',
124123
params=self._params(gracefully=gracefully),
125124
)
126-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
125+
return parse_date_fields(pluck_data(response.json()))

src/apify_client/clients/base/resource_client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
import json as jsonlib
4-
53
from apify_client._utils import catch_not_found_or_throw, parse_date_fields, pluck_data
64
from apify_client.clients.base.base_client import BaseClient, BaseClientAsync
75
from apify_client.errors import ApifyApiError
@@ -19,7 +17,7 @@ def _get(self, timeout_secs: int | None = None) -> dict | None:
1917
timeout_secs=timeout_secs,
2018
)
2119

22-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
20+
return parse_date_fields(pluck_data(response.json()))
2321

2422
except ApifyApiError as exc:
2523
catch_not_found_or_throw(exc)
@@ -35,7 +33,7 @@ def _update(self, updated_fields: dict, timeout_secs: int | None = None) -> dict
3533
timeout_secs=timeout_secs,
3634
)
3735

38-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
36+
return parse_date_fields(pluck_data(response.json()))
3937

4038
def _delete(self, timeout_secs: int | None = None) -> None:
4139
try:
@@ -62,7 +60,7 @@ async def _get(self, timeout_secs: int | None = None) -> dict | None:
6260
timeout_secs=timeout_secs,
6361
)
6462

65-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
63+
return parse_date_fields(pluck_data(response.json()))
6664

6765
except ApifyApiError as exc:
6866
catch_not_found_or_throw(exc)
@@ -78,7 +76,7 @@ async def _update(self, updated_fields: dict, timeout_secs: int | None = None) -
7876
timeout_secs=timeout_secs,
7977
)
8078

81-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
79+
return parse_date_fields(pluck_data(response.json()))
8280

8381
async def _delete(self, timeout_secs: int | None = None) -> None:
8482
try:

src/apify_client/clients/base/resource_collection_client.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import json as jsonlib
43
from typing import Any, Generic, TypeVar
54

65
from apify_client._utils import parse_date_fields, pluck_data
@@ -50,7 +49,7 @@ def _list(self, **kwargs: Any) -> ListPage:
5049
params=self._params(**kwargs),
5150
)
5251

53-
return ListPage(parse_date_fields(pluck_data(jsonlib.loads(response.text))))
52+
return ListPage(parse_date_fields(pluck_data(response.json())))
5453

5554
def _create(self, resource: dict) -> dict:
5655
response = self.http_client.call(
@@ -60,7 +59,7 @@ def _create(self, resource: dict) -> dict:
6059
json=resource,
6160
)
6261

63-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
62+
return parse_date_fields(pluck_data(response.json()))
6463

6564
def _get_or_create(self, name: str | None = None, resource: dict | None = None) -> dict:
6665
response = self.http_client.call(
@@ -70,7 +69,7 @@ def _get_or_create(self, name: str | None = None, resource: dict | None = None)
7069
json=resource,
7170
)
7271

73-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
72+
return parse_date_fields(pluck_data(response.json()))
7473

7574

7675
class ResourceCollectionClientAsync(BaseClientAsync):
@@ -83,7 +82,7 @@ async def _list(self, **kwargs: Any) -> ListPage:
8382
params=self._params(**kwargs),
8483
)
8584

86-
return ListPage(parse_date_fields(pluck_data(jsonlib.loads(response.text))))
85+
return ListPage(parse_date_fields(pluck_data(response.json())))
8786

8887
async def _create(self, resource: dict) -> dict:
8988
response = await self.http_client.call(
@@ -93,7 +92,7 @@ async def _create(self, resource: dict) -> dict:
9392
json=resource,
9493
)
9594

96-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
95+
return parse_date_fields(pluck_data(response.json()))
9796

9897
async def _get_or_create(
9998
self,
@@ -107,4 +106,4 @@ async def _get_or_create(
107106
json=resource,
108107
)
109108

110-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
109+
return parse_date_fields(pluck_data(response.json()))

src/apify_client/clients/resource_clients/actor.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import json as jsonlib
43
from typing import TYPE_CHECKING, Any, Literal
54

65
from apify_client._utils import (
@@ -286,7 +285,7 @@ def start(
286285
params=request_params,
287286
)
288287

289-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
288+
return parse_date_fields(pluck_data(response.json()))
290289

291290
def call(
292291
self,
@@ -404,7 +403,7 @@ def build(
404403
params=request_params,
405404
)
406405

407-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
406+
return parse_date_fields(pluck_data(response.json()))
408407

409408
def builds(self) -> BuildCollectionClient:
410409
"""Retrieve a client for the builds of this Actor."""
@@ -435,7 +434,7 @@ async def default_build(
435434
)
436435

437436
response = self.http_client.call(url=self._url('builds/default'), method='GET', params=request_params)
438-
data = pluck_data(jsonlib.loads(response.text))
437+
data = pluck_data(response.json())
439438

440439
return BuildClient(
441440
base_url=self.base_url,
@@ -706,7 +705,7 @@ async def start(
706705
params=request_params,
707706
)
708707

709-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
708+
return parse_date_fields(pluck_data(response.json()))
710709

711710
async def call(
712711
self,
@@ -828,7 +827,7 @@ async def build(
828827
params=request_params,
829828
)
830829

831-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
830+
return parse_date_fields(pluck_data(response.json()))
832831

833832
def builds(self) -> BuildCollectionClientAsync:
834833
"""Retrieve a client for the builds of this Actor."""
@@ -863,7 +862,7 @@ async def default_build(
863862
method='GET',
864863
params=request_params,
865864
)
866-
data = pluck_data(jsonlib.loads(response.text))
865+
data = pluck_data(response.json())
867866

868867
return BuildClientAsync(
869868
base_url=self.base_url,

src/apify_client/clients/resource_clients/build.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import json as jsonlib
43
from typing import Any
54

65
from apify_client.clients.base import ActorJobBaseClient, ActorJobBaseClientAsync
@@ -54,7 +53,7 @@ def get_open_api_definition(self) -> dict | None:
5453
method='GET',
5554
)
5655

57-
response_data: dict = jsonlib.loads(response.text)
56+
response_data: dict = response.json()
5857

5958
return response_data
6059

@@ -130,7 +129,7 @@ async def get_open_api_definition(self) -> dict | None:
130129
method='GET',
131130
)
132131

133-
response_data: dict = jsonlib.loads(response.text)
132+
response_data: dict = response.json()
134133

135134
return response_data
136135

src/apify_client/clients/resource_clients/dataset.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import json as jsonlib
43
import warnings
54
from contextlib import asynccontextmanager, contextmanager
65
from typing import TYPE_CHECKING, Any
@@ -141,7 +140,7 @@ def list_items(
141140
params=request_params,
142141
)
143142

144-
data = jsonlib.loads(response.text)
143+
data = response.json()
145144

146145
return ListPage(
147146
{
@@ -559,7 +558,7 @@ def get_statistics(self) -> dict | None:
559558
params=self._params(),
560559
timeout_secs=_SMALL_TIMEOUT,
561560
)
562-
return pluck_data(jsonlib.loads(response.text))
561+
return pluck_data(response.json())
563562
except ApifyApiError as exc:
564563
catch_not_found_or_throw(exc)
565564

@@ -739,7 +738,7 @@ async def list_items(
739738
params=request_params,
740739
)
741740

742-
data = jsonlib.loads(response.text)
741+
data = response.json()
743742

744743
return ListPage(
745744
{
@@ -1066,7 +1065,7 @@ async def get_statistics(self) -> dict | None:
10661065
params=self._params(),
10671066
timeout_secs=_SMALL_TIMEOUT,
10681067
)
1069-
return pluck_data(jsonlib.loads(response.text))
1068+
return pluck_data(response.json())
10701069
except ApifyApiError as exc:
10711070
catch_not_found_or_throw(exc)
10721071

src/apify_client/clients/resource_clients/key_value_store.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import json as jsonlib
43
from contextlib import asynccontextmanager, contextmanager
54
from http import HTTPStatus
65
from typing import TYPE_CHECKING, Any
@@ -106,7 +105,7 @@ def list_keys(
106105
timeout_secs=_MEDIUM_TIMEOUT,
107106
)
108107

109-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
108+
return parse_date_fields(pluck_data(response.json()))
110109

111110
def get_record(self, key: str) -> dict | None:
112111
"""Retrieve the given record from the key-value store.
@@ -424,7 +423,7 @@ async def list_keys(
424423
timeout_secs=_MEDIUM_TIMEOUT,
425424
)
426425

427-
return parse_date_fields(pluck_data(jsonlib.loads(response.text)))
426+
return parse_date_fields(pluck_data(response.json()))
428427

429428
async def get_record(self, key: str) -> dict | None:
430429
"""Retrieve the given record from the key-value store.

0 commit comments

Comments
 (0)