
    FgB                     N    S SK r 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r SU 4S jjr	\
S 5       r\SS	 j5       r\
S
 5       r\
S 5       r\
S 5       rSS jrSS jr\U 4S j5       r\S 5       r     SS jrSS jrSrU =r$ )GithubFileSystem   a  Interface to files in github

An instance of this class provides the files residing within a remote github
repository. You may specify a point in the repos history, by SHA, branch
or tag (default is current master).

Given that code files tend to be small, and that github does not support
retrieving partial content, we always fetch whole files.

When using fsspec.open, allows URIs of the form:

- "github://path/file", in which case you must specify org, repo and
  may specify sha in the extra args
- 'github://org:repo@/precip/catalog.yml', where the org and repo are
  part of the URI
- 'github://org:repo@sha/precip/catalog.yml', where the sha is also included

``sha`` can be the full or abbreviated hex of the commit you want to fetch
from, or a branch or tag name (so long as it doesn't contain special characters
like "/", "?", which would have to be HTTP-encoded).

For authorised access, you must provide username and token, which can be made
at https://github.com/settings/tokens
z9https://api.github.com/repos/{org}/{repo}/git/trees/{sha}z;https://raw.githubusercontent.com/{org}/{repo}/{sha}/{path}github)<   r   c                   > [         T
U ]  " S0 UD6  Xl        X l        US L US L -  (       a  [	        S5      eX@l        XPl        Ub  X`l        Uc_  Sn[        R                  " UR                  XS94SU R                  0U R                  D6n	U	R                  5         U	R                  5       S   nX0l        U R                  S5        g )Nz%Auth required both username and tokenz)https://api.github.com/repos/{org}/{repo}orgrepotimeoutdefault_branch  )super__init__r   r   
ValueErrorusernametokenr   requestsgetformatkwraise_for_statusjsonrootls)selfr   r   shar   r   r   kwargsur	__class__s             n/Users/admin/workspace/ai/PDFMathTranslate/myenv/lib/python3.13/site-packages/fsspec/implementations/github.pyr   GithubFileSystem.__init__+   s     	"6"	$/DEE 
"L;;AS,6:llFJggA  &&(+,C	    c                 \    U R                   (       a  SU R                   U R                  40$ 0 $ )Nauth)r   r   r#   s    r)   r   GithubFileSystem.kwC   s&    ==T]]DJJ788	r+   c                     [         R                  " SSS/U    SU S3U R                  S9nUR                  5         UR	                  5        Vs/ s H  oDS   PM	     sn$ s  snf )a  List repo names for given org or user

This may become the top level of the FS

Parameters
----------
org_or_user: str
    Name of the github org or user to query
is_org: bool (default True)
    Whether the name is an organisation (True) or user (False)

Returns
-------
List of string
zhttps://api.github.com/usersorgs/z/repos)r   name)r   r   r   r   r    )clsorg_or_useris_orgr'   r   s        r)   reposGithubFileSystem.reposI   sd    " LL%w&7&?%@+fUKK
 	
)*2V222s   Ac                    [         R                  " SU R                   SU R                   S34SU R                  0U R
                  D6nUR                  5         UR                  5        Vs/ s H  o"S   PM	     sn$ s  snf )zNames of tags in the repohttps://api.github.com/repos/r3   z/tagsr   r4   r   r   r   r   r   r   r   r    r#   r'   ts      r)   tagsGithubFileSystem.tagsa   st     LL+DHH:QtyykG
LL
 gg

 	
#$668,8a&	8,,,   +A<c                    [         R                  " SU R                   SU R                   S34SU R                  0U R
                  D6nUR                  5         UR                  5        Vs/ s H  o"S   PM	     sn$ s  snf )zNames of branches in the repor;   r3   z	/branchesr   r4   r<   r=   s      r)   branchesGithubFileSystem.branchesl   st     LL+DHH:QtyykK
LL
 gg

 	
#$668,8a&	8,,,rA   c                 4    U R                   U R                  S.$ )z#Named references, tags and branchesr?   rC   rF   r.   s    r)   refsGithubFileSystem.refsw   s     		t}}==r+   c           
         U R                  U5      nUS:X  a  U=(       d    U R                  nUc  UR                  S5      R                  S5      nSnU=(       d    U R                  nU Hu  nU R	                  USX4S9n	Xw(       a  SU-   OU-  nU	 V
s/ s H  oS   U:X  d  M  U
PM     n	n
U	(       d  [        U5      eU	S   n	U	S   S	:X  a  U(       a  U	/s  $ Us  $ U	S
   nMw     XR                  ;  d  X0R                  S4;  Ga  [        R                  " U R                  R                  U R                  U R                  US94SU R                  0U R                  D6nUR                  S:X  a  [        U5      eUR!                  5         S	SS.nUR#                  5       S    Vs/ s HF  nUS   U;   d  M  U(       a  US-   US   -   OUS   US   XS      UR                  SS5      US
   S.PMH     n	nX0R                  S4;   a  XR                  U'   OU R                  U   n	U(       a  U	$ [%        U	 Vs/ s H  oS   PM	     sn5      $ s  sn
f s  snf s  snf )a  List files at given path

Parameters
----------
path: str
    Location to list, relative to repo root
detail: bool
    If True, returns list of dicts, one per file; if False, returns
    list of full filenames only
sha: str (optional)
    List at the given point in the repo history, branch or tag name or commit
    SHA
_sha: str (optional)
    List this specific tree object (used internally to descend into trees)
r   Nr3   T)r$   _shar4   r   typefiler$   )r   r   r$   r     	directory)blobtreerP   pathmodesize)r4   rR   rK   rS   r$   )_strip_protocolr!   rstripsplitr"   FileNotFoundErrordircacher   r   urlr   r   r   r   r   status_coder   r    sorted)r#   rQ   detailr$   rJ   r%   partsso_farpartoutor'   typesfs                 r)   r"   GithubFileSystem.ls|   sQ     ##D)2:#$))D<KK$**3/EF#$))Dggfdg?#*D8"%=#Q6f)<q#=+D11!fv;&( #u#5z  }}$IIt3D(DDHH499$G ''A
 }}#'-- #[9E &)
 *AV9%6:D3J62&	fI!F),EE&!,U8 *  
 yy$''&)d#--%CJc2cV9c233M >(
