a oe#@sdZddlZddlZddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd l mZdd lmZdd lmZddlmZddlmZddlmZe rddlmZd8eee eefdddZeedddZd9eeeedddZGdddZGdd d ejZ Gd!d"d"ej!Z"e ej#ej$feeeed#d$d%Z%Gd&d'd'e&Z'eed(d)d*Z(Gd+d,d,ej!Z)eeeed-d.d/Z*Gd0d1d1ej!Z+Gd2d3d3ej!Z,Gd4d5d5ej!Z-ee.d(d6d7Z/dS):z"Certbot command line util functionN)Any)Iterable)List)Optional)Sequence)Tuple) TYPE_CHECKING)Union) challenges) configuration)errors)util) constants)os)helpfulrb)filenamemodereturnc Cs~zHtj|}t||}|}Wdn1s60Y||fWStyx}zt|jWYd}~n d}~00dS)aReturns the given file's contents. :param str filename: path to file :param str mode: open mode (see `open`) :returns: absolute path of filename and its contents :rtype: tuple :raises argparse.ArgumentTypeError: File does not exist or is not readable. N) rpathabspathopenreadIOErrorargparseArgumentTypeErrorstrerror)rrZthe_filecontentsexcr@C:\Program Files\Certbot\pkgs\certbot\_internal\cli\cli_utils.py read_files   & r!)namercCsttj|S)zDefault value for CLI flag.)copydeepcopyrZ CLI_DEFAULTS)r"rrr flag_default.sr%F)r"hiddenrcCs|r tjStttj|S)zRExtract the help message for a `configuration.NamespaceConfig` property docstring.)rSUPPRESSinspectZgetdocgetattrr NamespaceConfig)r"r&rrr config_help7sr+c@s4eZdZdZdeddddZeedddd ZdS) HelpfulArgumentGroupa+Emulates an argparse group for use with HelpfulArgumentParser. This class is used in the add_group method of HelpfulArgumentParser. Command line arguments can be added to the group, but help suppression and default detection is applied by HelpfulArgumentParser when necessary. zhelpful.HelpfulArgumentParserN)helpful_arg_parsertopicrcCs||_||_dSN)_parser_topic)selfr-r.rrr __init__GszHelpfulArgumentGroup.__init__)argskwargsrcOs |jj|jg|Ri|dS)z6Add a new command line argument to the argument group.N)r0addr1)r2r4r5rrr add_argumentKsz!HelpfulArgumentGroup.add_argument)__name__ __module__ __qualname____doc__strr3rr7rrrr r,>sr,c@s&eZdZdZejeedddZdS)CustomHelpFormatterzThis is a clone of ArgumentDefaultsHelpFormatter, with bugfixes. In particular we fix https://bugs.python.org/issue28742 )actionrcCsX|j}|jrTd|jvrTd|jvrT|jtjkrTtjtjg}|rT|jsL|j|vrT|d7}|S)Nz %(default)z (default:z (default: %(default)s))helpdefaultrr'OPTIONAL ZERO_OR_MOREoption_stringsnargs)r2r>Zhelpstrdefaulting_nargsrrr _get_help_stringVs  z$CustomHelpFormatter._get_help_stringN) r8r9r:r;rActionrr<rFrrrr r=Psr=c@s>eZdZdZdejejeee e dfe eddddZ dS)_DomainsActionz!Action class for parsing domains.N)parser namespacedomain option_stringrcCst||durt|nddS)z%Just wrap add_domains in argparseese.N) add_domainsr<)r2rIrJrKrLrrr __call__csz_DomainsAction.__call__)N r8r9r:r;rArgumentParser Namespacer r<rrrrNrrrr rH`s  rH)args_or_configdomainsrcCsNg}|s |S|dD]2}t|}||||jvr|j|q|S)aRegisters new domains to be used during the current client run. Domains are not added to the list of requested domains if they have already been registered. :param args_or_config: parsed command line arguments :type args_or_config: argparse.Namespace or configuration.NamespaceConfig :param str domain: one or more comma separated domains :returns: domains after they have been normalized and validated :rtype: `list` of `str` ,)splitr Zenforce_domain_sanitystripappendrS)rRrSZvalidated_domainsrKrrr rMjs  rMcs(eZdZdZeedfdd ZZS)CaseInsensitiveListaA list that will ignore case when searching. This class is passed to the `choices` argument of `argparse.add_arguments` through the `helpful` wrapper. It is necessary due to special handling of command line arguments by `set_by_cli` in which the `type_func` is not applied.)elementrcst|tsdSt|S)NF) isinstancer<super __contains__lower)r2rY __class__rr r\s z CaseInsensitiveList.__contains__)r8r9r:r;objectboolr\ __classcell__rrr^r rXsrX)valuercCsd|vsd|vrtd|S)N()zmay not contain parentheses)rr)rcrrr _user_agent_comment_types rfc@s>eZdZdZdejejeee e dfe eddddZ dS)_EncodeReasonActionz+Action class for parsing revocation reason.N)rIrJreasonrLrcCs4|durtdtjt|}t||j|dS)z.Encodes the reason for certificate revocation.NzUnexpected null reason.) ValueErrorrZREVOCATION_REASONSr<r]setattrdest)r2rIrJrhrLcoderrr rNsz_EncodeReasonAction.__call__)NrOrrrr rgs  rg) pref_challsrcsVddddd|D}fdd|D}ddd |D}|rRtd ||S) a Translate and validate preferred challenges. :param pref_challs: list of preferred challenge types :type pref_challs: `list` of `str` :returns: validated list of preferred challenge types :rtype: `list` of `str` :raises errors.Error: if pref_challs is invalid zdns-01zhttp-01)ZdnshttpcSsg|] }|qSr)rV.0crrr z.parse_preferred_challenges..csg|]}||qSr)getroaliasesrr rrrsz, css|]}|tjjvr|VqdSr/)r Z ChallengeZTYPES)rpr"rrr s z-parse_preferred_challenges..zUnrecognized challenges: {0})joinr Errorformat)rmchallsZ unrecognizedrrur parse_preferred_challengess r|c@s>eZdZdZdejejeee e dfe eddddZ dS)_PrefChallActionz.Action class for parsing preferred challenges.N)rIrJrmrLrc Csn|durtdztt|d}Wn6tjy\}zt|t|WYd}~n d}~00|j |dS)NzUnexpected null pref_challs.rT) rir|r<rUr ryr ArgumentErrorrmextend)r2rIrJrmrLr{errorrrr rNs&z_PrefChallAction.__call__)NrOrrrr r}s  r}c@s>eZdZdZdejejeee e dfe eddddZ dS)_DeployHookActionz&Action class for parsing deploy hooks.NrIrJvaluesrLrcCs6|j|jk}|r&|j|kr&t|d||_|_dS)Nz!conflicts with --renew-hook value) deploy_hook renew_hookrr~)r2rIrJrrLZrenew_hook_setrrr rNs  z_DeployHookAction.__call__)NrOrrrr rs  rc@s>eZdZdZdejejeee e dfe eddddZ dS)_RenewHookActionz%Action class for parsing renew hooks.NrcCs.|jdu}|r$|j|kr$t|d||_dS)Nz"conflicts with --deploy-hook value)rrr~r)r2rIrJrrLZdeploy_hook_setrrr rNs  z_RenewHookAction.__call__)NrOrrrr rs  rcCs@z t|}Wnty(tdYn0|dkrsH