
    h:,                        S r SSKrSSKrSSKrSSKr SSKrSSK
JrJr  SSKr
SrSr\R                   " \5      rSS0r S	 rS
 rSSSSSSS\4S jr " S S\R.                  5      r " S S\5      rg! \ a    Sr	 Nef = f)z3Implements file-like objects for reading from http.    NT)
bytebuffer	constantsi   )httphttpszAccept-Encodingidentityc                     [         R                  R                  U 5      nUR                  [        ;   d   eUR
                  UR                  -   nSUR                  S5      -   n[        UR                  US9$ )N/)schemeuri_path)	urllibparseurlsplitr
   SCHEMESnetlocpathlstripdict)uri_as_string	split_urir   s      I/home/james-whalen/.local/lib/python3.13/site-packages/smart_open/http.py	parse_urir   &   sd    %%m4Iw&&&)..0HX__S))Hy''(;;    c                 b    [         R                  R                  [        U5      n[        X40 UD6$ N)
smart_openutilscheck_kwargsopen)urimodetransport_paramskwargss       r   open_urir#   /   s+    **41ABF$V$$r   Fc
                     U[         R                  :X  a[  [        XXX4UXhUS9
n
[        R                  R                  [        R                  R                  U 5      R                  5      U
l	        U
$ [        SU-  5      e)u/  Implement streamed reader from a web site.

Supports Kerberos and Basic HTTP authentication.

Parameters
----------
url: str
    The URL to open.
mode: str
    The mode to open using.
kerberos: boolean, optional
    If True, will attempt to use the local Kerberos credentials
user: str, optional
    The username for authenticating over HTTP
password: str, optional
    The password for authenticating over HTTP
cert: str/tuple, optional
    if String, path to ssl client cert file (.pem). If Tuple, (‘cert’, ‘key’)
headers: dict, optional
    Any headers to send in the request. If ``None``, the default headers are sent:
    ``{'Accept-Encoding': 'identity'}``. To use no headers at all,
    set this variable to an empty dict, ``{}``.
session: object, optional
    The requests Session object to use with http get requests.
    Can be used for OAuth2 clients.
buffer_size: int, optional
    The buffer size to use when performing I/O.

Note
----
If neither kerberos or (user, password) are set, will connect
unauthenticated, unless set separately in headers.

)buffer_sizekerberosuserpasswordcertheaderssessiontimeoutz(http support for mode %r not implemented)r   READ_BINARYSeekableBufferedInputBaseosr   basenamer   r   urlparsenameNotImplementedError)r   r    r&   r'   r(   r)   r*   r,   r+   r%   fobjs              r   r   r   4   so    H y$$$(;tg

 GG$$V\\%:%:3%?%D%DE	!"Lt"STTr   c            	       v    \ rS rSrSrS\SSSSSSS4	S jrS r\S 5       r	S r
S	 rS
 rSS jrSS jrS rSrg)BufferedInputBased   NrFc           	      d   U	=(       d    [         U l        U(       a  SS KnUR                  5       nOUb  Ub  XV4nOS nX0l        X l        Uc  [        R                  5       U l        OXl        Xl	        U R                  R                  UUUSU R                  U R                  S9U l        U R                  R                  (       d  U R                  R                  5         U R                  R                  U R                  5      U l        [         R"                  " U5      U l        SU l        S U l        g )Nr   T)authr)   streamr*   r,   )requestsr+   requests_kerberosHTTPKerberosAuthr%   r    _HEADERScopyr*   r,   getresponseokraise_for_statusiter_content
_read_iterr   
ByteBuffer_read_buffer_current_posraw)selfurlr    r%   r&   r'   r(   r)   r*   r+   r,   r=   r:   s                r   __init__BufferedInputBase.__init__g   s     *($$557D("6#DD&	?#==?DL"L((LLLL ) 
 }}MM**,--44T5E5EF&11+>
 r   c                 n    [         R                  S5        U R                  (       d  SU l        SU l        gg)zFlush and close this stream.zclose: calledN)loggerdebugclosedrB   rF   rK   s    r   closeBufferedInputBase.close   s(    _%{{ DM"DO r   c                     U R                   S L $ r   )rB   rS   s    r   rR   BufferedInputBase.closed   s    }}$$r   c                     g)z+Return True if the stream can be read from.T rS   s    r   readableBufferedInputBase.readable   s    r   c                     g)NFrY   rS   s    r   seekableBufferedInputBase.seekable   s    r   c                 "    [         R                  ezUnsupported.ioUnsupportedOperationrS   s    r   detachBufferedInputBase.detach       %%%r   c                 X   [         R                  SU5        U R                  c  gUS:X  a  gUS:  a?  [        U R                  5      S:X  a&  U R                  R
                  R                  5       nGOUS:  a@  U R                  R                  5       U R                  R
                  R                  5       -   nO[        U R                  5      U:  a  [         R                  SU R                  U5        U R                  R                  U R                  5      nUS:X  a:  U R                  R                  5       nU =R                  [        U5      -  sl        U$ [        U R                  5      U:  a  M  U R                  R                  U5      nU =R                  [        U5      -  sl        U$ )z.
Mimics the read call to a filehandle object.
zreading with size: %dr   r   z:http reading more content at current_pos: %d with size: %d)
rP   rQ   rB   lenrH   rJ   readrI   fillrF   )rK   sizeretval
bytes_reads       r   ri   BufferedInputBase.read   sS    	,d3== 19AX#d//0A5]]&&++-FAX&&++-0A0A0F0F0HHFd''(4/P%%t "..33DOOD
?!..335F%%V4%!M d''(4/ &&++D1FS[(r   c                      U R                  US9$ )zThis is the same as read().)rk   )ri   rK   rk   s     r   read1BufferedInputBase.read1   s    yydy##r   c                 v    U R                  [        U5      5      nU(       d  gX!S[        U5      & [        U5      $ )zDRead up to len(b) bytes into b, and return the number of bytes
read.r   N)ri   rh   )rK   bdatas      r   readintoBufferedInputBase.readinto   s3     yyQ *3t94yr   )
rI   rH   rF   r%   r*   r    rJ   rB   r+   r,   ))__name__
__module____qualname____firstlineno__rB   DEFAULT_BUFFER_SIZErM   rT   propertyrR   rZ   r]   rd   ri   rq   rv   __static_attributes__rY   r   r   r6   r6   d   s[    H!$2EdTtT+`# % %&!F$r   r6   c            	       ^    \ rS rSrSrS\SSSSSSS4	S jrSS jrS rS	 r	SS
 jr
SS jrSrg)r.      zz
Implement seekable streamed reader from a web site.
Supports Kerberos, client certificate and Basic HTTP authentication.
r8   FNc                    Xl         U	=(       d    [        U l        U(       a  SSKnUR	                  5       U l        OUb  Ub	  XV4U l        OSU l        Uc  [        R                  5       U l        OXl        Xpl	        Xl
        X0l        X l        U R                  5       U l        U R                  R                  (       d  U R                  R!                  5         ["        R%                  SU R                  U R                  R&                  5        [)        U R                  R                  R+                  SS5      5      U l        U R                  R                  R+                  SS5      R/                  5       S:g  U l        U R                  R3                  U R                  5      U l        [6        R8                  " U5      U l        SU l        SU l        g)	a  
If Kerberos is True, will attempt to use the local Kerberos credentials.
If cert is set, will try to use a client certificate
Otherwise, will try to use "basic" HTTP authentication via username/password.

If none of those are set, will connect unauthenticated.
r   Nzself.response: %r, raw: %rzContent-Lengthrx   zAccept-Ranges none)rL   r<   r+   r=   r>   r:   r?   r@   r*   r)   r,   r%   r    _partial_requestrB   rC   rD   rP   rQ   rJ   intrA   content_lengthlower	_seekablerE   rF   r   rG   rH   rI   )rK   rL   r    r%   r&   r'   r(   r)   r*   r+   r,   r=   s               r   rM   "SeekableBufferedInputBase.__init__   sS    *($)::<DI("6(DIDI?#==?DL"L	&	--/}}MM**,14==$--BSBST!$--"7"7";";<Lb"QR ..22?BGMMOSYY--44T5E5EF&11+>
 r   c                 Z   [         R                  SX5        U[        R                  ;  a  [	        S[        R                  -  5      eU R                  5       (       d  [        S5      eU[        R                  :X  a  UnOGU[        R                  :X  a  U R                  U-   nO#U[        R                  :X  a  U R                  U-   nU R                  S:X  a  [        R                  R                  WSS9nO([        R                  R                  WU R                  S9nU R                  U:X  a  U R                  $ [         R                  SU R                  U5        X0l	        X0R                  :X  a4  SU l        SU l        U R"                  R%                  5         U R                  $ U R'                  U5      nUR(                  (       aV  X@l        U R                  R+                  U R,                  5      U l        U R"                  R%                  5         U R                  $ SU l        U R                  $ )zSeek to the specified position.

:param int offset: The offset in bytes.
:param int whence: Where the offset is from.

Returns the position after seeking.z seeking to offset: %r whence: %rz"invalid whence, expected one of %rzstream is not seekablerx   N)maxvalz0http seeking from current_pos: %d to new_pos: %d)rP   rQ   r   WHENCE_CHOICES
ValueErrorr]   OSErrorWHENCE_STARTWHENCE_CURRENTrI   
WHENCE_ENDr   r   r   clamprB   rF   rH   emptyr   rC   rE   r%   )rK   offsetwhencenew_posrB   s        r   seekSeekableBufferedInputBase.seek   s    	7H111AID\D\\]]}}233Y+++Gy///''&0Gy+++))F2G"$ &&,,WT,BG &&,,WT=P=P,QG'$$$GIZIZ\cd#))) DM"DO##%     ,,W5H{{ ("&--"<"<T=M=M"N!!'')     !%   r   c                     U R                   $ r   )rI   rS   s    r   tellSeekableBufferedInputBase.tellP  s       r   c                     U R                   $ r   )r   )rK   argsr"   s      r   r]   "SeekableBufferedInputBase.seekableS  s    ~~r   c                 "    [         R                  er`   ra   rp   s     r   truncate"SeekableBufferedInputBase.truncateV  rf   r   c           	          Ub:  U R                   R                  S[        R                  R	                  U5      05        U R
                  R                  U R                  U R                  SU R                  U R                   U R                  S9nU$ )NrangeT)r:   r;   r)   r*   r,   )r*   updater   r   make_range_stringr+   rA   rL   r:   r)   r,   )rK   	start_posrB   s      r   r   *SeekableBufferedInputBase._partial_requestZ  sv     LL**:*:*L*LY*W XY<<##HHLLLL $ 
 r   )rI   rH   rF   r   r:   r%   r)   r   r*   r    rJ   rB   r+   r,   rL   )r   r   )ry   rz   r{   r|   __doc__r}   rM   r   r   r]   r   r   r   rY   r   r   r.   r.      s?    
 "%2EdTtT7r.!`!&r   r.   )r   rb   loggingos.pathr/   urllib.parser   r<   ImportErrorMISSING_DEPSr   r   r   smart_open.utilsr}   r   	getLoggerry   rP   r?   r   r#   r   BufferedIOBaser6   r.   rY   r   r   <module>r      s    : 	    -   
			8	$ z*<%
 #4tT?R-U`z)) zzE 1 Ea  Ls   A3 3A>=A>