U
��W��@s�ddlmZmZmZddlmZGdd�de�ZGdd�de�ZGdd�de�Z Gd d
�d
e �Z
Gdd�de�ZGd
d�de�ZGdd�de�Z
Gdd�de�ZGdd�de�ZdS)�)�PY2�filename_to_ui�get_text_stderr)�echoc@s.eZdZdZdZdd�Zdd�Zd
dd �ZdS)�ClickExceptionz8An exception that Click can handle and show to the user.rcCs,tr|dk r|�d�}t�||�||_dS)Nzutf-8)r�encode� Exception�__init__�message)�selfr
�r�/exceptions.pyr s
zClickException.__init__cCs|jS�N)r
�rrrr
�format_messageszClickException.format_messageNcCs&|dkrt�}td|��|d�dS)N� Error: %s)�file)rrr)rrrrr
�showszClickException.show)N)�__name__�
__module__�__qualname__�__doc__� exit_coder rrrrrr
rs
rc@s(eZdZdZdZddd�Zd dd�ZdS)
�
UsageErrora+An internal exception that signals a usage error. This typically
aborts any further handling.
:param message: the error message to display.
:param ctx: optionally the context that caused this error. Click will
fill in the context automatically in some situations.
�NcCst�||�||_dSr)rr �ctx�rr
rrrr
r %szUsageError.__init__cCsV|dkrt�}d}|jdk r<|jj}t|j��d||d�td|��||d�dS)N�
)r�colorr)rrrrZ get_usager)rrrrrr
r)s
zUsageError.show)N)N)rrrrrr rrrrr
rs
rc@s"eZdZdZddd�Zdd�ZdS)�BadParametera
An exception that formats out a standardized error message for a
bad parameter. This is useful when thrown from a callback or type as
Click will attach contextual information to it (for instance, which
parameter it is).
.. versionadded:: 2.0
:param param: the parameter object that caused this error. This can
be left out, and Click will attach this info itself
if possible.
:param param_hint: a string that shows up as parameter name. This
can be used as alternative to `param` in cases
where custom validation should happen. If it is
a string it's used as such, if it's a list then
each item is quoted and separated.
NcCst�|||�||_||_dSr)rr �param�
param_hint)rr
rr r!rrr
r EszBadParameter.__init__cCsj|jdk r|j}n(|jdk r0|jjp,|jjg}n
d|jSt|ttf�r\d�dd�|D��}d||jfS)NzInvalid value: %s� / css|]}d|VqdS�z"%s"Nr��.0�xrrr
� <genexpr>Ssz.BadParameter.format_message.<locals>.<genexpr>zInvalid value for %s: %s) r!r �opts�human_readable_namer
�
isinstance�tuple�list�join)rr!rrr
rKs
zBadParameter.format_message)NNN�rrrrr rrrrr
r3s
�
rc@s"eZdZdZddd�Zdd�ZdS)�MissingParametera�Raised if click required an option or argument but it was not
provided when invoking the script.
.. versionadded:: 4.0
:param param_type: a string that indicates the type of the parameter.
The default is to inherit the parameter type from
the given `param`. Valid values are ``'parameter'``,
``'option'`` or ``'argument'``.
NcCst�|||||�||_dSr)rr �
param_type)rr
rr r!r0rrr
r cszMissingParameter.__init__cCs�|jdk r|j}n"|jdk r0|jjp,|jjg}nd}t|ttf�rVd�dd�|D��}|j}|dkrv|jdk rv|jj }|j
}|jdk r�|jj�|j�}|r�|r�|d|7}n|}d||r�d|p�d|r�dp�d|p�dfS) Nr"css|]}d|VqdSr#rr$rrr
r'psz2MissingParameter.format_message.<locals>.<genexpr>z. zMissing %s%s%s%sz %s��.)
r!r r(r)r*r+r,r-r0Zparam_type_namer
�typeZget_missing_message)rr!r0�msgZ msg_extrarrr
rhs.
�zMissingParameter.format_message)NNNNNr.rrrr
r/Ws�
r/c@s"eZdZdZddd�Zdd�ZdS)�NoSuchOptionzfRaised if click attempted to handle an option that does not
exist.
.. versionadded:: 4.0
NcCs.|dkrd|}t�|||�||_||_dS)Nzno such option: %s)rr �option_name�
possibilities)rr6r
r7rrrr
r �s
zNoSuchOption.__init__cCsZ|jg}|jrPt|j�dkr2|�d|jd�nt|j�}|�dd�|��d�|�S)NrzDid you mean %s?�z(Possible options: %s)z, z )r
r7�len�append�sortedr-)r�bitsr7rrr
r�s
zNoSuchOption.format_message)NNNr.rrrr
r5�s
�
r5c@seZdZdZddd�ZdS)�BadOptionUsagez�Raised if an option is generally supplied but the use of the option
was incorrect. This is for instance raised if the number of arguments
for an option is not correct.
.. versionadded:: 4.0
NcCst�|||�dSr�rr rrrr
r �szBadOptionUsage.__init__)N�rrrrr rrrr
r=�sr=c@seZdZdZddd�ZdS)�BadArgumentUsagez�Raised if an argument is generally supplied but the use of the argument
was incorrect. This is for instance raised if the number of values
for an argument is not correct.
.. versionadded:: 6.0
NcCst�|||�dSrr>rrrr
r �szBadArgumentUsage.__init__)Nr?rrrr
r@�sr@c@s"eZdZdZddd�Zdd�ZdS)� FileErrorz"Raised if a file cannot be opened.NcCs0t|�}|dkrd}t�||�||_||_dS)Nz
unknown error)rrr �ui_filename�filename)rrCZhintrBrrr
r �szFileError.__init__cCsd|j|jfS)NzCould not open file %s: %s)rBr
rrrr
r�szFileError.format_message)Nr.rrrr
rA�s
rAc@seZdZdZdS)�Abortz=An internal signalling exception that signals Click to abort.N)rrrrrrrr
rD�srDN)Z_compatrrrZutilsrrrrrr/r5r=r@rA�RuntimeErrorrDrrrr
�<module>s$0 |