File: //proc/1233/root/usr/lib/python3/dist-packages/docker/utils/__pycache__/json_stream.cpython-310.pyc
o
�2.a� � @ s\ d dl Z d dlZ ddlmZ e �� Zdd� Zdd� Zdd � Zddd�Z dd
d� fdd�Z
dS )� N� )�StreamParseErrorc c s, � | D ]}t |t�s|�dd�}|V qdS )z�
Given a stream of bytes or text, if any of the items in the stream
are bytes convert them to text.
This function can be removed once we return text streams
instead of byte streams.
zutf-8�replaceN)�
isinstance�str�decode)�stream�data� r
�:/usr/lib/python3/dist-packages/docker/utils/json_stream.py�stream_as_text
s �
�r c C sR | � � } zt�| �\}}| tjj�| |��� d� }||fW S ty( Y dS w )z�Attempt to parse a json object from a buffer. If there is at least one
object, return it and the rest of the buffer, otherwise return None.
N) �strip�json_decoder�
raw_decode�json�decoder�
WHITESPACE�match�end�
ValueError)�buffer�obj�index�restr
r
r �
json_splitter s
�r c C s t | ttj�S )z�Given a stream of text, return a stream of json objects.
This handles streams which are inconsistently buffered (some entries may
be newline delimited, and others are not).
)�split_bufferr r r )r r
r
r �json_stream$ s r �
c C s: | � t|��}|dkr
d S | d |d � | |d d � fS )N���� )�findr )r � separatorr r
r
r �
line_splitter, s r"