Skip to content

Commit

Permalink
Merge pull request #5806 from rahulporuri/cln/update-super-usage
Browse files Browse the repository at this point in the history
Update super usage
  • Loading branch information
kevin-bates committed Oct 13, 2020
2 parents 158cc00 + 84df529 commit 18e4834
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 60 deletions.
31 changes: 15 additions & 16 deletions notebook/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def allow_credentials(self):

def set_default_headers(self):
"""Add CORS headers, if defined"""
super(IPythonHandler, self).set_default_headers()
super().set_default_headers()
if self.allow_origin:
self.set_header("Access-Control-Allow-Origin", self.allow_origin)
elif self.allow_origin_pat:
Expand Down Expand Up @@ -442,7 +442,7 @@ def check_xsrf_cookie(self):
# Servers without authentication are vulnerable to XSRF
return
try:
return super(IPythonHandler, self).check_xsrf_cookie()
return super().check_xsrf_cookie()
except web.HTTPError as e:
if self.request.method in {'GET', 'HEAD'}:
# Consider Referer a sufficient cross-origin check for GET requests
Expand Down Expand Up @@ -496,7 +496,7 @@ def check_host(self):
def prepare(self):
if not self.check_host():
raise web.HTTPError(403)
return super(IPythonHandler, self).prepare()
return super().prepare()

#---------------------------------------------------------------
# template rendering
Expand Down Expand Up @@ -591,7 +591,7 @@ class APIHandler(IPythonHandler):
def prepare(self):
if not self.check_origin():
raise web.HTTPError(404)
return super(APIHandler, self).prepare()
return super().prepare()

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

def get_login_url(self):
Expand All @@ -627,12 +627,12 @@ def get_login_url(self):
# instead of redirecting, raise 403 instead.
if not self.current_user:
raise web.HTTPError(403)
return super(APIHandler, self).get_login_url()
return super().get_login_url()

@property
def content_security_policy(self):
csp = '; '.join([
super(APIHandler, self).content_security_policy,
super().content_security_policy,
"default-src 'none'",
])
return csp
Expand All @@ -653,7 +653,7 @@ def update_api_activity(self):
def finish(self, *args, **kwargs):
self.update_api_activity()
self.set_header('Content-Type', 'application/json')
return super(APIHandler, self).finish(*args, **kwargs)
return super().finish(*args, **kwargs)

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

@web.authenticated
def head(self, path):
self.check_xsrf_cookie()
return super(AuthenticatedFileHandler, self).head(path)
return super().head(path)

@web.authenticated
def get(self, path):
Expand All @@ -731,10 +730,10 @@ def get_content_type(self):
if cur_mime == 'text/plain':
return 'text/plain; charset=UTF-8'
else:
return super(AuthenticatedFileHandler, self).get_content_type()
return super().get_content_type()

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

def set_headers(self):
super(FileFindHandler, self).set_headers()
super().set_headers()
# disable browser caching, rely on 304 replies for savings
if "v" not in self.request.arguments or \
any(self.request.path.startswith(path) for path in self.no_cache_paths):
Expand Down Expand Up @@ -842,7 +841,7 @@ def validate_absolute_path(self, root, absolute_path):
if (absolute_path + os.sep).startswith(root):
break

return super(FileFindHandler, self).validate_absolute_path(root, absolute_path)
return super().validate_absolute_path(root, absolute_path)


class APIVersionHandler(APIHandler):
Expand Down
2 changes: 1 addition & 1 deletion notebook/base/zmqhandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def get(self, *args, **kwargs):
# assign and yield in two step to avoid tornado 3 issues
res = self.pre_get()
yield maybe_future(res)
res = super(AuthenticatedZMQStreamHandler, self).get(*args, **kwargs)
res = super().get(*args, **kwargs)
yield maybe_future(res)

def initialize(self):
Expand Down
2 changes: 1 addition & 1 deletion notebook/bundler/bundlerextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class BundlerExtensionApp(BaseExtensionApp):

def start(self):
"""Perform the App's functions as configured"""
super(BundlerExtensionApp, self).start()
super().start()

# The above should have called a subcommand and raised NoStart; if we
# get here, it didn't, so we should self.log.info a message.
Expand Down
3 changes: 1 addition & 2 deletions notebook/files/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class FilesHandler(IPythonHandler):
def content_security_policy(self):
# In case we're serving HTML/SVG, confine any Javascript to a unique
# origin so it can't interact with the notebook server.
return super(FilesHandler, self).content_security_policy + \
"; sandbox allow-scripts"
return super().content_security_policy + "; sandbox allow-scripts"

