
    lc                     p    d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 dZ
d Zdd	ZddZd Zd ZdS )zFCommon functions for working with docstrings.

For internal use only.
    N   )compression)	transportz*    smart_open/doctools.py magic goes herec                 
   | sg S t          j        |                               d          }g }|r/|d         dk    r#|                    d           |r|d         dk    #|sg S |                    d           |                    d           |r|d         r|                    d                              dd          \  }}g }|rr|d                             d          rW|                    |                    d                                                     |r|d                             d          Wd|v r<|                    |                                |                                |f           |r|d         |S )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       optional)inspectcleandocsplitpop
startswithappendstrip)	docstringlinesretvalnametype_descriptions         3lib/python3.11/site-packages/smart_open/doctools.pyextract_kwargsr      s   \  	Y''--d33EF  E!H, 		!  E!H,   		IIaLLL	IIaLLL
 FE!H Fiill((a00e 	5a++F33 	5uyy||1133444  	5a++F33 	5 	FMM4::<<DEEE  FE!H F M     c                     t          j                    }| D ]C\  }}}|                    ||d|d           |D ]}|                    |d|d           D|                                S )a  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)kwargslpadbufr   r   r   lines          r   to_docstringr&   f   s    > +--C$* 3 3 e[		$$eee4555 	3 	3DIIdddDDD12222	3<<>>r   r
   c                     t           j                            t           j                            t                              }t           j                            |dd          }	 t          |          5 }t          |          }ddd           n# 1 swxY w Y   |                    d          }|                    d          }||dz   |dz
           }d                     fd	|D                       S # t          $ r  d
z   cY S w xY w)aO  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:
      r   c                 B    g | ]}t          j        d d|          z   S )z^  r   )resub).0r%   indents     r   
<listcomp>z4extract_examples_from_readme_rst.<locals>.<listcomp>   s,    KKKTr4!8!88KKKr   zSee README.rst)
ospathdirnameabspath__file__joinopenlistindex	Exception)r.   curr_dirreadme_pathfinr   startends   `      r    extract_examples_from_readme_rstr?      s;   " wrwx8899H',,x|<<K)+ 	#IIE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	=>>kk:;;eAgc!em$wwKKKKUKKKLLL ) ) )((((()s7   %C6 4BC6 BC6 BAC6 6DDc           	         t          j                    }t                      }t          j                            t          j                            t                              }t          j        |          5  t          d           t                       t          t          j                                                  D ]	\  }}|t          j        k    s||v r|                    |           t          j                            |j        |          }|d|d}t          d|z             t          ddt#          |          z  z             t          d|j                            d          d         z             t                       t)          |j        j                  }|rt          t-          |d	
                     t          d           t          d           t                       t          t/                                 t          d           t          d           t                       t1          j                    D ]}	t          d|	z             t                       t          d           d d d            n# 1 swxY w Y   | j        r9| j                            t6          |                                          | _        d S d S )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   setr0   r1   r2   r4   
contextlibredirect_stdoutprintsortedr   	_REGISTRYitems	NO_SCHEMEaddrelpathlen__doc__r   r   r6   r&   r?   r   get_supported_extensionsreplacePLACEHOLDERr!   )
fr$   seen	root_pathscheme	submodulerM   headingr"   	extensions
             r   tweak_open_docstringrZ      s   
+--C55D 9 9::I		#C	(	( d dKLLL!'	(;(A(A(C(C!D!D 	: 	:FI,, 	T0A HHYgooi&8	oJJG#)667773G(W$%%%(cCLL01222(Y.44T::1==>>>GGG#IN$:;;F :l6888999nn.00111Z[[[/000$=?? 	* 	*I*y())))bccc=d d d d d d d d d d d d d d dF 	y CI%%k3<<>>BB			C Cs   7HJJJc                 L   t          j                    }t                      }g }g }t          t          j                                                  D ]o\  }}|t          j        k    s||v r|                    |           |	                    |           	 |
                    |j                   `# t          $ r Y lw xY wt          j        |          5  t          d           t                       |D ]}t          d|z             t                       t          d           t                       |D ]}t          d|z             	 d d d            n# 1 swxY w Y   | j        r9| j                            t$          |                                          | _        d S d S )Nz    Supported URI schemes are:rC   z    Valid URI examples::)r   r   rD   rH   r   rI   rJ   rK   r   rL   extendURI_EXAMPLESAttributeErrorrE   rF   rG   rO   rQ   rR   r!   )rS   r$   rT   schemesexamplesrV   rW   examples           r   tweak_parse_uri_docstringrb      s   
+--C55DGH#I$7$=$=$?$?@@ 	 		Y(( 	I,= 	v	OOI23333 	 	 	D	 
	#C	(	( 	( 	(./// 	' 	'F*v%&&&&())) 	( 	(G*w&''''	(	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	y CI%%k3<<>>BB			C Cs%   B11
B>=B>A7EE E)r   )r
   )rO   rE   r   r   os.pathr0   r+   r   r   r   rR   r   r&   r?   rZ   rb    r   r   <module>re      s    
      				  				            :I I IX$ $ $ $N) ) ) )<*C *C *CZC C C C Cr   