CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
gist.cpython-310.pyc89 linesDownload Raw Back to __pycache__
1o

2��YiP!�@s@ddlZddlmZddlmZddlmZGdd�de�ZdS)	�N�)�AbstractFileSystem)�infer_storage_options�)�3MemoryFilecs�eZdZdZdZdZdZ					d�fdd�	Zedd	��Z	d4d�Z5dd
�Zedd��Z
edd��Zddd�Zddd�Zddd�Z�ZS) �GistFileSystema6    Interface to files in a single GitHub Gist.7 8    Provides read-only access to a gist's files. Gists do not contain9    subdirectories, so file listing is straightforward.10 11    Parameters12    ----------13    gist_id: str14        The ID of the gist you want to access (the long hex value from the URL).15    filenames: list[str] (optional)16        If provided, only make a file system representing these files, and do not fetch17        the list of all files for this gist.18    sha: str (optional)19        If provided, fetch a particular revision of the gist. If omitted,20        the latest revision is used.21    username: str (optional)22        GitHub username for authentication.23    token: str (optional)24        GitHub personal access token (required if username is given), or.25    timeout: (float, float) or float, optional26        Connect and read timeouts for requests (default 60s each).27    kwargs: dict28        Stored on `self.request_kw` and passed to `requests.get` when fetching Gist29        metadata or reading ("opening") a file.30    Zgistz&https://api.github.com/gists/{gist_id}z,https://api.github.com/gists/{gist_id}/{sha}Ncsjt���||_||_||_|dur|durtd��||_||_||_|dur)|nd|_	|�31�|jd<dS)NzUser auth requires a token)�<r�)�super�__init__�gist_id�	filenames�sha�32ValueError�username�token�33request_kw�timeout�_fetch_file_list�dircache)�selfrr
rrrr�kwargs��	__class__���E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\fsspec/implementations/gist.pyr(s34 35zGistFileSystem.__init__cCsXdddd�i}|�|j�|jr|jr|j|jf|d<|S|jr*d|j��|dd<|S)z?Auth parameters passed to 'requests' if we have username/token.�headerszapplication/vnd.github+jsonz362022-11-28)�AcceptzX-GitHub-Api-Version�authzBearer �
Authorization)�updaterrr)r�kwrrrr!As���zGistFileSystem.kwcCs||jr|jj|j|jd�}n|jj|jd�}tj|fd|ji|j��}|j	dkr6t37d|j�d|jp2d����|��|��S)z[38        Fetch the JSON metadata for this gist (possibly for a specific revision).39        )rr)rr�zGist not found: �@Zlatest)
r�gist_rev_url�formatr�gist_url�requests�getrr!�status_code�FileNotFoundError�raise_for_status�json)r�url�rrrr�_fetch_gist_metadataQs40�z#GistFileSystem._fetch_gist_metadatac	Cs�|��}|jr$|�di�}i}|jD]}||vrt|��||||<qn|�di�}g}|��D]\}}|dur9q0|�|d|�dd�|�d�d��q0|S)zz41        Returns a list of dicts describing each file in the gist. These get stored42        in self.dircache[""].43        �filesN�file�sizer�raw_url)�name�typer2r3)r/r
r(r*�items�append)r�metaZavailable_filesr0�fn�out�fname�finforrrrbs,44�45��zGistFileSystem._fetch_file_listcCst|��d|�}|�d�S)z=46        Remove 'gist://' from the path, if present.47        �path�/)rr(�lstrip)�clsr=rrr�_strip_protocol�s48zGistFileSystem._strip_protocolcCs�t|�}i}d|vr|dr|d|d<d|vr"|dr"|d|d<d|vr0|dr0|d|d<d|vr_|dr_|d�dd�d	d49�}t|�dkr_|drT|d|d<|d
r_|d
g|d<|S)z�50        Parse 'gist://' style URLs into GistFileSystem constructor kwargs.51        For example:52          gist://:TOKEN@<gist_id>/file.txt53          gist://username:TOKEN@<gist_id>/file.txt54        r�passwordr�hostrr=r>r�����Nrrrr
)r�rsplit�len)r=�sor:�55path_partsrrr�_get_kwargs_from_urls�s z$GistFileSystem._get_kwargs_from_urlsr	Fcsd|��pd���dkr|jd}n|jd}�fdd�|D�}|s%t���|r)|Stdd�|D��S)a�56        List files in the gist. Gists are single-level, so any 'path' is basically57        the filename, or empty for all files.58 59        Parameters60        ----------61        path : str, optional62            The filename to list. If empty, returns all files in the gist.63        detail : bool, default False64            If True, return a list of dicts; if False, return a list of filenames.65        r	c�g|]66}|d�kr|�qS�r4r��.0�f�r=rr�67<listcomp>��z%GistFileSystem.ls.<locals>.<listcomp>css�|]}|dVqdS)r4NrrLrrr�	<genexpr>�s�z$GistFileSystem.ls.<locals>.<genexpr>)rArr*�sorted)rr=�detailr�results�	all_filesrrOr�ls�s68zGistFileSystem.ls�rbc	s�|dkrtd��|�����fdd�|jdD�}|st���|d}|�d�}|s1td�����tj|fd	|ji|j��}|jd69krGt���|�	�t70�d|j�S)z371        Read a single file from the gist.72        rXz'GitHub Gist FS is read-only (no write).crJrKrrLrOrrrP�rQz(GistFileSystem._open.<locals>.<listcomp>r	rr3zNo raw_url for file: rr"N)�NotImplementedErrorrArr*r(r'rr!r)r+r�content)	rr=�mode�73block_sizer�matchesr<r3r.rrOr�_open�s747576zGistFileSystem._open�raisec77Ks�|j||d�}i}|D]A}z|�|d��}|��||<Wd�n1s%wYWqtyL}	z|dkr9|	�|dkr>n|	||<WYd}	~	qd}	~	wwt|�dkr]|d|kr]||S|S)z�78        Return {path: contents} for the given file or files. If 'recursive' is True,79        and path is empty, returns all files in the gist.80        )�	recursiverXNr_Zomitrr)Zexpand_path�open�readr*rF)81rr=r`Zon_errorr�pathsr:�prN�errr�cat�s&����zGistFileSystem.cat)NNNNN)r	F)rXN)Fr_)�__name__�82__module__�__qualname__�__doc__�protocolr&r$r�propertyr!r/r�classmethodrA�staticmethodrIrWr^rf�
__classcell__rrrrrs,�83 8485 868788r)r'�specr�utilsrZmemoryrrrrrr�<module>s89
Aluode/PerceptionLabPortable · CoolFace