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
bc519cae
Commit
bc519cae
authored
Feb 22, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #176 from tschan/master
Add exception handling to the XML parser
parents
66eabe8b
44b56ed0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletions
+13
-1
djangorestframework/compat.py
+6
-0
djangorestframework/parsers.py
+7
-1
No files found.
djangorestframework/compat.py
View file @
bc519cae
...
...
@@ -465,3 +465,9 @@ except:
from
django.core.urlresolvers
import
reverse
from
django.utils.functional
import
lazy
reverse_lazy
=
lazy
(
reverse
,
str
)
# xml.etree.parse only throws ParseError for python >= 2.7
try
:
from
xml.etree
import
ParseError
as
ETParseError
except
ImportError
:
# python < 2.7
ETParseError
=
None
djangorestframework/parsers.py
View file @
bc519cae
...
...
@@ -20,6 +20,8 @@ from djangorestframework.compat import yaml
from
djangorestframework.response
import
ErrorResponse
from
djangorestframework.utils.mediatypes
import
media_type_matches
from
xml.etree
import
ElementTree
as
ET
from
djangorestframework.compat
import
ETParseError
from
xml.parsers.expat
import
ExpatError
import
datetime
import
decimal
...
...
@@ -185,7 +187,11 @@ class XMLParser(BaseParser):
`data` will simply be a string representing the body of the request.
`files` will always be `None`.
"""
tree
=
ET
.
parse
(
stream
)
try
:
tree
=
ET
.
parse
(
stream
)
except
(
ExpatError
,
ETParseError
,
ValueError
),
exc
:
content
=
{
'detail'
:
'XML parse error -
%
s'
%
unicode
(
exc
)}
raise
ErrorResponse
(
status
.
HTTP_400_BAD_REQUEST
,
content
)
data
=
self
.
_xml_convert
(
tree
.
getroot
())
return
(
data
,
None
)
...
...
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