§
    g˜ºh•   ã                   óN   — d dl Z ddlmZ ddlmZ ddlmZ  G d„ de¦  «        ZdS )	é    Né   )ÚAbstractFileSystem)Úinfer_storage_optionsé   )Ú
MemoryFilec                   ó    ‡ — e Zd ZdZdZdZdZ	 	 	 	 	 dˆ fd„	Zed„ ¦   «         Z	d„ Z
d	„ Zed
„ ¦   «         Zed„ ¦   «         Zdd„Zdd„Zdd„Zˆ xZS )ÚGistFileSystema9  
    Interface to files in a single GitHub Gist.

    Provides read-only access to a gist's files. Gists do not contain
    subdirectories, so file listing is straightforward.

    Parameters
    ----------
    gist_id : str
        The ID of the gist you want to access (the long hex value from the URL).
    filenames : list[str] (optional)
        If provided, only make a file system representing these files, and do not fetch
        the list of all files for this gist.
    sha : str (optional)
        If provided, fetch a particular revision of the gist. If omitted,
        the latest revision is used.
    username : str (optional)
        GitHub username for authentication (required if token is given).
    token : str (optional)
        GitHub personal access token (required if username is given).
    timeout : (float, float) or float, optional
        Connect and read timeouts for requests (default 60s each).
    kwargs : dict
        Stored on `self.request_kw` and passed to `requests.get` when fetching Gist
        metadata or reading ("opening") a file.
    Úgistz&https://api.github.com/gists/{gist_id}z,https://api.github.com/gists/{gist_id}/{sha}Nc                 ó"  •— t          ¦   «                              ¦   «          || _        || _        || _        |d u |d u z  r|s|rt          d¦  «        ‚|| _        || _        || _        |�|nd| _	        |  
                    ¦   «         | j        d<   d S )Nz2Auth requires both username and token, or neither.)é<   r   Ú )ÚsuperÚ__init__Úgist_idÚ	filenamesÚshaÚ
ValueErrorÚusernameÚtokenÚ
request_kwÚtimeoutÚ_fetch_file_listÚdircache)	Úselfr   r   r   r   r   r   ÚkwargsÚ	__class__s	           €úc/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/fsspec/implementations/gist.pyr   zGistFileSystem.__init__(   s¬   ø€ õ 	‰Œ×ÒÑÔÐØˆŒØ"ˆŒØˆŒØ˜Ð ¨$ Ñ/ð 	Wàð W˜5ð WÝ Ð!UÑVÔVÐVØ ˆŒØˆŒ
Ø ˆŒà")Ð"5�w�w¸8ˆŒð !×1Ò1Ñ3Ô3ˆŒ�bÑÐÐó    c                 óZ   — | j         �| j        �d| j         | j        fi| j        ¥S | j        S )z?Auth parameters passed to 'requests' if we have username/token.NÚauth)r   r   r   )r   s    r   ÚkwzGistFileSystem.kwC   s6   € ð Œ=Ð$¨¬Ð)?Ø˜Tœ]¨D¬JÐ7ÐK¸4¼?ÐKÐKØŒÐr   c                 ó‚  — | j         r'| j                             | j        | j         ¬¦  «        }n | j                             | j        ¬¦  «        }t          j        |fd| j        i| j        ¤Ž}|j	        dk    r!t          d| j        › d| j         pd› �¦  «        ‚|                     ¦   «          |                     ¦   «         S )z[
        Fetch the JSON metadata for this gist (possibly for a specific revision).
        )r   r   )r   r   é”  zGist not found: ú@Úlatest)r   Úgist_rev_urlÚformatr   Úgist_urlÚrequestsÚgetr   r!   Ústatus_codeÚFileNotFoundErrorÚraise_for_statusÚjson)r   ÚurlÚrs      r   Ú_fetch_gist_metadataz#GistFileSystem._fetch_gist_metadataJ   sÅ   € ð Œ8ð 	=ØÔ#×*Ò*°4´<ÀTÄXÐ*ÑNÔNˆCˆCà”-×&Ò&¨t¬|Ð&Ñ<Ô<ˆCåŒL˜Ð>Ð> d¤lÐ>°d´gÐ>Ð>ˆØŒ=˜CÒÐÝ#ØH 4¤<ÐHÐH°$´(Ð2F¸hÐHÐHñô ð ð 	
