GeneralApp add
This commit is contained in:
SDE
2023-06-19 17:19:18 +03:00
parent b0ad8e41d2
commit b2bd830b6e
69 changed files with 5337 additions and 16 deletions

View 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))