z\Vc@sdZddlZddlZddlZddlmZmZddlZddlTddlm Z ddl Z de fdYZ de fd YZd e fd YZdS( seM2Crypto support for Python's httplib. Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved.iN(turlsplitt urlunsplit(t*(t HTTPS_PORTtHTTPSConnectioncBsGeZdZeZdddZdZdZdZ dZ RS(sA This class allows communication via SSL using M2Crypto. cKsd|_|j}y|jdWntk r9nXy|jdWntk r^nXy|jdWntk rnX|rtdny|d|_Wn#tk rtjd|_nXt j ||||dS(Ntkey_filet cert_filet ssl_contextsunknown keyword argumenttsslv23( tNonetsessiontkeystremovet ValueErrortssl_ctxtKeyErrortSSLtContexttHTTPConnectiont__init__(tselfthosttporttstricttsslR ((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRs,       cCsd}xtj|j|jdtjD]\}}}}}d}zyjtj|jd|}|j dk r|j |j n|j |j|jf||_ d}dSWntj k r}|}nXWd|dk r|jnXq(W|dkr tdn|dS(Nitfamilys"Empty list returned by getaddrinfo(R tsockett getaddrinfoRRt SOCK_STREAMRt ConnectionRR t set_sessiontconnecttsockterrortclosetAssertionError(RR!Rt_R te((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyR.s(4   cCsdS(N((R((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyR"KscCs |jjS(N(R t get_session(R((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyR&\scCs ||_dS(N(R (RR ((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyR_sN( t__name__t __module__t__doc__Rt default_portR RRR"R&R(((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRs   tHTTPScBs eZeZddddZRS(tcKs`tj||||y|d|_Wn#tk rLtjd|_nX|j|j_dS(NRR(tHTTPRRRRRt_conn(RRRRR((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRgs  N(R'R(Rt_connection_classR R(((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyR+cstProxyHTTPSConnectioncBseZdZidd6dd6ZdZdZdddddZddd Zd Z d Z d Z d Z dZ dZRS(s An HTTPS Connection that uses a proxy and the CONNECT request. When the connection is initiated, CONNECT is first sent to the proxy (along with authorization headers, if supplied). If successful, an SSL connection will be established over the socket through the proxy and to the target host. Finally, the actual request is sent over the SSL connection tunneling through the proxy. iPthttpithttpssProxy-Authorizations User-AgentcKsAtj|||||||_||_d|_d|_dS(s Create the ProxyHTTPSConnection object. host and port are the hostname and port number of the proxy server. N(RRt _usernamet _passwordR t _proxy_autht _proxy_UA(RRRRtusernametpasswordR((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRs    icCsAt|\}}}}} |s1td|ny|jd\} } Wntk rc|} nXy| jd\} } WnItk r| } y|j|} Wqtk rtd|qXnX| |_t| |_tdd||| f}t j dkr$t j ||||nt j |||||dS(Nsunknown URL type: %st@t:sunknown protocol for: %sii(ii(RR tsplitt_portsRt _real_hosttintt _real_portRR tsyst version_infoRt putrequest(Rtmethodturlt skip_hosttskip_accept_encodingtprototnetloctpathtquerytfragmenttusername_passwordt host_portRRtrest((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRBs*     cCse|j|jjkr'||_n|j|jjkrN||_ntj|||dS(N(tlowert _UA_HEADERR6t _AUTH_HEADERR5Rt putheader(Rtheadertvalue((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRRs   cOs2|js|j|_ntj|||dS(N(R5t _encode_authRt endheaders(Rtargstkwargs((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRVs cCs|tj||jj|jt|j}|j|j}|dkrn|jt j d|n|j dS(NisProxy connection failed: %d( RRR tsendallt_get_connect_msgt HTTPResponsetbegintstatusR"RR!t _start_ssl(Rtresponsetcode((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRs     cCsd|j|jf}|d|j|jf}|jrV|d|j|jf}n|jr||d|j|jf}n|d}|S(s6 Return an HTTP CONNECT request to send to the proxy. sCONNECT %s:%d HTTP/1.1 s Host: %s:%d s%s: %s s (R=R?R6RPR5RQ(Rtmsg((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRZs   cCsFtj|j|j|_|jj|jj|jjdS(s* Make this connection's socket SSL-aware. N(RRRR t setup_ssltset_connect_statet connect_ssl(R((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyR^s  cCsO|jo|jsdSd|j|jf}tj|jdd}d|S(s> Encode the username and password for use in the auth header. s%s:%ss R,sBasic %sN(R3R4R tbase64t encodestringtreplace(Rtuserpasst enc_userpass((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRUs N(R'R(R)R<RQRPR RRBRRRVRRZR^RU(((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyR0qs     (R)tstringR@RturlparseRRRethttplibRRRRR-R+R0(((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyts    U