U
    M8c                     @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlmZmZmZmZmZmZmZmZmZ ddlmZmZ ddlmZmZmZmZmZmZ ddlm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z& ddl'm(Z(m)Z)m*Z* dd	l+m,Z, dd
l-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6 e7e8Z9G dd dZ:G dd dZ;G dd deZ<G dd dZ=dddZ>dS )zV
This module contains the main interface to the botocore package, the
Session object.
    N)	UNSIGNED__version__handlersinvoke_initializers
monitoringpaginateretryhandler	translatewaiter)HAS_CRTMutableMapping)!BOTOCORE_DEFAUT_SESSION_VARIABLESConfigChainFactoryConfigValueStoreDefaultConfigResolverSmartDefaultsConfigStoreFactory&create_botocore_default_config_mapping)ClientExceptionsFactory)ConfigNotFoundInvalidDefaultsModePartialCredentialsErrorProfileNotFoundUnknownServiceError)EventAliaserHierarchicalEmitterfirst_non_none_response)create_loader)ServiceModel)ResponseParserFactory)EndpointResolver)EVENT_ALIASESIMDSRegionProvidervalidate_region_namec                	   @   s  e Zd ZdZeeZdZd|ddZdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zed)d* Zd+d, Zed-d. Zd}d/d0Zd1d2 Zd3d4 Z d5d6 Z!d7d8 Z"ed9d: Z#d;d< Z$d=d> Z%d~d?d@Z&dAdB Z'dCdD Z(dEdF Z)dGdH Z*ddIdJZ+ddKdLZ,ddMdNZ-ddOdPZ.dQdR Z/ddTdUZ0ddVdWZ1ddXdYZ2dd[d\Z3dd]d^Z4d_d` Z5dadb Z6dcdd Z7dedf Z8dgdh Z9didj Z:dkdl Z;ddmdnZ<dodp Z=dqdr Z>dsdt Z?dudv Z@dwdx ZAddzd{ZBdS )Sessionae  
    The Session object collects together useful functionality
    from `botocore` as well as important data such as configuration
    information and credentials into a single, easy-to-use object.

    :ivar available_profiles: A list of profiles defined in the config
        file associated with this session.
    :ivar profile: The current profile.
    z4%(asctime)s - %(name)s - %(levelname)s - %(message)sNTc                 C   s   |dkrt  | _n|| _t| j| _|r4| | j d| _t| _d| _d| _	d| _
d| _d| _d| _i | _|dk	r||| jd< d| _d| _t | _t | _|   t| | j| _|dk	r| j| t|  dS )a  
        Create a new Session object.

        :type session_vars: dict
        :param session_vars: A dictionary that is used to override some or all
            of the environment variables associated with this session.  The
            key/value pairs defined in this dictionary will override the
            corresponding variables defined in ``SESSION_VARIABLES``.

        :type event_hooks: BaseEventHooks
        :param event_hooks: The event hooks object to use. If one is not
            provided, an event hooks object will be automatically created
            for you.

        :type include_builtin_handlers: bool
        :param include_builtin_handlers: Indicates whether or not to
            automatically register builtin handlers.

        :type profile: str
        :param profile: The name of the profile to use for this
            session.  Note that the profile can only be set when
            the session is created.

        NZBotocore profile)r   Z_original_handlerr   _events_register_builtin_handlersuser_agent_namer   user_agent_versionuser_agent_extra_profile_config_credentials_auth_token_profile_map_session_instance_vars_client_config_last_client_region_usedComponentLocator_components_internal_components_register_componentsSessionVarDictSESSION_VARIABLESsession_var_mapupdater   )selfsession_varsZevent_hooksZinclude_builtin_handlersr%    r=   4/tmp/pip-unpacked-wheel-ozje0y8b/botocore/session.py__init__\   s4    

