݁[c@s4dZddlZddlZddlZddlZddlZddlZddlmZddl Zddl Zddl Zddl m Z ddl mZddl mZddl mZddlmZmZdd lmZmZdd lmZdd lmZdd lmZmZdd lmZddlmZddlm Z ddl!m"Z"ddl#m$Z$ddlm%Z%ddlm&Z&ddlm'Z'm(Z(ddl)m*Z*ej+e,Z-de.fdYZ/de.fdYZ0dej1fdYZ2de.fdYZ3e4dZ5dS(sV This module contains the main interface to the botocore package, the Session object. iN(t __version__(tConfigValueStore(tConfigChainFactory(t&create_botocore_default_config_mapping(t!BOTOCORE_DEFAUT_SESSION_VARIABLES(tConfigNotFoundtProfileNotFound(tUnknownServiceErrortPartialCredentialsError(tClientExceptionsFactory(thandlers(tHierarchicalEmittertfirst_non_none_response(t EventAliaser(t create_loader(tResponseParserFactory(tEndpointResolver(t ServiceModel(tpaginate(twaiter(t retryhandlert translate(t EVENT_ALIASEStSessionc Bs-eZdZejeZdZd2d2ed2dZ dZ dZ dZ dZ dZdZd Zd Zd Zed Zd ZedZd2dZdZdZdZdZedZdZdZd2dZdZ dZ!dZ"d2dZ#d2dZ$d2dZ%d2dZ&dZ'd d!Z(d2d2d"Z)d d#Z*d2e+d$Z,d2d2e+d%Z-d&Z.d'Z/d(Z0d)Z1d*Z2d+Z3d,Z4d2d2ed2d2d2d2d2d2d- Z5d.Z6d/Z7d0e+d1Z8RS(3se 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. s4%(asctime)s - %(name)s - %(levelname)s - %(message)scCs|dkrt|_n ||_t|j|_|rO|j|jnd|_t|_d|_ d|_ d|_ d|_ d|_ i|_|dk r||jds(R)tlazy_register_component(R0((R0sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyR5s cs jjdfddS(Nt data_loadercstjdS(Nt data_path(Rtget_config_variable((R0(sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRBs(R)RC(R0((R0sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyR6s cs&fd}jjd|dS(Ncs(jd}|jd}t|S(NRDt endpoints(t get_componentt load_dataR(tloaderRG(R0(sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytcreate_default_resolverstendpoint_resolver(R*RC(R0RK((R0sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyR7s cCs|jjdtdS(Ntresponse_parser_factory(R)R=R(R0((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyR9s cCs|jjdtdS(Ntexceptions_factory(R*R=R (R0((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyR:s cCsxtjD]}t|dkrA|\}}|j||q |\}}}|tjkru|jj||q |tjkr |jj||q q WdS(Ni( R tBUILTIN_HANDLERStlentregistertREGISTER_FIRSTRtregister_firstt REGISTER_LASTt register_last(R0teventstspect event_namethandlert register_type((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRs cCs;td|}tdt|}|jjd|dS(Ntsessiontmappingt config_store(RRRR)R=(R0t chain_buildertconfig_store_component((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyR;s  cCst|jjS(N(tlistt_build_profile_maptkeys(R0((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytavailable_profilesscCs)|jdkr"|jd|_n|jS(Ntprofiles(R%Rt full_config(R0((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRascCs1|jdkr*|jd}||_n|jS(NR(R"RRF(R0R((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRs cCs2|dk r|j||S|jdj|S(NR](Rt(_get_config_variable_with_custom_methodsRHRF(R0t logical_nametmethods((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRFs   cCstd|d|}t|}x|jjD]\}}|\}}} } i| d6| d6} d|kr||| d>> # 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. s$Setting config variable for %s to %rN(tloggertdebugR&(R0RgRz((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytset_config_variables cCstj|jS(N(tcopyR&(R0((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytinstance_variablesscCsa|jd}|j}|dkr7|jdiS||krUtd|n||SdS(s5 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 RRjN(RFRaRtgetR(R0t profile_namet profile_map((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytget_scoped_configs   cCs|jdkry(|jd}tjj||_Wn!tk rZiid6|_nXy|jd}tjj|}xW|D]O}||}||jdkr||jd|N(R$RR)RHtload_credentials(R0((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytget_credentialss  cCsd|j|jtjtjtjf}tjjddk rf|dtjjd7}n|j r|d|j 7}n|S(sg Return a string suitable for use as a User-Agent header. The string will be of the form: / Python/ / Where: - agent_name is the value of the `user_agent_name` attribute of the session object (`Boto` 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. s%s/%s Python/%s %s/%stAWS_EXECUTION_ENVs exec-env/%ss %sN( RR tplatformtpython_versiontsystemtreleasetostenvironRRR!(R0tbase((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyt user_agents    cCs|jdj|S(s Retrieve the data associated with `data_path`. :type data_path: str :param data_path: The path to the data you wish to retrieve. RD(RHRI(R0RE((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytget_datascCs"|j||}t|d|S(sGet 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. t service_name(tget_service_dataR(R0Rt api_versiontservice_description((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytget_service_modelscCs1|jd}|j|d|}tj|S(NRDs waiters-2(RHtload_service_modelRt WaiterModel(R0RRRJt waiter_config((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytget_waiter_modelscCs1|jd}|j|d|}tj|S(NRDs paginators-1(RHRRtPaginatorModel(R0RRRJtpaginator_config((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytget_paginator_modelscCsf|}|jdj|ddd|}tj||}|jjd|d|d|d||S( sK Retrieve the fully merged data associated with a service. RDt type_names service-2Rsservice-data-loaded.%st service_dataRR[(RHRRRRtemit(R0RRRERt service_id((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRs  cCs|jdjddS(s? Return a list of names of available services. RDRs service-2(RHtlist_available_services(R0((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytget_available_servicessR?cCs|j|tjdS(sk Convenience function to quickly configure full debug output to go to the console. N(tset_stream_loggertloggingtDEBUG(R0t logger_name((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytset_debug_loggerscCstj|}|jtjtj|}|j||dkrS|j}ntj|}|j||j |dS(s 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( Rt getLoggertsetLevelRt StreamHandlerRt LOG_FORMATt Formattert setFormattert addHandler(R0Rt log_leveltstreamt format_stringtlogtcht formatter((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRs    cCsktj|}|jtjtj|}|j|tj|j}|j||j|dS(sV 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( RRRRt FileHandlerRRRR(R0RtpathRRRR((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytset_file_logger!s   cCs |jj|||d|dS(s)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``. tunique_id_uses_countN(RRQ(R0RXRYt unique_idR((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRQ=s"cCs&|jj|d|d|d|dS(sUnregister 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``. RYRRN(Rt unregister(R0RXRYRR((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRbscKs|jj||S(N(RR(R0RXtkwargs((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRscKs|jj||}t|S(N(RRR (R0RXRt responses((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytemit_first_non_none_responsescCs_y|jj|SWnDtk rZ|dkrTtjd|t|jj|SnXdS(NRLRNsFetching the %s component with the get_component() method is deprecated as the component has always been considered an internal interface of botocore(sendpoint_resolversexceptions_factory(R)RHt ValueErrortwarningstwarntDeprecationWarningR*(R0Rt((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRHs  cCs|jj|S(N(R*RH(R0Rt((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyt_get_internal_componentscCs|jj||S(N(R*R=(R0Rtt component((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyt_register_internal_componentscCs|jj||dS(N(R)R=(R0RtR((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyR=scCs|jj||dS(N(R)RC(R0RtR((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRCsc Cs|j} | dk r6| dk r6| j| } n| dk rK| } n|dkr| rx| jdk rx| j}q|jd}n|dkr|jd}n|dkr|jdj|d}n|jd} |jd} |jd}|dk r;|dk r;tjj d|d|d | }nB|j ||rqt d d d |j ||n |j }|j d }|j d}tjj| ||j| tt||}|jd|d|d|d|d|d|d|jd| d| }|S(sQ 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 ``Sesssion.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 tregiont ca_bundlet api_versionsRDR<RMRRRtprovidertexplicittcred_varRLRNRt region_namet is_securet endpoint_urltverifyR@t scoped_configRRN(RRtmergeRRFRRHR?R@Rt_missing_cred_varsRRRtclientt ClientCreatorRRRt create_clientR(R0RRRtuse_sslRRtaws_access_key_idtaws_secret_access_keytaws_session_tokenRotdefault_client_configRJR<RMR@RLRNtclient_creatorR((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRsTI                   cCs<|dk r|dkrdS|dk r8|dkr8dSdS(NRR(R(R0RR((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyR,s cCs|jd}|jS(sLists the available partitions found on disk :rtype: list :return: Returns a list of partition names (e.g., ["aws", "aws-cn"]) RL(Rtget_available_partitions(R0tresolver((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyR3stawscCsk|jd}g}y>|j|}|djd|}|j|||}Wntk rfnX|S(s]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"]). RLtmetadatatendpointPrefix(RRRtget_available_endpointsR(R0Rtpartition_nametallow_non_regionalRtresultsRtendpoint_prefix((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pytget_available_regions<s   N(9t__name__t __module__t__doc__R~RR-RRtTrueR4R+R8R5R6R7R9R:RR;tpropertyRcRaRRFRfR}RRReRRRRRRRRRRRRRRtFalseRQRRRRHRRR=RCRRRR(((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyR5sr 7            %#   #       '  $ !         R(cBs2eZdZdZdZdZdZRS(s'Service locator for session components.cCsi|_i|_dS(N(R)t _deferred(R0((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyR4_s cCsp||jkr9|j|}||j|<|j|=ny|j|SWn!tk rktd|nXdS(NsUnknown component: %s(RR)tKeyErrorR(R0Rttfactory((sh/private/var/folders/71/gccz42bs2nl23mxwq3vp1qmhw5xjlw/T/pip-install-k836tR/botocore/botocore/session.pyRHcs   cCs3||j|sJ         +"-(