
    Ng                         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 j        e          Z G d de
          ZdS )	    N)Path)IteratorOptionalUnion)Document)
BaseLoader)detect_file_encodingsc                   `    e Zd ZdZ	 	 d
deeef         dee         defdZ	de
e         f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                 0    || _         || _        || _        dS )zInitialize with file path.N)r   r   r   )selfr   r   r   s       e/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/text.py__init__zTextLoader.__init__   s      # #6       returnc              #     K   d}	 t          | j        | j                  5 }|                                }ddd           n# 1 swxY w Y   n# t          $ r}| j        rt          | j                  }|D ]}}t                              d|j                    	 t          | j        |j                  5 }|                                }ddd           n# 1 swxY w Y    n# t          $ r Y zw xY wnt          d| j                   |Y d}~n-d}~wt          $ r}t          d| j                   |d}~ww xY wdt          | j                  i}t          ||          V  dS )zLoad from file path. )r   NzTrying encoding: zError loading source)page_contentmetadata)openr   r   readUnicodeDecodeErrorr   r	   loggerdebugRuntimeError	Exceptionstrr   )r   textfedetected_encodingsr   r   s          r   	lazy_loadzTextLoader.lazy_load&   s"     	Idnt}===  vvxx                             ! 	M 	M 	M' M%:4>%J%J" 2 ! !HLL!HX5F!H!HIII!!$.8;LMMM ,QR#$6688D, , , , , , , , , , , , , , ,- ! ! ! ! ##DDN#D#DEE1L 	I 	I 	I@@@AAqH	I c$.112D8<<<<<<<<s   A AA AA 	A
A 
D;ADC#5C
C#CC#CC#!D#
C0-D/C00DD;D66D;)NF)__name__
__module____qualname____doc__r   r!   r   r   boolr   r   r   r&    r   r   r   r      s           #'$)		7 	7d#	7 3-	7 "		7 	7 	7 	7=8H- = = = = = =r   r   )loggingpathlibr   typingr   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   ,langchain_community.document_loaders.helpersr	   	getLoggerr'   r   r   r,   r   r   <module>r4      s           , , , , , , , , , , - - - - - - @ @ @ @ @ @ N N N N N N		8	$	$0= 0= 0= 0= 0= 0= 0= 0= 0= 0=r   