HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //proc/722141/root/lib/python3.6/site-packages/awscli/__pycache__/argprocess.cpython-36.pyc
3

�T_�Q�@s4dZddlZddlZddlmZddlmZmZddlm	Z	m
Z
ddlmZddlm
Z
ddlmZejd	�ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd-d#d$�Zd%d&�Z Gd'd(�d(e!�Z"Gd)d*�d*e"�Z#Gd+d,�d,e"�Z$dS).zModule for processing CLI args.�N)�six)�OrderedDict�json)�SCALAR_TYPES�
COMPLEX_TYPES)�	shorthand)�%find_service_and_method_in_event_name)�is_json_value_headerzawscli.argprocesscseZdZ�fdd�Z�ZS)�
ParamErrorcs,d||f}tt|�j|�||_||_dS)aB

        :type cli_name: string
        :param cli_name: The complete cli argument name,
            e.g. "--foo-bar".  It should include the leading
            hyphens if that's how a user would specify the name.

        :type message: string
        :param message: The error message to display to the user.

        z Error parsing parameter '%s': %sN)�superr
�__init__�cli_name�message)�selfr
r�full_message)�	__class__�� /usr/lib/python3.6/argprocess.pyrs

zParamError.__init__)�__name__�
__module__�__qualname__r�
__classcell__rr)rrr
sr
c@seZdZdS)�ParamSyntaxErrorN)rrrrrrrr0srcseZdZ�fdd�Z�ZS)�ParamUnknownKeyErrorcs*dj|�}d||f}tt|�j|�dS)Nz, z'Unknown key '%s', valid choices are: %s)�joinrrr)r�keyZ
valid_keysr)rrrr5s

zParamUnknownKeyError.__init__)rrrrrrr)rrr4src@seZdZdS)�TooComplexErrorN)rrrrrrrr=srcCs:t|dd�}|jd|||f||||d�}|dk	r6|}|S)a
    Unpack an argument's value from the commandline. This is part one of a two
    step process in handling commandline arguments. Emits the load-cli-arg
    event with service, operation, and parameter names. Example::

        load-cli-arg.ec2.describe-instances.foo

    �nameZ	anonymouszload-cli-arg.%s.%s.%s)�param�value�service_name�operation_nameN)�getattrZemit_first_non_none_response)Zsessionr r!�cli_argumentrZ
param_nameZvalue_overriderrr�unpack_argumentAs	r$cCsg}t||�S)N)�_detect_shape_structure)r�stackrrr�detect_shape_structureYsr'cs�|j�krdS�j|j�z�|jtkr*dS|jdkr��fdd�|jj�D�}t|�dkrntdd�|D��rnd	St|�dkr�td
d�|D��r�dSdd
jt	t
|���SnD|jdkr�dt|j��S|jdkr�|j
jtkr�dSdt|j
��SWd�j�XdS)N�	recursive�scalar�	structurecsg|]}t|���qSr)r%)�.0�p)r&rr�
<listcomp>gsz+_detect_shape_structure.<locals>.<listcomp>�css|]}|dkVqdS)r)Nr)r+r,rrr�	<genexpr>msz*_detect_shape_structure.<locals>.<genexpr>zstructure(scalar)css|]}|dkVqdS)r)Nr)r+r,rrrr/oszstructure(scalars)z
structure(%s)z, �listzlist-%s�mapz
map-scalarzmap-%s)r�append�	type_namer�members�values�len�allr�sorted�setr%�memberr�pop)rr&Z	sub_typesr)r&rr%^s*





r%cCst|j||j�S)a1
    Parses and unpacks the encoded string command line parameter
    and returns native Python data structures that can be passed
    to the Operation.

    :type cli_argument: :class:`awscli.arguments.BaseCLIArgument`
    :param cli_argument: The CLI argument object.

    :param value: The value of the parameter.  This can be a number of
        different python types (str, list, etc).  This is the value as
        it's specified on the command line.

    :return: The "unpacked" argument than can be sent to the `Operation`
        object in python.
    )�_unpack_cli_arg�argument_modelr
)r#rrrr�unpack_cli_arg~sr>cCs.|jjd�r*|jjd�dkr*|jdkr*dSdS)NZ	jsonvalue�location�header�stringTF)�
serialization�getr3)�modelrrr�
_special_type�s

rEcCsNt|�rt|||�S|jtkr*t|||�S|jtkr@t|||�Stj|�SdS)N)	r	�_unpack_json_cli_argr3r�unpack_scalar_cli_argr�_unpack_complex_cli_argrZ	text_type)r=rr
rrrr<�s



