§
    šŠtjÁ  ã                   ój   — d dl Z d dl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  G d„ de	¦  «        ZdS )é    N)ÚAnyÚListÚOptional)ÚDocument)Ú
BaseLoader)ÚUnstructuredFileLoaderc                   ód   — e Zd ZdZ	 	 	 ddededededee         d	dfd
„Zdded	e	e
         fd„ZdS )ÚOBSFileLoaderz Load from the `Huawei OBS file`.NÚ ÚbucketÚkeyÚclientÚendpointÚconfigÚreturnc                 óÔ  — 	 ddl m} n# t          $ r t          d¦  «        ‚w xY w|sŒ|st          d¦  «        ‚|st	          ¦   «         }|                     d¦  «        r ||d¬¦  «        }nH ||                     d¦  «        |                     d	¦  «        |                     d
¦  «        |¬¦  «        }t          ||¦  «        st          d¦  «        ‚|| _        || _	        || _
        dS )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          úk/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/document_loaders/obs_file.pyÚ__init__zOBSFileLoader.__init__   s0  € ðh	Ø%Ð%Ð%Ð%Ð%Ð%Ð%øÝð 	ð 	ð 	ÝðHñô ð ð	øøøð
 ð 	Øð SÝ Ð!QÑRÔRÐRØð  Ý™œ�Ø�zŠzÐ.Ñ/Ô/ð Ø"˜¨(ÈUÐSÑSÔS��à"˜Ø"(§*¢*¨TÑ"2Ô"2Ø&,§j¢j°Ñ&6Ô&6Ø#)§:¢:¨gÑ#6Ô#6Ø#ð	ñ ô �õ ˜& )Ñ,Ô,ð 	=ÝÐ;Ñ<Ô<Ð<ØˆŒØˆŒØˆŒˆˆs   ‚	 ‰#ÚsingleÚmodec                 ó‚  — t          j        ¦   «         5 }|› d| j        › d| j        › �}t	          j        t          j                             |¦  «        d¬¦  «         | j         	                    | j        | j        |¬¦  «         t          ||¬¦  «        }|                     ¦   «         cddd¦  «         S # 1 swxY w Y   dS )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   zOBSFileLoader.load_   sý   € åÔ(Ñ*Ô*ð 	!¨hØ#Ð>Ð> d¤kÐ>Ð>°D´HÐ>Ð>ˆIÝŒK�œŸš¨	Ñ2Ô2¸TÐBÑBÔBÐBàŒK×$Ò$Øœ;°$´(Èð %ñ ô ð õ ,¨I¸DÐAÑAÔAˆFØ—;’;‘=”=ð	!ð 	!ð 	!ð 	!ñ 	!ô 	!ð 	!ð 	!ð 	!ð 	!ð 	!ð 	!øøøð 	!ð 	!ð 	!ð 	!ð 	!ð 	!s   ”BB4Â4B8Â;B8)Nr   N)r(   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   r!   r'   r   r   r6   © ó    r&   r
   r
      s³   € € € € € Ø*Ð*ð ØØ!%ðMð MàðMð ðMð ð	Mð
 ðMð ˜”ðMð 
ðMð Mð Mð Mð^
!ð 
!˜ð 
!¨D°¬Nð 
!ð 
!ð 
!ð 
!ð 
!ð 
!r@   r
   )r2   r0   Útypingr   r   r   Úlangchain_core.documentsr   Ú)langchain_community.document_loaders.baser   Ú1langchain_community.document_loaders.unstructuredr   r
   r?   r@   r&   ú<module>rE      s«   ðð 
€	€	€	Ø €€€Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à -Ð -Ð -Ð -Ð -Ð -à @Ð @Ð @Ð @Ð @Ð @Ø TÐ TÐ TÐ TÐ TÐ Tð\!ð \!ð \!ð \!ð \!�Jñ \!ô \!ð \!ð \!ð \!r@   