zSession.__init__c                 C   s\   |    |   |   |   |   |   |   |   |   | 	  | 
  d S N)_register_credential_provider_register_token_provider_register_data_loader_register_endpoint_resolver_register_event_emitter!_register_response_parser_factory_register_exceptions_factory_register_config_store_register_monitor!_register_default_config_resolver _register_smart_defaults_factoryr;   r=   r=   r>   r6      s    zSession._register_componentsc                 C   s   | j d| j d S )Nevent_emitter)r4   register_componentr&   rL   r=   r=   r>   rE      s    zSession._register_event_emitterc                 C   s   | j d| j d S )Ntoken_provider)r4   lazy_register_component_create_token_resolverrL   r=   r=   r>   rB      s     z Session._register_token_providerc                 C   s   t j| S r@   )botocoretokensZcreate_token_resolverrL   r=   r=   r>   rQ      s    zSession._create_token_resolverc                 C   s   | j d| j d S )Ncredential_provider)r4   rP   _create_credential_resolverrL   r=   r=   r>   rA      s     z%Session._register_credential_providerc                 C   s   t jj| | jdS )N)region_name)rR   credentialsZcreate_credential_resolverr2   rL   r=   r=   r>   rU      s     z#Session._create_credential_resolverc                    s    j d fdd d S )Ndata_loaderc                      s   t  dS )N	data_path)r   get_config_variabler=   rL   r=   r>   <lambda>       z/Session._register_data_loader.<locals>.<lambda>r4   rP   rL   r=   rL   r>   rC      s    
zSession._register_data_loaderc                    s    fdd} j d| d S )Nc                     s.     d} | d\}}| |}t||dS )NrX   	endpoints)Zuses_builtin_data)get_componentZload_data_with_pathZis_builtin_pathr   )loaderr^   pathZuses_builtinrL   r=   r>   create_default_resolver   s    

zDSession._register_endpoint_resolver.<locals>.create_default_resolverendpoint_resolverr5   rP   )r;   rb   r=   rL   r>   rD      s
     z#Session._register_endpoint_resolverc                    s    fdd} j d| d S )Nc                     s     d} | d}t|S )NrX   zsdk-default-configuration)r_   	load_datar   )r`   defaultsrL   r=   r>   create_default_config_resolver   s    

zQSession._register_default_config_resolver.<locals>.create_default_config_resolverdefault_config_resolverrd   )r;   rg   r=   rL   r>   rJ      s
     z)Session._register_default_config_resolverc                    s    fdd} j d| d S )Nc                     s     d} t d}t| |S )Nrh   session)_get_internal_componentr!   r   )rh   Zimds_region_providerrL   r=   r>   create_smart_defaults_factory   s    
 zOSession._register_smart_defaults_factory.<locals>.create_smart_defaults_factorysmart_defaults_factoryrd   )r;   rl   r=   rL   r>   rK      s
    	 z(Session._register_smart_defaults_factoryc                 C   s   | j dt  d S )Nresponse_parser_factory)r4   rN   r   rL   r=   r=   r>   rF      s     z)Session._register_response_parser_factoryc                 C   s   | j dt  d S )Nexceptions_factory)r5   rN   r   rL   r=   r=   r>   rG      s     z$Session._register_exceptions_factoryc                 C   sn   t jD ]b}t|dkr,|\}}| || q|\}}}|t jkrP| j|| q|t jkr| j|| qd S )N   )	r   ZBUILTIN_HANDLERSlenregisterZREGISTER_FIRSTr&   Zregister_firstZREGISTER_LASTZregister_last)r;   eventsspec
event_namehandlerZregister_typer=   r=   r>   r'      s    



z"Session._register_builtin_handlersc                 C   s    t t| d}| jd| d S )Nmappingconfig_store)r   r   r4   rN   )r;   config_store_componentr=   r=   r>   rH      s     zSession._register_config_storec                 C   s   | j d| j d S )Nmonitor)r5   rP   _create_csm_monitorrL   r=   r=   r>   rI     s     zSession._register_monitorc              	   C   sd   |  dr`|  d}|  d}|  d}tjt tjttjtj||tj|ddd}|S d S )NZcsm_enabledcsm_client_idZcsm_hostZcsm_port)r}   )sockethostport
serializer)adapterZ	publisher)	rZ   r   ZMonitorZMonitorEventAdapterZSocketPublisherr~   AF_INET
SOCK_DGRAMZCSMSerializer)r;   Z	client_idr   r   rv   r=   r=   r>   r|   
  s"    



