a }|g$ @ s\ d Z ddlmZ ddlZddlZddlZddlZddlmZ ddlm Z ddl mZ ddlm Z z8ddlmZ dd lmZ dd lmZ ddlmZ dZW n ey d ZY n0 eeZerg dng ZddddZddddZeee e dddZ!ddddZ"ddddZ#e e ddd Z$e e d!d"d#Z%d'e e ee& e e'e e f d$d%d&Z(dS )(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 C s t st dkrtddS )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 shellwin32Z IsUserAnAdminr Error r r 7/usr/lib/python3.9/site-packages/certbot/compat/misc.py+raise_for_non_administrative_windows_rights! s r c C sT t rdS d} z"tt}|r,|| | B W n tyN tjddd Y n0 dS )zR On Windows, ensure that Console Virtual Terminal Sequences are enabled. N zFailed to set console modeT)exc_info)r r r ZSetConsoleModeZGetConsoleMode pywinerrorloggerdebug)Z"ENABLE_VIRTUAL_TERMINAL_PROCESSINGhr r r prepare_virtual_console, s r )timeoutpromptr c C sf zDt tjgg g | \}}}|s8td|r0|nd|d W S ty` tj Y S 0 dS )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 N)selectsysstdinr r formatreadlineOSError)r r Zrlist_r r r readline_with_timeout@ s r# z C:\CertbotzC:\Certbot\libzC:\Certbot\log)ZconfigZworkZlogsz/etc/letsencryptz/var/lib/letsencryptz/var/log/letsencrypt)folder_typer c C s t jdkrt| 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 nameLINUX_DEFAULT_FOLDERSWINDOWS_DEFAULT_FOLDERS)r$ r r r get_default_folderi s r) )pathr c C s. t jdkr| S t j| \}}||dd 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 r% :r" )r r&