
    h                     r    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  SSKJ	r	  Sr
S rSS jrSS	 jrS
 rS rg)zFCommon functions for working with docstrings.

For internal use only.
    N   )compression)	transportz*    smart_open/doctools.py magic goes herec                    U (       d  / $ [         R                  " U 5      R                  S5      n/ nU(       a,  US   S:w  a#  UR                  S5        U(       a  US   S:w  a  M#  U(       d  / $ UR                  S5        UR                  S5        U H  nUR	                  5       (       d    U$ UR                  S5      (       + nU(       aJ  UR                  SS5      u  pVUR	                  5       UR	                  5       / pvnUR                  XVU/5        M  UR                  S5      nU(       d  M  US   S   R                  UR	                  5       5        M     U$ )	a  Extract keyword argument documentation from a function's docstring.

Parameters
----------
docstring: str
    The docstring to extract keyword arguments from.

Returns
-------
list of (str, str, list str)

str
    The name of the keyword argument.
str
    Its type.
str
    Its documentation as a list of lines.

Notes
-----
The implementation is rather fragile.  It expects the following:

1. The parameters are under an underlined Parameters section
2. Keyword parameters have the literal ", optional" after the type
3. Names and types are not indented
4. Descriptions are indented with 4 spaces
5. The Parameters section ends with an empty line.

Examples
--------

>>> docstring = '''The foo function.
... Parameters
... ----------
... bar: str, optional
...     This parameter is the bar.
... baz: int, optional
...     This parameter is the baz.
...
... '''
>>> kwargs = extract_kwargs(docstring)
>>> kwargs[0]
('bar', 'str, optional', ['This parameter is the bar.'])


r   
Parameters :r       )inspectcleandocsplitpopstrip
startswithappend)		docstringlineskwargslineis_arg_linenametype_descriptionis_description_lines	            M/home/james-whalen/.local/lib/python3.13/site-packages/smart_open/doctools.pyextract_kwargsr      s"   \ 	Y'--d3EF E!H,		! E!H, 		IIaL	IIaLzz|| M //#..**S!,KD'+zz|U[[]BDMM445"oof52JrN!!$**,/  M    c                     [         R                  " 5       nU  HD  u  p4nUR                  U< U< SU< S35        U H  nUR                  U< SU< S35        M     MF     UR                  5       $ )at  Reconstruct a docstring from keyword argument info.

Basically reverses :func:`extract_kwargs`.

Parameters
----------
kwargs: list
    Output from the extract_kwargs function
lpad: str, optional
    Padding string (from the left).

Returns
-------
str
    The docstring snippet documenting the keyword arguments.

Examples
--------

>>> kwargs = [
...     ('bar', 'str, optional', ['This parameter is the bar.']),
...     ('baz', 'int, optional', ['This parameter is the baz.']),
... ]
>>> print(to_docstring(kwargs), end='')
bar: str, optional
    This parameter is the bar.
baz: int, optional
    This parameter is the baz.

z: r   r   )ioStringIOwritegetvalue)r   lpadbufr   r   r   r   s          r   to_docstringr'   k   sZ    > ++-C$* [		$e45DIIdD12   %+ <<>r   c                 &   [         R                  R                  [         R                  R                  [        5      5      n[         R                  R                  USS5      n [        U5       n[        U5      nSSS5        WR                  S5      nUR                  S5      nXES-   US-
   nSR                  U Vs/ s H  op[        R                  " S	SU5      -   PM     sn5      $ ! , (       d  f       Nt= fs  snf ! [         a    U S
-   s $ f = f)a  Extract examples from this project's README.rst file.

Parameters
----------
indent: str
    Prepend each line with this string.  Should contain some number of spaces.

Returns
-------
str
    The examples.

