
    #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 ddl	m
Z
mZmZ ddlmZmZ e
rddlmZ ej$                  d	k\  rd
ZdZndZdZddZdddZdddZddZddZy)zFCommon functions for working with docstrings.

For internal use only.
    )annotationsN)Path)TYPE_CHECKINGAnycast   )compression	transport)Callable)      z&smart_open/doctools.py magic goes here z*    smart_open/doctools.py magic goes here    c                p   | sg S t        j                  |       j                  d      }t        |      D ]"  \  }}|j	                         dk(  s||dz   d } n g S g }|D ]  }|j                         s |S |j                  d      rt|j                  d      sc|dd }d|vrB|j                  dd      \  }}|j                  |j                         d	|j                         r|j                         gng g       |j                  d      s|s|d
   d
   j                  |j                                 |S )a8  Extract keyword argument documentation from a Google-style ``Args:`` section.

    Args:
        docstring: The docstring to extract keyword arguments from.

    Returns:
        A list of ``[name, type, description_lines]`` triples. ``type`` is
        always an empty string since Google-style docstrings in this codebase
        don't carry argument types, and ``description_lines`` is a list of
        lines.

    Note:
        The implementation expects:

        1. The parameters are under an ``Args:`` header
        2. Argument lines start with 4 spaces of indent (``    name: desc``)
        3. Continuation lines for a description are indented with 8 spaces
        4. The ``Args:`` section ends with an empty line or another section header.

    Example:
        >>> docstring = '''The foo function.
        ... Args:
        ...     bar: This parameter is the bar.
        ...     baz: This parameter is the baz.
        ...
        ... '''
        >>> kwargs = extract_kwargs(docstring)
        >>> kwargs[0]
        ['bar', '', ['This parameter is the bar.']]
    
zArgs:r   Nr   z           :r   )inspectcleandocsplit	enumeraterstripstrip
startswithappend)	docstringlinesidxlinekwargsstrippednamedescs           ]/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/smart_open/doctools.pyextract_kwargsr&   )   s'   > 	Y'--d3Eu%	T;;=G##')$E &
 	 Fzz| M ??6"4??:+FABxH("!Q/JD$MM4::<tzz|djjl^QSTU??:&62JrN!!$**,/  M    c                    t        j                         }| D ]V  \  }}}|r|j                  | | d| d       n|j                  | | d       |D ]  }|j                  | d| d        X |j                         S )a  Reconstruct a docstring from keyword argument info.

    Basically reverses :func:`extract_kwargs`.

    Args:
        kwargs: Output from the :func:`extract_kwargs` function.
        lpad: Padding string (from the left).

    Returns:
        The docstring snippet documenting the keyword arguments.

    Example:
        >>> 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   z:
