Ë
    æš¾jõ2  ã                  ó|  — d Z ddlmZ ddlZddlZddlZddlZddlm	Z	m
Z
 	 ddlZddlZddlmZmZ e	rddlmZ ddlmZ d	Zd
Z ej0                  e«      Z G d„ de
«      ZddiZ	 dd„Zdd„Zdddddddef	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z G d„ dej@                  «      Z! G d„ de!«      Z"y# e$ r dZY Œ”w xY w)znImplements file-like objects for reading from http; ``kerberos=True`` needs the ``requests-kerberos`` package.é    )ÚannotationsN)ÚTYPE_CHECKINGÚ	TypedDictT)Ú
bytebufferÚ	constants)ÚWriteableBuffer)ÚTransportParamsi   )ÚhttpÚhttpsc                  ó"   — e Zd ZU ded<   ded<   y)Ú_HTTPUriÚstrÚschemeÚuri_pathN)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__© ó    úY/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/smart_open/http.pyr   r   $   s   … ØƒKØ„Mr   r   zAccept-EncodingÚidentityc                óà   — t         j                  j                  | «      }|j                  t        v sJ ‚|j
                  |j                  z   }d|j                  d«      z   }|j                  |dœS )zAParse an ``http://`` or ``https://`` URI into its path component.ú/)r   r   )ÚurllibÚparseÚurlsplitr   ÚSCHEMESÚnetlocÚpathÚlstrip)Úuri_as_stringÚ	split_urir   s      r   Ú	parse_urir$   2   sb   € ä—‘×%Ñ% mÓ4€IØ×ÑœwÑ&Ð&Ð&à×Ñ )§.¡.Ñ0€HØ�X—_‘_ SÓ)Ñ)€HØ×&Ñ&°HÑ=Ð=r   ÚBufferedInputBasec                ód   — t         j                  j                  t        |«      }t        | |fi |¤ŽS )zAOpen an HTTP/HTTPS URI using the given mode and transport params.)Ú
smart_openÚutilsÚcheck_kwargsÚopen)ÚuriÚmodeÚtransport_paramsÚkwargss       r   Úopen_urir/   <   s-   € ä×Ñ×*Ñ*¬4Ð1AÓB€FÜ��TÑ$˜VÑ$Ð$r   Fc
                óú   — |t         j                  k(  rXt        | ||	|||||||¬«
      }
t        j                  t
        j                  j                  | «      j                  «      |
