Ë
    M/Åe$  ã                   óx  — d Z ddlm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Z ej2                  e«      Zerg d¢ng Zd$d„Zd$d„Zdedee    de fd„Z!ddddœZ"ddddœZ#de de fd„Z$de de fd„Z%	 d%d e d!e d"ee&   de	e'e e f   fd#„Z(y# e$ r dZY Œlw xY w)&zk
This compat module handles various platform specific calls that do not fall into one
particular category.
é    )Úabsolute_importN)ÚOptional)ÚTuple)Úerrors)Úos)Úerror)Úshell)ÚGetStdHandle)ÚSTD_OUTPUT_HANDLEFT)z	/usr/sbinz/usr/local/binz/usr/local/sbinÚreturnc                  ój   — t         s-t        j                  «       dk(  rt        j                  d«      ‚yy)zÏ
    On Windows, raise if current shell does not have the administrative rights.
    Do nothing on Linux.

    :raises .errors.Error: If the current shell does not have administrative rights on Windows.
    r   zAError, certbot must be run on a shell with administrative rights.N)Ú
POSIX_MODEÚ
shellwin32ÚIsUserAnAdminr   ÚError© ó    ú5/usr/lib/python3/dist-packages/certbot/compat/misc.pyÚ+raise_for_non_administrative_windows_rightsr   !   s.   € õ œ*×2Ñ2Ó4¸Ò9Ü�l‰lÐ^Ó_Ð_ð :ˆ:r   c                  óÌ   — t         ryd} 	 t        t        «      }|r#|j                  |j	                  «       | z  «       yy# t
        $ r t        j                  dd¬«       Y yw xY w)zR
    On Windows, ensure that Console Virtual Terminal Sequences are enabled.

    Né   zFailed to set console modeT)Úexc_info)r   r
   r   ÚSetConsoleModeÚGetConsoleModeÚ
pywinerrorÚloggerÚdebug)Ú"ENABLE_VIRTUAL_TERMINAL_PROCESSINGÚhs     r   Úprepare_virtual_consoler    ,   sj   € õ
 Øð *0Ð&ðBÜÔ*Ó+ˆÙØ×Ñ˜Q×-Ñ-Ó/Ð2TÑTÕUð øäò BÜ�‰Ð1¸DˆÖAðBús   ‹3A  Á  A#Á"A#ÚtimeoutÚpromptc                 ó>  — 	 t        j                   t        j                  gg g | «      \  }}}|s0t        j                  dj                  |r
|«      «      ‚d«      «      ‚|d   j                  «       S # t        $ r! t        j                  j                  «       cY S w xY w)a(  
    Read user input to return the first line entered, or raise after specified timeout.

    :param float timeout: The timeout in seconds given to the user.
    :param str prompt: The prompt message to display to the user.

    :returns: The first line entered by the user.
    :rtype: str

    z,Timed out waiting for answer to prompt '{0}'Ú r   )ÚselectÚsysÚstdinr   r   ÚformatÚreadlineÚOSError)r!   r"   ÚrlistÚ_s       r   Úreadline_with_timeoutr-   @   s™   € ð$ô —m‘m¤S§Y¡Y K°°R¸ÓA‰ˆˆq�!ÙÜ—,‘,Ø>×EÑEÑPVÀfÓ_óað aØ\^Ó_óað aà�Q‰x× Ñ Ó"Ð"øÜò $ô �y‰y×!Ñ!Ó#Ò#ð$ús   ‚A/A2 Á2'BÂBz
C:\CertbotzC:\Certbot\libzC:\Certbot\log)ÚconfigÚworkÚlogsz/etc/letsencryptz/var/lib/letsencryptz/var/log/letsencryptÚfolder_typec                 óL   — t         j                  dk7  r	t        |    S t        |    S )zÏ
    Return the relevant default folder for the current OS

    :param str folder_type: The type of folder to retrieve (config, work or logs)

    :returns: The relevant default folder.
    :rtype: str

    Únt)r   ÚnameÚLINUX_DEFAULT_FOLDERSÚWINDOWS_DEFAULT_FOLDERS)r1   s    r   Úget_default_folderr7   i   s%   € ô 
‡w�w�$‚ä$ [Ñ1Ð1ä" ;Ñ/Ð/r   Úpathc                 óš   — t         j                  dk7  r| S t         j                  j                  | «      \  }}||j	                  dd«      z   S )z«
    Replace unsupported characters in path for current OS by underscores.
    :param str path: the path to normalize
    :return: the normalized path
    :rtype: str
    r3   ú:r,   )r   r4   r8   Ú
splitdriveÚreplace)r8   ÚdriveÚtails      r   Ú.underscores_for_unsupported_characters_in_pathr?   z   sD   € ô 
‡w�w�$‚àˆô —'‘'×$Ñ$ TÓ*�K€Eˆ4Ø�4—<‘<  SÓ)Ñ)Ð)r   Úcmd_nameÚ	shell_cmdÚenvc           	      ót  — t         j                  d| |«       t        r9t        j                  |dt        j
                  t        j
                  dd|¬«      }n<dd|g}t        j                  |t        j
                  t        j
                  dd|¬«      }|j                  |j                  }}|j                  ||fS )a#  
    Run a command:
        - on Linux command will be run by the standard shell selected with
          subprocess.run(shell=True)
        - on Windows command will be run in a Powershell shell

    This function returns the exit code, and does not log the result and output
    of the command.

    :param str cmd_name: the user facing name of the hook being run
    :param str shell_cmd: shell command to execute
    :param dict env: environ to pass into subprocess.run

    :returns: `tuple` (`int` returncode, `str` stderr, `str` stdout)
    zRunning %s command: %sTF)r	   ÚstdoutÚstderrÚuniversal_newlinesÚcheckrB   zpowershell.exez-Command)rD   rE   rF   rG   rB   )	r   Úinfor   Ú
subprocessÚrunÚPIPErD   rE   Ú
returncode)r@   rA   rB   ÚprocÚlineÚoutÚerrs          r   Úexecute_command_statusrQ   Š   s”   € ô" ‡K�KÐ(¨(°IÔ>åÜ�~‰~˜i¨t¼J¿O¹OÜ%/§_¡_ÈØ$)¨sô4‰ð ! *¨iÐ8ˆÜ�~‰~˜d¬:¯?©?Ä:Ç?Á?Ø15¸UÈôMˆð
 �{‰{˜DŸK™Kˆ€CØ�?‰?˜C Ð$Ð$r   )r   N)N))Ú__doc__Ú
__future__r   Úloggingr%   rI   r&   Útypingr   r   Úcertbotr   Úcertbot.compatr   Ú
pywintypesr   r   Úwin32com.shellr	   r   Úwin32consoler
   r   r   ÚImportErrorÚ	getLoggerÚ__name__r   ÚSTANDARD_BINARY_DIRSr   r    ÚfloatÚstrr-   r6   r5   r7   r?   ÚdictÚintrQ   r   r   r   ú<module>rc      s%  ðñõ 'ã Û Û Û 
Ý Ý å Ý ðÝ.Ý2Ý)Ý.Ø€Jð
 
ˆ×	Ñ	˜8Ó	$€ñ NXÓIÐ]_Ð ó`óBð($ 5ð $°(¸3±-ð $ÀCó $ð< ØØñÐ ð !Ø"Ø"ñÐ ð0 Cð 0¨Có 0ð"*¸ð *Àó *ð" 26ñ% Sð %°Sð %Ø (¨¡ð%Ø:?ÀÀSÈ#ÀÑ:Nô%øðg ò Ø‚Jðús   ²B/ Â/B9Â8B9