Ë
    æš¾jâ  ã                  óÐ   — 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           ú]/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/smart_open/doctools.pyÚextract_kwargsr&   '   s1  € ñ> Øˆ	ä×Ñ˜YÓ'×-Ñ-¨dÓ3€Eä˜uÓ%ò ‰	ˆˆTØ�;‰;‹=˜GÓ#Ø˜# ™'˜)Ð$ˆEÙðð
 ˆ	à €FØò 0ˆØ�z‰zŒ|Øð €Mð �?‰?˜6Ô"¨4¯?©?¸:Ô+FØ˜A˜B�xˆHØ˜(Ñ"ØØ!Ÿ™¨¨QÓ/‰JˆD�$Ø�M‰M˜4Ÿ:™:›<¨¸t¿z¹z¼|¨d¯j©j«l©^ÐQSÐTÔUØà�?‰?˜:Õ&ª6Ø�2‰J�r‰N×!Ñ! $§*¡*£,Õ/ð0ð €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   e   s’   € ô. �+‰+‹-€CØ$*ò -Ñ ˆˆe�[ÙØ�I‰I˜˜˜t˜f B u g¨RÐ0Õ1à�I‰I˜˜˜t˜f CÐ(Ô)Øò 	-ˆDØ�I‰I˜˜˜d 4 &¨Ð+Õ,ñ	-ð-ð �<‰<‹>Ð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¸;ÑF€Kð	(Ø×$Ñ$¨gÐ$Ó6ˆØ�z‰zÐ=¸qÓAÀ!ÑDˆØ�z‰zÐ<¸aÓ@ÀÑCˆà�z‰z˜+ qÓ)¨!Ñ,×3Ñ3°E¸1Ó=¸aÑ@ˆØ—
‘
˜4Ó ×&Ñ& tÓ,ˆØ�w‰wÓ>¸Ô>Ó>Ð>øÜò (Ø˜Ñ'Ò'ð(ús   ¿BC ÃC.Ã-C.c           	     óÜ  — t        j                  «       }t        «       }t        t        «      j
                  j
                  }t        dz   }t        t        › d�|¬«       t        |¬«       t        t        j                  j                  «       «      D �]:  \  }}|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j-                  t/        d	«      «      d
   › �|¬«       t        |¬«       t1        |j2                  j*                  «      }
|
s�Œ#t        t5        |
|¬«      |¬«       �Œ= t        t        › d�|¬«       t        |¬«       t        t7        |¬«      |¬«       t        t        › d�|¬«       t        |¬«       t        |› d�|¬«       t        |› d�|¬«       t        |¬«       t9        j:                  «       D ]  }t        |› d|› �|¬«       Œ t        |¬«       t        |› d�|¬«       | j*                  r4| j*                  j=                  t>        |jA                  «       «      | _        yy# t        $ r |g}Y �Œw xY w)zJInject transport, compression and example sections into ``f``'s docstring.r   zTransports:©ÚfileÚ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   Ú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   ¤   sr  € ä
�+‰+‹-€CÜ‹5€Dä”X“×%Ñ%×,Ñ,€IÜ�f‰}€Hä	ŒTˆF�+Ð
 SÕ)Ü	ˆs…OÜ#¤I×$7Ñ$7×$=Ñ$=Ó$?Ó@ó AÑˆ�	Ø”Y×(Ñ(Ò(¨I¸Ñ,=ØØ�‰�Ôð	Ø×'Ñ'ˆGô ”t˜E 9×#5Ñ#5Ó6Ó7×CÑCÀIÓNˆØ×"Ñ" 3§8¡8¨GÓ#4°gÓ>ˆÜ��
˜7˜)Ð$¨3Õ/Ü��
˜3¤ W£Ñ-Ð.Ð/°cÕ:Ü��
˜I×-Ñ-Ò3°×:Ñ:¼3¸r»7ÓCÀAÑFÐGÐHÈsÕSÜ�3�ä 	§¡× 6Ñ 6Ó7ˆÛÜ”,˜v¨HÔ5¸C×@ð'Aô* 
ŒTˆF�)Ð
 3Õ'Ü	ˆs…OÜ	Ô
&¨hÔ
7¸cÕBä	ŒTˆF�'Ð
 Õ%Ü	ˆs…OÜ	ˆXˆJÐ]Ð
^ÐehÕiÜ	ˆXˆJÐ4Ð
5¸CÕ@Ü	ˆs…OÜ ×9Ñ9Ó;ò 4ˆ	Ü��
˜"˜Y˜KÐ(¨sÖ3ð4ä	ˆs…OÜ	ˆXˆJÐHÐ
IÐPSÕTð
 	‡y‚yØ—I‘I×%Ñ%¤k°3·<±<³>ÓBˆ�	ð øô? ò 	Ø�h‹Gð	ús   ÃKËK+Ë*K+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#        t         › d�|¬«       t#        |¬«       |D ]  }t#        |› d|› �|¬«       Œ t#        |¬«       t#        t         › d�|¬«       t#        |¬«       |D ]  }t#        |› d|› �|¬«       Œ | j$                  r4| j$                  j'                  t(        |j+                  «       «      | _        yy# 1 sw Y   ŒïxY w# t        $ r |j                  |«       Y �Œ{w xY w)zAInject supported schemes and example URIs into ``f``'s docstring.Nr   zSchemes:rF   rM   rL   )r)   r*   rN   rP   r
   rQ   rR   rS   rT   Ú
contextlibÚsuppressrV   ÚextendÚURI_EXAMPLESrU   r   r9   rO   rZ   r^   r_   r,   )	r`   r.   ra   rf   Úexamplesrd   re   rc   Úexamples	            r%   Útweak_parse_uri_docstringrr   Ø   sˆ  € ä
�+‰+‹-€CÜ‹5€DØ€GØ€Hä#¤I×$7Ñ$7×$=Ñ$=Ó$?Ó@ò #Ñˆ�	Ø”Y×(Ñ(Ò(¨I¸Ñ,=Øà�‰�Ôä× Ñ ¤Ó0ñ 	4Ø�O‰O˜I×2Ñ2Ô3÷	4ð	#Ø�N‰N˜9×,Ñ,Õ-ð#ô �f‰}€Hä	ŒTˆF�(Ð
 #Õ&Ü	ˆs…OØò 1ˆÜ��
˜"˜V˜HÐ%¨CÖ0ð1ä	ˆs…OÜ	ŒTˆF�)Ð
 3Õ'Ü	ˆs…OØò 2ˆÜ��
˜"˜W˜IÐ&¨SÖ1ð2ð 	‡y‚yØ—I‘I×%Ñ%¤k°3·<±<³>ÓBˆ�	ð ÷)	4ð 	4ûô
 ò 	#Ø�N‰N˜6×"ð	#ús   ÂFÂ7F(ÆF%	Æ(GÇG)r   ú
str | NoneÚreturnzlist[list[Any]])r   )r!   z	list[Any]r-   rH   rt   rH   )N)r7   rs   rt   rH   )r`   zCallable[..., Any]rt   ÚNone)rZ   Ú
__future__r   rl   r   r)   ÚsysÚpathlibr   Útypingr   r   r   r   r	   r
   Úcollections.abcr   Úversion_infor_   r9   r&   r1   rD   rj   rr   r5   r'   r%   ú<module>r|      so   ðñõ
 #ã Û Û 	Û 
Ý ß +Ñ +ç $áÝ(ð ×Ñ�wÒØ:€KØ�Dà>€KØ€Dó;ô|ôD(ó:1Côh"Cr'   