Current File : //usr/lib/python2.7/site-packages/paramiko/config.pyo
�
=OXc@sxdZddlZddlZddlZddlZddlZdZdefd��YZdefd��YZ	dS(s2
Configuration file (aka ``ssh_config``) support.
i����Nit	SSHConfigcBs\eZdZejd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd�ZRS(	s�
    Representation of config information as stored in the format used by
    OpenSSH. Queries can be made via `lookup`. The format is described in
    OpenSSH's ``ssh_config`` man page. This class 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.

    .. versionadded:: 1.6
    s(\w+)(?:\s*=\s*|\s+)(.+)cCs
g|_dS(s5
        Create a new OpenSSH config object.
        N(t_config(tself((s3/usr/lib/python2.7/site-packages/paramiko/config.pyt__init__.scCs�idgd6id6}x�|D]�}|j�}|s|jd�rLqntj|j|�}|sztd|��n|jd�j�}|jd�}|dkr�|jj	|�i|j
|�d6id6}q|dkr	|j�d	kr	d|d|<q|jd
�r7|jd
�r7|dd!}n|dkr||dkrk|d|j	|�q�|g|d|<q||dkr||d|<qqW|jj	|�dS(s�
        Read an OpenSSH config from the given file object.

        :param file_obj: a file-like object to read the config file from
        t*thosttconfigt#sUnparsable line %siitproxycommandtnonet"i����tidentityfiletlocalforwardt
remoteforwardN(RRR
(
tstript
startswithtretmatchtSETTINGS_REGEXt	ExceptiontgrouptlowerRtappendt
_get_hoststNonetendswith(Rtfile_objRtlineRtkeytvalue((s3/usr/lib/python2.7/site-packages/paramiko/config.pytparse4s4

cCs�g|jD]"}|j|d|�r
|^q
}i}x{|D]s}xj|dj�D]X\}}||kr�|dk	r�|n|||<qV|dkrV||j|�qVqVWq?W|j||�}d|kr�|ddkr�|d=n|S(s�
        Return a dict of config options for a given hostname.

        The host-matching rules of OpenSSH's ``ssh_config`` man page are used:
        For each parameter, the first obtained value will be used.  The
        configuration files contain sections separated by ``Host``
        specifications, and that section is only applied for hosts that match
        one of the patterns given in the specification.

        Since the first obtained value for each parameter is used, more host-
        specific declarations should be given near the beginning of the file,
        and general defaults at the end.

        The keys in the returned dict are all normalized to lowercase (look for
        ``"port"``, not ``"Port"``. The values are processed according to the
        rules for substitution variable expansion in ``ssh_config``.

        :param str hostname: the hostname to lookup
        RRRRN(Rt_allowedtitemsRtextendt_expand_variables(RthostnameRtmatchestretRRR((s3/usr/lib/python2.7/site-packages/paramiko/config.pytlookupcs"
 
cCs2t�}x"|jD]}|j|d�qW|S(s�
        Return the set of literal hostnames defined in the SSH config (both
        explicit hostnames and wildcard entries).
        R(tsetRtupdate(Rthoststentry((s3/usr/lib/python2.7/site-packages/paramiko/config.pyt
get_hostnames�s	cCs_t}xR|D]J}|jd�r<tj||d�r<tStj||�r
t}q
q
W|S(Nt!i(tFalseRtfnmatchtTrue(RR)R#RR((s3/usr/lib/python2.7/site-packages/paramiko/config.pyR�s
%
c	Csxd|kr)|djd|�|d<n
||d<d|krL|d}nt}tjd�}d|krz|d}n|}tj�jd�d}t||�}tjj	d�}id|dfd	|fd
|fd|fd|fd
|fd|fgd6d|fd|fd|dfd	|fd|fd
|fgd6d|fd|dfd|fd
|fgd6}	x�|D]�}
||
dkr�q�n|
|	kr�x�|	|
D]�\}}t||
t�r6x�t
t||
��D]E}
|||
|
kr�||
|
j|t|��||
|
<q�q�Wq�|||
kr�||
j|t|��||
<q�q�Wq�q�W|S(sC
        Return a dict of config options with expanded substitutions
        for a given hostname.

        Please refer to man ``ssh_config`` for the parameters that
        are replaced.

        :param dict config: the config for the hostname
        :param str hostname: the hostname that the config belongs to
        R#s%htporttUSERtusert.it~s%ls%Ls%ns%ps%rs%utcontrolpaths%dRRN(treplacetSSH_PORTtostgetenvtsockettgethostnametsplittLazyFqdntpatht
expanduserRt
isinstancetlisttrangetlentstr(RRR#R0R2t
remoteuserRtfqdnthomedirtreplacementstktfindR6titem((s3/usr/lib/python2.7/site-packages/paramiko/config.pyR"�sX



							
			
	
$.cCs9ytj|�SWn!tk
r4td|��nXdS(s>
        Return a list of host_names from host value.
        sUnparsable host %sN(tshlexR<t
ValueErrorR(RR((s3/usr/lib/python2.7/site-packages/paramiko/config.pyR�s
(
t__name__t
__module__t__doc__RtcompileRRRR&R+RR"R(((s3/usr/lib/python2.7/site-packages/paramiko/config.pyR!s			/	*	
			JR=cBs#eZdZdd�Zd�ZRS(s7
    Returns the host's fqdn on request as string.
    cCsd|_||_||_dS(N(RRFRR(RRR((s3/usr/lib/python2.7/site-packages/paramiko/config.pyR�s		cCs|jdkrd}|jjdd�j�}|dkr�y�|dkrTtjntj}tj|j	d|tj
tjtj�}x?|D]7}|\}}}}	}
|	r�d|	kr�|	}Pq�q�WWq�tj
k
r�q�Xn|dkr�tj�}n||_n|jS(Nt
addressfamilytanytinetR3(RFRRtgetRR:tAF_INETtAF_INET6tgetaddrinfoRt
SOCK_DGRAMt
IPPROTO_IPtAI_CANONNAMEtgaierrortgetfqdn(RRFtaddress_familytfamilytresultstrestaftsocktypetprotot	canonnametsa((s3/usr/lib/python2.7/site-packages/paramiko/config.pyt__str__�s2	
N(RNRORPRRRg(((s3/usr/lib/python2.7/site-packages/paramiko/config.pyR=�s(
RPR.R8RRLR:R7tobjectRR=(((s3/usr/lib/python2.7/site-packages/paramiko/config.pyt<module>s