File: //snap/certbot/4965/lib64/python3.12/site-packages/certbot/compat/__pycache__/misc.cpython-312.pyc
�
N�h � �l � d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl m
Z
ddlmZ ddl
mZ ddlmZ dd lmZ dd
lmZ dZ ej0 e� Zerg d
�ng Zd#d�Zd#d�Zdedee defd�Z dddd�Z!dddd�Z"dedefd�Z#dedefd�Z$ d$ded ed!ee% de&e'eef fd"�Z(y# e$ r dZY �lw xY w)%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 � t s-t j � dk( rt j d� �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.
r zAError, 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�^�_�_� :�:r c �� � t ryd} t t � }|r#|j |j � | z � yy# t
$ r t j dd�� Y yw xY w)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 �> � t j t j gg g | � \ }}}|s0t j dj |r
|� � �d� � �|d j
� S # t $ r! t j j
� cY S w xY 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�Bz
C:\CertbotzC:\Certbot\libzC:\Certbot\log)�config�work�logsz/etc/letsencryptz/var/lib/letsencryptz/var/log/letsencrypt�folder_typec �L � t j dk7 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)r0 s r �get_default_folderr6 h s% � �
�w�w�$��$�[�1�1�"�;�/�/r �pathc � � t j dk7 r| S t j j | � \ }}||j dd� 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
r2 �:r+ )r r3 r7 �
splitdrive�replace)r7 �drive�tails r �.underscores_for_unsupported_characters_in_pathr>