U
    h                     @   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                   @   sB   e Zd ZdZd
eeef ee edddZ	e
e d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.Nr
   )selfr   r   r    r   M/tmp/pip-unpacked-wheel-9gdii04g/langchain_community/document_loaders/text.py__init__   s    zTextLoader.__init__)returnc                 c   s,  d}z(t | j| jd}| }W 5 Q R X W n tk
r } z| jrt| j}|D ]^}td|j  z.t | j|jd}| }W 5 Q R X W  qW qR tk
r   Y qRY qRX qRnt	d| j |W 5 d}~X Y n6 t
k
r
 } zt	d| j |W 5 d}~X Y nX dt| ji}t||dV  dS )zLoad from file path. )r   zTrying encoding: zError loading N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   
