
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
 `%                 @   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  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   beginr   
will_close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)r2   r0   r1   r   r,   r3   r4   )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)r3   r4   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)	r5   r6   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   r2      s    z!HTTPProxyConnection._set_hostport)r   )
r   r   r   r   r.   r   r,   r>   r?   r2   r   r   r   r   r/   x   s   
r/   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#   rJ   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   	SSLSocketrJ   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   rI   r<   r   r.   r   r,   r   r   r   r   rI      s
   rI   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   rR      s   rR   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   )r/   r   rJ   )r   r7   r"   r#   r8   r9   rJ   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   )r/   r,   r3   r4   r   r>   r?   Z
endheadersr%   rR   r+   r)   Zstatus	xmlrpclibZProtocolErrorreasonmsgr   rM   r&   rJ   rN   )r   r"   r%   r*   r   r   r   r,      s     



zHTTPSProxyConnection.connectr   c             C   s   t j| |||dS )N)r;   )r   r>   )r   r@   rA   r;   r   r   r   r>      s    zHTTPSProxyConnection.putrequestc             C   s   t j|  | jd| j d S )Nz
User-Agent)r/   r?   rH   r!   )r   r   r   r   r?      s    
z'HTTPSProxyConnection._add_proxy_headers)r   )r   r   r   rI   r<   r   r.   r   r,   r>   r?   r   r   r   r   rS      s   
rS   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   rF   decode)rB   r   r   r   idn_puny_to_unicode   s    
rZ   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 NrX   )r   Zustrencode)rB   r   r   r   idn_ascii_to_puny  s    
r\   )rE   Zencodings.idnaZ	encodingsrK   platformr   Zrhnr   r   r   r   r   r   r   rU   ImportErrorZhttp.clientZclientZxmlrpc.clientr	   r   r/   rI   rR   rS   rZ   r\   r   r   r   r   <module>
   s,   
S,&.