Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/site-packages/paramiko/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/site-packages/paramiko/__pycache__/config.cpython-38.pyc
U

P��g�j�
@s�dZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZd\Z
Zzddl
Z
Wn&ek
r�ZzeZW5dZ[XYnXddlmZmZd	ZGd
d�d�Zdd
�ZGdd�d�ZGdd�de�ZdS)z2
Configuration file (aka ``ssh_config``) support.
�N)�sha1)�StringIO)�partial)NN�)�CouldNotCanonicalize�ConfigParseError�c@seZdZdZe�d�Zddddddd	d
gdgdddddd
d	gdddd	gddd	gdddddddd	d
g	d
�Zdd�Ze	dd��Z
e	dd��Ze	dd��Zdd�Z
dd�Zd2dd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�ZdS)3�	SSHConfiga�
    Representation of config information as stored in the format used by
    OpenSSH. Queries can be made via `lookup`. The format is described in
    OpenSSH's ``ssh_config`` man page. This class is provided primarily as a
    convenience to posix users (since the OpenSSH format is a de-facto
    standard on posix) but should work fine on Windows too.

    .. versionadded:: 1.6
    z(\w+)(?:\s*=\s*|\s+)(.+)�%C�%h�%l�%L�%n�%p�%r�%u�~�%d)Zcontrolpath�hostname�identityfile�proxycommandZ	proxyjump�
match-execcCs
g|_dS)a�
        Create a new OpenSSH config object.

        Note: the newer alternate constructors `from_path`, `from_file` and
        `from_text` are simpler to use, as they parse on instantiation. For
        example, instead of::

            config = SSHConfig()
            config.parse(open("some-path.config")

        you could::

            config = SSHConfig.from_file(open("some-path.config"))
            # Or more directly:
            config = SSHConfig.from_path("some-path.config")
            # Or if you have arbitrary ssh_config text from some other source:
            config = SSHConfig.from_text("Host foo\n\tUser bar")
        N)�_config)�self�r�</opt/cppython/lib/python3.8/site-packages/paramiko/config.py�__init__HszSSHConfig.__init__cCs|�t|��S)zg
        Create a new, parsed `SSHConfig` from ``text`` string.

        .. versionadded:: 2.7
        )�	from_filer)�cls�textrrr�	from_text]szSSHConfig.from_textc
Cs*t|��}|�|�W5QR�SQRXdS)zr
        Create a new, parsed `SSHConfig` from the file found at ``path``.

        .. versionadded:: 2.7
        N)�openr)r�path�florrr�	from_pathfs
zSSHConfig.from_pathcCs|�}|�|�|S)zp
        Create a new, parsed `SSHConfig` from file-like object ``flo``.

        .. versionadded:: 2.7
        )�parse)rr#�objrrrrps
zSSHConfig.from_filecCsRdgid�}|D�].}|��}|r|�d�r.qt�|j|�}|sNtd�|���|�d���}|�d�}|dkr�|j	�
|�dii}|d	kr�|�|�|d	<n|�|�|d
<q|dkr�|��dkr�d
|d|<q|�d�r�|�
d�r�|dd�}|dk�r(||dk�r|d|�
|�n|g|d|<q||dkr||d|<q|j	�
|�d
S)z�
        Read an OpenSSH config from the given file object.

        :param file_obj: a file-like object to read the config file from
        �*)�host�config�#zUnparsable line {}r�)r(�matchr)r(�matchesr�noneN�"���)rZlocalforwardZ
