refactor: Replace deprecated force_text with force_str
This commit is contained in:
parent
dcb211fbb3
commit
07e26dd52e
|
@ -221,7 +221,7 @@ class JsonExportMixin(object):
|
|||
# obj = None
|
||||
#
|
||||
# if obj is None:
|
||||
# raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_text(self.model._meta.verbose_name), 'key': escape(object_id)})
|
||||
# raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_str(self.model._meta.verbose_name), 'key': escape(object_id)})
|
||||
#
|
||||
# content_type = 'application/json'
|
||||
# return HttpResponse(serialize([ obj ], sort_keys=True, indent=3)[2:-2], content_type=content_type)
|
||||
|
|
|
@ -11,7 +11,7 @@ from django.utils.html import strip_tags
|
|||
from django.conf import settings
|
||||
from django.urls import reverse as urlreverse
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_str
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
from ietf.doc.templatetags.mail_filters import std_level_prompt
|
||||
|
@ -175,7 +175,7 @@ def generate_ballot_writeup(request, doc):
|
|||
e.doc = doc
|
||||
e.rev = doc.rev
|
||||
e.desc = "Ballot writeup was generated"
|
||||
e.text = force_text(render_to_string("doc/mail/ballot_writeup.txt", {'iana': iana, 'doc': doc }))
|
||||
e.text = force_str(render_to_string("doc/mail/ballot_writeup.txt", {'iana': iana, 'doc': doc }))
|
||||
|
||||
# caller is responsible for saving, if necessary
|
||||
return e
|
||||
|
@ -187,7 +187,7 @@ def generate_ballot_rfceditornote(request, doc):
|
|||
e.doc = doc
|
||||
e.rev = doc.rev
|
||||
e.desc = "RFC Editor Note for ballot was generated"
|
||||
e.text = force_text(render_to_string("doc/mail/ballot_rfceditornote.txt"))
|
||||
e.text = force_str(render_to_string("doc/mail/ballot_rfceditornote.txt"))
|
||||
e.save()
|
||||
|
||||
return e
|
||||
|
@ -232,7 +232,7 @@ def generate_last_call_announcement(request, doc):
|
|||
e.doc = doc
|
||||
e.rev = doc.rev
|
||||
e.desc = "Last call announcement was generated"
|
||||
e.text = force_text(mail)
|
||||
e.text = force_str(mail)
|
||||
|
||||
# caller is responsible for saving, if necessary
|
||||
return e
|
||||
|
@ -252,7 +252,7 @@ def generate_approval_mail(request, doc):
|
|||
e.doc = doc
|
||||
e.rev = doc.rev
|
||||
e.desc = "Ballot approval text was generated"
|
||||
e.text = force_text(mail)
|
||||
e.text = force_str(mail)
|
||||
|
||||
# caller is responsible for saving, if necessary
|
||||
return e
|
||||
|
|
|
@ -23,7 +23,7 @@ from django.urls import reverse as urlreverse
|
|||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_str
|
||||
from django.utils.html import mark_safe # type:ignore
|
||||
from django.contrib.staticfiles import finders
|
||||
|
||||
|
@ -1131,7 +1131,7 @@ class DocHistory(DocumentInfo):
|
|||
name = models.CharField(max_length=255)
|
||||
|
||||
def __str__(self):
|
||||
return force_text(self.doc.name)
|
||||
return force_str(self.doc.name)
|
||||
|
||||
def get_related_session(self):
|
||||
return self.doc.get_related_session()
|
||||
|
@ -1193,7 +1193,7 @@ class DocAlias(models.Model):
|
|||
return self.docs.first()
|
||||
|
||||
def __str__(self):
|
||||
return u"%s-->%s" % (self.name, ','.join([force_text(d.name) for d in self.docs.all() if isinstance(d, Document) ]))
|
||||
return u"%s-->%s" % (self.name, ','.join([force_str(d.name) for d in self.docs.all() if isinstance(d, Document) ]))
|
||||
document_link = admin_link("document")
|
||||
class Meta:
|
||||
verbose_name = "document alias"
|
||||
|
|
|
@ -13,8 +13,7 @@ from django.utils.html import escape
|
|||
from django.template.defaultfilters import truncatewords_html, linebreaksbr, stringfilter, striptags
|
||||
from django.utils.safestring import mark_safe, SafeData
|
||||
from django.utils.html import strip_tags
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_str # pyflakes:ignore force_str is used in the doctests
|
||||
from django.utils.encoding import force_str
|
||||
from django.urls import reverse as urlreverse
|
||||
from django.core.cache import cache
|
||||
from django.core.exceptions import ValidationError
|
||||
|
@ -132,7 +131,7 @@ register.filter('fill', fill)
|
|||
@register.filter
|
||||
def prettystdname(string, space=" "):
|
||||
from ietf.doc.utils import prettify_std_name
|
||||
return prettify_std_name(force_text(string or ""), space)
|
||||
return prettify_std_name(force_str(string or ""), space)
|
||||
|
||||
@register.filter
|
||||
def rfceditor_info_url(rfcnum : str):
|
||||
|
|
|
@ -12,7 +12,7 @@ from django.conf import settings
|
|||
from django.urls import reverse as urlreverse
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import smart_text, force_text
|
||||
from django.utils.encoding import smart_text, force_str
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
|
@ -153,7 +153,7 @@ def generate_ballot_writeup(request, doc):
|
|||
e.doc = doc
|
||||
e.rev = doc.rev,
|
||||
e.desc = "Ballot writeup was generated"
|
||||
e.text = force_text(render_to_string("doc/charter/ballot_writeup.txt"))
|
||||
e.text = force_str(render_to_string("doc/charter/ballot_writeup.txt"))
|
||||
|
||||
# caller is responsible for saving, if necessary
|
||||
return e
|
||||
|
|
|
@ -17,7 +17,7 @@ from django.conf import settings
|
|||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_str
|
||||
from django.utils.html import escape
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
@ -821,7 +821,7 @@ def charter_with_milestones_txt(request, name, rev):
|
|||
|
||||
try:
|
||||
with io.open(os.path.join(settings.CHARTER_PATH, filename), 'r') as f:
|
||||
charter_text = force_text(f.read(), errors='ignore')
|
||||
charter_text = force_str(f.read(), errors='ignore')
|
||||
except IOError:
|
||||
charter_text = "Error reading charter text %s" % filename
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from django.http import Http404, HttpResponseRedirect
|
|||
from django.urls import reverse
|
||||
from django.template.loader import render_to_string
|
||||
from django.conf import settings
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_str
|
||||
from django.utils.html import escape
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
@ -665,7 +665,7 @@ def generate_last_call_text(request, doc):
|
|||
e.doc = doc
|
||||
e.rev = doc.rev
|
||||
e.desc = 'Last call announcement was generated'
|
||||
e.text = force_text(new_text)
|
||||
e.text = force_str(new_text)
|
||||
e.save()
|
||||
|
||||
return e
|
||||
|
|
|
@ -14,7 +14,7 @@ from django.contrib.admin.utils import unquote
|
|||
from django.core.management import load_command_class
|
||||
from django.http import Http404
|
||||
from django.shortcuts import render
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_str
|
||||
from django.utils.html import escape
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
@ -152,7 +152,7 @@ class GroupAdmin(admin.ModelAdmin):
|
|||
permission_denied(request, "You don't have edit permissions for this change.")
|
||||
|
||||
if obj is None:
|
||||
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_text(opts.verbose_name), 'key': escape(object_id)})
|
||||
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_str(opts.verbose_name), 'key': escape(object_id)})
|
||||
|
||||
return self.send_reminder(request, sdo=obj)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from django.contrib.syndication.views import Feed
|
|||
from django.utils.feedgenerator import Atom1Feed
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_str
|
||||
|
||||
from ietf.ipr.models import IprDisclosureBase
|
||||
|
||||
|
@ -25,7 +25,7 @@ class LatestIprDisclosuresFeed(Feed):
|
|||
return mark_safe(item.title)
|
||||
|
||||
def item_description(self, item):
|
||||
return force_text(item.title)
|
||||
return force_str(item.title)
|
||||
|
||||
def item_pubdate(self, item):
|
||||
return item.time
|
||||
|
|
|
@ -12,7 +12,7 @@ from email import message_from_bytes
|
|||
from email.utils import parsedate_tz
|
||||
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.encoding import force_text, force_bytes
|
||||
from django.utils.encoding import force_str, force_bytes
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
|
@ -102,7 +102,7 @@ def get_reply_to():
|
|||
address with "plus addressing" using a random string. Guaranteed to be unique"""
|
||||
local,domain = get_base_ipr_request_address().split('@')
|
||||
while True:
|
||||
rand = force_text(base64.urlsafe_b64encode(os.urandom(12)))
|
||||
rand = force_str(base64.urlsafe_b64encode(os.urandom(12)))
|
||||
address = "{}+{}@{}".format(local,rand,domain)
|
||||
q = Message.objects.filter(reply_to=address)
|
||||
if not q:
|
||||
|
|
|
@ -132,7 +132,7 @@ class AddCommentForm(forms.Form):
|
|||
# def render(self):
|
||||
# output = []
|
||||
# for widget in self:
|
||||
# output.append(format_html(force_text(widget)))
|
||||
# output.append(format_html(force_str(widget)))
|
||||
# return mark_safe('\n'.join(output))
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import re
|
|||
from django import template
|
||||
from django.conf import settings
|
||||
from django.template.defaultfilters import linebreaksbr, force_escape
|
||||
from django.utils.encoding import force_text, DjangoUnicodeDecodeError
|
||||
from django.utils.encoding import force_str, DjangoUnicodeDecodeError
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
@ -68,7 +68,7 @@ def decrypt(string, request, year, plain=False):
|
|||
code, out, error = pipe(command % (settings.OPENSSL_COMMAND,
|
||||
encrypted_file.name), key)
|
||||
try:
|
||||
out = force_text(out)
|
||||
out = force_str(out)
|
||||
except DjangoUnicodeDecodeError:
|
||||
pass
|
||||
if code != 0:
|
||||
|
|
|
@ -18,7 +18,7 @@ from django.http import Http404, HttpResponseRedirect, HttpResponse
|
|||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
from django.utils.encoding import force_bytes, force_str
|
||||
|
||||
|
||||
from ietf.dbtemplate.models import DBTemplate
|
||||
|
@ -684,7 +684,7 @@ def private_questionnaire(request, year):
|
|||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, 'The questionnaire response has been registered.')
|
||||
questionnaire_response = force_text(form.cleaned_data['comment_text'])
|
||||
questionnaire_response = force_str(form.cleaned_data['comment_text'])
|
||||
form = QuestionnaireForm(nomcom=nomcom, user=request.user)
|
||||
else:
|
||||
form = QuestionnaireForm(nomcom=nomcom, user=request.user)
|
||||
|
|
|
@ -16,7 +16,7 @@ from unicodedata import normalize
|
|||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.text import slugify
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_str
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
|
@ -68,7 +68,7 @@ class PersonFactory(factory.django.DjangoModelFactory):
|
|||
# Some i18n names, e.g., "शिला के.सी." have a dot at the end that is also part of the ASCII, e.g., "Shilaa Kesii."
|
||||
# That trailing dot breaks extract_authors(). Avoid this issue by stripping the dot from the ASCII.
|
||||
# Some others have a trailing semicolon (e.g., "உயிரோவியம் தங்கராஐ;") - strip those, too.
|
||||
ascii = factory.LazyAttribute(lambda p: force_text(unidecode_name(p.name)).rstrip(".;"))
|
||||
ascii = factory.LazyAttribute(lambda p: force_str(unidecode_name(p.name)).rstrip(".;"))
|
||||
|
||||
class Params:
|
||||
with_bio = factory.Trait(biography = "\n\n".join(fake.paragraphs())) # type: ignore
|
||||
|
|
|
@ -13,7 +13,7 @@ from django.urls import reverse as urlreverse
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.contrib.sites.models import Site
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.encoding import force_text, force_str
|
||||
from django.utils.encoding import force_str
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
|
@ -202,7 +202,7 @@ def get_reply_to():
|
|||
address with "plus addressing" using a random string. Guaranteed to be unique"""
|
||||
local,domain = get_base_submission_message_address().split('@')
|
||||
while True:
|
||||
rand = force_text(base64.urlsafe_b64encode(os.urandom(12)))
|
||||
rand = force_str(base64.urlsafe_b64encode(os.urandom(12)))
|
||||
address = "{}+{}@{}".format(local,rand,domain)
|
||||
q = Message.objects.filter(reply_to=address)
|
||||
if not q:
|
||||
|
|
|
@ -23,7 +23,7 @@ from django.test import override_settings
|
|||
from django.test.client import RequestFactory
|
||||
from django.urls import reverse as urlreverse
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_str, force_text
|
||||
from django.utils.encoding import force_str
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
from ietf.submit.utils import (expirable_submissions, expire_submission, find_submission_filenames,
|
||||
|
@ -701,10 +701,10 @@ class SubmitTests(BaseSubmitTestCase):
|
|||
self.assertTrue("New Version Notification" in outbox[-2]["Subject"])
|
||||
self.assertTrue(name in get_payload_text(outbox[-2]))
|
||||
interesting_address = {'ietf':'mars', 'irtf':'irtf-chair', 'iab':'iab-chair', 'ise':'rfc-ise'}[draft.stream_id]
|
||||
self.assertTrue(interesting_address in force_text(outbox[-2].as_string()))
|
||||
self.assertTrue(interesting_address in force_str(outbox[-2].as_string()))
|
||||
if draft.stream_id == 'ietf':
|
||||
self.assertTrue(draft.ad.role_email("ad").address in force_text(outbox[-2].as_string()))
|
||||
self.assertTrue(ballot_position.balloter.role_email("ad").address in force_text(outbox[-2].as_string()))
|
||||
self.assertTrue(draft.ad.role_email("ad").address in force_str(outbox[-2].as_string()))
|
||||
self.assertTrue(ballot_position.balloter.role_email("ad").address in force_str(outbox[-2].as_string()))
|
||||
self.assertTrue("New Version Notification" in outbox[-1]["Subject"])
|
||||
self.assertTrue(name in get_payload_text(outbox[-1]))
|
||||
r = self.client.get(urlreverse('ietf.doc.views_search.recent_drafts'))
|
||||
|
|
|
@ -12,7 +12,7 @@ from xml.dom import pulldom, Node
|
|||
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import smart_bytes, force_str, force_text
|
||||
from django.utils.encoding import smart_bytes, force_str
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
|
@ -583,7 +583,7 @@ def post_approved_draft(url, name):
|
|||
if r.status_code != 200:
|
||||
raise RuntimeError("Status code is not 200 OK (it's %s)." % r.status_code)
|
||||
|
||||
if force_text(r.text) != "OK":
|
||||
if force_str(r.text) != "OK":
|
||||
raise RuntimeError('Response is not "OK" (it\'s "%s").' % r.text)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
import time, random, hashlib
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
from django.utils.encoding import force_bytes, force_str
|
||||
|
||||
|
||||
def generate_random_key(max_length=32):
|
||||
|
@ -18,4 +18,4 @@ def generate_access_token(key, max_length=32):
|
|||
# we hash it with the private key to make sure only we can
|
||||
# generate and use the final token - so storing the key in the
|
||||
# database is safe
|
||||
return force_text(hashlib.sha256(force_bytes(settings.SECRET_KEY) + force_bytes(key)).hexdigest()[:max_length])
|
||||
return force_str(hashlib.sha256(force_bytes(settings.SECRET_KEY) + force_bytes(key)).hexdigest()[:max_length])
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
|
||||
from django.contrib import admin
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_str
|
||||
|
||||
from ietf.utils.models import VersionInfo
|
||||
|
||||
|
@ -14,7 +14,7 @@ def name(obj):
|
|||
if callable(obj.name):
|
||||
name = obj.name()
|
||||
else:
|
||||
name = force_text(obj.name)
|
||||
name = force_str(obj.name)
|
||||
if name:
|
||||
return name
|
||||
return str(obj)
|
||||
|
|
|
@ -27,7 +27,7 @@ from django.core.validators import validate_email
|
|||
from django.template.loader import render_to_string
|
||||
from django.template import Context,RequestContext
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_text, force_str, force_bytes
|
||||
from django.utils.encoding import force_str, force_bytes
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
|
@ -137,7 +137,7 @@ def send_smtp(msg, bcc=None):
|
|||
server.quit()
|
||||
except smtplib.SMTPServerDisconnected:
|
||||
pass
|
||||
subj = force_text(msg.get('Subject', '[no subject]'))
|
||||
subj = force_str(msg.get('Subject', '[no subject]'))
|
||||
tau = time.time() - mark
|
||||
log("sent email (%.3fs) from '%s' to %s id %s subject '%s'" % (tau, frm, to, msg.get('Message-ID', ''), subj))
|
||||
|
||||
|
@ -166,7 +166,7 @@ def copy_email(msg, to, toUser=False, originalBcc=None):
|
|||
# Overwrite the From: header, so that the copy from a development or
|
||||
# test server doesn't look like spam.
|
||||
new['From'] = settings.DEFAULT_FROM_EMAIL
|
||||
new['Subject'] = '[Django %s] %s' % (settings.SERVER_MODE, force_text(msg.get('Subject', '[no subject]')))
|
||||
new['Subject'] = '[Django %s] %s' % (settings.SERVER_MODE, force_str(msg.get('Subject', '[no subject]')))
|
||||
new['To'] = to
|
||||
send_smtp(new)
|
||||
|
||||
|
@ -325,7 +325,7 @@ def show_that_mail_was_sent(request,leadline,msg,bcc):
|
|||
from ietf.ietfauth.utils import has_role
|
||||
if has_role(request.user,['Area Director','Secretariat','IANA','RFC Editor','ISE','IAD','IRTF Chair','WG Chair','RG Chair','WG Secretary','RG Secretary']):
|
||||
info = "%s at %s %s\n" % (leadline,timezone.now().strftime("%Y-%m-%d %H:%M:%S"),settings.TIME_ZONE)
|
||||
info += "Subject: %s\n" % force_text(msg.get('Subject','[no subject]'))
|
||||
info += "Subject: %s\n" % force_str(msg.get('Subject','[no subject]'))
|
||||
info += "To: %s\n" % msg.get('To','[no to]')
|
||||
if msg.get('Cc'):
|
||||
info += "Cc: %s\n" % msg.get('Cc')
|
||||
|
@ -336,7 +336,7 @@ def show_that_mail_was_sent(request,leadline,msg,bcc):
|
|||
def save_as_message(request, msg, bcc):
|
||||
by = ((request and request.user and not request.user.is_anonymous and request.user.person)
|
||||
or ietf.person.models.Person.objects.get(name="(System)"))
|
||||
headers, body = force_text(str(msg)).split('\n\n', 1)
|
||||
headers, body = force_str(str(msg)).split('\n\n', 1)
|
||||
kwargs = {'by': by, 'body': body, 'content_type': msg.get_content_type(), 'bcc': bcc or '' }
|
||||
for (arg, field) in [
|
||||
('cc', 'Cc'),
|
||||
|
|
|
@ -18,7 +18,7 @@ from django.core.exceptions import ObjectDoesNotExist
|
|||
from django.core import serializers
|
||||
from django.db import DEFAULT_DB_ALIAS, DatabaseError, IntegrityError, connections
|
||||
from django.db.models.signals import post_save
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_str
|
||||
import django.core.management.commands.loaddata as loaddata
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
@ -91,7 +91,7 @@ class Command(loaddata.Command):
|
|||
obj.save(using=self.using)
|
||||
self.loaded_object_count += 1
|
||||
except (DatabaseError, IntegrityError, ObjectDoesNotExist, AttributeError) as e:
|
||||
error_msg = force_text(e)
|
||||
error_msg = force_str(e)
|
||||
if "Duplicate entry" in error_msg:
|
||||
pass
|
||||
else:
|
||||
|
|
|
@ -15,7 +15,7 @@ from django.core.management.base import CommandError
|
|||
from django.core.management.commands.loaddata import Command as LoadCommand, humanize
|
||||
from django.db import DatabaseError, IntegrityError, router, transaction
|
||||
from django.db.models import ManyToManyField
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.encoding import force_str
|
||||
|
||||
from ietf.utils.models import ForeignKey
|
||||
|
||||
|
@ -234,7 +234,7 @@ class Command(LoadCommand):
|
|||
'object_name': obj.object._meta.object_name,
|
||||
'pk': obj.object.pk,
|
||||
'data': obj_to_dict(obj.object),
|
||||
'error_msg': force_text(e)
|
||||
'error_msg': force_str(e)
|
||||
},)
|
||||
raise
|
||||
if objects and show_progress:
|
||||
|
|
Loading…
Reference in a new issue