
    ihh                     v    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y)zDocument loader helpers.    N)Path)List
NamedTupleOptionalUnioncastc                   @    e Zd ZU dZee   ed<   	 eed<   	 ee   ed<   y)FileEncodingz File encoding as the NamedTuple.encoding
confidencelanguageN)__name__
__module____qualname____doc__r   str__annotations__float     j/var/www/html/dev/engine/venv/lib/python3.12/site-packages/langchain_community/document_loaders/helpers.pyr
   r
      s(    *sm#)sm#r   r
   	file_pathtimeoutreturnc                    ddl t        |       } dt        dt        t           ffd}t        j
                  j                         5 }|j                  ||       }	 |j                  |      }	 ddd       t        d D              rt        d	|        |D cg c]  }|d
   	t        di | c}S # t        j
                  j                  $ r t        d|        w xY w# 1 sw Y   wxY wc c}w )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 }|j                         }d d d        t        t        t           j                              S # 1 sw Y   /xY w)Nrb)openreadr   r   dict
detect_all)r   frawdatachardets      r   read_and_detectz.detect_file_encodings.<locals>.read_and_detect#   sK    )T" 	affhG	DJ 2 27 ;<<	 	s   AA)r   z-Timeout reached while detecting encoding for c              3   *   K   | ]  }|d    du   yw)r   Nr   ).0r   s     r   	<genexpr>z(detect_file_encodings.<locals>.<genexpr>1   s     
BH8J4'
Bs   zCould not detect encoding for r   r   )r$   r   r   r    
concurrentfuturesThreadPoolExecutorsubmitresultTimeoutErrorallRuntimeErrorr
   )r   r   r%   executorfuture	encodingsencr$   s          @r   detect_file_encodingsr5      s     II=3 =4: =
 
			.	.	0 H)<	g6I 
B	
BB;I;GHH+4TCJ8SL3TT !!.. 	?	{K 		  Us*   C%B6
C1&C16,C""C%%C.)   )r   concurrent.futuresr)   pathlibr   typingr   r   r   r   r   r
   r   intr5   r   r   r   <module>r;      sT       : :$: $ 12 US$Y U*- U	, Ur   