anchorbrowser 0.1.0a3__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. anchorbrowser/__init__.py +3 -1
  2. anchorbrowser/_base_client.py +16 -13
  3. anchorbrowser/_client.py +38 -9
  4. anchorbrowser/_compat.py +48 -48
  5. anchorbrowser/_files.py +4 -4
  6. anchorbrowser/_models.py +54 -45
  7. anchorbrowser/_qs.py +7 -7
  8. anchorbrowser/_types.py +53 -12
  9. anchorbrowser/_utils/__init__.py +9 -2
  10. anchorbrowser/_utils/_compat.py +45 -0
  11. anchorbrowser/_utils/_datetime_parse.py +136 -0
  12. anchorbrowser/_utils/_transform.py +13 -3
  13. anchorbrowser/_utils/_typing.py +6 -1
  14. anchorbrowser/_utils/_utils.py +4 -5
  15. anchorbrowser/_version.py +1 -1
  16. anchorbrowser/lib/browser.py +1 -1
  17. anchorbrowser/resources/__init__.py +42 -0
  18. anchorbrowser/resources/batch_sessions.py +288 -0
  19. anchorbrowser/resources/events.py +270 -0
  20. anchorbrowser/resources/extensions.py +9 -9
  21. anchorbrowser/resources/profiles.py +24 -150
  22. anchorbrowser/resources/sessions/__init__.py +14 -0
  23. anchorbrowser/resources/sessions/agent/__init__.py +33 -0
  24. anchorbrowser/resources/sessions/agent/agent.py +273 -0
  25. anchorbrowser/resources/sessions/agent/files.py +280 -0
  26. anchorbrowser/resources/sessions/all.py +5 -5
  27. anchorbrowser/resources/sessions/clipboard.py +5 -5
  28. anchorbrowser/resources/sessions/keyboard.py +11 -13
  29. anchorbrowser/resources/sessions/mouse.py +12 -244
  30. anchorbrowser/resources/sessions/recordings/primary.py +3 -3
  31. anchorbrowser/resources/sessions/recordings/recordings.py +7 -7
  32. anchorbrowser/resources/sessions/sessions.py +345 -30
  33. anchorbrowser/resources/task/__init__.py +33 -0
  34. anchorbrowser/resources/task/run.py +225 -0
  35. anchorbrowser/resources/task/task.py +358 -0
  36. anchorbrowser/resources/tools.py +107 -37
  37. anchorbrowser/types/__init__.py +14 -1
  38. anchorbrowser/types/batch_session_create_params.py +487 -0
  39. anchorbrowser/types/batch_session_create_response.py +27 -0
  40. anchorbrowser/types/batch_session_retrieve_response.py +90 -0
  41. anchorbrowser/types/event_signal_params.py +13 -0
  42. anchorbrowser/types/event_wait_for_params.py +14 -0
  43. anchorbrowser/types/event_wait_for_response.py +12 -0
  44. anchorbrowser/types/extension_manifest.py +6 -1
  45. anchorbrowser/types/profile_create_params.py +3 -6
  46. anchorbrowser/types/profile_list_response.py +0 -3
  47. anchorbrowser/types/profile_retrieve_response.py +0 -3
  48. anchorbrowser/types/session_create_params.py +308 -29
  49. anchorbrowser/types/session_list_pages_response.py +25 -0
  50. anchorbrowser/types/session_retrieve_response.py +46 -0
  51. anchorbrowser/types/session_scroll_params.py +3 -0
  52. anchorbrowser/types/session_upload_file_params.py +14 -0
  53. anchorbrowser/types/session_upload_file_response.py +17 -0
  54. anchorbrowser/types/sessions/__init__.py +0 -4
  55. anchorbrowser/types/sessions/agent/__init__.py +7 -0
  56. anchorbrowser/types/sessions/agent/file_list_response.py +32 -0
  57. anchorbrowser/types/sessions/agent/file_upload_params.py +14 -0
  58. anchorbrowser/types/sessions/agent/file_upload_response.py +17 -0
  59. anchorbrowser/types/sessions/keyboard_shortcut_params.py +2 -2
  60. anchorbrowser/types/sessions/recording_list_response.py +4 -8
  61. anchorbrowser/types/task/__init__.py +6 -0
  62. anchorbrowser/types/task/run_execute_params.py +324 -0
  63. anchorbrowser/types/task/run_execute_response.py +33 -0
  64. anchorbrowser/types/task_create_params.py +317 -0
  65. anchorbrowser/types/task_create_response.py +345 -0
  66. anchorbrowser/types/task_list_params.py +15 -0
  67. anchorbrowser/types/task_list_response.py +361 -0
  68. anchorbrowser/types/tool_fetch_webpage_params.py +15 -0
  69. anchorbrowser/types/tool_perform_web_task_params.py +17 -1
  70. anchorbrowser/types/tool_perform_web_task_response.py +3 -3
  71. {anchorbrowser-0.1.0a3.dist-info → anchorbrowser-0.2.0.dist-info}/METADATA +13 -14
  72. anchorbrowser-0.2.0.dist-info/RECORD +126 -0
  73. anchorbrowser/types/profile_update_params.py +0 -27
  74. anchorbrowser/types/sessions/mouse_down_params.py +0 -18
  75. anchorbrowser/types/sessions/mouse_down_response.py +0 -11
  76. anchorbrowser/types/sessions/mouse_up_params.py +0 -18
  77. anchorbrowser/types/sessions/mouse_up_response.py +0 -11
  78. anchorbrowser-0.1.0a3.dist-info/RECORD +0 -100
  79. {anchorbrowser-0.1.0a3.dist-info → anchorbrowser-0.2.0.dist-info}/WHEEL +0 -0
  80. {anchorbrowser-0.1.0a3.dist-info → anchorbrowser-0.2.0.dist-info}/licenses/LICENSE +0 -0