r<cCsHytj|td�Stk
rB}zt|d||f��WYdd}~XnXdS)N)�object_pairs_hookz"Invalid JSON: %s
JSON received: %s)r�loadsr�
ValueErrorr
)r=rr
�errrrF�srFcsJ|j}|dks|dkrz|j�ddkrjytj|td�Stk
rh}zt�d||f��WYdd}~XnXt�d|��n�|dk�rFt|tj	�r�|j�dd	kr�tj|td�SnDt|t
�r�t|�d
kr�|dj�}|r�|dd	kr�tj|dtd�Sy|j
���fdd�|D�Sttfk
�rD}zt�|d��WYdd}~XnXdS)
Nr*r1r�{)rIz"Invalid JSON: %s
JSON received: %szInvalid JSON:
%sr0�[r.csg|]}t�|���qSr)r<)r+�v)r
�member_shape_modelrrr-�sz+_unpack_complex_cli_arg.<locals>.<listcomp>)r3�lstriprrJrrKr
�
isinstancer�string_typesr0r6�stripr:�	TypeError)r=rr
r3rLZsingle_valuer)r
rPrrH�s0
rH�cCs�|jdks|jdkrt|�S|jdks0|jdkr8t|�S|jdkr�|jjd�r�tjj|�}tjj|�}tjj	|�s�d}t
||��t|d�S|jd	kr�t|t
j�r�|j�d
kr�dSt|�S|SdS)NZintegerZlong�floatZdoubleZblobZ	streamingz%Blob values must be a path to a file.�rbZbooleanZfalseF)r3�intrWrBrC�os�path�
expandvars�
expanduser�isfiler
�openrRrrS�lower�bool)r=rr
Z	file_path�msgrrrrG�s"



rGcCs,|jdkrdS|jdkr(|jjdkr(dSdS)Nr*r0r1FT)r*r0r1)r*r0r1)r3r:)rDrrr�_is_complex_shape�s

rcc@seZdZdd�ZdS)�ParamShorthandcCsNddgidgdgdgd�dgdgdgdgd	�d
�}|j|i�j|g�}||kS)z�
        Determines whether a given operation for a service needs to use the
        deprecated shorthand parsing case for lists of structures that only have
        a single member.
        zput-record-batchZrecordszreboot-workspace-requestszrebuild-workspace-requestszterminate-workspace-requests)zreboot-workspaceszrebuild-workspaceszterminate-workspacesZtagsZ	instances)zremove-tagszdescribe-instance-healthz'deregister-instances-from-load-balancerz%register-instances-with-load-balancer)ZfirehoseZ
workspaceszelastic-load-balancing)rC)r�
service_idr!Z
argument_nameZcasesrrr�_uses_old_list_case�sz"ParamShorthand._uses_old_list_caseN)rrrrfrrrrrd�srdc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ParamShorthandParsercCstj�|_tj�|_dS)N)rZShorthandParser�_parserZBackCompatVisitor�_visitor)rrrrrs
zParamShorthandParser.__init__cKs0|j||�sdSt|�\}}|j||||�SdS)a�Attempt to parse shorthand syntax for values.

        This is intended to be hooked up as an event handler (hence the
        **kwargs).  Given ``param`` object and its string ``value``,
        figure out if we can parse it.  If we can parse it, we return
        the parsed value (typically some sort of python dict).

        :type cli_argument: :class:`awscli.arguments.BaseCLIArgument`
        :param cli_argument: The CLI argument object.

        :type param: :class:`botocore.parameters.Parameter`
        :param param: The parameter object (includes various metadata
            about the parameter).

        :type value: str
        :param value: The value for the parameter type on the command
            line, e.g ``--foo this_value``, value would be ``"this_value"``.

        :returns: If we can parse the value we return the parsed value.
            If it looks like JSON, we return None (which tells the event
            emitter to use the default ``unpack_cli_arg`` provided that
            no other event handlers can parsed the value).  If we
            run into an error parsing the value, a ``ParamError`` will
            be raised.

        N)�_should_parse_as_shorthandr�_parse_as_shorthand)rr#rZ
event_name�kwargsrer!rrr�__call__s
zParamShorthandParser.__call__cs�yxtjd|j��j||||�}|dk	r,|St|t�rZ�fdd�|D�}�jj||j�n�j	j
|�}�jj||j�Wnhtjk
r�}zt
|jt|���WYdd}~Xn6t
tfk
r�}zt
|jt|���WYdd}~XnX|S)NzParsing param %s as shorthandcsg|]}�jj|��qSr)rh�parse)r+rO)rrrr-Ksz<ParamShorthandParser._parse_as_shorthand.<locals>.<listcomp>)�LOG�debugr
�_handle_special_casesrRr0riZvisitr=rhrnrZShorthandParseErrorr
�strr)rr#rrer!Z
handled_valueZparsedrLr)rrrk<s"
 "z(ParamShorthandParser._parse_as_shorthandcs�|j}|jdkrf|jjdkrft|jj�dkrf|j|||j�rft|jjj��d��fdd�|D�}|S|jdkr�t|j�dkr�d|jkr�|jdjdkr�d	|kr�d|iSdS)
