Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit 0fdfc6c

Browse files
committed
Various Django and Python 2->3 updates.
1 parent 55e1155 commit 0fdfc6c

File tree

10 files changed

+43
-48
lines changed

10 files changed

+43
-48
lines changed

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ python manage.py test os2webscanner
157157
The test should pass. Now do:
158158

159159
```
160-
python manage.py syncdb
160+
python manage.py migrate
161161
```
162162

163163
and create a user with a password you can remember.

django-os2webscanner/os2webscanner/admin.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ class ProfileInline(admin.TabularInline):
4444
can_delete = False
4545

4646
def formfield_for_foreignkey(self, db_field, request, **kwargs):
47-
field = super(
48-
ProfileInline, self
49-
).formfield_for_foreignkey(db_field, request, **kwargs)
47+
field = super().formfield_for_foreignkey(db_field, request, **kwargs)
5048

5149
if db_field.name == 'organization':
5250
if not request.user.is_superuser:
@@ -77,12 +75,12 @@ def get_form(self, request, obj=None, **kwargs):
7775
)
7876

7977
self.exclude = ['is_superuser', 'permissions', 'groups']
80-
return super(MyUserAdmin, self).get_form(request, obj, **kwargs)
78+
return super().get_form(request, obj, **kwargs)
8179

8280
def get_queryset(self, request):
8381
"""Only allow users belonging to same organization to be edited."""
8482

85-
qs = super(MyUserAdmin, self).get_queryset(request)
83+
qs = super().get_queryset(request)
8684

8785
if request.user.is_superuser:
8886
return qs

django-os2webscanner/os2webscanner/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def save(self, *args, **kwargs):
835835
):
836836
self.end_time = datetime.datetime.now()
837837
# Actual save
838-
super(Scan, self).save(*args, **kwargs)
838+
super().save(*args, **kwargs)
839839
# Post-save stuff
840840

841841
if (
@@ -940,7 +940,7 @@ def __init__(self, *args, **kwargs):
940940
941941
Stores the old status of the scan for later use.
942942
"""
943-
super(Scan, self).__init__(*args, **kwargs)
943+
super().__init__(*args, **kwargs)
944944
self._old_status = self.status
945945

946946
def get_absolute_url(self):

django-os2webscanner/os2webscanner/views.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def dispatch(self, *args, **kwargs):
6262
except UserProfile.DoesNotExist:
6363
# User is *not* "upload only", all is good
6464
pass
65-
return super(LoginRequiredMixin, self).dispatch(*args, **kwargs)
65+
return super().dispatch(*args, **kwargs)
6666

6767

6868
class SuperUserRequiredMixin(LoginRequiredMixin):
@@ -74,7 +74,7 @@ def dispatch(self, *args, **kwargs):
7474
"""Check for login and superuser and dispatch the view."""
7575
user = self.request.user
7676
if user.is_superuser:
77-
return super(LoginRequiredMixin, self).dispatch(*args, **kwargs)
77+
return super().dispatch(*args, **kwargs)
7878
else:
7979
raise PermissionDenied
8080

@@ -129,7 +129,7 @@ class OrganizationList(RestrictedListView):
129129

130130
def get_context_data(self, **kwargs):
131131
"""Setup context for the template."""
132-
context = super(OrganizationList, self).get_context_data(**kwargs)
132+
context = super().get_context_data(**kwargs)
133133
organization_list = context['organization_list']
134134
orgs_with_domains = []
135135
for org in organization_list:
@@ -161,7 +161,7 @@ class ScannerList(RestrictedListView):
161161

162162
def get_queryset(self):
163163
"""Get queryset, don't include non-visible scanners."""
164-
qs = super(ScannerList, self).get_queryset()
164+
qs = super().get_queryset()
165165
# Dismiss scans that are not visible
166166
qs = qs.filter(is_visible=True)
167167
return qs
@@ -176,7 +176,7 @@ class DomainList(RestrictedListView):
176176

177177
def get_queryset(self):
178178
"""Get queryset, ordered by url followed by primary key."""
179-
query_set = super(DomainList, self).get_queryset()
179+
query_set = super().get_queryset()
180180

181181
if query_set:
182182
query_set = query_set.order_by('url', 'pk')
@@ -297,7 +297,7 @@ def form_valid(self, form):
297297
):
298298
self.object.group = user_profile.groups.all()[0]
299299