remoteforward)�strip�
startswith�rer,�SETTINGS_REGEXr�format�group�lowerr�append�
_get_hosts�_get_matches�endswith)rZfile_obj�context�liner,�key�valuerrrr%{s6


zSSHConfig.parsecCs�|j|d�}d|kr||d<|�dd�dk}t|�dd��}|r�|�d�|kr�|d	��}|�|||�}||d<|j||d
d
d�}n|j||dd
d�}|S)
a

        Return a dict (`SSHConfigDict`) of config options for a given hostname.

        The host-matching rules of OpenSSH's ``ssh_config`` man page are used:
        For each parameter, the first obtained value will be used.  The
        configuration files contain sections separated by ``Host`` and/or
        ``Match`` specifications, and that section is only applied for hosts
        which match the given patterns or keywords

        Since the first obtained value for each parameter is used, more host-
        specific declarations should be given near the beginning of the file,
        and general defaults at the end.

        The keys in the returned dict are all normalized to lowercase (look for
        ``"port"``, not ``"Port"``. The values are processed according to the
        rules for substitution variable expansion in ``ssh_config``.

        Finally, please see the docs for `SSHConfigDict` for deeper info on
        features such as optional type conversion methods, e.g.::

            conf = my_config.lookup('myhost')
            assert conf['passwordauthentication'] == 'yes'
            assert conf.as_bool('passwordauthentication') is True

        .. note::
            If there is no explicitly configured ``HostName`` value, it will be
            set to the being-looked-up hostname, which is as close as we can
            get to OpenSSH's behavior around that particular option.

        :param str hostname: the hostname to lookup

        .. versionchanged:: 2.5
            Returns `SSHConfigDict` objects instead of dict literals.
        .. versionchanged:: 2.7
            Added canonicalization support.
        .. versionchanged:: 2.7
            Added ``Match`` support.
        .. versionchanged:: 3.3
            Added ``Match final`` support.
        )rrZcanonicalizehostnameN)�yes�alwaysZcanonicalizemaxdotsr�.ZcanonicaldomainsT)�	canonical�finalF)�_lookup�get�int�count�split�canonicalize)rr�optionsZcanonZmaxdots�domainsrrr�lookup�s,*��zSSHConfig.lookupNFcs��dkrt��|jD]�}|�|�dg�|�sH|�|�dg�|||��sHq|d��D]T\�}��kr�|dk	rx|dd�n|��<qT�dkrT�����fdd�|D��qTq|r�|��|���S)Nr(r-r)rc3s|]}|��kr|VqdS�Nr��.0�x�r>rKrr�	<genexpr>sz$SSHConfig._lookup.<locals>.<genexpr>)�
SSHConfigDictr�_pattern_matchesrF�_does_match�items�extend�_expand_variables)rrrKrCrDr<r?rrRrrE�s0
�
��
�zSSHConfig._lookupc	Cs�d}|D]^}d�||�}t||�}|dk	r4|d}n&zt�|�}Wntjk
rXYnX|r|Sq|�dd�dkr||St|��dS)ag
        Return canonicalized version of ``hostname``.

        :param str hostname: Target hostname.
        :param options: An `SSHConfigDict` from a previous lookup pass.
        :param domains: List of domains (e.g. ``["paramiko.org"]``).

        :returns: A canonicalized hostname if one was found, else ``None``.

        .. versionadded:: 2.7
        Fz{}.{}NrZcanonicalizefallbacklocalr@)r5�_addressfamily_host_lookup�socket�
gethostbyname�gaierrorrFr)rrrKrL�found�domain�	candidateZfamily_specificrrrrJs


zSSHConfig.canonicalizecCs$t�}|jD]}|�|d�q|S)z�
        Return the set of literal hostnames defined in the SSH config (both
        explicit hostnames and wildcard entries).
        r()�setr�update)r�hosts�entryrrr�
get_hostnamesEs
zSSHConfig.get_hostnamescCsZt|d�r|�d�}d}|D]8}|�d�rDt�||dd��rDdSt�||�rd}q|S)NrI�,F�!rT)�hasattrrIr2�fnmatch)r�patterns�targetr,�patternrrrrUOs


�zSSHConfig._pattern_matchescCsVg}|dd�}t��}|�rR|�d�}	d}
|�dd�}|�dd�}|	d|	d}
}|
dkrn|�||	�rndS|
dkr||}
n�|
d	kr�d
S|
dkr�|p�|}|�||�}
n�|
dkr�|�||�}
nn|
dkr�|p�|}|�||�}
nP|
d
kr�|�||�}
n:|
dk�r*|�||d|�}tdk�rt�tj	|dd
d�j
}
|
dk	�rF|�|
|	��rFdS|�|	�q|S)Nrr�user�type�paramrCFrD�allTr(ZoriginalhostZ	localuser�execr�stdout)Zhide�warn)�getpass�getuser�poprF�_should_failrU�	_tokenize�invoke�invoke_import_error�run�okr8)rZ
match_list�target_hostnamerCrDrKZmatched�
candidatesZlocal_usernamer`ZpassedZconfigured_hostZconfigured_user�type_roZhostvalrmZexec_cmdrrrrV`sP

