
    3fi	                     N    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	y)    )ListOptional)Document)
BaseLoader)OBSFileLoaderc            	       F    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
y)OBSDirectoryLoaderz!Load from `Huawei OBS directory`.Nbucketendpointconfigprefixc                 4   	 ddl m} |s
t               }|j	                  d      r ||d      | _        n> ||j	                  d      |j	                  d      |j	                  d	      |
      | _        || _        || _        y# t        $ r t        d      w xY w)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         p/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_community/document_loaders/obs_directory.py__init__zOBSDirectoryLoader.__init__   s    >	% VF::*+#8eTDK#$jj."(**T"2%zz'2	DK %  	H 	s   B Breturnc                    d}d}g }	 | j                   j                  | j                  | j                  ||      }|j                  dk  r|j
                  j                  D ]M  }t        | j                  |j                  | j                         }|j                  |j                                O |j
                  j                  du r|j
                  j                  }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    ;;**DKKw + D {{S #yy11 /G*4;;DKKXFKK./ 99))T19900D     )N )__name__
__module____qualname____doc__strr   r   r!   r   r   r,    r5   r    r	   r	   
   sM    + "&33 3 	3
 3jd8n r5   r	   N)
typingr   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   -langchain_community.document_loaders.obs_filer   r	   r<   r5   r    <module>rA      s    ! - @ GI Ir5   