Skip to content

Commit f764280

Browse files
committed
Run "ruff format", use 88 line length
1 parent 9d98ede commit f764280

26 files changed

+721
-180
lines changed

Diff for: pgcommitfest/auth.py

+26-8
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ def login(request):
7777
# Now encrypt it
7878
r = Random.new()
7979
iv = r.read(16)
80-
encryptor = AES.new(SHA.new(settings.SECRET_KEY.encode('ascii')).digest()[:16], AES.MODE_CBC, iv)
81-
cipher = encryptor.encrypt(s.encode('ascii') + b' ' * (16 - (len(s) % 16))) # pad to 16 bytes
80+
encryptor = AES.new(
81+
SHA.new(settings.SECRET_KEY.encode('ascii')).digest()[:16], AES.MODE_CBC, iv
82+
)
83+
cipher = encryptor.encrypt(
84+
s.encode('ascii') + b' ' * (16 - (len(s) % 16))
85+
) # pad to 16 bytes
8286

8387
return HttpResponseRedirect(
8488
"%s?d=%s$%s"
@@ -115,9 +119,15 @@ def auth_receive(request):
115119
# Set up an AES object and decrypt the data we received
116120
try:
117121
decryptor = AES.new(
118-
base64.b64decode(settings.PGAUTH_KEY), AES.MODE_CBC, base64.b64decode(str(request.GET['i']), "-_")
122+
base64.b64decode(settings.PGAUTH_KEY),
123+
AES.MODE_CBC,
124+
base64.b64decode(str(request.GET['i']), "-_"),
125+
)
126+
s = (
127+
decryptor.decrypt(base64.b64decode(str(request.GET['d']), "-_"))
128+
.rstrip(b' ')
129+
.decode('utf8')
119130
)
120-
s = decryptor.decrypt(base64.b64decode(str(request.GET['d']), "-_")).rstrip(b' ').decode('utf8')
121131
except UnicodeDecodeError:
122132
return HttpResponse("Badly encoded data found", 400)
123133
except Exception:
@@ -203,15 +213,19 @@ def auth_receive(request):
203213

204214
# Signal that we have information about this user
205215
auth_user_data_received.send(
206-
sender=auth_receive, user=user, userdata={'secondaryemails': data['se'][0].split(',') if 'se' in data else []}
216+
sender=auth_receive,
217+
user=user,
218+
userdata={'secondaryemails': data['se'][0].split(',') if 'se' in data else []},
207219
)
208220

209221
# Finally, check of we have a data package that tells us where to
210222
# redirect the user.
211223
if 'd' in data:
212224
(ivs, datas) = data['d'][0].split('$')
213225
decryptor = AES.new(
214-
SHA.new(settings.SECRET_KEY.encode('ascii')).digest()[:16], AES.MODE_CBC, base64.b64decode(ivs, b"-_")
226+
SHA.new(settings.SECRET_KEY.encode('ascii')).digest()[:16],
227+
AES.MODE_CBC,
228+
base64.b64decode(ivs, b"-_"),
215229
)
216230
s = decryptor.decrypt(base64.b64decode(datas, "-_")).rstrip(b' ').decode('utf8')
217231
try:
@@ -224,7 +238,9 @@ def auth_receive(request):
224238
# No redirect specified, see if we have it in our settings
225239
if hasattr(settings, 'PGAUTH_REDIRECT_SUCCESS'):
226240
return HttpResponseRedirect(settings.PGAUTH_REDIRECT_SUCCESS)
227-
return HttpResponse("Authentication successful, but don't know where to redirect!", status=500)
241+
return HttpResponse(
242+
"Authentication successful, but don't know where to redirect!", status=500
243+
)
228244

229245

230246
# Receive API calls from upstream, such as push changes to users
@@ -332,7 +348,9 @@ def user_search(searchterm=None, userid=None):
332348
(ivs, datas) = r.text.encode('utf8').split(b'&')
333349

334350
# Decryption time
335-
decryptor = AES.new(base64.b64decode(settings.PGAUTH_KEY), AES.MODE_CBC, base64.b64decode(ivs, "-_"))
351+
decryptor = AES.new(
352+
base64.b64decode(settings.PGAUTH_KEY), AES.MODE_CBC, base64.b64decode(ivs, "-_")
353+
)
336354
s = decryptor.decrypt(base64.b64decode(datas, "-_")).rstrip(b' ').decode('utf8')
337355
j = json.loads(s)
338356

Diff for: pgcommitfest/commitfest/ajax.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ def _archivesAPI(suburl, params=None):
2727
try:
2828
resp = requests.get(
2929
"http{0}://{1}:{2}{3}".format(
30-
settings.ARCHIVES_PORT == 443 and 's' or '', settings.ARCHIVES_SERVER, settings.ARCHIVES_PORT, suburl
30+
settings.ARCHIVES_PORT == 443 and 's' or '',
31+
settings.ARCHIVES_SERVER,
32+
settings.ARCHIVES_PORT,
33+
suburl,
3134
),
3235
params=params,
3336
headers={
@@ -76,7 +79,9 @@ def getMessages(request):
7679

7780

7881
def refresh_single_thread(thread):
79-
r = sorted(_archivesAPI('/message-id.json/%s' % thread.messageid), key=lambda x: x['date'])
82+
r = sorted(
83+
_archivesAPI('/message-id.json/%s' % thread.messageid), key=lambda x: x['date']
84+
)
8085
if thread.latestmsgid != r[-1]['msgid']:
8186
# There is now a newer mail in the thread!
8287
thread.latestmsgid = r[-1]['msgid']
@@ -117,7 +122,10 @@ def annotateMessage(request):
117122

118123
for p in thread.patches.all():
119124
PatchHistory(
120-
patch=p, by=request.user, what='Added annotation "%s" to %s' % (textwrap.shorten(msg, 100), msgid)
125+
patch=p,
126+
by=request.user,
127+
what='Added annotation "%s" to %s'
128+
% (textwrap.shorten(msg, 100), msgid),
121129
).save_and_notify()
122130
p.set_modified()
123131
p.save()
@@ -134,7 +142,8 @@ def deleteAnnotation(request):
134142
PatchHistory(
135143
patch=p,
136144
by=request.user,
137-
what='Deleted annotation "%s" from %s' % (annotation.annotationtext, annotation.msgid),
145+
what='Deleted annotation "%s" from %s'
146+
% (annotation.annotationtext, annotation.msgid),
138147
).save_and_notify()
139148
p.set_modified()
140149
p.save()
@@ -212,7 +221,9 @@ def doAttachThread(cf, patch, msgid, user):
212221
m.save()
213222
parse_and_add_attachments(r, m)
214223

215-
PatchHistory(patch=patch, by=user, what='Attached mail thread %s' % r[0]['msgid']).save_and_notify()
224+
PatchHistory(
225+
patch=patch, by=user, what='Attached mail thread %s' % r[0]['msgid']
226+
).save_and_notify()
216227
patch.update_lastmail()
217228
patch.set_modified()
218229
patch.save()
@@ -227,7 +238,11 @@ def detachThread(request):
227238
thread = get_object_or_404(MailThread, messageid=request.POST['msg'])
228239

229240
patch.mailthread_set.remove(thread)
230-
PatchHistory(patch=patch, by=request.user, what='Detached mail thread %s' % request.POST['msg']).save_and_notify()
241+
PatchHistory(
242+
patch=patch,
243+
by=request.user,
244+
what='Detached mail thread %s' % request.POST['msg'],
245+
).save_and_notify()
231246
patch.update_lastmail()
232247
patch.set_modified()
233248
patch.save()

Diff for: pgcommitfest/commitfest/feeds.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ def __init__(self, activity, cf, *args, **kwargs):
1010
self.activity = activity
1111
if cf:
1212
self.cfid = cf.id
13-
self.title = self.description = 'PostgreSQL Commitfest {0} Activity Log'.format(cf.name)
13+
self.title = self.description = (
14+
'PostgreSQL Commitfest {0} Activity Log'.format(cf.name)
15+
)
1416
else:
1517
self.cfid = None
1618

@@ -21,11 +23,17 @@ def item_title(self, item):
2123
return item['name']
2224

2325
def item_description(self, item):
24-
return "<div>Patch: {name}</div><div>User: {by}</div>\n<div>{what}</div>".format(**item)
26+
return (
27+
"<div>Patch: {name}</div><div>User: {by}</div>\n<div>{what}</div>".format(
28+
**item
29+
)
30+
)
2531

2632
def item_link(self, item):
2733
if self.cfid:
28-
return 'https://commitfest.postgresql.org/{0}/{1}/'.format(self.cfid, item['patchid'])
34+
return 'https://commitfest.postgresql.org/{0}/{1}/'.format(
35+
self.cfid, item['patchid']
36+
)
2937
else:
3038
return 'https://commitfest.postgresql.org/{cfid}/{patchid}/'.format(**item)
3139

Diff for: pgcommitfest/commitfest/forms.py

+43-11
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ def __init__(self, cf, *args, **kwargs):
2929
q = Q(patch_author__commitfests=cf) | Q(patch_reviewer__commitfests=cf)
3030
userchoices = [(-1, '* All'), (-2, '* None'), (-3, '* Yourself')] + [
3131
(u.id, '%s %s (%s)' % (u.first_name, u.last_name, u.username))
32-
for u in User.objects.filter(q).distinct().order_by('first_name', 'last_name')
32+
for u in User.objects.filter(q)
33+
.distinct()
34+
.order_by('first_name', 'last_name')
3335
]
3436
self.fields['targetversion'] = forms.ChoiceField(
35-
choices=[('-1', '* All'), ('-2', '* None')] + [(v.id, v.version) for v in TargetVersion.objects.all()],
37+
choices=[('-1', '* All'), ('-2', '* None')]
38+
+ [(v.id, v.version) for v in TargetVersion.objects.all()],
3639
required=False,
3740
label="Target version",
3841
)
@@ -88,12 +91,21 @@ def __init__(self, *args, **kwargs):
8891
if 'data' in kwargs and str(field) in kwargs['data']:
8992
vals.extend([x for x in kwargs['data'].getlist(field)])
9093
self.fields[field].widget.attrs['data-selecturl'] = url
91-
self.fields[field].queryset = self.fields[field].queryset.filter(pk__in=set(vals))
92-
self.fields[field].label_from_instance = lambda u: '{} ({})'.format(u.username, u.get_full_name())
94+
self.fields[field].queryset = self.fields[field].queryset.filter(
95+
pk__in=set(vals)
96+
)
97+
self.fields[field].label_from_instance = lambda u: '{} ({})'.format(
98+
u.username, u.get_full_name()
99+
)
93100

94101

95102
class NewPatchForm(forms.ModelForm):
96-
threadmsgid = forms.CharField(max_length=200, required=True, label='Specify thread msgid', widget=ThreadPickWidget)
103+
threadmsgid = forms.CharField(
104+
max_length=200,
105+
required=True,
106+
label='Specify thread msgid',
107+
widget=ThreadPickWidget,
108+
)
97109
# patchfile = forms.FileField(allow_empty_file=False, max_length=50000, label='or upload patch file', required=False, help_text='This may be supported sometime in the future, and would then autogenerate a mail to the hackers list. At such a time, the threadmsgid would no longer be required.')
98110

99111
class Meta:
@@ -115,10 +127,20 @@ def clean_threadmsgid(self):
115127

116128
def _fetch_thread_choices(patch):
117129
for mt in patch.mailthread_set.order_by('-latestmessage'):
118-
ti = sorted(_archivesAPI('/message-id.json/%s' % mt.messageid), key=lambda x: x['date'], reverse=True)
130+
ti = sorted(
131+
_archivesAPI('/message-id.json/%s' % mt.messageid),
132+
key=lambda x: x['date'],
133+
reverse=True,
134+
)
119135
yield [
120136
mt.subject,
121-
[('%s,%s' % (mt.messageid, t['msgid']), 'From %s at %s' % (t['from'], t['date'])) for t in ti],
137+
[
138+
(
139+
'%s,%s' % (mt.messageid, t['msgid']),
140+
'From %s at %s' % (t['from'], t['date']),
141+
)
142+
for t in ti
143+
],
122144
]
123145

124146

@@ -130,7 +152,10 @@ def _fetch_thread_choices(patch):
130152

131153
def reviewfield(label):
132154
return forms.MultipleChoiceField(
133-
choices=review_state_choices, label=label, widget=forms.CheckboxSelectMultiple, required=False
155+
choices=review_state_choices,
156+
label=label,
157+
widget=forms.CheckboxSelectMultiple,
158+
required=False,
134159
)
135160

136161

@@ -144,7 +169,9 @@ class CommentForm(forms.Form):
144169
review_doc = reviewfield('Documentation')
145170

146171
message = forms.CharField(required=True, widget=forms.Textarea)
147-
newstatus = forms.ChoiceField(choices=PatchOnCommitFest.OPEN_STATUS_CHOICES(), label='New status')
172+
newstatus = forms.ChoiceField(
173+
choices=PatchOnCommitFest.OPEN_STATUS_CHOICES(), label='New status'
174+
)
148175

149176
def __init__(self, patch, poc, is_review, *args, **kwargs):
150177
super(CommentForm, self).__init__(*args, **kwargs)
@@ -173,8 +200,13 @@ def clean(self):
173200
if self.is_review:
174201
for fn, f in self.fields.items():
175202
if fn.startswith('review_') and fn in self.cleaned_data:
176-
if '1' in self.cleaned_data[fn] and '0' not in self.cleaned_data[fn]:
177-
self.errors[fn] = (('Cannot pass a test without performing it!'),)
203+
if (
204+
'1' in self.cleaned_data[fn]
205+
and '0' not in self.cleaned_data[fn]
206+
):
207+
self.errors[fn] = (
208+
('Cannot pass a test without performing it!'),
209+
)
178210
return self.cleaned_data
179211

180212

Diff for: pgcommitfest/commitfest/lookups.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@ def userlookup(request):
1414

1515
users = User.objects.filter(
1616
Q(is_active=True),
17-
Q(username__icontains=query) | Q(first_name__icontains=query) | Q(last_name__icontains=query),
17+
Q(username__icontains=query)
18+
| Q(first_name__icontains=query)
19+
| Q(last_name__icontains=query),
1820
)
1921

2022
return HttpResponse(
2123
json.dumps(
2224
{
23-
'values': [{'id': u.id, 'value': '{} ({})'.format(u.username, u.get_full_name())} for u in users],
25+
'values': [
26+
{
27+
'id': u.id,
28+
'value': '{} ({})'.format(u.username, u.get_full_name()),
29+
}
30+
for u in users
31+
],
2432
}
2533
),
2634
content_type='application/json',

Diff for: pgcommitfest/commitfest/management/commands/send_notifications.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ def handle(self, *args, **options):
1616
# Django doesn't do proper group by in the ORM, so we have to
1717
# build our own.
1818
matches = {}
19-
for n in PendingNotification.objects.all().order_by('user', 'history__patch__id', 'history__id'):
19+
for n in PendingNotification.objects.all().order_by(
20+
'user', 'history__patch__id', 'history__id'
21+
):
2022
if n.user.id not in matches:
2123
matches[n.user.id] = {'user': n.user, 'patches': {}}
2224
if n.history.patch.id not in matches[n.user.id]['patches']:
23-
matches[n.user.id]['patches'][n.history.patch.id] = {'patch': n.history.patch, 'entries': []}
24-
matches[n.user.id]['patches'][n.history.patch.id]['entries'].append(n.history)
25+
matches[n.user.id]['patches'][n.history.patch.id] = {
26+
'patch': n.history.patch,
27+
'entries': [],
28+
}
29+
matches[n.user.id]['patches'][n.history.patch.id]['entries'].append(
30+
n.history
31+
)
2532
n.delete()
2633

2734
# Ok, now let's build emails from this

0 commit comments

Comments
 (0)