a
    bgh                     @   sh   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e	eef eee dd	d
ZdS )zDocument loader helpers.    N)Path)List
NamedTupleOptionalUnioncastc                   @   s2   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   z/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/helpers.pyr      s
   
r      )	file_pathtimeoutreturnc              	      s   ddl  t| } ttt d fdd}tj R}||| }z|j|d}W n$ tjj	yt   t	d|  Y n0 W d   n1 s0    Y  t
dd	 |D rt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   N)r   r   c                    sF   t | d}| }W d    n1 s(0    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       z(detect_file_encodings.<locals>.<genexpr>zCould not detect encoding for c                 S   s&   g | ]}|d  durt f i |qS r#   )r   )r$   encr   r   r   
<listcomp>3   r&   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    (r4   )r   )r   concurrent.futuresr)   pathlibr   typingr   r   r   r   r   r   r   intr4   r   r   r   r   <module>   s    