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
0a5ca000
Commit
0a5ca000
authored
Jan 18, 2012
by
Ben Timby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docstring/whitespace fixes.
parent
5f4096ca
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
51 additions
and
59 deletions
+51
-59
djangorestframework/mixins.py
+4
-4
djangorestframework/parsers.py
+11
-11
djangorestframework/tests/accept.py
+0
-3
djangorestframework/tests/files.py
+0
-4
djangorestframework/tests/models.py
+28
-28
djangorestframework/tests/parsers.py
+0
-1
djangorestframework/utils/__init__.py
+2
-2
djangorestframework/views.py
+6
-6
No files found.
djangorestframework/mixins.py
View file @
0a5ca000
...
@@ -49,12 +49,12 @@ class RequestMixin(object):
...
@@ -49,12 +49,12 @@ class RequestMixin(object):
_CONTENTTYPE_PARAM
=
'_content_type'
_CONTENTTYPE_PARAM
=
'_content_type'
_CONTENT_PARAM
=
'_content'
_CONTENT_PARAM
=
'_content'
parsers
=
()
"""
"""
The set of request parsers that the view can handle.
The set of request parsers that the view can handle.
Should be a tuple/list of classes as described in the :mod:`parsers` module.
Should be a tuple/list of classes as described in the :mod:`parsers` module.
"""
"""
parsers
=
()
@property
@property
def
method
(
self
):
def
method
(
self
):
...
@@ -226,12 +226,12 @@ class ResponseMixin(object):
...
@@ -226,12 +226,12 @@ class ResponseMixin(object):
_ACCEPT_QUERY_PARAM
=
'_accept'
# Allow override of Accept header in URL query params
_ACCEPT_QUERY_PARAM
=
'_accept'
# Allow override of Accept header in URL query params
_IGNORE_IE_ACCEPT_HEADER
=
True
_IGNORE_IE_ACCEPT_HEADER
=
True
renderers
=
()
"""
"""
The set of response renderers that the view can handle.
The set of response renderers that the view can handle.
Should be a tuple/list of classes as described in the :mod:`renderers` module.
Should be a tuple/list of classes as described in the :mod:`renderers` module.
"""
"""
renderers
=
()
# TODO: wrap this behavior around dispatch(), ensuring it works
# TODO: wrap this behavior around dispatch(), ensuring it works
...
@@ -339,19 +339,19 @@ class AuthMixin(object):
...
@@ -339,19 +339,19 @@ class AuthMixin(object):
Simple :class:`mixin` class to add authentication and permission checking to a :class:`View` class.
Simple :class:`mixin` class to add authentication and permission checking to a :class:`View` class.
"""
"""
authentication
=
()
"""
"""
The set of authentication types that this view can handle.
The set of authentication types that this view can handle.
Should be a tuple/list of classes as described in the :mod:`authentication` module.
Should be a tuple/list of classes as described in the :mod:`authentication` module.
"""
"""
authentication
=
()
permissions
=
()
"""
"""
The set of permissions that will be enforced on this view.
The set of permissions that will be enforced on this view.
Should be a tuple/list of classes as described in the :mod:`permissions` module.
Should be a tuple/list of classes as described in the :mod:`permissions` module.
"""
"""
permissions
=
()
@property
@property
...
...
djangorestframework/parsers.py
View file @
0a5ca000
...
@@ -171,8 +171,8 @@ class MultiPartParser(BaseParser):
...
@@ -171,8 +171,8 @@ class MultiPartParser(BaseParser):
raise
ErrorResponse
(
status
.
HTTP_400_BAD_REQUEST
,
raise
ErrorResponse
(
status
.
HTTP_400_BAD_REQUEST
,
{
'detail'
:
'multipart parse error -
%
s'
%
unicode
(
exc
)})
{
'detail'
:
'multipart parse error -
%
s'
%
unicode
(
exc
)})
return
django_parser
.
parse
()
return
django_parser
.
parse
()
class
XMLParser
(
BaseParser
):
class
XMLParser
(
BaseParser
):
"""
"""
XML parser.
XML parser.
...
@@ -183,7 +183,7 @@ class XMLParser(BaseParser):
...
@@ -183,7 +183,7 @@ class XMLParser(BaseParser):
def
parse
(
self
,
stream
):
def
parse
(
self
,
stream
):
"""
"""
Returns a 2-tuple of `(data, files)`.
Returns a 2-tuple of `(data, files)`.
`data` will simply be a string representing the body of the request.
`data` will simply be a string representing the body of the request.
`files` will always be `None`.
`files` will always be `None`.
"""
"""
...
@@ -218,33 +218,33 @@ class XMLParser(BaseParser):
...
@@ -218,33 +218,33 @@ class XMLParser(BaseParser):
"""
"""
Converts the value returned by the XMl parse into the equivalent
Converts the value returned by the XMl parse into the equivalent
Python type
Python type
"""
"""
if
value
is
None
:
if
value
is
None
:
return
value
return
value
try
:
try
:
return
datetime
.
datetime
.
strptime
(
value
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
return
datetime
.
datetime
.
strptime
(
value
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
except
ValueError
:
except
ValueError
:
pass
pass
try
:
try
:
return
int
(
value
)
return
int
(
value
)
except
ValueError
:
except
ValueError
:
pass
pass
try
:
try
:
return
decimal
.
Decimal
(
value
)
return
decimal
.
Decimal
(
value
)
except
decimal
.
InvalidOperation
:
except
decimal
.
InvalidOperation
:
pass
pass
return
value
return
value
DEFAULT_PARSERS
=
(
JSONParser
,
DEFAULT_PARSERS
=
(
JSONParser
,
FormParser
,
FormParser
,
MultiPartParser
,
MultiPartParser
,
XMLParser
XMLParser
)
)
if
YAMLParser
:
if
YAMLParser
:
DEFAULT_PARSERS
+=
(
YAMLParser
,
)
DEFAULT_PARSERS
+=
(
YAMLParser
,
)
djangorestframework/tests/accept.py
View file @
0a5ca000
...
@@ -63,6 +63,3 @@ class UserAgentMungingTest(TestCase):
...
@@ -63,6 +63,3 @@ class UserAgentMungingTest(TestCase):
resp
=
self
.
view
(
req
)
resp
=
self
.
view
(
req
)
self
.
assertEqual
(
resp
[
'Content-Type'
],
'application/json'
)
self
.
assertEqual
(
resp
[
'Content-Type'
],
'application/json'
)
djangorestframework/tests/files.py
View file @
0a5ca000
...
@@ -30,7 +30,3 @@ class UploadFilesTests(TestCase):
...
@@ -30,7 +30,3 @@ class UploadFilesTests(TestCase):
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertEquals
(
response
.
content
,
'{"FILE_CONTENT": "stuff", "FILE_NAME": "stuff.txt"}'
)
self
.
assertEquals
(
response
.
content
,
'{"FILE_CONTENT": "stuff", "FILE_NAME": "stuff.txt"}'
)
djangorestframework/tests/models.py
View file @
0a5ca000
from
django.db
import
models
from
django.db
import
models
from
django.contrib.auth.models
import
Group
from
django.contrib.auth.models
import
Group
class
CustomUser
(
models
.
Model
):
class
CustomUser
(
models
.
Model
):
"""
"""
A custom user model, which uses a 'through' table for the foreign key
A custom user model, which uses a 'through' table for the foreign key
"""
"""
username
=
models
.
CharField
(
max_length
=
255
,
unique
=
True
)
username
=
models
.
CharField
(
max_length
=
255
,
unique
=
True
)
groups
=
models
.
ManyToManyField
(
groups
=
models
.
ManyToManyField
(
to
=
Group
,
blank
=
True
,
null
=
True
,
through
=
'UserGroupMap'
to
=
Group
,
blank
=
True
,
null
=
True
,
through
=
'UserGroupMap'
)
)
@models.permalink
@models.permalink
def
get_absolute_url
(
self
):
def
get_absolute_url
(
self
):
return
(
'custom_user'
,
(),
{
return
(
'custom_user'
,
(),
{
'pk'
:
self
.
id
'pk'
:
self
.
id
})
})
class
UserGroupMap
(
models
.
Model
):
class
UserGroupMap
(
models
.
Model
):
user
=
models
.
ForeignKey
(
to
=
CustomUser
)
user
=
models
.
ForeignKey
(
to
=
CustomUser
)
group
=
models
.
ForeignKey
(
to
=
Group
)
group
=
models
.
ForeignKey
(
to
=
Group
)
@models.permalink
@models.permalink
def
get_absolute_url
(
self
):
def
get_absolute_url
(
self
):
return
(
'user_group_map'
,
(),
{
return
(
'user_group_map'
,
(),
{
'pk'
:
self
.
id
'pk'
:
self
.
id
})
})
djangorestframework/tests/parsers.py
View file @
0a5ca000
...
@@ -172,7 +172,6 @@ class TestXMLParser(TestCase):
...
@@ -172,7 +172,6 @@ class TestXMLParser(TestCase):
'field_b'
:
'dasd'
,
'field_b'
:
'dasd'
,
'field_c'
:
None
,
'field_c'
:
None
,
'field_d'
:
datetime
.
datetime
(
2011
,
12
,
25
,
12
,
45
,
00
)
'field_d'
:
datetime
.
datetime
(
2011
,
12
,
25
,
12
,
45
,
00
)
}
}
self
.
_complex_data_input
=
StringIO
(
self
.
_complex_data_input
=
StringIO
(
'<?xml version="1.0" encoding="utf-8"?>'
'<?xml version="1.0" encoding="utf-8"?>'
...
...
djangorestframework/utils/__init__.py
View file @
0a5ca000
...
@@ -150,10 +150,10 @@ class XMLRenderer():
...
@@ -150,10 +150,10 @@ class XMLRenderer():
xml
.
startElement
(
key
,
{})
xml
.
startElement
(
key
,
{})
self
.
_to_xml
(
xml
,
value
)
self
.
_to_xml
(
xml
,
value
)
xml
.
endElement
(
key
)
xml
.
endElement
(
key
)
elif
data
is
None
:
elif
data
is
None
:
# Don't output any value
# Don't output any value
pass
pass
else
:
else
:
xml
.
characters
(
smart_unicode
(
data
))
xml
.
characters
(
smart_unicode
(
data
))
...
...
djangorestframework/views.py
View file @
0a5ca000
...
@@ -32,32 +32,32 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
...
@@ -32,32 +32,32 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
Performs request deserialization, response serialization, authentication and input validation.
Performs request deserialization, response serialization, authentication and input validation.
"""
"""
resource
=
None
"""
"""
The resource to use when validating requests and filtering responses,
The resource to use when validating requests and filtering responses,
or `None` to use default behaviour.
or `None` to use default behaviour.
"""
"""
resource
=
None
renderers
=
renderers
.
DEFAULT_RENDERERS
"""
"""
List of renderers the resource can serialize the response with, ordered by preference.
List of renderers the resource can serialize the response with, ordered by preference.
"""
"""
renderers
=
renderers
.
DEFAULT_RENDERERS
parsers
=
parsers
.
DEFAULT_PARSERS
"""
"""
List of parsers the resource can parse the request with.
List of parsers the resource can parse the request with.
"""
"""
parsers
=
parsers
.
DEFAULT_PARSERS
authentication
=
(
authentication
.
UserLoggedInAuthentication
,
authentication
.
BasicAuthentication
)
"""
"""
List of all authenticating methods to attempt.
List of all authenticating methods to attempt.
"""
"""
authentication
=
(
authentication
.
UserLoggedInAuthentication
,
authentication
.
BasicAuthentication
)
permissions
=
(
permissions
.
FullAnonAccess
,
)
"""
"""
List of all permissions that must be checked.
List of all permissions that must be checked.
"""
"""
permissions
=
(
permissions
.
FullAnonAccess
,
)
@classmethod
@classmethod
def
as_view
(
cls
,
**
initkwargs
):
def
as_view
(
cls
,
**
initkwargs
):
...
...
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