HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //snap/certbot/4965/lib64/python3.12/site-packages/certbot/compat/__pycache__/misc.cpython-312.pyc
�

N�h��l�dZddlmZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZ	ddl
mZddlmZdd	lmZdd
lmZdZej0e�Zergd
�ngZd#d�Zd#d�Zdedeedefd�Z dddd�Z!dddd�Z"dedefd�Z#dedefd�Z$	d$ded ed!ee%de&e'eeffd"�Z(y#e$rdZY�lwxYw)%zk
This compat module handles various platform specific calls that do not fall into one
particular category.
�)�absolute_importN)�Optional)�errors)�os)�error)�shell)�GetStdHandle)�STD_OUTPUT_HANDLEFT)z	/usr/sbinz/usr/local/binz/usr/local/sbin�returnc�j�ts-tj�dk(rtjd��yy)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.
    rzAError, certbot must be run on a shell with administrative rights.N)�
POSIX_MODE�
shellwin32�
IsUserAnAdminr�Error����/build/snapcraft-certbot-c9561b03ef7f16aa90eb6754ca5f17a1/parts/certbot/install/lib/python3.12/site-packages/certbot/compat/misc.py�+raise_for_non_administrative_windows_rightsr s.���*�2�2�4��9��l�l�^�_�_�:�:rc���tryd}	tt�}|r#|j|j	�|z�yy#t
$rtjdd��YywxYw)zR
    On Windows, ensure that Console Virtual Terminal Sequences are enabled.

    N�zFailed 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�>�	tjtjggg|�\}}}|s0tjdj|r
|���d���|dj
�S#t$r!tjj
�cYSwxYw)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�stdinrr�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�Bz
C:\CertbotzC:\Certbot\libzC:\Certbot\log)�config�work�logsz/etc/letsencryptz/var/lib/letsencryptz/var/log/letsencrypt�folder_typec�L�tjdk7r	t|St|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)r0s r�get_default_folderr6hs%��
�w�w�$��$�[�1�1�"�;�/�/r�pathc��tjdk7r|Stjj|�\}}||j	dd�zS)z�
    Replace unsupported characters in path for current OS by underscores.
    :param str path: the path to normalize
    :return: the normalized path
    :rtype: str
    r2�:r+)rr3r7�
splitdrive�replace)r7�drive�tails   r�.underscores_for_unsupported_characters_in_pathr>ysD��
�w�w�$�����'�'�$�$�T�*�K�E�4��4�<�<��S�)�)�)r�cmd_name�	shell_cmd�envc	�t�tjd||�tr9tj|dtj
tj
dd|��}n<dd|g}tj|tj
tj
dd|��}|j|j}}|j||fS)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)
    zRunning %s command: %sTF)r�stdout�stderr�universal_newlines�checkrAzpowershell.exez-Command)rCrDrErFrA)	r�infor
�
subprocess�run�PIPErCrD�
returncode)r?r@rA�proc�line�out�errs       r�execute_command_statusrP�s���"�K�K�(�(�I�>���~�~�i�t�J�O�O�%/�_�_��$)�s�4��!�*�i�8���~�~�d�:�?�?�:�?�?�15�U��M��
�{�{�D�K�K��C��?�?�C��$�$r)rN)N))�__doc__�
__future__r�loggingr$rHr%�typingr�certbotr�certbot.compatr�
pywintypesrr�win32com.shellrr�win32consoler	r
r
�ImportError�	getLogger�__name__r�STANDARD_BINARY_DIRSrr�float�strr,r5r4r6r>�dict�tuple�intrPrrr�<module>rcs"���'��
��
�����.�2�)�.��J�

��	�	�8�	$��NX�I�]_��`�B�($�5�$�(�3�-�$�C�$�<�����!�"�"���0�C�0�C�0�"
*��
*��
*�"26�%�S�%�S�%� (���%�:?��S�#�
�:N�%��g���J��s�B)�)B3�2B3