diff --git a/notebook/config_manager.py b/notebook/config_manager.py index 584df8870..a15c2454b 100644 --- a/notebook/config_manager.py +++ b/notebook/config_manager.py @@ -11,7 +11,6 @@ import json import os import copy -from six import PY3 from traitlets.config import LoggingConfigurable from traitlets.traitlets import Unicode, Bool @@ -119,10 +118,7 @@ class BaseJSONConfigManager(LoggingConfigurable): # in order to avoid writing half-finished corrupted data to disk. json_content = json.dumps(data, indent=2) - if PY3: - f = io.open(filename, 'w', encoding='utf-8') - else: - f = open(filename, 'wb') + f = io.open(filename, 'w', encoding='utf-8') with f: f.write(json_content) diff --git a/notebook/jstest.py b/notebook/jstest.py index 0e531f64f..6849c9fd0 100644 --- a/notebook/jstest.py +++ b/notebook/jstest.py @@ -23,32 +23,16 @@ import time from io import BytesIO from threading import Thread, Lock, Event -try: - from unittest.mock import patch -except ImportError: - from mock import patch # py3 +from unittest.mock import patch from jupyter_core.paths import jupyter_runtime_dir from ipython_genutils.py3compat import bytes_to_str, which from notebook._sysinfo import get_sys_info from ipython_genutils.tempdir import TemporaryDirectory -try: - # Python >= 3.3 - from subprocess import TimeoutExpired - def popen_wait(p, timeout): - return p.wait(timeout) -except ImportError: - class TimeoutExpired(Exception): - pass - def popen_wait(p, timeout): - """backport of Popen.wait from Python 3""" - for i in range(int(10 * timeout)): - if p.poll() is not None: - return - time.sleep(0.1) - if p.poll() is None: - raise TimeoutExpired +from subprocess import TimeoutExpired +def popen_wait(p, timeout): + return p.wait(timeout) NOTEBOOK_SHUTDOWN_TIMEOUT = 10 diff --git a/notebook/nbextensions.py b/notebook/nbextensions.py index a6b5400e4..c6dad116b 100644 --- a/notebook/nbextensions.py +++ b/notebook/nbextensions.py @@ -13,13 +13,8 @@ import tarfile import zipfile from os.path import basename, join as pjoin, normpath -try: - from urllib.parse import urlparse # Py3 - from urllib.request import urlretrieve -except ImportError: - from urlparse import urlparse - from urllib import urlretrieve - +from urllib.parse import urlparse +from urllib.request import urlretrieve from jupyter_core.paths import ( jupyter_data_dir, jupyter_config_path, jupyter_path, SYSTEM_JUPYTER_PATH, ENV_JUPYTER_PATH, diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index faebd884e..6eba37308 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -32,10 +32,7 @@ import time import warnings import webbrowser -try: #PY3 - from base64 import encodebytes -except ImportError: #PY2 - from base64 import encodestring as encodebytes +from base64 import encodebytes from jinja2 import Environment, FileSystemLoader @@ -71,10 +68,7 @@ from notebook import ( ) # py23 compatibility -try: - raw_input = raw_input -except NameError: - raw_input = input +raw_input = input from .base.handlers import Template404, RedirectWithParams from .log import log_request diff --git a/notebook/utils.py b/notebook/utils.py index 5d9815476..69f3586f1 100644 --- a/notebook/utils.py +++ b/notebook/utils.py @@ -16,13 +16,8 @@ import sys from distutils.version import LooseVersion -try: - from urllib.parse import quote, unquote, urlparse, urljoin - from urllib.request import pathname2url -except ImportError: - from urllib import quote, unquote, pathname2url - from urlparse import urlparse, urljoin - +from urllib.parse import quote, unquote, urlparse, urljoin +from urllib.request import pathname2url # tornado.concurrent.Future is asyncio.Future # in tornado >=5 with Python 3 from tornado.concurrent import Future as TornadoFuture