
    /;ji                        d dl mZmZmZmZmZmZ d dlZd dlZ	d dl
Z
ddlmZ ddlmZmZmZmZmZ 	 d dedee         d	ed
efdZdeeef         d
efdZded
efdZded
efdZd!deded
ee         fdZd"dededed
dfdZd"dededed
dfdZ	 	 d#dedee         deded
df
dZd!deded
ee         fdZ	 	 d#dedee         deded
df
dZ ded
efdZ!	 d!dee         ded
ee         fdZ"dS )$    )UnionIterableSequenceAnyOptionalIteratorN   )ujson)
force_pathforce_stringFilePath	JSONInput
JSONOutputFdataindent	sort_keysreturnc                 ~    |r#|dk    rdn|}t          j        | |d|          }nt          j        | |d          }|S )a  Serialize an object to a JSON string.

    data: The JSON-serializable data.
    indent (int): Number of spaces used to indent JSON.
    sort_keys (bool): Sort dictionary keys. Falls back to json module for now.
    RETURNS (str): The serialized string.
    r   N),:)r   
separatorsr   F)r   escape_forward_slashes)_builtin_jsondumpsr
   )r   r   r   results       I/root/voice-cloning/.venv/lib/python3.11/site-packages/srsly/_json_api.py
json_dumpsr   
   s]      P1&$J)
 
 
 T&OOOM    c                 T    | dk    rt          d          t          j        |           S )zDeserialize unicode or bytes to a Python object.

    data (str / bytes): The data to deserialize.
    RETURNS: The deserialized Python object.
    -zExpected object or value)
ValueErrorr
   loads)r   s    r   
json_loadsr#      s,     s{{3444;tr   pathc                    | dk    r2t           j                                        }t          j        |          S t          |           }|                    dd          5 }t          j        |          cddd           S # 1 swxY w Y   dS )zLoad JSON from file or standard input.

    path (FilePath): The file path. "-" for reading from stdin.
    RETURNS (JSONOutput): The loaded JSON content.
    r    rutf8encodingN)sysstdinreadr
   r"   r   openload)r$   r   	file_pathfs       r   	read_jsonr1   *   s     s{{y~~{4   4  I	f	-	- z!}}                 s   B  BBc                     t          |           }t          j        |d          5 }t          j        |          cddd           S # 1 swxY w Y   dS )zLoad JSON from a gzipped file.

    location (FilePath): The file path.
    RETURNS (JSONOutput): The loaded JSON content.
    r&   N)r   gzipr-   r
   r.   )r$   r/   r0   s      r   read_gzip_jsonr4   8   s     T""I	9c	"	" az!}}                 s   AA
A
skipc              #      K   t          j        t          |           d          5 }t          ||          D ]}|V  	 ddd           dS # 1 swxY w Y   dS )a  Read a gzipped .jsonl file and yield contents line by line.
    Blank lines will always be skipped.

    path (FilePath): The file path.
    skip (bool): Skip broken lines and don't raise ValueError.
    YIELDS (JSONOutput): The unpacked, deserialized Python objects.
    r&   r5   N)r3   r-   r   _yield_json_lines)r$   r5   r0   lines       r   read_gzip_jsonlr:   C   s       
:d##S	)	) Q%ad333 	 	DJJJJ	                 s   AAA   c                    t          ||          }| dk    rt          |           dS t          | d          }|                    dd          5 }|                    |           ddd           dS # 1 swxY w Y   dS )	a  Create a .json file and dump contents or write to standard
    output.

    location (FilePath): The file path. "-" for writing to stdout.
    data (JSONInput): The JSON-serializable data to output.
    indent (int): Number of spaces used to indent JSON.
    r   r    Frequire_existswr'   r(   N)r   printr   r-   writer$   r   r   	json_datar/   r0   s         r   
write_jsonrE   P   s     4///Is{{itE:::	^^C&^11 	QGGI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A44A8;A8c                     t          ||          }t          |           }t          j        |d          5 }|                    |                    d                     ddd           dS # 1 swxY w Y   dS )zCreate a .json.gz file and dump contents.

    path (FilePath): The file path.
    data (JSONInput): The JSON-serializable data to output.
    indent (int): Number of spaces used to indent JSON.
    r=   r@   utf-8N)r   r   r3   r-   rB   encoderC   s         r   write_gzip_jsonrI   a   s     4///IT""I	9c	"	" +a		  ))***+ + + + + + + + + + + + + + + + + +s   )A,,A03A0Tlinesappendappend_new_linec                 (   |rdnd}t          | d          }t          j        ||          5 }|r*|r(|                    d                    d                     |                    d |D                        d	d	d	           d	S # 1 swxY w Y   d	S )