$ 3s   I!I"I3<I2Ic                 8    U R                   R                  5         g N)rX   clear)r#   rQ   s     r)   invalidate_cache!GithubFileSystem.invalidate_cache   s    r+   c                 l   > [        U5      nSU;  a  [        TU ]	  U5      $ US   R                  S5      $ )Nr   rQ   r3   )r   r   rT   lstrip)r5   rQ   optsr(   s      r)   rT    GithubFileSystem._strip_protocol   s:    $T*T!7*400F|""3''r+   c                 f    [        U 5      nSU;  a  0 $ US   US   S.nUS   (       a  US   US'   U$ )Nr   passwordr   hostr$   r   )rQ   rl   r`   s      r)   _get_kwargs_from_urls&GithubFileSystem._get_kwargs_from_urls   sF    $T*T!I:&Z0@A<fCJ
r+   c                 |   US:w  a  [         eU R                  R                  U R                  U R                  X=(       d    U R
                  S9n[        R                  " U4SU R                  0U R                  D6n	U	R                  S:X  a  [        U5      eU	R                  5         [        S S U	R                  5      $ )Nrbr   r   rQ   r$   r   rM   )NotImplementedErrorrurlr   r   r   r!   r   r   r   r   rZ   rW   r   r   content)
r#   rQ   rR   
block_size
autocommitcache_optionsr$   r%   rY   r'   s
             r)   _openGithubFileSystem._open   s     4<%%iityyt9I		  
 LL>dll>dgg>==C#D))	$aii00r+   c                    U R                  XS9nU VVs/ s H>  u  pgU R                  R                  U R                  U R                  X`R
                  S9PM@     nnn[        R                  " S5      n	U	R                  USS9n
[        U
R                  5       U5       VVVs0 s H
  u  u  pofU_M     snnn$ s  snnf s  snnnf )N)	recursiveru   httpreturn)on_error)expand_pathrw   r   r   r   r!   fsspec
filesystemcatzipitems)r#   rQ   r   r   r%   pathsr&   shurlsfsdatakvs                r)   r   GithubFileSystem.cat   s       ; 
 II		yyQ 	 
 v&vvdXv.(+DJJL$(?@(?&1!1(?@@
 As   AB7!B=)r   r   r!   r   r   r   )NNNN)T)FNNrf   )rt   NTNN)Fraise)__name__
__module____qualname____firstlineno____doc__rY   rw   protocolr   r   propertyr   classmethodr8   r?   rC   rG   r"   rh   rT   staticmethodrq   r|   r   __static_attributes____classcell__)r(   s   @r)   r
   r
      s    2 FCHDHG GK0  
 3 3. - - - - > >@4D ( (   1*A Ar+   r
   )	r   r   specr   utilsr   memoryr   r
   r   r+   r)   <module>r      s%      % ) 
cA) cAr+   