Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/paramiko/__pycache__/hostkeys.cpython-39.pyc
Ðазад
a s�h�3 � @ s� d dl mZmZ d dlZd dlZd dlZd dlmZ d dlm Z d dl mZ d dlm Z mZ d dlmZmZmZmZ d dlmZ G d d � d e�ZG dd� de�ZG d d� d�ZdS )� )�encodebytes�decodebytesN)�MutableMapping)�sha1)�HMAC)�PKey�UnknownKeyType)� get_logger�constant_time_bytes_eq�b�u)�SSHExceptionc @ s� e Zd ZdZd#dd�Zdd� Zdd� Zd d � Zdd� Zd d� Z dd� Z dd� Zdd� Zdd� Z dd� Zdd� Zdd� Zdd� Zdd � Zed$d!d"��ZdS )%�HostKeysaZ Representation of an OpenSSH-style "known hosts" file. Host keys can be read from one or more files, and then individual hosts can be looked up to verify server keys during SSH negotiation. A `.HostKeys` object can be treated like a dict; any dict lookup is equivalent to calling `lookup`. .. versionadded:: 1.5.3 Nc C s g | _ |dur| �|� dS )z� Create a new HostKeys object, optionally loading keys from an OpenSSH style host-key file. :param str filename: filename to load host keys from, or ``None`` N)�_entries�load)�self�filename� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/paramiko/hostkeys.py�__init__/ s zHostKeys.__init__c C sH | j D ](}||jv r|j�� |kr||_ dS q| j �t|g|�� dS )a. Add a host key entry to the table. Any existing entry for a ``(hostname, keytype)`` pair will be replaced. :param str hostname: the hostname (or IP) to add :param str keytype: key type (``"ssh-rsa"`` or ``"ssh-dss"``) :param .PKey key: the key to add N)r � hostnames�key�get_name�append�HostKeyEntry)r �hostnameZkeytyper �er r r �add; s zHostKeys.addc C s� t |d���}t|d�D ]�\}}|�� }t|�dks|d dkr@qzt�||�}W n tyf Y qY n0 |dur|j}|D ]}| �||j �rz|j� |� qzt|j�r| j�|� qW d � n1 s�0 Y dS )a] Read a file of known SSH host keys, in the format used by OpenSSH. This type of file unfortunately doesn't exist on Windows, but on posix, it will usually be stored in ``os.path.expanduser("~/.ssh/known_hosts")``. If this method is called multiple times, the host keys are merged, not cleared. So multiple calls to `load` will just call `add`, replacing any existing entries and adding new ones. :param str filename: name of the file to read host keys from :raises: ``IOError`` -- if there was an error reading the file �r� r �#N) �open� enumerate�strip�lenr � from_liner r �checkr �remover r )r r �f�lineno�line�entryZ _hostnames�hr r r r J s z HostKeys.loadc C sP t |d��2}| jD ]}|�� }|r|�|� qW d � n1 sB0 Y dS )a� Save host keys into a file, in the format used by OpenSSH. The order of keys in the file will be preserved when possible (if these keys were loaded from a file originally). The single exception is that combined lines will be split into individual key lines, which is arguably a bug. :param str filename: name of the file to write :raises: ``IOError`` -- if there was an error writing the file .. versionadded:: 1.6.1 �wN)r! r �to_line�write)r r r( r r* r r r �savej s z HostKeys.savec sV G � fdd�dt �}g }| jD ]}| �� |�r|�|� qt|�dkrJdS |� || �S )a� Find a hostkey entry for a given hostname or IP. If no entry is found, ``None`` is returned. Otherwise a dictionary of keytype to key is returned. The keytype will be either ``"ssh-rsa"`` or ``"ssh-dss"``. :param str hostname: the hostname (or IP) to lookup :return: dict of `str` -> `.PKey` keys associated with this host (or ``None``) c sH e Zd Zdd� Zdd� Zdd� Zdd� Zd d � Z� fdd�Zd d� Z dS )z HostKeys.lookup.<locals>.SubDictc S s || _ || _|| _d S �N)Z _hostnamer � _hostkeys)r r �entriesZhostkeysr r r r � s z)HostKeys.lookup.<locals>.SubDict.__init__c s s | � � D ] }|V qd S r1 ��keys�r �kr r r �__iter__� s z)HostKeys.lookup.<locals>.SubDict.__iter__c S s t | �� �S r1 �r$ r5 �r r r r �__len__� s z(HostKeys.lookup.<locals>.SubDict.__len__c S s: t | j�D ]"}|j�� |kr | j�|� q6q t|��d S r1 )�listr r r r'