
    7|h                     h    d dl Z d dlZd dlmZmZ d dlmZ d dlm	Z	  G d de	      Z
 G d de
      Zy)	    N)AnyIterator)Document)
BaseLoaderc                   F    e Zd ZdZdededefdZdedefdZdee	   fd	Z
y
)LarkSuiteDocLoaderz!Load from `LarkSuite` (`FeiShu`).domainaccess_tokendocument_idc                 .    || _         || _        || _        y)zInitialize with domain, access_token (tenant / user), and document_id.

        Args:
            domain: The domain to load the LarkSuite.
            access_token: The access_token to use.
            document_id: The document_id to load.
        N)r	   r
   r   )selfr	   r
   r   s       m/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/document_loaders/larksuite.py__init__zLarkSuiteDocLoader.__init__   s     (&    api_urlreturnc                 6   dd| j                    i}t        j                  j                  ||      }t        j                  j	                  |      5 }t        j                  |j                         j                               }|cddd       S # 1 sw Y   yxY w)z.Get LarkSuite (FeiShu) API response json data.AuthorizationzBearer )headersN)	r
   urllibrequestRequesturlopenjsonloadsreaddecode)r   r   r   r   response	json_datas         r   _get_larksuite_api_json_dataz/LarkSuiteDocLoader._get_larksuite_api_json_data   s|    "gd.?.?-@$AB..(('(B^^##G, 	

8==?#9#9#;<I	 	 	s   3BBc              #     K   | j                    d}| j                  | d| j                         }| j                  | d| j                   d      }|d   d   }| j                  |d   d   d   |d   d   d   d	}t        ||
       yw)z&Lazy load LarkSuite (FeiShu) document.z/open-apis/docx/v1/documents/z/raw_contentdatacontentdocumentrevision_idtitle)r   r&   r'   )page_contentmetadataN)r	   r    r   r   )r   api_url_prefixmetadata_jsonraw_content_jsontextr)   s         r   	lazy_loadzLarkSuiteDocLoader.lazy_load!   s      KK=(DE99a 0 012
  <<a 0 01>
  '	2++(0<]K"6*:6w?

 D8<<s   BBN)__name__
__module____qualname____doc__strr   r   r    r   r   r.    r   r   r   r   
   sC    +
's 
'# 
'C 
'C C =8H- =r   r   c                   B     e Zd ZdZdededefdZdee   f fdZ xZ	S )LarkSuiteWikiLoaderz&Load from `LarkSuite` (`FeiShu`) wiki.r	   r
   wiki_idc                 <    || _         || _        || _        d| _        y)zInitialize with domain, access_token (tenant / user), and wiki_id.

        Args:
            domain: The domain to load the LarkSuite.
            access_token: The access_token to use.
            wiki_id: The wiki_id to load.
         N)r	   r
   r7   r   )r   r	   r
   r7   s       r   r   zLarkSuiteWikiLoader.__init__6   s"     (r   r   c              #      K   | j                   s?| j                   d}| j                  | d| j                         }|d   d   d   | _         t        |          E d{    y7 w)z+Lazy load LarkSuite (FeiShu) wiki document.z"/open-apis/wiki/v2/spaces/get_nodez?token=r#   node	obj_tokenN)r   r	   r    r7   superr.   )r   wiki_url_prefixwiki_node_info_json	__class__s      r   r.   zLarkSuiteWikiLoader.lazy_loadC   sq      !%-OPO"&"C"C"#74<<.9#  36:6B;OD7$&&&s   AA( A&!A()
r/   r0   r1   r2   r3   r   r   r   r.   __classcell__)r@   s   @r   r6   r6   3   s6    0s #  '8H- ' 'r   r6   )r   urllib.requestr   typingr   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   r   r6   r4   r   r   <module>rF      s.        - @&= &=R', 'r   