Ñò
ðgcJc           @   s¨  d  Z  d d k l Z d d k Z d d k l Z l Z d d k Z d d k Z d d k	 Z	 d d k
 Z
 d d k Td d k l Z e i d# j  o d	 d$ d
 „  ƒ  YZ n e d „ Z e d „ Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  h  a! d a" e
 i# ƒ  a$ d „  Z% e& d „ Z' d e( f d „  ƒ  YZ) e) ƒ  Z* d  „  Z+ d! e( f d" „  ƒ  YZ, d S(%   s0   
Useful functions used by the rest of paramiko.
iÿÿÿÿ(   t
   generatorsN(   t   hexlifyt	   unhexlify(   t   *(   t	   SSHConfigi   i   t	   enumeratec           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t   sequence(   t   selfR   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   __init__'   s    c         c   s3   d } x& |  i  D] } | | f V| d 7} q Wd  S(   Ni    i   (   R   (   R   t   countt   item(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   __iter__)   s
    
 (   t   __name__t
   __module__R   R   (    (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyR   &   s   	c         C   s  d } d } | o4 t  |  ƒ d j o! t |  d ƒ d j o
 d } n t  |  ƒ d o7 d } | o
 d } n | d t  |  ƒ d |  }  n xI t d t  |  ƒ d ƒ D]/ } | d >t i d	 |  | | d !ƒ d } q© W| o | d
 d t  |  ƒ >8} n | S(   sP   turns a normalized byte string into a long-int (adapted from Crypto.Util.number)l    i    i€   i   i   t    s   ÿi    s   >Il    i   (   t   lent   ordt   ranget   structt   unpack(   t   st   always_positivet   outt   negativet   fillert   i(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   inflate_long0   s    2

  -c         C   sY  d } t  |  ƒ }  xC |  d j o5 |  d j o( t i d |  d @ƒ | } |  d ?}  q Wx} t | ƒ D]L } |  d j o | d d j o Pn |  d j o | d d	 j o Pqe qe Wd } |  d j o
 d } n d	 } | | d } | oh |  d j o% t | d ƒ d
 j o d | } n |  d j o% t | d ƒ d
 j  o d	 | } qUn | S(   sP   turns a long-int into a normalized byte string (adapted from Crypto.Util.number)t    i    iÿÿÿÿs   >Il   ÿÿ i    i   R   s   ÿi€   (   i    (   t   longR   t   packR   R   (   t   nt   add_sign_paddingR   R   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   deflate_longA   s.      	
$$c         C   sy   d } xl t  |  ƒ D]^ } | d t | d ƒ 7} | d d o | d 7} n | d d d j o | d	 7} q q W| S(
   NR   s   %02Xi   i    i   t    i   i   s   
(   R   R   (   t   dataR   R   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   format_binary_weird^   s     R   c         C   s¤   d } g  } xD t  |  ƒ | d j o, | i t |  | | d !ƒ ƒ | d 7} q W| t  |  ƒ j  o | i t |  | ƒ ƒ n g  } | D] } | | | qŒ ~ S(   Ni    i   (   R   t   appendt   format_binary_line(   R"   t   prefixt   xR   t   _[1](    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   format_binaryh   s     c      	   C   s‚   d i  g  } |  D] } | d t | ƒ q ~ ƒ } d i  g  } |  D]# } | d | t | ƒ d d qE ~ ƒ } d | | f S(   NR!   s   %02XR   s   .%c..i?   i_   s   %-50s %s(   t   joinR   (   R"   R(   t   ct   leftt   _[2]t   right(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyR%   r   s    4@c         C   s   t  |  ƒ i ƒ  S(   N(   R   t   upper(   R   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   hexifyw   s    c         C   s
   t  |  ƒ S(   N(   R   (   R   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   unhexifyz   s    c         C   sc   d } xV |  D]N } t  | ƒ d j o! t  | ƒ d j o | | 7} q | d t  | ƒ 7} q W| S(   NR   i    i   s   %%%02X(   R   (   R   R   R+   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   safe_string}   s     &c         C   sl   t  |  d ƒ } t | d ƒ } | d j o d St | ƒ d } x$ | d @p | d K} | d 8} qD W| S(   Ni    i   i   i€   (   R    R   R   (   R   t   normt   hbytet   bitlen(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt
   bit_lengthˆ   s     
c           C   s%   d i  t i t i ƒ  Œ  ƒ i d ƒ S(   NR   s   
(   R*   t	   tracebackt   format_exceptiont   syst   exc_infot   split(    (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt
   tb_strings“   s    c         C   sÉ   d } d } t  | ƒ d j o | d  } n x• | d j o‡ |  i ƒ  } t  | ƒ d j o | i | ƒ n | i | ƒ | i | ƒ | i ƒ  } t | t  | ƒ ƒ } | | |  7} | | 8} q0 W| S(   sx  
    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.

    @param hashclass: class from L{Crypto.Hash} that can be used as a secure
        hashing function (like C{MD5} or C{SHA}).
    @type hashclass: L{Crypto.Hash}
    @param salt: data to salt the hash with.
    @type salt: string
    @param key: human-entered password or passphrase.
    @type key: string
    @param nbytes: number of bytes to generate.
    @type nbytes: int
    @return: key data
    @rtype: string
    R   i   i    (   R   t   newt   updatet   digestt   min(   t	   hashclasst   saltt   keyt   nbytest   keydataR?   t   hash_objt   size(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   generate_key_bytes–   s      c         C   s   d d k  l } | |  ƒ S(   sÒ  
    Read a file of known SSH host keys, in the format used by openssh, and
    return a compound dict of C{hostname -> keytype ->} L{PKey <paramiko.pkey.PKey>}.
    The hostname may be an IP address or DNS name.  The keytype will be either
    C{"ssh-rsa"} or C{"ssh-dss"}.

    This type of file unfortunately doesn't exist on Windows, but on posix,
    it will usually be stored in C{os.path.expanduser("~/.ssh/known_hosts")}.

    Since 1.5.3, this is just a wrapper around L{HostKeys}.

    @param filename: name of the file to read host keys from
    @type filename: str
    @return: dict of host keys, indexed by hostname and then keytype
    @rtype: dict(hostname, dict(keytype, L{PKey <paramiko.pkey.PKey>}))
    iÿÿÿÿ(   t   HostKeys(   t   paramiko.hostkeysRI   (   t   filenameRI   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   load_host_keys¸   s    c         C   s   t  ƒ  } | i |  ƒ | S(   sM   
    Provided only as a backward-compatible wrapper around L{SSHConfig}.
    (   R   t   parse(   t   file_objt   config(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   parse_ssh_configÌ   s    	c         C   s   | i  |  ƒ S(   sM   
    Provided only as a backward-compatible wrapper around L{SSHConfig}.
    (   t   lookup(   t   hostnameRO   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   lookup_ssh_host_configÔ   s    c   	      C   s¥   d d | } } } d d |  } } } x[ | d j oM | | } | | | | } } | | | | } } | | | | } } q+ W| d j  o | | 7} n | S(   Ni   i    (    (	   R'   t   mt   u1t   u2t   u3t   v1t   v2t   v3t   q(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   mod_inverseÚ   s     
i    c          C   sm   t  t i ƒ  ƒ }  y t |  SWnH t j
 o< t i ƒ  z t d 7a t } t |  <Wd  t i ƒ  X| SXd  S(   Ni   (	   t   idt	   threadingt   currentThreadt   _g_thread_idst   KeyErrort   _g_thread_lockt   acquiret   _g_thread_countert   release(   t   tidt   ret(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   get_thread_idë   s    

c         C   s   t  i d ƒ } t | i ƒ d j o d S| i | ƒ t |  d ƒ } t  i | ƒ } | i t  i d d ƒ ƒ | i	 | ƒ d S(   sG   send paramiko logs to a logfile, if they're not already going somewheret   paramikoi    Nt   wsT   %(levelname)-.3s [%(asctime)s.%(msecs)03d] thr=%(_threadid)-3d %(name)s: %(message)ss   %Y%m%d-%H:%M:%S(
   t   loggingt	   getLoggerR   t   handlerst   setLevelt   opent   StreamHandlert   setFormattert	   Formattert
   addHandler(   RK   t   levelt   lt   ft   lh(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   log_to_fileù   s    
t   PFilterc           B   s   e  Z d  „  Z RS(   c         C   s   t  ƒ  | _ t S(   N(   Rh   t	   _threadidt   True(   R   t   record(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   filter  s    (   R   R   R}   (    (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyRy     s   c         C   s    t  i |  ƒ } | i t ƒ | S(   N(   Rk   Rl   t	   addFiltert   _pfilter(   t   nameRu   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt
   get_logger  s    t   Counterc           B   sA   e  Z d  Z d d d „ Z d „  Z d d d „ Z e e ƒ Z RS(   s$   Stateful counter for CTR mode cryptol    l    c         C   s‡   | d |  _  | |  _ | d j o  t i d d |  i  ƒ |  _ nA t | d d t ƒ} t i d d |  i  t | ƒ | ƒ |  _ d  S(   Ni   i    R+   s   ÿi   R   R   (   t	   blocksizet   overflowt   arrayt   valueR    t   FalseR   (   R   t   nbitst   initial_valueR„   R'   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyR     s    	 c         C   s¿   |  i  d } xc | d j oU t t |  i | ƒ d d ƒ } |  i | <| d j o |  i i ƒ  S| d 8} q Wt |  i d t ƒ} t i d d |  i  t	 | ƒ | ƒ |  _ |  i i ƒ  S(   s/   Increament the counter and return the new valuei   iÿÿÿÿi   R   R   R+   (
   Rƒ   t   chrR   R†   t   tostringR    R„   R‡   R…   R   (   R   R   R+   R'   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   __call__  s     ,*c         C   s   |  | d | d | ƒS(   NR‰   R„   (    (   t   clsRˆ   R‰   R„   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyR=   ,  s    (   R   R   t   __doc__R   RŒ   R=   t   classmethod(    (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyR‚     s
   	(   i   i   (    (-   RŽ   t
   __future__R    R…   t   binasciiR   R   R9   R   R7   R^   t   paramiko.commont   paramiko.configR   t   version_infoR   R‡   R   R{   R    R#   R)   R%   R0   R1   R2   R6   R<   RH   RL   RP   RS   R\   R`   Rd   t   LockRb   Rh   t   DEBUGRx   t   objectRy   R   R   R‚   (    (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\util.pyt   <module>   sF   

	

							"							