0.0.1 init, main page prepare
This commit is contained in:
22
BaseModels/api/base_api_parsers.py
Normal file
22
BaseModels/api/base_api_parsers.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import codecs
|
||||
|
||||
from django.conf import settings
|
||||
from rest_framework.exceptions import ParseError
|
||||
from rest_framework.parsers import BaseParser
|
||||
|
||||
class PlainTextParser(BaseParser):
|
||||
media_type = "text/plain"
|
||||
|
||||
def parse(self, stream, media_type=None, parser_context=None):
|
||||
"""
|
||||
Parses the incoming bytestream as Plain Text and returns the resulting data.
|
||||
"""
|
||||
parser_context = parser_context or {}
|
||||
encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
|
||||
|
||||
try:
|
||||
decoded_stream = codecs.getreader(encoding)(stream)
|
||||
text_content = decoded_stream.read()
|
||||
return text_content
|
||||
except ValueError as exc:
|
||||
raise ParseError('Plain text parse error - %s' % str(exc))
|
||||
Reference in New Issue
Block a user