MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / Querystring

Class Querystring

src/anthropic/_qs.py:20–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19
20class Querystring:
21 array_format: ArrayFormat
22 nested_format: NestedFormat
23
24 def __init__(
25 self,
26 *,
27 array_format: ArrayFormat = "repeat",
28 nested_format: NestedFormat = "brackets",
29 ) -> None:
30 self.array_format = array_format
31 self.nested_format = nested_format
32
33 def parse(self, query: str) -> Mapping[str, object]:
34 # Note: custom format syntax is not supported yet
35 return parse_qs(query)
36
37 def stringify(
38 self,
39 params: Params,
40 *,
41 array_format: ArrayFormat | NotGiven = not_given,
42 nested_format: NestedFormat | NotGiven = not_given,
43 ) -> str:
44 return urlencode(
45 self.stringify_items(
46 params,
47 array_format=array_format,
48 nested_format=nested_format,
49 )
50 )
51
52 def stringify_items(
53 self,
54 params: Params,
55 *,
56 array_format: ArrayFormat | NotGiven = not_given,
57 nested_format: NestedFormat | NotGiven = not_given,
58 ) -> list[tuple[str, str]]:
59 opts = Options(
60 qs=self,
61 array_format=array_format,
62 nested_format=nested_format,
63 )
64 return flatten([self._stringify_item(key, value, opts) for key, value in params.items()])
65
66 def _stringify_item(
67 self,
68 key: str,
69 value: Data,
70 opts: Options,
71 ) -> list[tuple[str, str]]:
72 if isinstance(value, Mapping):
73 items: list[tuple[str, str]] = []
74 nested_format = opts.nested_format
75 for subkey, subvalue in value.items():
76 items.extend(
77 self._stringify_item(

Callers 9

test_nested_dottedFunction · 0.90
test_array_commaFunction · 0.90
test_array_bracketsFunction · 0.90
qsMethod · 0.85
qsMethod · 0.85
qsMethod · 0.85
_qs.pyFile · 0.85
qsMethod · 0.85
qsMethod · 0.85

Calls

no outgoing calls

Tested by 3

test_nested_dottedFunction · 0.72
test_array_commaFunction · 0.72
test_array_bracketsFunction · 0.72