%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/paramiko/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/paramiko/__pycache__/config.cpython-312.pyc

�

�ecfk����dZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZd\Z
Z	ddl
Z
ddlmZmZd	ZGd
�de�Zd�ZGd
�de�ZGd�de�Zy#e$rZeZYdZ[�;dZ[wwxYw)z2
Configuration file (aka ``ssh_config``) support.
�N)�sha1)�partial�)�StringIO)NN)�CouldNotCanonicalize�ConfigParseError�c���eZdZdZej
d�Zgd�dggd�gd�gd�gd�d	�Zd
�Ze	d��Z
e	d��Ze	d
��Zd�Z
d�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�	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�%ur
)r�~�%dr
rrr)rr
rr)r
rr)	rrr
rrrrrr)�controlpath�hostname�identityfile�proxycommand�	proxyjump�
match-execc��g|_y)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)�selfs �1/usr/lib/python3/dist-packages/paramiko/config.py�__init__zSSHConfig.__init__Is��&���c�6�|jt|��S)zg
        Create a new, parsed `SSHConfig` from ``text`` string.

        .. versionadded:: 2.7
        )�	from_filer)�cls�texts  r�	from_textzSSHConfig.from_text^s���}�}�X�d�^�,�,r!c�f�t|�5}|j|�cddd�S#1swYyxYw)zr
        Create a new, parsed `SSHConfig` from the file found at ``path``.

        .. versionadded:: 2.7
        N)�openr#)r$�path�flos   r�	from_pathzSSHConfig.from_pathgs.���$�Z�	&�3��=�=��%�	&�	&�	&�s�'�0c�6�|�}|j|�|S)zp
        Create a new, parsed `SSHConfig` from file-like object ``flo``.

        .. versionadded:: 2.7
        )�parse)r$r*�objs   rr#zSSHConfig.from_fileqs���e���	�	�#���
