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
4b77b3c5
Commit
4b77b3c5
authored
Jan 02, 2013
by
Xavier Ordoquy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the urlparse lib compatibility to the compat file.
parent
c95fa81c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
10 deletions
+13
-10
rest_framework/compat.py
+7
-1
rest_framework/relations.py
+2
-2
rest_framework/templatetags/rest_framework.py
+4
-7
No files found.
rest_framework/compat.py
View file @
4b77b3c5
...
@@ -30,6 +30,13 @@ except ImportError:
...
@@ -30,6 +30,13 @@ except ImportError:
from
six
import
BytesIO
from
six
import
BytesIO
# urlparse compat import (Required because it changed in python 3.x)
try
:
from
urllib
import
parse
as
urlparse
except
ImportError
:
import
urlparse
as
urlparse
# Try to import PIL in either of the two ways it can end up installed.
# Try to import PIL in either of the two ways it can end up installed.
try
:
try
:
from
PIL
import
Image
from
PIL
import
Image
...
@@ -109,7 +116,6 @@ else:
...
@@ -109,7 +116,6 @@ else:
import
re
import
re
import
random
import
random
import
logging
import
logging
import
urlparse
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.urlresolvers
import
get_callable
from
django.core.urlresolvers
import
get_callable
...
...
rest_framework/relations.py
View file @
4b77b3c5
...
@@ -12,7 +12,7 @@ except ImportError:
...
@@ -12,7 +12,7 @@ except ImportError:
from
django.utils.encoding
import
smart_unicode
as
smart_text
from
django.utils.encoding
import
smart_unicode
as
smart_text
from
rest_framework.fields
import
Field
,
WritableField
from
rest_framework.fields
import
Field
,
WritableField
from
rest_framework.reverse
import
reverse
from
rest_framework.reverse
import
reverse
from
urlparse
import
urlparse
from
rest_framework.compat
import
urlparse
##### Relational fields #####
##### Relational fields #####
...
@@ -360,7 +360,7 @@ class HyperlinkedRelatedField(RelatedField):
...
@@ -360,7 +360,7 @@ class HyperlinkedRelatedField(RelatedField):
if
value
.
startswith
(
'http:'
)
or
value
.
startswith
(
'https:'
):
if
value
.
startswith
(
'http:'
)
or
value
.
startswith
(
'https:'
):
# If needed convert absolute URLs to relative path
# If needed convert absolute URLs to relative path
value
=
urlparse
(
value
)
.
path
value
=
urlparse
.
urlparse
(
value
)
.
path
prefix
=
get_script_prefix
()
prefix
=
get_script_prefix
()
if
value
.
startswith
(
prefix
):
if
value
.
startswith
(
prefix
):
value
=
'/'
+
value
[
len
(
prefix
):]
value
=
'/'
+
value
[
len
(
prefix
):]
...
...
rest_framework/templatetags/rest_framework.py
View file @
4b77b3c5
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
,
absolute_import
import
six
import
six
from
django
import
template
from
django
import
template
...
@@ -10,10 +10,7 @@ except ImportError:
...
@@ -10,10 +10,7 @@ except ImportError:
from
django.utils.encoding
import
force_unicode
as
force_text
from
django.utils.encoding
import
force_unicode
as
force_text
from
django.utils.html
import
escape
from
django.utils.html
import
escape
from
django.utils.safestring
import
SafeData
,
mark_safe
from
django.utils.safestring
import
SafeData
,
mark_safe
try
:
from
rest_framework.compat
import
urlparse
from
urllib.parse
import
urlsplit
,
urlunsplit
except
ImportError
:
from
urlparse
import
urlsplit
,
urlunsplit
import
re
import
re
import
string
import
string
...
@@ -108,11 +105,11 @@ def replace_query_param(url, key, val):
...
@@ -108,11 +105,11 @@ def replace_query_param(url, key, val):
Given a URL and a key/val pair, set or replace an item in the query
Given a URL and a key/val pair, set or replace an item in the query
parameters of the URL, and return the new URL.
parameters of the URL, and return the new URL.
"""
"""
(
scheme
,
netloc
,
path
,
query
,
fragment
)
=
urlsplit
(
url
)
(
scheme
,
netloc
,
path
,
query
,
fragment
)
=
url
parse
.
url
split
(
url
)
query_dict
=
QueryDict
(
query
)
.
copy
()
query_dict
=
QueryDict
(
query
)
.
copy
()
query_dict
[
key
]
=
val
query_dict
[
key
]
=
val
query
=
query_dict
.
urlencode
()
query
=
query_dict
.
urlencode
()
return
urlunsplit
((
scheme
,
netloc
,
path
,
query
,
fragment
))
return
url
parse
.
url
unsplit
((
scheme
,
netloc
,
path
,
query
,
fragment
))
# Regex for adding classes to html snippets
# Regex for adding classes to html snippets
...
...
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