rm dependences of py2 in base path.

This commit is contained in:
Kerwin.Sun 2019-10-02 20:43:00 +08:00
parent 4a9cfa7518
commit ebfe75b6df
5 changed files with 11 additions and 47 deletions

View File

@ -11,7 +11,6 @@ import json
import os import os
import copy import copy
from six import PY3
from traitlets.config import LoggingConfigurable from traitlets.config import LoggingConfigurable
from traitlets.traitlets import Unicode, Bool from traitlets.traitlets import Unicode, Bool
@ -119,10 +118,7 @@ class BaseJSONConfigManager(LoggingConfigurable):
# in order to avoid writing half-finished corrupted data to disk. # in order to avoid writing half-finished corrupted data to disk.
json_content = json.dumps(data, indent=2) json_content = json.dumps(data, indent=2)
if PY3: f = io.open(filename, 'w', encoding='utf-8')
f = io.open(filename, 'w', encoding='utf-8')
else:
f = open(filename, 'wb')
with f: with f:
f.write(json_content) f.write(json_content)

View File

@ -23,32 +23,16 @@ import time
from io import BytesIO from io import BytesIO
from threading import Thread, Lock, Event from threading import Thread, Lock, Event
try: from unittest.mock import patch
from unittest.mock import patch
except ImportError:
from mock import patch # py3
from jupyter_core.paths import jupyter_runtime_dir from jupyter_core.paths import jupyter_runtime_dir
from ipython_genutils.py3compat import bytes_to_str, which from ipython_genutils.py3compat import bytes_to_str, which
from notebook._sysinfo import get_sys_info from notebook._sysinfo import get_sys_info
from ipython_genutils.tempdir import TemporaryDirectory from ipython_genutils.tempdir import TemporaryDirectory
try: from subprocess import TimeoutExpired
# Python >= 3.3 def popen_wait(p, timeout):
from subprocess import TimeoutExpired return p.wait(timeout)
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
NOTEBOOK_SHUTDOWN_TIMEOUT = 10 NOTEBOOK_SHUTDOWN_TIMEOUT = 10

View File

@ -13,13 +13,8 @@ import tarfile
import zipfile import zipfile
from os.path import basename, join as pjoin, normpath from os.path import basename, join as pjoin, normpath
try: from urllib.parse import urlparse
from urllib.parse import urlparse # Py3 from urllib.request import urlretrieve
from urllib.request import urlretrieve
except ImportError:
from urlparse import urlparse
from urllib import urlretrieve
from jupyter_core.paths import ( from jupyter_core.paths import (
jupyter_data_dir, jupyter_config_path, jupyter_path, jupyter_data_dir, jupyter_config_path, jupyter_path,
SYSTEM_JUPYTER_PATH, ENV_JUPYTER_PATH, SYSTEM_JUPYTER_PATH, ENV_JUPYTER_PATH,

View File

@ -32,10 +32,7 @@ import time
import warnings import warnings
import webbrowser import webbrowser
try: #PY3 from base64 import encodebytes
from base64 import encodebytes
except ImportError: #PY2
from base64 import encodestring as encodebytes
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
@ -71,10 +68,7 @@ from notebook import (
) )
# py23 compatibility # py23 compatibility
try: raw_input = input
raw_input = raw_input
except NameError:
raw_input = input
from .base.handlers import Template404, RedirectWithParams from .base.handlers import Template404, RedirectWithParams
from .log import log_request from .log import log_request

View File

@ -16,13 +16,8 @@ import sys
from distutils.version import LooseVersion from distutils.version import LooseVersion
try: from urllib.parse import quote, unquote, urlparse, urljoin
from urllib.parse import quote, unquote, urlparse, urljoin from urllib.request import pathname2url
from urllib.request import pathname2url
except ImportError:
from urllib import quote, unquote, pathname2url
from urlparse import urlparse, urljoin
# tornado.concurrent.Future is asyncio.Future # tornado.concurrent.Future is asyncio.Future
# in tornado >=5 with Python 3 # in tornado >=5 with Python 3
from tornado.concurrent import Future as TornadoFuture from tornado.concurrent import Future as TornadoFuture