
    #HJj                    $   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/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/smart_open/utils.pyinspect_kwargsr      sm    !!(+I %//5577KD%==G--333 	emm7  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~!BT9TA~U+1<<>U>!QQBT=T1>UCEYZ VUs   	A4A4A9A9c                6    |t        | |      } t        | |      S )zClamp 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#     E6"uf    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\rs4yH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0NE7MM#q)ME6++c1%KE4#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    ( 
		sE		:BK	yy&&3#::S[^:^ 0kk#{+\\""3">	77??;,D<<##BIIryy$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     JJL 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#HiCLL!!(IyADLL!!(IyAs	   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///""$ 0t||t///""$ 0s   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GS,
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-   