Ë
    æš¾jê  ã                  ó$  — 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
mZ ddlZe
rddlmZ ddlmZ  ej"                  e«      Zg d¢ZdZdd	„Zdd
„Zddd„Zddd„Zdd„Zdd„Z G d„ dej8                  «      Z G d„ dej:                  «      Zy)z(Helper functions for documentation, etc.é    )ÚannotationsN)ÚIOÚTYPE_CHECKINGÚAny)ÚCallable)ÚTracebackType)Ús3Ús3nÚs3aÚgcsÚgsz0///smart_open.utils.QUESTION_MARK_PLACEHOLDER///c                óö   — t        j                  | «      }|j                  j                  «       D ��ci c]9  \  }}|j                  t         j
                  j                  k7  r||j                  “Œ; c}}S c c}}w )zRReturn a ``{name: default}`` mapping for every default-valued kwarg of `kallable`.)ÚinspectÚ	signatureÚ
parametersÚitemsÚdefaultÚ	ParameterÚempty)Úkallabler   ÚnameÚparams       úZ/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/smart_open/utils.pyÚinspect_kwargsr      sh   € ä×!Ñ! (Ó+€Ið %×/Ñ/×5Ñ5Ó7÷áˆD�%Ø�=‰=œG×-Ñ-×3Ñ3Ò3ð 	ˆe�m‰mÑóð ùó s   ³>A5c                óþ   — t        t        | «      «      }t        |«      D �cg c]	  }||vsŒ|‘Œ }}|j                  «       D ��ci c]  \  }}||v sŒ||“Œ }}}|rt        j	                  d|«       |S c c}w c c}}w )a^  Check which keyword arguments the callable supports.

    Args:
        kallable: A function or method to test.
        kwargs: The keyword arguments to check.  If the callable doesn't support any
            of these, a warning message will get printed.

    Returns:
        A dictionary of argument names and values supported by the callable.
    z*ignoring unsupported keyword arguments: %r)Úsortedr   r   ÚloggerÚwarning)r   ÚkwargsÚsupported_keywordsÚkÚunsupported_keywordsÚvÚsupported_kwargss          r   Úcheck_kwargsr%   (   s€   € ô  ¤¨xÓ 8Ó9ÐÜ'-¨f£~ÖU !¸ÐBTÒ9TšAÐUÐÐUØ+1¯<©<«>×U¡ ! Q¸QÐBTÒ=T˜˜1™ÐUÐÑUáÜ�‰ÐCÐEYÔZàÐùò VùÛUs   ¢	A4¬A4ÁA9ÁA9c                ó6   — |�t        | |«      } t        | |«      S )z÷Clamp a numeric value to a specific range.

    Args:
        value: The value to clamp.
        minval: The lower bound.
        maxval: The upper bound.

    Returns:
        The clamped value.  It will be in the range ``[minval, maxval]``.
    )ÚminÚmax)ÚvalueÚminvalÚmaxvals      r   Úclampr,   =   s#   € ð ÐÜ�E˜6Ó"ˆÜˆu�fÓÐó    c                óp   — | €|€d}t        |«      ‚| €dn
t        | «      }|€dn
t        |«      }d|› d|› �S )ap  Create a byte range specifier in accordance with RFC-2616.

    Args:
        start: The start of the byte range.  If unspecified, stop indicated offset from EOF.
        stop: The end of the byte range.  If unspecified, indicates EOF.

    Returns:
        A byte range specifier.

    Raises:
        ValueError: If neither ``start`` nor ``stop`` are specified.
    z7make_range_string requires either a stop or start valueÚ zbytes=ú-)Ú
