a
    ¡˜ëjg
  ã                   @  sx   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 e	dgƒdddddœd	d
„ƒZ
ddddddœdd„ZdS )é    )ÚannotationsN)ÚIO)Úexactly_one)Úrequires_dependenciesÚpypandocÚstr)ÚfilenameÚsource_formatÚtarget_formatÚreturnc           
   
   C  sÄ   ddl }z|j| ||dd�}W n  tyT } zd|› �}t|ƒ‚W Y d}~ntd}~0  ty¾ } zT| ¡ \}}|dkr„||vr„d}	nd}	|› d	|	› d
| ¡ › d�}t|ƒ‚W Y d}~n
d}~0 0 |S )z@Uses pandoc to convert the source document to a raw text string.r   NT)ÚformatZsandboxzÐError converting the file to text. Ensure you have the pandoc package installed on your system. Installation instructions are available at https://pandoc.org/installing.html. The original exception text was:
Zrtfz³Support for RTF files is not available in the current pandoc installation. It was introduced in pandoc 2.14.2.
Reference: https://pandoc.org/releases.html#pandoc-2.14.2-2021-08-21Ú z

z

Current version of pandoc: z�
Make sure you have the right version installed in your system. Please follow the pandoc installation instructions in README.md to install the right version.)r   Zconvert_fileÚFileNotFoundErrorÚRuntimeErrorZget_pandoc_formatsZget_pandoc_version)
r   r	   r
   r   ÚtextÚerrÚmsgZsupported_source_formatsÚ_Zadditional_info© r   úf/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/unstructured/file_utils/file_conversion.pyÚconvert_file_to_text   s*    þÿÿÿÿr   z
str | NonezIO[bytes] | None)r	   r   Úfiler   c              	   C  s°   t ||d� |dur–t ¡ �j}tj |d| › �¡}t|dƒ�}| | ¡ ¡ W d  ƒ n1 s`0    Y  t	|| dd�W  d  ƒ S 1 sŒ0    Y  |dus¢J ‚t	|| dd�S )znConverts a document to HTML raw text.

    Enables the doucment to be processed using `partition_html()`.
    )r   r   Nz	tmp_file.ÚwbÚhtml)r   r	   r
   )
r   ÚtempfileÚTemporaryDirectoryÚosÚpathÚjoinÚopenÚwriteÚreadr   )r	   r   r   Ztemp_dir_pathZtmp_file_pathZtmp_filer   r   r   Ú&convert_file_to_html_text_using_pandoc0   s    
,ÿ$ÿr"   )NN)Ú
__future__r   r   r   Útypingr   Z$unstructured.partition.common.commonr   Zunstructured.utilsr   r   r"   r   r   r   r   Ú<module>   s   % ÿ