@@ -14,21 +14,21 @@ class GistFileSystem(AbstractFileSystem):
1414
1515 Parameters
1616 ----------
17- gist_id : str
17+ gist_id: str
1818 The ID of the gist you want to access (the long hex value from the URL).
19- filenames : list[str] (optional)
19+ filenames: list[str] (optional)
2020 If provided, only make a file system representing these files, and do not fetch
2121 the list of all files for this gist.
22- sha : str (optional)
22+ sha: str (optional)
2323 If provided, fetch a particular revision of the gist. If omitted,
2424 the latest revision is used.
25- username : str (optional)
26- GitHub username for authentication (required if token is given) .
27- token : str (optional)
28- GitHub personal access token (required if username is given).
29- timeout : (float, float) or float, optional
25+ username: str (optional)
26+ GitHub username for authentication.
27+ token: str (optional)
28+ GitHub personal access token (required if username is given), or .
29+ timeout: (float, float) or float, optional
3030 Connect and read timeouts for requests (default 60s each).
31- kwargs : dict
31+ kwargs: dict
3232 Stored on `self.request_kw` and passed to `requests.get` when fetching Gist
3333 metadata or reading ("opening") a file.
3434 """
@@ -51,10 +51,8 @@ def __init__(
5151 self .gist_id = gist_id
5252 self .filenames = filenames
5353 self .sha = sha # revision of the gist (optional)
54- if (username is None ) ^ (token is None ):
55- # Both or neither must be set
56- if username or token :
57- raise ValueError ("Auth requires both username and token, or neither." )
54+ if username is not None and token is None :
55+ raise ValueError ("User auth requires a token" )
5856 self .username = username
5957 self .token = token
6058 self .request_kw = kwargs
@@ -67,9 +65,18 @@ def __init__(
6765 @property
6866 def kw (self ):
6967 """Auth parameters passed to 'requests' if we have username/token."""
70- if self .username is not None and self .token is not None :
71- return {"auth" : (self .username , self .token ), ** self .request_kw }
72- return self .request_kw
68+ kw = {
69+ "headers" : {
70+ "Accept" : "application/vnd.github+json" ,
71+ "X-GitHub-Api-Version" : "2022-11-28" ,
72+ }
73+ }
74+ kw .update (self .request_kw )
75+ if self .username and self .token :
76+ kw ["auth" ] = (self .username , self .token )
77+ elif self .token :
78+ kw ["headers" ]["Authorization" ] = f"Bearer { self .token } "
79+ return kw
7380
7481 def _fetch_gist_metadata (self ):
7582 """
@@ -229,4 +236,6 @@ def cat(self, path, recursive=False, on_error="raise", **kwargs):
229236 pass # skip
230237 else :
231238 out [p ] = e
239+ if len (paths ) == 1 and paths [0 ] == path :
240+ return out [path ]
232241 return out
0 commit comments