Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
2bf5f630
Commit
2bf5f630
authored
Jun 22, 2013
by
Igor Kalat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make browsable API views play nice with utf-8
parent
df957c86
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
rest_framework/tests/test_utils.py
+36
-0
rest_framework/utils/formatting.py
+5
-0
No files found.
rest_framework/tests/test_utils.py
0 → 100644
View file @
2bf5f630
# -*- coding: utf-8 -*-
from
django.test
import
TestCase
from
rest_framework.utils
import
formatting
import
sys
class
FormattingUnitTests
(
TestCase
):
def
setUp
(
self
):
# test strings snatched from http://www.columbia.edu/~fdc/utf8/,
# http://winrus.com/utf8-jap.htm and memory
self
.
utf8_test_string
=
(
'zażółć gęślą jaźń'
'Sîne klâwen durh die wolken sint geslagen'
'Τη γλώσσα μου έδωσαν ελληνική'
'யாமறிந்த மொழிகளிலே தமிழ்மொழி'
'На берегу пустынных волн'
' てすと'
'アイウエオカキクケコサシスセソタチツテ'
)
self
.
non_utf8_test_string
=
(
'The quick brown fox jumps over the lazy '
'dog'
)
def
test_for_ascii_support_in_remove_leading_indent
(
self
):
if
sys
.
version_info
<
(
3
,
0
):
# only Python 2.x is affected, so we skip the test entirely
# if on Python 3.x
self
.
assertEqual
(
formatting
.
_remove_leading_indent
(
self
.
non_utf8_test_string
),
self
.
non_utf8_test_string
)
def
test_for_utf8_support_in_remove_leading_indent
(
self
):
if
sys
.
version_info
<
(
3
,
0
):
# only Python 2.x is affected, so we skip the test entirely
# if on Python 3.x
self
.
assertEqual
(
formatting
.
_remove_leading_indent
(
self
.
utf8_test_string
),
self
.
utf8_test_string
.
decode
(
'utf-8'
))
rest_framework/utils/formatting.py
View file @
2bf5f630
...
@@ -24,6 +24,11 @@ def _remove_leading_indent(content):
...
@@ -24,6 +24,11 @@ def _remove_leading_indent(content):
Remove leading indent from a block of text.
Remove leading indent from a block of text.
Used when generating descriptions from docstrings.
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
(
' '
))
whitespace_counts
=
[
len
(
line
)
-
len
(
line
.
lstrip
(
' '
))
for
line
in
content
.
splitlines
()[
1
:]
if
line
.
lstrip
()]
for
line
in
content
.
splitlines
()[
1
:]
if
line
.
lstrip
()]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment