
    h}                         S r SSKrSSKrSSKrSSKrSSKr\R                  " \5      r	/ SQr
SrS rS rSS jrSS jrS	 rS
 r " S S\R$                  5      r " S S\R&                  5      rg)z(Helper functions for documentation, etc.    N)s3s3ns3us3agsz0///smart_open.utils.QUESTION_MARK_PLACEHOLDER///c                     [         R                  " U 5      nUR                  R                  5        VVs0 s H;  u  p#UR                  [         R
                  R                  :w  d  M/  X#R                  _M=     snn$ s  snnf ! [         a`     [         R                  " U 5      u  pEpgO! [         a    0 s s $ f = fU(       d  0 s $ U[        U5      * S  n[        [        X5      5      s $ f = fN)inspect	signature
parametersitemsdefault	ParameteremptyAttributeError
getargspec	TypeErrorlendictzip)	kallabler   nameparamargsvarargskeywordsdefaultssupported_keywordss	            J/home/james-whalen/.local/lib/python3.13/site-packages/smart_open/utils.pyinspect_kwargsr       s    
%%h/	"  )3399;
;}} 1 1 7 77  D--;
 	
 
  7	070B0B80L-D8X 	 I		 I!3x=./2C*5667sF   B .A;'A;
C+B&%C+&B72C+6B77C+#C+*C+c                    [        [        U 5      5      n[        U5       Vs/ s H  o3U;  d  M
  UPM     nnUR                  5        VVs0 s H  u  p5X2;   d  M  X5_M     nnnU(       a  [        R	                  SU5        U$ s  snf s  snnf )ag  Check which keyword arguments the callable supports.

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

Returns
-------
dict
    A dictionary of argument names and values supported by the callable.
z*ignoring unsupported keyword arguments: %r)sortedr    r   loggerwarning)r   kwargsr   kunsupported_keywordsvsupported_kwargss          r   check_kwargsr*   6   s{       x 89'-f~U~!BT9TA~U+1<<>U>!Q=T>UCEYZ VUs   	BB
BBc                 8    Ub  [        X5      n [        X5      n U $ )a  Clamp a numeric value to a specific range.

Parameters
----------
value: numeric
    The value to clamp.

minval: numeric
    The lower bound.

maxval: numeric
    The upper bound.

Returns
-------
numeric
    The clamped value.  It will be in the range ``[minval, maxval]``.

)minmax)valueminvalmaxvals      r   clampr1   P   s#    ( E"EL    c                 x    U c  Uc  [        S5      eU c  SO
[        U 5      nUc  SO
[        U5      nSU< SU< 3$ )a?  Create a byte range specifier in accordance with RFC-2616.

Parameters
----------
start: int, optional
    The start of the byte range.  If unspecified, stop indicated offset from EOF.

stop: int, optional
    The end of the byte range.  If unspecified, indicates EOF.

Returns
-------
str
    A byte range specifier.

z7make_range_string requires either a stop or start value zbytes=-)
ValueErrorstr)startstop	start_strstop_strs       r   make_range_stringr<   j   sB    ( }RSSmUI\rs4yH%x00r2   c                     U R                  SS5      u  pUR                  SS5      u  p4UR                  SS5      u  pVU[        U5      [        U5      [        U5      4$ )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.

Parameters
----------
content_range: str
    The content-range header to parse.

Returns
-------
tuple (units: str, start: int, stop: int, length: int)
    The units and three integers from the content-range header.

    /r5   )splitint)content_rangeunitsnumbersrangelengthr8   r9   s          r   parse_content_rangerH      sW    " #((a0NEMM#q)ME++c1%KE#e*c$iV44r2   c                    [         R                  R                  U SS9nSnUR                  [        ;   aF  SU ;   a@  [
        U ;  a6  [
        nU R                  SU5      n [         R                  R                  U SS9nUc  U$ UR                  R                  US5      n[         R                  R                  UR                  UR                  USS5      $ )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.13/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?r4   )
urllibparseurlsplitschemeWORKAROUND_SCHEMESQUESTION_MARK_PLACEHOLDERreplacepathSplitResultnetloc)urlsrplaceholderrS   s       r   safe_urlsplitrY      s    * 
		sE		:BK	yy&&3#::S[^:^ 0kk#{+\\""3">	77??;,D<<##BIIryy$BGGr2   c                       \ rS rSrS rSrg)TextIOWrapper   c                 ,    Uc  U R                  5         gg)aL  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__TextIOWrapper.__exit__   s     JJL r2    N)__name__
__module____qualname____firstlineno__rc   __static_attributes__re   r2   r   r[   r[      s    	r2   r[   c                   D   ^  \ rS rSrSrU 4S jrU 4S jrS rS rSr	U =r
$ )FileLikeProxy   .c                 0   > [         TU ]  U5        X l        g r	   )super__init___FileLikeProxy__inner)r_   outerinner	__class__s      r   rp   FileLikeProxy.__init__   s    r2   c                    >  [         TU ]  " U0 UD6U R                  R                  " U0 UD6  $ ! U R                  R                  " U0 UD6  f = f)zExit inner after exiting outer.)ro   rc   rq   )r_   r   r%   rt   s      r   rc   FileLikeProxy.__exit__   sI    	37#T4V4LL!!4262DLL!!4262s	   / Ac                 6    U R                   R                  5       $ r	   )__wrapped____next__r_   s    r   rz   FileLikeProxy.__next__   s    ((**r2   c                     U R                   R                  5       U R                  U R                   :w  a  U R                  R                  5         $ $ ! U R                  U R                   :w  a  U R                  R                  5         f f = fr	   )ry   r^   rq   r{   s    r   r^   FileLikeProxy.close   sh    	%##))+||t///""$ 0t||t///""$ 0s   A 7B)__inner)rf   rg   rh   ri   rq   rp   rc   rz   r^   rj   __classcell__)rt   s   @r   rl   rl      s!    G3+% %r2   rl   )r   N)NN)__doc__r
   iologgingurllib.parserL   wrapt	getLoggerrf   r#   rP   rQ   r    r*   r1   r<   rH   rY   r[   ObjectProxyrl   re   r2   r   <module>r      sy    /  	   			8	$6 N 
<44165.&HR
B$$ 
%E%% %r2   