a
    bg                     @   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   w/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/text.py__init__   s    zTextLoader.__init__)returnc                 c   sV  d}z<t | j| jd}| }W d   n1 s40    Y  W n ty } z| jrt| j}|D ]p}td|j  zBt | j|jd}| }W d   n1 s0    Y  W  qW qd ty   Y qdY qd0 qdnt	d| j |W Y d}~n@d}~0  t
y4 } zt	d| j |W Y d}~n
d}~0 0 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   
