o
    .&ßa  ã                   @   s`   d dl Z d dlmZ d dlZdd„ Zdd„ ZG dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZdS )é    N)ÚCustomArgumentc                 C   sN   | du rdS t j t j | ¡¡}t  t j t j |¡¡t j¡s%td| ƒ‚|S )z=Asserts that a path is writable and returns the expanded pathNzUnable to write to file: %s)	ÚosÚpathÚ
expanduserÚ
expandvarsÚaccessÚdirnameÚabspathÚW_OKÚ
ValueError)r   Úoutfile© r   úA/usr/lib/python3/dist-packages/awscli/customizations/arguments.pyÚresolve_given_outfile_path   s   r   c                 C   s   | d d dk S )z-Returns True if a parsed result is successfulÚResponseMetadataÚHTTPStatusCodei,  r   )Úparsed_resultr   r   r   Úis_parsed_result_successful   s   r   c                       s8   e Zd ZdZddiZ‡ fdd„Zdd„ Zdd	„ Z‡  ZS )
ÚOverrideRequiredArgsArgumenta¶  An argument that if specified makes all other arguments not required

    By not required, it refers to not having an error thrown when the
    parser does not find an argument that is required on the command line.
    To obtain this argument's property of ignoring required arguments,
    subclass from this class and fill out the ``ARG_DATA`` parameter as
    described below. Note this class is really only useful for subclassing.
    Únamezno-required-argsc                    s*   || _ |  ¡  tt| ƒjdi | j¤Ž d S )Nr   )Ú_sessionÚ_register_argument_actionÚsuperr   Ú__init__ÚARG_DATA)ÚselfÚsession©Ú	__class__r   r   r   7   s   z%OverrideRequiredArgsArgument.__init__c                 C   s   | j  d| j¡ d S )Nz%before-building-argument-table-parser)r   ÚregisterÚoverride_required_args©r   r   r   r   r   <   s   ÿz6OverrideRequiredArgsArgument._register_argument_actionc                 K   s2   d| j  }||v r| ¡ D ]	}d|| _qd S d S )Nz--F)r   ÚkeysÚrequired)r   Úargument_tableÚargsÚkwargsÚname_in_cmdlineÚarg_namer   r   r   r    @   s   
þz3OverrideRequiredArgsArgument.override_required_args)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    Ú__classcell__r   r   r   r   r   !   s    r   c                       s8   e Zd ZdZ‡ fdd„Z‡ fdd„Zedd„ ƒZ‡  ZS )ÚStatefulArgumentz+An argument that maintains a stateful valuec                    s    t t| ƒj|i |¤Ž d | _d S ©N)r   r.   r   Ú_value)r   r%   r&   r   r   r   r   L   s   
zStatefulArgument.__init__c                    s   t t| ƒ ||¡ || _d S r/   )r   r.   Úadd_to_paramsr0   ©r   Ú
parametersÚvaluer   r   r   r1   P   s   
zStatefulArgument.add_to_paramsc                 C   ó   | j S r/   )r0   r!   r   r   r   r4   T   ó   zStatefulArgument.value)	r)   r*   r+   r,   r   r1   Úpropertyr4   r-   r   r   r   r   r.   I   s    r.   c                       sL   e Zd ZdZ‡ fdd„Zedd„ ƒZedd„ ƒZ‡ fdd	„Zd
d„ Z	‡  Z
S )ÚQueryOutFileArgumentz8An argument that write a JMESPath query result to a filec                    sP   || _ || _|| _|| _d|vrd| j |d< tt| ƒj|g|¢R i |¤Ž d S )NÚ	help_textz=Saves the command output contents of %s to the given filename)r   Ú_queryÚ_after_call_eventÚ_permÚqueryr   r8   r   )r   r   r   r=   Úafter_call_eventÚpermr%   r&   r   r   r   r   \   s   ÿ"zQueryOutFileArgument.__init__c                 C   r5   r/   )r:   r!   r   r   r   r=   h   r6   zQueryOutFileArgument.queryc                 C   r5   r/   )r<   r!   r   r   r   r?   l   r6   zQueryOutFileArgument.permc                    s>   t |ƒ}tt| ƒ ||¡ | jd ur| j | j| j¡ d S d S r/   )	r   r   r8   r1   r4   r   r   r;   Ú
save_queryr2   r   r   r   r1   p   s
   
þz"QueryOutFileArgument.add_to_paramsc                 K   sz   t |ƒr;t | j|¡}t| jdƒ� }|du r| d¡ n| |¡ t | j| j	¡ W d  ƒ dS 1 s4w   Y  dS dS )z¨Saves the result of a JMESPath expression to a file.

        This method only saves the query data if the response code of
        the parsed result is < 300.
        ÚwNÚ )
r   ÚjmespathÚsearchr=   Úopenr4   Úwriter   Úchmodr?   )r   Úparsedr&   ÚcontentsÚfpr   r   r   r@   w   s   
"úþzQueryOutFileArgument.save_query)r)   r*   r+   r,   r   r7   r=   r?   r1   r@   r-   r   r   r   r   r8   Y   s    

r8   )	r   Úawscli.argumentsr   rC   r   r   r   r.   r8   r   r   r   r   Ú<module>   s   
(