a ‚oe¨#ã@sdZddlZddlZddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd l mZdd lmZdd lmZddlmZddlmZddlmZe rÔddlmZd8eee eefdœdd„Zeedœdd„Zd9eeeedœdd„ZGdd„dƒZGdd „d ejƒZ 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*Gd0d1„d1ej!ƒZ+Gd2d3„d3ej!ƒZ,Gd4d5„d5ej!ƒZ-ee.d(œd6d7„Z/dS):z"Certbot command line util functionéN)ÚAny)ÚIterable)ÚList)ÚOptional)ÚSequence)ÚTuple)Ú TYPE_CHECKING)ÚUnion)Ú challenges)Ú configuration)Úerrors)Úutil)Ú constants)Úos)ÚhelpfulÚrb)ÚfilenameÚmodeÚreturnc Cs~zHtj |¡}t||ƒ�}| ¡}Wdƒn1s60Y||fWStyx}zt |j¡‚WYd}~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) rÚpathÚabspathÚopenÚreadÚIOErrorÚargparseÚArgumentTypeErrorÚstrerror)rrZthe_fileÚcontentsÚexc©rú@C:\Program Files\Certbot\pkgs\certbot\_internal\cli\cli_utils.pyÚ read_files   & r!)ÚnamercCst tj|¡S)zDefault value for CLI flag.)ÚcopyÚdeepcopyrZ CLI_DEFAULTS)r"rrr Ú flag_default.sr%F)r"ÚhiddenrcCs|r tjSt ttj|ƒ¡S)zRExtract the help message for a `configuration.NamespaceConfig` property docstring.)rÚSUPPRESSÚinspectZgetdocÚgetattrr ÚNamespaceConfig)r"r&rrr Ú config_help7sr+c@s4eZdZdZdeddœdd„Zeeddœdd „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_parserÚtopicrcCs||_||_dS©N)Ú_parserÚ_topic)Úselfr-r.rrr Ú__init__GszHelpfulArgumentGroup.__init__)ÚargsÚkwargsrcOs |jj|jg|¢Ri|¤ŽdS)z6Add a new command line argument to the argument group.N)r0Úaddr1)r2r4r5rrr Ú add_argumentKsz!HelpfulArgumentGroup.add_argument)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ústrr3rr7rrrr r,>sr,c@s&eZdZdZejeedœdd„ZdS)ÚCustomHelpFormatterz‚This 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))ÚhelpÚdefaultrr'ÚOPTIONALÚ ZERO_OR_MOREÚoption_stringsÚnargs)r2r>ZhelpstrÚdefaulting_nargsrrr Ú_get_help_stringVs  z$CustomHelpFormatter._get_help_stringN) r8r9r:r;rÚActionrr<rFrrrr r=Psr=c@s>eZdZdZdejejeee e dfe eddœdd„Z dS)Ú_DomainsActionz!Action class for parsing domains.N)ÚparserÚ namespaceÚdomainÚ option_stringrcCst||durt|ƒndƒdS)z%Just wrap add_domains in argparseese.N)Ú add_domainsr<)r2rIrJrKrLrrr Ú__call__csz_DomainsAction.__call__)N© r8r9r:r;rÚArgumentParserÚ Namespacer r<rrrrNrrrr rH`s þ þrH)Úargs_or_configÚdomainsrcCsNg}|s |S| d¡D]2}t | ¡¡}| |¡||jvr|j |¡q|S)a×Registers 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_sanityÚstripÚappendrS)rRrSZvalidated_domainsrKrrr rMjs  rMcs(eZdZdZeedœ‡fdd„ Z‡ZS)Ú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|tƒsdStƒ | ¡¡S)NF)Ú isinstancer<ÚsuperÚ __contains__Úlower)r2rY©Ú __class__rr r\�s z CaseInsensitiveList.__contains__)r8r9r:r;ÚobjectÚboolr\Ú __classcell__rrr^r rX‡srX)ÚvaluercCsd|vsd|vrt d¡‚|S)Nú(ú)zmay not contain parentheses)rr)rcrrr Ú_user_agent_comment_type“s rfc@s>eZdZdZdejejeee e dfe eddœdd„Z dS)Ú_EncodeReasonActionz+Action class for parsing revocation reason.N)rIrJÚreasonrLrcCs4|durtdƒ‚tjt|ƒ ¡}t||j|ƒdS)z.Encodes the reason for certificate revocation.NzUnexpected null reason.)Ú ValueErrorrZREVOCATION_REASONSr<r]ÚsetattrÚdest)r2rIrJrhrLÚcoderrr rNœsz_EncodeReasonAction.__call__)NrOrrrr rg™s þ þrg)Ú pref_challsrcsVdddœ‰dd„|Dƒ}‡fdd„|Dƒ}d dd „|Dƒ¡}|rRt d  |¡¡‚|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)ZdnsÚhttpcSsg|] }| ¡‘qSr)rV©Ú.0Úcrrr Ú ³óz.parse_preferred_challenges..csg|]}ˆ ||¡‘qSr)Úgetro©Úaliasesrr rr´rsz, css|]}|tjjvr|VqdSr/)r Z ChallengeZTYPES)rpr"rrr Ú ¶s ÿz-parse_preferred_challenges..zUnrecognized challenges: {0})Újoinr ÚErrorÚformat)rmÚchallsZ unrecognizedrrur Úparse_preferred_challenges¦s ÿr|c@s>eZdZdZdejejeee e dfe eddœdd„Z dS)Ú_PrefChallActionz.Action class for parsing preferred challenges.N)rIrJrmrLrc Csn|durtdƒ‚ztt|ƒ d¡ƒ}Wn6tjy\}zt |t|ƒ¡‚WYd}~n d}~00|j  |¡dS)NzUnexpected null pref_challs.rT) rir|r<rUr ryrÚ ArgumentErrorrmÚextend)r2rIrJrmrLr{Úerrorrrr rNÁs&z_PrefChallAction.__call__)NrOrrrr r}¾s þ þr}c@s>eZdZdZdejejeee e dfe eddœdd„Z dS)Ú_DeployHookActionz&Action class for parsing deploy hooks.N©rIrJÚvaluesrLrcCs6|j|jk}|r&|j|kr&t |d¡‚||_|_dS)Nz!conflicts with --renew-hook value)Ú deploy_hookÚ renew_hookrr~)r2rIrJrƒrLZrenew_hook_setrrr rNÐs  ÿz_DeployHookAction.__call__)NrOrrrr r�Ís þ þr�c@s>eZdZdZdejejeee e dfe eddœdd„Z dS)Ú_RenewHookActionz%Action class for parsing renew hooks.Nr‚cCs.|jdu}|r$|j|kr$t |d¡‚||_dS)Nz"conflicts with --deploy-hook value)r„rr~r…)r2rIrJrƒrLZdeploy_hook_setrrr rNÝs  ÿz_RenewHookAction.__call__)NrOrrrr r†Ús þ þr†cCs@z t|ƒ}Wnty(t d¡‚Yn0|dkrsH                  ÿ