MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / JSONObject

Function JSONObject

tools/python-3.11.9-amd64/Lib/json/decoder.py:136–215  ·  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

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

Callers

nothing calls this directly

Calls 3

scan_onceFunction · 0.85
JSONDecodeErrorClass · 0.70
endMethod · 0.45

Tested by

no test coverage detected