o
    Zhh                     @   sn   d Z ddlZddlmZ ddlmZmZmZm	Z	m
Z
 G dd deZ	dde	eef d	ed
ee fddZdS )zDocument loader helpers.    N)Path)List
NamedTupleOptionalUnioncastc                   @   s6   e Zd ZU dZee ed< 	 eed< 	 ee ed< dS )FileEncodingz File encoding as the NamedTuple.encoding
confidencelanguageN)__name__
__module____qualname____doc__r   str__annotations__float r   r   c/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/document_loaders/helpers.pyr      s   
 r      	file_pathtimeoutreturnc              	      s   ddl  t| } dtdtt f fdd}tj '}||| }z|j|d}W n tjj	y9   t	d|  w W d   n1 sDw   Y  t
d	d
 |D rYtd|  dd |D S )a  Try to detect the file encoding.

    Returns a list of `FileEncoding` tuples with the detected encodings ordered
    by confidence.

    Args:
        file_path: The path to the file to detect the encoding for.
        timeout: The timeout in seconds for the encoding detection.
    r   Nr   r   c                    sF   t | d}| }W d    n1 sw   Y  ttt  |S )Nrb)openreadr   r   dict
detect_all)r   frawdatachardetr   r   read_and_detect#   s   
z.detect_file_encodings.<locals>.read_and_detect)r   z-Timeout reached while detecting encoding for c                 s   s    | ]	}|d  du V  qdS )r	   Nr   ).0r	   r   r   r   	<genexpr>1   s    z(detect_file_encodings.<locals>.<genexpr>zCould not detect encoding for c                 S   s&   g | ]}|d  durt di |qS )r	   Nr   )r   )r#   encr   r   r   
<listcomp>3   s   & z)detect_file_encodings.<locals>.<listcomp>)r!   r   r   r   
concurrentfuturesThreadPoolExecutorsubmitresultTimeoutErrorallRuntimeError)r   r   r"   executorfuture	encodingsr   r    r   detect_file_encodings   s"   	r2   )r   )r   concurrent.futuresr'   pathlibr   typingr   r   r   r   r   r   r   intr2   r   r   r   r   <module>   s    