_	        |
S d|›d�}t        |«      ‚)aà  Implement streamed reader from a web site.

    Supports Kerberos and Basic HTTP authentication.

    Args:
        uri: The URL to open.
        mode: The mode to open using.
        kerberos: If True, will attempt to use the local Kerberos credentials.
        user: The username for authenticating over HTTP.
        password: The password for authenticating over HTTP.
        cert: If a string, path to ssl client cert file (``.pem``).
            If a tuple, ``('cert', 'key')``.
        headers: 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, ``{}``.
        timeout: Request timeout in seconds.
        session: The ``requests.Session`` object to use with HTTP GET requests.
            Can be used for OAuth2 clients.
        buffer_size: The buffer size to use when performing I/O.

    Returns:
        A file-like object opened for reading.

    Raises:
        NotImplementedError: If ``mode`` is anything other than ``"rb"``.

    Note:
        If neither ``kerberos`` nor ``(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 z not implemented)r   ÚREAD_BINARYÚSeekableBufferedInputBaseÚ	posixpathÚbasenamer   r   Úurlparser    ÚnameÚNotImplementedError)r+   r,   r2   r3   r4   r5   r6   r8   r7   r1   ÚfobjÚmsgs               r   r*   r*   B   sƒ   € ðT Œy×$Ñ$Ò$Ü(ØØØ#ØØØØØØØô
ˆô ×&Ñ&¤v§|¡|×'<Ñ'<¸SÓ'A×'FÑ'FÓGˆŒ	ØˆØ" 4 (Ð*:Ð
;€CÜ
˜cÓ
"Ð"r   c            	      ó¾   — e Zd ZU dZded<   dZded<   dedddddddf		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	„Zdd
„Ze	dd„«       Z
dd„Zdd„Zdd„Zddd„Zddd„Zdd„Zy)r%   zDBuffered HTTP reader implementing the `io.BufferedIOBase` interface.r   r>   Nzrequests.Response | NoneÚresponseÚrFc                ób  — || _         || _        |	xs t        | _        |rdd l}|j                  «       | _        n|�|�
||f| _        nd | _        || _        || _        |€t        j                  «       | _        n|| _        |
| _        | j                  j                  | j                   | j                  | j                  d| j                  | j                  ¬«      | _        | j                  j                  s| j                  j!                  «        t#        j$                  |«      | _        d| _        y )Nr   T)Úauthr5   Ústreamr6   r8   )Úurlr5   Úrequestsr7   Úrequests_kerberosÚHTTPKerberosAuthrF   r1   r,   Ú_HEADERSÚcopyr6   r8   ÚgetrC   ÚokÚraise_for_statusr   Ú
ByteBufferÚ_read_bufferÚ_current_pos)ÚselfrH   r,   r1   r2   r3   r4   r5   r6   r7   r8   rJ   s               r   Ú__init__zBufferedInputBase.__init__…   sý   € ð ˆŒØˆŒ	ØÒ*¤(ˆŒáÛ$à)×:Ñ:Ó<ˆD�IØÐ (Ð"6Ø˜xÐ(ˆD�IàˆDŒIà&ˆÔØˆŒ	àˆ?Ü#Ÿ=™=›?ˆD�Là"ˆDŒLàˆŒàŸ™×(Ñ(Ø�H‰HØ—‘Ø—‘ØØ—L‘LØ—L‘Lð )ó 
ˆŒð �}‰}×ÒØ�M‰M×*Ñ*Ô,ä:D×:OÑ:OÐP[Ó:\ˆÔØˆÕr   c                ód   — t         j                  d«       | j                  sd| _        d| _        yy)zFlush and close this stream.zclose: calledN)ÚloggerÚdebugÚclosedrC   rR   ©rT   s    r   ÚclosezBufferedInputBase.close¼   s)   € ä�‰�_Ô%Ø�{Š{Ø ˆDŒMØ $ˆDÕð r   c                ó   — | j                   du S )z$Return True if the stream is closed.N)rC   rZ   s    r   rY   zBufferedInputBase.closedÃ   s   € ð �}‰} Ð$Ð$r   c                 ó   — y)z+Return True if the stream can be read from.Tr   rZ   s    r   ÚreadablezBufferedInputBase.readableÈ   s   € àr   c                 ó   — y)z<Return False; the base HTTP reader does not support seeking.Fr   rZ   s    r   ÚseekablezBufferedInputBase.seekableÌ   s   € àr   c                ó"   — t         j                  ‚©zUnsupported.©ÚioÚUnsupportedOperationrZ   s    r   ÚdetachzBufferedInputBase.detachÓ   ó   € ä×%Ñ%Ð%r   c                ó,  — |€d}|dk  rd|› �}t        |«      ‚t        j                  d|«       | j                  | j                  }}|�|�|dk(  ry|dk(  rRt        |«      r,|j                  «       |j                  j                  «       z   }nh|j                  j                  «       }nMt        |«      |k  r.|j                  |j                  «      dk(  rnt        |«      |k  rŒ.|j                  |«      }| xj                  t        |«      z  c_	        |S )z+Mimic the read call to a filehandle object.éÿÿÿÿzsize must be >= -1, got zreading with size: %dr   r   )
Ú
ValueErrorrW   rX   rR   rC   ÚlenÚreadÚrawÚfillrS   )rT   ÚsizerA   ÚbufrC   Úretvals         r   rl   zBufferedInputBase.read×   sö   € àˆ<ØˆDØ�"Š9Ø,¨T¨FÐ3ˆCÜ˜S“/Ð!ä�‰Ð,¨dÔ3Ø×)Ñ)¨4¯=©=ˆXˆØˆ;˜(Ð*¨d°aªiØà�2Š:Ü�3ŒxØŸ™› h§l¡l×&7Ñ&7Ó&9Ñ9‘à!Ÿ™×*Ñ*Ó,‘ô �c“(˜T’/Ø—8‘8˜HŸL™LÓ)¨QÒ.Øô �c“(˜T“/ð —X‘X˜d“^ˆFà×ÒœS ›[Ñ(ÕØˆr   c                ó&   — | j                  |¬«      S )zThis is the same as read().)ro   )rl   ©rT   ro   s     r   Úread1zBufferedInputBase.read1ó   s   € à�y‰y˜dˆyÓ#Ð#r   c                ó¢   — t        |«      j                  d«      }| j                  t        |«      «      }|sy||dt        |«       t        |«      S )zLRead up to ``len(b)`` bytes into ``b``, and return the number of bytes read.ÚBr   N)Ú
memoryviewÚcastrl   rk   )rT   ÚbÚmvÚdatas       r   ÚreadintozBufferedInputBase.readinto÷   sG   € ä˜‹]×Ñ Ó$ˆØ�y‰yœ˜R›Ó!ˆÙØØˆˆ;ŒS�‹YˆÜ�4‹yÐr   ©rH   r   r,   r   r1   Úintr2   Úboolr3   ú
str | Noner4   r€   r5   ústr | tuple[str, str] | Noner6   údict[str, str] | Noner7   úrequests.Session | Noner8   úfloat | NoneÚreturnÚNone)r…   r†   )r…   r   )r…   zio.RawIOBase)ri   )ro   ú
int | Noner…   Úbytes)ry   r   r…   r~   )r   r   r   Ú__doc__r   rC   ÚDEFAULT_BUFFER_SIZErU   r[   ÚpropertyrY   r^   r`   rf   rl   rt   r|   r   r   r   r%   r%      sÛ   … ÙNà
ƒIØ)-€HÐ&Ó-ð
 Ø.ØØØ#Ø-1Ø)-Ø+/Ø $ð2àð2ð ð2ð ð	2ð
 ð2ð ð2ð ð2ð +ð2ð 'ð2ð )ð2ð ð2ð 
ó2ón%ð ò%ó ð%óóó&ôô8$ôr   c            	      ó�   ‡ — e Zd ZdZdedddddddf		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zddd„Zdd„Zdd„Zddd	„Z	ddd
„Z
ˆ xZS )r:   a•  Seekable streamed reader from a web site.

    Supports Kerberos, client certificate and Basic HTTP authentication.
    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.
    rD   FNc                ó2  •— t         ‰| �  |||||||||	|
«
       | j                  €J ‚t        | j                  j                  j                  dd«      «      | _        | j                  j                  j                  dd«      j                  «       dk7  | _        y )NzContent-Lengthri   zAccept-RangesÚ Únone)	ÚsuperrU   rC   r~   r6   rN   Úcontent_lengthÚlowerÚ	_seekable)rT   rH   r,   r1   r2   r3   r4   r5   r6   r7   r8   Ú	__class__s              €r   rU   z"SeekableBufferedInputBase.__init__  s‹   ø€ ô 	‰Ñ˜˜d K°¸4ÀÈ4ÐQXÐZaÐcjÔkØ�}‰}Ð(Ð(Ð(Ü! $§-¡-×"7Ñ"7×";Ñ";Ð<LÈbÓ"QÓRˆÔð Ÿ™×.Ñ.×2Ñ2°?ÀBÓG×MÑMÓOÐSYÑYˆ�r   c                óŽ  — t         j                  d||«       |t        j                  vrdt        j                  ›�}t	        |«      ‚| j                  «       sd}t        |«      ‚| j                  }|€d}t        |«      ‚|t        j                  k(  r|}n2|t        j                  k(  r| j                  |z   }n| j                  |z   }| j                  dk(  r"t        j                  j                  |d¬«      }n+t        j                  j                  || j                  ¬«      }| j                  |k(  r| j                  S || j                  kD  rL|| j                  z
  t        |«      k  r1|j!                  || j                  z
  «       || _
        | j                  S t         j                  d| j                  |«       || _
        || j                  k(  r#d| _        |j%                  «        | j                  S | j'                  |«      }|j(                  r#|| _        |j%                  «        | j                  S d| _        | j                  S )	aU  Seek to the specified position.

        Args:
            offset: The offset in bytes.
            whence: Where the offset is from.

        Returns:
            The position after seeking.

        Raises:
            ValueError: If ``whence`` is not one of ``WHENCE_CHOICES``.
            OSError: If the stream is not seekable.
        z seeking to offset: %r whence: %rz invalid whence, expected one of zstream is not seekableNzseek on closed streamri   )Úmaxvalz0http seeking from current_pos: %d to new_pos: %d)rW   rX   r   ÚWHENCE_CHOICESrj   r`   ÚOSErrorrR   ÚWHENCE_STARTÚWHENCE_CURRENTrS   r‘   r'   r(   Úclamprk   rl   rC   ÚemptyÚ_partial_requestrO   )rT   ÚoffsetÚwhencerA   rp   Únew_posrC   s          r   ÚseekzSeekableBufferedInputBase.seek#  s  € ô 	�‰Ð7¸ÀÔHØœ×1Ñ1Ñ1Ø4´Y×5MÑ5MÐ4PÐQˆCÜ˜S“/Ð!à�}‰}ŒØ*ˆCÜ˜#“,Ðà×ÑˆØˆ;Ø)ˆCÜ˜#“,Ðà”Y×+Ñ+Ò+Ø‰GØ”y×/Ñ/Ò/Ø×'Ñ'¨&Ñ0‰Gà×)Ñ)¨FÑ2ˆGà×Ñ "Ò$Ü ×&Ñ&×,Ñ,¨W¸TÐ,ÓB‰Gä ×&Ñ&×,Ñ,¨W¸T×=PÑ=PÐ,ÓQˆGà×Ñ Ò'Ø×$Ñ$Ð$ð �T×&Ñ&Ò&¨7°T×5FÑ5FÑ+FÌ#ÈcË(Ò+RØ�H‰H�W˜t×0Ñ0Ñ0Ô1Ø 'ˆDÔØ×$Ñ$Ð$ä�‰ÐGÈ×IZÑIZÐ\cÔdà#ˆÔà�d×)Ñ)Ò)Ø ˆDŒMØ�I‰IŒKð × Ñ Ð ð ×,Ñ,¨WÓ5ˆHØ�{Š{Ø (�”Ø—	‘	”ð × Ñ Ð ð !%�”à× Ñ Ð r   c                ó   — | j                   S )z#Return the current stream position.)rS   rZ   s    r   ÚtellzSeekableBufferedInputBase.telle  s   € à× Ñ Ð r   c                ó   — | j                   S )zAReturn True if the server reports it accepts byte-range requests.)r“   )rT   Úargsr.   s      r   r`   z"SeekableBufferedInputBase.seekablei  s   € à�~‰~Ðr   c                ó"   — t         j                  ‚rb   rc   rs   s     r   Útruncatez"SeekableBufferedInputBase.truncatem  rg   r   c                ó  — | j                   j                  «       }|�"t        j                  j	                  |«      |d<   | j
                  j                  | j                  | j                  d| j                  || j                  ¬«      S )NÚrangeT)rF   rG   r5   r6   r8   )r6   rM   r'   r(   Úmake_range_stringr7   rN   rH   rF   r5   r8   )rT   Ú	start_posr6   s      r   r�   z*SeekableBufferedInputBase._partial_requestq  ss   € Ø—,‘,×#Ñ#Ó%ˆØÐ Ü)×/Ñ/×AÑAÀ)ÓLˆG�GÑà�|‰|×ÑØ�H‰HØ—‘ØØ—‘ØØ—L‘Lð  ó 