anchorbrowser/__init__.py CHANGED
@@ -3,7 +3,7 @@
3
3
  import typing as _t
4
4
 
5
5
  from . import types
6
- from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes
6
+ from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes, omit, not_given
7
7
  from ._utils import file_from_path
8
8
  from ._client import (
9
9
  Client,
@@ -48,7 +48,9 @@ __all__ = [
48
48
  "ProxiesTypes",
49
49
  "NotGiven",
50
50
  "NOT_GIVEN",
51
+ "not_given",
51
52
  "Omit",
53
+ "omit",
52
54
  "AnchorbrowserError",
53
55
  "APIError",
54
56
  "APIStatusError",
@@ -42,7 +42,6 @@ from . import _exceptions
42
42
  from ._qs import Querystring
43
43
  from ._files import to_httpx_files, async_to_httpx_files
44
44
  from ._types import (
45
- NOT_GIVEN,
46
45
  Body,
47
46
  Omit,
48
47
  Query,
@@ -57,9 +56,10 @@ from ._types import (
57
56
  RequestOptions,
58
57
  HttpxRequestFiles,
59
58
  ModelBuilderProtocol,
59
+ not_given,
60
60
  )
61
61
  from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
62
- from ._compat import PYDANTIC_V2, model_copy, model_dump
62
+ from ._compat import PYDANTIC_V1, model_copy, model_dump
63
63
  from ._models import GenericModel, FinalRequestOptions, validate_type, construct_type
64
64
  from ._response import (
65
65
  APIResponse,
@@ -145,9 +145,9 @@ class PageInfo:
145
145
  def __init__(
146
146
  self,
147
147
  *,
148
- url: URL | NotGiven = NOT_GIVEN,
149
- json: Body | NotGiven = NOT_GIVEN,
150
- params: Query | NotGiven = NOT_GIVEN,
148
+ url: URL | NotGiven = not_given,
149
+ json: Body | NotGiven = not_given,
150
+ params: Query | NotGiven = not_given,
151
151
  ) -> None:
152
152
  self.url = url
153
153
  self.json = json
@@ -232,7 +232,7 @@ class BaseSyncPage(BasePage[_T], Generic[_T]):
232
232
  model: Type[_T],
233
233
  options: FinalRequestOptions,
234
234
  ) -> None:
235
- if PYDANTIC_V2 and getattr(self, "__pydantic_private__", None) is None:
235
+ if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
236
236
  self.__pydantic_private__ = {}
237
237
 
238
238
  self._model = model
@@ -320,7 +320,7 @@ class BaseAsyncPage(BasePage[_T], Generic[_T]):
320
320
  client: AsyncAPIClient,
321
321
  options: FinalRequestOptions,
322
322
  ) -> None:
323
- if PYDANTIC_V2 and getattr(self, "__pydantic_private__", None) is None:
323
+ if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
324
324
  self.__pydantic_private__ = {}
325
325
 
326
326
  self._model = model
@@ -532,7 +532,10 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
532
532
  is_body_allowed = options.method.lower() != "get"
533
533
 
534
534
  if is_body_allowed:
535
- kwargs["json"] = json_data if is_given(json_data) else None
535
+ if isinstance(json_data, bytes):
536
+ kwargs["content"] = json_data
537
+ else:
538
+ kwargs["json"] = json_data if is_given(json_data) else None
536
539
  kwargs["files"] = files
537
540
  else:
538
541
  headers.pop("Content-Type", None)
@@ -592,7 +595,7 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
592
595
  # we internally support defining a temporary header to override the
593
596
  # default `cast_to` type for use with `.with_raw_response` and `.with_streaming_response`
594
597
  # see _response.py for implementation details
595
- override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, NOT_GIVEN)
598
+ override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, not_given)
596
599
  if is_given(override_cast_to):
