Skip to content

Commit 18e4834

Browse files
authored
Merge pull request #5806 from rahulporuri/cln/update-super-usage
Update super usage
2 parents 158cc00 + 84df529 commit 18e4834

19 files changed

+56
-60
lines changed

notebook/base/handlers.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def allow_credentials(self):
301301

302302
def set_default_headers(self):
303303
"""Add CORS headers, if defined"""
304-
super(IPythonHandler, self).set_default_headers()
304+
super().set_default_headers()
305305
if self.allow_origin:
306306
self.set_header("Access-Control-Allow-Origin", self.allow_origin)
307307
elif self.allow_origin_pat:
@@ -442,7 +442,7 @@ def check_xsrf_cookie(self):
442442
# Servers without authentication are vulnerable to XSRF
443443
return
444444
try:
445-
return super(IPythonHandler, self).check_xsrf_cookie()
445+
return super().check_xsrf_cookie()
446446
except web.HTTPError as e:
447447
if self.request.method in {'GET', 'HEAD'}:
448448
# Consider Referer a sufficient cross-origin check for GET requests
@@ -496,7 +496,7 @@ def check_host(self):
496496
def prepare(self):
497497
if not self.check_host():
498498
raise web.HTTPError(403)
499-
return super(IPythonHandler, self).prepare()
499+
return super().prepare()
500500

501501
#---------------------------------------------------------------
502502
# template rendering
@@ -591,7 +591,7 @@ class APIHandler(IPythonHandler):
591591
def prepare(self):
592592
if not self.check_origin():
593593
raise web.HTTPError(404)
594-
return super(APIHandler, self).prepare()
594+
return super().prepare()
595595

596596
def write_error(self, status_code, **kwargs):
597597
"""APIHandler errors are JSON, not human pages"""
@@ -618,7 +618,7 @@ def get_current_user(self):
618618
# preserve _user_cache so we don't raise more than once
619619
if hasattr(self, '_user_cache'):
620620
return self._user_cache
621-
self._user_cache = user = super(APIHandler, self).get_current_user()
621+
self._user_cache = user = super().get_current_user()
622622
return user
623623

624624
def get_login_url(self):
@@ -627,12 +627,12 @@ def get_login_url(self):
627627
# instead of redirecting, raise 403 instead.
628628
if not self.current_user:
629629
raise web.HTTPError(403)
630-
return super(APIHandler, self).get_login_url()
630+
return super().get_login_url()
631631

632632
@property
633633
def content_security_policy(self):
634634
csp = '; '.join([
635-
super(APIHandler, self).content_security_policy,
635+
super().content_security_policy,
636636
"default-src 'none'",
637637
])
638638
return csp
@@ -653,7 +653,7 @@ def update_api_activity(self):
653653
def finish(self, *args, **kwargs):
654654
self.update_api_activity()
655655
self.set_header('Content-Type', 'application/json')
656-
return super(APIHandler, self).finish(*args, **kwargs)
656+
return super().finish(*args, **kwargs)
657657

658658
def options(self, *args, **kwargs):
659659
if 'Access-Control-Allow-Headers' in self.settings.get('headers', {}):
@@ -700,13 +700,12 @@ class AuthenticatedFileHandler(IPythonHandler, web.StaticFileHandler):
700700
def content_security_policy(self):
701701
# In case we're serving HTML/SVG, confine any Javascript to a unique
702702
# origin so it can't interact with the notebook server.
703-
return super(AuthenticatedFileHandler, self).content_security_policy + \
704-
"; sandbox allow-scripts"
703+
return super().content_security_policy + "; sandbox allow-scripts"
705704

706705
@web.authenticated
707706
def head(self, path):
708707
self.check_xsrf_cookie()
709-
return super(AuthenticatedFileHandler, self).head(path)
708+
return super().head(path)
710709

711710
@web.authenticated
712711
def get(self, path):
@@ -731,10 +730,10 @@ def get_content_type(self):
731730
if cur_mime == 'text/plain':
732731
return 'text/plain; charset=UTF-8'
733732
else:
734-
return super(AuthenticatedFileHandler, self).get_content_type()
733+
return super().get_content_type()
735734

