
    hh	                     V    d dl mZmZ d dlmZ d dlmZ d dlmZ  G d de          Z	dS )    )ListOptional)Document)
BaseLoader)OBSFileLoaderc            	       T    e Zd ZdZ	 	 ddededee         defdZd	ee	         fd
Z
dS )OBSDirectoryLoaderz!Load from `Huawei OBS directory`.N bucketendpointconfigprefixc                 v   	 ddl m} n# t          $ r t          d          w xY w|st                      }|                    d          r ||d          | _        nM ||                    d          |                    d          |                    d	          |
          | _        || _        || _        dS )a  Initialize the OBSDirectoryLoader with the specified settings.

        Args:
            bucket (str): The name of the OBS bucket to be used.
            endpoint (str): The endpoint URL of your OBS bucket.
            config (dict): The parameters for connecting to OBS, provided as a dictionary. The dictionary could have the following keys:
                - "ak" (str, optional): Your OBS access key (required if `get_token_from_ecs` is False and bucket policy is not public read).
                - "sk" (str, optional): Your OBS secret key (required if `get_token_from_ecs` is False and bucket policy is not public read).
                - "token" (str, optional): Your security token (required if using temporary credentials).
                - "get_token_from_ecs" (bool, optional): Whether to retrieve the security token from ECS. Defaults to False if not provided. If set to True, `ak`, `sk`, and `token` will be ignored.
            prefix (str, optional): The prefix to be added to the OBS key. Defaults to "".

        Note:
            Before using this class, make sure you have registered with OBS and have the necessary credentials. The `ak`, `sk`, and `endpoint` values are mandatory unless `get_token_from_ecs` is True or the bucket policy is public read. `token` is required when using temporary credentials.
        Example:
            To create a new OBSDirectoryLoader:
            ```
            config = {
                "ak": "your-access-key",
                "sk": "your-secret-key"
            }
            ```
            directory_loader = OBSDirectoryLoader("your-bucket-name", "your-end-endpoint", config, "your-prefix")
        r   )	ObsClientzfCould not import esdk-obs-python python package. Please install it with `pip install esdk-obs-python`.get_token_from_ecsECS)serversecurity_provider_policyaksktoken)access_key_idsecret_access_keysecurity_tokenr   N)obsr   ImportErrordictgetclientr   r   )selfr   r   r   r   r   s         o/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/langchain_community/document_loaders/obs_directory.py__init__zOBSDirectoryLoader.__init__   s    >	%%%%%%% 	 	 	H  	
  	VVF::*++ 	#)8eTTTDKK#)$jj.."(**T"2"2%zz'22	  DK s   	 #returnc                 b   d}d}g }	 | j                             | j        | j        ||          }|j        dk     rs|j        j        D ]J}t          | j        |j        | j                   }|	                    |
                                           K|j        j        du r|j        j        }nn|S )zLoad documents.i  NT)r   markermax_keysi,  )r   )r   listObjectsr   r   statusbodycontentsr   keyextendloadis_truncatednext_marker)r    max_nummarkdocsrespcontentloaders          r!   r-   zOBSDirectoryLoader.loadB   s    	;**DKw +  D {S  #y1 / /G*4;DKXXXFKK....9)T1190DD	     )Nr
   )__name__
__module____qualname____doc__strr   r   r"   r   r   r-    r6   r!   r	   r	   
   s        ++ "&3 33 3 	3
 3 3 3 3jd8n      r6   r	   N)
typingr   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   -langchain_community.document_loaders.obs_filer   r	   r<   r6   r!   <module>rA      s    ! ! ! ! ! ! ! ! - - - - - - @ @ @ @ @ @ G G G G G GI I I I I I I I I Ir6   