????

Your IP : 18.222.144.72


Current Path : /lib/python3.6/site-packages/certbot/_internal/cli/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/certbot/_internal/cli/__pycache__/helpful.cpython-36.pyc

3

گa�Q�@s�dZddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddlm
Z
ddlmZddlmZddl
Z
dd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddl"m#Z#ddl"m$Z$ddl%m&Z'ddl(m)Z)ddl*m+Z+Gdd�d�Z,dS) z$Certbot command line argument parser�N)�Any)�Dict)�Iterable)�List)�Optional)�Union)�crypto_util)�errors)�util)�	constants)�hooks)�ARGPARSE_PARAMS_TO_REMOVE)�COMMAND_OVERVIEW)�EXIT_ACTIONS)�HELP_AND_VERSION_USAGE)�SHORT_USAGE)�ZERO_ARG_ACTIONS)�_Default)�add_domains)�CustomHelpFormatter)�flag_default)�HelpfulArgumentGroup)�	VERB_HELP)�
VERB_HELP_MAP)�obj)�disco)�osc@szeZdZdZd2eeeeedd�dd�Zddd	d
dgZ	ed�d
d�Z
eeeeefed�dd�Ze
jdd�dd�Ze
jd�dd�Ze
jdd�dd�Ze
jdd�dd�Zdd�dd�Zeeeeeefd�dd�Zeeeeeefeedd �d!d"�Zeeeefd#�d$d%�Zeedd&�d'd(�Zffeeeeed)�d*d+�Zejdd,�d-d.�Z eeefeeefd/�d0d1�Z!dS)3�HelpfulArgumentParserz�Argparse Wrapper.

    This class wraps argparse, adding the ability to make --help less
    verbose, and request help on specific subcategories at a time, eg
    'certbot --help security' for security options.

    FN)�args�plugins�detect_defaults�returnc
Cs�ddlm}|j|j|j|j|j|j|j|j|j	|j
|j|j|j|j
|j|jd�|_tjtj�j|_dddddg}|t|j�|jd	g7}t|�}||dg|_||_||_|jr�|jdd
kr�d|jd<|j�|jd|j�}|jd|j�}|t|t��rt|t��r|�p||_ nt|t!��r,|n||_ |j"||j �}	|j#|j �|_$i|_%i|_&t'j(d
|	t)ddgt*d�dj+dj,t*d���d�|_-d|j-_.|dS)Nr)�main)�auth�certonly�run�installr�register�update_account�
unregister�renew�revoke�rollback�
everything�update_symlinks�certificates�delete�enhance�allZsecurity�pathsZ
automationZtestingZmanage�helpz--helpz-h�certbotz-cz--configZconfig_filesz"path to config file (default: {0})z and )�prog�usageZformatter_classZargs_for_setting_config_pathZdefault_config_filesZconfig_arg_help_messageF)/�certbot._internalr"r$r%r&Zplugins_cmdr'r(r)r*r+r,r.r/r0r1�VERBS�display_objZNoninteractiveDisplay�sys�stdoutZnotification�notify�list�COMMANDS_TOPICS�help_topicsr r�determine_verb�prescan_for_flag�
isinstance�bool�help_arg�str�
_usage_string�determine_help_topics�visible_topics�groups�defaults�configargparseZ	ArgParserrr�format�join�parserZ_add_config_file_help)
�selfrrr r"ZHELP_TOPICSZplugin_namesZhelp1Zhelp2Zshort_usage�rQ�/usr/lib/python3.6/helpful.py�__init__0s^
zHelpfulArgumentParser.__init__ZcommandZcommandsZ
subcommandZsubcommands�verbs)r!cCsXtdd�tD��}d}x4tt�D](\}}|jdd�}|dj|||d�7}q W|d7}|S)	Ncss|]}t|�VqdS)N)�len)�.0�vrQrQrR�	<genexpr>zsz:HelpfulArgumentParser._list_subcommands.<locals>.<genexpr>z,The full list of available SUBCOMMANDS is:

�short�z{0:<{length}}     {1}
)ZlengthzG
You can get more help on a specific subcommand with --help SUBCOMMAND
)�maxr�sortedr�getrM)rPZlongest�text�verbZprops�docrQrQrR�_list_subcommandsysz'HelpfulArgumentParser._list_subcommands)rrEr!cCs�d|krd}nd}d|kr d}nd}t}|dkrV|j|t||ft�tjd�nl||jkr~|j||j��tjd�nD|d	kr�|t||f7}n*t|t	�r�t
j|i�jd
d�}|r�|n|}|S)a#Make usage strings late so that plugins can be initialised late

        :param plugins: all discovered plugins
        :param help_arg: False for none; True for --help; "TOPIC" for --help TOPIC
        :rtype: str
        :returns: a short usage string for the top of --help TOPIC)
        ZnginxzH--nginx           Use the Nginx plugin for authentication & installationz+(the certbot nginx plugin is not installed)ZapachezI--apache          Use the Apache plugin for authentication & installationz,(the certbot apache plugin is not installed)Trr2r7N)rr=rrr;�exitr?rarCrFrr])rPrrEZ	nginx_docZ
