U
    M8c5                     @   sN   d dl Z d dlmZ d dlmZmZ d dlmZmZm	Z	m
Z
 G dd dZdS )    N)OrderedDict)DEFAULT_TIMEOUTMAX_POOL_CONNECTIONS)InvalidMaxRetryAttemptsErrorInvalidRetryConfigurationErrorInvalidRetryModeErrorInvalidS3AddressingStyleErrorc                   @   sz   e Zd ZdZedddddefdefdd	efd
ddddddddddgZddiZdd Z	dd Z
dd Zdd Zdd ZdS ) Configa  Advanced configuration for Botocore clients.

    :type region_name: str
    :param region_name: The region to use in instantiating the client

    :type signature_version: str
    :param signature_version: The signature version when signing requests.

    :type user_agent: str
    :param user_agent: The value to use in the User-Agent header.

    :type user_agent_extra: str
    :param user_agent_extra: The value to append to the current User-Agent
        header value.

    :type connect_timeout: float or int
    :param connect_timeout: The time in seconds till a timeout exception is
        thrown when attempting to make a connection. The default is 60
        seconds.

    :type read_timeout: float or int
    :param read_timeout: The time in seconds till a timeout exception is
        thrown when attempting to read from a connection. The default is
        60 seconds.

    :type parameter_validation: bool
    :param parameter_validation: Whether parameter validation should occur
        when serializing requests. The default is True.  You can disable
        parameter validation for performance reasons.  Otherwise, it's
        recommended to leave parameter validation enabled.

    :type max_pool_connections: int
    :param max_pool_connections: The maximum number of connections to
        keep in a connection pool.  If this value is not set, the default
        value of 10 is used.

    :type proxies: dict
    :param proxies: A dictionary of proxy servers to use by protocol or
        endpoint, e.g.:
        {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.
        The proxies are used on each request.

    :type proxies_config: dict
    :param proxies_config: A dictionary of additional proxy configurations.
        Valid keys are:

        * 'proxy_ca_bundle' -- The path to a custom certificate bundle to use
          when establishing SSL/TLS connections with proxy.

        * 'proxy_client_cert' -- The path to a certificate for proxy
          TLS client authentication.

          When a str is provided it is treated as a path to a proxy client
          certificate. When a two element tuple is provided, it will be
          interpreted as the path to the client certificate, and the path
          to the certificate key.

        * 'proxy_use_forwarding_for_https' -- For HTTPS proxies,
          forward your requests to HTTPS destinations with an absolute
          URI. We strongly recommend you only use this option with
          trusted or corporate proxies. Value must be boolean.

    :type s3: dict
    :param s3: A dictionary of s3 specific configurations.
        Valid keys are:

        * 'use_accelerate_endpoint' -- Refers to whether to use the S3
          Accelerate endpoint. The value must be a boolean. If True, the
          client will use the S3 Accelerate endpoint. If the S3 Accelerate
          endpoint is being used then the addressing style will always
          be virtual.

        * 'payload_signing_enabled' -- Refers to whether or not to SHA256
          sign sigv4 payloads. By default, this is disabled for streaming
          uploads (UploadPart and PutObject).

        * 'addressing_style' -- Refers to the style in which to address
          s3 endpoints. Values must be a string that equals:

          * auto -- Addressing style is chosen for user. Depending
            on the configuration of client, the endpoint may be addressed in
            the virtual or the path style. Note that this is the default
            behavior if no style is specified.

          * virtual -- Addressing style is always virtual. The name of the
            bucket must be DNS compatible or an exception will be thrown.
            Endpoints will be addressed as such: mybucket.s3.amazonaws.com

          * path -- Addressing style is always by path. Endpoints will be
            addressed as such: s3.amazonaws.com/mybucket

        * 'us_east_1_regional_endpoint' - Refers to what S3 endpoint to use
          when the region is configured to be us-east-1. Values must be a
          string that equals:

           * regional -- Use the us-east-1.amazonaws.com endpoint if the
             client is configured to use the us-east-1 region.

           * legacy -- Use the s3.amazonaws.com endpoint if the client is
             configured to use the us-east-1 region. This is the default if
             the configuration option is not specified.


    :type retries: dict
    :param retries: A dictionary for retry specific configurations.
        Valid keys are:

        * 'total_max_attempts' -- An integer representing the maximum number of
          total attempts that will be made on a single request.  This includes
          the initial request, so a value of 1 indicates that no requests
          will be retried.  If ``total_max_attempts`` and ``max_attempts``
          are both provided, ``total_max_attempts`` takes precedence.
          ``total_max_attempts`` is preferred over ``max_attempts`` because
          it maps to the ``AWS_MAX_ATTEMPTS`` environment variable and
          the ``max_attempts`` config file value.
        * 'max_attempts' -- An integer representing the maximum number of
          retry attempts that will be made on a single request. For
          example, setting this value to 2 will result in the request
          being retried at most two times after the initial request. Setting
          this value to 0 will result in no retries ever being attempted on
          the initial request. If not provided, the number of retries will
          default to whatever is modeled, which is typically four retries.
        * 'mode' -- A string representing the type of retry mode botocore
          should use.  Valid values are:
              * ``legacy`` - The pre-existing retry behavior.
              * ``standard`` - The standardized set of retry rules.  This
                will also default to 3 max attempts unless overridden.
              * ``adaptive`` - Retries with additional client side throttling.

    :type client_cert: str, (str, str)
    :param client_cert: The path to a certificate for TLS client authentication.

        When a str is provided it is treated as a path to a client certificate
        to be used when creating a TLS connection.

        If a client key is to be provided alongside the client certificate the
        client_cert should be set to a tuple of length two where the first
        element is the path to the client certificate and the second element is
        the path to the certificate key.

    :type inject_host_prefix: bool
    :param inject_host_prefix: Whether host prefix injection should occur.

        Defaults to True.

        Setting this to False disables the injection of operation parameters
        into the prefix of the hostname. This is useful for clients providing
        custom endpoints that should not have their host prefix modified.

    :type use_dualstack_endpoint: bool
    :param use_dualstack_endpoint: Setting to True enables dualstack
        endpoint resolution.

        Defaults to None.

    :type use_fips_endpoint: bool
    :param use_fips_endpoint: Setting to True enables fips
        endpoint resolution.

        Defaults to None.

    :type tcp_keepalive: bool
    :param tcp_keepalive: Enables the TCP Keep-Alive socket option used when
        creating new connections if set to True.

        Defaults to False.
    )Zregion_nameN)Zsignature_versionN)
