Ñò ñ1Mc @s¸dZddkZddkZddkZddklZlZddkZddkTddkl Z ddk 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|_|iƒ}y|idƒWntj onXy|idƒWntj onXy|idƒWntj onX|otdƒ‚ny4|d|_t|itiƒp t |i‚Wn%t j otidƒ|_nXt i ||||ƒdS(Ntkey_filet cert_filet ssl_contextsunknown keyword argumenttsslv23( tNonetsessiontkeystremovet ValueErrortssl_ctxt isinstancetSSLtContexttAssertionErrortKeyErrortHTTPConnectiont__init__(tselfthosttporttstricttsslR ((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyRs,   'cCsVti|iƒ|_|io|ii|iƒn|ii|i|ifƒdS(N( Rt ConnectionRtsockR t set_sessiontconnectRR(R((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyR.s cCsdS(N((R((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pytclose4scCs |iiƒS(N(Rt get_session(R((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyR EscCs ||_dS(N(R (RR ((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyRHsN( t__name__t __module__t__doc__Rt default_portR RRRR R(((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyRs   tHTTPScBs eZeZdddd„ZRS(tcKs|ti||||ƒy|d|_Wn%tj otidƒ|_nXt|itƒpt ‚|i|i_dS(NRR( tHTTPRRRRRRt_connRR(RRRRR((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyRPsN(R!R"Rt_connection_classR R(((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyR%LstProxyHTTPSConnectioncBsˆeZdZhdd6dd6ZdZdZddddd„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-AgentcKsAti|||||||_||_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/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyRls    ic CsKt|ƒ\}}}}} |ptd|‚ny|idƒ\} } Wntj o |} nXy| idƒ\} } WnMtj oA| } y|i|} WqÑtj otd|‚qÑXnX| |_t| ƒ|_tdd||| fƒ}t i djot i ||||ƒnt i |||||ƒ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/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyR<zs*  cCsi|iƒ|iiƒjo ||_n|iƒ|iiƒjo ||_nti|||ƒdS(N(tlowert _UA_HEADERR0t _AUTH_HEADERR/Rt putheader(Rtheadertvalue((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyRL™s   cCs.|ip|iƒ|_nti|ƒdS(N(R/t _encode_authRt endheaders(R((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyRP¢s cCs~ti|ƒ|ii|iƒƒt|iƒ}|iƒ|i}|djo|iƒt i d|‚n|i ƒdS(NiÈsProxy connection failed: %d( RRRtsendallt_get_connect_msgt HTTPResponsetbegintstatusRtsocketterrort _start_ssl(Rtresponsetcode((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyR«s     cCsŽd|i|if}|d|i|if}|io|d|i|if}n|io|d|i|if}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 (R7R9R0RJR/RK(Rtmsg((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyRR»s   cCsFti|i|iƒ|_|iiƒ|iiƒ|iiƒdS(s* Make this connection's socket SSL-aware. N(RRRRt setup_ssltset_connect_statet connect_ssl(R((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyRXÆs  cCsR|io|ipdSd|i|if}ti|ƒiddƒ}d|S(s> Encode the username and password for use in the auth header. s%s:%ss R&sBasic %sN(R-R.R tbase64t encodestringtreplace(Rtuserpasst enc_userpass((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyROÍs N(R!R"R#R6RKRJR RR<RLRPRRRRXRO(((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyR*Zs     (R#tstringR:RVturlparseRRR_thttplibRRRRR'R%R*(((s7/usr/lib/python2.6/vendor-packages/M2Crypto/httpslib.pyts    >