
    qh	>                        S r / SQrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKr SSKr SSKrS\R"                  < S\
R$                  < S3rSrSS jrS	 rSqS
 rSS jrS r " S S\5      r " S S\5      rS r " S S\5      r  " S S\5      r! " S S\5      r" " S S\ 5      r# " S S\5      r$ " S S\5      r%g! \ a    Sr Nf = f! \ a    Sr Nf = f) zN
This module contains the HTTP fetcher interface and several implementations.
)fetchgetDefaultFetchersetDefaultFetcherHTTPResponseHTTPFetchercreateHTTPFetcherHTTPFetchingError	HTTPError    Nzpython-openid/z ()   c                 :    [        5       nUR                  XU5      $ )zInvoke the fetch method on the default fetcher. Most users
should need only this method.

@raises Exception: any exceptions that may be raised by the default fetcher
)r   r   )urlbodyheadersfetchers       A/var/www/html/env/lib/python3.13/site-packages/openid/fetchers.pyr   r   *   s      !G==G,,    c                  @    [         c  [        5       n U $ [        5       n U $ )z@Create a default HTTP fetcher instance

prefers Curl to urllib2.)pycurlUrllib2FetcherCurlHTTPFetcherr   s    r   r   r   4   s'     ~ " N "#Nr   c                  B    [         c  [        [        5       5        [         $ )zReturn the default fetcher instance
if no fetcher has been set, it will create a default fetcher.

@return: the default fetcher
@rtype: HTTPFetcher
)_default_fetcherr   r    r   r   r   r   F   s     +-.r   c                 4    U b  U(       d  U q g[        U 5      q g)a  Set the default fetcher

@param fetcher: The fetcher to use as the default HTTP fetcher
@type fetcher: HTTPFetcher

@param wrap_exceptions: Whether to wrap exceptions thrown by the
    fetcher wil HTTPFetchingError so that they may be caught
    easier. By default, exceptions will be wrapped. In general,
    unwrapped fetchers are useful for debugging of fetching errors
    or if your fetcher raises well-known exceptions that you would
    like to catch.
@type wrap_exceptions: bool
N)r   ExceptionWrappingFetcher)r   wrap_exceptionss     r   r   r   U   s     o"3G<r   c                  x    [        5       n [        U [        5      (       a  U R                  n [        U [        5      $ )z>Whether the currently set HTTP fetcher is a Curl HTTP fetcher.)r   
isinstancer   r   r   r   s    r   	usingCurlr!   j   s.    !G'344//g//r   c                   8    \ rS rSrSrSrSrSrSrSS jr	S r
Srg)r   r   zXXX document attributesNc                 4    Xl         X l        X0l        X@l        g N)	final_urlstatusr   r   )selfr&   r'   r   r   s        r   __init__HTTPResponse.__init__y   s    "	r   c                 p    SU R                   R                  < SU R                  < SU R                  < S3$ )N<z status z for >)	__class____name__r'   r&   r(   s    r   __repr__HTTPResponse.__repr__   s&    *...*A*A4;;*...: 	:r   r   r&   r   r'   )NNNN)r/   
__module____qualname____firstlineno____doc__r   r'   r   r&   r)   r1   __static_attributes__r   r   r   r   r   r   s#    !GFDI:r   r   c                   "    \ rS rSrSrSS jrSrg)r      z
This class is the interface for openid HTTP fetchers.  This
interface is only important if you need to write a new fetcher for
some reason.
Nc                     [         e)aL  
This performs an HTTP POST or GET, following redirects along
the way. If a body is specified, then the request will be a
POST. Otherwise, it will be a GET.


@param headers: HTTP headers to include with the request
@type headers: {str:str}

@return: An object representing the server's HTTP response. If
    there are network or protocol errors, an exception will be
    raised. HTTP error responses, like 404 or 500, do not
    cause exceptions.

@rtype: L{HTTPResponse}

@raise Exception: Different implementations will raise
    different errors based on the underlying HTTP library.
)NotImplementedError)r(   r   r   r   s       r   r   HTTPFetcher.fetch   s
    ( "!r   r   NN)r/   r4   r5   r6   r7   r   r8   r   r   r   r   r      s    "r   r   c                 P    [         R                  R                  U 5      nUS   S;   $ )Nr
   )httphttps)urllibparseurlparse)r   parseds     r   _allowedURLrF      s&    \\""3'F!9)))r   c                   "    \ rS rSrSrSS jrSrg)r      zException that is wrapped around all exceptions that are raised
