MCPcopy Index your code
hub / github.com/clips/pattern / JSONObject

Function JSONObject

pattern/web/json/decoder.py:180–274  ·  view source on GitHub ↗
((s, end), encoding, strict, scan_once, object_hook,
        object_pairs_hook, memo=None,
        _w=WHITESPACE.match, _ws=WHITESPACE_STR)

Source from the content-addressed store, hash-verified

178WHITESPACE_STR = ' \t\n\r'
179
180def JSONObject((s, end), encoding, strict, scan_once, object_hook,
181 object_pairs_hook, memo=None,
182 _w=WHITESPACE.match, _ws=WHITESPACE_STR):
183 # Backwards compatibility
184 if memo is None:
185 memo = {}
186 memo_get = memo.setdefault
187 pairs = []
188 # Use a slice to prevent IndexError from being raised, the following
189 # check will raise a more specific ValueError if the string is empty
190 nextchar = s[end:end + 1]
191 # Normally we expect nextchar == '"'
192 if nextchar != '"':
193 if nextchar in _ws:
194 end = _w(s, end).end()
195 nextchar = s[end:end + 1]
196 # Trivial empty object
197 if nextchar == '}':
198 if object_pairs_hook is not None:
199 result = object_pairs_hook(pairs)
200 return result, end + 1
201 pairs = {}
202 if object_hook is not None:
203 pairs = object_hook(pairs)
204 return pairs, end + 1
205 elif nextchar != '"':
206 raise JSONDecodeError(
207 "Expecting property name enclosed in double quotes",
208 s, end)
209 end += 1
210 while True:
211 key, end = scanstring(s, end, encoding, strict)
212 key = memo_get(key, key)
213
214 # To skip some function call overhead we optimize the fast paths where
215 # the JSON key separator is ": " or just ":".
216 if s[end:end + 1] != ':':
217 end = _w(s, end).end()
218 if s[end:end + 1] != ':':
219 raise JSONDecodeError("Expecting ':' delimiter", s, end)
220
221 end += 1
222
223 try:
224 if s[end] in _ws:
225 end += 1
226 if s[end] in _ws:
227 end = _w(s, end + 1).end()
228 except IndexError:
229 pass
230
231 try:
232 value, end = scan_once(s, end)
233 except StopIteration:
234 raise JSONDecodeError("Expecting object", s, end)
235 pairs.append((key, value))
236
237 try:

Callers

nothing calls this directly

Calls 3

JSONDecodeErrorClass · 0.85
scan_onceFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…