o .&a!@sdZddlZddlZddlmZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZ dddZdddZddZdS)zC Utility functions to make it easier to work with customizations. N) ClientErrorcC ||}|||<||_||=dSNname)argument_table existing_namenew_namecurrentr =/usr/lib/python3/dist-packages/awscli/customizations/utils.pyrename_argument r cCs$||}t|}||_|||<|Sr)copyr)r current_name copy_namer copy_argr r r _copy_arguments  rcCs:||}t|||}d|_|jrd|_d|_d|_dSdS)a{Create a hidden alias for an existing argument. This will copy an existing argument object in an arg table, and add a new entry to the arg table with a different name. The new argument will also be undocumented. This is needed if you want to check an existing argument, but you still need the other one to work for backwards compatibility reasons. TFN)r _UNDOCUMENTEDrequired_DOCUMENT_AS_REQUIRED)rr alias_namer rr r r make_hidden_alias&s  rcCrrr command_tablerr r r r r rename_command?rrcCs||}t|||d|_dS)aWMoves an argument to a new name, keeping the old as a hidden alias. :type command_table: dict :param command_table: The full command table for the CLI or a service. :type existing_name: str :param existing_name: The current name of the command. :type new_name: str :param new_name: The new name for the command. TNrrrr r r alias_commandFs  rcCst|||}d|_dS)aCreate a hidden alias for an exiting command. This will copy an existing command object in a command table and add a new entry to the command table with a different name. The new command will be undocumented. This is needed if you want to change an existing command, but you still need the old name to work for backwards compatibility reasons. :type command_table: dict :param command_table: The full command table for the CLI or a service. :type existing_name: str :param existing_name: The current name of the command. :type alias_name: str :param alias_name: The new name for the command. TNr)rrrnewr r r make_hidden_command_aliasWs  rcsfdd}|S)Ncst|gRSr)validate_mutually_exclusive) parsed_argskwargsgroupsr r _handlerosz5validate_mutually_exclusive_handler.._handlerr )r$r%r r#r #validate_mutually_exclusive_handlerns r&cst|tdd|DtfddDsdSd}fddDD]"}t||}|dur2q&|dur9|}q&||ksHtd|d|fq&dS) z7Validate mututally exclusive groups in the parsed args.css|] }|D]}|VqqdSrr ).0groupargr r r wsz.validate_mutually_exclusive..c3s$|] }|dur|vVqdSrr r'kall_args args_dictr r r*xs"Ncsg|] }|dur|qSrr r+)r/r r }sz/validate_mutually_exclusive..zVThe key "%s" cannot be specified when one of the following keys are also specified: %sz, )varssetany_get_group_for_key ValueErrorjoin)r!r$ current_groupkey key_groupr r-r r ts"  r cCs|D] }||vr |SqdSrr )r8r$r(r r r r4s r4c Csjd}z |j|dW|Sty4}zt|jdd}|dkr)d}WYd}~|SWYd}~|Sd}~ww)NT)BucketErrorCodeiF) head_bucketrintresponse) s3_client bucket_name bucket_existse error_coder r r s3_bucket_existss rEcCsZi}d|vr |j|d<d|vr|j|d<d|vr|j|d<|r$|||j|fi|S)aCreates a service client, taking parsed_globals into account Any values specified in overrides will override the returned dict. Note that this override occurs after 'region' from parsed_globals has been translated into 'region_name' in the resulting dict. region region_name endpoint_url verify_sslverify)rFrHrIupdate create_client)session service_nameparsed_globals overrides client_argsr r r !create_client_from_parsed_globalss    rRcCsp|durtj}z||Wn#ty1t|dd}|dur!d}||d|}||Ynw|dS)z This function is used to properly write unicode to a file, usually stdout or stdderr. It ensures that the proper encoding is used if the statement is not a string type. Nencodingasciireplace)sysstdoutwriteUnicodeEncodeErrorgetattrencodedecodeflush) statementout_file new_encoding new_statementr r r uni_prints    rbcCs(|}|dr dS|drdSdS)z7Method to return region value as expected by policy arnzcn-zaws-cnzus-govz aws-us-govaws)lower startswith)rF region_stringr r r get_policy_arn_suffixs   rgr)__doc__rrVbotocore.exceptionsrr rrrrrr&r r4rErRrbrgr r r r s$    +