§
    ’©º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dS )é    NÚfile_urlÚfolderÚreturnc                 ó¦  — t           j                             | ¦  «        }t           j                             ||¦  «        }t           j                             |¦  «        rt          j        d|› d| › �¦  «         t          j        | d¬¦  «        }t          |d¦  «        5 }| 
                    |j        ¦  «         ddd¦  «         n# 1 swxY w Y   |S )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         úr/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/lightning_utilities/docs/retriever.pyÚ_download_filer      sö   € õ ŒG×Ò˜XÑ&Ô&€EÝ”—’˜V UÑ+Ô+€IÝ	„w‡~‚~�iÑ Ô ð lÝŒÐj yÐjÐjÐ`hÐjÐjÑkÔkÐkå	Œ�h¨Ð	+Ñ	+Ô	+€BÝ	ˆi˜Ñ	Ô	ð " 'Ø�Š�b”jÑ!Ô!Ð!ð"ð "ð "ñ "ô "ð "ð "ð "ð "ð "ð "øøøð "ð "ð "ð "à€Ls   ÂCÃC
ÃC
Ú
list_filesÚpatternc                 óÂ   — g }| D ]Y}t          |d¬¦  «        5 }|                     ¦   «         }ddd¦  «         n# 1 swxY w Y   t          j        ||¦  «        }||z  }ŒZ|S )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)      s­   € ð €IØð ð ˆ	Ý�) gÐ.Ñ.Ô.ð 	 °%Ø—:’:‘<”<ˆDð	 ð 	 ð 	 ñ 	 ô 	 ð 	 ð 	 ð 	 ð 	 ð 	 ð 	 øøøð 	 ð 	 ð 	 ð 	 å”
˜7 DÑ)Ô)ˆØ�UÑˆ	ˆ	ØÐs   ˜9¹=	Á =	r   Údocs_folderÚpairs_url_pathc                 óX  — t           j                             | ¦  «                             |d¦  «        }t	          d„ |                     t           j        j        ¦  «        D ¦   «         ¦  «        }t          | d¬¦  «        5 }|                     ¦   «         }ddd¦  «         n# 1 swxY w Y   |D ];\  }}|rdg|z  }	t          j        j	        g |	¢|‘R Ž }|                     ||¦  «        }Œ<t          | dd¬¦  «        5 }
|
 
                    |¦  «         ddd¦  «         dS # 1 swxY w Y   dS )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.

    Ú c                 ó   — g | ]}|¯|‘ŒS © r/   )Ú.0Úps     r   ú
<listcomp>z._replace_remote_with_local.<locals>.<listcomp>?   s   € Ð>Ð>Ð>�q¸AÐ>�Ð>Ð>Ð>ó    r   r    Nz..Úw)r
   r   ÚdirnameÚreplaceÚlenÚsplitÚsepr   r"   r   r   )r   r*   r+   Ú	relt_pathÚdepthÚfopenr'   ÚurlÚfpathÚpath_upÚfws              r   Ú_replace_remote_with_localrA   3   s¡  € õ ”—’ 	Ñ*Ô*×2Ò2°;ÀÑCÔC€IåÐ>Ð>˜IŸOšO­B¬G¬KÑ8Ô8Ð>Ñ>Ô>Ñ?Ô?€EÝ	ˆi 'Ð	*Ñ	*Ô	*ð ¨eØ�zŠz‰|Œ|ˆðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð à$ð (ð (‰
ˆˆUØð 	2Ø�f˜u‘nˆGÝ”G”LÐ1 'Ð1¨5Ð1Ð1Ð1ˆEØ�|Š|˜C Ñ'Ô'ˆˆÝ	ˆi˜ wÐ	/Ñ	/Ô	/ð °2Ø
�Š�‰Œˆðð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð s$   Â B!Â!B%Â(B%Ã<DÄD#Ä&D#údocs/sourceúfetched-s3-assetsú*.rstú5https?://[-a-zA-Z0-9_]+\.s3\.[-a-zA-Z0-9()_\\+.\\/=]+Úassets_folderÚfile_patternÚretrieve_patternc           	      óÊ  — t          j         t          j                             | d|¦  «        d¬¦  «        }|st	          j        d| › d|› d�¦  «         dS t          ||¬¦  «        }|st	          j        d	| › d
|› �¦  «         dS t          j                             | |¦  «        }t          j        |d¬¦  «         g }t          t          |¦  «        ¦  «        D ]t\  }}	t	          j        d|› dt          |¦  «        › d|	› �¦  «         t          |	|¦  «        }
|                     |	t          j                             ||
¦  «        f¦  «         Œu|D ]}t          || |¦  «         ŒdS )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Úsetr7   r   ÚappendrA   )r*   rF   rG   rH   r   ÚurlsÚtarget_folderÚpairs_url_fileÚir=   r   r>   s               r   Úfetch_external_assetsrX   K   s�  € õ ”�2œ7Ÿ<š<¨°T¸<ÑHÔHÐTXÐYÑYÔY€JØð ÝŒÐf¸;ÐfÐfÐWcÐfÐfÐfÑgÔgÐgØˆå" :Ð7GÐHÑHÔH€DØð ÝŒÐ^¸+Ð^Ð^ÐL\Ð^Ð^Ñ_Ô_Ð_ØˆÝ”G—L’L ¨mÑ<Ô<€MÝ„K�¨Ð-Ñ-Ô-Ð-Ø€NÝ�C ™IœIÑ&Ô&ð Ið I‰ˆˆ3ÝŒÐ@¨Ð@Ð@­S°©Y¬YÐ@Ð@¸3Ð@Ð@ÑAÔAÐAÝ˜s MÑ2Ô2ˆØ×Ò˜s¥B¤G§L¢L°ÀÑ$FÔ$FÐGÑHÔHÐHÐHàð Gð GˆÝ" 5¨+°~ÑFÔFÐFÐFðGð Gr3   )rB   rC   rD   rE   )rN   r   r
   r#   r   Ústrr   Úlistr)   ÚtuplerA   rX   r/   r3   r   ú<module>r\      s=  ðð €€€Ø €€€Ø 	€	€	€	Ø 	€	€	€	à €€€ð˜Sð ¨#ð °#ð ð ð ð ð&¨¨S¬	ð ¸Cð ÀDÈÄIð ð ð ð ð(¨#ð ¸Cð ÐQUÐV[Ð\_ÐadÐ\dÔVeÔQfð Ðkoð ð ð ð ð2 %Ø,ØØTð	!Gð !GØð!Gàð!Gð ð!Gð ð	!Gð
 
ð!Gð !Gð !Gð !Gð !Gð !Gr3   