
    NgD                    v    d dl mZ d dlZd dlZd dlmZmZmZmZm	Z	m
Z
 d dlmZ erd dlZ G d de          ZdS )    )annotationsN)TYPE_CHECKINGAnyCallableListOptionalUnion)UnstructuredBaseLoaderc                  N     e Zd ZdZddddddddddddd! fdZd"dZd#d Z xZS )$S3FileLoaderzLoad from `Amazon AWS S3` file.NTsingle)region_nameapi_versionuse_sslverifyendpoint_urlaws_access_key_idaws_secret_access_keyaws_session_tokenboto_configmodepost_processorsbucketstrkeyr   Optional[str]r   r   Optional[bool]r   Union[str, bool, None]r   r   r   r   r    Optional[botocore.client.Config]r   r   Optional[List[Callable]]unstructured_kwargsr   c                    t                      j        ||fi | || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        dS )a  Initialize with bucket and key name.

        :param bucket: The name of the S3 bucket.
        :param key: The key of the S3 object.

        :param region_name: The name of the region associated with the client.
            A client is associated with a single region.

        :param api_version: The API version to use.  By default, botocore will
            use the latest API version when creating a client.  You only need
            to specify this parameter if you want to use a previous API version
            of the client.

        :param use_ssl: Whether or not to use SSL.  By default, SSL is used.
            Note that not all services support non-ssl connections.

        :param verify: Whether or not to verify SSL certificates.
            By default SSL certificates are verified.  You can provide the
            following values:

            * False - do not validate SSL certificates.  SSL will still be
              used (unless use_ssl is False), but SSL certificates
              will not be verified.
            * path/to/cert/bundle.pem - A filename of the CA cert bundle to
              uses.  You can specify this argument if you want to use a
              different CA cert bundle than the one used by botocore.

        :param endpoint_url: The complete URL to use for the constructed
            client.  Normally, botocore will automatically construct the
            appropriate URL to use when communicating with a service.  You can
            specify a complete URL (including the "http/https" scheme) to
            override this behavior.  If this value is provided, then
            ``use_ssl`` is ignored.

        :param aws_access_key_id: The access key to use when creating
            the client.  This is entirely optional, and if not provided,
            the credentials configured for the session will automatically
            be used.  You only need to provide this argument if you want
            to override the credentials used for this specific client.

        :param aws_secret_access_key: The secret key to use when creating
            the client.  Same semantics as aws_access_key_id above.

        :param aws_session_token: The session token to use when creating
            the client.  Same semantics as aws_access_key_id above.

        :type boto_config: botocore.client.Config
        :param boto_config: Advanced boto3 client configuration options. If a value
            is specified in the client config, its value will take precedence
            over environment variables and configuration values, but not over
            a value passed explicitly to the method. If a default config
            object is set on the session, the config object used when creating
            the client will be the result of calling ``merge()`` on the
            default config with the config provided to this call.
        :param mode: Mode in which to read the file. Valid options are: single,
            paged and elements.
        :param post_processors: Post processing functions to be applied to
            extracted elements.
        :param **unstructured_kwargs: Arbitrary additional kwargs to pass in when
            calling `partition`
        N)super__init__r   r   r   r   r   r   r   r   r   r   r   )selfr   r   r   r   r   r   r   r   r   r   r   r   r   r!   	__class__s                  h/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/s3_file.pyr$   zS3FileLoader.__init__   s    ^ 	FF2EFFF&&(!2%:"!2&    returnr   c                $   ddl m} 	 ddl}n# t          $ r t          d          w xY w|                    d| j        | j        | j        | j        | j	        | j
        | j        | j        | j        
  
        }t          j                    5 }| d| j         }t#          j        t"          j                            |          d	           |                    | j        | j        |            |dd
|i| j        cddd           S # 1 swxY w Y   dS )zGet elements.r   )	partitionNzTCould not import `boto3` python package. Please install it with `pip install boto3`.s3)	r   r   r   r   r   r   r   r   config/T)exist_okfilename )unstructured.partition.autor+   boto3ImportErrorclientr   r   r   r   r   r   r   r   r   tempfileTemporaryDirectoryr   osmakedirspathdirnamedownload_filer   r!   )r%   r+   r3   r,   temp_dir	file_paths         r'   _get_elementszS3FileLoader._get_elementsl   s   999999	LLLL 	 	 	>  	
 \\((L;*"4"&"<"4#  
 
 (** 	Mh#00dh00IK	22TBBBBT[$(I>>>9LLiL43KLL		M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	Ms    '	A/DD	D	dictc                *    dd| j          d| j         iS )Nsourcezs3://r.   )r   r   )r%   s    r'   _get_metadatazS3FileLoader._get_metadata   s"    :$+::::;;r(   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r   )r)   r   )r)   r@   )__name__
__module____qualname____doc__r$   r?   rC   __classcell__)r&   s   @r'   r   r      s        )) &*%)"&)-&*+//3+/8<48Z' Z' Z' Z' Z' Z' Z' Z'xM M M M:< < < < < < < <r(   r   )
__future__r   r8   r6   typingr   r   r   r   r   r	   1langchain_community.document_loaders.unstructuredr
   botocorer   r1   r(   r'   <module>rM      s    " " " " " " 				  F F F F F F F F F F F F F F F F T T T T T T OOO}< }< }< }< }<) }< }< }< }< }<r(   