ok

Mini Shell

Direktori : /lib/python3.6/site-packages/certbot/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/certbot/__pycache__/util.cpython-36.pyc

3

گa(Y�@sbUdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddlm
Z
ddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZddlZddlZdd
lmZddlmZddlmZddlmZddlmZe
jj d�Z!e!�r4ddl"Z"e�rBddl#Z$ej%e&�Z'ej(dd�Z)ej(dd�Z*dZ+dZ,dZ-ej.j/d{�Z0ej1�Z2iZ3ee4ej5f3ej6dej7�Z8ee4e4fd�dd �Z9e'j:fee4e
e4gdfee4e4fd!�d"d#�Z;e4e<d$�d%d&�Z=e4dd'�d(d)�Z>dd�d*d+�Z?e4e@e<dd,�d-d.�ZAd|e4e@e<dd,�d1d2�ZBd}e4e4ee@ed4�d5d6�ZCe4e
e@ge4fe@e@e4eee4fd7�d8d9�ZDd~e4e@e4eee4fd;�d<d=�ZEde4e4e@e4eee4fd?�d@dA�ZFe4ddB�dCdD�ZGee4ee4dE�dFdG�ZHee4e4fd�dHdI�ZIe4d�dJdK�ZJee4d�dLdM�ZKd�e4e4e4dO�dPdQ�ZLe4e4dR�dSdT�ZMd�e<ee4e4fdU�dVdW�ZNej6dX�ZOe4e<dY�dZd[�ZPGd\d]�d]ejQ�ZRe
d�e4ee4e@fdd_�d`da�ZSe4e4db�dcdd�ZTee4eUfe4db�dedf�ZVe4e<dg�dhdi�ZWee4eUfe<db�djdk�ZXe4dldm�dndo�ZYe4e<dp�dqdr�ZZe
eedds�dtdu�Z[e4eee@e4fdv�dwdx�Z\e
eedds�dydz�Z]dS)�zUtilities for all Certbot.�N)�Any)�Callable)�Dict)�IO)�List)�Optional)�Set)�Tuple)�
TYPE_CHECKING)�Union)�errors)�	constants)�lock)�
filesystem)�os�linux�Keyzfile pem�CSRzfile data formzzz�$The following error was encountered:�{0}�WEither run as root, or set --config-dir, --work-dir, and --logs-dir to writeable paths.z(\d+ | [a-z]+ | \.))�returncs^tjj��d�ksd�kr�Sx:dD]2}|�kr$dj�fdd��|jd�D���|<q$W�S)	a�
    When Certbot is run inside a Snap, certain environment variables
    are modified. But Certbot sometimes calls out to external programs,
    since it uses classic confinement. When we do that, we must modify
    the env to remove our modifications so it will use the system's
    libraries, since they may be incompatible with the versions of
    libraries included in the Snap. For example, apachectl, Nginx, and
    anything run from inside a hook should call this function and pass
    the results into the ``env`` argument of ``subprocess.Popen``.

    :returns: A modified copy of os.environ ready to pass to Popen
    :rtype: dict

    �SNAPZCERTBOT_SNAPPED�PATH�LD_LIBRARY_PATH�:c3s|]}�d|kr|VqdS)rN�)�.0�x)�envr�/usr/lib/python3.6/util.py�	<genexpr>\sz1env_no_snap_for_external_calls.<locals>.<genexpr>)rr)r�environ�copy�join�split)Z	path_namer)rr �env_no_snap_for_external_callsGs

*r&)�params�logrcCs�y tj|dtjtjdt�d�}Wn8ttfk
rXddj|�}||�tj|��YnX|j	dkr�ddj|�|j
|jf}||�tj|��|j
|jfS)z�Run the script with the given params.

    :param list params: List of parameters to pass to subprocess.run
    :param callable log: Logger method to use for errors

    FT)�check�stdout�stderr�universal_newlinesrzUnable to run the command: %s� rzError while running %s.
%s
%s)�
subprocess�run�PIPEr&�OSError�
ValueErrorr$rZSubprocessError�
returncoder*r+)r'r(�proc�msgrrr �
run_script`s"

