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
60250f22
Commit
60250f22
authored
Jan 03, 2013
by
Xavier Ordoquy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the various compat things to the compat module.
parent
cf51dcc9
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
43 additions
and
49 deletions
+43
-49
rest_framework/compat.py
+21
-3
rest_framework/fields.py
+2
-5
rest_framework/parsers.py
+1
-2
rest_framework/relations.py
+1
-4
rest_framework/request.py
+0
-1
rest_framework/response.py
+2
-2
rest_framework/serializers.py
+1
-2
rest_framework/settings.py
+3
-3
rest_framework/templatetags/rest_framework.py
+3
-5
rest_framework/tests/files.py
+2
-3
rest_framework/tests/generics.py
+1
-3
rest_framework/tests/htmlrenderer.py
+1
-2
rest_framework/tests/renderers.py
+1
-1
rest_framework/tests/request.py
+1
-2
rest_framework/tests/response.py
+1
-3
rest_framework/utils/__init__.py
+2
-8
No files found.
rest_framework/compat.py
View file @
60250f22
...
...
@@ -4,16 +4,34 @@ versions of django/python, and compatibility wrappers around optional packages.
"""
# flake8: noqa
from
__future__
import
unicode_literals
import
six
import
django
# Try to import six from Django, fallback to six itself (1.3.x)
try
:
from
django.utils
import
six
except
:
import
six
# location of patterns, url, include changes in 1.4 onwards
try
:
from
django.conf.urls
import
patterns
,
url
,
include
except
:
from
django.conf.urls.defaults
import
patterns
,
url
,
include
# Handle django.utils.encoding rename:
# smart_unicode -> smart_text
# force_unicode -> force_text
try
:
from
django.utils.encoding
import
smart_text
except
ImportError
:
from
django.utils.encoding
import
smart_unicode
as
smart_text
try
:
from
django.utils.encoding
import
force_text
except
ImportError
:
from
django.utils.encoding
import
force_unicode
as
force_text
# django-filter is optional
try
:
import
django_filters
...
...
@@ -25,9 +43,9 @@ except:
try
:
import
cStringIO.StringIO
as
StringIO
except
ImportError
:
from
six
import
StringIO
StringIO
=
six
.
StringIO
from
six
import
BytesIO
BytesIO
=
six
.
BytesIO
# urlparse compat import (Required because it changed in python 3.x)
...
...
rest_framework/fields.py
View file @
60250f22
from
__future__
import
unicode_literals
import
six
import
copy
import
datetime
...
...
@@ -14,14 +13,12 @@ from django.conf import settings
from
django
import
forms
from
django.forms
import
widgets
from
django.utils.encoding
import
is_protected_type
try
:
from
django.utils.encoding
import
smart_text
except
ImportError
:
from
django.utils.encoding
import
smart_unicode
as
smart_text
from
django.utils.translation
import
ugettext_lazy
as
_
from
rest_framework.compat
import
parse_date
,
parse_datetime
from
rest_framework.compat
import
timezone
from
rest_framework.compat
import
BytesIO
from
rest_framework.compat
import
six
from
rest_framework.compat
import
smart_text
def
is_simple_callable
(
obj
):
...
...
rest_framework/parsers.py
View file @
60250f22
...
...
@@ -5,14 +5,13 @@ They give us a generic way of being able to handle various media types
on the request, such as form content or json encoded data.
"""
import
six
from
django.http
import
QueryDict
from
django.http.multipartparser
import
MultiPartParser
as
DjangoMultiPartParser
from
django.http.multipartparser
import
MultiPartParserError
from
django.utils
import
simplejson
as
json
from
rest_framework.compat
import
yaml
,
ETParseError
from
rest_framework.exceptions
import
ParseError
from
rest_framework.compat
import
six
from
xml.etree
import
ElementTree
as
ET
from
xml.parsers.expat
import
ExpatError
import
datetime
...
...
rest_framework/relations.py
View file @
60250f22
...
...
@@ -6,13 +6,10 @@ from django.core.urlresolvers import resolve, get_script_prefix
from
django
import
forms
from
django.forms
import
widgets
from
django.forms.models
import
ModelChoiceIterator
try
:
from
django.utils.encoding
import
smart_text
except
ImportError
:
from
django.utils.encoding
import
smart_unicode
as
smart_text
from
rest_framework.fields
import
Field
,
WritableField
from
rest_framework.reverse
import
reverse
from
rest_framework.compat
import
urlparse
from
rest_framework.compat
import
smart_text
##### Relational fields #####
...
...
rest_framework/request.py
View file @
60250f22
...
...
@@ -9,7 +9,6 @@ The wrapped request then offers a richer API, in particular :
- full support of PUT method, including support for file uploads
- form overloading of HTTP method, content type and content
"""
import
six
from
rest_framework.compat
import
BytesIO
from
django.http.multipartparser
import
parse_header
...
...
rest_framework/response.py
View file @
60250f22
import
six
from
django.core.handlers.wsgi
import
STATUS_CODE_TEXT
from
django.template.response
import
SimpleTemplateResponse
from
rest_framework.compat
import
six
class
Response
(
SimpleTemplateResponse
):
"""
...
...
rest_framework/serializers.py
View file @
60250f22
import
six
import
copy
import
datetime
import
types
...
...
@@ -8,6 +6,7 @@ from django.db import models
from
django.forms
import
widgets
from
django.utils.datastructures
import
SortedDict
from
rest_framework.compat
import
get_concrete_model
from
rest_framework.compat
import
six
# Note: We do the following so that users of the framework can use this style:
#
...
...
rest_framework/settings.py
View file @
60250f22
...
...
@@ -19,8 +19,7 @@ back to the defaults.
"""
from
django.conf
import
settings
from
django.utils
import
importlib
from
six
import
string_types
from
rest_framework.compat
import
six
USER_SETTINGS
=
getattr
(
settings
,
'REST_FRAMEWORK'
,
None
)
...
...
@@ -100,7 +99,7 @@ def perform_import(val, setting_name):
If the given setting is a string import notation,
then perform the necessary import or imports.
"""
if
isinstance
(
val
,
string_types
):
if
isinstance
(
val
,
s
ix
.
s
tring_types
):
return
import_from_string
(
val
,
setting_name
)
elif
isinstance
(
val
,
(
list
,
tuple
)):
return
[
import_from_string
(
item
,
setting_name
)
for
item
in
val
]
...
...
@@ -118,6 +117,7 @@ def import_from_string(val, setting_name):
module
=
importlib
.
import_module
(
module_path
)
return
getattr
(
module
,
class_name
)
except
:
raise
msg
=
"Could not import '
%
s' for API setting '
%
s'"
%
(
val
,
setting_name
)
raise
ImportError
(
msg
)
...
...
rest_framework/templatetags/rest_framework.py
View file @
60250f22
from
__future__
import
unicode_literals
,
absolute_import
import
six
from
django
import
template
from
django.core.urlresolvers
import
reverse
from
django.http
import
QueryDict
try
:
from
django.utils.encoding
import
force_text
except
ImportError
:
from
django.utils.encoding
import
force_unicode
as
force_text
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
import
re
import
string
...
...
rest_framework/tests/files.py
View file @
60250f22
from
rest_framework.compat
import
BytesIO
import
datetime
import
six
from
django.test
import
TestCase
from
rest_framework
import
serializers
from
rest_framework.compat
import
BytesIO
from
rest_framework.compat
import
six
class
UploadedFile
(
object
):
...
...
rest_framework/tests/generics.py
View file @
60250f22
from
__future__
import
unicode_literals
import
six
from
django.db
import
models
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
from
django.utils
import
simplejson
as
json
from
rest_framework
import
generics
,
serializers
,
status
from
rest_framework.tests.models
import
BasicModel
,
Comment
,
SlugBasedModel
from
rest_framework.compat
import
six
factory
=
RequestFactory
()
...
...
rest_framework/tests/htmlrenderer.py
View file @
60250f22
import
six
from
django.core.exceptions
import
PermissionDenied
from
django.http
import
Http404
from
django.test
import
TestCase
...
...
@@ -9,6 +7,7 @@ from rest_framework.compat import patterns, url
from
rest_framework.decorators
import
api_view
,
renderer_classes
from
rest_framework.renderers
import
TemplateHTMLRenderer
from
rest_framework.response
import
Response
from
rest_framework.compat
import
six
@api_view
((
'GET'
,))
...
...
rest_framework/tests/renderers.py
View file @
60250f22
import
pickle
import
re
import
six
from
django.core.cache
import
cache
from
django.test
import
TestCase
...
...
@@ -16,6 +15,7 @@ from rest_framework.parsers import YAMLParser, XMLParser
from
rest_framework.settings
import
api_settings
from
rest_framework.compat
import
StringIO
from
rest_framework.compat
import
six
import
datetime
from
decimal
import
Decimal
...
...
rest_framework/tests/request.py
View file @
60250f22
"""
Tests for content parsing, and form-overloaded content parsing.
"""
import
six
from
django.contrib.auth.models
import
User
from
django.contrib.auth
import
authenticate
,
login
,
logout
from
django.contrib.sessions.middleware
import
SessionMiddleware
...
...
@@ -22,6 +20,7 @@ from rest_framework.request import Request
from
rest_framework.response
import
Response
from
rest_framework.settings
import
api_settings
from
rest_framework.views
import
APIView
from
rest_framework.compat
import
six
factory
=
RequestFactory
()
...
...
rest_framework/tests/response.py
View file @
60250f22
import
unittest
import
six
from
django.test
import
TestCase
from
rest_framework.compat
import
patterns
,
url
,
include
from
rest_framework.response
import
Response
...
...
@@ -12,6 +9,7 @@ from rest_framework.renderers import (
BrowsableAPIRenderer
)
from
rest_framework.settings
import
api_settings
from
rest_framework.compat
import
six
class
MockPickleRenderer
(
BaseRenderer
):
...
...
rest_framework/utils/__init__.py
View file @
60250f22
import
six
try
:
from
django.utils.encoding
import
smart_text
except
ImportError
:
from
django.utils.encoding
import
smart_unicode
as
smart_text
from
django.utils.xmlutils
import
SimplerXMLGenerator
from
rest_framework.compat
import
StringIO
from
rest_framework.compat
import
six
from
rest_framework.compat
import
smart_text
import
re
import
xml.etree.ElementTree
as
ET
...
...
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