ee[c@sdZddlZddlZddlZddlZddlZddlmZddlZddl Zddl Zddl m Z m Z ddl mZmZddlmZddlmZddlmZmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlm Z m!Z!ej"e#Z$de%fdYZ&de%fdYZ'e(dZ)dS(sV This module contains the main interface to the botocore package, the Session object. iN(t __version__(tConfigNotFoundtProfileNotFound(tUnknownServiceErrortPartialCredentialsError(tClientExceptionsFactory(thandlers(tHierarchicalEmittertfirst_non_none_response(t create_loader(tResponseParserFactory(tEndpointResolver(t ServiceModel(tpaginate(twaiter(t retryhandlert translatetSessionc BseZdZi dLddgdLdLfd6dMd6dNd6dOd 6dPd 6d dLidLfd 6dQd6dddefd6dddefd6ddLedLfd6ZdZdLdLedLdZdZ dZ dZ dZ dZ dZdZd Zed!Zd"Zed#ZdRd'Zd(Zd)Zd*Zd+Zd,Zd-Zed.Zd/Zd0ZdLd1Zd2Z d3Z!d4Z"dLd5Z#dLd6Z$dLd7Z%dLd8Z&d9Z'd:d;Z(dLdLd<Z)d:d=Z*dLe+d>Z,dLdLe+d?Z-d@Z.dAZ/dBZ0dCZ1dDZ2dEZ3dFZ4dLdLedLdLdLdLdLdLdG Z5dHZ6dIZ7dJe+dKZ8RS(Sse 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. tAWS_DEFAULT_PROFILEt AWS_PROFILEtprofiletregiontAWS_DEFAULT_REGIONt data_patht AWS_DATA_PATHtAWS_CONFIG_FILEs ~/.aws/configt config_filet ca_bundlet AWS_CA_BUNDLEt api_versionstAWS_SHARED_CREDENTIALS_FILEs~/.aws/credentialstcredentials_filetmetadata_service_timeouttAWS_METADATA_SERVICE_TIMEOUTitmetadata_service_num_attemptst!AWS_METADATA_SERVICE_NUM_ATTEMPTStparameter_validations4%(asctime)s - %(name)s - %(levelname)s - %(message)scCstj|j|_|r.|jj|n|dkrIt|_n ||_|rk|j|jnd|_t |_ d|_ d|_ d|_ d|_d|_i|_|dk r||jds(R8tlazy_register_component(R;((R;s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyR@s cs jjdfddS(Nt data_loadercstjdS(NR(R tget_config_variable((R;(s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRLs(R8RM(R;((R;s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRAs cs&fd}jjd|dS(Ncs(jd}|jd}t|S(NRNt endpoints(t get_componentt load_dataR (tloaderRP(R;(s4/tmp/pip-install-xdEqop/botocore/botocore/session.pytcreate_default_resolverstendpoint_resolver(R9RM(R;RT((R;s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRBs cCs|jjdtdS(Ntresponse_parser_factory(R8RGR (R;((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRDs cCs|jjdtdS(Ntexceptions_factory(R9RGR(R;((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyREs cCsxtjD]}t|dkrA|\}}|j||q |\}}}|tjkru|jj||q |tjkr |jj||q q WdS(Ni( RtBUILTIN_HANDLERStlentregistertREGISTER_FIRSTR,tregister_firstt REGISTER_LASTt register_last(R;teventstspect event_namethandlert register_type((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyR-s cCst|jjS(N(tlistt_build_profile_maptkeys(R;((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pytavailable_profilesscCs)|jdkr"|jd|_n|jS(Ntprofiles(R4R+t full_config(R;((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRescCs1|jdkr*|jd}||_n|jS(NR(R1R+RO(R;R((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRs tinstancetenvtconfigcCs)||jkrdSd}|j|}|j||r\|j|}tjd|||S|j||r|j|dtj }tjd||n<|j ||r|j |d}tjd||n|dkrtjd||d}n|d dk r%|d |}n|S( s Retrieve the value associated with the specified logical_name from the environment or the config file. Values found in the environment variable take precedence of values found in the config file. If no value can be found, a None will be returned. :type logical_name: str :param logical_name: The logical name of the session variable you want to retrieve. This name will be mapped to the appropriate environment variable name for this session as well as the appropriate config file entry. :type method: tuple :param method: Defines which methods will be used to find the variable value. By default, all available methods are tried but you can limit which methods are used by supplying a different value to this parameter. Valid choices are: instance|env|config :returns: value of variable or None if not defined. Ns5Loading variable %s from instance vars with value %r.is3Loading variable %s from environment with value %r.is3Loading variable %s from config file with value %r.s"Loading variable %s from defaults.ii( R)R+t_found_in_instance_varsR5tloggertdebugt _found_in_envt_retrieve_from_envtostenviront_found_in_config_filetget_scoped_config(R;t logical_nametmethodstvaluet var_config((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyROs:      cCsd|kr||jkStS(NRj(R5tFalse(R;RwRv((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRm's  cCs9d|ko8|ddk o8|j|dtjdk S(NRki(R+RqRrRs(R;RwRy((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRp,s cCs4d|kr0|ddk r0|d|jkStS(NRli(R+RuRz(R;RwRy((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRt2scCsDt|ts|g}nx"|D]}||kr"||Sq"WdS(N(t isinstanceRdR+(R;tnamesRstname((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRq7s     cCs$tjd||||j|>> # 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(RnRoR5(R;RvRx((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pytset_config_variableAs cCsa|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 RtdefaultN(ROReR+tgetR(R;t profile_namet profile_map((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRu`s   cCs|jdkry(|jd}tjj||_Wn!tk rZiid6|_nXy|jd}tjj|}xW|D]O}||}||jdkr||jd|/ 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( R.R/tplatformtpython_versiontsystemtreleaseRrRsRR+R0(R;tbase((s4/tmp/pip-install-xdEqop/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. RN(RQRR(R;R((s4/tmp/pip-install-xdEqop/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 (R;Rt api_versiontservice_description((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pytget_service_model scCs1|jd}|j|d|}tj|S(NRNs waiters-2(RQtload_service_modelRt WaiterModel(R;RRRSt waiter_config((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pytget_waiter_modelscCs1|jd}|j|d|}tj|S(NRNs paginators-1(RQRR tPaginatorModel(R;RRRStpaginator_config((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pytget_paginator_model"scCsT|}|jdj|ddd|}|jjd|d|d|d||S( sK Retrieve the fully merged data associated with a service. RNt type_names service-2Rsservice-data-loaded.%st service_dataRtsession(RQRR,temit(R;RRRR((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyR(s  cCs|jdjddS(s? Return a list of names of available services. RNRs service-2(RQtlist_available_services(R;((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pytget_available_services7sRIcCs|j|tjdS(sk Convenience function to quickly configure full debug output to go to the console. N(tset_stream_loggertloggingtDEBUG(R;t logger_name((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pytset_debug_logger>scCstj|}|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 StreamHandlerR+t LOG_FORMATt Formattert setFormattert addHandler(R;Rt log_leveltstreamt format_stringtlogtcht formatter((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyREs    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(R;RtpathRRRR((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pytset_file_loggerms   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(R,RZ(R;RaRbt unique_idR((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRZs"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``. RbRRN(R,t unregister(R;RaRbRR((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRscKs|jj||S(N(R,R(R;Ratkwargs((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRscKs|jj||}t|S(N(R,RR(R;RaRt responses((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pytemit_first_non_none_responsescCs_y|jj|SWnDtk rZ|dkrTtjd|t|jj|SnXdS(NRURWsFetching 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(R8RQt ValueErrortwarningstwarntDeprecationWarningR9(R;R}((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRQs  cCs|jj|S(N(R9RQ(R;R}((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyt_get_internal_componentscCs|jj||S(N(R9RG(R;R}t component((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyt_register_internal_componentscCs|jj||dS(N(R8RG(R;R}R((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRGscCs|jj||dS(N(R8RM(R;R}R((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRMsc 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 RRRRNRFRVRRRtprovidertexplicittcred_varRURWRt region_namet is_securet endpoint_urltverifyRJt scoped_configRRN(RR+tmergeRRORRQRIRJRt_missing_cred_varsRRRtclientt ClientCreatorRRRt create_clientRu(R;RRRtuse_sslRRtaws_access_key_idtaws_secret_access_keytaws_session_tokenRltdefault_client_configRSRFRVRJRURWtclient_creatorR((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRsTI                   cCs<|dk r|dkrdS|dk r8|dkr8dSdS(NRR(R+(R;RR((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRxs cCs|jd}|jS(sLists the available partitions found on disk :rtype: list :return: Returns a list of partition names (e.g., ["aws", "aws-cn"]) RU(Rtget_available_partitions(R;tresolver((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRstawscCsk|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"]). RUtmetadatatendpointPrefix(RRRtget_available_endpointsR(R;Rtpartition_nametallow_non_regionalRtresultsRtendpoint_prefix((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pytget_available_regionss   N(sregionRNN(s data_pathRNN(NRs ~/.aws/configN(s ca_bundleRNN(NRs~/.aws/credentialsN(sinstancesenvsconfig(9t__name__t __module__t__doc__R+tinttTrueR(RR?R:RCR@RARBRDRER-tpropertyRgReRRORmRpRtRqR~RuRiRRRRRRRRRRRRRRRzRZRRRRQRRRGRMRRRR(((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyR.s 6          ;     %#   #       '  $ !         R7cBs2eZdZdZdZdZdZRS(s'Service locator for session components.cCsi|_i|_dS(N(R8t _deferred(R;((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyR?s cCsp||jkr9|j|}||j|<|j|=ny|j|SWn!tk rktd|nXdS(NsUnknown component: %s(RR8tKeyErrorR(R;R}tfactory((s4/tmp/pip-install-xdEqop/botocore/botocore/session.pyRQs   cCs3||j|s8        ~"