zSession._create_csm_monitorc                 C   s,   zdd l }|jW S  tk
r&   Y dS X d S )Nr   Unknown)awscrtr   AttributeError)r;   r   r=   r=   r>   _get_crt_version  s
    zSession._get_crt_versionc                 C   s   t |   S r@   )list_build_profile_mapkeysrL   r=   r=   r>   available_profiles%  s    zSession.available_profilesc                 C   s   | j d kr| jd | _ | j S )Nprofiles)r/   full_configrL   r=   r=   r>   r   )  s    
zSession._build_profile_mapc                 C   s    | j d kr| d}|| _ | j S )Nr%   )r+   rZ   )r;   r%   r=   r=   r>   r%   1  s    

zSession.profilec                 C   s$   |d k	r|  ||S | d|S )Nry   )(_get_config_variable_with_custom_methodsr_   rZ   )r;   logical_namemethodsr=   r=   r>   rZ   8  s     
zSession.get_config_variablec                 C   s   t | |d}t| }| j D ]^\}}|\}}}	}
|
|	d}d|krL||d< d|kr\||d< d|krl||d< |jf |||< qt|d	}||}|S )
N)rj   r   )conversion_funcdefaultinstanceinstance_nameenvenv_var_namesconfigconfig_property_namerw   )SubsetChainConfigFactoryr   r9   itemscreate_config_chainr   rZ   )r;   r   r   Zchain_builderrx   nameconfig_optionsconfig_nameenv_varsr   typecastZbuild_chain_config_argsrz   valuer=   r=   r>   r   A  s&    


z0Session._get_config_variable_with_custom_methodsc                 C   s   t d|| || j|< dS )a  Set a configuration variable to a specific value.

        By using this method, you can override the normal lookup
        process used in ``get_config_variable`` by explicitly setting
        a value.  Subsequent calls to ``get_config_variable`` will
        use the ``value``.  This gives you per-session specific
        configuration values.

        ::
            >>> # Assume logical name 'foo' maps to env var 'FOO'
            >>> os.environ['FOO'] = 'myvalue'
            >>> s.get_config_variable('foo')
            'myvalue'
            >>> s.set_config_variable('foo', 'othervalue')
            >>> s.get_config_variable('foo')
            'othervalue'

        :type logical_name: str
        :param logical_name: The logical name of the session variable
            you want to set.  These are the keys in ``SESSION_VARIABLES``.
        :param value: The value to associate with the config variable.

        z$Setting config variable for %s to %rN)loggerdebugr0   )r;   r   r   r=   r=   r>   set_config_variable]  s    zSession.set_config_variablec                 C   s   t  | jS r@   )copyr0   rL   r=   r=   r>   instance_variables|  s    zSession.instance_variablesc                 C   sF   |  d}|  }|dkr&|di S ||kr:t|dn|| S dS )a5  
        Returns the config values from the config file scoped to the current
        profile.

        The configuration data is loaded **only** from the config file.
        It does not resolve variables based on different locations
        (e.g. first from the session instance, then from environment
        variables, then from the config file).  If you want this lookup
        behavior, use the ``get_config_variable`` method instead.

        Note that this configuration is specific to a single profile (the
        ``profile`` session variable).

        If the ``profile`` session variable is set and the profile does
        not exist in the config file, a ``ProfileNotFound`` exception
        will be raised.

        :raises: ConfigNotFound, ConfigParseError, ProfileNotFound
        :rtype: dict

        r%   Nr   )r%   )rZ   r   getr   )r;   Zprofile_nameZprofile_mapr=   r=   r>   get_scoped_config  s    
zSession.get_scoped_configc                 C   s   | j dkrz| d}tj|| _ W n tk
rD   di i| _ Y nX z^| d}tj|}|D ]>}|| }|| j d kr|| j d |< qb| j d | | qbW n tk
r   Y nX | j S )zReturn the parsed config file.

        The ``get_config`` method returns the config associated with the
        specified profile.  This property returns the contents of the
        **entire** config file.

        :rtype: dict
        Nconfig_filer   Zcredentials_file)r,   rZ   rR   ZconfigloaderZload_configr   Zraw_config_parser:   )r;   r   Z	cred_fileZcred_profilesr%   Z	cred_varsr=   r=   r>   r     s&    



