Skip to content

Commit 4930508

Browse files
committed
Run "ruff format"
1 parent b5ff725 commit 4930508

34 files changed

+778
-389
lines changed

pgcommitfest/auth.py

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def authenticate(self, username=None, password=None):
6666
# Two regular django views to interact with the login system
6767
####
6868

69+
6970
# Handle login requests by sending them off to the main site
7071
def login(request):
7172
if 'next' in request.GET:
@@ -79,11 +80,14 @@ def login(request):
7980
encryptor = AES.new(SHA.new(settings.SECRET_KEY.encode('ascii')).digest()[:16], AES.MODE_CBC, iv)
8081
cipher = encryptor.encrypt(s.encode('ascii') + b' ' * (16 - (len(s) % 16))) # pad to 16 bytes
8182

82-
return HttpResponseRedirect("%s?d=%s$%s" % (
83-
settings.PGAUTH_REDIRECT,
84-
base64.b64encode(iv, b"-_").decode('utf8'),
85-
base64.b64encode(cipher, b"-_").decode('utf8'),
86-
))
83+
return HttpResponseRedirect(
84+
"%s?d=%s$%s"
85+
% (
86+
settings.PGAUTH_REDIRECT,
87+
base64.b64encode(iv, b"-_").decode('utf8'),
88+
base64.b64encode(cipher, b"-_").decode('utf8'),
89+
)
90+
)
8791
else:
8892
return HttpResponseRedirect(settings.PGAUTH_REDIRECT)
8993

@@ -110,9 +114,9 @@ def auth_receive(request):
110114

111115
# Set up an AES object and decrypt the data we received
112116
try:
113-
decryptor = AES.new(base64.b64decode(settings.PGAUTH_KEY),
114-
AES.MODE_CBC,
115-
base64.b64decode(str(request.GET['i']), "-_"))
117+
decryptor = AES.new(
118+
base64.b64decode(settings.PGAUTH_KEY), AES.MODE_CBC, base64.b64decode(str(request.GET['i']), "-_")
119+
)
116120
s = decryptor.decrypt(base64.b64decode(str(request.GET['d']), "-_")).rstrip(b' ').decode('utf8')
117121
except UnicodeDecodeError:
118122
return HttpResponse("Badly encoded data found", 400)
@@ -126,7 +130,7 @@ def auth_receive(request):
126130
return HttpResponse("Invalid encrypted data received.", status=400)
127131

128132
# Check the timestamp in the authentication
129-
if (int(data['t'][0]) < time.time() - 10):
133+
if int(data['t'][0]) < time.time() - 10:
130134
return HttpResponse("Authentication token too old.", status=400)
131135

132136
# Update the user record (if any)
@@ -153,7 +157,8 @@ def auth_receive(request):
153157
# somehow fix that live, give a proper error message and
154158
# have somebody look at it manually.
155159
if User.objects.filter(email=data['e'][0]).exists():
156-
return HttpResponse("""A user with email %s already exists, but with
160+
return HttpResponse(
161+
"""A user with email %s already exists, but with
157162
a different username than %s.
158163
159164
This is almost certainly caused by some legacy data in our database.
@@ -162,7 +167,10 @@ def auth_receive(request):
162167
for you.
163168
164169
We apologize for the inconvenience.
165-
""" % (data['e'][0], data['u'][0]), content_type='text/plain')
170+
"""
171+
% (data['e'][0], data['u'][0]),
172+
content_type='text/plain',
173+
)
166174

