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
44b56ed0
Commit
44b56ed0
authored
Feb 22, 2012
by
Can Yavuz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
let the XML parser fail gracefully on malformed XML
parent
66eabe8b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
+12
-0
djangorestframework/compat.py
+6
-0
djangorestframework/parsers.py
+6
-0
No files found.
djangorestframework/compat.py
View file @
44b56ed0
...
@@ -465,3 +465,9 @@ except:
...
@@ -465,3 +465,9 @@ except:
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.utils.functional
import
lazy
from
django.utils.functional
import
lazy
reverse_lazy
=
lazy
(
reverse
,
str
)
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 @
44b56ed0
...
@@ -20,6 +20,8 @@ from djangorestframework.compat import yaml
...
@@ -20,6 +20,8 @@ from djangorestframework.compat import yaml
from
djangorestframework.response
import
ErrorResponse
from
djangorestframework.response
import
ErrorResponse
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
xml.parsers.expat
import
ExpatError
import
datetime
import
datetime
import
decimal
import
decimal
...
@@ -185,7 +187,11 @@ class XMLParser(BaseParser):
...
@@ -185,7 +187,11 @@ class XMLParser(BaseParser):
`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`.
"""
"""
try
:
tree
=
ET
.
parse
(
stream
)
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
())
data
=
self
.
_xml_convert
(
tree
.
getroot
())
return
(
data
,
None
)
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