@web.authenticated
def head(self, path):
Expand Down
8 changes: 4 additions & 4 deletions notebook/gateway/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def initialize(self):
def get(self, kernel_id, *args, **kwargs):
self.authenticate()
self.kernel_id = cast_unicode(kernel_id, 'ascii')
yield super(WebSocketChannelsHandler, self).get(kernel_id=kernel_id, *args, **kwargs)
yield super().get(kernel_id=kernel_id, *args, **kwargs)

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

def on_close(self):
self.log.debug("Closing websocket connection %s", self.request.path)
self.gateway.on_close()
super(WebSocketChannelsHandler, self).on_close()
super().on_close()

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

def __init__(self, **kwargs):
super(GatewayWebSocketClient, self).__init__(**kwargs)
super().__init__(**kwargs)
self.kernel_id = None
self.ws = None
self.ws_future = Future()
Expand Down
6 changes: 3 additions & 3 deletions notebook/gateway/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def validate_cert_default(self):
return bool(os.environ.get(self.validate_cert_env, str(self.validate_cert_default_value)) not in ['no', 'false'])

def __init__(self, **kwargs):
super(GatewayClient, self).__init__(**kwargs)
super().__init__(**kwargs)
self._static_args = {} # initialized on first use

env_whitelist_default_value = ''
Expand Down Expand Up @@ -310,7 +310,7 @@ class GatewayKernelManager(MappingKernelManager):
_kernels = {}

def __init__(self, **kwargs):
super(GatewayKernelManager, self).__init__(**kwargs)
super().__init__(**kwargs)
self.base_endpoint = url_path_join(GatewayClient.instance().url, GatewayClient.instance().kernels_endpoint)

def __contains__(self, kernel_id):
Expand Down Expand Up @@ -507,7 +507,7 @@ def shutdown_all(self, now=False):
class GatewayKernelSpecManager(KernelSpecManager):

def __init__(self, **kwargs):
super(GatewayKernelSpecManager, self).__init__(**kwargs)
super().__init__(**kwargs)
base_endpoint = url_path_join(GatewayClient.instance().url,
GatewayClient.instance().kernelspecs_endpoint)

Expand Down
8 changes: 4 additions & 4 deletions notebook/jstest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class StreamCapturer(Thread):
daemon = True # Don't hang if main thread crashes
started = False
def __init__(self, echo=False):
super(StreamCapturer, self).__init__()
super().__init__()
self.echo = echo
self.streams = []
self.buffer = BytesIO()
Expand Down Expand Up @@ -261,14 +261,14 @@ def launch(self, buffer_output):
# If the engine is SlimerJS, we need to buffer the output because
# SlimerJS does not support exit codes, so CasperJS always returns 0.
if self.engine == 'slimerjs' and not buffer_output:
return super(JSController, self).launch(capture_output=True)
return super().launch(capture_output=True)

else:
return super(JSController, self).launch(buffer_output=buffer_output)
return super().launch(buffer_output=buffer_output)

def wait(self, *pargs, **kwargs):
"""Wait for the JSController to finish"""
ret = super(JSController, self).wait(*pargs, **kwargs)
ret = super().wait(*pargs, **kwargs)
# If this is a SlimerJS controller, check the captured stdout for
# errors. Otherwise, just return the return code.
if self.engine == 'slimerjs':
Expand Down
6 changes: 2 additions & 4 deletions notebook/nbconvert/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ class NbconvertFileHandler(IPythonHandler):
def content_security_policy(self):
# In case we're serving HTML/SVG, confine any Javascript to a unique
# origin so it can't interact with the notebook server.
return super(NbconvertFileHandler, self).content_security_policy + \
"; sandbox allow-scripts"
return super().content_security_policy + "; sandbox allow-scripts"

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

@web.authenticated
def post(self, format):
Expand Down
2 changes: 1 addition & 1 deletion notebook/nbextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ class NBExtensionApp(BaseExtensionApp):

def start(self):
"""Perform the App's functions as configured"""
super(NBExtensionApp, self).start()
super().start()

