summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/dateformat.py5
-rw-r--r--django/utils/html.py8
-rw-r--r--django/utils/text.py23
-rw-r--r--django/utils/translation/__init__.py3
4 files changed, 17 insertions, 22 deletions
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py
index 6c8cab61f5..d3f586aacf 100644
--- a/django/utils/dateformat.py
+++ b/django/utils/dateformat.py
@@ -18,7 +18,6 @@ import time
from django.utils.dates import (
MONTHS, MONTHS_3, MONTHS_ALT, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR,
)
-from django.utils.encoding import force_text
from django.utils.timezone import get_default_timezone, is_aware, is_naive
from django.utils.translation import gettext as _
@@ -29,14 +28,14 @@ re_escaped = re.compile(r'\\(.)')
class Formatter:
def format(self, formatstr):
pieces = []
- for i, piece in enumerate(re_formatchars.split(force_text(formatstr))):
+ for i, piece in enumerate(re_formatchars.split(str(formatstr))):
if i % 2:
if type(self.data) is datetime.date and hasattr(TimeFormat, piece):
raise TypeError(
"The format for date objects may not contain "
"time-related format specifiers (found '%s')." % piece
)
- pieces.append(force_text(getattr(self, piece)()))
+ pieces.append(str(getattr(self, piece)()))
elif piece:
pieces.append(re_escaped.sub(r'\1', piece))
return ''.join(pieces)
diff --git a/django/utils/html.py b/django/utils/html.py
index 25843ce576..9f4f58c7a1 100644
--- a/django/utils/html.py
+++ b/django/utils/html.py
@@ -43,7 +43,7 @@ def escape(text):
conditional_escape() instead.
"""
return mark_safe(
- force_text(text).replace('&', '&amp;').replace('<', '&lt;')
+ str(text).replace('&', '&amp;').replace('<', '&lt;')
.replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;')
)
@@ -70,7 +70,7 @@ _js_escapes.update((ord('%c' % z), '\\u%04X' % z) for z in range(32))
@keep_lazy(str, SafeText)
def escapejs(value):
"""Hex encode characters for use in JavaScript strings."""
- return mark_safe(force_text(value).translate(_js_escapes))
+ return mark_safe(str(value).translate(_js_escapes))
def conditional_escape(text):
@@ -121,8 +121,8 @@ def format_html_join(sep, format_string, args_generator):
@keep_lazy_text
def linebreaks(value, autoescape=False):
"""Convert newlines into <p> and <br />s."""
- value = normalize_newlines(force_text(value))
- paras = re.split('\n{2,}', value)
+ value = normalize_newlines(value)
+ paras = re.split('\n{2,}', str(value))
if autoescape:
paras = ['<p>%s</p>' % escape(p).replace('\n', '<br />') for p in paras]
else:
diff --git a/django/utils/text.py b/django/utils/text.py
index cd9e704ea1..3e04f8bec7 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -4,7 +4,6 @@ import unicodedata
from gzip import GzipFile
from io import BytesIO
-from django.utils.encoding import force_text
from django.utils.functional import (
SimpleLazyObject, keep_lazy, keep_lazy_text, lazy,
)
@@ -15,7 +14,7 @@ from django.utils.translation import gettext as _, gettext_lazy, pgettext
@keep_lazy_text
def capfirst(x):
"""Capitalize the first letter of a string."""
- return x and force_text(x)[0].upper() + force_text(x)[1:]
+ return x and str(x)[0].upper() + str(x)[1:]
# Set up regular expressions
@@ -62,7 +61,7 @@ class Truncator(SimpleLazyObject):
An object used to truncate text, either by characters or words.
"""
def __init__(self, text):
- super().__init__(lambda: force_text(text))
+ super().__init__(lambda: str(text))
def add_truncation_text(self, text, truncate=None):
if truncate is None:
@@ -230,7 +229,7 @@ def get_valid_filename(s):
>>> get_valid_filename("john's portrait in 2004.jpg")
'johns_portrait_in_2004.jpg'
"""
- s = force_text(s).strip().replace(' ', '_')
+ s = str(s).strip().replace(' ', '_')
return re.sub(r'(?u)[^-\w.]', '', s)
@@ -251,18 +250,17 @@ def get_text_list(list_, last_word=gettext_lazy('or')):
if len(list_) == 0:
return ''
if len(list_) == 1:
- return force_text(list_[0])
+ return str(list_[0])
return '%s %s %s' % (
# Translators: This string is used as a separator between list elements
- _(', ').join(force_text(i) for i in list_[:-1]),
- force_text(last_word), force_text(list_[-1]))
+ _(', ').join(str(i) for i in list_[:-1]), str(last_word), str(list_[-1])
+ )
@keep_lazy_text
def normalize_newlines(text):
"""Normalize CRLF and CR newlines to just LF."""
- text = force_text(text)
- return re_newlines.sub('\n', text)
+ return re_newlines.sub('\n', str(text))
@keep_lazy_text
@@ -349,8 +347,7 @@ def smart_split(text):
>>> list(smart_split(r'A "\"funky\" style" test.'))
['A', '"\\"funky\\" style"', 'test.']
"""
- text = force_text(text)
- for bit in smart_split_re.finditer(text):
+ for bit in smart_split_re.finditer(str(text)):
yield bit.group(0)
@@ -378,7 +375,7 @@ _entity_re = re.compile(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));")
@keep_lazy_text
def unescape_entities(text):
- return _entity_re.sub(_replace_entity, force_text(text))
+ return _entity_re.sub(_replace_entity, str(text))
@keep_lazy_text
@@ -409,7 +406,7 @@ def slugify(value, allow_unicode=False):
Remove characters that aren't alphanumerics, underscores, or hyphens.
Convert to lowercase. Also strip leading and trailing whitespace.
"""
- value = force_text(value)
+ value = str(value)
if allow_unicode:
value = unicodedata.normalize('NFKC', value)
else:
diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
index dc4936a976..f342cf7227 100644
--- a/django/utils/translation/__init__.py
+++ b/django/utils/translation/__init__.py
@@ -6,7 +6,6 @@ import warnings
from contextlib import ContextDecorator
from django.utils.deprecation import RemovedInDjango21Warning
-from django.utils.encoding import force_text
from django.utils.functional import lazy
__all__ = [
@@ -226,7 +225,7 @@ def _string_concat(*strings):
'django.utils.translate.string_concat() is deprecated in '
'favor of django.utils.text.format_lazy().',
RemovedInDjango21Warning, stacklevel=2)
- return ''.join(force_text(s) for s in strings)
+ return ''.join(str(s) for s in strings)
string_concat = lazy(_string_concat, str)