Skip to content

Commit f571358

Browse files
committed
cleanup
1 parent 892cc8f commit f571358

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

nbviewer/providers/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from urllib.parse import urlparse
2020
from urllib.parse import urlunparse
2121

22-
import statsd #type: ignore
23-
from nbformat import current_nbformat #type:ignore
22+
import statsd # type: ignore
23+
from nbformat import current_nbformat # type:ignore
2424
from nbformat import reads
2525
from tornado import httpclient
2626
from tornado import web
@@ -41,9 +41,9 @@
4141
import pycurl
4242
from tornado.curl_httpclient import CurlError
4343
except ModuleNotFoundError:
44-
pycurl = None #type: ignore
44+
pycurl = None # type: ignore
4545

46-
class CurlError(Exception): #type: ignore
46+
class CurlError(Exception): # type: ignore
4747
pass
4848

4949

@@ -417,8 +417,8 @@ async def fetch(self, url, **overrides):
417417

418418
def write_error(self, status_code: int, **kwargs):
419419
"""render custom error pages"""
420-
exc_info = kwargs.get('exc_info', None)
421-
message:str = ""
420+
exc_info = kwargs.get("exc_info")
421+
message: str = ""
422422
status_message = responses.get(status_code, "Unknown")
423423
exception = None
424424
if exc_info:

nbviewer/providers/github/handlers.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,19 @@ def render_treelist_template(
202202
)
203203

204204
async def _internal_get(self, user: str, repo: str, path: str, ref: str) -> str:
205-
key = (user, repo, path, ref)
205+
"""
206+
Hook into here later during testing – probably via a CLI.
207+
Do avoid doing actual github requests.
208+
209+
We can't use typical mock/patch, as we are in two different processes.
210+
"""
206211
with self.catch_client_error():
207212
response = await self.github_client.get_contents(user, repo, path, ref=ref)
208213
rt = response_text(response)
209-
self.log.info("For key: {key!r} for response: {tr!r}")
210214
return rt
211215

212-
# @cached
213-
async def get(self, user: str, repo: str, ref, path):
216+
@cached
217+
async def get(self, user: str, repo: str, ref: str, path: str):
214218
assert isinstance(user, str)
215219
assert isinstance(repo, str)
216220
assert isinstance(ref, str)
@@ -220,9 +224,9 @@ async def get(self, user: str, repo: str, ref, path):
220224
return
221225
path = path.rstrip("/")
222226

223-
r_text = await self._internal_get(user, repo, ref, path)
224-
225-
contents = json.loads(r_text)
227+
# TODO: check that we can't just use '.json()', it seem to me that recent
228+
# requests and similar expose a .json().
229+
contents = json.loads(await self._internal_get(user, repo, ref, path))
226230

227231
branches, tags = await self.refs(user, repo)
228232

nbviewer/templates/notebook.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,12 @@
159159
Rendered
160160
<span class='date' data-date='{{date}}' title='{{date}}'>({{date}})</span>
161161
</p>
162+
<style>
163+
/* I did not found other ways to override CSS for now */
164+
div.reveal {
165+
font-size: 10px;
166+
167+
}
168+
</style>
162169
{% endif %}
163170
{% endblock extra_footer %}

nbviewer/tests/test_security.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020
class XSSTestCase(NBViewerTestCase):
2121
def _xss(self, path, pattern="<script>alert"):
2222
r = requests.get(self.url() + path)
23-
# self.assertEqual(r.status_code, 200)
24-
# self.assertNotIn(pattern, r.content)
23+
self.assertEqual(r.status_code, 200)
24+
self.assertNotIn(pattern, r.content)
2525

2626
@skip_unless_github_auth
2727
def test_github_dirnames(self):
2828
self._xss("/github/bburky/xss/tree/%3Cscript%3Ealert(1)%3C%2fscript%3E/")
2929

3030
@skip_unless_github_auth
3131
def test_gist_filenames(self):
32-
3332
self._xss("/gist/bburky/c020825874798a6544a7")
3433

3534

0 commit comments

Comments
 (0)