by the underlying fetcher when using the ExceptionWrappingFetcher

@ivar why: The exception that caused this exception
Nc                 :    [         R                  X5        Xl        g r%   )	Exceptionr)   why)r(   rK   s     r   r)   HTTPFetchingError.__init__   s    4%r   rK   r%   )r/   r4   r5   r6   r7   r)   r8   r   r   r   r   r      s    r   r   c                   .    \ rS rSrSr\\\4rS r	S r
Srg)r      zFetcher that wraps another fetcher, causing all exceptions

@cvar uncaught_exceptions: Exceptions that should be exposed to the
    user if they are raised by the fetch call
c                     Xl         g r%   r   )r(   r   s     r   r)   !ExceptionWrappingFetcher.__init__   s    r   c                      U R                   R                  " U0 UD6$ ! U R                   a    e   [        R                  " 5       S S u  p4Uc  Un[        US9e= f)N   rM   )r   r   uncaught_exceptionssysexc_infor   )r(   argskwargsexc_clsexc_insts        r   r   ExceptionWrappingFetcher.fetch   sd    
	2<<%%t6v66'' 		2 #r 2G"#11s	    :Ar   N)r/   r4   r5   r6   r7   
SystemExitKeyboardInterruptMemoryErrorrT   r)   r   r8   r   r   r   r   r      s!     &'8+F2r   r   c                   l    \ rS rSrSr\" \R                  R                  5      rS	S jr	S r
S rS rSrg)
r      z,An C{L{HTTPFetcher}} that uses urllib2.
    Nc                 h   [        U5      (       d  [        SU< 35      eUc  0 nUR                  S[        < S[        R
                  R                  < 35        [        U[        5      (       a
  [        USS9n[        R
                  R                  XUS9nS n U R                  U5      n[        R                  " U5         U R                  U5      sS S S 5        $ ! , (       d  f       g = f! [        R                  R                    aR  n[        R                  " U5         U R                  U5      nUsS S S 5        s S nA$ ! , (       d  f        S nAg = fS nAf[        R                  R"                  [$        R&                  R(                  4 a  ne S nAf[*         a  n[-        U5      eS nAff = f)NzBad URL scheme: 
User-Agentz Python-urllib/zutf-8)encoding)datar   )rF   
ValueError
setdefault
USER_AGENTrB   request__version__r    strbytesRequesturlopen
contextlibclosing_makeResponseerrorr	   URLErrorr@   clientBadStatusLinerJ   AssertionError)r(   r   r   r   requrl_resourcerK   resps           r   r   Urllib2Fetcher.fetch   sE   3S;<<?G<&(B(B*D 	E dC  0Dnn$$SW$E	&<<,L##L1)),7 211||%% 	##C())#. )(((( %%t{{'@'@A 	 	& %%	&sr   'C- C	C- 
C*&C- *C- -F1E!E4	E=F1
E	EE;F1FF1!F,,F1c                 <   [        5       nUR                  [        S-  5      Ul        UR	                  5       Ul        U R                  [        [        UR                  5       R                  5       5      5      5      Ul        [        US5      (       a  UR                  Ul        OSUl        U R                  UR                  R!                  SS5      5      u  p4UR!                  SS5      n UR                  R#                  U5      Ul        U$ ! [$         a     U$ f = f)z
Construct an HTTPResponse from the the urllib response. Attempt to
decode the response body from bytes to str if the necessary information
is available.
r   code   zcontent-type charsetlatin1)r   readMAX_RESPONSE_KBr   geturlr&   _lowerCaseKeysdictlistinfoitemsr   hasattrr{   r'   _parseHeaderValuegetdecoderJ   )r(   urllib2_responserx   _
extra_dictr~   s         r   rp   Urllib2Fetcher._makeResponse   s     ~$))/D*@A	)002**&++-335679 #V,,*//DKDK..LL^R02
 ..H5			((1DI   		s   + D 
DDc                 `    0 nUR                  5        H  u  p4XBUR                  5       '   M     U$ r%   )r   lower)r(   headers_dictnew_dictkvs        r   r   Urllib2Fetcher._lowerCaseKeys  s/     &&(DA"#QWWY )r   c                 *   UR                  SS5      n[        U5      S:X  a  US   0 4$ US   US   R                  S5      pC0 nU H8  n UR                  SS5      u  pxUR                  5       XWR                  5       '   M:     X54$ ! [         a     ML  f = f)z
Parse out a complex header value (such as Content-Type, with a value
like "text/html; charset=utf-8") into a main value and a dictionary of
extra information (in this case, 'text/html' and {'charset': 'utf8'}).
;   r
   =)splitlenstripre   )	r(   header_valuevalues
main_valueextra_valuesr   value_stringkeyvalues	            r   r    Urllib2Fetcher._parseHeaderValue  s     ##C+v;!!9b= #)!9fQiooc.BL
(L)//Q7
*/++-
99;' ) %%  s   	4B
BBr   r>   )r/   r4   r5   r6   r7   staticmethodrB   rh   rm   r   rp   r   r   r8   r   r   r   r   r      s1    
 6>>112G&:<&r   r   c                       \ rS rSrSrSrg)r	   -  zs
This exception is raised by the C{L{CurlHTTPFetcher}} when it
encounters an exceptional situation fetching a URL.
r   N)r/   r4   r5   r6   r7   r8   r   r   r   r	   r	   -  s     	r   r	   c                   8    \ rS rSrSrSrS rS rS rS
S jr	S	r
g)r   i6  z\
An C{L{HTTPFetcher}} that uses pycurl for fetching.
See U{http://pycurl.sourceforge.net/}.
   c                 R    [         R                  U 5        [        c  [        S5      eg )NzCannot find pycurl library)r   r)   r   RuntimeErrorr0   s    r   r)   CurlHTTPFetcher.__init__=  s&    T">;<< r   c                 `   UR                  S5        U Vs/ s H)  nSU;   d  M  UR                  5       R                  5       PM+     nn0 nU H<  n UR                  SS5      u  pVUR                  5       nUR                  5       nXdU'   M>     U$ s  snf ! [         a    [        SU< 35      ef = f)Nr
      ::r   z(Malformed HTTP header line in response: )seekr   r   r   re   r	   r   )r(   header_filelinelinesr   namer   s          r   _parseHeadersCurlHTTPFetcher._parseHeadersB  s     4?O;4$$,&$$&;OD*"jja0
 KKME ::<D!DM  ! P  *!%!) * **s   
B"BBB-c                     [        U5      $ r%   )rF   )r(   r   s     r   	_checkURLCurlHTTPFetcher._checkURLX  s     3r   Nc                   ^ [        [        R                  " 5       5      U R                  -   nU R                  nUc  0 nUR                  S[        < S[
        R                  < 35        / nUbA  UR                  5        H-  u  pxU< SU< 3n	UR                  U	R                  5       5        M/     [
        R                  " 5       n
 U
R                  [
        R                  S5        U(       a   U
R                  [
        R                  U5        Ub@  U
R                  [
        R                  S5        U
R                  [
        R                  U5        US:  Ga   U R!                  U5      (       d  [#        SU< 35      e[$        R&                  " 5       mU4S jn[$        R&                  " 5       nU
R                  [
        R(                  U5        U
R                  [
        R*                  UR,                  5        U
R                  [
        R.                  U5        U
R                  [
        R0                  [2        R4                  R5                  U5      5        U
R7                  5         U R9                  U5      nU
R;                  [
        R<                  5      nUS;   aC  UR?                  S	5      nUc  [#        S
U-  5      eU
R                  [
        R                  S5        OQ[A        5       nXl!        Xl"        Xl#        TRI                  5       RK                  5       Ul&        UU
RO                  5         $ U[        [        R                  " 5       5      -
  nUS:  a  GM   [#        SU< 35      e! U
RO                  5         f = f)Nrb    z: r   r
   zFetching URL not allowed: c                 ^   > TR                  5       S[        -  :  a  gTR                  U 5      $ )Nr   r
   )tellr   write)chunkrd   s    r   
write_data)CurlHTTPFetcher.fetch.<locals>.write_data  s(    yy{d_&<= #zz%00r   )r   i.  i/  i3  locationz)Redirect (%s) returned without a locationzTimed out fetching: )(inttimeALLOWED_TIMErf   rg   r   versionr   appendencodeCurlsetoptNOSIGNAL
HTTPHEADERPOST
POSTFIELDSr   r	   ioBytesIOWRITEFUNCTIONHEADERFUNCTIONr   TIMEOUTURLopenidurinormperformr   getinfoRESPONSE_CODEr   r   r   r'   r&   getvaluer   r   close)r(   r   r   r   stopoffheader_listheader_namer   headercr   response_header_dataresponse_headersr{   rx   rd   s                   @r   r   CurlHTTPFetcher.fetch]  s   499;$"3"33?G<&0&..C	E -4]]_)%0,?""6==?3 .= KKM8	HHV__a(**K8 a(**D1'~~c**#c$LMMzz|1 (*zz|$--z:..0D0J0JK-V^^%;%;C%@A		#'#5#56J#K yy!5!56//*..z:C{'G$NP P HHV[[!,
 (>D#3L"&K%(N $ 6 6 8DI GGI	 S--S 'V >??GGIs   IM% ,'M% M% %M7r   r>   )r/   r4   r5   r6   r7   r   r)   r   r   r   r8   r   r   r   r   r   6  s#     L=
, 
Ir   r   c                   :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )HTTPLib2Fetcheri  zA fetcher that uses C{httplib2} for performing HTTP
requests. This implementation supports HTTP caching.

@see: http://bitworking.org/projects/httplib2/
c                    > [         c  [        S5      e[        [        U ]  5         [         R
                  " U5      U l         SU R                   l        g)z@param cache: An object suitable for use as an C{httplib2}
cache. If a string is passed, it is assumed to be a
directory name.
NzJCannot find httplib2 library. See http://bitworking.org/projects/httplib2/F)httplib2r   superr   r)   Httpforce_exception_to_status_code)r(   cacher.   s     r   r)   HTTPLib2Fetcher.__init__  sO    
   N O O 	ot-/ !e, 8=4r   c           
         U(       a  SnOSnUc  0 nUR                  S5      (       d%  UR                  S5      (       d  [        SU< 35      eU R                  R                  XX#S9u  pV US   n[        UR                  5       U[        [        UR                  5       5      5      UR                  S	9$ ! [         a*    UR
                  (       a   eUR                  S:w  d   eUn Nwf = f)
zxPerform an HTTP request

@raises Exception: Any exception that can be raised by httplib2

@see: C{L{HTTPFetcher.fetch}}
r   GETzhttp://zhttps://zURL is not a HTTP URL: )r   r   zcontent-locationr|   r3   )
startswithre   r   rh   KeyErrorpreviousr'   r   r   r   r   r   )r(   r   r   r   methodhttplib2_responsecontentr&   s           r   r   HTTPLib2Fetcher.fetch  s     FF?G y))S^^J-G-GCBCC%)]]%:%:d &; &5"	)*<=I !/55789$++	/ 	/  	(1111 %++s222I	s   *B3 31C'&C')r   r%   r>   )	r/   r4   r5   r6   r7   r)   r   r8   __classcell__)r.   s   @r   r   r     s    =$+/ +/r   r   r>   )T)&r7   __all__urllib.requestrB   urllib.errorurllib.parsehttp.clientr@   r   r   rU   rn   r   openid.urinormr   ImportErrorr   ri   platformrg   r   r   r   r   r   r   r!   objectr   r   rF   rJ   r   r   r   r	   r   r   r   r   r   <module>r     s  
      	 
    )/(:(:CLLI
-	  =*0:6 :$"& "<*		 	2{ 24\&[ \&~	! 	pk pfD/k D/[  H  Fs"   C C CCC$#C$