kipy_ldjson_reader/ldjson.py
def ldjson(stream, buffer_size=64*1024):
    """
    Iterates through each json document in a stream.

    :param stream:
    :param buffer_size:
    """
    buffer = ""
    decoder = json.JSONDecoder()
    error_position = -1
    exception = None

    while True:
        index = 0
        block = stream.read(buffer_size)

        if not block:  # If end of stream
            if exception:  # If end of stream and exception, then rethrow it
                raise exception
            break  # otherwise exit

        buffer = buffer + block
        buffer_len = len(buffer)
        exception = None

        try:
            while True:
                # We looks for the first non-whitespace character
                m = _leading_space_regex.search(buffer, index)

                # If there is no match - then we have only whitespace
                if m is None:
                    buffer = ''
                    break

                index = m.start()

                # if we've move beyond the end of the buffer, then there's nothing to evaluate
                if index >= buffer_len:
                    buffer = ''
                    break  # Read next block

                val, index = decoder.raw_decode(buffer, index)
                error_position = -1

                yield val

        except JSONDecodeError as ex:
            # If error is same position as previous error, then it's a physical error
            if ex.pos == error_position:
                raise ex

            exception = ex
            error_position = ex.pos

            if index > 0:
                buffer = buffer[index:]

    Iterates through each json document in a stream.

    :param stream:
    :param buffer_size:
    
Iterates through each json document in a stream.
Iterates through each json document in a stream .
def ldjson(stream, buffer_size=64*1024):
    buffer = ""
    decoder = json.JSONDecoder()
    error_position = -1
    exception = None
    while True:
        index = 0
        block = stream.read(buffer_size)
        if not block:  
            if exception:   and exception, then rethrow it
                raise exception
            break  
        buffer = buffer + block
        buffer_len = len(buffer)
        exception = None
        try:
            while True:
                m = _leading_space_regex.search(buffer, index)
                if m is None:
                    buffer = ''
                    break
                index = m.start()
                if index >= buffer_len:
                    buffer = ''
                    break  
                val, index = decoder.raw_decode(buffer, index)
                error_position = -1
                yield val
        except JSONDecodeError as ex:
            if ex.pos == error_position:
                raise ex
            exception = ex
            error_position = ex.pos
            if index > 0:
                buffer = buffer[index:]
def ldjson ( stream , buffer_size = 64 * 1024 ) : buffer = "" decoder = json . JSONDecoder ( ) error_position = - 1 exception = None while True : index = 0 block = stream . read ( buffer_size ) if not block : if exception : raise exception break buffer = buffer + block buffer_len = len ( buffer ) exception = None try : while True : m = _leading_space_regex . search ( buffer , index ) if m is None : buffer = '' break index = m . start ( ) if index >= buffer_len : buffer = '' break val , index = decoder . raw_decode ( buffer , index ) error_position = - 1 yield val except JSONDecodeError as ex : if ex . pos == error_position : raise ex exception = ex error_position = ex . pos if index > 0 : buffer = buffer [ index : ]
Iterates through each json document in a stream.
Iterates through each json document in a stream .
"""
    Iterates through each json document in a stream.

    :param stream:
    :param buffer_size:
    """ # If end of stream # If end of stream and exception, then rethrow it # otherwise exit # We looks for the first non-whitespace character # If there is no match - then we have only whitespace # if we've move beyond the end of the buffer, then there's nothing to evaluate # Read next block # If error is same position as previous error, then it's a physical error
stream
None
buffer_size
None