aboutsummaryrefslogtreecommitdiffstats
path: root/flywheel/parsers.py
diff options
context:
space:
mode:
Diffstat (limited to 'flywheel/parsers.py')
-rw-r--r--flywheel/parsers.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/flywheel/parsers.py b/flywheel/parsers.py
index 3f0a4e5b..98232a96 100644
--- a/flywheel/parsers.py
+++ b/flywheel/parsers.py
@@ -8,13 +8,21 @@ except ImportError:
# TODO: Make all parsers only list a single media_type, rather than a list
class BaseParser(object):
+ """All parsers should extend BaseParser, specifing a media_type attribute,
+ and overriding the parse() method."""
+
media_type = None
def __init__(self, resource):
+ """Initialise the parser with the Resource instance as state,
+ in case the parser needs to access any metadata on the Resource object."""
self.resource = resource
def parse(self, input):
- return {}
+ """Given some serialized input, return the deserialized output.
+ The input will be the raw request content body. The return value may be of
+ any type, but for many parsers/inputs it might typically be a dict."""
+ return input
class JSONParser(BaseParser):
@@ -26,6 +34,7 @@ class JSONParser(BaseParser):
except ValueError, exc:
raise ResponseException(status.HTTP_400_BAD_REQUEST, {'detail': 'JSON parse error - %s' % str(exc)})
+
class XMLParser(BaseParser):
media_type = 'application/xml'