r6)�exercCsVtjj|�\}}|rtj|�Sx2tjdjtj�D]}tjtjj||��r2dSq2WdS)z�Determine whether path/name refers to an executable.

    :param str exe: Executable path or name

    :returns: If exe is a valid executable
    :rtype: bool

    rTF)r�pathr%rZ
is_executabler"�pathsepr$)r7r8�_rrr �
exe_exists~s	
r;)�dir_pathrcCs&tstt�|tkr"tj|�t|<dS)z�Lock the directory at dir_path until program exit.

    :param str dir_path: path to directory

    :raises errors.LockError: if the lock is held by another process

    N)�_LOCKS�atexit_register�_release_locksrZlock_dir)r<rrr �lock_dir_until_exit�sr@cCsPxBtj�D]6}y|j�Wq
dj|�}tj|dd�Yq
Xq
Wtj�dS)Nz(Exception occurred releasing lock: {0!r}T)�exc_info)r=�values�release�format�logger�debug�clear)Zdir_lockr5rrr r?�s
r?)�	directory�mode�strictrcCs^yt|||�t|�Wn@tk
rX}z$tjddd�tjtj|���WYdd}~XnXdS)ahEnsure directory exists with proper permissions and is locked.

    :param str directory: Path to a directory.
    :param int mode: Directory mode.
    :param bool strict: require directory to be owned by current user

    :raises .errors.LockError: if the directory cannot be locked
    :raises .errors.Error: if the directory cannot be made or verified

    zException was:T)rAN)	�make_or_verify_dirr@r1rErFr�Error�PERM_ERR_FMTrD)rHrIrJ�errorrrr �set_up_core_dir�srO��FcCspytj||�WnZtk
rj}z>|jtjkrX|rZtj||�rZtjd|t|�f��n�WYdd}~XnXdS)a�Make sure directory exists with proper permissions.

    :param str directory: Path to a directory.
    :param int mode: Directory mode.
    :param bool strict: require directory to be owned by current user

    :raises .errors.Error: if a directory already exists,
        but has wrong permissions or owner

    :raises OSError: if invalid or inaccessible file names and
        paths, or other arguments that have the correct type,
        but are not accepted by the operating system.

    zE%s exists, but it should be owned by current user with permissions %sN)	r�makedirsr1�errno�EEXISTZcheck_permissionsrrL�oct)rHrIrJZ	exceptionrrr rK�srK�w)r8rI�chmodrcCsHf}|dk	r|f}f}tj|tjtjBtjBf|��}tj||f|��S)z�Safely open a file.

    :param str path: Path to a file.
    :param str mode: Same os `mode` for `open`.
    :param int chmod: Same as `mode` for `filesystem.open`, uses Python defaults
        if ``None``.

    N)r�openr�O_CREAT�O_EXCL�O_RDWR�fdopen)r8rIrVZ	open_argsZfdopen_args�fdrrr �	safe_open�s	 r])r8�filename_pat�countrVrIrcCspxjtjj|||��}yt|||d�tjj|�fStk
r^}z|jtjkrN�WYdd}~XnX|d7}qWdS)N)rVrI�)rr8r$r]�abspathr1rRrS)r8r^r_rVrIZcurrent_path�errrrr �_unique_file�src�)r8rVrIrcs*tjj|�\}�t|�fdd�d||d�S)z�Safely finds a unique file.

    :param str path: path/filename.ext
    :param int chmod: File mode
    :param str mode: Open mode

    :returns: tuple of file object and file name

    csd|�fS)Nz%04d_%sr)r_)�tailrr �<lambda>szunique_file.<locals>.<lambda>r)r^r_rVrI)rr8r%rc)r8rVrIr)rer �unique_file�s
