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

Function _make_iterencode

simplejson/encoder.py:436–777  ·  view source on GitHub ↗
(markers, _default, _encoder, _indent, _floatstr,
        _key_separator, _item_separator, _sort_keys, _skipkeys,
        _use_decimal, _namedtuple_as_object, _tuple_as_array,
        _int_as_string_bitcount, _item_sort_key,
        _encoding,_for_json,
        _iterable_as_array,
        ## HACK: hand-optimized bytecode; turn globals into locals
        _PY3=PY3,
        ValueError=ValueError,
        string_types=string_types,
        Decimal=None,
        dict=dict,
        _dict_types=_dict_types,
        float=float,
        id=id,
        integer_types=integer_types,
        isinstance=isinstance,
        list=list,
        str=str,
        tuple=tuple,
        iter=iter,
    )

Source from the content-addressed store, hash-verified

434
435
436def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
437 _key_separator, _item_separator, _sort_keys, _skipkeys,
438 _use_decimal, _namedtuple_as_object, _tuple_as_array,
439 _int_as_string_bitcount, _item_sort_key,
440 _encoding,_for_json,
441 _iterable_as_array,
442 ## HACK: hand-optimized bytecode; turn globals into locals
443 _PY3=PY3,
444 ValueError=ValueError,
445 string_types=string_types,
446 Decimal=None,
447 dict=dict,
448 _dict_types=_dict_types,
449 float=float,
450 id=id,
451 integer_types=integer_types,
452 isinstance=isinstance,
453 list=list,
454 str=str,
455 tuple=tuple,
456 iter=iter,
457 ):
458 if _use_decimal and Decimal is None:
459 Decimal = decimal.Decimal
460 if _item_sort_key and not callable(_item_sort_key):
461 raise TypeError("item_sort_key must be None or callable")
462 elif _sort_keys and not _item_sort_key:
463 _item_sort_key = itemgetter(0)
464
465 if (_int_as_string_bitcount is not None and
466 (_int_as_string_bitcount <= 0 or
467 not isinstance(_int_as_string_bitcount, integer_types))):
468 raise TypeError("int_as_string_bitcount must be a positive integer")
469
470 def call_method(obj, method_name):
471 method = getattr(obj, method_name, None)
472 if callable(method):
473 try:
474 return (method(),)
475 except TypeError:
476 pass
477 return None
478
479 def _encode_int(value):
480 skip_quoting = (
481 _int_as_string_bitcount is None
482 or
483 _int_as_string_bitcount < 1
484 )
485 if type(value) not in integer_types:
486 # See #118, do not trust custom str/repr
487 value = int(value)
488 if (
489 skip_quoting or
490 (-1 << _int_as_string_bitcount)
491 < value <
492 (1 << _int_as_string_bitcount)
493 ):

Callers 1

iterencodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…