Notes
-----
Quite fragile, depends on named labels inside the README.rst file.
z..z
README.rstNz.. _doctools_before_examples:
z.. _doctools_after_examples:
       z^  zSee README.rst)ospathdirnameabspath__file__joinopenlistindexresub	Exception)indentcurr_dirreadme_pathfinr   startendr   s           r    extract_examples_from_readme_rstr>      s    " wwrwwx89H'',,x|<K)+#IE =>kk:;Agc!e$wwUKUTr4!88UKLL 
 L )((()s7   #C> .C(:AC> =$C9!C> (
C62C> >DDc           	         [         R                  " 5       n[        5       n[        R                  R                  [        R                  R                  [        5      5      n[        R                  " U5         [        S5        [        5         [        [        R                  R                  5       5       GH  u  pEU[        R                  :X  d  XR;   a  M!  UR                  U5         UR                   n[        R                  R%                  UR                  US9nSR'                  U5      < SU< S3n[        SU-  5        [        SS[)        U5      -  -  5        [        SUR*                  R-                  S5      S	   -  5        [        5         [/        UR0                  R*                  5      n	U	(       d  GM  [        [3        U	S
S95        GM     [        S5        [        S5        [        5         [        [5        5       5        [        S5        [        S5        [        5         [6        R8                  " 5        H  n
[        SU
-  5        M     [        5         [        S5        S S S 5        U R*                  (       a4  U R*                  R;                  [<        UR?                  5       5      U l        g g ! ["         a    U/n GNf = f! , (       d  f       Nh= f)Nz;    smart_open supports the following transport mechanisms:)r<   /z ()z    %s~r   r   r   )r%   z    Examplesz    --------zJ    This function also supports transparent compression and decompression z    using the following codecs:    * %szR    The function depends on the file extension to determine the appropriate codec.) r!   r"   setr,   r-   r.   r0   
contextlibredirect_stdoutprintsortedr   	_REGISTRYitems	NO_SCHEMEaddSCHEMESAttributeErrorrelpathr1   len__doc__r   r   r2   r'   r>   r   get_supported_extensionsreplacePLACEHOLDERr$   )fr&   seen	root_pathscheme	submoduleschemesrO   headingr   	extensions              r   tweak_open_docstringr]      s   
++-C5D 9:I		#	#C	(KL!'	(;(;(A(A(C!DF,,,	0AHHY##++ ggooi&8&8	oJG#&88G#4g>G(W$%(cCL012(Y..44T:1==>G#INN$:$:;Fvl689' "E* 	nn.01Z[/0$==?I*y() @bcG 
)P 	yyII%%k3<<>B	 = " #!(# 
)	(s9   6A/K&J02CK8B*K0K=K KK
Kc                    [         R                  " 5       n[        5       n/ n/ n[        [        R
                  R                  5       5       Hi  u  pVU[        R                  :X  d  Xb;   a  M   UR                  U5         UR                  UR                  5         UR                  UR                  5        Mk     [        R                  " U5         [!        S5        [!        5         U H  n[!        SU-  5        M     [!        5         [!        S5        [!        5         U H  n[!        SU-  5        M     S S S 5        U R"                  (       a4  U R"                  R%                  [&        UR)                  5       5      U l        g g ! [         a     Nf = f! [         a    UR                  U5         GMc  f = f! , (       d  f       N= f)Nz    Supported URI schemes are:rC   z    Valid URI examples::)r!   r"   rD   rH   r   rI   rJ   rK   rL   extendURI_EXAMPLESrN   rM   r   rE   rF   rG   rQ   rS   rT   r$   )rU   r&   rV   rZ   examplesrX   rY   examples           r   tweak_parse_uri_docstringrc      s\   
++-C5DGH#I$7$7$=$=$?@Y(((I,=	OOI223	#NN9,,- A  
	#	#C	(./F*v%& ()G*w&'   
) 	yyII%%k3<<>B	 '  		
  	#NN6""	# 
)	(s1   =E?FA#F2?
FFF/.F/2
G )r+   )r   )rQ   rE   r   r!   os.pathr,   r5   r+   r   r   rT   r   r'   r>   r]   rc    r   r   <module>rf      sE   
   	  	  :Nb$N)</Cd"Cr   