597
600
  options.headers = headers
598
601
  return cast(Type[ResponseT], override_cast_to)
@@ -822,7 +825,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
822
825
  version: str,
823
826
  base_url: str | URL,
824
827
  max_retries: int = DEFAULT_MAX_RETRIES,
825
- timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
828
+ timeout: float | Timeout | None | NotGiven = not_given,
826
829
  http_client: httpx.Client | None = None,
827
830
  custom_headers: Mapping[str, str] | None = None,
828
831
  custom_query: Mapping[str, object] | None = None,
@@ -1353,7 +1356,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
1353
1356
  base_url: str | URL,
1354
1357
  _strict_response_validation: bool,
1355
1358
  max_retries: int = DEFAULT_MAX_RETRIES,
1356
- timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
1359
+ timeout: float | Timeout | None | NotGiven = not_given,
1357
1360
  http_client: httpx.AsyncClient | None = None,
1358
1361
  custom_headers: Mapping[str, str] | None = None,
1359
1362
  custom_query: Mapping[str, object] | None = None,
@@ -1815,8 +1818,8 @@ def make_request_options(
1815
1818
  extra_query: Query | None = None,
1816
1819
  extra_body: Body | None = None,
1817
1820
  idempotency_key: str | None = None,
1818
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
1819
- post_parser: PostParser | NotGiven = NOT_GIVEN,
1821
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
1822
+ post_parser: PostParser | NotGiven = not_given,
1820
1823
  ) -> RequestOptions:
1821
1824
  """Create a dict of type RequestOptions without keys of NotGiven values."""
1822
1825
  options: RequestOptions = {}
anchorbrowser/_client.py CHANGED
@@ -3,7 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import os
6
- from typing import Any, Union, Mapping
6
+ from typing import Any, Mapping
7
7
  from typing_extensions import Self, override
8
8
 
9
9
  import httpx
@@ -11,17 +11,17 @@ import httpx
11
11
  from . import _exceptions
12
12
  from ._qs import Querystring
13
13
  from ._types import (
14
- NOT_GIVEN,
15
14
  Omit,
16
15
  Timeout,
17
16
  NotGiven,
18
17
  Transport,
19
18
  ProxiesTypes,
20
19
  RequestOptions,
20
+ not_given,
21
21
  )
22
22
  from ._utils import is_given, get_async_library
23
23
  from ._version import __version__
24
- from .resources import agent, tools, browser, profiles, extensions
24
+ from .resources import agent, tools, events, browser, profiles, extensions, batch_sessions
25
25
  from ._streaming import Stream as Stream, AsyncStream as AsyncStream
26
26
  from ._exceptions import APIStatusError, AnchorbrowserError
