
    Ngh                         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e          Z	 dde	eef         d	ed
ee         fdZdS )zDocument loader helpers.    N)Path)List
NamedTupleOptionalUnioncastc                   N    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     h/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/helpers.pyr
   r
      sJ         **sm#)sm##r   r
      	file_pathtimeoutreturnc                    ddl t          |           } dt          dt          t                   ffd}t          j                                        5 }|                    ||           }	 |                    |          }n*# t          j        j	        $ r t          d|            w xY w	 ddd           n# 1 swxY w Y   t          d |D                       rt          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                     t          | d          5 }|                                }d d d            n# 1 swxY w Y   t          t          t                                       |                    S )Nrb)openreadr   r   dict
detect_all)r   frawdatachardets      r   read_and_detectz.detect_file_encodings.<locals>.read_and_detect#   s    )T"" 	affhhG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	DJ 2 27 ; ;<<<s   377)r   z-Timeout reached while detecting encoding for c              3   *   K   | ]}|d          du V  dS )r   Nr   ).0r   s     r   	<genexpr>z(detect_file_encodings.<locals>.<genexpr>1   s,      
B
BH8J4'
B
B
B
B
B
Br   zCould not detect encoding for c                 6    g | ]}|d          
t          di |S )r   Nr   )r
   )r(   encs     r   
<listcomp>z)detect_file_encodings.<locals>.<listcomp>3   s/    TTTCJ8SL38S8S8Sr   )r%   r   r   r!   
concurrentfuturesThreadPoolExecutorsubmitresultTimeoutErrorallRuntimeError)r   r   r&   executorfuture	encodingsr%   s         @r   detect_file_encodingsr8      so    NNNII=3 =4: = = = = = =
 
		.	.	0	0 H)<<	g66II!. 	 	 	K	KK  	                
B
B	
B
B
BBB IGIGGHHHTT9TTTTs*   B8*B B8'B((B88B<?B<)r   )r   concurrent.futuresr-   pathlibr   typingr   r   r   r   r   r
   r   intr8   r   r   r   <module>r=      s                : : : : : : : : : : : : : :$ $ $ $ $: $ $ $ 12 U  US$Y U*- U	, U  U  U  U  U  Ur   