
    Ng                        d dl mZ d dlZd dlZd dlmZmZmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ 	 ddddd
ddZ ed          dd            ZdS )    )annotationsN)IOAnyOptionalcast)Element)FileType)exactly_one)get_last_modified_date)partition_docx)requires_dependencies)filemetadata_filenamemetadata_last_modifiedfilenameOptional[str]r   Optional[IO[bytes]]r   r   kwargsr   returnlist[Element]c          	         | rt          |           nd}t          j                    5 }t          || |          }t	          d||p| t
          j        |p|d|}ddd           n# 1 swxY w Y   |S )a  Partitions Open Office Documents in .odt format into its document elements.

    All parameters that are available on `partition_docx()` are also available here.

    Parameters
    ----------
    filename
        A string defining the target filename path.
    file
        A file-like object using "rb" mode --> open(filename, "rb").
    infer_table_structure
        If True, any Table elements that are extracted will also have a metadata field
        named "text_as_html" where the table's text content is rendered into an html string.
        I.e., rows and cells are preserved.
        Whether True or False, the "text" field is always present in any Table element
        and is the text content of the table (no structure).
    metadata_last_modified
        The last modified date for the document.
    languages
        User defined value for `metadata.languages` if provided. Otherwise language is detected
        using naive Bayesian filter via `langdetect`. Multiple languages indicates text could be
        in either language.
        Additional Parameters:
            detect_language_per_element
                Detect language per element instead of at the document level.
    N)r   r   metadata_file_typer    )r   tempfileTemporaryDirectory_convert_odt_to_docxr   r	   ODT)	r   r   r   r   r   last_modified
target_dir	docx_pathelementss	            V/var/www/html/ai-engine/env/lib/python3.11/site-packages/unstructured/partition/odt.pypartition_odtr#      s    F 9AJ*8444dM		$	&	& 
*(XtDD	! 
/;8'|#9#J]	
 

 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Os   1A$$A(+A(pypandocr   strc                l   t          ||           |2t          j                            |          st	          d| d          ||  dnt          t          |          }|Ot          |d          5 }|                    |	                                           ddd           n# 1 swxY w Y   t          j        
                    |          }t          j                            |          \  }}t          j                            | | d          }ddl}	|	                    |d	d
|           |S )a{  Convert ODT document to DOCX returning the new .docx file's path.

    Parameters
    ----------
    target_dir
        The str directory-path to use for conversion purposes. The new DOCX file is written to this
        directory. When passed as a file-like object, a copy of the source file is written here as
        well. It is the caller's responsibility to remove this directory and its contents when
        they are no longer needed.
    filename
        A str file-path specifying the location of the source ODT file on the local filesystem.
    file
        A file-like object open for reading in binary mode ("rb" mode).
    )r   r   Nz	The file z does not exist.z/document.odtwbz.docxr   docxodt)format
outputfile)r
   ospathexists
ValueErrorr   r%   openwritereadbasenamesplitextjoinr$   convert_file)
r   r   r   source_file_pathf	file_name	base_name_target_docx_pathr$   s
             r"   r   r   A   s   $ ---- BGNN8$<$<?X???@@@
 8<7G*3333TRUW_M`M`"D)) 	!QGGDIIKK   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!   !122I7##I..LIqw||J90C0C0CDDOOO#	     s   4(B((B,/B,)N)r   r   r   r   r   r   r   r   r   r   r   r   )r   r%   r   r   r   r   r   r%   )
__future__r   r,   r   typingr   r   r   r   unstructured.documents.elementsr   unstructured.file_utils.modelr	   $unstructured.partition.common.commonr
   &unstructured.partition.common.metadatar   unstructured.partition.docxr   unstructured.utilsr   r#   r   r       r"   <module>rF      s#   " " " " " " 				  * * * * * * * * * * * * 3 3 3 3 3 3 2 2 2 2 2 2 < < < < < < I I I I I I 6 6 6 6 6 6 4 4 4 4 4 4 #/ !%'+,0/ / / / / /d z""2 2 2 #"2 2 2rE   