27
27
  from ._base_client import (
@@ -29,6 +29,7 @@ from ._base_client import (
29
29
  SyncAPIClient,
30
30
  AsyncAPIClient,
31
31
  )
32
+ from .resources.task import task
32
33
  from .resources.sessions import sessions
33
34
 
34
35
  __all__ = [
@@ -50,6 +51,9 @@ class Anchorbrowser(SyncAPIClient):
50
51
  extensions: extensions.ExtensionsResource
51
52
  browser: browser.BrowserResource
52
53
  agent: agent.AgentResource
54
+ events: events.EventsResource
55
+ batch_sessions: batch_sessions.BatchSessionsResource
56
+ task: task.TaskResource
53
57
  with_raw_response: AnchorbrowserWithRawResponse
54
58
  with_streaming_response: AnchorbrowserWithStreamedResponse
55
59
 
@@ -61,7 +65,7 @@ class Anchorbrowser(SyncAPIClient):
61
65
  *,
62
66
  api_key: str | None = None,
63
67
  base_url: str | httpx.URL | None = None,
64
- timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
68
+ timeout: float | Timeout | None | NotGiven = not_given,
65
69
  max_retries: int = DEFAULT_MAX_RETRIES,
66
70
  default_headers: Mapping[str, str] | None = None,
67
71
  default_query: Mapping[str, object] | None = None,
@@ -113,6 +117,9 @@ class Anchorbrowser(SyncAPIClient):
113
117
  self.extensions = extensions.ExtensionsResource(self)
114
118
  self.browser = browser.BrowserResource(self)
115
119
  self.agent = agent.AgentResource(self)
120
+ self.events = events.EventsResource(self)
121
+ self.batch_sessions = batch_sessions.BatchSessionsResource(self)
122
+ self.task = task.TaskResource(self)
116
123
  self.with_raw_response = AnchorbrowserWithRawResponse(self)
117
124
  self.with_streaming_response = AnchorbrowserWithStreamedResponse(self)
118
125
 
@@ -141,9 +148,9 @@ class Anchorbrowser(SyncAPIClient):
141
148
  *,
142
149
  api_key: str | None = None,
143
150
  base_url: str | httpx.URL | None = None,
144
- timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
151
+ timeout: float | Timeout | None | NotGiven = not_given,
145
152
  http_client: httpx.Client | None = None,
146
- max_retries: int | NotGiven = NOT_GIVEN,
153
+ max_retries: int | NotGiven = not_given,
147
154
  default_headers: Mapping[str, str] | None = None,
148
155
  set_default_headers: Mapping[str, str] | None = None,
149
156
  default_query: Mapping[str, object] | None = None,
@@ -228,6 +235,9 @@ class AsyncAnchorbrowser(AsyncAPIClient):
228
235
  extensions: extensions.AsyncExtensionsResource
229
236
  browser: browser.AsyncBrowserResource
230
237
  agent: agent.AsyncAgentResource
238
+ events: events.AsyncEventsResource
239
+ batch_sessions: batch_sessions.AsyncBatchSessionsResource
240
+ task: task.AsyncTaskResource
231
241
  with_raw_response: AsyncAnchorbrowserWithRawResponse
232
242
  with_streaming_response: AsyncAnchorbrowserWithStreamedResponse
233
243
 
@@ -239,7 +249,7 @@ class AsyncAnchorbrowser(AsyncAPIClient):
239
249
  *,
240
250
  api_key: str | None = None,
241
251
  base_url: str | httpx.URL | None = None,
242
- timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
252
+ timeout: float | Timeout | None | NotGiven = not_given,
243
253
  max_retries: int = DEFAULT_MAX_RETRIES,
244
254
  default_headers: Mapping[str, str] | None = None,
245
255
  default_query: Mapping[str, object] | None = None,
@@ -291,6 +301,9 @@ class AsyncAnchorbrowser(AsyncAPIClient):
291
301
  self.extensions = extensions.AsyncExtensionsResource(self)
292
302
  self.browser = browser.AsyncBrowserResource(self)
293
303
  self.agent = agent.AsyncAgentResource(self)
304
+ self.events = events.AsyncEventsResource(self)
305
+ self.batch_sessions = batch_sessions.AsyncBatchSessionsResource(self)
306
+ self.task = task.AsyncTaskResource(self)
294
307
  self.with_raw_response = AsyncAnchorbrowserWithRawResponse(self)
295
308
  self.with_streaming_response = AsyncAnchorbrowserWithStreamedResponse(self)
296
309
 
@@ -319,9 +332,9 @@ class AsyncAnchorbrowser(AsyncAPIClient):
319
332
  *,
320
333
  api_key: str | None = None,
321
334
  base_url: str | httpx.URL | None = None,
322
- timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
335
+ timeout: float | Timeout | None | NotGiven = not_given,
323
336
  http_client: httpx.AsyncClient | None = None,
324
- max_retries: int | NotGiven = NOT_GIVEN,
337
+ max_retries: int | NotGiven = not_given,
325
338
  default_headers: Mapping[str, str] | None = None,
326
339
  set_default_headers: Mapping[str, str] | None = None,
327
340
  default_query: Mapping[str, object] | None = None,
@@ -407,6 +420,10 @@ class AnchorbrowserWithRawResponse:
407
420
  self.extensions = extensions.ExtensionsResourceWithRawResponse(client.extensions)
408
421
  self.browser = browser.BrowserResourceWithRawResponse(client.browser)
409
422
  self.agent = agent.AgentResourceWithRawResponse(client.agent)
423
+ self.events = events.EventsResourceWithRawResponse(client.events)
424
+ self.batch_sessions = batch_sessions.BatchSessionsResourceWithRawResponse(client.batch_sessions)
425
+ self.task = task.TaskResourceWithRawResponse(client.task)
426
+
410
427
 
411
428
  class AsyncAnchorbrowserWithRawResponse:
412
429
  def __init__(self, client: AsyncAnchorbrowser) -> None:
@@ -416,6 +433,10 @@ class AsyncAnchorbrowserWithRawResponse:
416
433
  self.extensions = extensions.AsyncExtensionsResourceWithRawResponse(client.extensions)
417
434
  self.browser = browser.AsyncBrowserResourceWithRawResponse(client.browser)
418
435
  self.agent = agent.AsyncAgentResourceWithRawResponse(client.agent)
436
+ self.events = events.AsyncEventsResourceWithRawResponse(client.events)
437
+ self.batch_sessions = batch_sessions.AsyncBatchSessionsResourceWithRawResponse(client.batch_sessions)
438
+ self.task = task.AsyncTaskResourceWithRawResponse(client.task)
439
+
419
440
 
420
441
  class AnchorbrowserWithStreamedResponse:
421
442
  def __init__(self, client: Anchorbrowser) -> None:
@@ -425,6 +446,10 @@ class AnchorbrowserWithStreamedResponse:
425
446
  self.extensions = extensions.ExtensionsResourceWithStreamingResponse(client.extensions)
426
447
  self.browser = browser.BrowserResourceWithStreamingResponse(client.browser)
427
448
  self.agent = agent.AgentResourceWithStreamingResponse(client.agent)
449
+ self.events = events.EventsResourceWithStreamingResponse(client.events)
450
+ self.batch_sessions = batch_sessions.BatchSessionsResourceWithStreamingResponse(client.batch_sessions)
451
+ self.task = task.TaskResourceWithStreamingResponse(client.task)
452
+
428
453
 
429
454
  class AsyncAnchorbrowserWithStreamedResponse:
430
455
  def __init__(self, client: AsyncAnchorbrowser) -> None:
@@ -434,6 +459,10 @@ class AsyncAnchorbrowserWithStreamedResponse:
434
459
  self.extensions = extensions.AsyncExtensionsResourceWithStreamingResponse(client.extensions)
435
460
  self.browser = browser.AsyncBrowserResourceWithStreamingResponse(client.browser)
436
461
  self.agent = agent.AsyncAgentResourceWithStreamingResponse(client.agent)
462
+ self.events = events.AsyncEventsResourceWithStreamingResponse(client.events)
463
+ self.batch_sessions = batch_sessions.AsyncBatchSessionsResourceWithStreamingResponse(client.batch_sessions)
464
+ self.task = task.AsyncTaskResourceWithStreamingResponse(client.task)
465
+
437
466
 
438
467
  Client = Anchorbrowser
439
468
 
anchorbrowser/_compat.py CHANGED
@@ -12,14 +12,13 @@ from ._types import IncEx, StrBytesIntFloat
12
12
  _T = TypeVar("_T")
13
13
  _ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)
14
14
 
15
- # --------------- Pydantic v2 compatibility ---------------
15
+ # --------------- Pydantic v2, v3 compatibility ---------------
16
16
 
17
17
  # Pyright incorrectly reports some of our functions as overriding a method when they don't
18
18
  # pyright: reportIncompatibleMethodOverride=false
19
19
 
20
- PYDANTIC_V2 = pydantic.VERSION.startswith("2.")
20
+ PYDANTIC_V1 = pydantic.VERSION.startswith("1.")
21
21
 
22
- # v1 re-exports
23
22
  if TYPE_CHECKING:
24
23
 
25
24
  def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
@@ -44,90 +43,92 @@ if TYPE_CHECKING:
44
43
  ...
45
44
 
46
45
  else:
47
- if PYDANTIC_V2:
48
- from pydantic.v1.typing import (
46
+ # v1 re-exports
47
+ if PYDANTIC_V1:
48
+ from pydantic.typing import (
49
49
  get_args as get_args,
50
50
  is_union as is_union,
51
51
  get_origin as get_origin,
52
52
  is_typeddict as is_typeddict,
53
53
  is_literal_type as is_literal_type,
54
54
  )
55
- from pydantic.v1.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
55
+ from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
56
56
  else:
57
- from pydantic.typing import (
57
+ from ._utils import (
58
58
  get_args as get_args,
59
59
  is_union as is_union,
60
60
  get_origin as get_origin,
61
+ parse_date as parse_date,
61
62
  is_typeddict as is_typeddict,
63
+ parse_datetime as parse_datetime,
62
64
  is_literal_type as is_literal_type,
63
65
  )
64
- from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
65
66
 
66
67
 
67
68
  # refactored config
68
69
  if TYPE_CHECKING:
69
70
  from pydantic import ConfigDict as ConfigDict
70
71
  else:
71
- if PYDANTIC_V2:
72
- from pydantic import ConfigDict
73
- else:
72
+ if PYDANTIC_V1:
74
73
  # TODO: provide an error message here?
75
74
  ConfigDict = None
75
+ else:
76
+ from pydantic import ConfigDict as ConfigDict
76
77
 
77
78
 
78
79
  # renamed methods / properties
79
80
  def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
80
- if PYDANTIC_V2:
81
- return model.model_validate(value)
82
- else:
81
+ if PYDANTIC_V1:
83
82
  return cast(_ModelT, model.parse_obj(value)) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
83
+ else:
84
+ return model.model_validate(value)
84
85
 
85
86
 
86
87
  def field_is_required(field: FieldInfo) -> bool:
87
- if PYDANTIC_V2:
88
- return field.is_required()
89
- return field.required # type: ignore
88
+ if PYDANTIC_V1:
89
+ return field.required # type: ignore
90
+ return field.is_required()
90
91
 
91
92
 
92
93
  def field_get_default(field: FieldInfo) -> Any:
93
94
  value = field.get_default()
94
- if PYDANTIC_V2:
95
- from pydantic_core import PydanticUndefined
96
-
97
- if value == PydanticUndefined:
98
- return None
95
+ if PYDANTIC_V1:
99
96
  return value
97
+ from pydantic_core import PydanticUndefined
98
+
99
+ if value == PydanticUndefined:
100
+ return None
100
101
  return value
101
102
 
102
103
 
103
104
  def field_outer_type(field: FieldInfo) -> Any:
104
- if PYDANTIC_V2:
105
- return field.annotation
106
- return field.outer_type_ # type: ignore
105
+ if PYDANTIC_V1:
106
+ return field.outer_type_ # type: ignore
107
+ return field.annotation
107
108
 
108
109
 
109
110
  def get_model_config(model: type[pydantic.BaseModel]) -> Any:
110
- if PYDANTIC_V2:
111
- return model.model_config
112
- return model.__config__ # type: ignore
111
+ if PYDANTIC_V1:
112
+ return model.__config__ # type: ignore
113
+ return model.model_config
113
114
 
114
115
 
115
116
  def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
116
- if PYDANTIC_V2:
117
- return model.model_fields
118
- return model.__fields__ # type: ignore
117
+ if PYDANTIC_V1:
118
+ return model.__fields__ # type: ignore
119
+ return model.model_fields
119
120
 
120
121
 
121
122
  def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT:
122
- if PYDANTIC_V2:
123
- return model.model_copy(deep=deep)
124
- return model.copy(deep=deep) # type: ignore
123
+ if PYDANTIC_V1:
124
+ return model.copy(deep=deep) # type: ignore
125
+ return model.model_copy(deep=deep)
125
126
 
126
127
 
127
128
  def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
128
- if PYDANTIC_V2:
129
- return model.model_dump_json(indent=indent)
130
- return model.json(indent=indent) # type: ignore
129
+ if PYDANTIC_V1:
130
+ return model.json(indent=indent) # type: ignore
131
+ return model.model_dump_json(indent=indent)
131
132
 
132
133
 
133
134
  def model_dump(
@@ -139,14 +140,14 @@ def model_dump(
139
140
  warnings: bool = True,
140
141
  mode: Literal["json", "python"] = "python",
141
142
  ) -> dict[str, Any]:
142
- if PYDANTIC_V2 or hasattr(model, "model_dump"):
143
+ if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
143
144
  return model.model_dump(
144
145
  mode=mode,
145
146
  exclude=exclude,
146
147
  exclude_unset=exclude_unset,
147
148
  exclude_defaults=exclude_defaults,
148
149
  # warnings are not supported in Pydantic v1
149
- warnings=warnings if PYDANTIC_V2 else True,
150
+ warnings=True if PYDANTIC_V1 else warnings,
150
151
  )
151
152
  return cast(
152
153
  "dict[str, Any]",
@@ -159,9 +160,9 @@ def model_dump(
159
160
 
160
161
 
161
162
  def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
162
- if PYDANTIC_V2:
163
- return model.model_validate(data)
164
- return model.parse_obj(data) # pyright: ignore[reportDeprecated]
163
+ if PYDANTIC_V1:
164
+ return model.parse_obj(data) # pyright: ignore[reportDeprecated]
165
+ return model.model_validate(data)
165
166
 
166
167
 
167
168
  # generic models
@@ -170,17 +171,16 @@ if TYPE_CHECKING:
170
171
  class GenericModel(pydantic.BaseModel): ...
171
172
 
172
173
  else:
173
- if PYDANTIC_V2:
174
+ if PYDANTIC_V1:
175
+ import pydantic.generics
176
+
177
+ class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
178
+ else:
174
179
  # there no longer needs to be a distinction in v2 but
175
180
  # we still have to create our own subclass to avoid
176
181
  # inconsistent MRO ordering errors
177
182
  class GenericModel(pydantic.BaseModel): ...
178
183
 
179
- else:
180
- import pydantic.generics
181
-
182
- class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
183
-
184
184
 
185
185
  # cached properties
186
186
  if TYPE_CHECKING:
anchorbrowser/_files.py CHANGED
@@ -69,12 +69,12 @@ def _transform_file(file: FileTypes) -> HttpxFileTypes:
69
69
  return file
70
70
 
71
71
  if is_tuple_t(file):
72
- return (file[0], _read_file_content(file[1]), *file[2:])
72
+ return (file[0], read_file_content(file[1]), *file[2:])
73
73
 
74
74
  raise TypeError(f"Expected file types input to be a FileContent type or to be a tuple")
75
75
 
76
76
 
77
- def _read_file_content(file: FileContent) -> HttpxFileContent:
77
+ def read_file_content(file: FileContent) -> HttpxFileContent:
78
78
  if isinstance(file, os.PathLike):
79
79
  return pathlib.Path(file).read_bytes()
80
80
  return file
@@ -111,12 +111,12 @@ async def _async_transform_file(file: FileTypes) -> HttpxFileTypes:
111
111
  return file
112
112
 
113
113
  if is_tuple_t(file):
114
- return (file[0], await _async_read_file_content(file[1]), *file[2:])
114
+ return (file[0], await async_read_file_content(file[1]), *file[2:])
115
115
 
116
116
  raise TypeError(f"Expected file types input to be a FileContent type or to be a tuple")
117
117
 
118
118
 
119
- async def _async_read_file_content(file: FileContent) -> HttpxFileContent:
119
+ async def async_read_file_content(file: FileContent) -> HttpxFileContent:
120
120
  if isinstance(file, os.PathLike):
121
121
  return await anyio.Path(file).read_bytes()
122
122