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

Function _make_iterencode

Lib/json/encoder.py:265–461  ·  view source on GitHub ↗
(markers, _default, _encoder, _indent, _floatstr,
        _key_separator, _item_separator, _sort_keys, _skipkeys, _one_shot,
        ## HACK: hand-optimized bytecode; turn globals into locals
        ValueError=ValueError,
        dict=dict,
        float=float,
        id=id,
        int=int,
        isinstance=isinstance,
        list=list,
        str=str,
        tuple=tuple,
        _intstr=int.__repr__,
    )

Source from the content-addressed store, hash-verified

263 return _iterencode(o, 0)
264
265def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
266 _key_separator, _item_separator, _sort_keys, _skipkeys, _one_shot,
267 ## HACK: hand-optimized bytecode; turn globals into locals
268 ValueError=ValueError,
269 dict=dict,
270 float=float,
271 id=id,
272 int=int,
273 isinstance=isinstance,
274 list=list,
275 str=str,
276 tuple=tuple,
277 _intstr=int.__repr__,
278 ):
279
280 def _iterencode_list(lst, _current_indent_level):
281 if not lst:
282 yield '[]'
283 return
284 if markers is not None:
285 markerid = id(lst)
286 if markerid in markers:
287 raise ValueError("Circular reference detected")
288 markers[markerid] = lst
289 buf = '['
290 if _indent is not None:
291 _current_indent_level += 1
292 newline_indent = '\n' + _indent * _current_indent_level
293 separator = _item_separator + newline_indent
294 buf += newline_indent
295 else:
296 newline_indent = None
297 separator = _item_separator
298 for i, value in enumerate(lst):
299 if i:
300 buf = separator
301 try:
302 if isinstance(value, str):
303 yield buf + _encoder(value)
304 elif value is None:
305 yield buf + 'null'
306 elif value is True:
307 yield buf + 'true'
308 elif value is False:
309 yield buf + 'false'
310 elif isinstance(value, int):
311 # Subclasses of int/float may override __repr__, but we still
312 # want to encode them as integers/floats in JSON. One example
313 # within the standard library is IntEnum.
314 yield buf + _intstr(value)
315 elif isinstance(value, float):
316 # see comment above for int
317 yield buf + _floatstr(value)
318 else:
319 yield buf
320 if isinstance(value, (list, tuple)):
321 chunks = _iterencode_list(value, _current_indent_level)
322 elif isinstance(value, dict):

Callers 1

iterencodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected