
    .Ph&                         d Z ddlZddlZddlZdZddgZeddfdZ	  G d d          Zed	k    rd
 Z	 e	             dS dS )z``jsonutils`` aims to provide various helpers for working with
JSON. Currently it focuses on providing a reliable and intuitive means
of working with `JSON Lines`_-formatted files.

.. _JSON Lines: http://jsonlines.org/

    N   JSONLIteratorreverse_iter_linesTc              #     K   	 |p| j         }d}n# t          $ r d}Y nw xY w| }	 |                                } n# t          t          j        f$ r Y nw xY wd\  }}}|r |                     dt          j                   |}|                                 }	d|	k     rt          ||	          }
|	|
z  }	|                     |	t          j
                   |                     |
          }||z   }|                                }t          |          dk     s|d         |k    r|dd         |k    r|r|n|V  |ddd         D ]}|r|                    |          n|V  |d         }d|	k     |r|r|                    |          n|V  dS dS )a;  Returns an iterator over the lines from a file object, in
    reverse order, i.e., last line first, first line last. Uses the
    :meth:`file.seek` method of file objects, and is tested compatible with
    :class:`file` objects, as well as :class:`StringIO.StringIO`.

    Args:
        file_obj (file): An open file object. Note that
            ``reverse_iter_lines`` mutably reads from the file and
            other functions should not mutably interact with the file
            object after being passed. Files can be opened in bytes or
            text mode.
        blocksize (int): The block size to pass to
          :meth:`file.read()`. Warning: keep this a fairly large
          multiple of 2, defaults to 4096.
        preseek (bool): Tells the function whether or not to automatically
            seek to the end of the file. Defaults to ``True``.
            ``preseek=False`` is useful in cases when the
            file cursor is already in position, either at the end of
            the file or in the middle for relative reverse line
            generation.

    zutf-8N)       
 r      )encodingAttributeErrordetachioUnsupportedOperationseekosSEEK_ENDtellminSEEK_SETread
splitlineslendecode)file_obj	blocksizepreseekr   orig_objempty_bytesnewline_bytes
empty_textbuffcur_pos	read_sizecurlineslines                 Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/boltons/jsonutils.pyr   r   3   s     00x0
 	     H??$$B34    .<*K
 &a%%%DmmooG
g++	7++	9gr{+++mmI&&Tz!!u::>>U1X449%% (9**k999%1R%L 	> 	>D+3=$++h'''====Qx g++  :'/9dkk(###T99999: :s   	 : AAc                   N    e Zd ZdZ	 d
dZed             Zd Zd Zd Z	d	 Z
e
ZdS )r   a  The ``JSONLIterator`` is used to iterate over JSON-encoded objects
    stored in the `JSON Lines format`_ (one object per line).

    Most notably it has the ability to efficiently read from the
    bottom of files, making it very effective for reading in simple
    append-only JSONL use cases. It also has the ability to start from
    anywhere in the file and ignore corrupted lines.

    Args:
        file_obj (file): An open file object.
        ignore_errors (bool): Whether to skip over lines that raise an error on
            deserialization (:func:`json.loads`).
        reverse (bool): Controls the direction of the iteration.
            Defaults to ``False``. If set to ``True`` and *rel_seek*
            is unset, seeks to the end of the file before iteration
            begins.
        rel_seek (float): Used to preseek the start position of
            iteration. Set to 0.0 for the start of the file, 1.0 for the
            end, and anything in between.

    .. _JSON Lines format: http://jsonlines.org/
    FNc                 ~   t          |          | _        || _        || _        ||rd}n,d|cxk     rdk     sn t	          d|z            |dk     rd|z
  }|| _        d| _        ||                                  | j        r#t          | j        | j        d          | _	        d S t          | j                  | _	        d S )N      ?g      z8'rel_seek' expected a float between -1.0 and 1.0, not %rr   r   F)r   r   )bool_reverse	_file_objignore_errors
ValueError	_rel_seek
_blocksize_init_rel_seekr   
_line_iteriter)selfr   r/   reverserel_seeks        r(   __init__zJSONLIterator.__init__   s    W!* &&&&3&&&& 57?@ A A A\\X~H!!!!= 	30;??9>@ @ @DOOO #4>22DOOOr   c                 4    | j                                         S )zBA property representing where in the file the iterator is reading.)r.   r   r6   s    r(   cur_byte_poszJSONLIterator.cur_byte_pos   s     ~""$$$r   c                     | j         | j        }}d\  }}|                                }d|vr|                    |          }||z  }d|v	 |                    d          |z   |z
  }n# t
          $ r  w xY w|                    ||z              dS )z6Aligns the file object's position to the next newline.)r	   r   
N)r.   r2   r   r   indexr0   r   )r6   fobsizer%   
total_readr#   newline_offsets          r(   _align_to_newlinezJSONLIterator._align_to_newline   s    NDOEZ''))#oo''%..C%J #oo	 YYt__z9EANN 	 	 		
.()))))s   A' 'A3c                    | j         | j        }}|dk    r"|                    dt          j                   dS |                    dt          j                   |                                }|dk    r	|| _        dS t          ||z            }|                    |t          j                   | 	                                 |                                | _        dS )zCSets the file object's position to the relative location set above.g        r   r+   N)
r1   r.   r   r   r   r   r   _cur_posintrD   )r6   rsr@   sizetargets        r(   r3   zJSONLIterator._init_rel_seek   s    B99GGAr{#####GGAr{###7799DSyy $TBY,,,&&((( "		r   c                     | S )N r;   s    r(   __iter__zJSONLIterator.__iter__   s    r   c                     	 t          | j                                                  }|s*	 t          j        |          }n# t
          $ r | j        s Y Tw xY w|S )zYields one :class:`dict` loaded with :func:`json.loads`, advancing
        the file object by one line. Raises :exc:`StopIteration` upon reaching
        the end of the file (or beginning, if ``reverse`` was set to ``True``.
        )nextr4   lstripjsonloads	Exceptionr/   )r6   r'   objs      r(   rO   zJSONLIterator.next   sx    

	((//11D j&&   )  Js   A AA)FFN)__name__
__module____qualname____doc__r9   propertyr<   rD   r3   rM   rO   __next__rL   r   r(   r   r   {   s         . ?C3 3 3 32 % % X%* * ** * *     " HHHr   __main__c                     dd l } d| j        v s	d| j        v rt          d           d S d}d| j        v s	d| j        v rd}d	\  }}| j        d
d          }|D ]}|dv r|d
z  }t          |d          5 }t	          |          }d}	 	 t          |           nH# t          $ r0 t          d|d
z   d|j        d|           Y d d d             d S t          $ r Y nXw xY w|d
z  }|d
z  }|rG|rE|dz  dk    r<| j	        
                    d           |dz  r| j	        
                    d|z             	 d d d            n# 1 swxY w Y   |r$t          d|z             t          d|z             d S )Nr   -h--helpz7loads one or more JSON Line files for basic validation.F-v	--verboseT)r   r      )r]   r^   r_   r`   rbzerror reading object #z around byte z in d   .i'  z%s
zfiles checked: %szobjects loaded: %s)sysargvprintopenr   rO   r0   r<   StopIterationstdoutwrite)	re   verbose
file_count	obj_count	filenamesfilenamer   iteratorcur_obj_counts	            r(   _mainrs      s   


38x3833KLLLF38{ch66G $
IHQRRL	! 	A 	AH>>>!OJh%% A(22 !AX%   !.!2!2!2H4I4I4I88U V V VA A A A A A A A A )   NI!Q&M A9 ASA1E1E
((---$u, AJ,,Vi-?@@@A A A A A A A A A A A A A A A A$  	4%
2333&2333sC   0D=BD=*C>D=	CD=CAD==E	E	)
rX   r   r   rQ   DEFAULT_BLOCKSIZE__all__r   r   rU   rs   rL   r   r(   <module>rv      s   >  
			 				    0
1 ,=dUY =: =: =: =:Bg g g g g g g gT z# # #J 
EGGGGGM r   