rg�)r8�filenamerVrIrcsntjj|d��}yt||d�|fStk
rR}z|jtjkrB�WYdd}~XnXt|�fdd�d||d�S)aSafely finds a unique file using lineage convention.

    :param str path: directory path
    :param str filename: proposed filename
    :param int chmod: file mode
    :param str mode: open mode

    :returns: tuple of file object and file name (which may be modified
        from the requested one by appending digits to ensure uniqueness)

    :raises OSError: if writing files fails for an unanticipated reason,
        such as a full disk or a lack of permission to write to
        specified location.

    z%s.conf)rVNcsd�|fS)Nz%s-%04d.confr)r_)rirr rfsz%unique_lineage_name.<locals>.<lambda>r`)r^r_rVrI)rr8r$r]r1rRrSrc)r8rirVrIZpreferred_pathrbr)rir �unique_lineage_namesrj)r8rcCsDytj|�Wn0tk
r>}z|jtjkr.�WYdd}~XnXdS)z!Remove a file that may not exist.N)r�remover1rR�ENOENT)r8rbrrr �
safely_remove"s
rm)�	all_namesrcCsRt�}xF|D]>}y|jt|��Wqtjk
rHtjd|dd�YqXqW|S)z�Removes names that aren't considered valid by Let's Encrypt.

    :param set all_names: all names found in the configuration

    :returns: all found names that are considered valid by LE
    :rtype: set

    zNot suggesting name "%s"T)rA)�set�add�enforce_le_validityr�ConfigurationErrorrErF)rnZfiltered_names�namerrr �get_filtered_names+s	
rtcCs
tdd�S)zc
    Get OS name and version

    :returns: (os_name, os_version)
    :rtype: `tuple` of `str`
    F)�pretty)�get_python_os_inforrrr �get_os_info<srwcCs0trtjdd�}ts|r,djtdd��S|S)z^
    Get OS name and version string for User Agent

    :returns: os_ua
    :rtype: `str`
    T)rur-)�_USE_DISTRO�distrorsr$rv)Zos_inforrr �get_os_info_uaFs
rzcCstrtj�jd�SgS)z�
    Get a list of strings that indicate the distribution likeness to
    other distributions.

    :returns: List of distribution acronyms
    :rtype: `list` of `str`
    r-)rxryZliker%rrrr �get_systemd_os_likeTs	r{�/etc/os-release)�varname�filepathrcCsn|d}tjj|�sdSt|d��}|j�}WdQRXx2|D]*}|j�j|�r<t|j�t|�d��Sq<WdS)z�
    Get single value from a file formatted like systemd /etc/os-release

    :param str varname: Name of variable to fetch
    :param str filepath: File path of os-release file
    :returns: requested value
    :rtype: `str`
    �=��rN)	rr8�isfilerW�	readlines�strip�
startswith�_normalize_string�len)r}r~Z
var_stringZfh�contents�linerrr �get_var_from_fileas

r�)�origrcCs|jdd�jdd�j�S)zV
    Helper function for get_var_from_file() to remove quotes
    and whitespaces
    �"r��')�replacer�)r�rrr r�wsr�)rurcCs.tjtj�tj�tj��}|\}}}|j�}|jd�rjtrj|rFtj	�ntj
�tj�}}|r`|}|rh|}n�|jd�r�y$tjddgtj
tj
ddt�d�}Wn4tk
r�tjddgtj
tj
ddt�d�}YnX|jjd	�}nJ|jd
��r|jd�d}|jd
�d}n tj�d�r"tj�d}nd}||fS)z�
    Get Operating System type/distribution and major version
    using python platform module

    :param bool pretty: If the returned OS name should be in longer (pretty) form

    :returns: (os_name, os_version)
    :rtype: `tuple` of `str`
    r�darwinz/usr/bin/sw_versz-productVersionFT)r*r+r)r,rZsw_vers�
