ó z\Vc@s¸dZddlZddlZddlZddlmZmZddlZddlTddlm Z ddl Z de fd„ƒYZ de fd „ƒYZd e fd „ƒYZdS( seM2Crypto support for Python's httplib. Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved.iÿÿÿÿN(turlsplitt urlunsplit(t*(t HTTPS_PORTtHTTPSConnectioncBsGeZdZeZddd„Zd„Zd„Zd„Z d„Z RS(sA This class allows communication via SSL using M2Crypto. cKsd|_|jƒ}y|jdƒWntk r9nXy|jdƒWntk r^nXy|jdƒWntk rƒnX|r™tdƒ‚ny5|d|_t|jtjƒsÍt |jƒ‚Wn#t k rótjdƒ|_nXt j ||||ƒdS(Ntkey_filet cert_filet ssl_contextsunknown keyword argumenttsslv23( tNonetsessiontkeystremovet ValueErrortssl_ctxt isinstancetSSLtContexttAssertionErrortKeyErrortHTTPConnectiont__init__(tselfthosttporttstricttsslR ((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRs,      ( cCsd}xètj|j|jdtjƒD]Å\}}}}}d}zyjtj|jd|ƒ}|j dk rƒ|j |j ƒn|j |j|jfƒ||_ d}dSWntj k rÎ}|}nXWd|dk rì|jƒnXq(W|dkr tdƒ‚n|‚dS(Nitfamilys"Empty list returned by getaddrinfo(R tsockett getaddrinfoRRt SOCK_STREAMRt ConnectionRR t set_sessiontconnecttsockterrortcloseR(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 |jjƒS(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 RR!R$R'R (((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRs   tHTTPScBs eZeZdddd„ZRS(tcKsxtj||||ƒy|d|_Wn#tk rLtjdƒ|_nXt|jtƒset ‚|j|j_dS(NRR( tHTTPRRRRRRt_connRR(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,cstProxyHTTPSConnectioncBsˆeZdZidd6dd6ZdZdZddddd„Zddd „Zd „Z d „Z d „Z d „Z d„Z d„ZRS(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. iPthttpi»thttpssProxy-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.pyRƒs    icCsAt|ƒ\}}}}} |s1td|‚ny|jdƒ\} } Wntk rc|} nXy| jdƒ\} } WnItk rÈ| } y|j|} WqÉtk rÄtd|‚qÉXnX| |_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.pyRC‘s*     cCse|jƒ|jjƒkr'||_n|jƒ|jjƒkrN||_ntj|||ƒdS(N(tlowert _UA_HEADERR7t _AUTH_HEADERR6Rt putheader(Rtheadertvalue((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRS°s   cOs2|js|jƒ|_ntj|||ŽdS(N(R6t _encode_authRt endheaders(Rtargstkwargs((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRW¹s cCs|tj|ƒ|jj|jƒƒt|jƒ}|jƒ|j}|dkrn|jƒt j d|‚n|j ƒdS(NiÈsProxy connection failed: %d( RR!R"tsendallt_get_connect_msgt HTTPResponsetbegintstatusR$RR#t _start_ssl(Rtresponsetcode((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyR!Âs     cCsŠd|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@R7RQR6RR(Rtmsg((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyR[Òs   cCsFtj|j|jƒ|_|jjƒ|jjƒ|jjƒdS(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(R4R5R tbase64t encodestringtreplace(Rtuserpasst enc_userpass((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyRVäs N(R(R)R*R=RRRQR RRCRSRWR!R[R_RV(((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyR1qs     (R*tstringRARturlparseRRRfthttplibRRRRR.R,R1(((s7/usr/lib64/python2.7/site-packages/M2Crypto/httpslib.pyts    U