
    9iP!                     F    S SK r SSKJr  SSKJr  SSKJr   " S S\5      rg)	    N   )AbstractFileSystem)infer_storage_options   )
MemoryFilec                      ^  \ rS rSrSrSrSrSr     SU 4S jjr\	S 5       r
S rS	 r\S
 5       r\S 5       rSS jrSS jrSS jrSrU =r$ )GistFileSystem   a  
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}c                    > [         TU ]  5         Xl        X l        X0l        Ub  Uc  [        S5      eX@l        XPl        Xpl        Ub  UOSU l	        U R                  5       U R                  S'   g )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	           [/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/fsspec/implementations/gist.pyr   GistFileSystem.__init__(   sk     	"EM9:: 
 ")"5w8 !113b    c                    SSSS.0nUR                  U R                  5        U R                  (       a.  U R                  (       a  U R                  U R                  4US'   U$ U R                  (       a  SU R                   3US   S'   U$ )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'   GistFileSystem.kwA   s|     7(4
 			$//"==TZZ--4BvJ 	 ZZ/6tzzl-CByM/*	r    c                    U R                   (       a/  U R                  R                  U R                  U R                   S9nO#U R                  R                  U R                  S9n[
        R                  " U4SU R                  0U R                  D6nUR                  S:X  a.  [        SU R                   SU R                   =(       d    S 35      eUR                  5         UR                  5       $ )zK
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_metadata#GistFileSystem._fetch_gist_metadataQ   s     88##**4<<TXX*NC--&&t||&<CLL>dll>dgg>==C#"4<<.$((2Fh1GH  	
vvxr    c           	         U R                  5       nU R                  (       a>  UR                  S0 5      n0 nU R                   H  nXB;  a  [        U5      eX$   X4'   M     OUR                  S0 5      n/ nUR	                  5        H?  u  pgUc  M
  UR                  USUR                  SS5      UR                  S5      S.5        MA     U$ )zb
Returns a list of dicts describing each file in the gist. These get stored
in self.dircache[""].
filesfilesizer   raw_url)nametyper=   r>   )r8   r   r1   r3   itemsappend)r   metaavailable_filesr;   fnoutfnamefinfos           r   r   GistFileSystem._fetch_file_listb   s    
 ((*>>"hhw3OEnn,+B//+/	 %
 HHWb)E!KKMLE}JJ!"!IIfa0$yy3	 * 
r    c                 Z    [        U5      R                  SU5      nUR                  S5      $ )z-
Remove 'gist://' from the path, if present.
path/)r   r1   lstrip)clsrK   s     r   _strip_protocolGistFileSystem._strip_protocol   s*     %T*..vt<{{3r    c                 h   [        U 5      n0 nSU;   a  US   (       a  US   US'   SU;   a  US   (       a  US   US'   SU;   a  US   (       a  US   US'   SU;   aV  US   (       aL  US   R                  SS5      S	S
 n[        U5      S:X  a%  US   (       a  US   US'   US   (       a	  US   /US'   U$ )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   rK   rL   r   Nr   r   r   r   )r   rsplitlen)rK   sorF   
path_partss       r   _get_kwargs_from_urls$GistFileSystem._get_kwargs_from_urls   s     #4(: nC
O:j>CLR<BvJZC	N R<BvJF**32237J:!#a=!+ACJa=(21C$
r    c                    U R                  U=(       d    S5      nUS:X  a  U R                  S   nO=U R                  S   nU Vs/ s H  ofS   U:X  d  M  UPM     nnU(       d  [        U5      eU(       a  U$ [        S U 5       5      $ s  snf )aI  
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   r?   c              3   *   #    U  H	  oS    v   M     g7f)r?   N ).0fs     r   	<genexpr>$GistFileSystem.ls.<locals>.<genexpr>   s     5WF)Ws   )rO   r   r3   sorted)r   rK   detailr   results	all_filesr_   s          r   lsGistFileSystem.ls   s     ##DJB/2:mmB'G b)I"+A)QyD/@q)GA'--N5W555 Bs   B	B	c                    US:w  a  [        S5      eU R                  U5      nU R                  S    Vs/ s H  oUS   U:X  d  M  UPM     nnU(       d  [        U5      eUS   nUR	                  S5      nU(       d  [        SU 35      e[
        R                  " U4SU R                  0U R                  D6n	U	R                  S	:X  a  [        U5      eU	R                  5         [        US
U	R                  5      $ s  snf )z#
Read a single file from the gist.
rbz'GitHub Gist FS is read-only (no write).r   r?   r   r>   zNo raw_url for file: r   r*   N)NotImplementedErrorrO   r   r3   r1   r0   r   r'   r2   r4   r   content)
r   rK   mode
block_sizer   r_   matchesrH   r>   r7   s
             r   _openGistFileSystem._open   s     4<%&OPP##D)"mmB/E/V93D1/E#D))
))I&#&;D6$BCCLLB$,,B$''B==C#D))	$aii00 Fs   C8C8c                 R   U R                  XS9n0 nU H1  n U R                  US5       nUR                  5       Xg'   SSS5        M3     [	        U5      S:X  a  US   U:X  a  Xa   $ U$ ! , (       d  f       Mb  = f! [         a#  n	US:X  a  U	eUS:X  a   Sn	A	M  XU'    Sn	A	M  Sn	A	ff = f)z
Return {path: contents} for the given file or files. If 'recursive' is True,
and path is empty, returns all files in the gist.
)	recursiveri   Nraiseomitr   r   )expand_pathopenreadr3   rV   )
r   rK   rr   on_errorr   pathsrF   pr_   es
             r   catGistFileSystem.cat   s    
    ;A	YYq$'1VVXCF ('  u:?uQx4/9
 ('$ w&G'Fs9   A9A'A9'
A6	1A96A99
B&B!B!!B&)r   r   r   r   r   r   r   )NNNNN)r   F)ri   N)Frs   )__name__
__module____qualname____firstlineno____doc__protocolr/   r-   r   propertyr'   r8   r   classmethodrO   staticmethodrY   rf   ro   r|   __static_attributes____classcell__)r   s   @r   r	   r	      s    6 H7HAL
 42  "@      86610 r    r	   )r0   specr   utilsr   memoryr   r	   r]   r    r   <module>r      s      % ) i' ir    