736735
def set_headers(self):
737-
super(AuthenticatedFileHandler, self).set_headers()
736+
super().set_headers()
738737
# disable browser caching, rely on 304 replies for savings
739738
if "v" not in self.request.arguments:
740739
self.add_header("Cache-Control", "no-cache")
@@ -749,7 +748,7 @@ def validate_absolute_path(self, root, absolute_path):
749748
750749
Adding to tornado's own handling, forbids the serving of hidden files.
751750
"""
752-
abs_path = super(AuthenticatedFileHandler, self).validate_absolute_path(root, absolute_path)
751+
abs_path = super().validate_absolute_path(root, absolute_path)
753752
abs_root = os.path.abspath(root)
754753
if is_hidden(abs_path, abs_root) and not self.contents_manager.allow_hidden:
755754
self.log.info("Refusing to serve hidden file, via 404 Error, use flag 'ContentsManager.allow_hidden' to enable")
@@ -795,7 +794,7 @@ class FileFindHandler(IPythonHandler, web.StaticFileHandler):
795794
_static_paths = {}
796795

797796
def set_headers(self):
798-
super(FileFindHandler, self).set_headers()
797+
super().set_headers()
799798
# disable browser caching, rely on 304 replies for savings
800799
if "v" not in self.request.arguments or \
801800
any(self.request.path.startswith(path) for path in self.no_cache_paths):
@@ -842,7 +841,7 @@ def validate_absolute_path(self, root, absolute_path):
842841
if (absolute_path + os.sep).startswith(root):
843842
break
844843

845-
return super(FileFindHandler, self).validate_absolute_path(root, absolute_path)
844+
return super().validate_absolute_path(root, absolute_path)
846845

847846

848847
class APIVersionHandler(APIHandler):

notebook/base/zmqhandlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def get(self, *args, **kwargs):
288288
# assign and yield in two step to avoid tornado 3 issues
289289
res = self.pre_get()
290290
yield maybe_future(res)
291-
res = super(AuthenticatedZMQStreamHandler, self).get(*args, **kwargs)
291+
res = super().get(*args, **kwargs)
292292
yield maybe_future(res)
293293

294294
def initialize(self):

notebook/bundler/bundlerextensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class BundlerExtensionApp(BaseExtensionApp):
294294

295295
def start(self):
296296
"""Perform the App's functions as configured"""
297-
super(BundlerExtensionApp, self).start()
297+
super().start()
298298

299299
# The above should have called a subcommand and raised NoStart; if we
300300
# get here, it didn't, so we should self.log.info a message.

notebook/files/handlers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class FilesHandler(IPythonHandler):
2626
def content_security_policy(self):
2727
# In case we're serving HTML/SVG, confine any Javascript to a unique
2828
# origin so it can't interact with the notebook server.
29-
return super(FilesHandler, self).content_security_policy + \
30-
"; sandbox allow-scripts"
29+
return super().content_security_policy + "; sandbox allow-scripts"
3130

3231
@web.authenticated
3332
def head(self, path):

notebook/gateway/handlers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def initialize(self):
6868
def get(self, kernel_id, *args, **kwargs):
6969
self.authenticate()
7070
self.kernel_id = cast_unicode(kernel_id, 'ascii')
71-
yield super(WebSocketChannelsHandler, self).get(kernel_id=kernel_id, *args, **kwargs)
71+
yield super().get(kernel_id=kernel_id, *args, **kwargs)
7272

7373
def send_ping(self):
7474
if self.ws_connection is None and self.ping_callback is not None:
@@ -97,15 +97,15 @@ def write_message(self, message, binary=False):
9797
if self.ws_connection: # prevent WebSocketClosedError
9898
if isinstance(message, bytes):
9999
binary = True
100-
super(WebSocketChannelsHandler, self).write_message(message, binary=binary)
100+
super().write_message(message, binary=binary)
101101
elif self.log.isEnabledFor(logging.DEBUG):
102102
msg_summary = WebSocketChannelsHandler._get_message_summary(json_decode(utf8(message)))
103103
self.log.debug("Notebook client closed websocket connection - message dropped: {}".format(msg_summary))
104104

105105
def on_close(self):
106106
self.log.debug("Closing websocket connection %s", self.request.path)
107107
self.gateway.on_close()
108-
super(WebSocketChannelsHandler, self).on_close()
108+
super().on_close()
109109

110110
@staticmethod
111111
def _get_message_summary(message):
@@ -129,7 +129,7 @@ class GatewayWebSocketClient(LoggingConfigurable):
129129
"""Proxy web socket connection to a kernel/enterprise gateway."""
130130

131131
def __init__(self, **kwargs):
132-
super(GatewayWebSocketClient, self).__init__(**kwargs)
132+
super().__init__(**kwargs)
133133
self.kernel_id = None
134134
self.ws = None
135135
self.ws_future = Future()

notebook/gateway/managers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def validate_cert_default(self):
205205
return bool(os.environ.get(self.validate_cert_env, str(self.validate_cert_default_value)) not in ['no', 'false'])
206206

207207
def __init__(self, **kwargs):
208-
super(GatewayClient, self).__init__(**kwargs)
208+
super().__init__(**kwargs)
209209
self._static_args = {} # initialized on first use
210210

211211
env_whitelist_default_value = ''
@@ -310,7 +310,7 @@ class GatewayKernelManager(MappingKernelManager):
310310
_kernels = {}
311311

312312
def __init__(self, **kwargs):
313-
super(GatewayKernelManager, self).__init__(**kwargs)
313+
super().__init__(**kwargs)
314314
self.base_endpoint = url_path_join(GatewayClient.instance().url, GatewayClient.instance().kernels_endpoint)
315315

316316
def __contains__(self, kernel_id):
@@ -507,7 +507,7 @@ def shutdown_all(self, now=False):
507507
class GatewayKernelSpecManager(KernelSpecManager):
508508

