L iP!FddlZddlmZddlmZddlmZGddeZy) N)AbstractFileSystem)infer_storage_options) MemoryFileceZdZdZdZdZdZ dfd ZedZ dZ dZ e d Z ed Zdd Zdd Zdd ZxZS)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}c t|||_||_||_| | t d||_||_||_||nd|_ |j|jd<y)NzUser auth requires a token)<r ) super__init__gist_id filenamessha ValueErrorusernametoken request_kwtimeout_fetch_file_listdircache) selfrrrrrrkwargs __class__s a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fsspec/implementations/gist.pyrzGistFileSystem.__init__(sw  "  EM9: :    ")"5w8 !113 bcddddi}|j|j|jr)|jr|j|jf|d<|S|jrd|j|dd<|S)z?Auth parameters passed to 'requests' if we have username/token.headerszapplication/vnd.github+jsonz 2022-11-28)AcceptzX-GitHub-Api-VersionauthzBearer Authorization)updaterrr)rkws rr%zGistFileSystem.kwAs| 7(4  $//" ==TZZ--4BvJ ZZ/6tzzl-CByM/ * rc|jr2|jj|j|j}n&|jj|j}t j |fd|ji|j}|jdk(r)td|jd|jxsd|j|jS)z[ Fetch the JSON metadata for this gist (possibly for a specific revision). )rr)rrzGist not found: @latest) r gist_rev_urlformatrgist_urlrequestsgetrr% status_codeFileNotFoundErrorraise_for_statusjson)rurlrs r_fetch_gist_metadataz#GistFileSystem._fetch_gist_metadataQs 88##**4<dll >dgg > ==C #"4<<.$((2Fh1GH  vvxrc |j}|jr=|jdi}i}|jD]}||vr t|||||<n|jdi}g}|j D]=\}}| |j |d|jdd|jdd?|S)zz Returns a list of dicts describing each file in the gist. These get stored in self.dircache[""]. filesfilesizerraw_url)nametyper9r:)r5rr.r0itemsappend)rmetaavailable_filesr7fnoutfnamefinfos rrzGistFileSystem._fetch_file_listbs ((* >>"hhw3OEnn 0_,+B//+B/b  0 HHWb)E!KKM LE5} JJ!"!IIfa0$yy3    rcZt|jd|}|jdS)z= Remove 'gist://' from the path, if present. path/)rr.lstrip)clsrFs r_strip_protocolzGistFileSystem._strip_protocols*%T*..vt<{{3rct|}i}d|vr |dr|d|d<d|vr |dr|d|d<d|vr |dr|d|d<d|vrF|drA|djddd d }t|dk(r|d r|d |d <|d r |d g|d<|S)z Parse 'gist://' style URLs into GistFileSystem constructor kwargs. For example: gist://:TOKEN@/file.txt gist://username:TOKEN@/file.txt rpasswordrhostrrFrGrNrrrr)rrsplitlen)rFsorB path_partss r_get_kwargs_from_urlsz$GistFileSystem._get_kwargs_from_urlss#4 (  : nC O  :j>CL Rz$GistFileSystem.ls..s5!F)5s)rJrr0sorted)rrFdetailrresults all_filesrXs rlszGistFileSystem.lss##DJB/ 2:mmB'G b)I"+AQqyD/@qAGA'-- N5W55 5 Bs A5 A5c |dk7r td|j|}|jdDcgc] }|d|k(s |}}|s t||d}|j d}|std|t j|fd|j i|j} | jd k(r t|| jt|d | jScc}w) z3 Read a single file from the gist. rbz'GitHub Gist FS is read-only (no write).r r;rr:zNo raw_url for file: rr'N) NotImplementedErrorrJrr0r.r-rr%r/r1rcontent) rrFmode block_sizerrXmatchesrDr:r4s r_openzGistFileSystem._opens 4<%&OP P##D)"mmB/E1V93D1EE#D) ) ))I&#&;D6$BC C LL B$,, B$'' B ==C #D) ) $aii00Fs C'C'c :|j||}i}|D]1} |j|d5}|j||<ddd3t |dk(r |d|k(r||S|S#1swY(xYw#t$r} |dk(r| |dk(rn| ||<Yd} ~ }d} ~ wwxYw)z Return {path: contents} for the given file or files. If 'recursive' is True, and path is empty, returns all files in the gist. ) recursiver`Nraiseomitrr) expand_pathopenreadr0rP) rrFrhon_errorrpathsrBprXes rcatzGistFileSystem.cats    ; A YYq$'&1VVXCF&  u:?uQx4/t9  &&$ w&G'CF  s.A5A)A5)A2 .A55 B>BB)NNNNN)r F)r`N)Fri)__name__ __module__ __qualname____doc__protocolr,r*rpropertyr%r5r classmethodrJ staticmethodrSr^rfrr __classcell__)rs@rr r s6H7HAL  42  "@  86610rr )r-specrutilsrmemoryrr rVrrrs %)i'ir