U W@sddlmZmZmZddlmZGdddeZGdddeZGdddeZ Gd d d e Z Gd d d eZ Gd ddeZ GdddeZ GdddeZGdddeZdS))PY2filename_to_uiget_text_stderr)echoc@s.eZdZdZdZddZddZd dd ZdS) ClickExceptionz8An exception that Click can handle and show to the user.rcCs,tr|dk r|d}t||||_dS)Nzutf-8)rencode Exception__init__message)selfr r /exceptions.pyr s   zClickException.__init__cCs|jSN)r r r r r format_messageszClickException.format_messageNcCs&|dkrt}td||ddS)N Error: %s)file)rrr)r rr r r showszClickException.show)N)__name__ __module__ __qualname____doc__ exit_coder rrr r r r rs rc@s(eZdZdZdZdddZd ddZdS) 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 ctxr r rr r r r %s zUsageError.__init__cCsV|dkrt}d}|jdk r<|jj}t|jd||dtd|||ddS)N )rcolorr)rrrrZ get_usager)r rrr r r r)s zUsageError.show)N)N)rrrrrr rr r r r rs rc@s"eZdZdZdddZddZdS) 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)r r rr r!r r r r EszBadParameter.__init__cCsj|jdk r|j}n(|jdk r0|jjp,|jjg}n d|jSt|ttfr\ddd|D}d||jfS)NzInvalid value: %s / css|]}d|VqdSz"%s"Nr .0xr r r Ssz.BadParameter.format_message..zInvalid value for %s: %s) r!r optshuman_readable_namer isinstancetuplelistjoin)r r!r r r rKs   zBadParameter.format_message)NNNrrrrr rr r r r r3s  rc@s"eZdZdZdddZddZdS)MissingParameteraRaised 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)r r rr r!r0r r r r cszMissingParameter.__init__cCs|jdk r|j}n"|jdk r0|jjp,|jjg}nd}t|ttfrVddd|D}|j}|dkrv|jdk rv|jj }|j }|jdk r|jj |j}|r|r|d|7}n|}d||rd|pd|rdpd|pdfS) Nr"css|]}d|VqdSr#r r$r r r r'psz2MissingParameter.format_message..z. zMissing %s%s%s%sz %s.) r!r r(r)r*r+r,r-r0Zparam_type_namer typeZget_missing_message)r r!r0msgZ msg_extrar r r rhs.    zMissingParameter.format_message)NNNNNr.r r r r r/Ws   r/c@s"eZdZdZdddZddZdS) 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)r r6r r7rr r r r s zNoSuchOption.__init__cCsZ|jg}|jrPt|jdkr2|d|jdnt|j}|dd|d|S)NrzDid you mean %s?z(Possible options: %s)z, z )r r7lenappendsortedr-)r bitsr7r r r rs zNoSuchOption.format_message)NNNr.r r r r r5s  r5c@seZdZdZdddZdS)BadOptionUsagezRaised 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|||dSrrr rr r r r szBadOptionUsage.__init__)Nrrrrr r r r r r=sr=c@seZdZdZdddZdS)BadArgumentUsagezRaised 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>rr r r r szBadArgumentUsage.__init__)Nr?r r r r r@sr@c@s"eZdZdZdddZddZdS) FileErrorz"Raised if a file cannot be opened.NcCs0t|}|dkrd}t||||_||_dS)Nz unknown error)rrr ui_filenamefilename)r rCZhintrBr r r r s  zFileError.__init__cCsd|j|jfS)NzCould not open file %s: %s)rBr rr r r rszFileError.format_message)Nr.r r r r rAs rAc@seZdZdZdS)Abortz=An internal signalling exception that signals Click to abort.N)rrrrr r r r rDsrDN)Z_compatrrrZutilsrrrrrr/r5r=r@rA RuntimeErrorrDr r r r s $0