user_agentN)Zuser_agent_extraNconnect_timeoutread_timeout)Zparameter_validationTZmax_pool_connections)proxiesN)Zproxies_configN)s3N)retriesN)client_certN)Zinject_host_prefixT)Zendpoint_discovery_enabledN)Zuse_dualstack_endpointN)Zuse_fips_endpointN)defaults_modeN)Ztcp_keepaliveNNc                 O   s   |  ||| _t| j}| jdd}|dkr<|| j || j | D ]\}}t| || qP| 	| j
 | | j d S )Nr   legacy)_record_user_provided_options_user_provided_optionscopyOPTION_DEFAULTSgetupdateNON_LEGACY_OPTION_DEFAULTSitemssetattr_validate_s3_configurationr   _validate_retry_configurationr   )selfargskwargsconfig_varsr   keyvalue r$   3/tmp/pip-unpacked-wheel-ozje0y8b/botocore/config.py__init__   s       zConfig.__init__c           	      C   s   t | j}i }| D ],\}}|| jkr2|||< qtd| dqt|t|krrtdt| dt| dt|D ]4\}}|| |krtd||  d|||| < qz|S )Nz!Got unexpected keyword argument ''zTakes at most z arguments (z given)z*Got multiple values for keyword argument ')listr   r   	TypeErrorlen	enumerate)	r   r   r    option_orderZuser_provided_optionsr"   r#   iargr$   r$   r%   r      s"    


z$Config._record_user_provided_optionsc                 C   s(   |d k	r$| d}|dkr$t|dd S )Naddressing_style)ZvirtualautopathN)Zs3_addressing_style)r   r   )r   r   r/   r$   r$   r%   r     s    
z!Config._validate_s3_configurationc                 C   s   d}d}|d k	r|  D ]p\}}||kr4t||d|dkrP|dk rPt|dd|dkrl|dk rlt|dd|d	kr||krt||d
qd S )N)max_attemptsmodetotal_max_attempts)r   standardZadaptive)Zretry_config_optionvalid_optionsr2   r   )Zprovided_max_attemptsZ	min_valuer4      r3   )Zprovided_retry_modevalid_modes)r   r   r   r   )r   r   r6   r8   r"   r#   r$   r$   r%   r     s0    z$Config._validate_retry_configurationc                 C   s"   t  | j}||j tf |S )a  Merges the config object with another config object

        This will merge in all non-default values from the provided config
        and return a new config object

        :type other_config: botocore.config.Config
        :param other config: Another config object to merge with. The values
            in the provided config object will take precedence in the merging

        :returns: A config object built from the merged values of both
            config objects.
        )r   r   r   r	   )r   Zother_configZconfig_optionsr$   r$   r%   merge7  s    zConfig.merge)__name__
__module____qualname____doc__r   r   r   r   r   r&   r   r   r   r9   r$   r$   r$   r%   r	      s@    )  r	   )r   Zbotocore.compatr   Zbotocore.endpointr   r   Zbotocore.exceptionsr   r   r   r   r	   r$   r$   r$   r%   <module>   s   