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
26831df8
Commit
26831df8
authored
Aug 25, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ParseError (Removing ImmediateResponse)
parent
aed26b21
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
14 deletions
+11
-14
djangorestframework/exceptions.py
+3
-0
djangorestframework/parsers.py
+5
-13
djangorestframework/views.py
+3
-1
No files found.
djangorestframework/exceptions.py
0 → 100644
View file @
26831df8
class
ParseError
(
Exception
):
def
__init__
(
self
,
detail
):
self
.
detail
=
detail
djangorestframework/parsers.py
View file @
26831df8
...
@@ -15,9 +15,8 @@ from django.http import QueryDict
...
@@ -15,9 +15,8 @@ from django.http import QueryDict
from
django.http.multipartparser
import
MultiPartParser
as
DjangoMultiPartParser
from
django.http.multipartparser
import
MultiPartParser
as
DjangoMultiPartParser
from
django.http.multipartparser
import
MultiPartParserError
from
django.http.multipartparser
import
MultiPartParserError
from
django.utils
import
simplejson
as
json
from
django.utils
import
simplejson
as
json
from
djangorestframework
import
status
from
djangorestframework.compat
import
yaml
from
djangorestframework.compat
import
yaml
from
djangorestframework.
response
import
ImmediateResponse
from
djangorestframework.
exceptions
import
ParseError
from
djangorestframework.utils.mediatypes
import
media_type_matches
from
djangorestframework.utils.mediatypes
import
media_type_matches
from
xml.etree
import
ElementTree
as
ET
from
xml.etree
import
ElementTree
as
ET
from
djangorestframework.compat
import
ETParseError
from
djangorestframework.compat
import
ETParseError
...
@@ -83,9 +82,7 @@ class JSONParser(BaseParser):
...
@@ -83,9 +82,7 @@ class JSONParser(BaseParser):
try
:
try
:
return
(
json
.
load
(
stream
),
None
)
return
(
json
.
load
(
stream
),
None
)
except
ValueError
,
exc
:
except
ValueError
,
exc
:
raise
ImmediateResponse
(
raise
ParseError
(
'JSON parse error -
%
s'
%
unicode
(
exc
))
{
'detail'
:
'JSON parse error -
%
s'
%
unicode
(
exc
)},
status
=
status
.
HTTP_400_BAD_REQUEST
)
class
YAMLParser
(
BaseParser
):
class
YAMLParser
(
BaseParser
):
...
@@ -105,9 +102,7 @@ class YAMLParser(BaseParser):
...
@@ -105,9 +102,7 @@ class YAMLParser(BaseParser):
try
:
try
:
return
(
yaml
.
safe_load
(
stream
),
None
)
return
(
yaml
.
safe_load
(
stream
),
None
)
except
(
ValueError
,
yaml
.
parser
.
ParserError
),
exc
:
except
(
ValueError
,
yaml
.
parser
.
ParserError
),
exc
:
raise
ImmediateResponse
(
raise
ParseError
(
'YAML parse error -
%
s'
%
unicode
(
exc
))
{
'detail'
:
'YAML parse error -
%
s'
%
unicode
(
exc
)},
status
=
status
.
HTTP_400_BAD_REQUEST
)
class
PlainTextParser
(
BaseParser
):
class
PlainTextParser
(
BaseParser
):
...
@@ -163,9 +158,7 @@ class MultiPartParser(BaseParser):
...
@@ -163,9 +158,7 @@ class MultiPartParser(BaseParser):
parser
=
DjangoMultiPartParser
(
meta
,
stream
,
upload_handlers
)
parser
=
DjangoMultiPartParser
(
meta
,
stream
,
upload_handlers
)
return
parser
.
parse
()
return
parser
.
parse
()
except
MultiPartParserError
,
exc
:
except
MultiPartParserError
,
exc
:
raise
ImmediateResponse
(
raise
ParseError
(
'Multipart form parse error -
%
s'
%
unicode
(
exc
))
{
'detail'
:
'multipart parse error -
%
s'
%
unicode
(
exc
)},
status
=
status
.
HTTP_400_BAD_REQUEST
)
class
XMLParser
(
BaseParser
):
class
XMLParser
(
BaseParser
):
...
@@ -185,8 +178,7 @@ class XMLParser(BaseParser):
...
@@ -185,8 +178,7 @@ class XMLParser(BaseParser):
try
:
try
:
tree
=
ET
.
parse
(
stream
)
tree
=
ET
.
parse
(
stream
)
except
(
ExpatError
,
ETParseError
,
ValueError
),
exc
:
except
(
ExpatError
,
ETParseError
,
ValueError
),
exc
:
content
=
{
'detail'
:
'XML parse error -
%
s'
%
unicode
(
exc
)}
raise
ParseError
(
'XML parse error -
%
s'
%
unicode
(
exc
))
raise
ImmediateResponse
(
content
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
data
=
self
.
_xml_convert
(
tree
.
getroot
())
data
=
self
.
_xml_convert
(
tree
.
getroot
())
return
(
data
,
None
)
return
(
data
,
None
)
...
...
djangorestframework/views.py
View file @
26831df8
...
@@ -13,7 +13,7 @@ from django.views.decorators.csrf import csrf_exempt
...
@@ -13,7 +13,7 @@ from django.views.decorators.csrf import csrf_exempt
from
djangorestframework.compat
import
View
as
DjangoView
,
apply_markdown
from
djangorestframework.compat
import
View
as
DjangoView
,
apply_markdown
from
djangorestframework.response
import
Response
,
ImmediateResponse
from
djangorestframework.response
import
Response
,
ImmediateResponse
from
djangorestframework.request
import
Request
from
djangorestframework.request
import
Request
from
djangorestframework
import
renderers
,
parsers
,
authentication
,
permissions
,
status
from
djangorestframework
import
renderers
,
parsers
,
authentication
,
permissions
,
status
,
exceptions
__all__
=
(
__all__
=
(
...
@@ -249,6 +249,8 @@ class View(DjangoView):
...
@@ -249,6 +249,8 @@ class View(DjangoView):
except
ImmediateResponse
,
exc
:
except
ImmediateResponse
,
exc
:
response
=
exc
.
response
response
=
exc
.
response
except
exceptions
.
ParseError
as
exc
:
response
=
Response
({
'detail'
:
exc
.
detail
},
status
=
status
.
HTTP_400_BAD_REQUEST
)
self
.
response
=
self
.
final
(
request
,
response
,
*
args
,
**
kwargs
)
self
.
response
=
self
.
final
(
request
,
response
,
*
args
,
**
kwargs
)
return
self
.
response
return
self
.
response
...
...
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