
    M/e,              	          d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ erddlmZ d5dededeeef   fdZdedefdZd6dedede	e   fdZ G d d      Z G d dej@                        Z! G d dejD                        Z#d eejH                  ejJ                  f   d!e	e   dee   fd"Z& G d# d$e'      Z(d%edefd&Z) G d' d(ejD                        Z*d)ee   dee   fd*Z+ G d+ d,ejD                        Z, G d- d.ejD                        Z- G d/ d0ejD                        Z.d%ede/fd1Z0d2ed3ejJ                  ddfd4Z1y)7z"Certbot command line util function    N)Any)Iterable)List)Optional)Sequence)Tuple)TYPE_CHECKING)Union)
challenges)configuration)errors)util)	constants)os)helpfulfilenamemodereturnc                    	 t         j                  j                  |       } t        | |      5 }|j	                         }ddd       | fS # 1 sw Y   xY w# t
        $ r$}t        j                  |j                        d}~ww xY w)a  Returns 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)r   r   the_filecontentsexcs        A/usr/lib/python3/dist-packages/certbot/_internal/cli/cli_utils.py	read_filer"      sv    777??8,(D! 	'X}}H	'!!	' 	'  7((667s-   +A A
A 
AA 	BA>>Bnamec                 N    t        j                  t        j                  |          S )zDefault value for CLI flag.)copydeepcopyr   CLI_DEFAULTS)r#   s    r!   flag_defaultr(   /   s     ==//566    hiddenc                     |rt         j                  S t        j                  t	        t
        j                  |             S )zRExtract the help message for a `configuration.NamespaceConfig` property docstring.)r   SUPPRESSinspectgetdocgetattrr   NamespaceConfig)r#   r*   s     r!   config_helpr1   8   s-       >>'-"?"?FGGr)   c                   8    e Zd ZdZdddeddfdZded	eddfd
Zy)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.

    helpful_arg_parserzhelpful.HelpfulArgumentParsertopicr   Nc                      || _         || _        y N)_parser_topic)selfr4   r5   s      r!   __init__zHelpfulArgumentGroup.__init__H   s    )r)   argskwargsc                 X     | j                   j                  | j                  g|i | y)z6Add a new command line argument to the argument group.N)r8   addr9   )r:   r<   r=   s      r!   add_argumentz!HelpfulArgumentGroup.add_argumentL   s$    6t6v6r)   )__name__
__module____qualname____doc__strr;   r   r@    r)   r!   r3   r3   ?   s>    +J SV [_ 7# 7 7 7r)   r3   c                   :    e Zd ZdZdej
                  dee   fdZy)CustomHelpFormatterzThis is a clone of ArgumentDefaultsHelpFormatter, with bugfixes.

    In particular we fix https://bugs.python.org/issue28742
    actionr   c                 *   |j                   }|j                   rzd|j                   vrld|j                   vr^|j                  t        j                  k7  rAt        j                  t        j
                  g}|r|j                  s|j                  |v r|dz  }|S )Nz
%(default)z	(default:z (default: %(default)s))helpdefaultr   r,   OPTIONALZERO_OR_MOREoption_stringsnargs)r:   rI   helpstrdefaulting_nargss       r!   _get_help_stringz$CustomHelpFormatter._get_help_stringW   s{    ++;;<v{{:{RXR]R]?]~~!2!22$,$5$5x7L7L#M  5 5IY9Y88Gr)   N)	rA   rB   rC   rD   r   Actionr   rE   rS   rF   r)   r!   rH   rH   Q   s"    
x 8C= r)   rH   c                   p    e Zd ZdZ	 d	dej
                  dej                  deee	e
   df   dee   ddf
