U
    W¨+d±  ã                   @   s,   d dl Z G dd„ deƒZG dd„ deƒZdS )é    Nc                   @   sT   e Zd Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZed	d
„ ƒZedd„ ƒZ	dS )Ú	Converterc                 C   s   t |tƒst‚|S ©N)Ú
isinstanceÚ
basestringÚ
ValueError©ÚclsÚparamÚvalue© r   ú5/tmp/pip-unpacked-wheel-dlxw5sjy/boto/roboto/param.pyÚconvert_string   s    
zConverter.convert_stringc                 C   s   t |ƒS r   )Úintr   r   r   r   Úconvert_integer"   s    zConverter.convert_integerc                 C   s   dS )zt
        For command line arguments, just the presence
        of the option means True so just return True
        Tr   r   r   r   r   Úconvert_boolean'   s    zConverter.convert_booleanc                 C   s$   t j |¡rt j |¡s|S t‚d S r   )ÚosÚpathÚexistsÚisdirr   r   r   r   r   Úconvert_file/   s    zConverter.convert_filec                 C   s   t j |¡r|S t‚d S r   )r   r   r   r   r   r   r   r   Úconvert_dir5   s    zConverter.convert_dirc                 C   sP   z4t | d|j ƒr$t| d|j ƒ}n| j}|||ƒW S    t|dƒ‚Y nX d S )NZconvert_Ú )ÚhasattrÚptypeÚgetattrr   ZValidationException)r   r	   r
   Zmthdr   r   r   Úconvert;   s    zConverter.convertN)
Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r   r   r   r   r   r   r   r   r   r      s   




r   c                       sn   e Zd Zddd„Zedd	„ ƒZed
d„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZ	edd„ ƒZ
‡ fdd„Z‡  ZS )ÚParamNÚstringTr   é   c                 C   sL   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _d S r   )Únamer   ÚoptionalÚ
short_nameÚ	long_nameÚdocÚmetavarÚcardinalityÚdefaultÚchoicesÚencoderÚrequest_param)Úselfr#   r   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r   r   r   Ú__init__H   s    zParam.__init__c                 C   s   d }| j rd| j  }|S ©Nz--%s©r&   ©r.   Úlnr   r   r   Úoptparse_long_nameY   s    
zParam.optparse_long_namec                 C   s   d }| j rd| j  }|S r0   r1   r2   r   r   r   Úsynopsis_long_name`   s    
zParam.synopsis_long_namec                 C   s*   d }| j r&d| j  }| jdkr&|d7 }|S )Nú%sÚbooleanú=)r&   r   r2   r   r   r   Úgetopt_long_nameg   s    

zParam.getopt_long_namec                 C   s   d }| j rd| j  }|S ©Nz-%s©r%   ©r.   Zsnr   r   r   Úoptparse_short_namep   s    
zParam.optparse_short_namec                 C   s   d }| j rd| j  }|S r:   r;   r<   r   r   r   Úsynopsis_short_namew   s    
zParam.synopsis_short_namec                 C   s*   d }| j r&d| j  }| jdkr&|d7 }|S )Nr6   r7   ú:)r%   r   r<   r   r   r   Úgetopt_short_name~   s    

zParam.getopt_short_namec                    s   t t| ƒ | |¡S )aB  
        Convert a string value as received in the command line
        tools and convert to the appropriate type of value.
        Raise a ValidationError if the value can't be converted.

        :type value: str
        :param value: The value to convert.  This should always
                      be a string.
        )Úsuperr    r   )r.   r
   ©Ú	__class__r   r   r   ‡   s    
zParam.convert)Nr!   TNNr   Nr"   NNNT)r   r   r   r/   Úpropertyr4   r5   r9   r=   r>   r@   r   Ú__classcell__r   r   rB   r   r    F   s0                   ý






r    )r   Úobjectr   r    r   r   r   r   Ú<module>   s   -