assassinlike commited on
Commit
cf7dbc5
·
verified ·
1 Parent(s): bea701a

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. data/conda_envs/evalclaw/lib/python3.11/site-packages/_multiprocess/__pycache__/__init__.cpython-311.pyc +0 -0
  2. data/conda_envs/evalclaw/lib/python3.11/site-packages/aiosignal/__pycache__/__init__.cpython-311.pyc +0 -0
  3. data/conda_envs/evalclaw/lib/python3.11/site-packages/annotated_doc/__pycache__/__init__.cpython-311.pyc +0 -0
  4. data/conda_envs/evalclaw/lib/python3.11/site-packages/annotated_doc/__pycache__/main.cpython-311.pyc +0 -0
  5. data/conda_envs/evalclaw/lib/python3.11/site-packages/annotated_types/__pycache__/__init__.cpython-311.pyc +0 -0
  6. data/conda_envs/evalclaw/lib/python3.11/site-packages/annotated_types/__pycache__/test_cases.cpython-311.pyc +0 -0
  7. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/__init__.cpython-311.pyc +0 -0
  8. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_base_client.cpython-311.pyc +0 -0
  9. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_client.cpython-311.pyc +0 -0
  10. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_compat.cpython-311.pyc +0 -0
  11. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_constants.cpython-311.pyc +0 -0
  12. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_exceptions.cpython-311.pyc +0 -0
  13. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_files.cpython-311.pyc +0 -0
  14. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_legacy_response.cpython-311.pyc +0 -0
  15. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_models.cpython-311.pyc +0 -0
  16. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_qs.cpython-311.pyc +0 -0
  17. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_resource.cpython-311.pyc +0 -0
  18. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_response.cpython-311.pyc +0 -0
  19. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_streaming.cpython-311.pyc +0 -0
  20. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_types.cpython-311.pyc +0 -0
  21. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_version.cpython-311.pyc +0 -0
  22. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/pagination.cpython-311.pyc +0 -0
  23. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_decoders/__pycache__/jsonl.cpython-311.pyc +0 -0
  24. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_decoders/jsonl.py +123 -0
  25. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__init__.py +64 -0
  26. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/__init__.cpython-311.pyc +0 -0
  27. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_compat.cpython-311.pyc +0 -0
  28. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_datetime_parse.cpython-311.pyc +0 -0
  29. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_httpx.cpython-311.pyc +0 -0
  30. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_json.cpython-311.pyc +0 -0
  31. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_logs.cpython-311.pyc +0 -0
  32. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_proxy.cpython-311.pyc +0 -0
  33. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_reflection.cpython-311.pyc +0 -0
  34. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_resources_proxy.cpython-311.pyc +0 -0
  35. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_streams.cpython-311.pyc +0 -0
  36. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_sync.cpython-311.pyc +0 -0
  37. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_transform.cpython-311.pyc +0 -0
  38. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_typing.cpython-311.pyc +0 -0
  39. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_utils.cpython-311.pyc +0 -0
  40. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_compat.py +45 -0
  41. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_datetime_parse.py +136 -0
  42. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_httpx.py +64 -0
  43. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_json.py +35 -0
  44. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_logs.py +25 -0
  45. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_proxy.py +65 -0
  46. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_reflection.py +42 -0
  47. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_resources_proxy.py +24 -0
  48. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_streams.py +12 -0
  49. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_sync.py +58 -0
  50. data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_transform.py +457 -0
