MCPcopy Create free account
hub / github.com/simplejson/simplejson / _iterencode_list

Function _iterencode_list

simplejson/encoder.py:497–578  ·  view source on GitHub ↗
(lst, _current_indent_level)

Source from the content-addressed store, hash-verified

495 return '"' + str(value) + '"'
496
497 def _iterencode_list(lst, _current_indent_level):
498 if not lst:
499 yield '[]'
500 return
501 if markers is not None:
502 markerid = id(lst)
503 if markerid in markers:
504 raise ValueError("Circular reference detected")
505 markers[markerid] = lst
506 buf = '['
507 if _indent is not None:
508 _current_indent_level += 1
509 newline_indent = '\n' + (_indent * _current_indent_level)
510 separator = _item_separator + newline_indent
511 buf += newline_indent
512 else:
513 newline_indent = None
514 separator = _item_separator
515 first = True
516 for i, value in enumerate(lst):
517 if first:
518 first = False
519 else:
520 buf = separator
521 try:
522 if isinstance(value, string_types):
523 yield buf + _encoder(value)
524 elif _PY3 and isinstance(value, bytes) and _encoding is not None:
525 yield buf + _encoder(value)
526 elif isinstance(value, RawJSON):
527 yield buf + value.encoded_json
528 elif value is None:
529 yield buf + 'null'
530 elif value is True:
531 yield buf + 'true'
532 elif value is False:
533 yield buf + 'false'
534 elif isinstance(value, integer_types):
535 yield buf + _encode_int(value)
536 elif isinstance(value, float):
537 yield buf + _floatstr(value)
538 elif _use_decimal and isinstance(value, Decimal):
539 yield buf + str(value)
540 else:
541 yield buf
542 for_json = _for_json and call_method(value, 'for_json')
543 if for_json:
544 chunks = _iterencode(for_json[0], _current_indent_level)
545 else:
546 _asdict = _namedtuple_as_object and call_method(value, '_asdict')
547 if _asdict:
548 dct = _asdict[0]
549 if not isinstance(dct, dict):
550 raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,))
551 chunks = _iterencode_dict(dct,
552 _current_indent_level)
553 elif isinstance(value, list):
554 chunks = _iterencode_list(value, _current_indent_level)

Callers 2

_iterencode_dictFunction · 0.85
_iterencodeFunction · 0.85

Calls 4

_encode_intFunction · 0.85
call_methodFunction · 0.85
_iterencodeFunction · 0.85
_iterencode_dictFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…