300-
return super(RestrictedCreateView, self).form_valid(form)
300+
return super().form_valid(form)
301301

302302

303303
class OrgRestrictedMixin(ModelFormMixin, LoginRequiredMixin):
@@ -348,7 +348,7 @@ def get_form(self, form_class=None):
348348

349349
def get_queryset(self):
350350
"""Get queryset filtered by user's organization."""
351-
queryset = super(OrgRestrictedMixin, self).get_queryset()
351+
queryset = super().get_queryset()
352352
if not self.request.user.is_superuser:
353353
organization = None
354354

@@ -435,7 +435,7 @@ def get_form(self, form_class=None):
435435
if form_class is None:
436436
form_class = self.get_form_class()
437437

438-
form = super(ScannerCreate, self).get_form(form_class)
438+
form = super().get_form(form_class)
439439
try:
440440
organization = self.request.user.profile.organization
441441
groups = self.request.user.profile.groups.all()
@@ -499,7 +499,7 @@ def get_form(self, form_class=None):
499499
form_class = self.get_form_class()
500500

501501
self.fields = self.get_form_fields()
502-
form = super(ScannerUpdate, self).get_form(form_class)
502+
form = super().get_form(form_class)
503503

504504
scanner = self.get_object()
505505

@@ -547,7 +547,7 @@ class ScannerAskRun(RestrictedDetailView):
547547

548548
def get_context_data(self, **kwargs):
549549
"""Check that user is allowed to run this scanner."""
550-
context = super(ScannerAskRun, self).get_context_data(**kwargs)
550+
context = super().get_context_data(**kwargs)
551551

