diff options
| author | tom christie tom@tomchristie.com | 2011-01-26 08:58:09 +0000 |
|---|---|---|
| committer | tom christie tom@tomchristie.com | 2011-01-26 08:58:09 +0000 |
| commit | 6807cf014cb0fde611f63c64bc352038206176cc (patch) | |
| tree | b5ebd4414852bf39efdf5380c57875c91e798ee2 /flywheel/parsers.py | |
| parent | eff54c00d514e1edd74fbc789f9064d09db40b02 (diff) | |
| download | django-rest-framework-6807cf014cb0fde611f63c64bc352038206176cc.tar.bz2 | |
Added pygments_api example
Diffstat (limited to 'flywheel/parsers.py')
| -rw-r--r-- | flywheel/parsers.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/flywheel/parsers.py b/flywheel/parsers.py index f0684612..57218cc6 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_types = () 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_types = ('application/xml',) |