Nr0r*r.rcsg|]}�|i�qSrr)r+rO)�key_namerrr-nsz>ParamShorthandParser._handle_special_cases.<locals>.<listcomp>�ValuerA�=)	r=r3r:r6r4rfrr0�keys)rr#rrer!rDZ
new_valuesr)rsrrq[s



z*ParamShorthandParser._handle_special_casescCsV|rt|t�r|d}n|}t|tj�rH|j�jd�rHtjd|j�dS|j	}t
|�S)NrrNrMz=Param %s looks like JSON, not considered for param shorthand.F)rNrM)rRr0rrSrT�
startswithrorpZpy_namer=rc)rr#rZ	check_valrDrrrrj~s
z/ParamShorthandParser._should_parse_as_shorthandN)rrrrrmrkrqrjrrrrrgs
$#rgc@sZeZdZdZe�ZdZdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�ZdS)�ParamShorthandDocGenz3Documentation generator for param shorthand syntax.�cCs|dk	rt|�SdS)z3Checks if a CLI argument supports shorthand syntax.NF)rc)rr=rrr�supports_shorthand�sz'ParamShorthandDocGen.supports_shorthandcCsx|j|||�}||jkrdS|r$|Sg}y6|jjdkrN|jj}|j||�dS|j|j|�SWntk
rrdSXdS)a�Generate documentation for a CLI argument.

        :type cli_argument: awscli.arguments.BaseCLIArgument
        :param cli_argument: The CLI argument which to generate
            documentation for.

        :return: Returns either a string or ``None``.  If a string
            is returned, it is the generated shorthand example.
            If a value of ``None`` is returned then this indicates
            that no shorthand syntax is available for the provided
            ``argument_model``.

        Nr0z ...rV)rq�	_DONT_DOCr=r3r:�_shorthand_docsr)rr#rer!Z	docstringr&r=rrr�generate_shorthand_example�s

z/ParamShorthandDocGen.generate_shorthand_examplecCs�|j}|jdkr�|jjdkr�t|jj�dkr�|j|||j�r�t|jj�d}|j}|j	d�dkr||j	d�dkr|d|j
|fSd|j
|||fS|jdkr�t|j�dkr�d	|jkr�|jd	jd
kr�|jSdS)Nr0r*r.r�min�maxz%s %s1z%s %s1 %s2 %s3rtrArV)r=r3r:r6r4rfrr0�metadatarCr
r{)rr#rer!rD�member_namer�rrrrq�s$



z*ParamShorthandDocGen._handle_special_casescCs`t|�|jkrt��|jdkr*|j||�S|jdkr@|j||�S|jdkrV|j||�S|jSdS)Nr*r0r1)r6�
_MAX_STACKrr3�_structure_docs�
_list_docs�	_map_docs)rr=r&rrrr|�s


z$ParamShorthandDocGen._shorthand_docscCsb|j}|j|j�z|j|j|�}Wd|j�X|jtksFt|�dkrRd||fSd||fSdS)Nr.z[%s,%s]z%s,%s)r:r2rr|r;r3rr6)rr=r&Zlist_memberZelement_docsrrrr��s
zParamShorthandDocGen._list_docscCsb|j}|j|j|�}d||f}|jrR|rR|d7}x(|jD]}|d|7}q<Wn|r^d|}|S)NzKeyName1=%s,KeyName2=%sz

Where valid key names are:
z  %s
z{%s})rr|r�enum)rr=r&�kZ
value_docs�startr�rrrr��szParamShorthandDocGen._map_docscCsJg}x*|jj�D]\}}|j|j|||��qWdj|�}|sB|Sd|S)N�,z{%s})r4�itemsr2�_member_docsr)rr=r&�partsrZmember_shapeZ
inner_partrrrr��s
z$ParamShorthandDocGen._structure_docscCsH|j|j�dkrdS|j|j�z|j||�}Wd|j�Xd||fS)Nrz( ... recursive ... )z%s=%s)�countrr2r|r;)rr�shaper&Z	value_docrrrr�s
z!ParamShorthandDocGen._member_docsN)rrr�__doc__�objectr{r�rzr}rqr|r�r�r�r�rrrrrx�s"	rx)rV)%r�rZZloggingZ
awscli.compatrZbotocore.compatrrZawsclirrrZawscli.utilsrZbotocore.utilsr	Z	getLoggerro�	Exceptionr
rrrr$r'r%r>rEr<rFrHrGrcr�rdrgrxrrrr�<module>
s6
	 	
	$