Skip to content

Commit eb3e1a4

Browse files
authored
Merge pull request #4991 from 00Kai0/fix-py2dep
remove py2 dependence
2 parents 5f53f35 + b5f5c95 commit eb3e1a4

File tree

14 files changed

+18
-74
lines changed

14 files changed

+18
-74
lines changed

notebook/auth/login.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
import re
77
import os
88

9-
try:
10-
from urllib.parse import urlparse # Py 3
11-
except ImportError:
12-
from urlparse import urlparse # Py 2
9+
from urllib.parse import urlparse
10+
1311
import uuid
1412

1513
from tornado.escape import url_escape

notebook/base/handlers.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,10 @@
1414
import traceback
1515
import types
1616
import warnings
17-
try:
18-
# py3
19-
from http.client import responses
20-
from http.cookies import Morsel
21-
except ImportError:
22-
from httplib import responses
23-
from Cookie import Morsel
24-
try:
25-
from urllib.parse import urlparse # Py 3
26-
except ImportError:
27-
from urlparse import urlparse # Py 2
17+
from http.client import responses
18+
from http.cookies import Morsel
2819

20+
from urllib.parse import urlparse
2921
from jinja2 import TemplateNotFound
3022
from tornado import web, gen, escape, httputil
3123
from tornado.log import app_log
@@ -35,7 +27,7 @@
3527

3628
from traitlets.config import Application
3729
from ipython_genutils.path import filefind
38-
from ipython_genutils.py3compat import string_types, PY3
30+
from ipython_genutils.py3compat import string_types
3931

4032
import notebook
4133
from notebook._tz import utcnow
@@ -479,10 +471,6 @@ def check_host(self):
479471
if host.startswith('[') and host.endswith(']'):
480472
host = host[1:-1]
481473

482-
if not PY3:
483-
# ip_address only accepts unicode on Python 2
484-
host = host.decode('utf8', 'replace')
485-
486474
try:
487475
addr = ipaddress.ip_address(host)
488476
except ValueError:

notebook/bundler/tests/test_bundler_api.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
new_notebook, new_markdown_cell, new_code_cell, new_output,
1313
)
1414

15-
try:
16-
from unittest.mock import patch
17-
except ImportError:
18-
from mock import patch # py3
15+
from unittest.mock import patch
16+
1917

2018
def bundle(handler, model):
2119
"""Bundler test stub. Echo the notebook path."""

notebook/bundler/tests/test_bundlerextension.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
import shutil
88
import unittest
99

10-
try:
11-
from unittest.mock import patch
12-
except ImportError:
13-
from mock import patch # py2
14-
10+
from unittest.mock import patch
1511
from ipython_genutils.tempdir import TemporaryDirectory
1612
from ipython_genutils import py3compat
1713

notebook/nbconvert/tests/test_nbconvert_handlers.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616

1717
from ipython_genutils.testing.decorators import onlyif_cmds_exist
1818

19-
try: #PY3
20-
from base64 import encodebytes
21-
except ImportError: #PY2
22-
from base64 import encodestring as encodebytes
23-
24-
19+
from base64 import encodebytes
2520

2621

2722
class NbconvertAPI(object):

notebook/services/config/handlers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import errno
99
from tornado import web
1010

11-
from ipython_genutils.py3compat import PY3
1211
from ...base.handlers import APIHandler
1312

1413
class ConfigHandler(APIHandler):

notebook/services/contents/fileio.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
from traitlets.config import Configurable
2525
from traitlets import Bool
2626

27-
try: #PY3
28-
from base64 import encodebytes, decodebytes
29-
except ImportError: #PY2
30-
from base64 import encodestring as encodebytes, decodestring as decodebytes
27+
from base64 import encodebytes, decodebytes
3128

3229

3330
def replace_file(src, dst):

notebook/services/contents/filemanager.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@
3434
from notebook.base.handlers import AuthenticatedFileHandler
3535
from notebook.transutils import _
3636

37-
try:
38-
from os.path import samefile
39-
except ImportError:
40-
# windows + py2
41-
from notebook.utils import samefile_simple as samefile
37+
from os.path import samefile
4238

4339
_script_exporter = None
4440

notebook/tests/launchnotebook.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313

1414
pjoin = os.path.join
1515

16-
try:
17-
from unittest.mock import patch
18-
except ImportError:
19-
from mock import patch #py2
16+
from unittest.mock import patch
2017

2118
import requests
2219
from tornado.ioloop import IOLoop

notebook/tests/test_nbextensions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
from traitlets.tests.utils import check_help_all_output
1515
from unittest import TestCase
1616

17-
try:
18-
from unittest.mock import patch
19-
except ImportError:
20-
from mock import patch # py2
17+
from unittest.mock import patch
2118

2219
import ipython_genutils.testing.decorators as dec
2320
from ipython_genutils import py3compat

0 commit comments

Comments
 (0)