a  Create a .jsonl.gz file and dump contents.

    location (FilePath): The file path.
    lines (Sequence[JSONInput]): The JSON-serializable contents of each line.
    append (bool): Whether or not to append to the location. Appending to .gz files is generally not recommended, as it
        doesn't allow the algorithm to take advantage of all data when compressing - files may hence be poorly
        compressed.
    append_new_line (bool): Whether or not to write a new line before appending
        to the file.
    ar@   Fr>   )mode
rG   c                 X    g | ]'}t          |          d z                       d          (S )rP   rG   )r   rH   ).0r9   s     r   
<listcomp>z$write_gzip_jsonl.<locals>.<listcomp>   s3    RRRDz$''$.66w??RRRr   N)r   r3   r-   rB   rH   
writelines)r$   rJ   rK   rL   rO   r/   r0   s          r   write_gzip_jsonlrU   n   s      !33cD4666I	94	(	(	( TA 	*o 	*GGDKK(()))	RRERRRSSST T T T T T T T T T T T T T T T T Ts   ABBBc              #     K   | dk    r$t          t          j        |          D ]}|V  dS t          |           }|                    dd          5 }t          ||          D ]}|V  	 ddd           dS # 1 swxY w Y   dS )a2  Read a .jsonl file or standard input and yield contents line by line.
    Blank lines will always be skipped.

    path (FilePath): The file path. "-" for reading from stdin.
    skip (bool): Skip broken lines and don't raise ValueError.
    YIELDS (JSONOutput): The loaded JSON contents of each line.
    r    r7   r&   r'   r(   N)r8   r*   r+   r   r-   )r$   r5   r9   r/   r0   s        r   
read_jsonlrW      s       s{{%cid;;; 	 	DJJJJ	 	 t$$	^^C&^11 	Q)!$777  



	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A::A>A>c                 n   | dk    r#|D ]}t          t          |                     d	S |rdnd}t          | d          }|                    |d          5 }|r|r|                    d           |D ]'}|                    t          |          dz              (	 d	d	d	           d	S # 1 swxY w Y   d	S )
a|  Create a .jsonl file and dump contents or write to standard output.

    location (FilePath): The file path. "-" for writing to stdout.
    lines (Sequence[JSONInput]): The JSON-serializable contents of each line.
    append (bool): Whether or not to append to the location.
    append_new_line (bool): Whether or not to write a new line before appending
        to the file.
    r    rN   r@   Fr>   rG   r(   rP   N)rA   r   r   r-   rB   )r$   rJ   rK   rL   r9   rO   r/   r0   s           r   write_jsonlrY      s,    s{{ 	$ 	$D*T""####	$ 	$ %ss#tE:::	^^D7^33 	1q /  1 1
4((4/00001	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s   AB**B.1B.objc                     t          | d          rdS 	 t          j        |            dS # t          t          f$ r Y dS w xY w)zCheck if a Python object is JSON-serializable.

    obj: The object to check.
    RETURNS (bool): Whether the object is JSON-serializable.
    __call__FT)hasattrr
   r   	TypeErrorOverflowError)rZ   s    r   is_json_serializabler`      s\     sJ uCt}%   uus   * ??streamc              #      K   d}| D ]a}|                                 }|dk    r	 t          j        |          V  n'# t          $ r |rY Ct          d| d|           w xY w|dz  }bd S )Nr	    zInvalid JSON on line z: )stripr
   r"   r!   )ra   r5   line_nor9   s       r   r8   r8      s       G 
 
zz||2::	H+d###### 	H 	H 	H FWFFFFGGG	H 	1
 
s   <A 
A )r   F)F)r;   )FT)#typingr   r   r   r   r   r   r*   jsonr   r3   rc   r
   utilr   r   r   r   r   intboolstrr   bytesr#   r1   r4   r:   rE   rI   rU   rW   rY   r`   r8    r   r   <module>rn      s/   E E E E E E E E E E E E E E E E 



            K K K K K K K K K K K K K K CH 
%c];?   (	U3:& 	: 	 	 	 	H      j    
 
( 
$ 
8J;O 
 
 
 
 X Y  D    "
+ 
+( 
+) 
+S 
+ 
+ 
+ 
+ 
+   	T T
TIT T 	T
 
T T T T0 X T hz6J    *  	1 1
1I1 1 	1
 
1 1 1 16c d    " ). SM!%j     r   