Ë
    µŒjÁ  ã                   ób   — 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y)é    N)ÚAnyÚListÚOptional)ÚDocument)Ú
BaseLoader)ÚUnstructuredFileLoaderc                   óV   — 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y)ÚOBSFileLoaderz Load from the `Huawei OBS file`.NÚbucketÚkeyÚclientÚendpointÚconfigÚreturnc                 óz  — 	 ddl m} |sn|st        d«      ‚|s
t	        «       }|j                  d«      r ||d¬«      }n9 ||j                  d«      |j                  d	«      |j                  d
«      |¬«      }t        ||«      st        d«      ‚|| _        || _	        || _
        y# t        $ r t        d«      ‚w xY w)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          úw/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/document_loaders/obs_file.pyÚ__init__zOBSFileLoader.__init__   sÄ   € ðh	Ý%ñ ÙÜ Ð!QÓRÐRÙÜ›�Ø�z‰zÐ.Ô/Ù"¨(ÈUÔS‘á"Ø"(§*¡*¨TÓ"2Ø&,§j¡j°Ó&6Ø#)§:¡:¨gÓ#6Ø#ô	�ô ˜& )Ô,ÜÐ;Ó<Ð<ØˆŒØˆŒØˆ�øô/ ò 	ÜðHóð ð	ús   ‚B% Â%B:Úmodec                 ó˜  — t        j                  «       5 }|› d| j                  › d| j                  › �}t	        j
                  t        j                  j                  |«      d¬«       | j                  j                  | j                  | j                  |¬«       t        ||¬«      }|j                  «       cddd«       S # 1 sw Y   yxY w)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%   r4   zOBSFileLoader.load_   s’   € ä×(Ñ(Ô*¨hØ#˜* A d§k¡k ]°!°D·H±H°:Ð>ˆIÜ�K‰KœŸ™Ÿ™¨	Ó2¸TÕBà�K‰K×$Ñ$ØŸ;™;°$·(±(Èð %ô ô ,¨I¸DÔAˆFØ—;‘;“=÷ +×*Ò*ús   •B!C Ã C	)NÚ N)Úsingle)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   r    r&   r   r   r4   © ó    r%   r
   r
      sr   „ Ù*ð ØØ!%ñMàðMð ðMð ð	Mð
 ðMð ˜‘ðMð 
óMñ^
!˜ð 
!¨D°©Nô 
!r@   r
   )r0   r.   Útypingr   r   r   Úlangchain_core.documentsr   Ú)langchain_community.document_loaders.baser   Ú1langchain_community.document_loaders.unstructuredr   r
   r?   r@   r%   Ú<module>rE      s*   ðó 
Û ß &Ñ &å -å @Ý Tô\!�Jõ \!r@   