???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................3
Uf%                 @   s&  d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 y(d dl
Z
d dl
mZmZmZ d dlZW n< ek
r   d dljZ
d dlmZmZmZ d dljZY nX G dd de
jZG d	d
 d
e
jZG dd deZG dd deZG dd deZG dd deZdd Zdd ZdS )    N)python_version)SSL)nonblocking)i18n)_CS_REQ_SENT_CS_IDLEResponseNotReadyc               @   s   e Zd Zdd ZdS )HTTPResponsec             C   s4   t | jtjstj| j| _| jj||||| d S )N)
isinstancefpr   ZNonBlockingFileset_callback)selfrswsex	user_datacallback r   !/usr/lib/python3.6/connections.pyr       s    zHTTPResponse.set_callbackN)__name__
__module____qualname__r   r   r   r   r   r	      s   r	   c               @   s@   e Zd ZeZdejfddZdd Zdd Z	dd	 Z
d
d ZdS )HTTPConnectionNc             C   s^   t  dkr tjj| |||d ntjj| || g | _g | _g | _d | _d | _d| _	|| _
d S )Nz2.6.1)timeoutz#rhn.connections $Revision$ (python))r   httplibr   __init___cb_rs_cb_ws_cb_ex_cb_user_data_cb_callback_user_agentr   )r   hostportr   r   r   r   r   (   s    
zHTTPConnection.__init__c             C   s"   || _ || _|| _|| _|| _d S )N)r   r   r   r   r    )r   r   r   r   r   r   r   r   r   r   5   s
    zHTTPConnection.set_callbackc             C   s
   || _ d S )N)r!   )r   Z
user_agentr   r   r   set_user_agent=   s    zHTTPConnection.set_user_agentc             C   s   | j r| j j rd| _ | jtks&| j r,t | jdkrH| j| j| j}n| j| j}| jrv|j	| j
| j| j| j| j |j  |jtjkstt| _|jr| j  n|| _ |S )z!Get the response from the server.Nr   )Z_HTTPConnection__responseZisclosedZ_HTTPConnection__stater   r   Z
debuglevelresponse_classsockr    r   r   r   r   r   begin
will_closer   Z_UNKNOWNAssertionErrorr   close)r   responser   r   r   getresponseB   s"    

zHTTPConnection.getresponsec             C   s   t jj|  | jj| j d S )N)r   r   connectr&   
settimeoutr   )r   r   r   r   r-   s   s    zHTTPConnection.connect)r   r   r   r	   r%   r   DEFAULT_TIMEOUTr   r   r$   r,   r-   r   r   r   r   r   %   s   1r   c               @   sB   e Zd ZdddejfddZdd ZdddZd	d
 Zdd Z	dS )HTTPProxyConnectionNc             C   sP   t j| ||d | j| j | _| _| j|| | j| j | _| _|| _	|| _
d S )N)r   )r   r   r"   r#   _HTTPProxyConnection__proxy _HTTPProxyConnection__proxy_port_set_hostport_host_port_HTTPProxyConnection__username_HTTPProxyConnection__password)r   proxyr"   r#   usernamepasswordr   r   r   r   r   y   s    zHTTPProxyConnection.__init__c             C   s.   | j | j| j tj|  | j | j| j d S )N)r3   r1   r2   r   r-   r4   r5   )r   r   r   r   r-      s    
zHTTPProxyConnection.connectr   c             C   sN   | j }| j| jkr$|d t| j }d||f }tj| |||d | j  d S )N:zhttp://%s%s)	skip_host)r4   r5   default_portstrr   
putrequest_add_proxy_headers)r   methodurlr<   hostnameZnewurlr   r   r   r?      s    zHTTPProxyConnection.putrequestc             C   sX   | j s
d S d| j | jf }tjtj|jtjdtjd}| jddtj|  d S )Nz%s:%s
 zProxy-AuthorizationzBasic %s)	r6   r7   base64Zencodestringr   bstrreplace	putheaderZsstr)r   ZuserpassZenc_userpassr   r   r   r@      s
    $z&HTTPProxyConnection._add_proxy_headersc             C   s   | j ||\| _| _d S )N)Z_get_hostportr"   r#   )r   r"   r#   r   r   r   r3      s    z!HTTPProxyConnection._set_hostport)r   )
