From 2bf5f6305030d5ebbd5a8a0fd5c31586c08a558d Mon Sep 17 00:00:00 2001 From: Igor Kalat Date: Sat, 22 Jun 2013 13:43:45 +0200 Subject: Make browsable API views play nice with utf-8 --- rest_framework/utils/formatting.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'rest_framework/utils') diff --git a/rest_framework/utils/formatting.py b/rest_framework/utils/formatting.py index ebadb3a6..a2a5609c 100644 --- a/rest_framework/utils/formatting.py +++ b/rest_framework/utils/formatting.py @@ -24,6 +24,11 @@ def _remove_leading_indent(content): Remove leading indent from a block of text. Used when generating descriptions from docstrings. """ + try: + content = content.decode('utf-8') + except (AttributeError, UnicodeEncodeError): + pass # the string should keep the default 'ascii' encoding in + # Python 2.x or stay a unicode string in Python 3.x whitespace_counts = [len(line) - len(line.lstrip(' ')) for line in content.splitlines()[1:] if line.lstrip()] -- cgit v1.2.3