paramiko.util

Package paramiko :: Module util |
[show private | hide private]
[frames | no frames]

## Module paramiko.util

Useful functions used by the rest of paramiko.

Classes
`PFilter` |

Function Summary
| `bit_length(n)`
| ``deflate_long`(n, add_sign_padding)` turns a long-int into a normalized byte string (adapted from Crypto.Util.number)
| `format_binary(data, prefix)`
| `format_binary_line(data)`
| `format_binary_weird(data)`
string | ``generate_key_bytes`(hashclass, salt, key, nbytes)` Given a password, passphrase, or other human-source key, scramble it through a secure hash into some keyworthy bytes.
| `get_logger(name)`
| `get_thread_id()`
| ``hexify`(s)` turn a string into a hex sequence
| ``inflate_long`(s, always_positive)` turns a normalized byte string into a long-int (adapted from Crypto.Util.number)
dict(hostname, dict(keytype, `PKey`)) | ``load_host_keys`(filename)` Read a file of known SSH host keys, in the format used by openssh, and return a compound dict of `hostname -> keytype ->` `PKey`.
| ``log_to_file`(filename, level)` send paramiko logs to a logfile, if they're not already going somewhere
| ``lookup_ssh_host_config`(hostname, config)` Return a dict of config options for a given hostname.
| `mod_inverse(x, m)`
object | ``parse_ssh_config`(file_obj)` Parse a config file of the format used by OpenSSH, and return an object that can be used to make queries to `lookup_ssh_host_config`.
| `safe_string(s)`
| `tb_strings()`
| ``unhexify`(s)` turn a hex sequence back into a string

Variable Summary
`int` | `_g_thread_counter` = 0
`dict` | `_g_thread_ids` = `{}`
`lock` | `_g_thread_lock` = `<thread.lock object at 0xb7df2180>`
`PFilter` | `_pfilter` = `<paramiko.util.PFilter object at 0xb7b39dac>`

Function Details

### deflate_long(n, add_sign_padding=True) turns a long-int into a normalized byte string (adapted from Crypto.Util.number)

### generate_key_bytes(hashclass, salt, key, nbytes) Given a password, passphrase, or other human-source key, scramble it through a secure hash into some keyworthy bytes. This specific algorithm is used for encrypting/decrypting private key files. Parameters: `hashclass` - class from `Crypto.Hash` that can be used as a secure hashing function (like `MD5` or `SHA`). (type=`Crypto.Hash`) `salt` - data to salt the hash with. (type=string) `key` - human-entered password or passphrase. (type=string) `nbytes` - number of bytes to generate. (type=int) Returns: key data (type=string)

### hexify(s) turn a string into a hex sequence

### inflate_long(s, always_positive=False) turns a normalized byte string into a long-int (adapted from Crypto.Util.number)

### load_host_keys(filename) Read a file of known SSH host keys, in the format used by openssh, and return a compound dict of `hostname -> keytype ->` `PKey`. The hostname may be an IP address or DNS name. The keytype will be either `"ssh-rsa"` or `"ssh-dss"`. 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")`. Parameters: `filename` - name of the file to read host keys from (type=str) Returns: dict of host keys, indexed by hostname and then keytype (type=dict(hostname, dict(keytype, `PKey`)))

### log_to_file(filename, level=10) send paramiko logs to a logfile, if they're not already going somewhere

### lookup_ssh_host_config(hostname, config) Return a dict of config options for a given hostname. The `config` object must come from `parse_ssh_config`. The host-matching rules of OpenSSH's `ssh_config` man page are used, which means that all configuration options from matching host specifications are merged, with more specific hostmasks taking precedence. In other words, if `"Port"` is set under `"Host *"` and also `"Host *.example.com"`, and the lookup is for `"ssh.example.com"`, then the port entry for `"Host *.example.com"` will win out. The keys in the returned dict are all normalized to lowercase (look for `"port"`, not `"Port"`. No other processing is done to the keys or values. Parameters: `hostname` - the hostname to lookup (type=str) `config` - the config object to search (type=object)

### parse_ssh_config(file_obj) Parse a config file of the format used by OpenSSH, and return an object that can be used to make queries to `lookup_ssh_host_config`. The format is described in OpenSSH's `ssh_config` man page. This method 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. The return value is currently a list of dictionaries, each containing host-specific configuration, but this is considered an implementation detail and may be subject to change in later versions. Parameters: `file_obj` - a file-like object to read the config file from (type=file) Returns: opaque configuration object (type=object)

### unhexify(s) turn a hex sequence back into a string

Variable Details

    ### _g_thread_counter Type: `int` Value:
        0

    ### _g_thread_ids Type: `dict` Value:
        {}

    ### _g_thread_lock Type: `lock` Value:
        <thread.lock object at 0xb7df2180>

    ### _pfilter Type: `PFilter` Value:
        <paramiko.util.PFilter object at 0xb7b39dac>

Generated by Epydoc 2.1 on Sun Dec 4 11:16:48 2005 | http://epydoc.sf.net