Ë
    çÍ:j{  ã                   ó®   — d dl Z d dlZd dlZd dlZd dlZdededefd„Zdee   dedee   fd„Zd	ed
edee	eef      ddfd„Z
	 	 	 	 dd
ededededdf
d„Zy)é    NÚfile_urlÚfolderÚreturnc                 ó   — t         j                  j                  | «      }t         j                  j                  ||«      }t         j                  j	                  |«      rt        j                  d|› d| › �«       t        j                  | d¬«      }t        |d«      5 }|j                  |j                  «       ddd«       |S # 1 sw Y   |S xY w)a*  Download a file from a URL into the given folder.

    If a file with the same name already exists, it will be overwritten.
    Returns the basename of the downloaded file. Network-related exceptions from
    ``requests.get`` (e.g., timeouts or connection errors) may propagate to the caller.

    zgiven file "z." already exists and will be overwritten with é
   )ÚtimeoutÚwbN)ÚosÚpathÚbasenameÚjoinÚisfileÚloggingÚwarningÚrequestsÚgetÚopenÚwriteÚcontent)r   r   ÚfnameÚ	file_pathÚrqÚoutfiles         úw/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/lightning_utilities/docs/retriever.pyÚ_download_filer      sž   € ô �G‰G×Ñ˜XÓ&€EÜ—‘—‘˜V UÓ+€IÜ	‡w�w‡~�~�iÔ Ü�‰˜, y kÐ1_Ð`hÐ_iÐjÔkä	�‰�h¨Ô	+€BÜ	ˆi˜Ó	ð " 'Ø�‰�b—j‘jÔ!÷"à€L÷"à€Lús   ÂCÃCÚ
list_filesÚpatternc                 ó²   — g }| D ]C  }t        |d¬«      5 }|j                  «       }ddd«       t        j                  |«      }||z  }ŒE |S # 1 sw Y   Œ(xY w)aA  Search for all occurrences of a regular-expression pattern across files.

    Args:
        list_files: The list of file paths to scan.
        pattern: A regular-expression pattern to search for in each file.

    Returns:
        A list with all matches found across the provided files (order preserved per file).

    úUTF-8©ÚencodingN)r   ÚreadÚreÚfindall)r   r   Ú	collectedr   ÚfopemÚbodyÚfounds          r   Ú_search_all_occurrencesr)      sf   € ð €IØò ˆ	Ü�) gÔ.ð 	 °%Ø—:‘:“<ˆD÷	 ä—
‘
˜7 DÓ)ˆØ�UÑ‰	ð	ð
 Ð÷		 ð 	 ús   •AÁA	r   Údocs_folderÚpairs_url_pathc                 óH  — t         j                  j                  | «      j                  |d«      }t	        |j                  t         j                  j                  «      D �cg c]  }|sŒ|‘Œ	 c}«      }t        | d¬«      5 }|j                  «       }ddd«       |D ]@  \  }}	|r'dg|z  }
t        j                  j                  g |
¢|	‘­Ž }	j                  ||	«      }ŒB t        | dd¬«      5 }|j                  «       ddd«       yc c}w # 1 sw Y   Œ|xY w# 1 sw Y   yxY w)aC  Replace all matching remote URLs with local file paths in a given file.

    Args:
        file_path: The file in which replacements should be performed.
        docs_folder: The documentation root folder (used to compute relative paths).
        pairs_url_path: Pairs of (remote_url, local_relative_path) to replace.

    Ú r   r    Nz..Úw)r
   r   ÚdirnameÚreplaceÚlenÚsplitÚsepr   r"   r   r   )r   r*   r+   Ú	relt_pathÚpÚdepthÚfopenr'   ÚurlÚfpathÚpath_upÚfws               r   Ú_replace_remote_with_localr<   3   sü   € ô —‘—‘ 	Ó*×2Ñ2°;ÀÓC€Iä˜IŸO™O¬B¯G©G¯K©KÓ8Ö>�qºA’Ò>Ó?€EÜ	ˆi 'Ô	*ð ¨eØ�z‰z‹|ˆ÷à$ò (‰
ˆˆUÙØ�f˜u‘nˆGÜ—G‘G—L‘LÐ1 'Ð1¨5Ò1ˆEØ�|‰|˜C Ó'‰ð	(ô
 
ˆi˜ wÔ	/ð °2Ø
�‰�Œ÷ð ùò ?÷ð ú÷ð ús$   Á DÁ(DÂ DÃ,DÄDÄD!Úassets_folderÚfile_patternÚretrieve_patternc           	      óž  — t        j                   t        j                  j                  | d|«      d¬«      }|st	        j
                  d| › d|› d�«       yt        ||¬«      }|st	        j                  d	| › d
|› �«       yt        j                  j                  | |«      }t        j                  |d¬«       g }t        t        |«      «      D ]i  \  }}	t	        j                  d|› dt        |«      › d|	› �«       t        |	|«      }
|j                  |	t        j                  j                  ||
«      f«       Œk |D ]  }t        || |«       Œ y)a±  Find S3 (or HTTP) asset URLs in docs, download them locally, and rewrite references to local paths.

    Args:
        docs_folder: The documentation root relative to the project.
        assets_folder: Subfolder inside ``docs_folder`` used to store downloaded assets (created if missing).
        file_pattern: Glob pattern of files to scan.
        retrieve_pattern: Regular-expression pattern used to find remote asset URLs.

    z**T)Ú	recursivez no files were listed in folder "z" and pattern "ú"N)r   z"no resources/assets were match in z for )Úexist_okz >> downloading (ú/z): )Úglobr
   r   r   r   r   r)   ÚinfoÚmakedirsÚ	enumerateÚsetr1   r   Úappendr<   )r*   r=   r>   r?   r   ÚurlsÚtarget_folderÚpairs_url_fileÚir8   r   r9   s               r   Úfetch_external_assetsrO   K   s0  € ô —‘œ2Ÿ7™7Ÿ<™<¨°T¸<ÓHÐTXÔY€JÙÜ�‰Ð:¸;¸-ÀÐWcÐVdÐdeÐfÔgØä" :Ð7GÔH€DÙÜ�‰Ð9¸+¸ÀeÐL\ÐK]Ð^Ô_ØÜ—G‘G—L‘L ¨mÓ<€MÜ‡K�K�¨Õ-Ø€NÜœC ›IÓ&ò I‰ˆˆ3Ü�‰Ð(¨¨¨1¬S°«Y¨K°s¸3¸%Ð@ÔAÜ˜s MÓ2ˆØ×Ñ˜s¤B§G¡G§L¡L°ÀÓ$FÐGÕHðIð
 ò GˆÜ" 5¨+°~ÕFñGó    )zdocs/sourcezfetched-s3-assetsz*.rstz5https?://[-a-zA-Z0-9_]+\.s3\.[-a-zA-Z0-9()_\\+.\\/=]+)rE   r   r
   r#   r   Ústrr   Úlistr)   Útupler<   rO   © rP   r   ú<module>rU      sÎ   ðó Û Û 	Û 	ã ð˜Sð ¨#ð °#ó ð&¨¨S©	ð ¸Cð ÀDÈÁIó ð(¨#ð ¸Cð ÐQUÐV[Ð\_ÐadÐ\dÑVeÑQfð Ðkoó ð2 %Ø,ØØTñ	!GØð!Gàð!Gð ð!Gð ð	!Gð
 
ô!GrP   