zSession.full_configc                 C   s   | j S )a  Retrieves the default config for creating clients

        :rtype: botocore.client.Config
        :returns: The default client config object when creating clients. If
            the value is ``None`` then there is no default config object
            attached to the session.
        r1   rL   r=   r=   r>   get_default_client_config  s    z!Session.get_default_client_configc                 C   s
   || _ dS )a1  Sets the default config for creating clients

        :type client_config: botocore.client.Config
        :param client_config: The default client config object when creating
            clients. If the value is ``None`` then there is no default config
            object attached to the session.
        Nr   )r;   client_configr=   r=   r>   set_default_client_config  s    z!Session.set_default_client_configc                 C   s   t j|||| _dS )aO  
        Manually create credentials for this session.  If you would
        prefer to use botocore without a config file, environment variables,
        or IAM roles, you can pass explicit credentials into this
        method to establish credentials for this session.

        :type access_key: str
        :param access_key: The access key part of the credentials.

        :type secret_key: str
        :param secret_key: The secret key part of the credentials.

        :type token: str
        :param token: An option session token used by STS session
            credentials.
        N)rR   rW   Credentialsr-   )r;   
access_key
secret_keytokenr=   r=   r>   set_credentials  s
      zSession.set_credentialsc                 C   s"   | j dkr| jd | _ | j S )a$  
        Return the :class:`botocore.credential.Credential` object
        associated with this session.  If the credentials have not
        yet been loaded, this will attempt to load them.  If they
        have already been loaded, this will return the cached
        credentials.

        NrT   )r-   r4   r_   Zload_credentialsrL   r=   r=   r>   get_credentials  s
    	

zSession.get_credentialsc                 C   s&   | j dkr | jd}| | _ | j S )a  
        Return the :class:`botocore.tokens.AuthToken` object associated with
        this session. If the authorization token has not yet been loaded, this
        will attempt to load it. If it has already been loaded, this will
        return the cached authorization token.

        NrO   )r.   r4   r_   Z
load_token)r;   providerr=   r=   r>   get_auth_token   s    

zSession.get_auth_tokenc              
   C   s   | j  d| j dt  dt  dt  	}trD|d|   7 }tj	
ddk	rh|dtj	
d 7 }| jr||d| j 7 }|S )	ak  
        Return a string suitable for use as a User-Agent header.
        The string will be of the form:

        <agent_name>/<agent_version> Python/<py_ver> <plat_name>/<plat_ver> <exec_env>

        Where:

         - agent_name is the value of the `user_agent_name` attribute
           of the session object (`Botocore` by default).
         - agent_version is the value of the `user_agent_version`
           attribute of the session object (the botocore version by default).
           by default.
         - py_ver is the version of the Python interpreter beng used.
         - plat_name is the name of the platform (e.g. Darwin)
         - plat_ver is the version of the platform
         - exec_env is exec-env/$AWS_EXECUTION_ENV

        If ``user_agent_extra`` is not empty, then this value will be
        appended to the end of the user agent string.

        /z Python/ z
 awscrt/%sZAWS_EXECUTION_ENVNz exec-env/%sz %s)r(   r)   platformpython_versionsystemreleaser   r   osenvironr   r*   )r;   baser=   r=   r>   