r   r   r   r   r/   r   r-   r?   r@   r3   r   r   r   r   r0   x   s   
r0   c               @   s2   e Zd ZeZejjZddej	fddZ
dd ZdS )HTTPSConnectionNc             C   s$   t j| |||d |pg }|| _d S )N)r   )r   r   trusted_certs)r   r"   r#   rK   r   r   r   r   r      s    zHTTPSConnection.__init__c       	      C   s   t j| j| jt jt j}x|D ]}|\}}}}}yt j |||}W n t jk
r^   d}wY nX y"|j| j| jf |j| j	 W n$ t jk
r   |j
  d}wY nX P qW |dkrt jdtj|| j| _| jj  dS )z'Connect to a host on a given (SSL) portNz0Unable to connect to the host and port specified)socketZgetaddrinfor"   r#   Z	AF_UNSPECZSOCK_STREAMerrorr-   r.   r   r*   r   	SSLSocketrK   r&   init_ssl)	r   resultsrZafZsocktypeprotoZ	canonnameZsar&   r   r   r   r-      s*    

zHTTPSConnection.connect)r   r   r   r	   r%   r   rJ   r=   r   r/   r   r-   r   r   r   r   rJ      s
   rJ   c               @   s   e Zd Zdd ZdS )HTTPSProxyResponsec             C   s   t j|  d| _d S )Nr   )r	   r'   r(   )r   r   r   r   r'      s    
zHTTPSProxyResponse.beginN)r   r   r   r'   r   r   r   r   rS      s   rS   c               @   sB   e Zd ZejZddddejfddZdd ZdddZ	d	d
 Z
dS )HTTPSProxyConnectionNc          	   C   s*   t j| ||||||d |pg }|| _d S )N)r   )r0   r   rK   )r   r8   r"   r#   r9   r:   rK   r   r   r   r   r      s    
zHTTPSProxyConnection.__init__c             C   s   t j|  d| j| jf }tj| d| | j  tj|  | j}t	| _tj
| }|| _|j  |jdkr| j  tj||j|j|jtj| j| j| _| jj  d S )Nz%s:%sZCONNECT   )r0   r-   r4   r5   r   r?   r@   Z
endheadersr%   rS   r,   r*   Zstatus	xmlrpclibZProtocolErrorreasonmsgr   rN   r&   rK   rO   )r   r"   r%   r+   r   r   r   r-      s     



zHTTPSProxyConnection.connectr   c             C   s   t j| |||dS )N)r<   )r   r?   )r   rA   rB   r<   r   r   r   r?      s    zHTTPSProxyConnection.putrequestc             C   s   t j|  | jd| j d S )Nz
User-Agent)r0   r@   rI   r!   )r   r   r   r   r@      s    
z'HTTPSProxyConnection._add_proxy_headers)r   )r   r   r   rJ   r=   r   r/   r   r-   r?   r@   r   r   r   r   rT      s   
rT   c             C   s$   | dkrdS t j| } | jdS dS )zJ Convert Internationalized domain name from Punycode (RFC3492) to Unicode Nidna)r   rG   decode)rC   r   r   r   idn_puny_to_unicode   s    
r[   c             C   s*   | dkrdS t j| } t j| jdS dS )zZ Convert domain name to Punycode (RFC3492). Hostname can be instance of string or Unicode NrY   )r   Zustrencode)rC   r   r   r   idn_ascii_to_puny  s    
r]   )rF   Zencodings.idnaZ	encodingsrL   platformr   Zrhnr   r   r   r   r   r   r   rV   ImportErrorZhttp.clientZclientZxmlrpc.clientr	   r   r0   rJ   rS   rT   r[   r]   r   r   r   r   <module>
   s,   
S,&.