
    Mi@              	      b   % S SK Jr  S SKrS SKJr  S SKJrJrJrJ	r	  S SK
Jr  S SK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Jr  S SKJrJr  S SKJr  SrS\S'   \" \R@                  5      \ SSSSSSS.               SS jjj5       5       r!          SS jr"      SS jr#g)    )annotationsN)BytesIO)IOAnyIteratorcast)etree)add_chunking_strategy)ElementElementMetadataText)read_txt_file)FileType)exactly_onespooled_to_bytes_io_if_needed)apply_metadataget_last_modified_date)element_from_textxmlstrDETECTION_ORIGINF)filetextencodingxml_keep_tagsxml_pathc                  [        XUS9  / n[        X (       a  [        U 5      OSS9n[        Ul        U(       aE  U (       a  [        XS9S   n	O%U(       a  [        [        U5      US9S   n	OUc   eUn	[        XS9/nU$ [        U UUUS9n
U
 HC  nU(       d  M  [        U5      n[        R                  " U5      Ul        UR                  U5        ME     U$ )	a0  Partitions an XML document into its document elements.

Parameters
----------
filename
    A string defining the target filename path.
file
    A file-like object using "rb" mode --> open(filename, "rb").
text
    The text of the XML file.
encoding
    The encoding method used to decode the text input. If None, utf-8 will be used.
xml_keep_tags
    If True, will retain the XML tags in the output. Otherwise it will simply extract
    the text from within the tags.
xml_path
    The xml_path to use for extracting the text. Only used if xml_keep_tags=False.
filenamer   r   N)r   last_modified)r   r      )r   r   )r   metadata)r   r   r   r   )r   r   r   r   detection_originr   r   r   get_leaf_elementsr   copydeepcopyr"   append)r   r   r   r   r   r   kwargselementsr"   raw_textleaf_elementsleaf_elementelements                t/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/unstructured/partition/xml.pypartition_xmlr/      s    < 48 HX)?)I[_H !1H$hJ1MH$*G*MX`abcdH###Hh:; O *	
 *L|+L9#'==#: (	 * O    c                    [        XUS9  U (       a	  [        XS9$ U(       a  [        [        U5      US9$ [        [	        [        [        U5      SS95      n[        XCS9$ )zGGet leaf elements from the XML tree defined in filename, file, or text.r   )r   )r   r   zutf-8)r   )r   _get_leaf_elementsr   r   bytesr   r   )r   r   r   r   bs        r.   r$   r$   Y   sU     48!(>>	!'DT'JU]^^E$sD/G<=!!77r0   c              #  &  #    / n[         R                  " U SSS9nUb2  [        U5      u  pE[         R                  " U5      nS U" U5       5       nU H  u  puUS:X  a  UR	                  U5        US:X  aJ  UR
                  b-  UR
                  R                  5       (       a  UR
                  v   UR                  5         U(       d  Mu  US   R                  5       b  M  UR                  5         U(       d  M  US   R                  5       c  M/  M     g7f)	z<Parse the XML tree in a memory efficient manner if possible.)startendF)eventsresolve_entitiesNc              3  *   #    U  H	  nS U4v   M     g7f)r7   N ).0els     r.   	<genexpr>%_get_leaf_elements.<locals>.<genexpr>u   s     I2HBUBK2Hs   r6   r7   )
r	   	iterparsenextXPathr'   r   stripclear	getparentpop)r   r   element_stackelement_iterator_r-   compiled_pathevents           r.   r2   r2   g   s     
 +-Mt4DW\] *+
H-I-2HI*G  )E>||'GLL,>,>,@,@ll"MMOmb 1 ; ; = E mb 1 ; ; = E +s   CDDD6DD)N)r   
str | Noner   IO[bytes] | Noner   rM   r   rM   r   boolr   rM   r(   r   returnzlist[Element])
r   rM   r   rN   r   rM   r   rM   rP   Iterator[str | None])r   zstr | IO[bytes]r   rM   rP   rQ   )$
__future__r   r%   ior   typingr   r   r   r   lxmlr	   unstructured.chunkingr
   unstructured.documents.elementsr   r   r    unstructured.file_utils.encodingr   unstructured.file_utils.modelr   $unstructured.partition.common.commonr   r   &unstructured.partition.common.metadatar   r   unstructured.partition.textr   r   __annotations__XMLr/   r$   r2   r;   r0   r.   <module>r_      s   "   * *  7 J J : 2 Z 9 #  = "== = 	=
 = = = = =  =@88 088B8NX88 
    r0   