user_agent  s    .zSession.user_agentc                 C   s   |  d|S )z
        Retrieve the data associated with `data_path`.

        :type data_path: str
        :param data_path: The path to the data you wish to retrieve.
        rX   )r_   re   )r;   rY   r=   r=   r>   get_data2  s    zSession.get_datac                 C   s   |  ||}t||dS )a  Get the service model object.

        :type service_name: string
        :param service_name: The service name

        :type api_version: string
        :param api_version: The API version of the service.  If none is
            provided, then the latest API version will be used.

        :rtype: L{botocore.model.ServiceModel}
        :return: The botocore service model for the service.

        )service_name)get_service_datar   )r;   r   api_versionZservice_descriptionr=   r=   r>   get_service_model;  s    zSession.get_service_modelc                 C   s"   |  d}||d|}t|S )NrX   z	waiters-2)r_   load_service_modelr
   ZWaiterModel)r;   r   r   r`   Zwaiter_configr=   r=   r>   get_waiter_modelL  s    
  zSession.get_waiter_modelc                 C   s"   |  d}||d|}t|S )NrX   zpaginators-1)r_   r   r   ZPaginatorModel)r;   r   r   r`   Zpaginator_configr=   r=   r>   get_paginator_modelS  s    
  zSession.get_paginator_modelc                 C   sB   |}|  dj|d|d}t||}| jjd| ||| d |S )zK
        Retrieve the fully merged data associated with a service.
        rX   	service-2)	type_namer   zservice-data-loaded.%s)service_datar   rj   )r_   r   r    r   r&   emit)r;   r   r   rY   r   Z
service_idr=   r=   r>   r   Z  s    
  zSession.get_service_datac                 C   s   |  djddS )z?
        Return a list of names of available services.
        rX   r   )r   )r_   Zlist_available_servicesrL   r=   r=   r>   get_available_servicesk  s    
zSession.get_available_servicesrR   c                 C   s   |  |tj dS )zk
        Convenience function to quickly configure full debug output
        to go to the console.
        N)set_stream_loggerloggingDEBUG)r;   logger_namer=   r=   r>   set_debug_loggers  s    zSession.set_debug_loggerc                 C   sZ   t |}|t j t |}|| |dkr8| j}t |}|| || dS )a  
        Convenience method to configure a stream logger.

        :type logger_name: str
        :param logger_name: The name of the logger to configure

        :type log_level: str
        :param log_level: The log level to set for the logger.  This
            is any param supported by the ``.setLevel()`` method of
            a ``Log`` object.

        :type stream: file
        :param stream: A file like object to log to.  If none is provided
            then sys.stderr will be used.

        :type format_string: str
        :param format_string: The format string to use for the log
            formatter.  If none is provided this will default to
            ``self.LOG_FORMAT``.

        N)	r   	getLoggersetLevelr   StreamHandler
LOG_FORMAT	FormattersetFormatter
addHandler)r;   r   	log_levelstreamformat_stringlogch	formatterr=   r=   r>   r   z  s    




zSession.set_stream_loggerc                 C   sN   t |}|t j t |}|| t | j}|| || dS )aV  
        Convenience function to quickly configure any level of logging
        to a file.

        :type log_level: int
        :param log_level: A log level as specified in the `logging` module

        :type path: string
        :param path: Path to the log file.  The file will be created
            if it doesn't already exist.
        N)	r   r   r   r   FileHandlerr   r   r   r   )r;   r   ra   r   r   r   r   r=   r=   r>   set_file_logger  s    