�
zSSHConfig._does_matchcCs|dr|S|S)N�negater)rZ
would_passr`rrrrw�szSSHConfig._should_failcCs�|�|�}|s|S|}|dkr*|�d|�}d|kr<|d}nt}t��}d|krZ|d}	n|}	t���d�d}
t||
�}t	j
�d�}|
|t|�|	}
t
|
�����|||
||||	||d�
}|}|��D]"\}}||kr�q�|�|t|��}q�|S)a�
        Tokenize a string based on current config/hostname data.

        :param config: Current config data.
        :param target_hostname: Original target connection hostname.
        :param key: Config key being tokenized (used to filter token list).
        :param value: Config value being tokenized.

        :returns: The tokenized version of the input ``value`` string.
        r�portrmrBrr)
r
rrr
rrrrrr)�_allowed_tokensrF�SSH_PORTrtrur[�gethostnamerI�LazyFqdn�osr"�
expanduser�reprr�encode�	hexdigestrW�replace�str)rr)r}r>r?Zallowed_tokensZconfigured_hostnamer�rmZ
remoteuserZlocal_hostnameZ
local_fqdn�homedirZtohashZreplacementsZ	tokenized�findr�rrrrx�sD



�zSSHConfig._tokenizecCs|j�|g�S)aJ
        Given config ``key``, return list of token strings to tokenize.

        .. note::
            This feels like it wants to eventually go away, but is used to
            preserve as-strict-as-possible compatibility with OpenSSH, which
            for whatever reason only applies some tokens to some config keys.
        )�TOKENS_BY_CONFIG_KEYrF�rr>rrrr��s	zSSHConfig._allowed_tokenscCsr|D]h}||dkrqt|j|||�}t||t�r\t||�D]\}}||�|||<q@q|||�||<q|S)aA
        Return a dict of config options with expanded substitutions
        for a given original & current target hostname.

        Please refer to :doc:`/api/config` for details.

        :param dict config: the currently parsed config
        :param str hostname: the hostname whose config is being looked up
        N)rrx�
isinstance�list�	enumerate)rr)r}�k�	tokenizer�ir?rrrrY�s
zSSHConfig._expand_variablescCs4zt�|�WStk
r.td�|���YnXdS)z>
        Return a list of host_names from host value.
        zUnparsable host {}N)�shlexrI�
ValueErrorrr5)rr(rrrr9�szSSHConfig._get_hostsc	s$g}t�|�}|r�dddd�}|�d�}|�d�rFd|d<|dd�}||d	<|d
krb|�|�q|sttd�|���|�d�|d<|�|�qd
d�|D�}d|k�r d�tt�fdd�|��tt�fdd�|��}}d}t	|�r�d}n$d|k�r|�
d�|�
d�k�rd}|dk	�r t|��|S)z�
        Parse a specific Match config line into a list-of-dicts for its values.

        Performs some parse-time validation as well.
        NF)rnror�rrgTr�rrn)rprCrDz'Missing parameter to Match '{}' keywordrocSsg|]}|d�qS)rnrrOrrr�
<listcomp>sz*SSHConfig._get_matches.<locals>.<listcomp>rp)rprCcs|�kSrNr�rQ�Z	allowablerr�<lambda>"�z(SSHConfig._get_matches.<locals>.<lambda>cs|�kSrNrr�r�rrr�#r�z>Match does not allow 'all' mixed with anything but 'canonical'rCz-Match does not allow 'all' before 'canonical')r�rIrvr2r8rr5r��filter�any�index)	rr,r-�tokensr�keywordsr|�bad�errrr�rr:s@



�
� 
zSSHConfig._get_matches)NFF)�__name__�
__module__�__qualname__�__doc__r3�compiler4r�r�classmethodr r$rr%rMrErJrerUrVrwrxr�rYr9r:rrrrr	.s:


�

	

<B
#)
8>	r	cCsh|�dd���}|dkrdSz0tj}|dkr2tj}t�|d|tjtjtj�WStj	k
rbYnXdS)a
    Try looking up ``hostname`` in an IPv4 or IPv6 specific manner.

    This is an odd duck due to needing use in two divergent use cases. It looks
    up ``AddressFamily`` in ``options`` and if it is ``inet`` or ``inet6``,
    this function uses `socket.getaddrinfo` to perform a family-specific
    lookup, returning the result if successful.

    In any other situation -- lookup failure, or ``AddressFamily`` being
    unspecified or ``any`` -- ``None`` is returned instead and the caller is
    expected to do something situation-appropriate like calling
    `socket.gethostbyname`.

    :param str hostname: Hostname to look up.
    :param options: `SSHConfigDict` instance w/ parsed options.
    :returns: ``getaddrinfo``-style tuples, or ``None``, depending.
    Z
addressfamilyr�NZinet)
rFr7r[�AF_INET6�AF_INET�getaddrinfo�
SOCK_DGRAM�
IPPROTO_IP�AI_CANONNAMEr])rrK�address_family�familyrrrrZ/s"�rZc@s"eZdZdZddd�Zdd�ZdS)r�z7
    Returns the host's fqdn on request as string.
    NcCsd|_||_||_dSrN)�fqdnr)r()rr)r(rrrrYszLazyFqdn.__init__c	Csl|jdkrfd}t|j|j�}|dk	rP|D]&}|\}}}}}|r(d|kr(|}qPq(|dkr`t��}||_|jS)NrB)r�rZr(r)r[�getfqdn)	rr��results�res�af�socktype�proto�	canonname�sarrr�__str__^s