data/conda_envs/evalclaw/lib/python3.11/site-packages/_multiprocess/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (244 Bytes). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/aiosignal/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (3.12 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/annotated_doc/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (274 Bytes). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/annotated_doc/__pycache__/main.cpython-311.pyc ADDED
Binary file (2.02 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/annotated_types/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (20.6 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/annotated_types/__pycache__/test_cases.cpython-311.pyc ADDED
Binary file (15.5 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (3.3 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_base_client.cpython-311.pyc ADDED
Binary file (87.5 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_client.cpython-311.pyc ADDED
Binary file (26.3 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_compat.cpython-311.pyc ADDED
Binary file (9.41 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_constants.cpython-311.pyc ADDED
Binary file (1.11 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_exceptions.cpython-311.pyc ADDED
Binary file (7.51 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_files.cpython-311.pyc ADDED
Binary file (7.51 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_legacy_response.cpython-311.pyc ADDED
Binary file (26.1 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_models.cpython-311.pyc ADDED
Binary file (38.3 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_qs.cpython-311.pyc ADDED
Binary file (6.7 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_resource.cpython-311.pyc ADDED
Binary file (2.3 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_response.cpython-311.pyc ADDED
Binary file (42.3 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_streaming.cpython-311.pyc ADDED
Binary file (20.5 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_types.cpython-311.pyc ADDED
Binary file (10.4 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/_version.cpython-311.pyc ADDED
Binary file (251 Bytes). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/__pycache__/pagination.cpython-311.pyc ADDED
Binary file (8 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_decoders/__pycache__/jsonl.cpython-311.pyc ADDED
Binary file (5.83 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_decoders/jsonl.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from typing_extensions import Generic, TypeVar, Iterator, AsyncIterator
5
+
6
+ import httpx
7
+
8
+ from .._models import construct_type_unchecked
9
+
10
+ _T = TypeVar("_T")
11
+
12
+
13
+ class JSONLDecoder(Generic[_T]):
14
+ """A decoder for [JSON Lines](https://jsonlines.org) format.
15
+
16
+ This class provides an iterator over a byte-iterator that parses each JSON Line
17
+ into a given type.
18
+ """
19
+
20
+ http_response: httpx.Response
21
+ """The HTTP response this decoder was constructed from"""
22
+
23
+ def __init__(
24
+ self,
25
+ *,
26
+ raw_iterator: Iterator[bytes],
27
+ line_type: type[_T],
28
+ http_response: httpx.Response,
29
+ ) -> None:
30
+ super().__init__()
31
+ self.http_response = http_response
32
+ self._raw_iterator = raw_iterator
33
+ self._line_type = line_type
34
+ self._iterator = self.__decode__()
35
+
36
+ def close(self) -> None:
37
+ """Close the response body stream.
38
+
39
+ This is called automatically if you consume the entire stream.
40
+ """
41
+ self.http_response.close()
42
+
43
+ def __decode__(self) -> Iterator[_T]:
44
+ buf = b""
45
+ for chunk in self._raw_iterator:
46
+ for line in chunk.splitlines(keepends=True):
47
+ buf += line
48
+ if buf.endswith((b"\r", b"\n", b"\r\n")):
49
+ yield construct_type_unchecked(
50
+ value=json.loads(buf),
51
+ type_=self._line_type,
52
+ )
53
+ buf = b""
54
+
55
+ # flush
56
+ if buf:
57
+ yield construct_type_unchecked(
58
+ value=json.loads(buf),
59
+ type_=self._line_type,
60
+ )
61
+
62
+ def __next__(self) -> _T:
63
+ return self._iterator.__next__()
64
+
65
+ def __iter__(self) -> Iterator[_T]:
66
+ for item in self._iterator:
67
+ yield item
68
+
69
+
70
+ class AsyncJSONLDecoder(Generic[_T]):
71
+ """A decoder for [JSON Lines](https://jsonlines.org) format.
72
+
73
+ This class provides an async iterator over a byte-iterator that parses each JSON Line
74
+ into a given type.
75
+ """
76
+
77
+ http_response: httpx.Response
78
+
79
+ def __init__(
80
+ self,
81
+ *,
82
+ raw_iterator: AsyncIterator[bytes],
83
+ line_type: type[_T],
84
+ http_response: httpx.Response,
85
+ ) -> None:
86
+ super().__init__()
87
+ self.http_response = http_response
88
+ self._raw_iterator = raw_iterator
89
+ self._line_type = line_type
90
+ self._iterator = self.__decode__()
91
+
92
+ async def close(self) -> None:
93
+ """Close the response body stream.
94
+
95
+ This is called automatically if you consume the entire stream.
96
+ """
97
+ await self.http_response.aclose()
98
+
99
+ async def __decode__(self) -> AsyncIterator[_T]:
100
+ buf = b""
101
+ async for chunk in self._raw_iterator:
102
+ for line in chunk.splitlines(keepends=True):
103
+ buf += line
104
+ if buf.endswith((b"\r", b"\n", b"\r\n")):
105
+ yield construct_type_unchecked(
106
+ value=json.loads(buf),
107
+ type_=self._line_type,
108
+ )
109
+ buf = b""
110
+
111
+ # flush
112
+ if buf:
113
+ yield construct_type_unchecked(
114
+ value=json.loads(buf),
115
+ type_=self._line_type,
116
+ )
117
+
118
+ async def __anext__(self) -> _T:
119
+ return await self._iterator.__anext__()
120
+
121
+ async def __aiter__(self) -> AsyncIterator[_T]:
122
+ async for item in self._iterator:
123
+ yield item
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__init__.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ._sync import asyncify as asyncify
2
+ from ._proxy import LazyProxy as LazyProxy
3
+ from ._utils import (
4
+ flatten as flatten,
5
+ is_dict as is_dict,
6
+ is_list as is_list,
7
+ is_given as is_given,
8
+ is_tuple as is_tuple,
9
+ json_safe as json_safe,
10
+ lru_cache as lru_cache,
11
+ is_mapping as is_mapping,
12
+ is_tuple_t as is_tuple_t,
13
+ is_iterable as is_iterable,
14
+ is_sequence as is_sequence,
15
+ coerce_float as coerce_float,
16
+ is_mapping_t as is_mapping_t,
17
+ removeprefix as removeprefix,
18
+ removesuffix as removesuffix,
19
+ extract_files as extract_files,
20
+ is_sequence_t as is_sequence_t,
21
+ required_args as required_args,
22
+ coerce_boolean as coerce_boolean,
23
+ coerce_integer as coerce_integer,
24
+ file_from_path as file_from_path,
25
+ strip_not_given as strip_not_given,
26
+ deepcopy_minimal as deepcopy_minimal,
27
+ get_async_library as get_async_library,
28
+ maybe_coerce_float as maybe_coerce_float,
29
+ get_required_header as get_required_header,
30
+ maybe_coerce_boolean as maybe_coerce_boolean,
31
+ maybe_coerce_integer as maybe_coerce_integer,
32
+ )
33
+ from ._compat import (
34
+ get_args as get_args,
35
+ is_union as is_union,
36
+ get_origin as get_origin,
37
+ is_typeddict as is_typeddict,
38
+ is_literal_type as is_literal_type,
39
+ )
40
+ from ._typing import (
41
+ is_list_type as is_list_type,
42
+ is_union_type as is_union_type,
43
+ extract_type_arg as extract_type_arg,
44
+ is_iterable_type as is_iterable_type,
45
+ is_required_type as is_required_type,
46
+ is_sequence_type as is_sequence_type,
47
+ is_annotated_type as is_annotated_type,
48
+ is_type_alias_type as is_type_alias_type,
49
+ strip_annotated_type as strip_annotated_type,
50
+ extract_type_var_from_base as extract_type_var_from_base,
51
+ )
52
+ from ._streams import consume_sync_iterator as consume_sync_iterator, consume_async_iterator as consume_async_iterator
53
+ from ._transform import (
54
+ PropertyInfo as PropertyInfo,
55
+ transform as transform,
56
+ async_transform as async_transform,
57
+ maybe_transform as maybe_transform,
58
+ async_maybe_transform as async_maybe_transform,
59
+ )
60
+ from ._reflection import (
61
+ function_has_argument as function_has_argument,
62
+ assert_signatures_in_sync as assert_signatures_in_sync,
63
+ )
64
+ from ._datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (2.47 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_compat.cpython-311.pyc ADDED
Binary file (2.52 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_datetime_parse.cpython-311.pyc ADDED
Binary file (6.92 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_httpx.cpython-311.pyc ADDED
Binary file (3.19 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_json.cpython-311.pyc ADDED
Binary file (2.04 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_logs.cpython-311.pyc ADDED
Binary file (1.66 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_proxy.cpython-311.pyc ADDED
Binary file (3.9 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_reflection.cpython-311.pyc ADDED
Binary file (2.36 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_resources_proxy.cpython-311.pyc ADDED
Binary file (1.41 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_streams.cpython-311.pyc ADDED
Binary file (847 Bytes). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_sync.cpython-311.pyc ADDED
Binary file (2.56 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_transform.cpython-311.pyc ADDED
Binary file (17.9 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_typing.cpython-311.pyc ADDED
Binary file (6.25 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/__pycache__/_utils.cpython-311.pyc ADDED
Binary file (20.6 kB). View file
 
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_compat.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+ import typing_extensions
5
+ from typing import Any, Type, Union, Literal, Optional
6
+ from datetime import date, datetime
7
+ from typing_extensions import get_args as _get_args, get_origin as _get_origin
8
+
9
+ from .._types import StrBytesIntFloat
10
+ from ._datetime_parse import parse_date as _parse_date, parse_datetime as _parse_datetime
11
+
12
+ _LITERAL_TYPES = {Literal, typing_extensions.Literal}
13
+
14
+
15
+ def get_args(tp: type[Any]) -> tuple[Any, ...]:
16
+ return _get_args(tp)
17
+
18
+
19
+ def get_origin(tp: type[Any]) -> type[Any] | None:
20
+ return _get_origin(tp)
21
+
22
+
23
+ def is_union(tp: Optional[Type[Any]]) -> bool:
24
+ if sys.version_info < (3, 10):
25
+ return tp is Union # type: ignore[comparison-overlap]
26
+ else:
27
+ import types
28
+
29
+ return tp is Union or tp is types.UnionType # type: ignore[comparison-overlap]
30
+
31
+
32
+ def is_typeddict(tp: Type[Any]) -> bool:
33
+ return typing_extensions.is_typeddict(tp)
34
+
35
+
36
+ def is_literal_type(tp: Type[Any]) -> bool:
37
+ return get_origin(tp) in _LITERAL_TYPES
38
+
39
+
40
+ def parse_date(value: Union[date, StrBytesIntFloat]) -> date:
41
+ return _parse_date(value)
42
+
43
+
44
+ def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime:
45
+ return _parse_datetime(value)
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_datetime_parse.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ This file contains code from https://github.com/pydantic/pydantic/blob/main/pydantic/v1/datetime_parse.py
3
+ without the Pydantic v1 specific errors.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import re
9
+ from typing import Dict, Union, Optional
10
+ from datetime import date, datetime, timezone, timedelta
11
+
12
+ from .._types import StrBytesIntFloat
13
+
14
+ date_expr = r"(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})"
15
+ time_expr = (
16
+ r"(?P<hour>\d{1,2}):(?P<minute>\d{1,2})"
17
+ r"(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?"
18
+ r"(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$"
19
+ )
20
+
21
+ date_re = re.compile(f"{date_expr}$")
22
+ datetime_re = re.compile(f"{date_expr}[T ]{time_expr}")
23
+
24
+
25
+ EPOCH = datetime(1970, 1, 1)
26
+ # if greater than this, the number is in ms, if less than or equal it's in seconds
27
+ # (in seconds this is 11th October 2603, in ms it's 20th August 1970)
28
+ MS_WATERSHED = int(2e10)
29
+ # slightly more than datetime.max in ns - (datetime.max - EPOCH).total_seconds() * 1e9
30
+ MAX_NUMBER = int(3e20)
31
+
32
+
33
+ def _get_numeric(value: StrBytesIntFloat, native_expected_type: str) -> Union[None, int, float]:
34
+ if isinstance(value, (int, float)):
35
+ return value
36
+ try:
37
+ return float(value)
38
+ except ValueError:
39
+ return None
40
+ except TypeError:
41
+ raise TypeError(f"invalid type; expected {native_expected_type}, string, bytes, int or float") from None
42
+
43
+
44
+ def _from_unix_seconds(seconds: Union[int, float]) -> datetime:
45
+ if seconds > MAX_NUMBER:
46
+ return datetime.max
47
+ elif seconds < -MAX_NUMBER:
48
+ return datetime.min
49
+
50
+ while abs(seconds) > MS_WATERSHED:
51
+ seconds /= 1000
52
+ dt = EPOCH + timedelta(seconds=seconds)
53
+ return dt.replace(tzinfo=timezone.utc)
54
+
55
+
56
+ def _parse_timezone(value: Optional[str]) -> Union[None, int, timezone]:
57
+ if value == "Z":
58
+ return timezone.utc
59
+ elif value is not None:
60
+ offset_mins = int(value[-2:]) if len(value) > 3 else 0
61
+ offset = 60 * int(value[1:3]) + offset_mins
62
+ if value[0] == "-":
63
+ offset = -offset
64
+ return timezone(timedelta(minutes=offset))
65
+ else:
66
+ return None
67
+
68
+
69
+ def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime:
70
+ """
71
+ Parse a datetime/int/float/string and return a datetime.datetime.
72
+
73
+ This function supports time zone offsets. When the input contains one,
74
+ the output uses a timezone with a fixed offset from UTC.
75
+
76
+ Raise ValueError if the input is well formatted but not a valid datetime.
77
+ Raise ValueError if the input isn't well formatted.
78
+ """
79
+ if isinstance(value, datetime):
80
+ return value
81
+
82
+ number = _get_numeric(value, "datetime")
83
+ if number is not None:
84
+ return _from_unix_seconds(number)
85
+
86
+ if isinstance(value, bytes):
87
+ value = value.decode()
88
+
89
+ assert not isinstance(value, (float, int))
90
+
91
+ match = datetime_re.match(value)
92
+ if match is None:
93
+ raise ValueError("invalid datetime format")
94
+
95
+ kw = match.groupdict()
96
+ if kw["microsecond"]:
97
+ kw["microsecond"] = kw["microsecond"].ljust(6, "0")
98
+
99
+ tzinfo = _parse_timezone(kw.pop("tzinfo"))
100
+ kw_: Dict[str, Union[None, int, timezone]] = {k: int(v) for k, v in kw.items() if v is not None}
101
+ kw_["tzinfo"] = tzinfo
102
+
103
+ return datetime(**kw_) # type: ignore
104
+
105
+
106
+ def parse_date(value: Union[date, StrBytesIntFloat]) -> date:
107
+ """
108
+ Parse a date/int/float/string and return a datetime.date.
109
+
110
+ Raise ValueError if the input is well formatted but not a valid date.
111
+ Raise ValueError if the input isn't well formatted.
112
+ """
113
+ if isinstance(value, date):
114
+ if isinstance(value, datetime):
115
+ return value.date()
116
+ else:
117
+ return value
118
+
119
+ number = _get_numeric(value, "date")
120
+ if number is not None:
121
+ return _from_unix_seconds(number).date()
122
+
123
+ if isinstance(value, bytes):
124
+ value = value.decode()
125
+
126
+ assert not isinstance(value, (float, int))
127
+ match = date_re.match(value)
128
+ if match is None:
129
+ raise ValueError("invalid date format")
130
+
131
+ kw = {k: int(v) for k, v in match.groupdict().items()}
132
+
133
+ try:
134
+ return date(**kw)
135
+ except ValueError:
136
+ raise ValueError("invalid date format") from None
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_httpx.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ This file includes code adapted from HTTPX's utility module
3
+ (https://github.com/encode/httpx/blob/336204f0121a9aefdebac5cacd81f912bafe8057/httpx/_utils.py).
4
+ We implement custom proxy handling to support configurations like `socket_options`,
5
+ which are not currently configurable through the HTTPX client.
6
+ For more context, see: https://github.com/encode/httpx/discussions/3514
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import ipaddress
12
+ from typing import Mapping
13
+ from urllib.request import getproxies
14
+
15
+
16
+ def is_ipv4_hostname(hostname: str) -> bool:
17
+ try:
18
+ ipaddress.IPv4Address(hostname.split("/")[0])
19
+ except Exception:
20
+ return False
21
+ return True
22
+
23
+
24
+ def is_ipv6_hostname(hostname: str) -> bool:
25
+ try:
26
+ ipaddress.IPv6Address(hostname.split("/")[0])
27
+ except Exception:
28
+ return False
29
+ return True
30
+
31
+
32
+ def get_environment_proxies() -> Mapping[str, str | None]:
33
+ """
34
+ Gets the proxy mappings based on environment variables.
35
+ We use our own logic to parse these variables, as HTTPX
36
+ doesn’t allow full configuration of the underlying
37
+ transport when proxies are set via environment variables.
38
+ """
39
+
40
+ proxy_info = getproxies()
41
+ mounts: dict[str, str | None] = {}
42
+
43
+ for scheme in ("http", "https", "all"):
44
+ if proxy_info.get(scheme):
45
+ hostname = proxy_info[scheme]
46
+ mounts[f"{scheme}://"] = hostname if "://" in hostname else f"http://{hostname}"
47
+
48
+ no_proxy_hosts = [host.strip() for host in proxy_info.get("no", "").split(",")]
49
+ for hostname in no_proxy_hosts:
50
+ if hostname == "*":
51
+ return {}
52
+ elif hostname:
53
+ if "://" in hostname:
54
+ mounts[hostname] = None
55
+ elif is_ipv4_hostname(hostname):
56
+ mounts[f"all://{hostname}"] = None
57
+ elif is_ipv6_hostname(hostname):
58
+ mounts[f"all://[{hostname}]"] = None
59
+ elif hostname.lower() == "localhost":
60
+ mounts[f"all://{hostname}"] = None
61
+ else:
62
+ mounts[f"all://*{hostname}"] = None
63
+
64
+ return mounts
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_json.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from typing import Any
3
+ from datetime import datetime
4
+ from typing_extensions import override
5
+
6
+ import pydantic
7
+
8
+ from .._compat import model_dump
9
+
10
+
11
+ def openapi_dumps(obj: Any) -> bytes:
12
+ """
13
+ Serialize an object to UTF-8 encoded JSON bytes.
14
+
15
+ Extends the standard json.dumps with support for additional types
16
+ commonly used in the SDK, such as `datetime`, `pydantic.BaseModel`, etc.
17
+ """
18
+ return json.dumps(
19
+ obj,
20
+ cls=_CustomEncoder,
21
+ # Uses the same defaults as httpx's JSON serialization
22
+ ensure_ascii=False,
23
+ separators=(",", ":"),
24
+ allow_nan=False,
25
+ ).encode()
26
+
27
+
28
+ class _CustomEncoder(json.JSONEncoder):
29
+ @override
30
+ def default(self, o: Any) -> Any:
31
+ if isinstance(o, datetime):
32
+ return o.isoformat()
33
+ if isinstance(o, pydantic.BaseModel):
34
+ return model_dump(o, exclude_unset=True, mode="json", by_alias=True)
35
+ return super().default(o)
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_logs.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import logging
3
+
4
+ logger: logging.Logger = logging.getLogger("anthropic")
5
+ httpx_logger: logging.Logger = logging.getLogger("httpx")
6
+
7
+
8
+ def _basic_config() -> None:
9
+ # e.g. [2023-10-05 14:12:26 - anthropic._base_client:818 - DEBUG] HTTP Request: POST http://127.0.0.1:4010/foo/bar "200 OK"
10
+ logging.basicConfig(
11
+ format="[%(asctime)s - %(name)s:%(lineno)d - %(levelname)s] %(message)s",
12
+ datefmt="%Y-%m-%d %H:%M:%S",
13
+ )
14
+
15
+
16
+ def setup_logging() -> None:
17
+ env = os.environ.get("ANTHROPIC_LOG")
18
+ if env == "debug":
19
+ _basic_config()
20
+ logger.setLevel(logging.DEBUG)
21
+ httpx_logger.setLevel(logging.DEBUG)
22
+ elif env == "info":
23
+ _basic_config()
24
+ logger.setLevel(logging.INFO)
25
+ httpx_logger.setLevel(logging.INFO)
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_proxy.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from abc import ABC, abstractmethod
4
+ from typing import Generic, TypeVar, Iterable, cast
5
+ from typing_extensions import override
6
+
7
+ T = TypeVar("T")
8
+
9
+
10
+ class LazyProxy(Generic[T], ABC):
11
+ """Implements data methods to pretend that an instance is another instance.
12
+
13
+ This includes forwarding attribute access and other methods.
14
+ """
15
+
16
+ # Note: we have to special case proxies that themselves return proxies
17
+ # to support using a proxy as a catch-all for any random access, e.g. `proxy.foo.bar.baz`
18
+
19
+ def __getattr__(self, attr: str) -> object:
20
+ proxied = self.__get_proxied__()
21
+ if isinstance(proxied, LazyProxy):
22
+ return proxied # pyright: ignore
23
+ return getattr(proxied, attr)
24
+
25
+ @override
26
+ def __repr__(self) -> str:
27
+ proxied = self.__get_proxied__()
28
+ if isinstance(proxied, LazyProxy):
29
+ return proxied.__class__.__name__
30
+ return repr(self.__get_proxied__())
31
+
32
+ @override
33
+ def __str__(self) -> str:
34
+ proxied = self.__get_proxied__()
35
+ if isinstance(proxied, LazyProxy):
36
+ return proxied.__class__.__name__
37
+ return str(proxied)
38
+
39
+ @override
40
+ def __dir__(self) -> Iterable[str]:
41
+ proxied = self.__get_proxied__()
42
+ if isinstance(proxied, LazyProxy):
43
+ return []
44
+ return proxied.__dir__()
45
+
46
+ @property # type: ignore
47
+ @override
48
+ def __class__(self) -> type: # pyright: ignore
49
+ try:
50
+ proxied = self.__get_proxied__()
51
+ except Exception:
52
+ return type(self)
53
+ if issubclass(type(proxied), LazyProxy):
54
+ return type(proxied)
55
+ return proxied.__class__
56
+
57
+ def __get_proxied__(self) -> T:
58
+ return self.__load__()
59
+
60
+ def __as_proxied__(self) -> T:
61
+ """Helper method that returns the current proxy, typed as the loaded object"""
62
+ return cast(T, self)
63
+
64
+ @abstractmethod
65
+ def __load__(self) -> T: ...
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_reflection.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import inspect
4
+ from typing import Any, Callable
5
+
6
+
7
+ def function_has_argument(func: Callable[..., Any], arg_name: str) -> bool:
8
+ """Returns whether or not the given function has a specific parameter"""
9
+ sig = inspect.signature(func)
10
+ return arg_name in sig.parameters
11
+
12
+
13
+ def assert_signatures_in_sync(
14
+ source_func: Callable[..., Any],
15
+ check_func: Callable[..., Any],
16
+ *,
17
+ exclude_params: set[str] = set(),
18
+ ) -> None:
19
+ """Ensure that the signature of the second function matches the first."""
20
+
21
+ check_sig = inspect.signature(check_func)
22
+ source_sig = inspect.signature(source_func)
23
+
24
+ errors: list[str] = []
25
+
26
+ for name, source_param in source_sig.parameters.items():
27
+ if name in exclude_params:
28
+ continue
29
+
30
+ custom_param = check_sig.parameters.get(name)
31
+ if not custom_param:
32
+ errors.append(f"the `{name}` param is missing")
33
+ continue
34
+
35
+ if custom_param.annotation != source_param.annotation:
36
+ errors.append(
37
+ f"types for the `{name}` param are do not match; source={repr(source_param.annotation)} checking={repr(custom_param.annotation)}"
38
+ )
39
+ continue
40
+
41
+ if errors:
42
+ raise AssertionError(f"{len(errors)} errors encountered when comparing signatures:\n\n" + "\n\n".join(errors))
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_resources_proxy.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+ from typing_extensions import override
5
+
6
+ from ._proxy import LazyProxy
7
+
8
+
9
+ class ResourcesProxy(LazyProxy[Any]):
10
+ """A proxy for the `anthropic.resources` module.
11
+
12
+ This is used so that we can lazily import `anthropic.resources` only when
13
+ needed *and* so that users can just import `anthropic` and reference `anthropic.resources`
14
+ """
15
+
16
+ @override
17
+ def __load__(self) -> Any:
18
+ import importlib
19
+
20
+ mod = importlib.import_module("anthropic.resources")
21
+ return mod
22
+
23
+
24
+ resources = ResourcesProxy().__as_proxied__()
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_streams.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any
2
+ from typing_extensions import Iterator, AsyncIterator
3
+
4
+
5
+ def consume_sync_iterator(iterator: Iterator[Any]) -> None:
6
+ for _ in iterator:
7
+ ...
8
+
9
+
10
+ async def consume_async_iterator(iterator: AsyncIterator[Any]) -> None:
11
+ async for _ in iterator:
12
+ ...
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_sync.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ import functools
5
+ from typing import TypeVar, Callable, Awaitable
6
+ from typing_extensions import ParamSpec
7
+
8
+ import anyio
9
+ import sniffio
10
+ import anyio.to_thread
11
+
12
+ T_Retval = TypeVar("T_Retval")
13
+ T_ParamSpec = ParamSpec("T_ParamSpec")
14
+
15
+
16
+ async def to_thread(
17
+ func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
18
+ ) -> T_Retval:
19
+ if sniffio.current_async_library() == "asyncio":
20
+ return await asyncio.to_thread(func, *args, **kwargs)
21
+
22
+ return await anyio.to_thread.run_sync(
23
+ functools.partial(func, *args, **kwargs),
24
+ )
25
+
26
+
27
+ # inspired by `asyncer`, https://github.com/tiangolo/asyncer
28
+ def asyncify(function: Callable[T_ParamSpec, T_Retval]) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
29
+ """
30
+ Take a blocking function and create an async one that receives the same
31
+ positional and keyword arguments.
32
+
33
+ Usage:
34
+
35
+ ```python
36
+ def blocking_func(arg1, arg2, kwarg1=None):
37
+ # blocking code
38
+ return result
39
+
40
+
41
+ result = asyncify(blocking_function)(arg1, arg2, kwarg1=value1)
42
+ ```
43
+
44
+ ## Arguments
45
+
46
+ `function`: a blocking regular callable (e.g. a function)
47
+
48
+ ## Return
49
+
50
+ An async function that takes the same positional and keyword arguments as the
51
+ original one, that when called runs the same original function in a thread worker
52
+ and returns the result.
53
+ """
54
+
55
+ async def wrapper(*args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs) -> T_Retval:
56
+ return await to_thread(function, *args, **kwargs)
57
+
58
+ return wrapper
data/conda_envs/evalclaw/lib/python3.11/site-packages/anthropic/_utils/_transform.py ADDED
@@ -0,0 +1,457 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import io
4
+ import base64
5
+ import pathlib
6
+ from typing import Any, Mapping, TypeVar, cast
7
+ from datetime import date, datetime
8
+ from typing_extensions import Literal, get_args, override, get_type_hints as _get_type_hints
9
+
10
+ import anyio
11
+ import pydantic
12
+
13
+ from ._utils import (
14
+ is_list,
15
+ is_given,
16
+ lru_cache,
17
+ is_mapping,
18
+ is_iterable,
19
+ is_sequence,
20
+ )
21
+ from .._files import is_base64_file_input
22
+ from ._compat import get_origin, is_typeddict
23
+ from ._typing import (
24
+ is_list_type,
25
+ is_union_type,
26
+ extract_type_arg,
27
+ is_iterable_type,
28
+ is_required_type,
29
+ is_sequence_type,
30
+ is_annotated_type,
31
+ strip_annotated_type,
32
+ )
33
+
34
+ _T = TypeVar("_T")
35
+
36
+
37
+ # TODO: support for drilling globals() and locals()
38
+ # TODO: ensure works correctly with forward references in all cases
39
+
40
+
41
+ PropertyFormat = Literal["iso8601", "base64", "custom"]
42
+
43
+
44
+ class PropertyInfo:
45
+ """Metadata class to be used in Annotated types to provide information about a given type.
46
+
47
+ For example:
48
+
49
+ class MyParams(TypedDict):
50
+ account_holder_name: Annotated[str, PropertyInfo(alias='accountHolderName')]
51
+
52
+ This means that {'account_holder_name': 'Robert'} will be transformed to {'accountHolderName': 'Robert'} before being sent to the API.
53
+ """
54
+
55
+ alias: str | None
56
+ format: PropertyFormat | None
57
+ format_template: str | None
58
+ discriminator: str | None
59
+
60
+ def __init__(
61
+ self,
62
+ *,
63
+ alias: str | None = None,
64
+ format: PropertyFormat | None = None,
65
+ format_template: str | None = None,
66
+ discriminator: str | None = None,
67
+ ) -> None:
68
+ self.alias = alias
69
+ self.format = format
70
+ self.format_template = format_template
71
+ self.discriminator = discriminator
72
+
73
+ @override
74
+ def __repr__(self) -> str:
75
+ return f"{self.__class__.__name__}(alias='{self.alias}', format={self.format}, format_template='{self.format_template}', discriminator='{self.discriminator}')"
76
+
77
+
78
+ def maybe_transform(
79
+ data: object,
80
+ expected_type: object,
81
+ ) -> Any | None:
82
+ """Wrapper over `transform()` that allows `None` to be passed.
83
+
84
+ See `transform()` for more details.
85
+ """
86
+ if data is None:
87
+ return None
88
+ return transform(data, expected_type)
89
+
90
+
91
+ # Wrapper over _transform_recursive providing fake types
92
+ def transform(
93
+ data: _T,
94
+ expected_type: object,
95
+ ) -> _T:
96
+ """Transform dictionaries based off of type information from the given type, for example:
97
+
98
+ ```py
99
+ class Params(TypedDict, total=False):
100
+ card_id: Required[Annotated[str, PropertyInfo(alias="cardID")]]
101
+
102
+
103
+ transformed = transform({"card_id": "<my card ID>"}, Params)
104
+ # {'cardID': '<my card ID>'}
105
+ ```
106
+
107
+ Any keys / data that does not have type information given will be included as is.
108
+
109
+ It should be noted that the transformations that this function does are not represented in the type system.
110
+ """
111
+ transformed = _transform_recursive(data, annotation=cast(type, expected_type))
112
+ return cast(_T, transformed)
113
+
114
+
115
+ @lru_cache(maxsize=8096)
116
+ def _get_annotated_type(type_: type) -> type | None:
117
+ """If the given type is an `Annotated` type then it is returned, if not `None` is returned.
118
+
119
+ This also unwraps the type when applicable, e.g. `Required[Annotated[T, ...]]`
120
+ """
121
+ if is_required_type(type_):
122
+ # Unwrap `Required[Annotated[T, ...]]` to `Annotated[T, ...]`
123
+ type_ = get_args(type_)[0]
124
+
125
+ if is_annotated_type(type_):
126
+ return type_
127
+
128
+ return None
129
+
130
+
131
+ def _maybe_transform_key(key: str, type_: type) -> str:
132
+ """Transform the given `data` based on the annotations provided in `type_`.
133
+
134
+ Note: this function only looks at `Annotated` types that contain `PropertyInfo` metadata.
135
+ """
136
+ annotated_type = _get_annotated_type(type_)
137
+ if annotated_type is None:
138
+ # no `Annotated` definition for this type, no transformation needed
139
+ return key
140
+
141
+ # ignore the first argument as it is the actual type
142
+ annotations = get_args(annotated_type)[1:]
143
+ for annotation in annotations:
144
+ if isinstance(annotation, PropertyInfo) and annotation.alias is not None:
145
+ return annotation.alias
146
+
147
+ return key
148
+
149
+
150
+ def _no_transform_needed(annotation: type) -> bool:
151
+ return annotation == float or annotation == int
152
+
153
+
154
+ def _transform_recursive(
155
+ data: object,
156
+ *,
157
+ annotation: type,
158
+ inner_type: type | None = None,
159
+ ) -> object:
160
+ """Transform the given data against the expected type.
161
+
162
+ Args:
163
+ annotation: The direct type annotation given to the particular piece of data.
164
+ This may or may not be wrapped in metadata types, e.g. `Required[T]`, `Annotated[T, ...]` etc
165
+
166
+ inner_type: If applicable, this is the "inside" type. This is useful in certain cases where the outside type
167
+ is a container type such as `List[T]`. In that case `inner_type` should be set to `T` so that each entry in
168
+ the list can be transformed using the metadata from the container type.
169
+
170
+ Defaults to the same value as the `annotation` argument.
171
+ """
172
+ from .._compat import model_dump
173
+
174
+ if inner_type is None:
175
+ inner_type = annotation
176
+
177
+ stripped_type = strip_annotated_type(inner_type)
178
+ origin = get_origin(stripped_type) or stripped_type
179
+ if is_typeddict(stripped_type) and is_mapping(data):
180
+ return _transform_typeddict(data, stripped_type)
181
+
182
+ if origin == dict and is_mapping(data):
183
+ items_type = get_args(stripped_type)[1]
184
+ return {key: _transform_recursive(value, annotation=items_type) for key, value in data.items()}
185
+
186
+ if (
187
+ # List[T]
188
+ (is_list_type(stripped_type) and is_list(data))
189
+ # Iterable[T]
190
+ or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
191
+ # Sequence[T]
192
+ or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
193
+ ):
194
+ # dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
195
+ # intended as an iterable, so we don't transform it.
196
+ if isinstance(data, dict):
197
+ return cast(object, data)
198
+
199
+ inner_type = extract_type_arg(stripped_type, 0)
200
+ if _no_transform_needed(inner_type):
201
+ # for some types there is no need to transform anything, so we can get a small
202
+ # perf boost from skipping that work.
203
+ #
204
+ # but we still need to convert to a list to ensure the data is json-serializable
205
+ if is_list(data):
206
+ return data
207
+ return list(data)
208
+
209
+ return [_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]
210
+
211
+ if is_union_type(stripped_type):
212
+ # For union types we run the transformation against all subtypes to ensure that everything is transformed.
213
+ #
214
+ # TODO: there may be edge cases where the same normalized field name will transform to two different names
215
+ # in different subtypes.
216
+ for subtype in get_args(stripped_type):
217
+ data = _transform_recursive(data, annotation=annotation, inner_type=subtype)
218
+ return data
219
+
220
+ if isinstance(data, pydantic.BaseModel):
221
+ return model_dump(data, exclude_unset=True, mode="json", exclude=getattr(data, "__api_exclude__", None))
222
+
223
+ annotated_type = _get_annotated_type(annotation)
224
+ if annotated_type is None:
225
+ return data
226
+
227
+ # ignore the first argument as it is the actual type
228
+ annotations = get_args(annotated_type)[1:]
229
+ for annotation in annotations:
230
+ if isinstance(annotation, PropertyInfo) and annotation.format is not None:
231
+ return _format_data(data, annotation.format, annotation.format_template)
232
+
233
+ return data
234
+
235
+
236
+ def _format_data(data: object, format_: PropertyFormat, format_template: str | None) -> object:
237
+ if isinstance(data, (date, datetime)):
238
+ if format_ == "iso8601":
239
+ return data.isoformat()
240
+
241
+ if format_ == "custom" and format_template is not None:
242
+ return data.strftime(format_template)
243
+
244
+ if format_ == "base64" and is_base64_file_input(data):
245
+ binary: str | bytes | None = None
246
+
247
+ if isinstance(data, pathlib.Path):
248
+ binary = data.read_bytes()
249
+ elif isinstance(data, io.IOBase):
250
+ binary = data.read()
251
+
252
+ if isinstance(binary, str): # type: ignore[unreachable]
253
+ binary = binary.encode()
254
+
255
+ if not isinstance(binary, bytes):
256
+ raise RuntimeError(f"Could not read bytes from {data}; Received {type(binary)}")
257
+
258
+ return base64.b64encode(binary).decode("ascii")
259
+
260
+ return data
261
+
262
+
263
+ def _transform_typeddict(
264
+ data: Mapping[str, object],
265
+ expected_type: type,
266
+ ) -> Mapping[str, object]:
267
+ result: dict[str, object] = {}
268
+ annotations = get_type_hints(expected_type, include_extras=True)
269
+ for key, value in data.items():
270
+ if not is_given(value):
271
+ # we don't need to include omitted values here as they'll
272
+ # be stripped out before the request is sent anyway
273
+ continue
274
+
275
+ type_ = annotations.get(key)
276
+ if type_ is None:
277
+ # we do not have a type annotation for this field, leave it as is
278
+ result[key] = value
279
+ else:
280
+ result[_maybe_transform_key(key, type_)] = _transform_recursive(value, annotation=type_)
281
+ return result
282
+
283
+
284
+ async def async_maybe_transform(
285
+ data: object,
286
+ expected_type: object,
287
+ ) -> Any | None:
288
+ """Wrapper over `async_transform()` that allows `None` to be passed.
289
+
290
+ See `async_transform()` for more details.
291
+ """
292
+ if data is None:
293
+ return None
294
+ return await async_transform(data, expected_type)
295
+
296
+
297
+ async def async_transform(
298
+ data: _T,
299
+ expected_type: object,
300
+ ) -> _T:
301
+ """Transform dictionaries based off of type information from the given type, for example:
302
+
303
+ ```py
304
+ class Params(TypedDict, total=False):
305
+ card_id: Required[Annotated[str, PropertyInfo(alias="cardID")]]
306
+
307
+
308
+ transformed = transform({"card_id": "<my card ID>"}, Params)
309
+ # {'cardID': '<my card ID>'}
310
+ ```
311
+
312
+ Any keys / data that does not have type information given will be included as is.
313
+
314
+ It should be noted that the transformations that this function does are not represented in the type system.
315
+ """
316
+ transformed = await _async_transform_recursive(data, annotation=cast(type, expected_type))
317
+ return cast(_T, transformed)
318
+
319
+
320
+ async def _async_transform_recursive(
321
+ data: object,
322
+ *,
323
+ annotation: type,
324
+ inner_type: type | None = None,
325
+ ) -> object:
326
+ """Transform the given data against the expected type.
327
+
328
+ Args:
329
+ annotation: The direct type annotation given to the particular piece of data.
330
+ This may or may not be wrapped in metadata types, e.g. `Required[T]`, `Annotated[T, ...]` etc
331
+
332
+ inner_type: If applicable, this is the "inside" type. This is useful in certain cases where the outside type
333
+ is a container type such as `List[T]`. In that case `inner_type` should be set to `T` so that each entry in
334
+ the list can be transformed using the metadata from the container type.
335
+
336
+ Defaults to the same value as the `annotation` argument.
337
+ """
338
+ from .._compat import model_dump
339
+
340
+ if inner_type is None:
341
+ inner_type = annotation
342
+
343
+ stripped_type = strip_annotated_type(inner_type)
344
+ origin = get_origin(stripped_type) or stripped_type
345
+ if is_typeddict(stripped_type) and is_mapping(data):
346
+ return await _async_transform_typeddict(data, stripped_type)
347
+
348
+ if origin == dict and is_mapping(data):
349
+ items_type = get_args(stripped_type)[1]
350
+ return {key: _transform_recursive(value, annotation=items_type) for key, value in data.items()}
351
+
352
+ if (
353
+ # List[T]
354
+ (is_list_type(stripped_type) and is_list(data))
355
+ # Iterable[T]
356
+ or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
357
+ # Sequence[T]
358
+ or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
359
+ ):
360
+ # dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
361
+ # intended as an iterable, so we don't transform it.
362
+ if isinstance(data, dict):
363
+ return cast(object, data)
364
+
365
+ inner_type = extract_type_arg(stripped_type, 0)
366
+ if _no_transform_needed(inner_type):
367
+ # for some types there is no need to transform anything, so we can get a small
368
+ # perf boost from skipping that work.
369
+ #
370
+ # but we still need to convert to a list to ensure the data is json-serializable
371
+ if is_list(data):
372
+ return data
373
+ return list(data)
374
+
375
+ return [await _async_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]
376
+
377
+ if is_union_type(stripped_type):
378
+ # For union types we run the transformation against all subtypes to ensure that everything is transformed.
379
+ #
380
+ # TODO: there may be edge cases where the same normalized field name will transform to two different names
381
+ # in different subtypes.
382
+ for subtype in get_args(stripped_type):
383
+ data = await _async_transform_recursive(data, annotation=annotation, inner_type=subtype)
384
+ return data
385
+
386
+ if isinstance(data, pydantic.BaseModel):
387
+ return model_dump(data, exclude_unset=True, mode="json")
388
+
389
+ annotated_type = _get_annotated_type(annotation)
390
+ if annotated_type is None:
391
+ return data
392
+
393
+ # ignore the first argument as it is the actual type
394
+ annotations = get_args(annotated_type)[1:]
395
+ for annotation in annotations:
396
+ if isinstance(annotation, PropertyInfo) and annotation.format is not None:
397
+ return await _async_format_data(data, annotation.format, annotation.format_template)
398
+
399
+ return data
400
+
401
+
402
+ async def _async_format_data(data: object, format_: PropertyFormat, format_template: str | None) -> object:
403
+ if isinstance(data, (date, datetime)):
404
+ if format_ == "iso8601":
405
+ return data.isoformat()
406
+
407
+ if format_ == "custom" and format_template is not None:
408
+ return data.strftime(format_template)
409
+
410
+ if format_ == "base64" and is_base64_file_input(data):
411
+ binary: str | bytes | None = None
412
+
413
+ if isinstance(data, pathlib.Path):
414
+ binary = await anyio.Path(data).read_bytes()
415
+ elif isinstance(data, io.IOBase):
416
+ binary = data.read()
417
+
418
+ if isinstance(binary, str): # type: ignore[unreachable]
419
+ binary = binary.encode()
420
+
421
+ if not isinstance(binary, bytes):
422
+ raise RuntimeError(f"Could not read bytes from {data}; Received {type(binary)}")
423
+
424
+ return base64.b64encode(binary).decode("ascii")
425
+
426
+ return data
427
+
428
+
429
+ async def _async_transform_typeddict(
430
+ data: Mapping[str, object],
431
+ expected_type: type,
432
+ ) -> Mapping[str, object]:
433
+ result: dict[str, object] = {}
434
+ annotations = get_type_hints(expected_type, include_extras=True)
435
+ for key, value in data.items():
436
+ if not is_given(value):
437
+ # we don't need to include omitted values here as they'll
438
+ # be stripped out before the request is sent anyway
439
+ continue
440
+
441
+ type_ = annotations.get(key)
442
+ if type_ is None:
443
+ # we do not have a type annotation for this field, leave it as is
444
+ result[key] = value
445
+ else:
446
+ result[_maybe_transform_key(key, type_)] = await _async_transform_recursive(value, annotation=type_)
447
+ return result
448
+
449
+
450
+ @lru_cache(maxsize=8096)
451
+ def get_type_hints(
452
+ obj: Any,
453
+ globalns: dict[str, Any] | None = None,
454
+ localns: Mapping[str, Any] | None = None,
455
+ include_extras: bool = False,
456
+ ) -> dict[str, Any]:
457
+ return _get_type_hints(obj, globalns=globalns, localns=localns, include_extras=include_extras)