zSession.set_file_loggerFc                 C   s   | j j||||d dS )a)  Register a handler with an event.

        :type event_name: str
        :param event_name: The name of the event.

        :type handler: callable
        :param handler: The callback to invoke when the event
            is emitted.  This object must be callable, and must
            accept ``**kwargs``.  If either of these preconditions are
            not met, a ``ValueError`` will be raised.

        :type unique_id: str
        :param unique_id: An optional identifier to associate with the
            registration.  A unique_id can only be used once for
            the entire session registration (unless it is unregistered).
            This can be used to prevent an event handler from being
            registered twice.

        :param unique_id_uses_count: boolean
        :param unique_id_uses_count: Specifies if the event should maintain
            a count when a ``unique_id`` is registered and unregisted. The
            event can only be completely unregistered once every register call
            using the unique id has been matched by an ``unregister`` call.
            If ``unique_id`` is specified, subsequent ``register``
            calls must use the same value for  ``unique_id_uses_count``
            as the ``register`` call that first registered the event.

        :raises ValueError: If the call to ``register`` uses ``unique_id``
            but the value for ``unique_id_uses_count`` differs from the
            ``unique_id_uses_count`` value declared by the very first
            ``register`` call for that ``unique_id``.
        )unique_id_uses_countN)r&   rr   r;   ru   rv   	unique_idr   r=   r=   r>   rr     s    #zSession.registerc                 C   s   | j j||||d dS )a  Unregister a handler with an event.

        :type event_name: str
        :param event_name: The name of the event.

        :type handler: callable
        :param handler: The callback to unregister.

        :type unique_id: str
        :param unique_id: A unique identifier identifying the callback
            to unregister.  You can provide either the handler or the
            unique_id, you do not have to provide both.

        :param unique_id_uses_count: boolean
        :param unique_id_uses_count: Specifies if the event should maintain
            a count when a ``unique_id`` is registered and unregisted. The
            event can only be completely unregistered once every ``register``
            call using the ``unique_id`` has been matched by an ``unregister``
            call. If the ``unique_id`` is specified, subsequent
            ``unregister`` calls must use the same value for
            ``unique_id_uses_count`` as the ``register`` call that first
            registered the event.

        :raises ValueError: If the call to ``unregister`` uses ``unique_id``
            but the value for ``unique_id_uses_count`` differs from the
            ``unique_id_uses_count`` value declared by the very first
            ``register`` call for that ``unique_id``.
        )rv   r   r   N)r&   
unregisterr   r=   r=   r>   r     s    #zSession.unregisterc                 K   s   | j j|f|S r@   )r&   r   )r;   ru   kwargsr=   r=   r>   r     s    zSession.emitc                 K   s   | j j|f|}t|S r@   )r&   r   r   )r;   ru   r   	responsesr=   r=   r>   emit_first_non_none_response  s    z$Session.emit_first_non_none_responsec                 C   sR   z| j |W S  tk
rL   |dkrFtd| t | j| Y S  Y nX d S )N)rc   ro   zFetching the %s component with the get_component() method is deprecated as the component has always been considered an internal interface of botocore)r4   r_   
ValueErrorwarningswarnDeprecationWarningr5   r;   r   r=   r=   r>   r_     s    zSession.get_componentc                 C   s   | j |S r@   )r5   r_   r   r=   r=   r>   rk   (  s    zSession._get_internal_componentc                 C   s   | j ||S r@   )r5   rN   r;   r   	componentr=   r=   r>   _register_internal_component.  s    z$Session._register_internal_componentc                 C   s   | j || d S r@   )r4   rN   r   r=   r=   r>   rN   4  s    zSession.register_componentc                 C   s   | j || d S r@   r]   r   r=   r=   r>   rP   7  s    zSession.lazy_register_componentc                 C   s  |   }|
dk	r$|dk	r$||
}
n|dk	r0|}
| ||
}|dkrN| d}|dkrh| d|d}| d}| d}| d}|
dk	r|
jtkrd}nN|dk	r|dk	rtj	j
|||	d}n*| ||rtd| ||d	n|  }|  }| d
}| d}| d}| |
|}|dkrJ| d}t|}|||| tj|||  |tt|||	}|j|||||||  |
||d
}| d}|dk	r||jj |S )aP  Create a botocore client.

        :type service_name: string
        :param service_name: The name of the service for which a client will
            be created.  You can use the ``Session.get_available_services()``
            method to get a list of all available service names.

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

        :type api_version: string
        :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.

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

        :type verify: boolean/string
        :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.

        :type endpoint_url: string
        :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.

        :type aws_access_key_id: string
        :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.

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

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

        :type config: botocore.client.Config
        :param config: Advanced 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.

        :rtype: botocore.client.BaseClient
        :return: A botocore client instance

        NZ	ca_bundleZapi_versionsrX   rM   rn   )r   r   r   explicit)r   Zcred_varrc   ro   ry   legacyrm   )
