a br!@spdZddlmZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z m Z ddlmZmZmZmZmZddlmZd3dd Zere ndZere nd Zd4d d Zd5ddZddZddZddZddZddZddZ ddZ!dd Z"d!d"Z#e$a%da&e'a(d#d$Z)e fd%d&Z*Gd'd(d(e+Z,e,Z-d)d*Z.d+d,Z/d-d.Z0Gd/d0d0e+Z1d1d2Z2dS)6z0 Useful functions used by the rest of paramiko. ) generatorsN)DEBUG zero_byte xffffffffmax_byte)PY2longbyte_chrbyte_ordb) SSHConfigFc Cstd}d}|s0t|dkr0t|ddkr0d}t|dr`t}|rHt}|dt|d|}tdt|dD](}|d>td|||dd}qp|r|tddt|>8}|S)zTturns a normalized byte string into a long-int (adapted from Crypto.Util.number)r >I)rlenr rrrangestructunpack)sZalways_positiveoutnegativeZfillerir4/tmp/pip-target-98j97qn4/lib/python/paramiko/util.py inflate_long%s  &rTcCst}t|}|dkr<|dkrs*  r&cspd}g}t||dkr<|t|||d|d7}q|t|kr^|t||dfdd|DS)Nrcsg|] }|qSrr).0lineprefixrr ez!format_binary..)rappendformat_binary_line)datar,xrrr+r format_binary]s  r3cCs4ddd|D}ddd|D}d||S)N cSsg|]}dt|qS)z{:02X}formatr r)crrrr-ir.z&format_binary_line..r'cSs*g|]"}dt|t|ddqS)z.{:c}..?_r5r7rrrr-kr.z {:50s} {})joinr6)r1leftrightrrrr0hs  r0cCsRd}|D]D}t|}d|kr(dkr:nn|t|7}q|td|7}q|S)Nr.rz%{:02X})r r r r6)rrr8rrrr safe_stringpsr?cCspz |WStyjt|d}t|d}|dkr 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")``. Since 1.5.3, this is just a wrapper around `.HostKeys`. :param str filename: name of the file to read host keys from :return: nested dict of `.PKey` objects, indexed by hostname and then keytype r)HostKeys)Zparamiko.hostkeysrQ)filenamerQrrrload_host_keyss rScCst}|||S)z Provided only as a backward-compatible wrapper around `.SSHConfig`. .. deprecated:: 2.7 Use `SSHConfig.from_file` instead. )r parse)Zfile_objconfigrrrparse_ssh_configs rVcCs ||S)zM Provided only as a backward-compatible wrapper around `.SSHConfig`. )lookup)hostnamerUrrrlookup_ssh_host_configsrYc Cs|dd|}}}dd|}}}|dkrh||}||||}}||||}}||||}}q |dkrx||7}|S)Nrrr) r2mu1u2u3v1v2Zv3qrrr mod_inversesrac CsXztjWStyRttd7att_Wdn1s>0YtjYS0dS)Nr)_g_thread_dataidrA_g_thread_lock_g_thread_counterrrrr get_thread_ids $rfcCsftd}t|jdkrdS||t|d}t|}d}|d7}|t|d| |dS)zKsend paramiko logs to a logfile, if they're not already going somewhereZparamikorNaz>%(levelname)-.3s [%(asctime)s.%(msecs)03d] thr=%(_threadid)-3dz %(name)s: %(message)sz%Y%m%d-%H:%M:%S) logging getLoggerrhandlerssetLevelopen StreamHandler setFormatter Formatter addHandler)rRlevelloggerfhandlerfrmrrr log_to_files    rvc@seZdZddZdS)PFiltercCs t|_dS)NT)rfZ _threadid)selfrecordrrrfilterszPFilter.filterN)__name__ __module__ __qualname__rzrrrrrwsrwcCst|}|t|SN)rhri addFilter_pfilter)namerrrrr get_logger s  rc CsBz|WSty:}z|jtjkr&WYd}~qd}~00qdS)z6Retries function until it doesn't raise an EINTR errorN)EnvironmentErrorerrnoZEINTR)functionerrrretry_on_signals  rcCsVt|t|krdSd}tr tntt|D] }|t||t||AO}q,|dkS)NFr)rrxrangerr )rgr resrrrrconstant_time_bytes_eqs rc@seZdZddZddZdS)ClosingContextManagercCs|Sr~r)rxrrr __enter__(szClosingContextManager.__enter__cCs |dSr~)close)rxtypevaluerCrrr__exit__+szClosingContextManager.__exit__N)r{r|r}rrrrrrr'srcCst|t||Sr~)maxrK)minimumvalmaximumrrr clamp_value/sr)F)T)r')3__doc__ __future__rrrErrC threadingrhZparamiko.commonrrrrZparamiko.py3compatrrr r r Zparamiko.configr rr#r$r&r3r0r?r@rHrPrSrVrYralocalrbreLockrdrfrvobjectrwrrrrrrrrrrsH