apache_docr7ZcustomrQrQrRrG�s&

z#HelpfulArgumentParser._usage_string)�parsed_argsr!cCsL|jdkrHx<|jjj�D],\}}|jd�rd|kr|jr>t�ng|_qWdS)z8Make "certbot renew" safe if domains are set in cli.ini.r*Zconfig_file�domainsN)r_rOZ_source_to_settings�items�
startswithr rrd)rPrc�source�flagsrQrQrR�&remove_config_file_domains_for_renewal�s
z<HelpfulArgumentParser.remove_config_file_domains_for_renewalcsB�jj�j�}�j�j|_�j|_�j|��jr8|S�fdd�t|�D��_	�jdkrx|j
rrtjdj
tj���d|_|j
r�|jr�tjdj
tj���|js�|jr��j|�|jr��j|�|jr�d|_|jr�tj|�|jr�tdd�|jD��r�tjd	��|j�r|j�rtjd
��t|j t!��r>t"|j �dk�r>tjd��|S)
z�Parses command line arguments and returns the result.

        :returns: parsed command line arguments
        :rtype: argparse.Namespace

        cs i|]}tj�jj|��|�qSrQ)�copy�deepcopyrOZget_default)rV�key)rPrQrR�
<dictcomp>�sz4HelpfulArgumentParser.parse_args.<locals>.<dictcomp>r*z{0} cannot be used with renewTz.Flag for non-interactive mode and {0} conflictcss|]}tj|�VqdS)N)r
Zis_wildcard_domain)rV�drQrQrRrX�sz3HelpfulArgumentParser.parse_args.<locals>.<genexpr>zFUsing --allow-subset-of-names with a wildcard domain is not supported.z@Parameters --hsts and --auto-hsts cannot be used simultaneously.�z8Only *one* --key-type type may be provided at this time.)#rO�
parse_argsrr9r_�funcrir �varsrKZforce_interactiver	�ErrorrMrZFORCE_INTERACTIVE_FLAGZnoninteractive_mode�staging�dry_run�set_test_server�csr�
handle_csrZmust_stapleZstapleZvalidate_hooksr�allow_subset_of_names�anyrdZhstsZ	auto_hstsrCZkey_typer>rU)rPrcrQ)rPrRrp�sH








z HelpfulArgumentParser.parse_argscCs�td�tjf}|jr(|j|kr(tjd��|j|kr:tj|_|jr�|jd	krZtjd|j��d|_	|_t
j
tjj
|jtjd��r�d|_d|_dS)
zGWe have --staging/--dry-run; perform sanity check and set config.server�serverz'--server value conflicts with --stagingr$r*zN--dry-run currently only works with the 'certonly' or 'renew' subcommands (%r)T�*N)r$r*)rrZSTAGING_URIrtr{r	rsrur_Zbreak_my_certs�globr�pathrNZ
config_dirZACCOUNTS_DIRZtosZregister_unsafely_without_email)rPrcZdefault_serversrQrQrRrv�s




z%HelpfulArgumentParser.set_test_serverc
Cs�|jdkrtjd��|jr$tjd��|jdd�\}}tj||�\}}}x|D]}t||�qNW|sxtjd|jd��||f|_dd�|D�}t	|j
�}	||	kr�tjd	jd
j
|�d
j
|	����dS)zProcess a --csr flag.r$z�Currently, a CSR file may only be specified when obtaining a new or replacement via the certonly command. Please try the certonly command instead.z1--allow-subset-of-names cannot be used with --csrr�zJUnfortunately, your CSR %s needs to have a SubjectAltName for every domaincSsh|]}|j��qSrQ)�lower)rVrnrQrQrR�	<setcomp>"sz3HelpfulArgumentParser.handle_csr.<locals>.<setcomp>zMInconsistent domain requests:
From the CSR: {0}
From command line/config: {1}z, N)r_r	rsryrwrZimport_csr_filerZ
actual_csr�setrdZConfigurationErrorrMrN)
rPrcZcsrfile�contents�typrwrdZdomainZcsr_domainsZconfig_domainsrQrQrRrxs&





z HelpfulArgumentParser.handle_csrcCs|d|jksd|jkrd|_dSxRt|j�D]D\}}||jkr*|}|dkrLd}|dkrXd}||_|jj|�dSq*Wd|_dS)	z�Determines the verb/subcommand provided by the user.

        This function works around some of the limitations of argparse.

        z-hz--helpr4Nr#r$r-r%)rr_�	enumerater9�pop)rP�i�tokenr_rQrQrRrA*s
z$HelpfulArgumentParser.determine_verb)�flag�possible_argumentsr!cCsR||jkrdS|jj|�}y|j|d}||kr6|SWntk
rLYnXdS)asChecks cli input for flags.

        Check for a flag, which accepts a fixed set of possible arguments, in
        the command line; we will use this information to configure argparse's
        help correctly.  Return the flag's argument, if it has one that matches
        the sequence @possible_arguments; otherwise return whether the flag is
        present.

        FroT)r�index�
