a =jg%@sJddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z ej rzdd l mZdd l mZdd l mZejejejeefejed d dZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdd d eZ Gd!d"d"eZ!dS)#N)gettext)ngettext)get_text_stderr)resolve_color_default)echo)format_filename)Command)Context) Parameter) param_hintreturncCs*|dur&t|ts&ddd|DS|S)Nz / css|]}t|VqdSN)repr).0xr:/usr/local/lib/python3.9/site-packages/click/exceptions.py z$_join_param_hints..) isinstancestrjoin)r rrr_join_param_hintssrcsheZdZdZdZeddfdd Zeddd Zedd d Zde j e j e j dd d dZ ZS)ClickExceptionz8An exception that Click can handle and show to the user.rN)messager cst|t|_||_dSr)super__init__r show_colorr)selfr __class__rrrs zClickException.__init__r cCs|jSrrrrrrformat_message&szClickException.format_messagecCs|jSrr#r$rrr__str__)szClickException.__str__filer cCs2|durt}ttdj|d||jddS)NError: {message}r#r(color)rr_formatr%r)rr(rrrshow,szClickException.show)N)__name__ __module__ __qualname____doc__ exit_coderrr%r&tOptionalIOAnyr. __classcell__rrr rrs rcsVeZdZdZdZd eejdddfdd Zd ejej ej ddd d Z Z S) 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. Nr )rctxr cs*t|||_|jr |jjnd|_dSr)rrr;commandcmd)rrr;r rrrBs zUsageError.__init__r'cCs|durt}d}d}|jdur\|jj|jdur\tdj|jj|jjdd}|d}|jdur|jj}t |j d|||dt tdj| d||ddS) Nz"Try '{command} {option}' for help.r)r<option r*r)r#) rr;r<Zget_help_optionr,r-Z command_pathZhelp_option_namesr+r get_usager%)rr(r+hintrrrr.Gs(  zUsageError.show)N)N) r/r0r1r2r3rr4r5rr6r7r.r8rrr rr97sr9csPeZdZdZd eejdejdejeddfdd Zedd d ZZ S) 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. Nr r )rr;paramr r cst||||_||_dSr)rrrDr )rrr;rDr r rrrpszBadParameter.__init__r"cCsV|jdur|j}n,|jdur,|j|j}ntdj|jdStdjt||jdS)NzInvalid value: {message}r#z)Invalid value for {param_hint}: {message})r r)r rDget_error_hintr;r,r-rr)rr rrrr%{s   zBadParameter.format_message)NNN r/r0r1r2rr4r5rr%r8rrr rrC^s rCcsleZdZdZd ejeejdejdejeejeddfdd Zedd d Zedd d Z Z S)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'``. Nr r )rr;rDr param_typer cs t|p d|||||_dS)Nr>)rrrH)rrr;rDr rHr rrrszMissingParameter.__init__r"cCs|jdur|j}n|jdur,|j|j}nd}t|}|rFd|nd}|j}|durj|jdurj|jj}|j}|jdur|jj |j}|r|r|d|7}n|}|rd|nd}|dkrt d}n4|dkrt d}n"|dkrt d }nt d j |d }||d |S) N r>z. argumentzMissing argumentr?zMissing optionZ parameterzMissing parameterzMissing {param_type})rH.) r rDrEr;rrHZparam_type_namertypeZget_missing_messager,r-)rr rHmsgZ msg_extramissingrrrr%s4      zMissingParameter.format_messagecCs2|js(|jr|jjnd}tdj|dS|jSdS)NzMissing parameter: {param_name}) param_name)rrDnamer,r-)rrOrrrr&szMissingParameter.__str__)NNNNN) r/r0r1r2r4r5rrr%r&r8rrr rrGs   &rGcsVeZdZdZd eejeejejeejdddfdd Zeddd Z Z S) NoSuchOptionzfRaised if click attempted to handle an option that does not exist. .. versionadded:: 4.0 Nr ) option_namer possibilitiesr;r cs6|durtdj|d}t||||_||_dS)NzNo such option: {name})rP)r,r-rrrRrS)rrRrrSr;r rrrs zNoSuchOption.__init__r"cCsH|js |jSdt|j}tddt|jj||d}|jd|S)Nz, zDid you mean {possibility}?z#(Possible options: {possibilities}))Z possibilityrSrI)rSrrsortedrlenr-)rZpossibility_strZsuggestrrrr%szNoSuchOption.format_message)NNN) r/r0r1r2rr4r5Sequencerr%r8rrr rrQs rQcs4eZdZdZdeeejdddfdd ZZS)BadOptionUsageaRaised 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 :param option_name: the name of the option being used incorrectly. Nr )rRrr;r cst||||_dSr)rrrR)rrRrr;r rrrszBadOptionUsage.__init__)N) r/r0r1r2rr4r5rr8rrr rrWs   rWc@seZdZdZdS)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 Nr/r0r1r2rrrrrXsrXcs@eZdZdZd eejeddfdd ZedddZZ S) FileErrorz"Raised if a file cannot be opened.N)filenamerBr cs0|durtd}t|t||_||_dS)Nz unknown error)r,rrr ui_filenamer[)rr[rBr rrr s   zFileError.__init__r"cCstdj|j|jdS)Nz+Could not open file {filename!r}: {message})r[r)r,r-r\rr$rrrr%szFileError.format_message)NrFrrr rrZ srZc@seZdZdZdS)Abortz=An internal signalling exception that signals Click to abort.NrYrrrrr]sr]c@s&eZdZdZdZdeddddZdS) ExitzAn exception that indicates that the application should exit with some status code. :param code: the status code to exit with. r3rN)coder cCs ||_dSrr_)rr`rrrr'sz Exit.__init__)r)r/r0r1r2 __slots__intrrrrrr^sr^)"typingr4rr,rZ_compatrglobalsrutilsrr TYPE_CHECKINGcorer r r r5UnionrVrr Exceptionrr9rCrGrQrWrXrZ RuntimeErrorr]r^rrrrs.          '*E"