509509
def __init__(self, **kwargs):
510-
super(GatewayKernelSpecManager, self).__init__(**kwargs)
510+
super().__init__(**kwargs)
511511
base_endpoint = url_path_join(GatewayClient.instance().url,
512512
GatewayClient.instance().kernelspecs_endpoint)
513513

notebook/jstest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class StreamCapturer(Thread):
4242
daemon = True # Don't hang if main thread crashes
4343
started = False
4444
def __init__(self, echo=False):
45-
super(StreamCapturer, self).__init__()
45+
super().__init__()
4646
self.echo = echo
4747
self.streams = []
4848
self.buffer = BytesIO()
@@ -261,14 +261,14 @@ def launch(self, buffer_output):
261261
# If the engine is SlimerJS, we need to buffer the output because
262262
# SlimerJS does not support exit codes, so CasperJS always returns 0.
263263
if self.engine == 'slimerjs' and not buffer_output:
264-
return super(JSController, self).launch(capture_output=True)
264+
return super().launch(capture_output=True)
265265

266266
else:
267-
return super(JSController, self).launch(buffer_output=buffer_output)
267+
return super().launch(buffer_output=buffer_output)
268268

269269
def wait(self, *pargs, **kwargs):
270270
"""Wait for the JSController to finish"""
271-
ret = super(JSController, self).wait(*pargs, **kwargs)
271+
ret = super().wait(*pargs, **kwargs)
272272
# If this is a SlimerJS controller, check the captured stdout for
273273
# errors. Otherwise, just return the return code.
274274
if self.engine == 'slimerjs':

notebook/nbconvert/handlers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ class NbconvertFileHandler(IPythonHandler):
8383
def content_security_policy(self):
8484
# In case we're serving HTML/SVG, confine any Javascript to a unique
8585
# origin so it can't interact with the notebook server.
86-
return super(NbconvertFileHandler, self).content_security_policy + \
87-
"; sandbox allow-scripts"
86+
return super().content_security_policy + "; sandbox allow-scripts"
8887

8988
@web.authenticated
9089
@gen.coroutine
@@ -158,8 +157,7 @@ class NbconvertPostHandler(IPythonHandler):
158157
def content_security_policy(self):
159158
# In case we're serving HTML/SVG, confine any Javascript to a unique
160159
# origin so it can't interact with the notebook server.
161-
return super(NbconvertPostHandler, self).content_security_policy + \
162-
"; sandbox allow-scripts"
160+
return super().content_security_policy + "; sandbox allow-scripts"
163161

164162
@web.authenticated
165163
def post(self, format):

notebook/nbextensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ class NBExtensionApp(BaseExtensionApp):
977977

978978
def start(self):
979979
"""Perform the App's functions as configured"""
980-
super(NBExtensionApp, self).start()
980+
super().start()
981981

982982
# The above should have called a subcommand and raised NoStart; if we
983983
# get here, it didn't, so we should self.log.info a message.

notebook/notebookapp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def __init__(self, jupyter_app, kernel_manager, contents_manager,
187187
if settings['autoreload']:
188188
log.info('Autoreload enabled: the webapp will restart when any Python src file changes.')
189189

190-
super(NotebookWebApplication, self).__init__(handlers, **settings)
190+
super().__init__(handlers, **settings)
191191

192192
def init_settings(self, jupyter_app, kernel_manager, contents_manager,
193193
session_manager, kernel_spec_manager,
@@ -508,7 +508,7 @@ class NbserverStopApp(JupyterApp):
508508
help="UNIX socket of the server to be killed.")
509509

510510
def parse_command_line(self, argv=None):
511-
super(NbserverStopApp, self).parse_command_line(argv)
511+
super().parse_command_line(argv)
512512
if self.extra_args:
513513
try:
514514
self.port = int(self.extra_args[0])
@@ -1520,7 +1520,7 @@ def _update_server_extensions(self, change):
15201520
terminals_available = False
15211521

15221522
def parse_command_line(self, argv=None):
1523-
super(NotebookApp, self).parse_command_line(argv)
1523+
super().parse_command_line(argv)
15241524

15251525
if self.extra_args:
15261526
arg0 = self.extra_args[0]
@@ -2023,7 +2023,7 @@ def _init_asyncio_patch(self):
20232023
def initialize(self, argv=None):
20242024
self._init_asyncio_patch()
20252025

2026-
super(NotebookApp, self).initialize(argv)
2026+
super().initialize(argv)
20272027
self.init_logging()
20282028
if self._dispatching:
20292029
return
@@ -2189,7 +2189,7 @@ def start(self):
21892189
This method takes no arguments so all configuration and initialization
21902190
must be done prior to calling this method."""
21912191

2192-
super(NotebookApp, self).start()
2192+
super().start()
21932193

21942194
if not self.allow_root:
21952195
# check if we are running as root, and abort if it's not allowed

0 commit comments

Comments
 (0)