IndexError)rPr�r��posZnxtrQrQrRrBBs

z&HelpfulArgumentParser.prescan_for_flag)�topicsr�kwargsr!cOs�|jd�}|tjkr&|jj||�dSt|t�rJ|j|kr@|jn|d}n|}|jr`|j	f|�}t|t
�r�|j|r�||jkr�|j|}|j||�q�|jj||�nt
j|d<|jj||�dS)a1Add a new command line argument.

        :param topics: str or [str] help topic(s) this should be listed under,
                       or None for options that don't fit under a specific
                       topic which will only be shown in "--help all" output.
                       The first entry determines where the flag lives in the
                       "--help all" output (None -> "optional arguments").
        :param list *args: the names of this argument flag
        :param dict **kwargs: various argparse settings for this argument

        �actionNrr4)r]r
ZDeprecatedArgumentActionrO�add_argumentrCr>rEr �#modify_kwargs_for_default_detectionrFrIrJ�argparseZSUPPRESS)rPr�rr�r��topic�grouprQrQrR�addWs 

	



zHelpfulArgumentParser.add)r�r!cKsP|jdd�}|tkrL|tkr dnd|d<t�|d<xtD]}|j|d�q8W|S)a_Modify an arg so we can check if it was set by the user.

        Changes the parameters given to argparse when adding an argument
        so we can properly detect if the value was set by the user.

        :param dict kwargs: various argparse settings for this argument

        :returns: a modified versions of kwargs
        :rtype: dict

        r�N�
store_trueZstore�default)r]rrrr
r�)rPr�r�ZparamrQrQrRr��s

z9HelpfulArgumentParser.modify_kwargs_for_default_detection)�
argument_name�num_argsr!cCs tj|jd�}tj|||�dS)a�Adds a deprecated argument with the name argument_name.

        Deprecated arguments are not shown in the help. If they are used
        on the command line, a warning is shown stating that the
        argument is deprecated and no other action is taken.

        :param str argument_name: Name of deprecated argument.
        :param int num_args: Number of arguments the option takes.

        N)�	functools�partialr�r
�add_deprecated_argument)rPr�r�Zadd_funcrQrQrRr��sz-HelpfulArgumentParser.add_deprecated_argument)r�rTr�r!cKsZ|j|rP|jj|f|�|j|<|jrPx(|D] }|j|j|t|dd�q,Wt||�S)a�Create a new argument group.

        This method must be called once for every topic, however, calls
        to this function are left next to the argument definitions for
        clarity.

        :param str topic: Name of the new argument group.
        :param str verbs: List of subcommands that should be documented as part of
                          this help group / topic

        :returns: The new argument group.
        :rtype: `HelpfulArgumentGroup`

        rY)r4)rIrOZadd_argument_grouprJrEr�rr)rPr�rTr�rWrQrQrR�	add_group�s

 zHelpfulArgumentParser.add_group)rr!cCs8x2|j�D]&\}}|j||jd�}|jj||�q
WdS)z�

        Let each of the plugins add its own command line arguments, which
        may or may not be displayed as help topics.

        )�descriptionN)rer�Zlong_descriptionZ
plugin_clsZinject_parser_options)rPr�nameZ	plugin_epZparser_or_grouprQrQrR�add_plugin_args�s
z%HelpfulArgumentParser.add_plugin_args)�chosen_topicr!csX�dkrd��dkrd��dkr0dd�|jD�S�sDdd�|jD�S�fd	d�|jD�S)
z�

        The user may have requested help on a topic, return a dict of which
        topics to display. @chosen_topic has prescan_for_flag's return type

        :returns: dict

        r#r$r-r%r2cSsi|]}|dk|�qS)zcertbot-route53:authrQ)rV�trQrQrRrm�sz?HelpfulArgumentParser.determine_help_topics.<locals>.<dictcomp>cSsi|]
}d|�qS)FrQ)rVr�rQrQrRrm�scsi|]}|�k|�qSrQrQ)rVr�)r�rQrRrm�s)r@)rPr�rQ)r�rRrH�sz+HelpfulArgumentParser.determine_help_topics)F)"�__name__�
__module__�__qualname__�__doc__rrFrrDrSr?rarrGr�Z	NamespacerirprvrxrArBrrr�rr��intr�rr�rZPluginsRegistryr�rHrQrQrQrRr(s&F#<"-r)-r�r�rjr�r}r;ZtypingrrrrrrrLr5rr	r
r8rrZ#certbot._internal.cli.cli_constantsr
rrrrrZcertbot._internal.cli.cli_utilsrrrrrZcertbot._internal.cli.verb_helprrZcertbot._internal.displayrr:Zcertbot._internal.pluginsrZcertbot.compatrrrQrQrQrR�<module>sD