3 گa @ s d Z ddlmZ ddlZddlZddlZddlZddlmZ ddlm Z ddl Z ddlmZ ddl mZ y8ddlmZ dd lmZ dd lmZ ddlmZ dZW n ek r d ZY nX ejeZerdddgng ZddddZddddZe ee! e!dddZ"ddddZ#ddddZ$e!e!d d!d"Z%e!e!d#d$d%Z&d+e!e!ee' e e(e!e!f d&d'd(Z)d,e!e!ee' 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_HANDLEFTz /usr/sbinz/usr/local/binz/usr/local/sbin)returnc C s t rtj dkrtjddS )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 /usr/lib/python3.6/misc.py+raise_for_non_administrative_windows_rights" s r c C sV t rdS d} y"tt}|r,|j|j | B W n" tk rP tjddd Y nX 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 sb yBt j tjgg g | \}}}|s8tjdj|r0|nd|d j S tk r\ tjj S X 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_timeoutA s r# z C:\CertbotzC:\Certbot\libzC:\Certbot\log)configZworkZlogsz/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_folderj s r* )pathr c C s. t jdkr| S t jj| \}}||jdd 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&