§
    dŠtjP!  ã                   ó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 )ÚGistFileSystema  
    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.
    token: str (optional)
        GitHub personal access token (required if username is given), or.
    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          ¦   «                              ¦   «          || _        || _        || _        |�|€t          d¦  «        ‚|| _        || _        || _        |�|nd| _	        |  
                    ¦   «         | j        d<   d S )NzUser auth requires a token)é<   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	           €úY/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/fsspec/implementations/gist.pyr   zGistFileSystem.__init__(   sŽ   ø€ õ 	‰Œ×ÒÑÔÐØˆŒØ"ˆŒØˆŒØÐ E MÝÐ9Ñ:Ô:Ð:Ø ˆŒØˆŒ
Ø ˆŒà")Ð"5�w�w¸8ˆŒð !×1Ò1Ñ3Ô3ˆŒ�bÑÐÐó    c                 ó¼   — ddddœi}|                      | j        ¦  «         | j        r| j        r| j        | j        f|d<   n| j        rd| j        › �|d         d<   |S )z?Auth parameters passed to 'requests' if we have username/token.Úheaderszapplication/vnd.github+jsonz
2022-11-28)ÚAcceptzX-GitHub-Api-VersionÚauthzBearer ÚAuthorization)Úupdater   r   r   )r   Úkws     r   r%   zGistFileSystem.kwA   s…   € ð Ø7Ø(4ðð ð
ˆð 	�	Š	�$”/Ñ"Ô"Ð"ØŒ=ð 	D˜TœZð 	DØœ-¨¬Ð4ˆBˆv‰JˆJØŒZð 	DØ-C°t´zÐ-CÐ-CˆBˆyŒM˜/Ñ*Øˆ	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_metadataQ   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Útyper9   r:   )r5   r   r.   r0   ÚitemsÚappend)r   ÚmetaÚavailable_filesr7   ÚfnÚoutÚfnameÚfinfos           r   r   zGistFileSystem._fetch_file_listb   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)ÚclsrF   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   rF   rG   r   éþÿÿÿNr   r   r   r   )r   ÚrsplitÚlen)rF   ÚsorB   Ú
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 ©r;   © ©Ú.0ÚfrF   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 )r;   NrW   )rY   rZ   s     r   ú	<genexpr>z$GistFileSystem.ls.<locals>.<genexpr>Ã   s&   è è € Ð5Ð5¨˜!˜Fœ)Ð5Ð5Ð5Ð5Ð5Ð5r   )rJ   r   r0   Úsorted)r   rF   Ú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.
        rc   z'GitHub Gist FS is read-only (no write).c                 ó,   •— g | ]}|d          ‰k    ¯|‘ŒS rV   rW   rX   s     €r   r[   z(GistFileSystem._open.<locals>.<listcomp>Î   s'   ø€ ÐEÐEÐE˜°1°V´9ÀÒ3DÐ3D�1Ð3DÐ3DÐ3Dr   r   r   r:   zNo raw_url for file: r   r'   N)ÚNotImplementedErrorrJ   r   r0   r.   r-   r   r%   r/   r1   r   Úcontent)	r   rF   ÚmodeÚ
block_sizer   ÚmatchesrD   r:   r4   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                 ór  — |                       ||¬¦  «        }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t	          |¦  «        dk    r|d         |k    r||         S |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.
        )Ú	recursiverc   Nrl   Úomitr   r   )Úexpand_pathÚopenÚreadr0   rP   )
r   rF   rn   Úon_errorr   ÚpathsrB   ÚprZ   Úes
             r   ÚcatzGistFileSystem.catÝ   s&  € ð
 × Ò  °Ð Ñ;Ô;ˆØˆØð 
	ð 
	ˆAð	Ø—Y’Y˜q $Ñ'Ô'ð &¨1ØŸVšV™XœX�C˜‘Fð&ð &ð &ñ &ô &ð &ð &ð &ð &ð &ð &øøøð &ð &ð &ð &øøå$ð ð ð Ø˜wÒ&Ð&Ø�GØ Ò'Ð'Øà�C˜‘Føøøøøøøøøðøøøõ ˆu‰:Œ:˜Š?ˆ?˜u Qœx¨4Ò/Ð/Ø�t”9ÐØˆ
s:   ŸA%µAÁA%ÁA	ÁA%Á A	Á!A%Á%
BÁ/BÂB)NNNNN)r   F)rc   N)Frl   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úprotocolr,   r*   r   Úpropertyr%   r5   r   ÚclassmethodrJ   ÚstaticmethodrS   rb   rk   rw   Ú__classcell__)r   s   @r   r	   r	      s  ø€ € € € € ðð ð6 €HØ7€HØA€Lð
 ØØØØð4ð 4ð 4ð 4ð 4ð 4ð2 ðð ñ „Xððð ð ð"ð ð ð@ ð ð  ñ „[ð ð ðð ñ „\ðð86ð 6ð 6ð 6ð61ð 1ð 1ð 1ð0ð ð ð ð ð ð ð r   r	   )r-   Úspecr   Úutilsr   Úmemoryr   r	   rW   r   r   ú<module>r„      sƒ   ðØ €€€à %Ð %Ð %Ð %Ð %Ð %Ø )Ð )Ð )Ð )Ð )Ð )Ø Ð Ð Ð Ð Ð ðið ið ið ið iÐ'ñ iô ið ið ið ir   