Skip to content

Commit 5ed7c43

Browse files
committed
debug
1 parent 345ec8c commit 5ed7c43

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

nbviewer/providers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def reraise_client_error(self, exc):
383383

384384
slim_body = escape(body[:300])
385385

386-
self.log.warn("Fetching %s failed with %s. Body=%s", url, msg, slim_body)
386+
self.log.error("Fetching %s failed with %s. Body=%s", url, msg, slim_body)
387387
raise web.HTTPError(code, msg)
388388

389389
@contextmanager

nbviewer/providers/github/handlers.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ async def get(self, user, repo):
155155
self.redirect(new_url)
156156

157157

158+
TEST_KEYS = {(1, 2, 3): ""}
159+
160+
158161
class GitHubTreeHandler(GithubClientMixin, BaseHandler):
159162
"""list files in a github repo (like github tree)"""
160163

@@ -198,16 +201,28 @@ def render_treelist_template(
198201
**namespace,
199202
)
200203

201-
@cached
202-
async def get(self, user, repo, ref, path):
204+
async def _internal_get(self, user: str, repo: str, path: str, ref: str) -> str:
205+
key = (user, repo, path, ref)
206+
with self.catch_client_error():
207+
response = await self.github_client.get_contents(user, repo, path, ref=ref)
208+
rt = response_text(response)
209+
self.log.info("For key: {key!r} for response: {tr!r}")
210+
return rt
211+
212+
# @cached
213+
async def get(self, user: str, repo: str, ref, path):
214+
assert isinstance(user, str)
215+
assert isinstance(repo, str)
216+
assert isinstance(ref, str)
217+
assert isinstance(path, str)
203218
if not self.request.uri.endswith("/"):
204219
self.redirect(self.request.uri + "/")
205220
return
206221
path = path.rstrip("/")
207-
with self.catch_client_error():
208-
response = await self.github_client.get_contents(user, repo, path, ref=ref)
209222

210-
contents = json.loads(response_text(response))
223+
r_text = await self._internal_get(user, repo, ref, path)
224+
225+
contents = json.loads(r_text)
211226

212227
branches, tags = await self.refs(user, repo)
213228

nbviewer/tests/test_security.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,7 @@ def test_github_dirnames(self):
3131
@skip_unless_github_auth
3232
def test_gist_filenames(self):
3333

34-
from nbviewer.providers.github.client import AsyncGitHubClient
35-
36-
AsyncGitHubClient.fetch = lambda x: "123"
37-
38-
with patch(
39-
"nbviewer.providers.github.client.AsyncGitHubClient.fetch"
40-
) as mock_fetch:
41-
mock_fetch.return_value = "123"
42-
self._xss("/gist/bburky/c020825874798a6544a7")
43-
mock_fetch.assert_called_with("123")
34+
self._xss("/gist/bburky/c020825874798a6544a7")
4435

4536

4637
class LocalDirectoryTraversalTestCase(LFRPTC):

0 commit comments

Comments
 (0)