11
11
import warnings
12
12
from contextlib import contextmanager
13
13
14
- from ipython_genutils .py3compat import cast_bytes
15
- from ipython_genutils .py3compat import cast_unicode
16
- from ipython_genutils .py3compat import str_to_bytes
17
14
from jupyter_core .paths import jupyter_config_dir
18
15
from traitlets .config import Config
19
16
from traitlets .config import ConfigFileNotFound
@@ -72,11 +69,11 @@ def passwd(passphrase=None, algorithm="argon2"):
72
69
)
73
70
h = ph .hash (passphrase )
74
71
75
- return ":" .join ((algorithm , cast_unicode ( h , "ascii" ) ))
72
+ return ":" .join ((algorithm , h ))
76
73
77
74
h = hashlib .new (algorithm )
78
75
salt = ("%0" + str (salt_len ) + "x" ) % random .getrandbits (4 * salt_len )
79
- h .update (cast_bytes ( passphrase , "utf-8" ) + str_to_bytes ( salt , "ascii" ))
76
+ h .update (passphrase . encode ( "utf-8" ) + salt . encode ( "ascii" ))
80
77
81
78
return ":" .join ((algorithm , salt , h .hexdigest ()))
82
79
@@ -133,7 +130,7 @@ def passwd_check(hashed_passphrase, passphrase):
133
130
if len (pw_digest ) == 0 :
134
131
return False
135
132
136
- h .update (cast_bytes ( passphrase , "utf-8" ) + cast_bytes ( salt , "ascii" ))
133
+ h .update (passphrase . encode ( "utf-8" ) + salt . encode ( "ascii" ))
137
134
138
135
return h .hexdigest () == pw_digest
139
136
@@ -160,7 +157,7 @@ def persist_config(config_file=None, mode=0o600):
160
157
yield config
161
158
162
159
with io .open (config_file , "w" , encoding = "utf8" ) as f :
163
- f .write (cast_unicode ( json .dumps (config , indent = 2 ) ))
160
+ f .write (json .dumps (config , indent = 2 ))
164
161
165
162
try :
166
163
os .chmod (config_file , mode )
0 commit comments