ValueErrorÚstr)ÚstartÚstopÚmsgÚ	start_strÚstop_strs        r   Úmake_range_stringr8   M   sM   € ð  €}˜˜ØGˆÜ˜‹oÐØ�m‘¬¨U«€IØ�\‰r¤s¨4£y€HØ�I�;˜a ˜zÐ*Ð*r-   c                óÂ   — | j                  dd«      \  }}|j                  dd«      \  }}|j                  dd«      \  }}|t        |«      t        |«      t        |«      fS )a½  Extract units, start, stop, and length from a content range header like "bytes 0-846981/846982".

    Assumes a properly formatted content-range header from S3.
    See werkzeug.http.parse_content_range_header for a more robust version.

    Args:
        content_range: The content-range header to parse.

    Returns:
        A tuple ``(units, start, stop, length)`` of one string and three integers
        from the content-range header.
    ú é   ú/r0   )ÚsplitÚint)Úcontent_rangeÚunitsÚnumbersÚrangeÚlengthr3   r4   s          r   Úparse_content_rangerD   e   s]   € ð #×(Ñ(¨¨aÓ0�N€Eˆ7Ø—M‘M # qÓ)�M€Eˆ6Ø—+‘+˜c 1Ó%�K€Eˆ4Ø”#�e“*œc $›i¬¨V«Ð4Ð4r-   c                ó¤  — t         j                  j                  | d¬«      }d}|j                  t        v rEd| v rAt
        | vr9t
        }| j                  d|«      } t         j                  j                  | d¬«      }|€|S |j                  j                  |d«      }t         j                  j                  |j                  |j                  |dd«      S )aß  This is a hack to prevent the regular urlsplit from splitting around question marks.

    A question mark (?) in a URL typically indicates the start of a
    querystring, and the standard library's urlparse function handles the
    querystring separately.  Unfortunately, question marks can also appear
    _inside_ the actual URL for some schemas like S3, GS.

    Replaces question marks with a special placeholder substring prior to
    splitting.  This work-around behavior is disabled in the unlikely event the
    placeholder is already part of the URL.  If this affects you, consider
    changing the value of QUESTION_MARK_PLACEHOLDER to something more suitable.

    See Also:
        - https://bugs.python.org/issue43882
        - https://github.com/python/cpython/blob/3.14/Lib/urllib/parse.py
        - https://github.com/piskvorky/smart_open/issues/285
        - https://github.com/piskvorky/smart_open/issues/458
        - ``smart_open/utils.py:QUESTION_MARK_PLACEHOLDER``
    F)Úallow_fragmentsNú?r/   )
ÚurllibÚparseÚurlsplitÚschemeÚWORKAROUND_SCHEMESÚQUESTION_MARK_PLACEHOLDERÚreplaceÚpathÚSplitResultÚnetloc)ÚurlÚsrÚplaceholderrO   s       r   Úsafe_urlsplitrU   x   s²   € ô( 
�‰×	Ñ	˜s°EÐ	Ó	:€Bà€KØ	‡y�yÔ&Ñ&¨3°#©:Ô:SÐ[^Ñ:^ô 0ˆØ�k‰k˜#˜{Ó+ˆÜ�\‰\×"Ñ" 3¸Ð"Ó>ˆàÐØˆ	à�7‰7�?‰?˜;¨Ó,€DÜ�<‰<×#Ñ# B§I¡I¨r¯y©y¸$ÀÀBÓGÐGr-   c                  ó(   — e Zd ZdZ	 	 	 	 	 	 	 	 dd„Zy)ÚTextIOWrapperzI`io.TextIOWrapper` subclass that does not close the buffer on exceptions.c                ó*   — |€| j                  «        yy)at  Call close on underlying buffer only when there was no exception.

        Without this patch, TextIOWrapper would call self.buffer.close() during
        exception handling, which is unwanted for e.g. s3 and azure. They only call
        self.close() when there was no exception (self.terminate() otherwise) to avoid
        committing unfinished/failed uploads.
        N)Úclose)ÚselfÚexc_typeÚexc_valÚexc_tbs       r   Ú__exit__zTextIOWrapper.__exit__£   s   € ð ÐØ�J‰J�Lð r-   N)r[   útype[BaseException] | Noner\   úBaseException | Noner]   úTracebackType | NoneÚreturnÚNone)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r^   © r-   r   rW   rW       s0   „ ÙSðà,ðð &ðð %ð	ð
 