r   rV   Z	is_secureendpoint_urlverifyrW   Zscoped_configr   r   
auth_tokenr{   )r   merge_resolve_region_namerZ   r   r_   Zsignature_versionr   rR   rW   r   _missing_cred_varsr   r   r   rk   _resolve_defaults_moder   deepcopyZmerge_smart_defaultsclientZClientCreatorr   r   r	   create_clientr   rr   metars   )r;   r   rV   r   Zuse_sslr   r   aws_access_key_idaws_secret_access_keyZaws_session_tokenr   Zdefault_client_configr`   rM   rn   rW   r   rc   ro   ry   defaults_moderm   Zclient_creatorr   r{   r=   r=   r>   r   :  s    R

 


 




  

zSession.create_clientc                 C   s:   |d kr(|r|j d k	r|j }n
| d}t| || _|S )NZregion)rV   rZ   r"   r2   )r;   rV   r   r=   r=   r>   r     s    

zSession._resolve_region_namec                 C   sR   | d}|r|jr|j}| d}| }| }||krNt|d|d|S )Nr   rh   z, )modeZvalid_modes)rZ   r   rk   Zget_default_modeslowerr   join)r;   r   ry   r  rh   Zdefault_modesZlmoder=   r=   r>   r     s    

 zSession._resolve_defaults_modec                 C   s,   |d k	r|d krdS |d k	r(|d kr(dS d S )Nr   r   r=   )r;   r   r   r=   r=   r>   r   	  s
    zSession._missing_cred_varsc                 C   s   |  d}| S )zLists the available partitions found on disk

        :rtype: list
        :return: Returns a list of partition names (e.g., ["aws", "aws-cn"])
        rc   )rk   get_available_partitions)r;   resolverr=   r=   r>   r    s    
z Session.get_available_partitionsc                 C   s   |  d}||S )a  Lists the partition name of a particular region.

        :type region_name: string
        :param region_name: Name of the region to list partition for (e.g.,
             us-east-1).

        :rtype: string
        :return: Returns the respective partition name (e.g., aws).
        rc   )rk   get_partition_for_region)r;   rV   r  r=   r=   r>   r    s    

z Session.get_partition_for_regionawsc                 C   sT   |  d}g }z,| |}|d d|}||||}W n tk
rN   Y nX |S )a]  Lists the region and endpoint names of a particular partition.

        :type service_name: string
        :param service_name: Name of a service to list endpoint for (e.g., s3).
            This parameter accepts a service name (e.g., "elb") or endpoint
            prefix (e.g., "elasticloadbalancing").

        :type partition_name: string
        :param partition_name: Name of the partition to limit endpoints to.
            (e.g., aws for the public AWS endpoints, aws-cn for AWS China
            endpoints, aws-us-gov for AWS GovCloud (US) Endpoints, etc.

        :type allow_non_regional: bool
        :param allow_non_regional: Set to True to include endpoints that are
             not regional endpoints (e.g., s3-external-1,
             fips-us-gov-west-1, etc).
        :return: Returns a list of endpoint names (e.g., ["us-east-1"]).
        rc   metadataZendpointPrefix)rk   r   r   Zget_available_endpointsr   )r;   r   Zpartition_nameZallow_non_regionalr  resultsr   Zendpoint_prefixr=   r=   r>   get_available_regions&  s     

   zSession.get_available_regions)NNTN)N)N)N)N)N)N)rR   )NN)rR   )NF)NNF)	NNTNNNNNN)r  F)C__name__
__module____qualname____doc__r   r   r8   r   r?   r6   rE   rB   rQ   rA   rU   rC   rD   rJ   rK   rF   rG   r'   rH   rI   r|   r   propertyr   r   r%   rZ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rr   r   r   r   r_   rk   r   rN   rP   r   r   r   r   r  r  r
  r=   r=   r=   r>   r#   L   s   

    
@



	%
#


%	




   
)
   
-   
*         
 (	   r#   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )r3   z'Service locator for session components.c                 C   s   i | _ i | _d S r@   )r4   	_deferredrL   r=   r=   r>   r?   M  s    zComponentLocator.__init__c                 C   sZ   || j kr(| j | }| | j|< | j |= z| j| W S  tk
rT   td| Y nX d S )NzUnknown component: %s)r  r4   KeyErrorr   )r;   r   factoryr=   r=   r>   r_   Q  s    

zComponentLocator.get_componentc                 C   s0   || j |< z| j|= W n tk
r*   Y nX d S r@   )r4   r  r  r   r=   r=   r>   rN   ^  s
    
z#ComponentLocator.register_componentc                 C   s0   || j |< z| j|= W n tk
r*   Y nX d S r@   )r  r4   r  )r;   r   Zno_arg_factoryr=   r=   r>   rP   e  s
    
z(ComponentLocator.lazy_register_componentN)r  r  r  r  r?   r_   rN   rP   r=   r=   r=   r>   r3   J  s
   r3   c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )r7   c                 C   s   || _ t|| _d S r@   )_sessionr   _store)r;   rj   r<   r=   r=   r>   r?   n  s    zSessionVarDict.__init__c                 C   s
   | j | S r@   r  r;   keyr=   r=   r>   __getitem__r  s    zSessionVarDict.__getitem__c                 C   s   || j |< | || d S r@   )r  &_update_config_store_from_session_vars)r;   r  r   r=   r=   r>   __setitem__u  s    
zSessionVarDict.__setitem__c                 C   s   | j |= d S r@   r  r  r=   r=   r>   __delitem__y  s    zSessionVarDict.__delitem__c                 C   s
   t | jS r@   )iterr  rL   r=   r=   r>   __iter__|  s    zSessionVarDict.__iter__c                 C   s
   t | jS r@   )rq   r  rL   r=   r=   r>   __len__  s    zSessionVarDict.__len__c           	   
   C   sD   t | jd}|\}}}}| jd}|||j|||||d d S )Nri   ry   r   r   Zconfig_property_namesr   r   )r   r  r_   Zset_config_providerr   )	r;   r   r   Zconfig_chain_builderr   r   r   r   ry   r=   r=   r>   r    s    
z5SessionVarDict._update_config_store_from_session_varsN)
r  r  r  r?   r  r  r  r  r  r  r=   r=   r=   r>   r7   m  s   r7   c                   @   s$   e Zd ZdZdddZdddZdS )	r   a`  A class for creating backwards compatible configuration chains.

    This class can be used instead of
    :class:`botocore.configprovider.ConfigChainFactory` to make it honor the
    methods argument to get_config_variable. This class can be used to filter
    out providers that are not in the methods tuple when creating a new config
    chain.
    Nc                 C   s   t ||| _|| _d S r@   )r   _factory_supported_methods)r;   rj   r   r   r=   r=   r>   r?     s    z!SubsetChainConfigFactory.__init__c                 C   s@   d| j krd}d| j krd}d| j kr*d}| jj|||||dS )a  Build a config chain following the standard botocore pattern.

        This config chain factory will omit any providers not in the methods
        tuple provided at initialization. For example if given the tuple
        ('instance', 'config',) it will not inject the environment provider
        into the standard config chain. This lets the botocore session support
        the custom ``methods`` argument for all the default botocore config
        variables when calling ``get_config_variable``.
        r   Nr   r   r  )r!  r   r   )r;   r   r   r   r   r   r=   r=   r>   r     s    


z,SubsetChainConfigFactory.create_config_chain)N)NNNNN)r  r  r  r  r?   r   r=   r=   r=   r>   r     s   	
     r   c                 C   s   t | S )z&
    Return a new session object.
    )r#   )r   r=   r=   r>   get_session  s    r"  )N)?r  r   r   r   r   r~   r   Zbotocore.clientrR   Zbotocore.configloaderZbotocore.credentialsZbotocore.tokensr   r   r   r   r   r   r   r	   r
   Zbotocore.compatr   r   Zbotocore.configproviderr   r   r   r   r   r   Zbotocore.errorfactoryr   Zbotocore.exceptionsr   r   r   r   r   Zbotocore.hooksr   r   r   Zbotocore.loadersr   Zbotocore.modelr   Zbotocore.parsersr   Zbotocore.regionsr   Zbotocore.utilsr    r!   r"   r   r  r   r#   r3   r7   r   r"  r=   r=   r=   r>   <module>   sF   , 
        #..