
    dh                     b    S SK r S SKrS SKJrJrJr  S SKJr  S SKJ	r	  S SK
Jr   " S S\	5      rg)    N)AnyListOptional)Document)
BaseLoader)UnstructuredFileLoaderc                   f    \ rS rSrSr   SS\S\S\S\S\\   S	S4S
 jjr	SS\S	\
\   4S jjrSrg)OBSFileLoader   z Load from the `Huawei OBS file`.Nbucketkeyclientendpointconfigreturnc                     SSK Jn  U(       dw  U(       d  [        S5      eU(       d
  [	        5       nUR                  S5      (       a  U" USS9nO6U" UR                  S5      UR                  S	5      UR                  S
5      US9n[        X65      (       d  [        S5      eX0l        Xl	        X l
        g! [         a    [        S5      ef = f)a	  Initialize the OBSFileLoader with the specified settings.

Args:
    bucket (str): The name of the OBS bucket to be used.
    key (str): The name of the object in the OBS bucket.
    client (ObsClient, optional): An instance of the ObsClient to connect to OBS.
    endpoint (str, optional): The endpoint URL of your OBS bucket. This parameter is mandatory if `client` is not provided.
    config (dict, optional): The parameters for connecting to OBS, provided as a dictionary. This parameter is ignored if `client` is provided. 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.

Raises:
    ValueError: If the `esdk-obs-python` package is not installed.
    TypeError: If the provided `client` is not an instance of ObsClient.
    ValueError: If `client` is not provided, but `endpoint` is missing.

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 OBSFileLoader with a new client:
    ```
    config = {
        "ak": "your-access-key",
        "sk": "your-secret-key"
    }
    obs_loader = OBSFileLoader("your-bucket-name", "your-object-key", config=config)
    ```

    To create a new OBSFileLoader with an existing client:
    ```
    from obs import ObsClient

    # Assuming you have an existing ObsClient object 'obs_client'
    obs_loader = OBSFileLoader("your-bucket-name", "your-object-key", client=obs_client)
    ```

    To create a new OBSFileLoader without an existing client:
    ```
    obs_loader = OBSFileLoader("your-bucket-name", "your-object-key", endpoint="your-endpoint-url")
    ```
r   )	ObsClientzfCould not import esdk-obs-python python package. Please install it with `pip install esdk-obs-python`.z.Either OBSClient or endpoint must be provided.get_token_from_ecsECS)serversecurity_provider_policyaksktoken)access_key_idsecret_access_keysecurity_tokenr   zClient must be ObsClient typeN)obsr   ImportError
ValueErrordictget
isinstance	TypeErrorr   r   r   )selfr   r   r   r   r   r   s          e/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/document_loaders/obs_file.py__init__OBSFileLoader.__init__   s    h	%  !QRRzz.//"(US""(**T"2&,jj&6#)::g#6#	 &,,;<</  	H 	s   B4 4C
modec                    [         R                  " 5        nU SU R                   SU R                   3n[        R
                  " [        R                  R                  U5      SS9  U R                  R                  U R                  U R                  US9  [        X1S9nUR                  5       sSSS5        $ ! , (       d  f       g= f)zLoad documents./T)exist_ok)
bucketName	objectKeydownloadFile)r)   N)tempfileTemporaryDirectoryr   r   osmakedirspathdirnamer   r/   r   load)r%   r)   temp_dir	file_pathloaders        r&   r6   OBSFileLoader.load_   s    ((*h#*Adkk]!DHH:>IKK	2TBKK$$;;$(( %  ,IAF;;= +**s   BB88
C)r   r   r   )N N)single)__name__
__module____qualname____firstlineno____doc__strr   r   r!   r'   r   r   r6   __static_attributes__     r&   r
   r
      sw    * !%MM M 	M
 M M 
M^
! 
!DN 
! 
!rE   r
   )r2   r0   typingr   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   1langchain_community.document_loaders.unstructuredr   r
   rD   rE   r&   <module>rJ      s*    
  & & - @ T\!J \!rE   