Skip to content

Commit

Permalink
Fix jupyter#6256 : migrate to python 3.7+
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
penguinolog committed Dec 25, 2021
1 parent 8fd3ce9 commit e497b9c
Show file tree
Hide file tree
Showing 72 changed files with 709 additions and 765 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
# -- Options for link checks ----------------------------------------------

linkcheck_ignore = [
'http://127\.0\.0\.1/*'
r'http://127\.0\.0\.1/*'
]


Expand Down
1 change: 0 additions & 1 deletion notebook/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

if __name__ == '__main__':
from notebook import notebookapp as app
app.launch_new_instance()
6 changes: 3 additions & 3 deletions notebook/_sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def pkg_commit_hash(pkg_path):
if repo_commit:
return 'repository', repo_commit.strip().decode('ascii')
else:
return u'', u''
return '', ''
par_path = p.dirname(par_path)
return u'', u''

return '', ''


def pkg_info(pkg_path):
Expand Down
14 changes: 7 additions & 7 deletions notebook/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def hashed_password(self):

def passwd_check(self, a, b):
return passwd_check(a, b)

def post(self):
typed_password = self.get_argument('password', default=u'')
new_password = self.get_argument('new_password', default=u'')
typed_password = self.get_argument('password', default='')
new_password = self.get_argument('new_password', default='')




if self.get_login_available(self.settings):
if self.passwd_check(self.hashed_password, typed_password) and not new_password:
self.set_login_cookie(self, uuid.uuid4().hex)
Expand Down Expand Up @@ -112,7 +112,7 @@ def set_login_cookie(cls, handler, user_id=None):
handler.set_secure_cookie(handler.cookie_name, user_id, **cookie_options)
return user_id

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

@classmethod
def get_token(cls, handler):
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_user(cls, handler):
@classmethod
def get_user_token(cls, handler):
"""Identify the user based on a token in the URL or Authorization header
Returns:
- uuid if authenticated
- None if not
Expand Down Expand Up @@ -245,7 +245,7 @@ def password_from_settings(cls, settings):
If there is no configured password, an empty string will be returned.
"""
return settings.get('password', u'')
return settings.get('password', '')

@classmethod
def get_login_available(cls, settings):
Expand Down
7 changes: 3 additions & 4 deletions notebook/auth/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from contextlib import contextmanager
import getpass
import hashlib
import io
import json
import os
import random
Expand Down Expand Up @@ -135,7 +134,7 @@ def passwd_check(hashed_passphrase, passphrase):
def persist_config(config_file=None, mode=0o600):
"""Context manager that can be used to modify a config object
On exit of the context manager, the config will be written back to disk,
On exit of the context manager, the config will be written back to disk,
by default with user-only (600) permissions.
"""

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

yield config

with io.open(config_file, 'w', encoding='utf8') as f:
with open(config_file, 'w', encoding='utf8') as f:
f.write(cast_unicode(json.dumps(config, indent=2)))

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

def set_password(password=None, config_file=None):
"""Ask user for password, store it in notebook json configuration file"""

hashed_password = passwd(password)

with persist_config(config_file) as config:
Expand Down
10 changes: 5 additions & 5 deletions notebook/auth/tests/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def test_bad():

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

0 comments on commit e497b9c

Please sign in to comment.