MCPcopy Index your code
hub / github.com/RustPython/RustPython / JSONObject

Function JSONObject

Lib/json/decoder.py:151–233  ·  view source on GitHub ↗
(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
               memo=None, _w=WHITESPACE.match, _ws=WHITESPACE_STR)

Source from the content-addressed store, hash-verified

149
150
151def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
152 memo=None, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
153 s, end = s_and_end
154 pairs = []
155 pairs_append = pairs.append
156 # Backwards compatibility
157 if memo is None:
158 memo = {}
159 memo_get = memo.setdefault
160 # Use a slice to prevent IndexError from being raised, the following
161 # check will raise a more specific ValueError if the string is empty
162 nextchar = s[end:end + 1]
163 # Normally we expect nextchar == '"'
164 if nextchar != '"':
165 if nextchar in _ws:
166 end = _w(s, end).end()
167 nextchar = s[end:end + 1]
168 # Trivial empty object
169 if nextchar == '}':
170 if object_pairs_hook is not None:
171 result = object_pairs_hook(pairs)
172 return result, end + 1
173 pairs = {}
174 if object_hook is not None:
175 pairs = object_hook(pairs)
176 return pairs, end + 1
177 elif nextchar != '"':
178 raise JSONDecodeError(
179 "Expecting property name enclosed in double quotes", s, end)
180 end += 1
181 while True:
182 key, end = scanstring(s, end, strict)
183 key = memo_get(key, key)
184 # To skip some function call overhead we optimize the fast paths where
185 # the JSON key separator is ": " or just ":".
186 if s[end:end + 1] != ':':
187 end = _w(s, end).end()
188 if s[end:end + 1] != ':':
189 raise JSONDecodeError("Expecting ':' delimiter", s, end)
190 end += 1
191
192 try:
193 if s[end] in _ws:
194 end += 1
195 if s[end] in _ws:
196 end = _w(s, end + 1).end()
197 except IndexError:
198 pass
199
200 try:
201 value, end = scan_once(s, end)
202 except StopIteration as err:
203 raise JSONDecodeError("Expecting value", s, err.value) from None
204 pairs_append((key, value))
205 try:
206 nextchar = s[end]
207 if nextchar in _ws:
208 end = _w(s, end + 1).end()

Callers

nothing calls this directly

Calls 4

JSONDecodeErrorClass · 0.85
scan_onceFunction · 0.85
scanstringFunction · 0.50
endMethod · 0.45

Tested by

no test coverage detected