r   )ioStringIOwritegetvalue)r!   lpadbufr#   type_descriptionr    s          r%   to_docstringr1   g   s    . ++-C$* e[IItfBugR01IItfC()DIId4&+,   %+ <<>r'   c                     t          t        t              j                         j                  j                  dz  }	 |j                  d      }|j                  dd      d   }|j                  dd      d   }|j                  dd      d   j                  d	d      d   }|j                  d
      j                  d
      }dj                   fd|D              S # t        $ r  dz   cY S w xY w)a`  Extract examples from this project's README.md file.

    Args:
        indent: Prepend each line with this string.  Should contain some number
            of spaces.

    Returns:
        The examples as a single string.

    Note:
        Quite fragile, depends on the example markers and the fenced code block
        inside the README.md file.
    z	README.mdzutf-8)encodingz!<!-- doctools_before_examples -->r   z <!-- doctools_after_examples -->r   z	```pythonz```r   r   c              3  .   K   | ]  }|z   d z     yw)r   N ).0r    indents     r%   	<genexpr>z/extract_examples_from_readme.<locals>.<genexpr>   s     >v}t+s   zSee README.md)LPADr   __file__resolveparent	read_textr   rsplitr   join	Exception)r7   readme_pathtextbodyr   s   `    r%   extract_examples_from_readmerD      s     ~x.((*1188;FK	($$g$6zz=qA!Dzz<a@Czz+q)!,33E1=a@

4 &&t,ww>>>> (''(s   BC C.-C.c           
        t        j                         }t               }t        t              j
                  j
                  }t        dz   }t        j                  |      5  t        t         d       t                t        t        j                  j                               D ]0  \  }}|t        j                  k(  s||v r|j                  |       	 |j                   }t        t%        d|j                              j'                  |      }dj)                  dj+                  |      |      }	t        | |	        t        | dt-        |	      z          t        | |j.                  xs dj1                  t3        d            d	           t                t5        |j6                  j.                        }
|
st        t9        |
|
             3 t        t         d       t                t        t;        |             t        t         d       t                t        | d       t        | d       t                t=        j>                         D ]  }t        | d|         t                t        | d       ddd       | j.                  r4| j.                  jA                  tB        |jE                               | _        yy# t"        $ r |g}Y w xY w# 1 sw Y   ]xY w)zJInject transport, compression and example sections into ``f``'s docstring.r   zTransports:strz{} ({})/~r   
   r   )r-   	Examples:)r7   zCodecs:zGsmart_open supports transparent compression and decompression for fileszwith the following extensions:* z2The codec is selected based on the file extension.N)#r)   r*   setr   r:   r<   r9   
contextlibredirect_stdoutprintsortedr
   	_REGISTRYitems	NO_SCHEMEaddSCHEMESAttributeErrorr   relative_toformatr?   len__doc__r   chrr&   openr1   rD   r	   get_supported_extensionsreplacePLACEHOLDERr,   )fr.   seen	root_pathbody_padscheme	submoduleschemesrelpathheadingr!   	extensions               r%   tweak_open_docstringrj      s`   
++-C5DX%%,,If}H		#	#C	(k"#!'	(;(;(A(A(C!DFI,,,	T0AHHY##++ 4y'9'9:;GG	RG&&sxx'8'BGXJwi()XJsS\1234XJ	 1 1 7R>>s2wGJKLMG#INN$:$:;Fl69:' "E* 	i !*(;<g
abc
89:$==?IXJb,- @
LMNI 
)R 	yyII%%k3<<>B	 ? " #!(# 
)	(s9    A4K(K!CK(?CK(K%!K($K%%K((K1c                   t        j                         }t               }g }g }t        t        j
                  j                               D ]  \  }}|t        j                  k(  s||v r|j                  |       t        j                  t              5  |j                  |j                         ddd       	 |j                  |j                          t         dz   }t        j"                  |      5  t%        t          d       t%                |D ]  }t%        | d|         t%                t%        t          d       t%                |D ]  }t%        | d|         	 ddd       | j&                  r4| j&                  j)                  t*        |j-                               | _        yy# 1 sw Y   xY w# t        $ r |j                  |       Y w xY w# 1 sw Y   xxY w)zAInject supported schemes and example URIs into ``f``'s docstring.Nr   zSchemes:rK   rJ   )r)   r*   rL   rP   r
   rQ   rR   rS   rT   rM   suppressrV   extendURI_EXAMPLESrU   r   r9   rN   rO   rZ   r^   r_   r,   )	r`   r.   ra   rf   examplesrd   re   rc   examples	            r%   tweak_parse_uri_docstringrq      s   
++-C5DGH#I$7$7$=$=$?@	Y(((I,=  0OOI223 1	#NN9,,- A f}H		#	#C	(h FXJb)* i !GXJb	*+   
) 	yyII%%k3<<>B	 + 10
  	#NN6"	#
 
)	(s+   F-7F:2A1G-F7	:GGG$)r   
str | Nonereturnzlist[list[Any]])r   )r!   z	list[Any]r-   rF   rs   rF   )N)r7   rr   rs   rF   )r`   zCallable[..., Any]rs   None)rZ   
__future__r   rM   r   r)   syspathlibr   typingr   r   r   r   r	   r
   collections.abcr   version_infor_   r9   r&   r1   rD   rj   rq   r5   r'   r%   <module>r{      so    #   	 
  + + $( w:KD>KD;|D(:2Cj#Cr'   