Skip to content

Commit 831fb18

Browse files
committed
Python2/3 compatibility: Added force_str or force_bytes in some places, to ensure the argument right type
- Legacy-Id: 16450
1 parent eb42394 commit 831fb18

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

ietf/ietfauth/views.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright The IETF Trust 2007-2019, All Rights Reserved
2-
2+
# -*- coding: utf-8 -*-
3+
#
34
# Portions Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
45
# All rights reserved. Contact: Pasi Eronen <pasi.eronen@nokia.com>
56
#
@@ -32,6 +33,9 @@
3233
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3334
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3435

36+
37+
from __future__ import absolute_import, print_function, unicode_literals
38+
3539
import importlib
3640

3741
from datetime import datetime as DateTime, timedelta as TimeDelta, date as Date
@@ -54,6 +58,7 @@
5458
from django.utils.safestring import mark_safe
5559
from django.http import Http404, HttpResponseRedirect #, HttpResponse,
5660
from django.shortcuts import render, redirect, get_object_or_404
61+
from django.utils.encoding import force_bytes
5762

5863
import debug # pyflakes:ignore
5964

@@ -674,7 +679,7 @@ def apikey_disable(request):
674679
class KeyDeleteForm(forms.Form):
675680
hash = forms.ChoiceField(label='Key', choices=choices)
676681
def clean_key(self):
677-
hash = self.cleaned_data['hash']
682+
hash = force_bytes(self.cleaned_data['hash'])
678683
key = PersonalApiKey.validate_key(hash)
679684
if key and key.person == request.user.person:
680685
return hash
@@ -684,7 +689,7 @@ def clean_key(self):
684689
if request.method == 'POST':
685690
form = KeyDeleteForm(request.POST)
686691
if form.is_valid():
687-
hash = form.data['hash']
692+
hash = force_bytes(form.data['hash'])
688693
key = PersonalApiKey.validate_key(hash)
689694
key.valid = False
690695
key.save()

ietf/ipr/forms.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# Copyright The IETF Trust 2014-2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
5+
from __future__ import absolute_import, print_function, unicode_literals
6+
27
import datetime
38
import email
49

510

611
from django import forms
712
from django.core.validators import RegexValidator
813
from django.utils.safestring import mark_safe
14+
from django.utils.encoding import force_str
915

1016
import debug # pyflakes:ignore
1117

@@ -71,7 +77,7 @@ def __init__(self, *args, **kwargs):
7177
def clean_message(self):
7278
'''Returns a ietf.message.models.Message object'''
7379
text = self.cleaned_data['message']
74-
message = email.message_from_string(text)
80+
message = email.message_from_string(force_str(text))
7581
for field in ('to','from','subject','date'):
7682
if not message[field]:
7783
raise forms.ValidationError('Error parsing email: {} field not found.'.format(field))

ietf/utils/decorators.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Copyright The IETF Trust 2016-2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
5+
from __future__ import absolute_import, print_function, unicode_literals
26

37
import datetime
48

@@ -8,6 +12,7 @@
812
from django.contrib.auth import login
913
from django.http import HttpResponse
1014
from django.shortcuts import render
15+
from django.utils.encoding import force_bytes
1116

1217
import debug # pyflakes:ignore
1318

@@ -49,7 +54,7 @@ def err(code, text):
4954
if not hash:
5055
return err(400, "Missing apikey parameter")
5156
# Check hash
52-
key = PersonalApiKey.validate_key(hash)
57+
key = PersonalApiKey.validate_key(force_bytes(hash))
5358
if not key:
5459
return err(400, "Invalid apikey")
5560
# Check endpoint

0 commit comments

Comments
 (0)