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
f4707ad0
Commit
f4707ad0
authored
Feb 02, 2017
by
Xavier Ordoquy
Committed by
GitHub
Feb 02, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4870 from felixxm/issue-dedent
Fixed `dedent` for tab indent.
parents
2ec3db81
b99272c4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
16 deletions
+15
-16
rest_framework/utils/formatting.py
+10
-15
tests/test_description.py
+5
-1
No files found.
rest_framework/utils/formatting.py
View file @
f4707ad0
...
@@ -32,23 +32,18 @@ def dedent(content):
...
@@ -32,23 +32,18 @@ def dedent(content):
unindented text on the initial line.
unindented text on the initial line.
"""
"""
content
=
force_text
(
content
)
content
=
force_text
(
content
)
whitespace_counts
=
[
lines
=
[
line
for
line
in
content
.
splitlines
()[
1
:]
if
line
.
lstrip
()]
len
(
line
)
-
len
(
line
.
lstrip
(
' '
))
for
line
in
content
.
splitlines
()[
1
:]
if
line
.
lstrip
()
]
tab_counts
=
[
len
(
line
)
-
len
(
line
.
lstrip
(
'
\t
'
))
for
line
in
content
.
splitlines
()[
1
:]
if
line
.
lstrip
()
]
# unindent the content if needed
# unindent the content if needed
if
whitespace_counts
:
if
lines
:
whitespace_pattern
=
'^'
+
(
' '
*
min
(
whitespace_counts
))
whitespace_counts
=
min
([
len
(
line
)
-
len
(
line
.
lstrip
(
' '
))
for
line
in
lines
])
content
=
re
.
sub
(
re
.
compile
(
whitespace_pattern
,
re
.
MULTILINE
),
''
,
content
)
tab_counts
=
min
([
len
(
line
)
-
len
(
line
.
lstrip
(
'
\t
'
))
for
line
in
lines
])
elif
tab_counts
:
if
whitespace_counts
:
whitespace_pattern
=
'^'
+
(
'
\t
'
*
min
(
whitespace_counts
))
whitespace_pattern
=
'^'
+
(
' '
*
whitespace_counts
)
content
=
re
.
sub
(
re
.
compile
(
whitespace_pattern
,
re
.
MULTILINE
),
''
,
content
)
content
=
re
.
sub
(
re
.
compile
(
whitespace_pattern
,
re
.
MULTILINE
),
''
,
content
)
elif
tab_counts
:
whitespace_pattern
=
'^'
+
(
'
\t
'
*
tab_counts
)
content
=
re
.
sub
(
re
.
compile
(
whitespace_pattern
,
re
.
MULTILINE
),
''
,
content
)
return
content
.
strip
()
return
content
.
strip
()
...
...
tests/test_description.py
View file @
f4707ad0
...
@@ -124,4 +124,8 @@ class TestViewNamesAndDescriptions(TestCase):
...
@@ -124,4 +124,8 @@ class TestViewNamesAndDescriptions(TestCase):
def
test_dedent_tabs
():
def
test_dedent_tabs
():
assert
dedent
(
"
\t
first string
\n\n\t
second string"
)
==
'first string
\n\n\t
second string'
result
=
'first string
\n\n
second string'
assert
dedent
(
" first string
\n\n
second string"
)
==
result
assert
dedent
(
"first string
\n\n
second string"
)
==
result
assert
dedent
(
"
\t
first string
\n\n\t
second string"
)
==
result
assert
dedent
(
"first string
\n\n\t
second string"
)
==
result
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