Skip to content

Commit 7d417fc

Browse files
committed
Make _force_text_recursive private.
1 parent 37312ee commit 7d417fc

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

rest_framework/exceptions.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@
1313
import math
1414

1515

16+
def _force_text_recursive(data):
17+
"""
18+
Descend into a nested data structure, forcing any
19+
lazy translation strings into plain text.
20+
"""
21+
if isinstance(data, list):
22+
return [
23+
_force_text_recursive(item) for item in data
24+
]
25+
elif isinstance(data, dict):
26+
return dict([
27+
(key, _force_text_recursive(value))
28+
for key, value in data.items()
29+
])
30+
return force_text(data)
31+
32+
1633
class APIException(Exception):
1734
"""
1835
Base class for REST framework exceptions.
@@ -38,19 +55,6 @@ def __str__(self):
3855
# from rest_framework import serializers
3956
# raise serializers.ValidationError('Value was invalid')
4057

41-
def force_text_recursive(data):
42-
if isinstance(data, list):
43-
return [
44-
force_text_recursive(item) for item in data
45-
]
46-
elif isinstance(data, dict):
47-
return dict([
48-
(key, force_text_recursive(value))
49-
for key, value in data.items()
50-
])
51-
return force_text(data)
52-
53-
5458
class ValidationError(APIException):
5559
status_code = status.HTTP_400_BAD_REQUEST
5660

@@ -59,7 +63,7 @@ def __init__(self, detail):
5963
# The details should always be coerced to a list if not already.
6064
if not isinstance(detail, dict) and not isinstance(detail, list):
6165
detail = [detail]
62-
self.detail = force_text_recursive(detail)
66+
self.detail = _force_text_recursive(detail)
6367

6468
def __str__(self):
6569
return str(self.detail)

0 commit comments

Comments
 (0)