o ckF[H@sddlZddlZddlZddlZddlZddlZddlZddlZddlZzddl Z Wn e y7ddl Z YnwddZ GdddeZGdddejjZGdd d ejjZGd d d ejjZGd d d eZGdddeZdS)Ncsfdd}|S)Ncs|tjur tdtjt_r/tjr/tjr/t j dkr(t |||dSt |dSr?t t |tddSt |tddS)Nepdb)bdbBdbQuitsysexit__excepthook__ excepthookstdoutisattystdindebugger__name__ post_mortemprint tracebackprint_tb)typvaluetb debug_flag debugger_flag=/usr/lib/python3/dist-packages/boto/roboto/awsqueryrequest.pyr &s   z$boto_except_hook..excepthookr)rrr rrrboto_except_hook%src@s$eZdZddZddZddZdS)LinecCs&||_||_||_d||_d|_dS)N%s F)fmtdatalabellineprinted)selfrrr rrr__init__;s   z Line.__init__cCs|jd|7_dS)Nr)r!)r#datumrrrappendBsz Line.appendcCs|js t|jd|_dSdS)NT)r"rr!r#rrrprint_itEs  z Line.print_itN)r __module__ __qualname__r$r&r(rrrrr9s rceZdZfddZZS)RequiredParamErrorc$||_d|j}tt||dS)Nz#Required parameters are missing: %s)requiredsuperr,r$)r#r.s __class__rrr$L zRequiredParamError.__init__rr)r*r$ __classcell__rrr1rr,Jr,cr+) EncoderErrorcsd|}tt||dS)NzError encoding value (%s))r/r7r$)r# error_msgr0r1rrr$SszEncoderError.__init__r4rrr1rr7Qr6r7cr+) FilterErrorcr-)NUnknown filters: %s)filtersr/r9r$)r#r;r0r1rrr$Yr3zFilterError.__init__r4rrr1rr9Wr6r9c@s^eZdZedddZeddZeZeZeddZedd Z ed d Z ed d Z dS)EncoderNcCsR|jdrdSzt|d|j}|||||WdSty(td|jw)N_encode_zUnknown type: %s)name startswithgetattrptypeAttributeErrorr7)clsprpvr mthdrrrencode`s  zEncoder.encodecC|r|}n|j}|||<dSNr?rDrErFrGlr rrr encode_stringj zEncoder.encode_stringcCs |r|}n|j}d|||<dS)Nz%drLrMrrrencode_integeruszEncoder.encode_integercCs*|r|}n|j}|r d}nd}|||<dS)NtruefalserLrMrrrencode_boolean}s zEncoder.encode_booleancCrJrKrLrMrrrencode_datetimerPzEncoder.encode_datetimecCsJtj|}|r |}n|j}|d}t|D] \}}||||d<qdS)Nz.%dr)botoutilsmklistr? enumerate)rDrErFrGrNr irrrr encode_arrays zEncoder.encode_arrayrK) rr)r* classmethodrIrO encode_file encode_enumrQrTrUr[rrrrr<^s     r<c @seZdZdZdZgZgZgZiZdddddddddZ e ddZ d d Z d d Z d dZeddZeddZeddZddZddZd,ddZd-ddZddZd d!Zd"d#Zd$d%Zd&d'Zd.d(d)Zd*d+ZdS)/AWSQueryRequestNstringintchoice)raintegerrbenumdatetimedateTimefilebooleancCs|jSrK)r)rDrrrr?szAWSQueryRequest.namecKs@||_d|_d|_d|_d|_d|_g|_g|_i|_d|_ dSrK) argsparser cli_optionscli_argscli_output_format connection list_markers item_markersrequest_paramsconnection_argsr#rjrrrr$s zAWSQueryRequest.__init__cCs|SrKrLr'rrr__repr__szAWSQueryRequest.__repr__cKs"|jdur|jdi||_|jS)Nr)ro ServiceClassrtrrrget_connections zAWSQueryRequest.get_connectioncCd}|jdur |jj}|SrK) http_responsestatusr#retvalrrrrz zAWSQueryRequest.statuscCrxrK)ryreasonr{rrrr~r}zAWSQueryRequest.reasoncCsd}|jdur t|jd}|S)N requestId) aws_responserAr{rrr request_ids  zAWSQueryRequest.request_idc s|jdg}dd|jDfdd|D}|r td|t|jD]5\}}|d}||vrZ||jd|d<ttj||D]\}}t ||j|d |d|dfqDq%dS) Nr;cSsg|]}|dqSrLr.0frrr sz3AWSQueryRequest.process_filters..csg|]}|vr|qSrrr filter_namesrrrr:r?zFilter.%d.NamerzFilter.%d.Value.%d) rjgetFiltersr9rYrrrVrWrXr<rI)r#r;unknown_filtersrZfilterr?jrrrrprocess_filterss  zAWSQueryRequest.process_filterscKs|j|t|j|_d|jvr |jddkr t|dd|j|jD}|j|jD]W}|j r>|j dd}ntj |jd}d}||jvrR|j|}|durY|j }|dur|j|vrh||j|jr|jrw|||j|nt||j|||jvr|j|=q1|rg}|j|jD]-}|j|vr|jr|j r|d|j|jfq|jr|d |jq|d |jqtd |tjd |j||jdS) a Responsible for walking through Params defined for the request and: * Matching them with keyword parameters passed to the request constructor or via the command line. * Checking to see if all required parameters have been specified and raising an exception, if not. * Encoding each value into the set of request parameters that will be sent in the request to the AWS service. debugcSsg|]}|js|jqSr)optionalr?)rrErrrrrz0AWSQueryRequest.process_args..-r=Nz(%s, %s)z(%s),zrequest_params: %s)rjupdatecopyrsrVset_stream_loggerr?ParamsArgs long_namereplacerWpythonize_namedefaultremove request_paramencoderrrr<rI short_namer&optparse_short_nameoptparse_long_namer,joinlogrprocess_markersResponse)r#rjr.param python_namerrNrErrr process_argssN          zAWSQueryRequest.process_argscCsj|r|ddkr|dD] }|||dq dS|r1|ddkr3|j||j|ddSdSdS)Ntypeobject propertiesr?array)rrpr&rq)r#r prev_nameproprrrrs  zAWSQueryRequest.process_markersGETcKs|jdi|||jdi|j}|j||j|d|_|j|_ t j |j |jj dkrPt jj|j|jd|_t j|j|}||j |jSt j d|jj |jjft j d|j ||jj |jj|j )N)verb) list_marker item_markerz%s %sz%sr)rrrwrs make_requestr?rrryreadbodyrVrrrz jsonresponseElementrprqr XmlHandlerparseerrorr~ ResponseError)r#rrjconnhrrrsend%s0      zAWSQueryRequest.sendcCst|jd}|jddddd|jdddd d |jd d d dd|jdd dd|jddd dd|jddd dd|jdddd|jrZ|jjdddd|jjddddd|j|dS) NzStandard Optionsz-Dz--debug store_truezTurn on all debugging output)actionhelpz --debuggerFz$Enable interactive debugger on error)rrrz-Uz--urlstorez(Override service URL with value providedz--regionz Name of the region to connect toz-Iz--access-key-idzOverride access key valuez-Sz --secret-keyzOverride secret key valuez --versionzDisplay version stringz--help-filtersz!Display list of available filtersz--filterr&z name=valuez!A filter for limiting the results)rmetavarr)optparse OptionGrouprk add_optionrgroupadd_option_group)r#rrrradd_standard_options<s@      z$AWSQueryRequest.add_standard_optionscCst|dr!|jr!td|jD] }td|j|jfqtd|jr)d|j d<|j r2|j |j d<|j r;|j |j d<|j rD|j |j d <|j rM|j |j d <|jrXtd tdt|j|jt_dS) N help_filterszAvailable filters:z%s %srrrurlregionaws_access_key_idaws_secret_access_keyz version x.xx)hasattrrrrr?docrrrrjrr access_key_id secret_keyversionrr r )r#optionsrjdrrrrprocess_standard_optionsVs*        z(AWSQueryRequest.process_standard_optionscCsLd}dd|jD}|d|7}|jD]}|jr#|d|j|jf7}q|S)Nzusage: %prog [options] cSsg|]}|jqSr)r)rarrrrosz-AWSQueryRequest.get_usage.. z %s - %s)rrrr)r#r0rNrrrr get_usagems zAWSQueryRequest.get_usagec Cstj|j|d|_||jD]f}d}}}|j|jvr(|j|j}d}|jdkr0d}n|jdkrFt |j dkrE|j dd}d }n|j dkrMd }|sS|dkrx|j rg|jj |j|j|||j|jd q|jrx|jj |j|||j|jd qdS) N) descriptionusagerrirrrrrr&)rrchoicesr)r OptionParser DescriptionrrkrrrB CLITypeMaplenitems cardinalityrrrrrrr)r#rrBrrrrrbuild_cli_parservsD          z AWSQueryRequest.build_cli_parserc Cs|js||j\|_|_i}||j|j||jD]V}|jr+|jdd}nt j |j }t |j|}|jdkrp|rp|dkrItj}n'tj|}tj|}tj|rht|}|}|n|jd||||<q|jD]/}|jr|jdd}nt j |j }d}|jdkrt|jdkr|jd}n|j}|||<qx|j|t|jdr|jj ri}|jj D] }|!d\} }||| <qd |jvr|jd |n||jd <z |"} |#| WdSt$y} zt%| t&dWYd} ~ dSd} ~ w|j'j(y,} zt%d | j)| j*ft&dWYd} ~ dSd} ~ wt j+j,j-yK} zt%d t&dWYd} ~ dSd} ~ wt.yg} zt%| t&dWYd} ~ dSd} ~ ww) Nrr=rhzUnable to read file: %srrr=r;z Error(%s): %szUnable to find credentials.)/rkr parse_argsrlrmrrrrrVrWrr?rArBrr rospath expanduser expandvarsisfileopencloserrrrrjrrrsplitmain cli_formatterr,rrrvr error_code error_messagerobotoawsqueryserviceNoCredentialsError Exception) r#rrp_namerrfpargrr?responseeerrrrrdo_clisz                 zAWSQueryRequest.do_clicCs|ddkrA|dD]4}d|vr7|d|vr||d}|d|jvr7|d}|ddkr3|dd}|}||||q dS|ddkrr|D]*}t|||}t|trc|D] }|||qXn t|trm|||qIdSdS) Nrrrr?r0rr) rpupper_generic_cli_formatterr isinstancedictr& basestringr()r#rrr ritemr! field_namerrrrs0            z&AWSQueryRequest._generic_cli_formattercCs|r ||j|dSdS)a This method is responsible for formatting the output for the command line interface. The default behavior is to call the generic CLI formatter which attempts to print something reasonable. If you want specific formatting, you should override this method and do your own thing. :type data: dict :param data: The data returned by AWS. N)rr)r#rrrrrs zAWSQueryRequest.cli_formatterrK)r)r`)rr)r*rvrrrrrrr\r?r$rurwpropertyrzr~rrrrrrrrrrrrrrrrr_sL      3   ? r_)rrrVrrboto.exceptionboto.roboto.awsqueryservicerrrr ImportErrorpdbrrr exceptionBotoClientErrorr,r7r9r<r_rrrrs*   >