dZy)
_DomainsActionz!Action class for parsing domains.Nparser	namespacedomainoption_stringr   c                 @    t        ||t        |             yd       y)z%Just wrap add_domains in argparseese.N)add_domainsrE   )r:   rW   rX   rY   rZ   s        r!   __call__z_DomainsAction.__call__d   s     	If.@s6{KdKr)   r7   rA   rB   rC   rD   r   ArgumentParser	Namespacer
   rE   r   r   r   r]   rF   r)   r!   rV   rV   a   s[    + 15Lx66 L8CUCU LsHSM478L (L9=Lr)   rV   args_or_configdomainsc                     g }|s|S |j                  d      D ]`  }t        j                  |j                               }|j	                  |       || j
                  vsF| j
                  j	                  |       b |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   enforce_domain_sanitystripappendrb   )ra   rb   validated_domainsrY   s       r!   r\   r\   k   sy      $&  --$ 2++FLLN;  (///""))&1	2 r)   c                   ,     e Zd ZdZdedef fdZ xZS )CaseInsensitiveLista  A 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.elementr   c                 `    t        |t              syt        |   |j	                               S )NF)
isinstancerE   super__contains__lower)r:   rl   	__class__s     r!   rp   z CaseInsensitiveList.__contains__   s&    '3'w#GMMO44r)   )rA   rB   rC   rD   objectboolrp   __classcell__)rr   s   @r!   rk   rk      s!    W
5F 5t 5 5r)   rk   valuec                 @    d| v sd| v rt        j                  d      | S )N()zmay not contain parentheses)r   r   )rv   s    r!   _user_agent_comment_typerz      s&    
e|se|(()FGGLr)   c                   p    e Zd ZdZ	 d	dej
                  dej                  deee	e
   df   dee   ddf
dZy)
_EncodeReasonActionz+Action class for parsing revocation reason.NrW   rX   reasonrZ   r   c                     |t        d      t        j                  t        |      j	                            }t        || j                  |       y)z.Encodes the reason for certificate revocation.NzUnexpected null reason.)
ValueErrorr   REVOCATION_REASONSrE   rq   setattrdest)r:   rW   rX   r}   rZ   codes         r!   r]   z_EncodeReasonAction.__call__   sB     >677++CK,=,=,?@	499d+r)   r7   r^   rF   r)   r!   r|   r|      sU    5 15,x66 ,8CUCU ,sHSM478, (,9=,r)   r|   pref_challsc                    ddd}| D cg c]  }|j                          }}|D cg c]  }|j                  ||       }}dj                  d |D              }|r$t        j                  dj                  |            |S c c}w c c}w )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

    zdns-01zhttp-01)dnshttpz, c              3   X   K   | ]"  }|t         j                  j                  vr| $ y wr7   )r   	ChallengeTYPES).0r#   s     r!   	<genexpr>z-parse_preferred_challenges.<locals>.<genexpr>   s-      Hd $J,@,@,F,F F " Hs   (*zUnrecognized challenges: {0})rg   getjoinr   Errorformat)r   aliasescchallsunrecognizeds        r!   parse_preferred_challengesr      s     	2G!,-Aaggi-F-)/0Agkk!Q0F099 Hf H HLll*11,?A 	AM .0s
   BBc                   p    e Zd ZdZ	 d	dej
                  dej                  deee	e
   df   dee   ddf
dZy)
_PrefChallActionz.Action class for parsing preferred challenges.NrW   rX   r   rZ   r   c                    |t        d      	 t        t        |      j                  d            }|j                  j                  |       y # t        j
                  $ r$}t        j                  | t        |            d }~ww xY w)NzUnexpected null pref_challs.rd   )