# The above should have called a subcommand and raised NoStart; if we
# get here, it didn't, so we should self.log.info a message.
Expand Down
10 changes: 5 additions & 5 deletions notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def __init__(self, jupyter_app, kernel_manager, contents_manager,
if settings['autoreload']:
log.info('Autoreload enabled: the webapp will restart when any Python src file changes.')

super(NotebookWebApplication, self).__init__(handlers, **settings)
super().__init__(handlers, **settings)

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

def parse_command_line(self, argv=None):
super(NbserverStopApp, self).parse_command_line(argv)
super().parse_command_line(argv)
if self.extra_args:
try:
self.port = int(self.extra_args[0])
Expand Down Expand Up @@ -1520,7 +1520,7 @@ def _update_server_extensions(self, change):
terminals_available = False

def parse_command_line(self, argv=None):
super(NotebookApp, self).parse_command_line(argv)
super().parse_command_line(argv)

if self.extra_args:
arg0 = self.extra_args[0]
Expand Down Expand Up @@ -2023,7 +2023,7 @@ def _init_asyncio_patch(self):
def initialize(self, argv=None):
self._init_asyncio_patch()

super(NotebookApp, self).initialize(argv)
super().initialize(argv)
self.init_logging()
if self._dispatching:
return
Expand Down Expand Up @@ -2189,7 +2189,7 @@ def start(self):
This method takes no arguments so all configuration and initialization
must be done prior to calling this method."""

super(NotebookApp, self).start()
super().start()

if not self.allow_root:
# check if we are running as root, and abort if it's not allowed
Expand Down
2 changes: 1 addition & 1 deletion notebook/serverextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class ServerExtensionApp(BaseExtensionApp):

def start(self):
"""Perform the App's actions as configured"""
super(ServerExtensionApp, self).start()
super().start()

# The above should have called a subcommand and raised NoStart; if we
# get here, it didn't, so we should self.log.info a message.
Expand Down
4 changes: 2 additions & 2 deletions notebook/services/contents/largefilemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def save(self, model, path=''):
if chunk == 1:
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)
super(LargeFileManager, self)._save_file(os_path, model['content'], model.get('format'))
super()._save_file(os_path, model['content'], model.get('format'))
else:
self._save_large_file(os_path, model['content'], model.get('format'))
except web.HTTPError:
Expand All @@ -43,7 +43,7 @@ def save(self, model, path=''):
self.run_post_save_hook(model=model, os_path=os_path)
return model
else:
return super(LargeFileManager, self).save(model, path)
return super().save(model, path)

def _save_large_file(self, os_path, content, format):
"""Save content of a generic file."""
Expand Down
12 changes: 6 additions & 6 deletions notebook/services/kernels/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _finish_kernel_info(self, info):
self._kernel_info_future.set_result(info)

def initialize(self):
super(ZMQChannelsHandler, self).initialize()
super().initialize()
self.zmq_stream = None
self.channels = {}
self.kernel_id = None
Expand All @@ -212,7 +212,7 @@ def initialize(self):
@gen.coroutine
def pre_get(self):
# authenticate first
super(ZMQChannelsHandler, self).pre_get()
super().pre_get()
# check session collision:
yield self._register_session()
# then request kernel info, waiting up to a certain time before giving up.
Expand All @@ -236,7 +236,7 @@ def give_up():
@gen.coroutine
def get(self, kernel_id):
self.kernel_id = cast_unicode(kernel_id, 'ascii')
yield super(ZMQChannelsHandler, self).get(kernel_id=kernel_id)
yield super().get(kernel_id=kernel_id)

@gen.coroutine
def _register_session(self):
Expand All @@ -254,7 +254,7 @@ def _register_session(self):
self._open_sessions[self.session_key] = self

def open(self, kernel_id):
super(ZMQChannelsHandler, self).open()
super().open()
km = self.kernel_manager
km.notify_connect(kernel_id)

Expand Down Expand Up @@ -419,10 +419,10 @@ def write_stderr(error_message):
self._iopub_window_byte_count -= byte_count
self._iopub_window_byte_queue.pop(-1)
return
super(ZMQChannelsHandler, self)._on_zmq_reply(stream, msg)
super()._on_zmq_reply(stream, msg)

def close(self):
super(ZMQChannelsHandler, self).close()
super().close()
return self._close_future

def on_close(self):
Expand Down

0 comments on commit 18e4834

Please sign in to comment.