U!\c@spdZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z ddl Zddl Zddl ZddlmZddlmZddlmZddlmZdd lmZmZdd lmZmZdd lmZdd lmZdd lmZmZddlmZddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&ddlm'Z'ddlm(Z(ddlm)Z)ddlm*Z*m+Z+ddlm,Z,ddl-m.Z.ej/e0Z1de2fdYZ3de2fdYZ4dej5fdYZ6de2fd YZ7e8d!Z9dS("sV This module contains the main interface to the botocore package, the Session object. iN(t __version__(tUNSIGNED(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(t monitoring(tpaginate(twaiter(t retryhandlert translate(tutils(t EVENT_ALIASEStSessionc Bs?eZdZejeZdZd4d4ed4dZ dZ dZ dZ dZ dZdZd Zd Zd Zd Zd ZedZdZedZd4dZdZdZdZdZedZdZdZ d4dZ!dZ"dZ#dZ$d4dZ%d4dZ&d4dZ'd4d Z(d!Z)d"d#Z*d4d4d$Z+d"d%Z,d4e-d&Z.d4d4e-d'Z/d(Z0d)Z1d*Z2d+Z3d,Z4d-Z5d.Z6d4d4ed4d4d4d4d4d4d/ Z7d0Z8d1Z9d2e-d3Z:RS(5se 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(R3((R3s4/tmp/pip-install-usGedi/botocore/botocore/session.pyR8s cs jjdfddS(Nt data_loadercstjdS(Nt data_path(Rtget_config_variable((R3(s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRFs(R,RG(R3((R3s4/tmp/pip-install-usGedi/botocore/botocore/session.pyR9s cs&fd}jjd|dS(Ncs(jd}|jd}t|S(NRHt endpoints(t get_componentt load_dataR(tloaderRK(R3(s4/tmp/pip-install-usGedi/botocore/botocore/session.pytcreate_default_resolverstendpoint_resolver(R-RG(R3RO((R3s4/tmp/pip-install-usGedi/botocore/botocore/session.pyR:s cCs|jjdtdS(Ntresponse_parser_factory(R,RAR(R3((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyR<s cCs|jjdtdS(Ntexceptions_factory(R-RAR (R3((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyR=s cCsxtjD]}t|dkrA|\}}|j||q |\}}}|tjkru|jj||q |tjkr |jj||q q WdS(Ni( R tBUILTIN_HANDLERStlentregistertREGISTER_FIRSTR tregister_firstt REGISTER_LASTt register_last(R3teventstspect event_namethandlert register_type((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyR!s cCs;td|}tdt|}|jjd|dS(Ntsessiontmappingt config_store(RRRR,RA(R3t chain_buildertconfig_store_component((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyR>s  cCs|jjd|jdS(Ntmonitor(R-RGt_create_csm_monitor(R3((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyR?s cCs|jdr|jd}|jd}tjdtjdtjdtjtjtjddd |d tjd|}|SdS( Nt csm_enabledt csm_client_idtcsm_porttadaptert publishertsocketthosts 127.0.0.1tportt serializer( RJRtMonitortMonitorEventAdaptertSocketPublisherRktAF_INETt SOCK_DGRAMt CSMSerializerR(R3t client_idRmR]((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRes    cCst|jjS(N(tlistt_build_profile_maptkeys(R3((s4/tmp/pip-install-usGedi/botocore/botocore/session.pytavailable_profilesscCs)|jdkr"|jd|_n|jS(Ntprofiles(R(Rt full_config(R3((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRwscCs1|jdkr*|jd}||_n|jS(NR(R%RRJ(R3R((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRs cCs2|dk r|j||S|jdj|S(NRa(Rt(_get_config_variable_with_custom_methodsRLRJ(R3t logical_nametmethods((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRJs   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)(R3R}R((s4/tmp/pip-install-usGedi/botocore/botocore/session.pytset_config_variable s cCstj|jS(N(tcopyR)(R3((s4/tmp/pip-install-usGedi/botocore/botocore/session.pytinstance_variables*scCsa|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 RRN(RJRwRtgetR(R3t profile_namet profile_map((s4/tmp/pip-install-usGedi/botocore/botocore/session.pytget_scoped_config-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_versiontsystemtreleasetostenvironRRR$(R3tbase((s4/tmp/pip-install-usGedi/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. RH(RLRM(R3RI((s4/tmp/pip-install-usGedi/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(R3Rt api_versiontservice_description((s4/tmp/pip-install-usGedi/botocore/botocore/session.pytget_service_modelscCs1|jd}|j|d|}tj|S(NRHs waiters-2(RLtload_service_modelRt WaiterModel(R3RRRNt waiter_config((s4/tmp/pip-install-usGedi/botocore/botocore/session.pytget_waiter_modelscCs1|jd}|j|d|}tj|S(NRHs paginators-1(RLRRtPaginatorModel(R3RRRNtpaginator_config((s4/tmp/pip-install-usGedi/botocore/botocore/session.pytget_paginator_modelscCsf|}|jdj|ddd|}tj||}|jjd|d|d|d||S( sK Retrieve the fully merged data associated with a service. RHt type_names service-2Rsservice-data-loaded.%st service_dataRR_(RLRRRR temit(R3RRRIRt service_id((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRs  cCs|jdjddS(s? Return a list of names of available services. RHRs service-2(RLtlist_available_services(R3((s4/tmp/pip-install-usGedi/botocore/botocore/session.pytget_available_servicessRCcCs|j|tjdS(sk Convenience function to quickly configure full debug output to go to the console. N(tset_stream_loggertloggingtDEBUG(R3t logger_name((s4/tmp/pip-install-usGedi/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 StreamHandlerRt LOG_FORMATt Formattert setFormattert addHandler(R3Rt log_leveltstreamt format_stringtlogtcht formatter((s4/tmp/pip-install-usGedi/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(R3RtpathRRRR((s4/tmp/pip-install-usGedi/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(R RU(R3R\R]t unique_idR((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRUWs"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``. R]RRN(R t unregister(R3R\R]RR((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyR|scKs|jj||S(N(R R(R3R\tkwargs((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRscKs|jj||}t|S(N(R RR (R3R\Rt responses((s4/tmp/pip-install-usGedi/botocore/botocore/session.pytemit_first_non_none_responsescCs_y|jj|SWnDtk rZ|dkrTtjd|t|jj|SnXdS(NRPRRsFetching 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,RLt ValueErrortwarningstwarntDeprecationWarningR-(R3R((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRLs  cCs|jj|S(N(R-RL(R3R((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyt_get_internal_componentscCs|jj||S(N(R-RA(R3Rt component((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyt_register_internal_componentscCs|jj||dS(N(R,RA(R3RR((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRAscCs|jj||dS(N(R,RG(R3RR((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRGsc 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#| jtkr#d}n~|dk r_|dk r_t j j d|d|d | }nB|j ||rt d d d |j ||n |j}|jd }|jd}|jd}t jj| ||j| tt||| }|jd|d|d|d|d|d|d|jd| d| }|jd}|dk rw|j|jjn|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_versionsRHR@RQRRRtprovidertexplicittcred_varRPRRRaRt region_namet is_securet endpoint_urltverifyRDt scoped_configRRRdN(RRtmergeRRJRRLtsignature_versionRRCRDRt_missing_cred_varsR RRtclientt ClientCreatorRRRt create_clientRRUtmetaRZ(R3RRRtuse_sslRRtaws_access_key_idtaws_secret_access_keytaws_session_tokenRtdefault_client_configRNR@RQRDRPRRRatclient_creatorRRd((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRs`I                     cCs<|dk r|dkrdS|dk r8|dkr8dSdS(NRR(R(R3RR((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRLs cCs|jd}|jS(sLists the available partitions found on disk :rtype: list :return: Returns a list of partition names (e.g., ["aws", "aws-cn"]) RP(Rtget_available_partitions(R3tresolver((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRSstawscCsk|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"]). RPtmetadatatendpointPrefix(RRRtget_available_endpointsR(R3Rtpartition_nametallow_non_regionalRtresultsRtendpoint_prefix((s4/tmp/pip-install-usGedi/botocore/botocore/session.pytget_available_regions\s   N(;t__name__t __module__t__doc__RRR0RRtTrueR7R.R;R8R9R:R<R=R!R>R?RetpropertyRyRwRRJR|RRRR{RRRRRRRRRRRRRRtFalseRURRRRLRRRARGRRRR (((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyR9sv 7              %#   #       '  $ !         R+cBs2eZdZdZdZdZdZRS(s'Service locator for session components.cCsi|_i|_dS(N(R,t _deferred(R3((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyR7s cCsp||jkr9|j|}||j|<|j|=ny|j|SWn!tk rktd|nXdS(NsUnknown component: %s(RR,tKeyErrorR(R3Rtfactory((s4/tmp/pip-install-usGedi/botocore/botocore/session.pyRLs   cCs3||j|sR          G"-(