ôr-   rW   c                  óh   ‡ — e Zd ZU dZdZded<   d
ˆ fd„Zdd„Z	 	 	 	 	 	 	 	 dˆ fd„Zdd„Z	dd	„Z
ˆ xZS )ÚFileLikeProxyzHWrap an `outer` file-like object so that closing it also closes `inner`..r   Ú_FileLikeProxy__innerc                ó2   •— t         ‰| �  |«       || _        y )N)ÚsuperÚ__init__rk   )rZ   ÚouterÚinnerÚ	__class__s      €r   rn   zFileLikeProxy.__init__¹   s   ø€ Ü‰Ñ˜ÔØˆ�r-   c                ó6   — | j                   j                  «       S )zAThis explicit proxy method is only required for pylance ref #916.)Ú__wrapped__Ú	__enter__©rZ   s    r   rt   zFileLikeProxy.__enter__½   s   € à×Ñ×)Ñ)Ó+Ð+r-   c                ó¦   •— 	 t         ‰| �  |||«      | j                  j                  |||«       S # | j                  j                  |||«       w xY w)zExit inner after exiting outer.)rm   r^   rk   )rZ   r[   Ú	exc_valueÚ	tracebackrq   s       €r   r^   zFileLikeProxy.__exit__Á   sG   ø€ ð	BÜ‘7Ñ# H¨i¸ÓCà�L‰L×!Ñ! (¨I°yÕAøˆD�L‰L×!Ñ! (¨I°yÕAús	   ƒ1 ±Ac                ó6   — | j                   j                  «       S )z3Delegate iteration to the wrapped file-like object.)rs   Ú__next__ru   s    r   rz   zFileLikeProxy.__next__Í   s   € à×Ñ×(Ñ(Ó*Ð*r-   c                ó  — 	 | j                   j                  «       | j                  | j                   k7  r| j                  j                  «        S S # | j                  | j                   k7  r| j                  j                  «        w w xY w)z3Close both the wrapped object and the inner object.)rs   rY   rk   ru   s    r   rY   zFileLikeProxy.closeÑ   sh   € ð	%Ø×#Ñ#×)Ñ)Ó+à�|‰|˜t×/Ñ/Ò/Ø—‘×"Ñ"Õ$ð 0øˆt�|‰|˜t×/Ñ/Ò/Ø—‘×"Ñ"Õ$ð 0ús   ‚A Á6B)ro   úIO[Any]rp   r|   rb   rc   )rb   r   )r[   r_   rw   r`   rx   ra   rb   r   )rb   rc   )rd   re   rf   rg   rk   Ú__annotations__rn   rt   r^   rz   rY   Ú__classcell__)rq   s   @r   rj   rj   ´   sT   ø… ÙRà€GˆSÓõó,ð
Bà,ð
Bð (ð
Bð (ð	
Bð
 
õ
Bó+÷%r-   rj   )r   úCallable[..., Any]rb   údict[str, Any])r   r   r   r€   rb   r€   )r   N)r)   r>   r*   r>   r+   ú
int | Nonerb   r>   )NN)r3   r�   r4   r�   rb   r2   )r?   r2   rb   ztuple[str, int, int, int])rR   r2   rb   zurllib.parse.SplitResult)rg   Ú
__future__r   r   ÚioÚloggingÚurllib.parserH   Útypingr   r   r   ÚwraptÚcollections.abcr   Útypesr   Ú	getLoggerrd   r   rL   rM   r   r%   r,   r8   rD   rU   rW   ÚObjectProxyrj   rh   r-   r   ú<module>rŒ      s�   ðñ /å "ã Û 	Û Û ß )Ñ )ã áÝ(Ý#à	ˆ×	Ñ	˜8Ó	$€â6Ð ØNÐ óóô*ô +ó05ó&%HôP�B×$Ñ$ô ô(#%�E×%Ñ%õ #%r-   