B
    è?F[±  ã               @   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)Ú
isinstanceZ
basestringÚ
ValueError)ÚclsÚparamÚvalue© r   ú0lib/python3.7/site-packages/boto/roboto/param.pyÚconvert_string   s    
zConverter.convert_stringc             C   s   t |ƒS )N)Úint)r   r   r   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   r   r	   Úconvert_boolean'   s    zConverter.convert_booleanc             C   s$   t j |¡rt j |¡s|S t‚d S )N)ÚosÚpathÚexistsÚisdirr   )r   r   r   r   r   r	   Úconvert_file/   s    zConverter.convert_filec             C   s   t j |¡r|S t‚d S )N)r   r   r   r   )r   r   r   r   r   r	   Úconvert_dir5   s    zConverter.convert_dirc             C   sN   y2t | d|j ƒr$t| d|j ƒ}n| j}|||ƒ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 )N)Ú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 )Nz--%s)r#   )r+   r-   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 )Nz%sÚbooleanú=)r#   r   )r+   r-   r   r   r	   Úgetopt_long_nameg   s    

zParam.getopt_long_namec             C   s   d }| j rd| j  }|S )Nz-%s)r"   )r+   Úsnr   r   r	   Úoptparse_short_namep   s    
zParam.optparse_short_namec             C   s   d }| j rd| j  }|S )Nz-%s)r"   )r+   r3   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 )Nz%sr0   ú:)r"   r   )r+   r3   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,   Úpropertyr.   r/   r2   r4   r5   r7   r   Ú__classcell__r   r   )r9   r	   r   F   s      
		r   )r   Úobjectr   r   r   r   r   r	   Ú<module>   s   -