
    7Th-                     V    S SK r 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S jrS rSrU =r$ )GithubFileSystem   aJ  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).

For files less than 1 MB in size, file content is returned directly in a
MemoryFile. For larger files, or for files tracked by git-lfs, file content
is returned as an HTTPFile wrapping the ``download_url`` provided by the
GitHub API.

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}zChttps://api.github.com/repos/{org}/{repo}/contents/{path}?ref={sha}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         SSKJn
  U
" S	0 UD6U l        g ! [&         a
    S U l         g f = f)
Nz%Auth required both username and tokenz)https://api.github.com/repos/{org}/{repo}orgrepotimeoutdefault_branch r   )HTTPFileSystem )super__init__r   r   
ValueErrorusernametokenr   requestsgetformatkwraise_for_statusjsonrootlshttpr   http_fsImportError)selfr   r   shar   r   r   kwargsurr   	__class__s              U/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/implementations/github.pyr   GithubFileSystem.__init__.   s     	"6"	$/DEE 
"L;;AS,6:llFJggA  &&(+,C		 ,)3F3DL 	 DL	 s   C C.-C.c                 \    U R                   (       a  SU R                   U R                  40$ 0 $ )Nauth)r   r   r'   s    r-   r   GithubFileSystem.kwL   s&    ==T]]DJJ788	    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.reposR   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/r7   z/tagsr   r8   r   r   r   r   r   r   r    r!   r'   r+   ts      r-   tagsGithubFileSystem.tagsj   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?   r7   z	/branchesr   r8   r@   rA   s      r-   branchesGithubFileSystem.branchesu   st     LL+DHH:QtyykK
LL
 gg

 	
#$668,8a&	8,,,rE   c                 4    U R                   U R                  S.$ )z#Named references, tags and branchesrC   rG   rJ   r1   s    r-   refsGithubFileSystem.refs   s     		t}}==r3   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   Nr7   T)r(   _shar8   r   typefiler(   )r   r   r(   r     	directory)blobtreerT   pathmodesize)r8   rV   rO   rW   r(   )_strip_protocolr"   rstripsplitr#   FileNotFoundErrordircacher   r   urlr   r   r   r   r   status_coder    r!   sorted)r'   rU   detailr(   rN   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)r\   clear)r'   rU   s     r-   invalidate_cache!GithubFileSystem.invalidate_cache   s    r3   c                 l   > [        U5      nSU;  a  [        TU ]	  U5      $ US   R                  S5      $ )Nr   rU   r7   )r   r   rX   lstrip)r9   rU   optsr,   s      r-   rX    GithubFileSystem._strip_protocol   s:    $T*T!7*400F|""3''r3   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   )rU   rp   rd   s      r-   _get_kwargs_from_urls&GithubFileSystem._get_kwargs_from_urls   sF    $T*T!I:&Z0@A<fCJ
r3   c                 r   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         UR                  5       n	U	S   (       a<  [        R                  " U	S   5      n
U
R!                  S5      (       d  [#        S S U
5      $ U R$                  c  ['        S5      eU R$                  R(                  " U	S   4UUUS	.UD6$ )
Nrbr   r   rU   r(   r   rQ   contents#   version https://git-lfs.github.com/zRPlease install fsspec[http] to access github files >1 MB or git-lfs tracked files.download_url)rV   
block_sizecache_options)NotImplementedErrorcontent_urlr   r   r   r"   r   r   r   r   r^   r[   r    r!   base64	b64decode
startswithr   r%   r&   open)r'   rU   rV   r|   r}   r(   r)   r]   r+   content_jsonrz   s              r-   _openGithubFileSystem._open   s/    4<%% %%tyyt9I		 & 

 LL>dll>dgg>==C#D))	vvx 	"&&|I'>?G %%&LMM!$g66
 <<,  ||  (
!'	

 
 	
r3   c                 f    U R                  XUS9n[        U5       H  nU R                  XTS9  M     g )N)	recursivemaxdepth)message)expand_pathreversedrm_file)r'   rU   r   r   r   ps         r-   rmGithubFileSystem.rm  s3    HM$ALLL,  r3   c                    U R                   (       d  [        S5      eU R                  U5      nU R                  U5      nU(       d  U R                  R                  U R                  U R                  UR                  S5      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         UR#                  5       S   nU R                  R                  U R                  U R                  XR                  S9nU R                  nU=(       d    SU 3US.U(       a  S	U0O0 En	[        R$                  " U4XR                  S
.U R                  D6nUR#                  5       R                  SS5      n
[&        R(                  " SU
5      (       a  Sn[        U5      eUR!                  5         U R+                  U5        g)a  
Remove a file from a specified branch using a given commit message.

Since Github DELETE operation requires a branch name, and we can't reliably
determine whether the provided SHA refers to a branch, tag, or commit, we
assume it's a branch. If it's not, the user will encounter an error when
attempting to retrieve the file SHA or delete the file.

Parameters
----------
path: str
    The file's location relative to the repository root.
message: str, optional
    The commit message for the deletion.
zAuthentication requiredr7   ry   r   rQ   r(   zDelete )r   r(   branch)r!   r   r   r   zBranch .+ not foundzTRemove only works when the filesystem is initialised from a branch or default (None)N)r   r   rX   _get_sha_from_cacher   r   r   r   ro   r"   r   r   r   r   r^   r[   r    r!   deleteresearchrl   )r'   rU   r   r)   r(   r]   r+   
delete_urlr   dataerror_messageerrors               r-   r   GithubFileSystem.rm_file  s   " }}677##D) &&t,""))HH4994;;s3C * C SB$,,B$''BA}}#'-- &&(5/C %%,,tyyt - 

 2GD6"2
 &,&!
 OOJST<<S477SY399+];;jEU##	d#r3   c                     U R                   R                  5        H<  nU H3  nUR                  S5      nU(       d  M  XA:X  d  M$  SU;   d  M,  US   s  s  $    M>     g )Nr8   r(   )r\   valuesr   )r'   rU   entriesentry
entry_paths        r-   r   $GithubFileSystem._get_sha_from_cacheI  sP    }}++-G "YYv.
:*"4% <' ! .
 r3   )r%   r   r   r"   r   r   r   )NNNN)T)FNNrj   )rx   NNN)__name__
__module____qualname____firstlineno____doc__r]   r   protocolr   r   propertyr   classmethodr<   rC   rG   rK   r#   rl   rX   staticmethodru   r   r   r   r   __static_attributes____classcell__)r,   s   @r-   r
   r
      s    6 FCWKHG GK <  
 3 3. - - - - > >@4D ( (   1
f-
4$l r3   r
   )
r   r   r   specr   utilsr   memoryr   r
   r   r3   r-   <module>r      s&     	  % ) 
B) Br3   