
    Mi                        S r SSKJr  SSKrSSKJrJrJr  SSKJ	r	  SSK
JrJr  SSKJrJrJr  SSKJr  SS	KJr  SS
KJr  \" 5       \" \R.                  5      \	    S           SS jj5       5       5       rg)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_dictsc                   Ub$  UR                  5       S:X  a  U(       d	  U (       d  / $ [        XUS9  U (       a  [        U 5      OSnSnU b$  [        U SS9 nUR	                  5       nSSS5        OZUbI  UR	                  5       n[        U[        5      (       a  UOUR                  5       nUR                  S5        OUb  [        U5      n[        US9(       d  [        S5      e [        R                  " U5      n	[        U	5      n
[        U	5      S:  a  [        U
5      S:X  a  [        S5      eU
 H  nU=(       d    UUR                   l        M     U
$ ! , (       d  f       N= f! [        R                   a    [        S	5      ef = f)
aV  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 )filenamefiletext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   lenJSONDecodeErrormetadatalast_modified)r   r   r   metadata_last_modifiedkwargsr%   r   ffile_contentelement_dictselementselements               u/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/unstructured/partition/json.pypartition_jsonr.      sZ   . DJJLB.tH	488@*84dMI(V,I -, 
	yy{$.|S$A$AL|GZGZG\			!		I	3X
 	
	-

9-&}5}!c(mq&8\  )?)P=&  O= -,0  -+,,-s   E#A
E# 
E # F)NNNN)r   Optional[str]r   zOptional[IO[bytes]]r   r/   r&   r/   r'   r   returnzlist[Element])__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   JSONr.        r-   <module>r=      s    #  $ $ 7 E 
 = I 9 HMM*" $,0	::
: : *	:
 : :  + :r<   