Skip to content

Commit e497b9c

Browse files
committed
Fix jupyter#6256 : migrate to python 3.7+
* Update classifiers * Update python_requires * Fix deprecated code (some from python 2.x): - `io.open` -> `open` - `IOError` -> `OSError` (in python 3 `IOError` is alias) - `socket.error` -> `OSError` - `u''` -> `''` - `str().format` -> f-strings (where it was quick automatically validated change) - `object` is not needed as base class - use `set` comprehensions - `sum` over generators (do not produce temporary lists) - use plain `super()` * remove unused imports
1 parent 8fd3ce9 commit e497b9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+709
-765
lines changed

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@
319319
# -- Options for link checks ----------------------------------------------
320320

321321
linkcheck_ignore = [
322-
'http://127\.0\.0\.1/*'
322+
r'http://127\.0\.0\.1/*'
323323
]
324324

325325

notebook/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
if __name__ == '__main__':
32
from notebook import notebookapp as app
43
app.launch_new_instance()

notebook/_sysinfo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def pkg_commit_hash(pkg_path):
5555
if repo_commit:
5656
return 'repository', repo_commit.strip().decode('ascii')
5757
else:
58-
return u'', u''
58+
return '', ''
5959
par_path = p.dirname(par_path)
60-
61-
return u'', u''
60+
61+
return '', ''
6262

6363

6464
def pkg_info(pkg_path):

notebook/auth/login.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ def hashed_password(self):
7373

7474
def passwd_check(self, a, b):
7575
return passwd_check(a, b)
76-
76+
7777
def post(self):
78-
typed_password = self.get_argument('password', default=u'')
79-
new_password = self.get_argument('new_password', default=u'')
78+
typed_password = self.get_argument('password', default='')
79+
new_password = self.get_argument('new_password', default='')
80+
8081

8182

82-
8383
if self.get_login_available(self.settings):
8484
if self.passwd_check(self.hashed_password, typed_password) and not new_password:
8585
self.set_login_cookie(self, uuid.uuid4().hex)
@@ -112,7 +112,7 @@ def set_login_cookie(cls, handler, user_id=None):
112112
handler.set_secure_cookie(handler.cookie_name, user_id, **cookie_options)
113113
return user_id
114114

115-
auth_header_pat = re.compile('token\s+(.+)', re.IGNORECASE)
115+
auth_header_pat = re.compile(r'token\s+(.+)', re.IGNORECASE)
116116

117117
@classmethod
118118
def get_token(cls, handler):
@@ -197,7 +197,7 @@ def get_user(cls, handler):
197197
@classmethod
198198
def get_user_token(cls, handler):
199199
"""Identify the user based on a token in the URL or Authorization header
200-
200+
201201
Returns:
202202
- uuid if authenticated
203203
- None if not
@@ -245,7 +245,7 @@ def password_from_settings(cls, settings):
245245
246246
If there is no configured password, an empty string will be returned.
247247
"""
248-
return settings.get('password', u'')
248+
return settings.get('password', '')
249249

250250
@classmethod
251251
def get_login_available(cls, settings):

notebook/auth/security.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from contextlib import contextmanager
66
import getpass
77
import hashlib
8-
import io
98
import json
109
import os
1110
import random
@@ -135,7 +134,7 @@ def passwd_check(hashed_passphrase, passphrase):
135134
def persist_config(config_file=None, mode=0o600):
136135
"""Context manager that can be used to modify a config object
137136
138-
On exit of the context manager, the config will be written back to disk,
137+
On exit of the context manager, the config will be written back to disk,
139138
by default with user-only (600) permissions.
140139
"""
141140

@@ -152,7 +151,7 @@ def persist_config(config_file=None, mode=0o600):
152151

153152
yield config
154153

155-
with io.open(config_file, 'w', encoding='utf8') as f:
154+
with open(config_file, 'w', encoding='utf8') as f:
156155
f.write(cast_unicode(json.dumps(config, indent=2)))
157156

158157
try:
@@ -165,7 +164,7 @@ def persist_config(config_file=None, mode=0o600):
165164

166165
def set_password(password=None, config_file=None):
167166
"""Ask user for password, store it in notebook json configuration file"""
168-
167+
169168
hashed_password = passwd(password)
170169

171170
with persist_config(config_file) as config:

notebook/auth/tests/test_security.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def test_bad():
1818

1919
def test_passwd_check_unicode():
2020
# GH issue #4524
21-
phash = u'sha1:23862bc21dd3:7a415a95ae4580582e314072143d9c382c491e4f'
22-
assert passwd_check(phash, u"łe¶ŧ←↓→")
23-
phash = (u'argon2:$argon2id$v=19$m=10240,t=10,p=8$'
24-
u'qjjDiZUofUVVnrVYxacnbA$l5pQq1bJ8zglGT2uXP6iOg')
25-
assert passwd_check(phash, u"łe¶ŧ←↓→")
21+
phash = 'sha1:23862bc21dd3:7a415a95ae4580582e314072143d9c382c491e4f'
22+
assert passwd_check(phash, "łe¶ŧ←↓→")
23+
phash = ('argon2:$argon2id$v=19$m=10240,t=10,p=8$'
24+
'qjjDiZUofUVVnrVYxacnbA$l5pQq1bJ8zglGT2uXP6iOg')
25+
assert passwd_check(phash, "łe¶ŧ←↓→")

0 commit comments

Comments
 (0)