
    Ng
                        d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	 ddl
mZmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ  e             eej                  e		 	 	 	 ddd                                    ZdS )a  Provides `partition_json()`.

Note this does not partition arbitrary JSON. Its only use-case is to "rehydrate" unstructured
document elements serialized to JSON, essentially the same function as `elements_from_json()`, but
this allows a document of already-partitioned elements to be combined transparently with other
documents in a partitioning run. It also allows multiple (low-cost) chunking runs to be performed on
a document while only incurring partitioning cost once.
    )annotationsN)IOAnyOptional)add_chunking_strategy)Elementprocess_metadata)FileTypeadd_metadata_with_filetypeis_json_processable)exactly_one)get_last_modified_date)elements_from_dictsfilenameOptional[str]fileOptional[IO[bytes]]textmetadata_last_modifiedkwargsr   returnlist[Element]c                   ||                                 dk    r|s| sg S t          | ||           | rt          |           nd}d}| >t          | d          5 }|                                }ddd           n# 1 swxY w Y   nh|U|                                }t          |t                    r|n|                                }|                    d           n|t          |          }t          |          st          d          	 t          j        |          }	t          |	          }
n"# t          j        $ r t          d	          w xY w|
D ]}|p||j        _        |
S )
a  Partitions serialized Unstructured output into its constituent elements.

    Parameters
    ----------
    filename
        A string defining the target filename path.
    file
        A file-like object as bytes --> open(filename, "rb").
    text
        The string representation of the .json document.
    metadata_last_modified
        The last modified date for the document.
    N )r   r   r   utf8)encodingr   )	file_textzJJSON cannot be partitioned. Schema does not match the Unstructured schema.zNot a valid json)stripr   r   openread
isinstancestrdecodeseekr   
ValueErrorjsonloadsr   JSONDecodeErrormetadatalast_modified)r   r   r   r   r   r*   r   ffile_contentelement_dictselementselements               W/var/www/html/ai-engine/env/lib/python3.11/site-packages/unstructured/partition/json.pypartition_jsonr1      s   . DJJLLB..t.H.	488888@J*8444dMI(V,,, 	!I	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 
	yy{{$.|S$A$A\LL|GZGZG\G\			!		II	333 
X
 
 	
-
9--&}55 - - -+,,,-  Q Q)?)P=&&Os   A<<B B #D4 4E)NNNN)r   r   r   r   r   r   r   r   r   r   r   r   )__doc__
__future__r   r&   typingr   r   r   unstructured.chunkingr   unstructured.documents.elementsr   r	    unstructured.file_utils.filetyper
   r   r   $unstructured.partition.common.commonr   &unstructured.partition.common.metadatar   unstructured.staging.baser   JSONr1        r0   <module>r>      sF    # " " " " "  $ $ $ $ $ $ $ $ $ $ 7 7 7 7 7 7 E E E E E E E E         
 = < < < < < I I I I I I 9 9 9 9 9 9 HM**" $,0	5 5 5 5  +* 5 5 5r=   