×ÒÑÔÐØ�vŠv‰xŒxˆr   c           	      óª  — |                       ¦   «         }| j        rA|                     di ¦  «        }i }| j        D ] }||vrt          |¦  «        ‚||         ||<   Œ!n|                     di ¦  «        }g }|                     ¦   «         D ]I\  }}|€Œ|                     |d|                     dd¦  «        |                     d¦  «        dœ¦  «         ŒJ|S )zz
        Returns a list of dicts describing each file in the gist. These get stored
        in self.dircache[""].
        ÚfilesNÚfileÚsizer   Úraw_url)ÚnameÚtyper5   r6   )r1   r   r*   r,   ÚitemsÚappend)r   ÚmetaÚavailable_filesr3   ÚfnÚoutÚfnameÚfinfos           r   r   zGistFileSystem._fetch_file_list[   s  € ð
 ×(Ò(Ñ*Ô*ˆØŒ>ð 	*Ø"Ÿhšh w°Ñ3Ô3ˆOØˆEØ”nð 0ð 0�Ø˜_Ð,Ð,Ý+¨BÑ/Ô/Ð/Ø+¨BÔ/��b‘	�	ð0ð
 —H’H˜W bÑ)Ô)ˆEàˆØ!ŸKšK™MœMð 	ð 	‰LˆE�5Øˆ}àà�JŠJà!Ø"Ø!ŸIšI f¨aÑ0Ô0Ø$Ÿyšy¨Ñ3Ô3ð	ð ñô ð ð ð ˆ
r   c                 ór   — t          |¦  «                             d|¦  «        }|                     d¦  «        S )z=
        Remove 'gist://' from the path, if present.
        Úpathú/)r   r*   Úlstrip)ÚclsrB   s     r   Ú_strip_protocolzGistFileSystem._strip_protocol{   s3   € õ % TÑ*Ô*×.Ò.¨v°tÑ<Ô<ˆØ�{Š{˜3ÑÔÐr   c                 ó†  — t          | ¦  «        }i }d|v r|d         r|d         |d<   d|v r|d         r|d         |d<   d|v r|d         r|d         |d<   d|v rf|d         r^|d                              dd¦  «        d	d
…         }t          |¦  «        dk    r'|d         r|d         |d<   |d         r|d         g|d<   |S )zÇ
        Parse 'gist://' style URLs into GistFileSystem constructor kwargs.
        For example:
          gist://:TOKEN@<gist_id>/file.txt
          gist://username:TOKEN@<gist_id>/file.txt
        r   Úpasswordr   Úhostr   rB   rC   r   éþÿÿÿNr   r   r   r   )r   ÚrsplitÚlen)rB   Úsor>   Ú
path_partss       r   Ú_get_kwargs_from_urlsz$GistFileSystem._get_kwargs_from_urls†   sö   € õ # 4Ñ(Ô(ˆØˆØ˜ÐÐ  :¤ÐØ  œnˆC�
‰OØ˜ÐÐ  :¤ÐØ˜jœ>ˆC�‰LØ�Rˆ<ˆ<˜B˜vœJˆ<à œZˆC�	‰Nð �Rˆ<ˆ<˜B˜vœJˆ<Ø˜Fœ×*Ò*¨3°Ñ2Ô2°2°3°3Ô7ˆJÝ�:‰Œ !Ò#Ð#Ø˜a”=ð /Ø!+¨A¤�C˜‘JØ˜a”=ð 7Ø(2°1¬ �C˜Ñ$àˆ
r   r   Fc                 óì   ‡— |                       ‰pd¦  «        Š‰dk    r| j        d         }n,| j        d         }ˆfd„|D ¦   «         }|st          ‰¦  «        ‚|r|S t          d„ |D ¦   «         ¦  «        S )a‘  
        List files in the gist. Gists are single-level, so any 'path' is basically
        the filename, or empty for all files.

        Parameters
        ----------
        path : str, optional
            The filename to list. If empty, returns all files in the gist.
        detail : bool, default False
            If True, return a list of dicts; if False, return a list of filenames.
        r   c                 ó,   •— g | ]}|d          ‰k    ¯|‘ŒS ©r7   © ©Ú.0ÚfrB   s     €r   ú