552552
if self.object.has_active_scans:
553553
ok = False
@@ -601,7 +601,7 @@ def get_form_fields(self):
601601
The 'validation_status' field will be added to the form if the
602602
user is a superuser.
603603
"""
604-
fields = super(DomainCreate, self).get_form_fields()
604+
fields = super().get_form_fields()
605605
if self.request.user.is_superuser:
606606
fields.append('validation_status')
607607
return fields
@@ -614,7 +614,7 @@ def get_form(self, form_class=None):
614614
if form_class is None:
615615
form_class = self.get_form_class()
616616

617-
form = super(DomainCreate, self).get_form(form_class)
617+
form = super().get_form(form_class)
618618

619619
for fname in form.fields:
620620
f = form.fields[fname]
@@ -637,7 +637,7 @@ class DomainUpdate(RestrictedUpdateView):
637637

638638
def get_form_fields(self):
639639
"""Get the list of form fields."""
640-
fields = super(DomainUpdate, self).get_form_fields()
640+
fields = super().get_form_fields()
641641

642642
if self.request.user.is_superuser:
643643
fields.append('validation_status')
@@ -653,7 +653,7 @@ def get_form(self, form_class=None):
653653
if form_class is None:
654654
form_class = self.get_form_class()
655655

656-
form = super(DomainUpdate, self).get_form(form_class)
656+
form = super().get_form(form_class)
657657

658658
for fname in form.fields:
659659
f = form.fields[fname]
@@ -680,13 +680,13 @@ def form_valid(self, form):
680680
self.object = form.save(commit=False)
681681
self.object.organization = user_profile.organization
682682

683-
result = super(DomainUpdate, self).form_valid(form)
683+
result = super().form_valid(form)
684684

685685
return result
686686

687687
def get_context_data(self, **kwargs):
688688
"""Get the context used when rendering the template."""
689-
context = super(DomainUpdate, self).get_context_data(**kwargs)
689+
context = super().get_context_data(**kwargs)
690690
for value, desc in Domain.validation_method_choices:
691691
key = 'valid_txt_' + str(value)
692692
context[key] = get_validation_str(self.object, value)
@@ -712,7 +712,7 @@ class DomainValidate(RestrictedDetailView):
712712

713713
def get_context_data(self, **kwargs):
714714
"""Perform validation and populate the template context."""
715-
context = super(DomainValidate, self).get_context_data(**kwargs)
715+
context = super().get_context_data(**kwargs)
716716
context['validation_status'] = self.object.validation_status
717717
if not self.object.validation_status:
718718
result = validate_domain(self.object)
@@ -743,7 +743,7 @@ class GroupCreate(RestrictedCreateView):
743743

744744
def get_form_fields(self):
745745
"""Get the list of fields to use in the form for the view."""
746-
fields = super(GroupCreate, self).get_form_fields()
746+
fields = super().get_form_fields()
747747

748748
if 'group' in fields:
749749
fields.remove('group')
@@ -760,7 +760,7 @@ def get_form(self, form_class=None):
760760
if form_class is None:
761761
form_class = self.get_form_class()
762762

763-
form = super(GroupCreate, self).get_form(form_class)
763+
form = super().get_form(form_class)
764764

765765
field_name = 'user_profiles'
766766
queryset = form.fields[field_name].queryset
@@ -791,7 +791,7 @@ def get_form(self, form_class=None):
791791
if form_class is None:
792792
form_class = self.get_form_class()
793793

794-
form = super(GroupUpdate, self).get_form(form_class)
794+
form = super().get_form(form_class)
795795
group = self.get_object()
796796
field_name = 'user_profiles'
797797
queryset = form.fields[field_name].queryset
@@ -831,7 +831,7 @@ def get_form(self, form_class=None):
831831
if form_class is None:
832832
form_class = self.get_form_class()
833833

834-
form = super(RuleCreate, self).get_form(form_class)
834+
form = super().get_form(form_class)
835835

836836
for fname in form.fields:
837837
f = form.fields[fname]
@@ -859,7 +859,7 @@ def get_form(self, form_class=None):
859859
if form_class is None:
860860
form_class = self.get_form_class()
861861

862-
form = super(RuleUpdate, self).get_form(form_class)
862+
form = super().get_form(form_class)
863863

864864
for fname in form.fields:
865865
f = form.fields[fname]
@@ -899,7 +899,7 @@ def get_queryset(self):
899899
If the user is not a superuser the queryset will be limited by the
900900
user's organization.
901901
"""
902-
queryset = super(ReportDetails, self).get_queryset()
902+
queryset = super().get_queryset()
903903
if not self.request.user.is_superuser:
904904
try:
905905
user_profile = self.request.user.profile
@@ -911,7 +911,7 @@ def get_queryset(self):
911911

