aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/parsers.py
diff options
context:
space:
mode:
authormarkotibold2011-06-26 01:34:52 +0200
committermarkotibold2011-06-26 01:34:52 +0200
commit7f536c1db3950bff2486fd243748f833565c9155 (patch)
treeb92dda970166130d1009a6fe8d77dbf34b171fce /djangorestframework/parsers.py
parent0b18b58c170aae0c2a93a608997e557fdcefe826 (diff)
downloaddjango-rest-framework-7f536c1db3950bff2486fd243748f833565c9155.tar.bz2
Very basic YAML support. Probably needs some tweaking, and definitely needs tests.
Diffstat (limited to 'djangorestframework/parsers.py')
-rw-r--r--djangorestframework/parsers.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py
index 3346a26e..a25ca89e 100644
--- a/djangorestframework/parsers.py
+++ b/djangorestframework/parsers.py
@@ -18,12 +18,15 @@ from djangorestframework import status
from djangorestframework.response import ErrorResponse
from djangorestframework.utils.mediatypes import media_type_matches
+import yaml
+
__all__ = (
'BaseParser',
'JSONParser',
'PlainTextParser',
'FormParser',
'MultiPartParser',
+ 'YAMLParser',
)
@@ -84,6 +87,26 @@ class JSONParser(BaseParser):
{'detail': 'JSON parse error - %s' % unicode(exc)})
+class YAMLParser(BaseParser):
+ """
+ Parses YAML-serialized data.
+ """
+
+ media_type = 'application/yaml'
+
+ def parse(self, stream):
+ """
+ Returns a 2-tuple of `(data, files)`.
+
+ `data` will be an object which is the parsed content of the response.
+ `files` will always be `None`.
+ """
+ try:
+ return (yaml.safe_load(stream), None)
+ except ValueError, exc:
+ raise ErrorResponse(status.HTTP_400_BAD_REQUEST,
+ {'detail': 'YAML parse error - %s' % unicode(exc)})
+
class PlainTextParser(BaseParser):
"""