167175
if getattr(settings, 'PGAUTH_CREATEUSER_CALLBACK', None):
168176
res = getattr(settings, 'PGAUTH_CREATEUSER_CALLBACK')(
@@ -176,12 +184,13 @@ def auth_receive(request):
176184
if res:
177185
return res
178186

179-
user = User(username=data['u'][0],
180-
first_name=data['f'][0],
181-
last_name=data['l'][0],
182-
email=data['e'][0],
183-
password='setbypluginnotasha1',
184-
)
187+
user = User(
188+
username=data['u'][0],
189+
first_name=data['f'][0],
190+
last_name=data['l'][0],
191+
email=data['e'][0],
192+
password='setbypluginnotasha1',
193+
)
185194
user.save()
186195

187196
auth_user_created_from_upstream.send(sender=auth_receive, user=user)
@@ -193,17 +202,17 @@ def auth_receive(request):
193202
django_login(request, user)
194203

195204
# Signal that we have information about this user
196-
auth_user_data_received.send(sender=auth_receive, user=user, userdata={
197-
'secondaryemails': data['se'][0].split(',') if 'se' in data else []
198-
})
205+
auth_user_data_received.send(
206+
sender=auth_receive, user=user, userdata={'secondaryemails': data['se'][0].split(',') if 'se' in data else []}
207+
)
199208

200209
# Finally, check of we have a data package that tells us where to
201210
# redirect the user.
202211
if 'd' in data:
203212
(ivs, datas) = data['d'][0].split('$')
204-
decryptor = AES.new(SHA.new(settings.SECRET_KEY.encode('ascii')).digest()[:16],
205-
AES.MODE_CBC,
206-
base64.b64decode(ivs, b"-_"))
213+
decryptor = AES.new(
214+
SHA.new(settings.SECRET_KEY.encode('ascii')).digest()[:16], AES.MODE_CBC, base64.b64decode(ivs, b"-_")
215+
)
207216
s = decryptor.decrypt(base64.b64decode(datas, "-_")).rstrip(b' ').decode('utf8')
208217
try:
209218
rdata = parse_qs(s, strict_parsing=True)
@@ -267,7 +276,8 @@ def _conditionally_update_record(rectype, recordkey, structkey, fieldmap, struct
267276
for u in pushstruct.get('users', []):
268277
user = _conditionally_update_record(
269278
User,
270-
'username', 'username',
279+
'username',
280+
'username',
271281
{
272282
'firstname': 'first_name',
273283
'lastname': 'last_name',
@@ -278,9 +288,20 @@ def _conditionally_update_record(rectype, recordkey, structkey, fieldmap, struct
278288

279289
# Signal that we have information about this user (only if it exists)
280290
if user:
281-
auth_user_data_received.send(sender=auth_api, user=user, userdata={
282-
k: u[k] for k in u.keys() if k not in ['firstname', 'lastname', 'email', ]
283-
})
291+
auth_user_data_received.send(
292+
sender=auth_api,
293+
user=user,
294+
userdata={
295+
k: u[k]
296+
for k in u.keys()
297+
if k
298+
not in [
299+
'firstname',
300+
'lastname',
301+
'email',
302+
]
303+
},
304+
)
284305

285306
return HttpResponse("OK", status=200)
286307

@@ -311,9 +332,7 @@ def user_search(searchterm=None, userid=None):
311332
(ivs, datas) = r.text.encode('utf8').split(b'&')
312333

313334
# Decryption time
314-
decryptor = AES.new(base64.b64decode(settings.PGAUTH_KEY),
315-
AES.MODE_CBC,
316-
base64.b64decode(ivs, "-_"))
335+
decryptor = AES.new(base64.b64decode(settings.PGAUTH_KEY), AES.MODE_CBC, base64.b64decode(ivs, "-_"))
317336
s = decryptor.decrypt(base64.b64decode(datas, "-_")).rstrip(b' ').decode('utf8')
318337
j = json.loads(s)
319338

@@ -324,9 +343,11 @@ def user_search(searchterm=None, userid=None):
324343
def subscribe_to_user_changes(userid):
325344
socket.setdefaulttimeout(10)
326345

327-
body = json.dumps({
328-
'u': userid,
329-
})
346+
body = json.dumps(
347+
{
348+
'u': userid,
349+
}
350+
)
330351

331352
h = hmac.digest(
332353
base64.b64decode(settings.PGAUTH_KEY),

pgcommitfest/commitfest/admin.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
from django.contrib import admin
22

3-
from .models import Committer, CommitFest, Patch, PatchHistory, PatchOnCommitFest, TargetVersion, Topic, MailThread, MailThreadAttachment
3+
from .models import (
4+
Committer,
5+
CommitFest,
6+
Patch,
7+
PatchHistory,
8+
PatchOnCommitFest,
9+
TargetVersion,
10+
Topic,
11+
MailThread,
12+
MailThreadAttachment,
13+
)
414

515

616
class CommitterAdmin(admin.ModelAdmin):
@@ -14,11 +24,16 @@ class PatchOnCommitFestInline(admin.TabularInline):
1424

1525
class PatchAdmin(admin.ModelAdmin):
1626
inlines = (PatchOnCommitFestInline,)
17-
list_display = ('name', )
27+
list_display = ('name',)
1828

1929

2030
class MailThreadAttachmentAdmin(admin.ModelAdmin):
21-
list_display = ('date', 'author', 'messageid', 'mailthread',)
31+
list_display = (
32+
'date',
33+
'author',
34+
'messageid',
35+
'mailthread',
36+
)
2237

2338

2439
admin.site.register(Committer, CommitterAdmin)

pgcommitfest/commitfest/ajax.py

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ class Http503(Exception):
2626
def _archivesAPI(suburl, params=None):
2727
try:
2828
resp = requests.get(
29-
"http{0}://{1}:{2}{3}".format(settings.ARCHIVES_PORT == 443 and 's' or '',
30-
settings.ARCHIVES_SERVER,
31-
settings.ARCHIVES_PORT,
32-
suburl),
29+
"http{0}://{1}:{2}{3}".format(
30+
settings.ARCHIVES_PORT == 443 and 's' or '', settings.ARCHIVES_SERVER, settings.ARCHIVES_PORT, suburl
31+
),
3332
params=params,
3433
headers={
3534
'Host': settings.ARCHIVES_HOST,
@@ -105,17 +104,21 @@ def annotateMessage(request):
105104
r = _archivesAPI('/message-id.json/%s' % thread.messageid)
106105
for m in r:
107106
if m['msgid'] == msgid:
108-
annotation = MailThreadAnnotation(mailthread=thread,
109-
user=request.user,
110-
msgid=msgid,
111-
annotationtext=msg,
112-
mailsubject=m['subj'],
113-
maildate=m['date'],
114-
mailauthor=m['from'])
107+
annotation = MailThreadAnnotation(
108+
mailthread=thread,
109+
user=request.user,
110+
msgid=msgid,
111+
annotationtext=msg,
112+
mailsubject=m['subj'],
113+
maildate=m['date'],
114+
mailauthor=m['from'],
115+
)
115116
annotation.save()
116117

117118
for p in thread.patches.all():
118-
PatchHistory(patch=p, by=request.user, what='Added annotation "%s" to %s' % (textwrap.shorten(msg, 100), msgid)).save_and_notify()
119+
PatchHistory(
120+
patch=p, by=request.user, what='Added annotation "%s" to %s' % (textwrap.shorten(msg, 100), msgid)
121+
).save_and_notify()
119122
p.set_modified()
120123
p.save()
121124

@@ -128,7 +131,11 @@ def deleteAnnotation(request):
128131
annotation = get_object_or_404(MailThreadAnnotation, pk=request.POST['id'])
129132

130133
for p in annotation.mailthread.patches.all():
131-
PatchHistory(patch=p, by=request.user, what='Deleted annotation "%s" from %s' % (annotation.annotationtext, annotation.msgid)).save_and_notify()
134+
PatchHistory(
135+
patch=p,
136+
by=request.user,
137+
what='Deleted annotation "%s" from %s' % (annotation.annotationtext, annotation.msgid),
138+
).save_and_notify()
132139
p.set_modified()
133140
p.save()
134141

@@ -143,14 +150,16 @@ def parse_and_add_attachments(threadinfo, mailthread):
143150
# One or more attachments. For now, we're only actually going
144151
# to store and process the first one, even though the API gets
145152
# us all of them.
146-
MailThreadAttachment.objects.get_or_create(mailthread=mailthread,
147-
messageid=t['msgid'],
148-
defaults={
149-
'date': t['date'],
150-
'author': t['from'],
151-
'attachmentid': t['atts'][0]['id'],
152-
'filename': t['atts'][0]['name'],
153-
})
153+
MailThreadAttachment.objects.get_or_create(
154+
mailthread=mailthread,
155+
messageid=t['msgid'],
156+
defaults={
157+
'date': t['date'],
158+
'author': t['from'],
159+
'attachmentid': t['atts'][0]['id'],
160+
'filename': t['atts'][0]['name'],
161+
},
162+
)
154163
# In theory we should remove objects if they don't have an
155164
# attachment, but how could that ever happen? Ignore for now.
156165

@@ -188,15 +197,16 @@ def doAttachThread(cf, patch, msgid, user):
188197
else:
189198
# No existing thread existed, so create it
190199
# Now create a new mailthread entry
191-
m = MailThread(messageid=r[0]['msgid'],
192-
subject=r[0]['subj'],
193-
firstmessage=r[0]['date'],
194-
firstauthor=r[0]['from'],
195-
latestmessage=r[-1]['date'],
196-
latestauthor=r[-1]['from'],
197-
latestsubject=r[-1]['subj'],
198-
latestmsgid=r[-1]['msgid'],
199-
)
200+
m = MailThread(
201+
messageid=r[0]['msgid'],
202+
subject=r[0]['subj'],
203+
firstmessage=r[0]['date'],
204+
firstauthor=r[0]['from'],
205+
latestmessage=r[-1]['date'],
206+
latestauthor=r[-1]['from'],
207+
latestsubject=r[-1]['subj'],
208+
latestmsgid=r[-1]['msgid'],
209+
)
200210
m.save()
201211
m.patches.add(patch)
202212
m.save()
@@ -248,12 +258,13 @@ def importUser(request):
248258

249259
if User.objects.filter(username=u['u']).exists():
250260
return "User already exists"
251-
User(username=u['u'],
252-
first_name=u['f'],
253-
last_name=u['l'],
254-
email=u['e'],
255-
password='setbypluginnotsha1',
256-
).save()
261+
User(
262+
username=u['u'],
263+
first_name=u['f'],
264+
last_name=u['l'],
265+
email=u['e'],
266+
password='setbypluginnotsha1',
267+
).save()
257268
return 'OK'
258269
else:
259270
raise Http404()

0 commit comments

Comments
 (0)