Skip to content

Commit c9ef500

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ebe0f8c commit c9ef500

File tree

2 files changed

+91
-78
lines changed

2 files changed

+91
-78
lines changed

jupyter_server/auth/identity.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -292,19 +292,28 @@ def user_to_cookie(self, user: User) -> str:
292292
Default is just the user's username.
293293
"""
294294
# default: username is enough
295-
cookie = json.dumps({
296-
'username': user.username,
297-
'name': user.name,
298-
'display_name': user.display_name,
299-
'initials': user.initials,
300-
'color': user.color
301-
})
295+
cookie = json.dumps(
296+
{
297+
"username": user.username,
298+
"name": user.name,
299+
"display_name": user.display_name,
300+
"initials": user.initials,
301+
"color": user.color,
302+
}
303+
)
302304
return cookie
303305

304306
def user_from_cookie(self, cookie_value: str) -> User | None:
305307
"""Inverse of user_to_cookie"""
306308
user = json.loads(cookie_value)
307-
return User(user['username'], user['name'], user['display_name'], user['initials'], None, user['color'])
309+
return User(
310+
user["username"],
311+
user["name"],
312+
user["display_name"],
313+
user["initials"],
314+
None,
315+
user["color"],
316+
)
308317

309318
def get_cookie_name(self, handler: JupyterHandler) -> str:
310319
"""Return the login cookie name
@@ -457,8 +466,8 @@ def generate_anonymous_user(self, handler: JupyterHandler) -> User:
457466
"""
458467
user_id = uuid.uuid4().hex
459468
moon = get_anonymous_username()
460-
name = display_name = "Anonymous {}".format(moon)
461-
initials = "A{}".format(moon[0])
469+
name = display_name = f"Anonymous {moon}"
470+
initials = f"A{moon[0]}"
462471
color = get_random_color()
463472
handler.log.info(f"Generating new user for token-authenticated request: {user_id}")
464473
return User(user_id, name, display_name, initials, None, color)

jupyter_server/auth/utils.py

+72-68
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# Copyright (c) Jupyter Development Team.
44
# Distributed under the terms of the Modified BSD License.
55
import importlib
6-
import re
76
import math
87
import random
8+
import re
99
import warnings
1010

1111

@@ -77,107 +77,111 @@ def match_url_to_resource(url, regex_mapping=None):
7777
if pattern.fullmatch(url):
7878
return auth_resource
7979

80+
8081
# From https://en.wikipedia.org/wiki/Moons_of_Jupiter
8182
moons_of_jupyter = [
82-
'Metis',
83-
'Adrastea',
84-
'Amalthea',
85-
'Thebe',
86-
'Io',
87-
'Europa',
88-
'Ganymede',
89-
'Callisto',
90-
'Themisto',
91-
'Leda',
92-
'Ersa',
93-
'Pandia',
94-
'Himalia',
95-
'Lysithea',
96-
'Elara',
97-
'Dia',
98-
'Carpo',
99-
'Valetudo',
100-
'Euporie',
101-
'Eupheme',
83+
"Metis",
84+
"Adrastea",
85+
"Amalthea",
86+
"Thebe",
87+
"Io",
88+
"Europa",
89+
"Ganymede",
90+
"Callisto",
91+
"Themisto",
92+
"Leda",
93+
"Ersa",
94+
"Pandia",
95+
"Himalia",
96+
"Lysithea",
97+
"Elara",
98+
"Dia",
99+
"Carpo",
100+
"Valetudo",
101+
"Euporie",
102+
"Eupheme",
102103
# 'S/2003 J 18',
103104
# 'S/2010 J 2',
104-
'Helike',
105+
"Helike",
105106
# 'S/2003 J 16',
106107
# 'S/2003 J 2',
107-
'Euanthe',
108+
"Euanthe",
108109
# 'S/2017 J 7',
109-
'Hermippe',
110-
'Praxidike',
111-
'Thyone',
112-
'Thelxinoe',
110+
"Hermippe",
111+
"Praxidike",
112+
"Thyone",
113+
"Thelxinoe",
113114
# 'S/2017 J 3',
114-
'Ananke',
115-
'Mneme',
115+
"Ananke",
116+
"Mneme",
116117
# 'S/2016 J 1',
117-
'Orthosie',
118-
'Harpalyke',
119-
'Iocaste',
118+
"Orthosie",
119+
"Harpalyke",
120+
"Iocaste",
120121
# 'S/2017 J 9',
121122
# 'S/2003 J 12',
122123
# 'S/2003 J 4',
123-
'Erinome',
124-
'Aitne',
125-
'Herse',
126-
'Taygete',
124+
"Erinome",
125+
"Aitne",
126+
"Herse",
127+
"Taygete",
127128
# 'S/2017 J 2',
128129
# 'S/2017 J 6',
129-
'Eukelade',
130-
'Carme',
130+
"Eukelade",
131+
"Carme",
131132
# 'S/2003 J 19',
132-
'Isonoe',
133+
"Isonoe",
133134
# 'S/2003 J 10',
134-
'Autonoe',
135-
'Philophrosyne',
136-
'Cyllene',
137-
'Pasithee',
135+
"Autonoe",
136+
"Philophrosyne",
137+
"Cyllene",
138+
"Pasithee",
138139
# 'S/2010 J 1',
139-
'Pasiphae',
140-
'Sponde',
140+
"Pasiphae",
141+
"Sponde",
141142
# 'S/2017 J 8',
142-
'Eurydome',
143+
"Eurydome",
143144
# 'S/2017 J 5',
144-
'Kalyke',
145-
'Hegemone',
146-
'Kale',
147-
'Kallichore',
145+
"Kalyke",
146+
"Hegemone",
147+
"Kale",
148+
"Kallichore",
148149
# 'S/2011 J 1',
149150
# 'S/2017 J 1',
150-
'Chaldene',
151-
'Arche',
152-
'Eirene',
153-
'Kore',
151+
"Chaldene",
152+
"Arche",
153+
"Eirene",
154+
"Kore",
154155
# 'S/2011 J 2',
155156
# 'S/2003 J 9',
156-
'Megaclite',
157-
'Aoede',
157+
"Megaclite",
158+
"Aoede",
158159
# 'S/2003 J 23',
159-
'Callirrhoe',
160-
'Sinope'
160+
"Callirrhoe",
161+
"Sinope",
161162
]
162163

164+
163165
def get_anonymous_username() -> str:
164166
"""
165167
Get a random user-name based on the moons of Jupyter.
166168
This function returns names like "Anonymous Io" or "Anonymous Metis".
167169
"""
168-
return moons_of_jupyter[random.randint(0, len(moons_of_jupyter)-1)]
170+
return moons_of_jupyter[random.randint(0, len(moons_of_jupyter) - 1)]
171+
169172

170173
# Using JupyterLab CSS variable because the colors may change with the theme
171174
user_colors = [
172-
'var(--jp-collaborator-color1)',
173-
'var(--jp-collaborator-color2)',
174-
'var(--jp-collaborator-color3)',
175-
'var(--jp-collaborator-color4)',
176-
'var(--jp-collaborator-color5)',
177-
'var(--jp-collaborator-color6)',
178-
'var(--jp-collaborator-color7)'
175+
"var(--jp-collaborator-color1)",
176+
"var(--jp-collaborator-color2)",
177+
"var(--jp-collaborator-color3)",
178+
"var(--jp-collaborator-color4)",
179+
"var(--jp-collaborator-color5)",
180+
"var(--jp-collaborator-color6)",
181+
"var(--jp-collaborator-color7)",
179182
]
180183

184+
181185
def get_random_color() -> str:
182-
""" Get a random color from the list of colors. """
183-
return user_colors[random.randint(0, len(user_colors)-1)];
186+
"""Get a random color from the list of colors."""
187+
return user_colors[random.randint(0, len(user_colors) - 1)]

0 commit comments

Comments
 (0)