<listcomp>z%GistFileSystem.ls.<locals>.<listcomp>¶   s'   ø€ ÐAÐAÐA˜Q¨q°¬y¸DÒ/@Ð/@�qÐ/@Ð/@Ð/@r   c              3   ó&   K  — | ]}|d          V — ŒdS )r7   NrS   )rU   rV   s     r   ú	<genexpr>z$GistFileSystem.ls.<locals>.<genexpr>¼   s&   è è € Ð5Ð5¨˜!˜Fœ)Ð5Ð5Ð5Ð5Ð5Ð5r   )rF   r   r,   Úsorted)r   rB   Údetailr   ÚresultsÚ	all_filess    `    r   ÚlszGistFileSystem.ls£   sš   ø€ ð ×#Ò# D J¨BÑ/Ô/ˆà�2Š:ˆ:Ø”m BÔ'ˆGˆGð œ bÔ)ˆIØAÐAÐAÐA )ÐAÑAÔAˆGØð .Ý'¨Ñ-Ô-Ð-Øð 	6ØˆNåÐ5Ð5¨WÐ5Ñ5Ô5Ñ5Ô5Ð5r   Úrbc                 óÒ  ‡— |dk    rt          d¦  «        ‚|                      ‰¦  «        Šˆfd„| j        d         D ¦   «         }|st          ‰¦  «        ‚|d         }|                     d¦  «        }|st          d‰› �¦  «        ‚t          j        |fd| j        i| j        ¤Ž}|j        d	k    rt          ‰¦  «        ‚| 	                    ¦   «          t          ‰d
|j        ¦  «        S )z3
        Read a single file from the gist.
        r_   z'GitHub Gist FS is read-only (no write).c                 ó,   •— g | ]}|d          ‰k    ¯|‘ŒS rR   rS   rT   s     €r   rW   z(GistFileSystem._open.<locals>.<listcomp>Ç   s'   ø€ ÐEÐEÐE˜°1°V´9ÀÒ3DÐ3D�1Ð3DÐ3DÐ3Dr   r   r   r6   zNo raw_url for file: r   r#   N)ÚNotImplementedErrorrF   r   r,   r*   r)   r   r!   r+   r-   r   Úcontent)	r   rB   ÚmodeÚ
block_sizer   Úmatchesr@   r6   r0   s	    `       r   Ú_openzGistFileSystem._open¾   s  ø€ ð �4Š<ˆ<Ý%Ð&OÑPÔPÐPà×#Ò# DÑ)Ô)ˆàEÐEÐEÐE˜dœm¨BÔ/ÐEÑEÔEˆØð 	*Ý# DÑ)Ô)Ð)Ø˜”
ˆà—)’)˜IÑ&Ô&ˆØð 	DÝ#Ð$B¸DÐ$BÐ$BÑCÔCÐCåŒL˜ÐBÐB¨$¬,ÐB¸$¼'ÐBÐBˆØŒ=˜CÒÐÝ# DÑ)Ô)Ð)Ø	×ÒÑÔÐÝ˜$  a¤iÑ0Ô0Ð0r   Úraisec                 ó$  — |                       ||¬¦  «        }i }|D ]s}	 |                      |d¦  «        5 }|                     ¦   «         ||<   ddd¦  «         n# 1 swxY w Y   ŒI# t          $ r}	|dk    r|	‚|dk    rn|	||<   Y d}	~	Œld}	~	ww xY w|S )z˜
        Return {path: contents} for the given file or files. If 'recursive' is True,
        and path is empty, returns all files in the gist.
        )Ú	recursiver_   Nrh   Úomit)Úexpand_pathÚopenÚreadr,   )
r   rB   rj   Úon_errorr   Úpathsr>   ÚprV   Úes
             r   ÚcatzGistFileSystem.catÖ   sÿ   € ð
 × Ò  °Ð Ñ;Ô;ˆØˆØð 
	ð 
	ˆAð	Ø—Y’Y˜q $Ñ'Ô'ð &¨1ØŸVšV™XœX�C˜‘Fð&ð &ð &ñ &ô &ð &ð &ð &ð &ð &ð &øøøð &ð &ð &ð &øøå$ð ð ð Ø˜wÒ&Ð&Ø�GØ Ò'Ð'Øà�C˜‘Føøøøøøøøøðøøøð ˆ
s:   ŸA%µAÁA%ÁA	ÁA%Á A	Á!A%Á%
BÁ/BÂB)NNNNN)r   F)r_   N)Frh   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úprotocolr(   r&   r   Úpropertyr!   r1   r   ÚclassmethodrF   ÚstaticmethodrO   r^   rg   rs   Ú__classcell__)r   s   @r   r	   r	      s  ø€ € € € € ðð ð6 €HØ7€HØA€Lð
 ØØØØð4ð 4ð 4ð 4ð 4ð 4ð6 ðð ñ „Xððð ð ð"ð ð ð@ ð ð  ñ „[ð ð ðð ñ „\ðð86ð 6ð 6ð 6ð61ð 1ð 1ð 1ð0ð ð ð ð ð ð ð r   r	   )r)   Úspecr   Úutilsr   Úmemoryr   r	   rS   r   r   ú<module>r€      sƒ   ðØ €€€à %Ð %Ð %Ð %Ð %Ð %Ø )Ð )Ð )Ð )Ð )Ð )Ø Ð Ð Ð Ð Ð ð`ð `ð `ð `ð `Ð'ñ `ô `ð `ð `ð `r   