Skip to content

Commit 9004183

Browse files
authored
Merge pull request #1028 from Carreau/pyup
More pyupgrade cleanup.
2 parents 5888059 + 4fec2e8 commit 9004183

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

nbviewer/providers/base.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import asyncio
88
import hashlib
99
import pickle
10-
import socket
1110
import time
1211
from contextlib import contextmanager
1312
from datetime import datetime
@@ -342,7 +341,7 @@ def client_error_message(self, exc, url, body, msg=None):
342341

343342
if (msg is None) and body and len(body) < 100:
344343
# if it's a short plain-text error message, include it
345-
msg = "%s (%s)" % (str_exc, escape(body))
344+
msg = "{} ({})".format(str_exc, escape(body))
346345

347346
if not msg:
348347
msg = str_exc
@@ -396,7 +395,7 @@ def catch_client_error(self):
396395
yield
397396
except httpclient.HTTPError as e:
398397
self.reraise_client_error(e)
399-
except socket.error as e:
398+
except OSError as e:
400399
raise web.HTTPError(404, str(e))
401400

402401
@property
@@ -478,7 +477,7 @@ def cache_key(self):
478477
def truncate(self, s, limit=256):
479478
"""Truncate long strings"""
480479
if len(s) > limit:
481-
s = "%s...%s" % (s[: limit // 2], s[limit // 2 :])
480+
s = "{}...{}".format(s[: limit // 2], s[limit // 2 :])
482481
return s
483482

484483
async def cache_and_finish(self, content=""):
@@ -767,7 +766,7 @@ class FilesRedirectHandler(BaseHandler):
767766

768767
def get(self, before_files, after_files):
769768
self.log.info("Redirecting %s to %s", before_files, after_files)
770-
self.redirect("%s/%s" % (before_files, after_files))
769+
self.redirect("{}/{}".format(before_files, after_files))
771770

772771

773772
class AddSlashHandler(BaseHandler):
@@ -776,7 +775,7 @@ class AddSlashHandler(BaseHandler):
776775
def get(self, *args, **kwargs):
777776
uri = self.request.path + "/"
778777
if self.request.query:
779-
uri = "%s?%s" % (uri, self.request.query)
778+
uri = "{}?{}".format(uri, self.request.query)
780779
self.redirect(uri)
781780

782781

@@ -786,5 +785,5 @@ class RemoveSlashHandler(BaseHandler):
786785
def get(self, *args, **kwargs):
787786
uri = self.request.path.rstrip("/")
788787
if self.request.query:
789-
uri = "%s?%s" % (uri, self.request.query)
788+
uri = "{}?{}".format(uri, self.request.query)
790789
self.redirect(uri)

nbviewer/providers/gist/handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ async def tree_get(self, user, gist_id, gist, files):
159159
e = {}
160160
e["name"] = file["filename"]
161161
if file["filename"].endswith(".ipynb"):
162-
e["url"] = quote("/%s/%s" % (gist_id, file["filename"]))
162+
e["url"] = quote("/{}/{}".format(gist_id, file["filename"]))
163163
e["class"] = "fa-book"
164164
ipynbs.append(e)
165165
else:
@@ -318,9 +318,9 @@ class GistRedirectHandler(BaseHandler):
318318
"""redirect old /<gist-id> to new /gist/<gist-id>"""
319319

320320
def get(self, gist_id, file=""):
321-
new_url = "%s/gist/%s" % (self.format_prefix, gist_id)
321+
new_url = "{}/gist/{}".format(self.format_prefix, gist_id)
322322
if file:
323-
new_url = "%s/%s" % (new_url, file)
323+
new_url = "{}/{}".format(new_url, file)
324324

325325
self.log.info("Redirecting %s to %s", self.request.uri, new_url)
326326
self.redirect(self.from_base(new_url))

nbviewer/providers/github/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# -----------------------------------------------------------------------------
2222

2323

24-
class AsyncGitHubClient(object):
24+
class AsyncGitHubClient:
2525
"""AsyncHTTPClient wrapper with methods for common requests"""
2626

2727
auth = None

nbviewer/providers/github/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .client import AsyncGitHubClient
2626

2727

28-
class GithubClientMixin(object):
28+
class GithubClientMixin:
2929

3030
# PROVIDER_CTX is a dictionary whose entries are passed as keyword arguments
3131
# to the render_template method of the GistHandler. The following describe

nbviewer/providers/local/handlers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# the file COPYING, distributed as part of this software.
66
# -----------------------------------------------------------------------------
77
import errno
8-
import io
98
import os
109
import stat
1110
from datetime import datetime
@@ -150,9 +149,9 @@ async def get_notebook_data(self, path):
150149

151150
async def deliver_notebook(self, fullpath, path):
152151
try:
153-
with io.open(fullpath, encoding="utf-8") as f:
152+
with open(fullpath, encoding="utf-8") as f:
154153
nbdata = f.read()
155-
except IOError as ex:
154+
except OSError as ex:
156155
if ex.errno == errno.EACCES:
157156
# py3: can't read the file, so don't give away it exists
158157
self.log.info(
@@ -236,7 +235,7 @@ def show_dir(self, fullpath, path, **namespace):
236235

237236
try:
238237
contents = os.listdir(fullpath)
239-
except IOError as ex:
238+
except OSError as ex:
240239
if ex.errno == errno.EACCES:
241240
# can't access the dir, so don't give away its presence
242241
self.log.info(

0 commit comments

Comments
 (0)