MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / _stringify_item

Method _stringify_item

src/opencode_ai/_qs.py:69–119  ·  view source on GitHub ↗
(
        self,
        key: str,
        value: Data,
        opts: Options,
    )

Source from the content-addressed store, hash-verified

67 return flatten([self._stringify_item(key, value, opts) for key, value in params.items()])
68
69 def _stringify_item(
70 self,
71 key: str,
72 value: Data,
73 opts: Options,
74 ) -> list[tuple[str, str]]:
75 if isinstance(value, Mapping):
76 items: list[tuple[str, str]] = []
77 nested_format = opts.nested_format
78 for subkey, subvalue in value.items():
79 items.extend(
80 self._stringify_item(
81 # TODO: error if unknown format
82 f"{key}.{subkey}" if nested_format == "dots" else f"{key}[{subkey}]",
83 subvalue,
84 opts,
85 )
86 )
87 return items
88
89 if isinstance(value, (list, tuple)):
90 array_format = opts.array_format
91 if array_format == "comma":
92 return [
93 (
94 key,
95 ",".join(self._primitive_value_to_str(item) for item in value if item is not None),
96 ),
97 ]
98 elif array_format == "repeat":
99 items = []
100 for item in value:
101 items.extend(self._stringify_item(key, item, opts))
102 return items
103 elif array_format == "indices":
104 raise NotImplementedError("The array indices format is not supported yet")
105 elif array_format == "brackets":
106 items = []
107 key = key + "[]"
108 for item in value:
109 items.extend(self._stringify_item(key, item, opts))
110 return items
111 else:
112 raise NotImplementedError(
113 f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}"
114 )
115
116 serialised = self._primitive_value_to_str(value)
117 if not serialised:
118 return []
119 return [(key, serialised)]
120
121 def _primitive_value_to_str(self, value: PrimitiveData) -> str:
122 # copied from httpx

Callers 1

stringify_itemsMethod · 0.95

Calls 2

get_argsFunction · 0.85

Tested by

no test coverage detected