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
3774ba3e
Commit
3774ba3e
authored
Mar 28, 2013
by
glic3rinu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added force_text to compat
parent
2c0363dd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletions
+33
-1
rest_framework/compat.py
+31
-0
rest_framework/templatetags/rest_framework.py
+2
-1
No files found.
rest_framework/compat.py
View file @
3774ba3e
...
...
@@ -395,6 +395,37 @@ except ImportError:
kw
=
dict
((
k
,
int
(
v
))
for
k
,
v
in
kw
.
iteritems
()
if
v
is
not
None
)
return
datetime
.
datetime
(
**
kw
)
# smart_urlquote is new on Django 1.4
try
:
from
django.utils.html
import
smart_urlquote
except
ImportError
:
try
:
from
urllib.parse
import
quote
,
urlsplit
,
urlunsplit
except
ImportError
:
# Python 2
from
urllib
import
quote
from
urlparse
import
urlsplit
,
urlunsplit
def
smart_urlquote
(
url
):
"Quotes a URL if it isn't already quoted."
# Handle IDN before quoting.
scheme
,
netloc
,
path
,
query
,
fragment
=
urlsplit
(
url
)
try
:
netloc
=
netloc
.
encode
(
'idna'
)
.
decode
(
'ascii'
)
# IDN -> ACE
except
UnicodeError
:
# invalid domain part
pass
else
:
url
=
urlunsplit
((
scheme
,
netloc
,
path
,
query
,
fragment
))
# An URL is considered unquoted if it contains no % characters or
# contains a % not followed by two hexadecimal digits. See #9655.
if
'
%
'
not
in
url
or
unquoted_percents_re
.
search
(
url
):
# See http://bugs.python.org/issue2637
url
=
quote
(
force_bytes
(
url
),
safe
=
b
'!*
\'
();:@&=+$,/?#[]~'
)
return
force_text
(
url
)
# Markdown is optional
try
:
import
markdown
...
...
rest_framework/templatetags/rest_framework.py
View file @
3774ba3e
...
...
@@ -2,11 +2,12 @@ from __future__ import unicode_literals, absolute_import
from
django
import
template
from
django.core.urlresolvers
import
reverse
,
NoReverseMatch
from
django.http
import
QueryDict
from
django.utils.html
import
escape
,
smart_urlquote
from
django.utils.html
import
escape
from
django.utils.safestring
import
SafeData
,
mark_safe
from
rest_framework.compat
import
urlparse
from
rest_framework.compat
import
force_text
from
rest_framework.compat
import
six
from
rest_framework.compat
import
smart_urlquote
import
re
import
string
...
...
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