r!c�.�dgid�}|D�]n}|j�}|r|jd�r�(tj|j|�}|stdj
|���|jd�j�}|jd�}|dvrN|jj|�dii}|d	k(r|j|�|d	<��|j|�|d
<��|dk(r|j�dk(r
d
|d|<��|jd�r|jd�r|dd}|dvr+||dvr|d|j|���S|g|d|<��^||dvs��g||d|<��q|jj|�y
)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�)r1�matchr2r1�matchesr�noneN�"���)r�localforward�
remoteforward)�strip�
startswith�rer5�SETTINGS_REGEXr�format�group�lowerr�append�
_get_hosts�_get_matches�endswith)r�file_obj�context�liner5�key�values       rr-zSSHConfig.parse|s��� �5�B�/���0	3�D��:�:�<�D��4�?�?�3�/���H�H�T�0�0�$�7�E��&�';�'B�'B�4�'H�I�I��+�+�a�.�&�&�(�C��K�K��N�E��'�'����#�#�G�,�#�R�.���&�=�'+�o�o�e�&<�G�F�O�)-�):�):�5�)A�G�I�&���&�5�;�;�=�F�+B�*.���!�#�&��#�#�C�(�U�^�^�C�-@�!�!�B�K�E�
�K�K��g�h�/�/���)�#�.�5�5�e�<�27����)�#�.���� 1�1�-2�G�H�%�c�*�a0	3�d	
�����G�$r!c�D�|j|��}d|vr||d<|jdd�dv}t|jdd��}|rS|jd�|kr?|d	j	�}|j|||�}||d<|j||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.
        )rr�canonicalizehostnameN)�yes�always�canonicalizemaxdotsr�.�canonicaldomainsT)�	canonical)�_lookup�get�int�count�split�canonicalize)rr�options�canon�maxdots�domainss      r�lookupzSSHConfig.lookup�s���P�,�,��,�1���W�$�"*�G�J�����2�D�9�=N�N���g�k�k�"7��;�<���X�^�^�C�(�G�3��0�1�7�7�9�G��(�(��7�G�D�H�"*�G�J���l�l�8�W��l�E�G��r!Nc������
t��|jD]�}|j|jdg�|�s%|j	|jdg�||��s�J|dj�D]:\�}��vr
|�|ddn|��<��dk(s���j
��fd�|D���<��|j�|��d�vr�d��d=�S)Nr1r6r2rc3�2�K�|]}|��vs�|���y�w�N�)�.0�xrJrZs  ��r�	<genexpr>z$SSHConfig._lookup.<locals>.<genexpr>	s!�����(��A�W�S�\�,A��(�s��r)�
SSHConfigDictr�_pattern_matchesrU�_does_match�items�extend�_expand_variables)rrrZrSrHrKrJs  `   @rrTzSSHConfig._lookup�s�����?�#�o�G��|�|�	�G��%�%�g�k�k�&�"�&=�x�H��#�#��K�K�	�2�.��)�W���%�h�/�5�5�7�

�
��U��g�%�
05�/@�5��8�e�G�C�L��N�*��C�L�'�'�(�#(�(��

�	�*�(�(��(�;���W�$���)@�)H���'��r!c��d}|D]D}dj||�}t||�}|�|d}n	tj|�}|s�B|cS|jdd�dk(r|St
|��#tj$rY�?wxYw)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{}.{}r�canonicalizefallbacklocalrN)r@�_addressfamily_host_lookup�socket�
gethostbyname�gaierrorrUr)rrrZr]�found�domain�	candidate�family_specifics        rrYzSSHConfig.canonicalizes������	!�F����x��8�I�8��G�L�O��*�(��*���"�0�0��;�E��!� �%	!�,�;�;�2�E�:�e�C��O�#�8�,�,��������s�A.�.B�Bc�d�t�}|jD]}|j|d��|S)z�
        Return the set of literal hostnames defined in the SSH config (both
        explicit hostnames and wildcard entries).
        r1)�setr�update)r�hosts�entrys   r�
get_hostnameszSSHConfig.get_hostnames=s3��
����\�\�	(�E��L�L��v��'�	(��r!c���t|d�r|jd�}d}|D]G}|jd�rtj||dd�rytj||�s�Fd}�I|S)NrX�,F�!rT)�hasattrrXr=�fnmatch)r�patterns�targetr5�patterns     rrgzSSHConfig._pattern_matchesGss���8�W�%��~�~�c�*�H����		�G��!�!�#�&�7�?�?������,�������1���		��r!c�&�|j||�Sra)rg)rryrs   r�_allowedzSSHConfig._allowedYs���$�$�U�H�5�5r!c��g}|dd}tj�}|�r<|jd�}d}	|jdd�}
|jdd�}|d|d}
}|dk(r|j	||�r�y|dk(ry	|d
k(r|
xs|}|j|
|�}	n�|dk(r|j|
|�}	n}|dk(r|xs|}|j|
|�}	n_|dk(r|j|
|�}	nG|d
k(rB|j
||d|
�}t�t�tj|dd	��j}	|	�|j	|	|�ry|j|�|r��<|S)Nrr�user�type�paramrSF�allTr1�originalhost�	localuser�execr�stdout)�hide�warn)�getpass�getuser�poprU�_should_failrg�	_tokenize�invoke�invoke_import_error�run�okrC)r�
match_list�target_hostnamerSrZ�matched�
candidates�local_usernamert�passed�configured_host�configured_user�type_r��hostvalr��exec_cmds                 rrhzSSHConfig._does_match\s�������]�
� ���*���"���q�)�I��F�&�k�k�*�d�;�O�%�k�k�&�$�7�O�$�V�,�i��.@�5�E���#��$�$�Y�	�:� ��%����&��)�<�_���.�.�u�g�>���.�(��.�.�u�o�F���&��&�8�.���.�.�u�d�;���+�%��.�.�u�n�E���&���>�>��_�l�E���
�>�-�-����H�8�$�G�J�J���!�d�&7�&7��	�&J���N�N�9�%�Y�\�r!c��|dr|S|S)N�negaterb)r�
would_passrts   rr�zSSHConfig._should_fail�s��&�x�0�z�D�*�n�Dr!c�d�|j|�}|s|S|}|dk7r|jd|�}d|vr|d}nt}tj�}d|vr|d}	n|}	tj�jd�d}
t||
�}tjjd�}|
|zt|�z|	z}
t|
j��j�|||
||||	||d�
}|}|j!�D]%\}}||vr�|j#|t%|��}�'|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�portr�rQrr)
rrr
rrrrrrr)�_allowed_tokensrU�SSH_PORTr�r�ro�gethostnamerX�LazyFqdn�osr)�
expanduser�reprr�encode�	hexdigestri�replace�str)rr2r�rJrK�allowed_tokens�configured_hostnamer�r��
remoteuser�local_hostname�
local_fqdn�homedir�tohash�replacements�	tokenized�findr�s                  rr�zSSHConfig._tokenize�sU���-�-�c�2����L�.���*��"(�*�*�Z�9L�"M���V���&�>�D��D���� ���V�����J��J��+�+�-�3�3�C�8��;���f�n�5�
��'�'�$�$�S�)���/�1�D��J�>��K���v�}�}��'�1�1�3��%� ��"�����
��$�	�)�/�/�1�	>�M�D�'��>�)��!�)�)�$��G��=�I�	>�
�r!c�:�|jj|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_KEYrU�rrJs  rr�zSSHConfig._allowed_tokens�s���(�(�,�,�S�"�5�5r!c���|D]f}||��	t|j|||�}t||t�r%t	||�D]\}}||�|||<��Y|||�||<�h|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
        )rr��
isinstance�list�	enumerate)rr2r��k�	tokenizer�irKs       rrkzSSHConfig._expand_variables�s����	1�A��a�y� ���������K�I��&��)�T�*� )�&��)� 4�4�H�A�u�#,�U�#3�F�1�I�a�L�4�&�f�Q�i�0��q�	�	1��
r!c�|�	tj|�S#t$rtdj	|���wxYw)z>
        Return a list of host_names from host value.
        zUnparsable host {})�shlexrX�
ValueErrorrr@)rr1s  rrDzSSHConfig._get_hosts�s?��	F��;�;�t�$�$���	F�"�#7�#>�#>�t�#D�E�E�	F�s��$;c��
�g}tj|�}|r�dddd�}|jd�}|jd�r
d|d<|dd}||d	<|d
vr|j	|��O|stdj
|���|jd�|d<|j	|�|r��|D�cgc]}|d	��	}}d
|vrxd
�
tt�
fd�|��tt�
fd�|��}}d}	t|�rd}	n)d|vr%|jd�|jd
�kDrd}	|	�t|	��|Scc}w)z�
        Parse a specific Match config line into a list-of-dicts for its values.

        Performs some parse-time validation as well.
        NF)r�r�r�rr~Tr�rr�)r�rSz'Missing parameter to Match '{}' keywordr�r�c���|�vSrarb�rd�	allowables �r�<lambda>z(SSHConfig._get_matches.<locals>.<lambda>s���a�9�n�r!c���|�vSrarbr�s �rr�z(SSHConfig._get_matches.<locals>.<lambda>s���a�y�&8�r!z>Match does not allow 'all' mixed with anything but 'canonical'rSz-Match does not allow 'all' before 'canonical')r�rXr�r=rCrr@r��filter�any�index)rr5r6�tokensr�rd�keywordsr��bad�errr�s          @rrEzSSHConfig._get_matches�sX��������U�#���!�D�E�B�E��J�J�q�M�E�����$�"&��h���a�b�	��!�E�&�M��,�,����u�%���&�=�D�D�U�K���$�Z�Z��]�E�'�N��N�N�5�!�#�((/�/�!�A�f�I�/��/��H��,�I��V�4�h�?�@��V�8�(�C�D��B��C��3�x�V����"�r�x�x��'<�r�x�x���'N�E����&�s�+�+����0s�0D<)NF)�__name__�
__module__�__qualname__�__doc__r>�compiler?r�r �classmethodr&r+r#r-r^rTrYr{rgr�rhr�r�r�rkrDrErbr!rrr/s���� �R�Z�Z� ;�<�N�
H��F�A�/�'�M�	���*�-��-��&��&�����;%�z8�t�B'-�R��$6�2�hE�<�|	6��*F�*r!rc�T�|jdd�j�}|dk(ry	tj}|dk(rtj}tj
|d|tjtjtj�S#tj$rYywxYw)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.
    �
addressfamilyr�N�inet)
rUrBro�AF_INET6�AF_INET�getaddrinfo�
SOCK_DGRAM�
IPPROTO_IP�AI_CANONNAMErq)rrZ�address_family�familys    rrnrn's���$�[�[��%�8�>�>�@�N�����

������V�#��^�^�F��!�!�������������

�	
���?�?�
��
�s�A(B�B'�&B'c��eZdZdZdd�Zd�Zy)r�z7
    Returns the host's fqdn on request as string.
    Nc�.�d|_||_||_yra)�fqdnr2r1)rr2r1s   rr zLazyFqdn.__init__Qs����	������	r!c���|j�[d}t|j|j�}|�|D]}|\}}}}}|s�d|vs�|}n|�t	j
�}||_|jS)NrQ)r�rnr1r2ro�getfqdn)	rr��results�res�af�socktype�proto�	canonname�sas	         r�__str__zLazyFqdn.__str__Vs����9�9���D�0����D�K�K�H�G��"�"��C�9<�6�B��%��B� �S�I�%5�(���	��|��~�~�'���D�I��y�y�r!ra)r�r�r�r�r r�rbr!rr�r�Ls����
r!r�c�.��eZdZdZ�fd�Zd�Zd�Z�xZS)rfa�
    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
    c�,��tt|�
|i|��yra)�superrfr )r�args�kwargs�	__class__s   �rr zSSHConfigDict.__init__�s���
�m�T�+�T�<�V�<r!c�V�||}t|t�r|S|j�dk(S)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
        rN)r��boolrB)rrJ�vals   r�as_boolzSSHConfigDict.as_bool�s-���3�i���c�4� ��J��y�y�{�e�#�#r!c��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
        )rVr�s  r�as_intzSSHConfigDict.as_int�s���4��9�~�r!)r�r�r�r�r rr�
__classcell__)r�s@rrfrfrs����B=�$�&	r!rf)r�r�r�r�r>r�ro�hashlibr�	functoolsr�	py3compatrr�r��ImportError�e�
ssh_exceptionrrr��objectrrnr��dictrfrbr!r�<module>rs���(���	�	��
����(������B���u��u�p"
�J#�v�#�LB�D�B��Y������s�A&�&A7�+A2�2A7

Zerion Mini Shell 1.0