912912
def get_context_data(self, **kwargs):
913913
"""Add the scan's matches to the report context data."""
914-
context = super(ReportDetails, self).get_context_data(**kwargs)
914+
context = super().get_context_data(**kwargs)
915915
all_matches = Match.objects.filter(
916916
scan=self.get_object()
917917
).order_by('-sensitivity', 'url', 'matched_rule', 'matched_data')
@@ -949,7 +949,7 @@ def get_queryset(self):
949949
If the user is not a superuser the queryset will be limited by the
950950
user's organization.
951951
"""
952-
queryset = super(ReportDelete, self).get_queryset()
952+
queryset = super().get_queryset()
953953
if not self.request.user.is_superuser:
954954
try:
955955
user_profile = self.request.user.profile
@@ -1051,7 +1051,7 @@ class DialogSuccess(TemplateView):
10511051

10521052
def get_context_data(self, **kwargs):
10531053
"""Setup context for the template."""
1054-
context = super(DialogSuccess, self).get_context_data(**kwargs)
1054+
context = super().get_context_data(**kwargs)
10551055
model_type = self.args[0]
10561056
pk = self.args[1]
10571057
created = self.args[2] == 'created'
@@ -1073,7 +1073,7 @@ class SystemStatusView(TemplateView, SuperUserRequiredMixin):
10731073

10741074
def get_context_data(self, **kwargs):
10751075
"""Setup context for the template."""
1076-
context = super(SystemStatusView, self).get_context_data(**kwargs)
1076+
context = super().get_context_data(**kwargs)
10771077
all = ConversionQueueItem.objects.filter(
10781078
status=ConversionQueueItem.NEW
10791079
)
@@ -1134,7 +1134,7 @@ def get_form(self, form_class=None):
11341134
if form_class is None:
11351135
form_class = self.get_form_class()
11361136

1137-
form = super(SummaryCreate, self).get_form(form_class)
1137+
form = super().get_form(form_class)
11381138

11391139
field_names = ['recipients', 'scanners']
11401140
for field_name in field_names:
@@ -1167,7 +1167,7 @@ def get_form(self, form_class=None):
11671167
if form_class is None:
11681168
form_class = self.get_form_class()
11691169

1170-
form = super(SummaryUpdate, self).get_form(form_class)
1170+
form = super().get_form(form_class)
11711171
summary = self.get_object()
11721172
# Limit recipients to organization
11731173
queryset = form.fields['recipients'].queryset
@@ -1212,7 +1212,7 @@ class SummaryReport(RestrictedDetailView):
12121212

12131213
def get_context_data(self, **kwargs):
12141214
"""Setup context for the template."""
1215-
context = super(SummaryReport, self).get_context_data(**kwargs)
1215+
context = super().get_context_data(**kwargs)
12161216

12171217
summary = self.object
12181218
scan_list, from_date, to_date = scans_for_summary_report(summary)

doc/SYSTEM_DEPENDENCIES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apache2
2-
libapache2-mod-wsgi
2+
libapache2-mod-wsgi-py3
33
python-virtualenv
44
postgresql
55
libpq-dev

scrapy-webscanner/scanner/middlewares.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ def process_response(self, request, response, spider):
8484
"""Collect cookie, store on scan object."""
8585

8686
# First, extract cookies as needed - call superclass.
87-
response = super(
88-
CookieCollectorMiddleware,
89-
self
90-
).process_response(request, response, spider)
87+
response = super().process_response(request, response, spider)
9188

9289
# Now collect cookie
9390
current_scan = spider.scanner.scan_object

scrapy-webscanner/scanner/processors/libreoffice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class LibreOfficeProcessor(Processor):
4242

4343
def __init__(self):
4444
"""Initialize the processor, setting an empty home directory."""
45-
super(Processor, self).__init__()
45+
super().__init__()
4646
self.home_dir = None
4747

4848
def setup_home_dir(self):
@@ -65,7 +65,7 @@ def set_home_dir(self, home_dir):
6565

6666
def setup_queue_processing(self, pid, *args):
6767
"""Setup the home directory as the first argument."""
68-
super(LibreOfficeProcessor, self).setup_queue_processing(
68+
super().setup_queue_processing(
6969
pid, *args
7070
)
7171
self.set_home_dir(os.path.join(home_root_dir, args[0]))

scrapy-webscanner/scanner/spiders/base_spider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, scanner, *a, **kw):
3131
3232
The configuration will be loaded from the Scanner.
3333
"""
34-
super(BaseScannerSpider, self).__init__(*a, **kw)
34+
super().__init__(*a, **kw)
3535

3636
self.scanner = scanner
3737

scrapy-webscanner/scanner/spiders/scanner_spider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, scanner, runner="", *a, **kw):
5050
5151
The configuration will be loaded from the Scanner.
5252
"""
53-
super(ScannerSpider, self).__init__(scanner=scanner, *a, **kw)
53+
super().__init__(scanner=scanner, *a, **kw)
5454

5555
self.runner = runner
5656

scrapy-webscanner/scanner/spiders/sitemap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, scanner, sitemap_urls="", uploaded_sitemap_urls="",
2525
*a,
2626
**kw):
2727
"""Initialize the sitemap spider."""
28-
super(SitemapURLGathererSpider, self).__init__(scanner=scanner, *a,
28+
super().__init__(scanner=scanner, *a,
2929
**kw)
3030
self.sitemap_urls = sitemap_urls
3131
self.uploaded_sitemap_urls = uploaded_sitemap_urls

0 commit comments

Comments
 (0)