zLazyFqdn.__str__)N)r�r�r�r�rr�rrrrr�Ts
r�c@s eZdZdZdd�Zdd�ZdS)rTa�
    A dictionary wrapper/subclass for per-host configuration structures.

    This class introduces some usage niceties for consumers of `SSHConfig`,
    specifically around the issue of variable type conversions: normal value
    access yields strings, but there are now methods such as `as_bool` and
    `as_int` that yield casted values instead.

    For example, given the following ``ssh_config`` file snippet::

        Host foo.example.com
            PasswordAuthentication no
            Compression yes
            ServerAliveInterval 60

    the following code highlights how you can access the raw strings as well as
    usefully Python type-casted versions (recalling that keys are all
    normalized to lowercase first)::

        my_config = SSHConfig()
        my_config.parse(open('~/.ssh/config'))
        conf = my_config.lookup('foo.example.com')

        assert conf['passwordauthentication'] == 'no'
        assert conf.as_bool('passwordauthentication') is False
        assert conf['compression'] == 'yes'
        assert conf.as_bool('compression') is True
        assert conf['serveraliveinterval'] == '60'
        assert conf.as_int('serveraliveinterval') == 60

    .. versionadded:: 2.5
    cCs"||}t|t�r|S|��dkS)a�
        Express given key's value as a boolean type.

        Typically, this is used for ``ssh_config``'s pseudo-boolean values
        which are either ``"yes"`` or ``"no"``. In such cases, ``"yes"`` yields
        ``True`` and any other value becomes ``False``.

        .. note::
            If (for whatever reason) the stored value is already boolean in
            nature, it's simply returned.

        .. versionadded:: 2.5
        r@)r��boolr7)rr>�valrrr�as_bool�s
zSSHConfigDict.as_boolcCst||�S)z�
        Express given key's value as an integer, if possible.

        This method will raise ``ValueError`` or similar if the value is not
        int-appropriate, same as the builtin `int` type.

        .. versionadded:: 2.5
        )rGr�rrr�as_int�s	zSSHConfigDict.as_intN)r�r�r�r�r�r�rrrrrTzs!rT)r�rirtr�r3r�r[�hashlibr�ior�	functoolsrryrz�ImportError�eZ
ssh_exceptionrrr�r	rZr��dictrTrrrr�<module>s0%&

F1le Man4ger