diff options
| author | Tom Christie | 2011-04-11 11:54:26 +0100 | 
|---|---|---|
| committer | Tom Christie | 2011-04-11 11:54:26 +0100 | 
| commit | d4ed17845650d9a548ff0df362f3469878db2f91 (patch) | |
| tree | 27dd8cab495f01ad17b10c89b8623413ebeecd5d /djangorestframework/parsers.py | |
| parent | 338b5213fa6232dc6115b214495cf13ded6a3a17 (diff) | |
| download | django-rest-framework-d4ed17845650d9a548ff0df362f3469878db2f91.tar.bz2 | |
More tests passing
Diffstat (limited to 'djangorestframework/parsers.py')
| -rw-r--r-- | djangorestframework/parsers.py | 43 | 
1 files changed, 12 insertions, 31 deletions
diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index 1503342c..5b236647 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -27,38 +27,7 @@ except ImportError:  class ParserMixin(object):      parsers = () -    def parse(self, stream, content_type): -        """ -        Parse the request content. - -        May raise a 415 ResponseException (Unsupported Media Type), -        or a 400 ResponseException (Bad Request). -        """ -        parsers = as_tuple(self.parsers) -        parser = None -        for parser_cls in parsers: -            if parser_cls.handles(content_type): -                parser = parser_cls(self) -                break - -        if parser is None: -            raise ResponseException(status.HTTP_415_UNSUPPORTED_MEDIA_TYPE, -                                    {'error': 'Unsupported media type in request \'%s\'.' % -                                     content_type.media_type}) - -        return parser.parse(stream) - -    @property -    def parsed_media_types(self): -        """Return an list of all the media types that this ParserMixin can parse.""" -        return [parser.media_type for parser in self.parsers] -     -    @property -    def default_parser(self): -        """Return the ParerMixin's most prefered emitter. -        (This has no behavioural effect, but is may be used by documenting emitters)"""         -        return self.parsers[0]  class BaseParser(object): @@ -122,6 +91,18 @@ class DataFlatener(object):          return False +class PlainTextParser(BaseParser): +    """ +    Plain text parser. +     +    Simply returns the content of the stream +    """ +    media_type = MediaType('text/plain') + +    def parse(self, stream): +        return stream.read() + +  class FormParser(BaseParser, DataFlatener):      """The default parser for form data.      Return a dict containing a single value for each non-reserved parameter.  | 
