t_c@sydZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z ddl Zddl Zddl ZddlmZddlmZddlmZddlmZdd lmZmZmZmZdd lmZdd lmZdd lmZmZdd lmZddlm 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.m/Z/ddl0m1Z1ej2e3Z4de5fdYZ6de5fdYZ7de1fdYZ8de5fd YZ9e:d!Z;dS("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(tConfigNotFoundtProfileNotFoundtUnknownServiceErrortPartialCredentialsError(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_ALIASEStvalidate_region_name(tMutableMappingtSessionc BsQeZdZejeZdZd6d6ed6dZ dZ dZ dZ dZ dZdZd Zd Zd Zd Zd ZdZedZdZedZd6dZdZdZdZdZedZdZ dZ!d6dZ"dZ#dZ$dZ%d6dZ&d6dZ'd6d Z(d6d!Z)d"Z*d#d$Z+d6d6d%Z,d#d&Z-d6e.d'Z/d6d6e.d(Z0d)Z1d*Z2d+Z3d,Z4d-Z5d.Z6d/Z7d6d6ed6d6d6d6d6d6d0 Z8d1Z9d2Z:d3Z;d4e.d5Z<RS(7se 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||jdscCs|jjd|jdS(Ntcredential_provider(R/tlazy_register_componentt_create_credential_resolver(R6((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyR;s cCstjj|d|jS(Nt region_name(tbotocoret credentialstcreate_credential_resolverR-(R6((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRGs cs jjdfddS(Nt data_loadercstjdS(Nt data_path(Rtget_config_variable((R6(s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytR(R/RF(R6((R6s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyR<s cs&fd}jjd|dS(Ncs(jd}|jd}t|S(NRLt endpoints(t get_componentt load_dataR(tloaderRP(R6(s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytcreate_default_resolverstendpoint_resolver(R0RF(R6RT((R6s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyR=s cCs|jjdtdS(Ntresponse_parser_factory(R/RDR(R6((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyR?s cCs|jjdtdS(Ntexceptions_factory(R0RDR (R6((s;/opt/awscli/lib/python2.7/site-packages/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(R6teventstspect event_namethandlert register_type((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyR#s cCs,tdt|}|jjd|dS(Ntmappingt config_store(RRR/RD(R6tconfig_store_component((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRAs cCs|jjd|jdS(Ntmonitor(R0RFt_create_csm_monitor(R6((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRBs cCs|jdr|jd}|jd}|jd}tjdtjdtjdtjtjtjd|d |d tjd|}|SdS( Nt csm_enabledt csm_client_idtcsm_hosttcsm_porttadaptert publishertsocketthosttportt serializer( RNRtMonitortMonitorEventAdaptertSocketPublisherRotAF_INETt SOCK_DGRAMt CSMSerializerR (R6t client_idRpRqRb((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRhs    cCst|jjS(N(tlistt_build_profile_maptkeys(R6((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytavailable_profilesscCs)|jdkr"|jd|_n|jS(Ntprofiles(R*R t full_config(R6((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyR{scCs1|jdkr*|jd}||_n|jS(NR(R'R RN(R6R((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRs cCs2|dk r|j||S|jdj|S(NRe(R t(_get_config_variable_with_custom_methodsRQRN(R6t logical_nametmethods((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRNs   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+(R6RR((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytset_config_variables cCstj|jS(N(tcopyR+(R6((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytinstance_variables0scCsa|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(RNR{R tgetR(R6t profile_namet profile_map((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytget_scoped_config3s   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 (`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. s%s/%s Python/%s %s/%stAWS_EXECUTION_ENVs exec-env/%ss %sN( R$R%tplatformtpython_versiontsystemtreleasetostenvironRR R&(R6tbase((s;/opt/awscli/lib/python2.7/site-packages/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. RL(RQRR(R6RM((s;/opt/awscli/lib/python2.7/site-packages/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(R6Rt api_versiontservice_description((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytget_service_modelscCs1|jd}|j|d|}tj|S(NRLs waiters-2(RQtload_service_modelRt WaiterModel(R6RRRSt waiter_config((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytget_waiter_modelscCs1|jd}|j|d|}tj|S(NRLs paginators-1(RQRRtPaginatorModel(R6RRRStpaginator_config((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytget_paginator_modelscCsf|}|jdj|ddd|}tj||}|jjd|d|d|d||S( sK Retrieve the fully merged data associated with a service. RLt type_names service-2Rsservice-data-loaded.%st service_dataRR(RQRRRR"temit(R6RRRMRt service_id((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRs  cCs|jdjddS(s? Return a list of names of available services. RLRs service-2(RQtlist_available_services(R6((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytget_available_services sRIcCs|j|tjdS(sk Convenience function to quickly configure full debug output to go to the console. N(tset_stream_loggertloggingtDEBUG(R6t logger_name((s;/opt/awscli/lib/python2.7/site-packages/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 StreamHandlerR t LOG_FORMATt Formattert setFormattert addHandler(R6Rt log_leveltstreamt format_stringtlogtcht formatter((s;/opt/awscli/lib/python2.7/site-packages/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(R6RtpathRRRR((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytset_file_loggerAs   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(R6RaRbt unique_idR((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRZ]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``. RbRRN(R"t unregister(R6RaRbRR((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRscKs|jj||S(N(R"R(R6Ratkwargs((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRscKs|jj||}t|S(N(R"RR (R6RaRt responses((s;/opt/awscli/lib/python2.7/site-packages/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(RURW(R/RQt ValueErrortwarningstwarntDeprecationWarningR0(R6R((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRQs  cCs|jj|S(N(R0RQ(R6R((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyt_get_internal_componentscCs|jj||S(N(R0RD(R6Rt component((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyt_register_internal_componentscCs|jj||dS(N(R/RD(R6RR((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRDscCs|jj||dS(N(R/RF(R6RR((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRFsc CsN|j} | dk r6| dk r6| j| } n| dk rK| } n|j|| }|dkr{|jd}n|dkr|jdj|d}n|jd} |jd} |jd}| dk r| jtkrd}n~|dk r2|dk r2t j j d|d|d| }nB|j ||rht d d d |j ||n |j}|jd }|jd }|jd}t jj| ||j| tt||| }|jd|d|d|d|d|d|d|jd| d| }|jd}|dk rJ|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 t ca_bundlet api_versionsRLRCRVRRRtprovidertexplicittcred_varRURWReRRHt is_securet endpoint_urltverifyRJt scoped_configRRRgN(RR tmerget_resolve_region_nameRNRRQtsignature_versionRRIRJRt_missing_cred_varsR RRtclientt ClientCreatorRRRt create_clientRRZtmetaR_(R6RRHRtuse_sslRRtaws_access_key_idtaws_secret_access_keytaws_session_tokenRtdefault_client_configRSRCRVRJRURWRetclient_creatorRRg((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRsZI                   cCsV|dkr?|r-|jdk r-|j}q?|jd}nt|||_|S(Ntregion(R RHRNRR-(R6RHR((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRLs   cCs<|dk r|dkrdS|dk r8|dkr8dSdS(NRR(R (R6RR((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRbs 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(R6tresolver((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRistawscCsk|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(R6Rtpartition_nametallow_non_regionalR tresultsRtendpoint_prefix((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pytget_available_regionsrs   N(=t__name__t __module__t__doc__RRR3RR tTrueR:R1R>R;RGR<R=R?R@R#RARBRhtpropertyR}R{RRNRRRRRRRRRRRRRRRRRRRtFalseRZRRRRQRRRDRFRRRRR(((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyR<sz 8                %#   #       '  $ !          R.cBs2eZdZdZdZdZdZRS(s'Service locator for session components.cCsi|_i|_dS(N(R/t _deferred(R6((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyR:s cCsp||jkr9|j|}||j|<|j|=ny|j|SWn!tk rktd|nXdS(NsUnknown component: %s(RR/tKeyErrorR(R6Rtfactory((s;/opt/awscli/lib/python2.7/site-packages/botocore/session.pyRQs   cCs3||j|sR          "Z"-(