o
    Zh                     @   sj   d dl Z d dlmZ d dlmZmZmZ d dlmZ d dl	m
Z
 d dlmZ e eZG dd de
ZdS )	    N)Path)IteratorOptionalUnion)Document)
BaseLoader)detect_file_encodingsc                   @   sJ   e Zd ZdZ		ddeeef dee defddZ	d	e
e fd
dZdS )
TextLoadera=  Load text file.


    Args:
        file_path: Path to the file to load.

        encoding: File encoding to use. If `None`, the file will be loaded
        with the default system encoding.

        autodetect_encoding: Whether to try to autodetect the file encoding
            if the specified encoding fails.
    NF	file_pathencodingautodetect_encodingc                 C   s   || _ || _|| _dS )zInitialize with file path.N)r
   r   r   )selfr
   r   r    r   `/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/document_loaders/text.py__init__   s   
zTextLoader.__init__returnc                 c   s@   d}zt | j| jd}| }W d   n1 sw   Y  W nn ty{ } zN| jrht| j}|D ]3}td|j  zt | j|jd}| }W d   n1 sVw   Y  W  n	 tyf   Y q3w n	t	d| j |W Y d}~nd}~w t
y } z	t	d| j |d}~ww dt| ji}t||dV  dS )zLoad from file path. )r   NzTrying encoding: zError loading source)Zpage_contentmetadata)openr
   r   readUnicodeDecodeErrorr   r   loggerdebugRuntimeError	Exceptionstrr   )r   textfeZdetected_encodingsr   r   r   r   r   	lazy_load&   s:   


zTextLoader.lazy_load)NF)__name__
__module____qualname____doc__r   r   r   r   boolr   r   r   r    r   r   r   r   r	      s    

r	   )loggingpathlibr   typingr   r   r   Zlangchain_core.documentsr   Z)langchain_community.document_loaders.baser   Z,langchain_community.document_loaders.helpersr   	getLoggerr!   r   r	   r   r   r   r   <module>   s    
