
    Mim&                        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/var/www/eduai.edurigo.com/storigo/production/storigo_env/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           	      t   Xl         Xpl        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        X0l        X l        Uc  [        R                  5       U l        OXl        Xl        U R                  R                  U R                   U R                  U R                  SU R                  U R                  S9U l        U R                  R                  (       d  U R                  R!                  5         ["        R$                  " U5      U l        SU l        g )Nr   T)authr)   streamr*   r,   )urlr)   requestsr+   requests_kerberosHTTPKerberosAuthr:   r%   r    _HEADERScopyr*   r,   getresponseokraise_for_statusr   
ByteBuffer_read_buffer_current_pos)selfr<   r    r%   r&   r'   r(   r)   r*   r+   r,   r>   s               r   __init__BufferedInputBase.__init__g   s     	*($)::<DI("6(DIDI&	?#==?DL"L((HHLLLL ) 
 }}MM**,&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closedrC   rG   rI   s    r   closeBufferedInputBase.close   s)    _%{{ DM $D r   c                     U R                   S L $ r   )rC   rP   s    r   rO   BufferedInputBase.closed   s    }}$$r   c                     g)z+Return True if the stream can be read from.T rP   s    r   readableBufferedInputBase.readable   s    r   c                     g)NFrV   rP   s    r   seekableBufferedInputBase.seekable   s    r   c                 "    [         R                  ezUnsupported.ioUnsupportedOperationrP   s    r   detachBufferedInputBase.detach       %%%r   c                    US:  a  [        SU 35      e[        R                  SU5        U R                  (       d  US:X  a  gUS:X  a  [	        U R
                  5      (       a@  U R
                  R                  5       U R                  R                  R                  5       -   nOU R                  R                  R                  5       nO[	        U R
                  5      U:  aO  U R
                  R                  U R                  R                  5      S:X  a  O[	        U R
                  5      U:  a  MO  U R
                  R                  U5      nU =R                  [	        U5      -  sl
        U$ )z.
Mimics the read call to a filehandle object.
zsize must be >= -1, got zreading with size: %dr   r   )
ValueErrorrM   rN   rO   lenrG   readrC   rawfillrH   )rI   sizeretvals      r   rh   BufferedInputBase.read   s    "97v>??,d3;;$!)2:4$$%%**//1DMM4E4E4J4J4LL**//1 d''(4/$$))$--*;*;<A d''(4/ &&++D1FS[(r   c                      U R                  US9$ )zThis is the same as read().)rk   )rh   rI   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)rh   rg   )rI   bdatas      r   readintoBufferedInputBase.readinto   s3     yyQ *3t94yr   )rH   rG   r:   r%   r)   r*   r    rC   r+   r,   r<   )re   )__name__
__module____qualname____firstlineno__rC   DEFAULT_BUFFER_SIZErJ   rQ   propertyrO   rW   rZ   ra   rh   rp   ru   __static_attributes__rV   r   r   r6   r6   d   sZ    H!$2EdTtT'X% % %&4$r   r6   c            	       l   ^  \ rS rSrSrS\SSSSSSS4	U 4S jjrSS jrS rS	 r	SS
 jr
SS jrSrU =r$ )r.      zz
Implement seekable streamed reader from a web site.
Supports Kerberos, client certificate and Basic HTTP authentication.
r8   FNc                   > [         TU ]  XX4XVXxX5
        [        U R                  R                  R                  SS5      5      U l        U R                  R                  R                  SS5      R                  5       S:g  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.
zContent-Lengthre   zAccept-Ranges noneN)	superrJ   intrC   r*   rB   content_lengthlower	_seekable)rI   r<   r    r%   r&   r'   r(   r)   r*   r+   r,   	__class__s              r   rJ   "SeekableBufferedInputBase.__init__   so     	K44Zak!$--"7"7";";<Lb"QR ..22?BGMMOSYYr   c                    [         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  a-  SU l        U R                   R#                  5         U R                  $ U R%                  U5      nUR&                  (       a,  X@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 seekablere   N)maxvalz0http seeking from current_pos: %d to new_pos: %d)rM   rN   r   WHENCE_CHOICESrf   rZ   OSErrorWHENCE_STARTWHENCE_CURRENTrH   
WHENCE_ENDr   r   r   clamprC   rG   empty_partial_requestrD   )rI   offsetwhencenew_posrC   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##%     ,,W5H{{ (!!'')     !%   r   c                     U R                   $ r   )rH   rP   s    r   tellSeekableBufferedInputBase.tell  s       r   c                     U R                   $ r   )r   )rI   argsr"   s      r   rZ   "SeekableBufferedInputBase.seekable  s    ~~r   c                 "    [         R                  er]   r^   ro   s     r   truncate"SeekableBufferedInputBase.truncate"  rc   r   c           	         U R                   R                  5       nUb"  [        R                  R	                  U5      US'   U R
                  R                  U R                  U R                  SU R                  UU R                  S9nU$ )NrangeT)r:   r;   r)   r*   r,   )r*   rA   r   r   make_range_stringr+   rB   r<   r:   r)   r,   )rI   	start_posr*   rC   s       r   r   *SeekableBufferedInputBase._partial_request&  sw    ,,##% )//AA)LGG<<##HHLL $ 
 r   )rH   r   r   rC   )r   r   )rw   rx   ry   rz   __doc__r{   rJ   r   r   rZ   r   r   r}   __classcell__)r   s   @r   r.   r.      sE    
 "%2EdTtTZ(,!\!& r   r.   )r   r_   loggingos.pathr/   urllib.parser   r=   ImportErrorMISSING_DEPSr   r   r   smart_open.utilsr{   r   	getLoggerrw   rM   r@   r   r#   r   BufferedIOBaser6   r.   rV   r   r   <module>r      s    : 	    -   
			8	$ z*<%
 #4tT?R-U`m)) m`_ 1 _G  Ls   A3 3A>=A>