r   r   rE   re   r   r   r   ArgumentErrorr   extend)r:   rW   rX   r   rZ   r   errors          r!   r]   z_PrefChallAction.__call__   sx     ;<<	;/K0@0F0Fs0KLF 	$$V, || 	;((s5z::	;s   #A B!B  Br7   r^   rF   r)   r!   r   r      sU    8 15	-x66 	-8CUCU 	-#C#$<=	- (	-9=	-r)   r   c                   p    e Zd ZdZ	 d	dej
                  dej                  deee	e
   df   dee   ddf
dZy)
_DeployHookActionz&Action class for parsing deploy hooks.NrW   rX   valuesrZ   r   c                     |j                   |j                  k7  }|r%|j                  |k7  rt        j                  | d      |x|_         |_        y )Nz!conflicts with --renew-hook value)deploy_hook
renew_hookr   r   )r:   rW   rX   r   rZ   renew_hook_sets         r!   r]   z_DeployHookAction.__call__   sS     #..)2F2FFi22f<((9; ;7==		 4r)   r7   r^   rF   r)   r!   r   r      sU    0 15>x66 >8CUCU >sHSM478> (>9=>r)   r   c                   p    e Zd ZdZ	 d	dej
                  dej                  deee	e
   df   dee   ddf
dZy)
_RenewHookActionz%Action class for parsing renew hooks.NrW   rX   r   rZ   r   c                 |    |j                   d u}|r%|j                   |k7  rt        j                  | d      ||_        y )Nz"conflicts with --deploy-hook value)r   r   r   r   )r:   rW   rX   r   rZ   deploy_hook_sets         r!   r]   z_RenewHookAction.__call__   sE     $//t;y44>((:< <%	r)   r7   r^   rF   r)   r!   r   r      sU    / 15&x66 &8CUCU &sHSM478& (&9=&r)   r   c                     	 t        |       }|dk  rt        j                  d      |S # t        $ r t        j                  d      w xY w)a[  Converts value to an int and checks that it is not negative.

    This function should used as the type parameter for argparse
    arguments.

    :param str value: value provided on the command line

    :returns: integer representation of value
    :rtype: int

    :raises argparse.ArgumentTypeError: if value isn't a non-negative integer

    zvalue must be an integerr   zvalue must be non-negative)intr   r   r   )rv   	int_values     r!   nonnegative_intr      sW    EJ	 1}(()EFF  E(()CDDEs	   ) Averbconfigc                 $   t        d      t        j                  f}|j                  r#|j                  |vrt        j                  d      |j                  t        d      k(  rt        j                  |_        d|_        |j                  r| dvrt        j                  d| z        dx|_	        |_        t        j                  t        j                  j                  |j                  t        j                  d            rd|_        d|_        yyy)a	  Updates server, break_my_certs, staging, tos, and
    register_unsafely_without_email in config as necessary to prepare
    to use the test server.

    We have --staging/--dry-run; perform sanity check and set config.server

    :param str verb: subcommand called

    :param config: parsed command line arguments
    :type config: configuration.NamespaceConfig

    :raises errors.Error: if non-default server is used and --staging is set
    :raises errors.Error: if inapplicable verb is used and --dry-run is set
    serverz'--server value conflicts with --stagingN)certonlyrenewreconfigurezN--dry-run currently only works with the 'certonly' or 'renew' subcommands (%r)T*)r(   r   STAGING_URIstagingr   r   r   accountdry_runbreak_my_certsglobr   r   r   
config_dirACCOUNTS_DIRtosregister_unsafely_without_email)r   r   default_serverss      r!   set_test_server_optionsr      s    . $H-y/D/DEO~~&-->llDEE}}X..!-- ~~;;,,  HJN O P P15599RWW\\&"3"3Y5K5KSQR FJ59F2	 S r)   )rb)F)2rD   r   r%   r   r-   typingr   r   r   r   r   r   r	   r
   acmer   certbotr   r   r   certbot._internalr   certbot.compatr   certbot._internal.clir   rE   r"   r(   rt   r1   r3   HelpFormatterrH   rT   rV   r`   r0   r\   listrk   rz   r|   r   r   r   r   r   r   r   rF   r)   r!   <module>r      s   (               !   ' -7 73 7%S/ 7*7s 7s 7Hc H4 HHSM H7 7$(00  LX__ Lh&8&8-:W:W&W X !#+/9:	5$ 	5C C 
,(// 
,HSM d3i 0-x -
> 
>
&x 
&3 3 .+:# +:}/L/L +:QU +:r)   