ð 	
r   r}   )r   )rž   r~   rŸ   r~   r…   r~   )r…   r~   )r¥   Úobjectr.   r¬   r…   r   )N)ro   r‡   r…   r~   )r«   r‡   r…   zrequests.Response)r   r   r   r‰   rŠ   rU   r¡   r£   r`   r§   r�   Ú__classcell__)r”   s   @r   r:   r:     sÂ   ø„ ñð Ø.ØØØ#Ø-1Ø)-Ø+/Ø $ðZàðZð ðZð ð	Zð
 ðZð ðZð ðZð +ðZð 'ðZð )ðZð ðZð 
õZô0@!óD!óô&÷
ð 
r   r:   )r"   r   r…   r   )r+   r   r,   r   r-   r	   r…   r%   )r+   r   r,   r   r2   r   r3   r€   r4   r€   r5   r�   r6   r‚   r8   r„   r7   rƒ   r1   r~   r…   r%   )#r‰   Ú
__future__r   rd   Úloggingr;   Úurllib.parser   Útypingr   r   rI   ÚImportErrorÚMISSING_DEPSÚsmart_open.utilsr'   r   r   Ú	_typeshedr   Úsmart_open._typingr	   rŠ   r   Ú	getLoggerr   rW   r   rL   r$   r/   r*   ÚBufferedIOBaser%   r:   r   r   r   ú<module>r¹      s?  ðñ uå "ã 	Û Û Û ß +ðÛó ß ,áÝ)å2à Ð Ø
€à	ˆ×	Ñ	˜8Ó	$€ôˆyô ð
 ˜zÐ*€ðó>ó%ð ØØØ)-Ø%)Ø Ø'+Ø*ð:#Ø	ð:#à
ð:#ð ð:#ð ð	:#ð
 ð:#ð 'ð:#ð #ð:#ð ð:#ð %ð:#ð ð:#ð ó:#ôz˜×)Ñ)ô ôD|
Ð 1õ |
øð] ò Ø‚Lðús   ¢B1 Â1B;Â:B;