diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2014-02-21 10:21:19 -0800 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2014-02-21 10:21:19 -0800 |
commit | eb332c781bf26a96a472f970550938ccba118056 (patch) | |
tree | 8dd932dff3d90e2350485c33fcf12fae860d88b9 | |
parent | d4148ab6f30fbea9d42e6999fb793a557a4d0f92 (diff) |
Reorganize Client so API doc flows better
-rw-r--r-- | paramiko/client.py | 115 | ||||
-rw-r--r-- | sites/docs/api/client.rst | 1 |
2 files changed, 58 insertions, 58 deletions
diff --git a/paramiko/client.py b/paramiko/client.py index 19a09c2d..c7f9cfc8 100644 --- a/paramiko/client.py +++ b/paramiko/client.py @@ -17,7 +17,7 @@ # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. """ -:class:`SSHClient`. +SSH client & key policies """ from binascii import hexlify @@ -38,63 +38,6 @@ from paramiko.transport import Transport from paramiko.util import retry_on_signal -class MissingHostKeyPolicy (object): - """ - Interface for defining the policy that :class:`SSHClient` should use when the - SSH server's hostname is not in either the system host keys or the - application's keys. Pre-made classes implement policies for automatically - adding the key to the application's :class:`HostKeys` object (:class:`AutoAddPolicy`), - and for automatically rejecting the key (:class:`RejectPolicy`). - - This function may be used to ask the user to verify the key, for example. - """ - - def missing_host_key(self, client, hostname, key): - """ - Called when an :class:`SSHClient` receives a server key for a server that - isn't in either the system or local :class:`HostKeys` object. To accept - the key, simply return. To reject, raised an exception (which will - be passed to the calling application). - """ - pass - - -class AutoAddPolicy (MissingHostKeyPolicy): - """ - Policy for automatically adding the hostname and new host key to the - local :class:`HostKeys` object, and saving it. This is used by :class:`SSHClient`. - """ - - def missing_host_key(self, client, hostname, key): - client._host_keys.add(hostname, key.get_name(), key) - if client._host_keys_filename is not None: - client.save_host_keys(client._host_keys_filename) - client._log(DEBUG, 'Adding %s host key for %s: %s' % - (key.get_name(), hostname, hexlify(key.get_fingerprint()))) - - -class RejectPolicy (MissingHostKeyPolicy): - """ - Policy for automatically rejecting the unknown hostname & key. This is - used by :class:`SSHClient`. - """ - - def missing_host_key(self, client, hostname, key): - client._log(DEBUG, 'Rejecting %s host key for %s: %s' % - (key.get_name(), hostname, hexlify(key.get_fingerprint()))) - raise SSHException('Server %r not found in known_hosts' % hostname) - - -class WarningPolicy (MissingHostKeyPolicy): - """ - Policy for logging a python-style warning for an unknown host key, but - accepting it. This is used by :class:`SSHClient`. - """ - def missing_host_key(self, client, hostname, key): - warnings.warn('Unknown %s host key for %s: %s' % - (key.get_name(), hostname, hexlify(key.get_fingerprint()))) - - class SSHClient (object): """ A high-level representation of a session with an SSH server. This class @@ -536,3 +479,59 @@ class SSHClient (object): def _log(self, level, msg): self._transport._log(level, msg) + +class MissingHostKeyPolicy (object): + """ + Interface for defining the policy that :class:`SSHClient` should use when the + SSH server's hostname is not in either the system host keys or the + application's keys. Pre-made classes implement policies for automatically + adding the key to the application's :class:`HostKeys` object (:class:`AutoAddPolicy`), + and for automatically rejecting the key (:class:`RejectPolicy`). + + This function may be used to ask the user to verify the key, for example. + """ + + def missing_host_key(self, client, hostname, key): + """ + Called when an :class:`SSHClient` receives a server key for a server that + isn't in either the system or local :class:`HostKeys` object. To accept + the key, simply return. To reject, raised an exception (which will + be passed to the calling application). + """ + pass + + +class AutoAddPolicy (MissingHostKeyPolicy): + """ + Policy for automatically adding the hostname and new host key to the + local :class:`HostKeys` object, and saving it. This is used by :class:`SSHClient`. + """ + + def missing_host_key(self, client, hostname, key): + client._host_keys.add(hostname, key.get_name(), key) + if client._host_keys_filename is not None: + client.save_host_keys(client._host_keys_filename) + client._log(DEBUG, 'Adding %s host key for %s: %s' % + (key.get_name(), hostname, hexlify(key.get_fingerprint()))) + + +class RejectPolicy (MissingHostKeyPolicy): + """ + Policy for automatically rejecting the unknown hostname & key. This is + used by :class:`SSHClient`. + """ + + def missing_host_key(self, client, hostname, key): + client._log(DEBUG, 'Rejecting %s host key for %s: %s' % + (key.get_name(), hostname, hexlify(key.get_fingerprint()))) + raise SSHException('Server %r not found in known_hosts' % hostname) + + +class WarningPolicy (MissingHostKeyPolicy): + """ + Policy for logging a python-style warning for an unknown host key, but + accepting it. This is used by :class:`SSHClient`. + """ + def missing_host_key(self, client, hostname, key): + warnings.warn('Unknown %s host key for %s: %s' % + (key.get_name(), hostname, hexlify(key.get_fingerprint()))) diff --git a/sites/docs/api/client.rst b/sites/docs/api/client.rst index 1661f97d..b201812f 100644 --- a/sites/docs/api/client.rst +++ b/sites/docs/api/client.rst @@ -2,3 +2,4 @@ Client ====== .. automodule:: paramiko.client + :member-order: bysource |