Zfreebsd�-r�.r`r�)�platformZsystem_alias�systemrC�version�lowerr�rxryrs�idr.r/r0r&r1r*�rstrip�	partitionZ	win32_ver)ru�infoZos_typeZos_verr:Zdistro_nameZdistro_versionr4rrr rv~sB



rvz![a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+$)�emailrcCs2tj|�dk	r"|jd�o d|kStjd|�dS)z$Scrub email address before using it.Nr�z..zInvalid email address: %s.F)�EMAIL_REGEX�matchr�rErN)r�rrr �
safe_email�sr�c@s,eZdZdZdeeeeedd�dd�ZdS)�DeprecatedArgumentActionz1Action to log a warning when an argument is used.N)�unused1�unused2�unused3�
option_stringrcCstjd|t�dS)NzUse of %s is deprecated.)�warnings�warn�DeprecationWarning)�selfr�r�r�r�rrr �__call__�sz!DeprecatedArgumentAction.__call__)N)�__name__�
__module__�__qualname__�__doc__rr�strr�rrrr r��sr�.)�add_argument�
argument_name�nargsrcCsJttjkr4ttjt�r$tjjt�ntjtf7_||ttj|d�dS)a�Adds a deprecated argument with the name argument_name.

    Deprecated arguments are not shown in the help. If they are used on
    the command line, a warning is shown stating that the argument is
    deprecated and no other action is taken.

    :param callable add_argument: Function that adds arguments to an
        argument parser/group.
    :param str argument_name: Name of deprecated argument.
    :param nargs: Value for nargs when adding the argument to argparse.

    )�action�helpr�N)r��configargparseZ#ACTION_TYPES_THAT_DONT_NEED_A_VALUE�
isinstancerorp�argparseZSUPPRESS)r�r�r�rrr �add_deprecated_argument�s

r�)�domainrcCs�t|�}tjd|�s$tjdj|���|jd�}t|�dkrJtjdj|���xD|D]<}|jd�rptjdj||���|j	d�rPtjdj||���qPW|S)	ahChecks that Let's Encrypt will consider domain to be valid.

    :param str domain: FQDN to check
    :type domain: `str`
    :returns: The domain cast to `str`, with ASCII-only contents
    :rtype: str
    :raises ConfigurationError: for invalid domains and cases where Let's
                                Encrypt currently will not issue certificates

    z^[A-Za-z0-9.-]*$zP{0} contains an invalid character. Valid characters are A-Z, a-z, 0-9, ., and -.r��z{0} needs at least two labelsr�z1label "{0}" in domain "{1}" cannot start with "-"z/label "{0}" in domain "{1}" cannot end with "-")
�enforce_domain_sanity�rer�rrrrDr%r�r��endswith)r��labelsZlabelrrr rq�s&




rqc
Cs"y"t|t�r|jd�}|jd�Wntk
r@tjd��YnX|j�}|jd�r`|dd�n|}x.dD]&}|j	d	j
|��rjtjd
j
||���qjWt|�r�tjdj
|���dj
|�}t|�d
kr�tjdj
|���|j
d�}x@|D]8}|�s�tjdj
|���t|�dkr�tjdj
||���q�W|S)a�Method which validates domain value and errors out if
    the requirements are not met.

    :param domain: Domain to check
    :type domain: `str` or `bytes`
    :raises ConfigurationError: for invalid domains and cases where Let's
                                Encrypt currently will not issue certificates

    :returns: The domain cast to `str`, with ASCII-only contents
    :rtype: str
    zutf-8�asciizbNon-ASCII domain names not supported. To issue for an Internationalized Domain Name, use Punycode.r�Nr`�http�httpsz{0}://z[Requested name {0} appears to be a URL, not a FQDN. Try again without the leading "{1}://".zRequested name {0} is an IP address. The Let's Encrypt certificate authority will not issue certificates for a bare IP address.z*Requested domain {0} is not a FQDN because�z{0} it is too long.z{0} it contains an empty label.�?z{0} label {1} is too long.���)r�r�)r��bytes�decode�encode�UnicodeErrorrrrr�r�r�rD�is_ipaddressr�r%)r��schemer5r��lrrr r�s6






r�)�addressrcCsXytjtj|�dStjk
rRytjtj|�dStjk
rLdSXYnXdS)z�Is given address string form of IP(v4 or v6) address?

    :param address: address to check
    :type address: `str`

    :returns: True if address is valid IP address, otherwise return False.
    :rtype: bool

    TFN)�socketZ	inet_ptonZAF_INETrNZAF_INET6)r�rrr r�@s
r�cCst|t�r|jd�S|jd�S)z�"Is domain a wildcard domain?

    :param domain: domain to check
    :type domain: `bytes` or `str`

    :returns: True if domain is a wildcard, otherwise, False
    :rtype: bool

    z*.s*.)r�r�r�)r�rrr �is_wildcard_domainWs


r�zdistutils.version.StrictVersion)�
normalizedrcCsHtjdt�tj��*tjdt�ddl}|jj|jdd��SQRXdS)z�Converts a normalized version to a strict version.

    :param str normalized: normalized version string

    :returns: An equivalent strict version
    :rtype: distutils.version.StrictVersion

    zVcertbot.util.get_strict_version is deprecated and will be removed in a future release.�ignorerNz.dev�a)	r�r�r��catch_warnings�simplefilter�distutils.versionr�Z
StrictVersionr�)r��	distutilsrrr �get_strict_versionfs	
r�)�srvrcCs|tjkpd|kS)z�
    Determine whether a given ACME server is a known test / staging server.

    :param str srv: the URI for the ACME server
    :returns: True iff srv is a known test / staging server
    :rtype bool:
    Zstaging)r
ZSTAGING_URI)r�rrr �
is_stagingxsr�)�func�args�kwargsrcOstjt|f|�|�dS)aSets func to be called before the program exits.

    Special care is taken to ensure func is only called when the process
    that first imports this module exits rather than any child processes.

    :param function func: function to be called in case of an error

    N)�atexit�register�_atexit_call)r�r�r�rrr r>�s	r>)�version_stringrcCsTdd�tj|�D�}x:t|�D].\}}yt|�||<Wqtk
rJYqXqW|S)aParses a version string into its components.

    This code and the returned tuple is based on the now deprecated
    distutils.version.LooseVersion class from the Python standard library.
    Two LooseVersion classes and two lists as returned by this function should
    compare in the same way. See
    https://github.com/python/cpython/blob/v3.10.0/Lib/distutils/version.py#L205-L347.

    :param str version_string: version string

    :returns: list of parsed version string components
    :rtype: list

    cSsg|]}|r|dkr|�qS)r�r)rrrrr �
<listcomp>�sz'parse_loose_version.<locals>.<listcomp>)�_VERSION_COMPONENT_REr%�	enumerate�intr2)r�Z
components�i�objrrr �parse_loose_version�s
r�cOsttj�kr|||�dS)N)�_INITIAL_PIDr�getpid)r�r�r�rrr r��sr�)rrr)rPF)rUN)rdrU)rhrU)r|)F).N)^r�r�r��collectionsrRZloggingr�r�r�r.�sysZtypingrrrrrrrr	r
rr�r�ZcertbotrZcertbot._internalr
rZcertbot.compatrrr�rxryr�r�Z	getLoggerr�rE�
namedtuplerrZ
ANSI_SGR_BOLDZANSI_SGR_REDZANSI_SGR_RESET�linesepr$rMr�r�r=r�ZLockFile�compile�VERBOSEr�r&rNr6�boolr;r@r?r�rOrKr]rcrgrjrmrtrwrzr{r�r�rvr�r�ZActionr�r�rqr�r�r�r�r�r�r>r�r�rrrr �<module>s�
.
 	

8
";

Zerion Mini Shell 1.0