U
     T‚g¢  ã                   @   sˆ   d Z ddlZddlmZ ddlmZ ddlmZ dddd	d
gZdd„ Z	ddd„Z
dd„ Zddd	„Zdd
„ Zeeddddƒƒdd„ ƒZdS )z@
Common functions for the SSH classes.

Maintainer: Paul Swartz
é    N)Úint_to_bytes)Ú
deprecated)ÚVersionÚNSÚgetNSÚMPÚgetMPÚffsc                 C   s(   t | tƒr|  d¡} t dt| ƒ¡|  S )z
    net string
    zutf-8ú!L)Ú
isinstanceÚstrÚencodeÚstructÚpackÚlen)Út© r   ú</tmp/pip-unpacked-wheel-1_7di8ic/twisted/conch/ssh/common.pyr      s    

é   c                 C   sp   g }d}t |ƒD ]H}t d| ||d … ¡\}| | |d d| | … ¡ |d| 7 }qt|ƒ| |d… f S )z
    get net string
    r   r
   é   N)Úranger   ÚunpackÚappendÚtuple)ÚsÚcountÚnsÚcÚiÚlr   r   r   r      s    c                 C   sP   | dkrdS | dkst ‚t| ƒ}t|dd… ƒd@ r<d| }t dt|ƒ¡| S )Nr   s       r   é€   ó    ú>L)ÚAssertionErrorr   Úordr   r   r   )ÚnumberZbnr   r   r   r   ,   s    c              	   C   sx   g }d}t |ƒD ]P}t d| ||d … ¡\}| t | |d |d | … d¡¡ |d| 7 }qt|ƒ| |d… f S )a=  
    Get multiple precision integer out of the string.  A multiple precision
    integer is stored as a 4-byte length followed by length bytes of the
    integer.  If count is specified, get count integers out of the string.
    The return value is a tuple of count integers followed by the rest of
    the data.
    r   r"   r   ÚbigN)r   r   r   r   ÚintÚ
from_bytesr   )Údatar   Úmpr   r   Úlengthr   r   r   r   6   s    &c                 C   s   | D ]}||kr|  S qdS )zs
    first from second
    goes through the first list, looking for items in the second, returns the first one
    Nr   )r   r   r   r   r   r   r	   G   s    ZTwistedé   é   c                   C   s   d S )Nr   r   r   r   r   ÚinstallQ   s    r.   )r   )r   )Ú__doc__r   Zcryptography.utilsr   Ztwisted.python.deprecater   Ztwisted.python.versionsr   Ú__all__r   r   r   r   r	   r.   r   r   r   r   Ú<module>   s   	



