本文整理汇总了Python中django.http.multipartparser.MultiPartParser方法的典型用法代码示例。如果您正苦于以下问题:Python multipartparser.MultiPartParser方法的具体用法?Python multipartparser.MultiPartParser怎么用?Python multipartparser.MultiPartParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.multipartparser
的用法示例。
在下文中一共展示了multipartparser.MultiPartParser方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_file_upload
# 需要导入模块: from django.http import multipartparser [as 别名]
# 或者: from django.http.multipartparser import MultiPartParser [as 别名]
def parse_file_upload(self, META, post_data):
"""Returns a tuple of (POST QueryDict, FILES MultiValueDict)."""
self.upload_handlers = ImmutableList(
self.upload_handlers,
warning="You cannot alter upload handlers after the upload has been processed."
)
parser = MultiPartParser(META, post_data, self.upload_handlers, self.encoding)
return parser.parse()
示例2: parse_file_upload
# 需要导入模块: from django.http import multipartparser [as 别名]
# 或者: from django.http.multipartparser import MultiPartParser [as 别名]
def parse_file_upload(self, META, post_data):
"""Return a tuple of (POST QueryDict, FILES MultiValueDict)."""
self.upload_handlers = ImmutableList(
self.upload_handlers,
warning="You cannot alter upload handlers after the upload has been processed."
)
parser = MultiPartParser(META, post_data, self.upload_handlers, self.encoding)
return parser.parse()
示例3: process_as_post
# 需要导入模块: from django.http import multipartparser [as 别名]
# 或者: from django.http.multipartparser import MultiPartParser [as 别名]
def process_as_post(view_func: ViewFuncT) -> ViewFuncT:
@wraps(view_func)
def _wrapped_view_func(request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse:
# Adapted from django/http/__init__.py.
# So by default Django doesn't populate request.POST for anything besides
# POST requests. We want this dict populated for PATCH/PUT, so we have to
# do it ourselves.
#
# This will not be required in the future, a bug will be filed against
# Django upstream.
if not request.POST:
# Only take action if POST is empty.
if request.META.get('CONTENT_TYPE', '').startswith('multipart'):
# Note that request._files is just the private attribute that backs the
# FILES property, so we are essentially setting request.FILES here. (In
# Django 1.5 FILES was still a read-only property.)
request.POST, request._files = MultiPartParser(
request.META,
BytesIO(request.body),
request.upload_handlers,
request.encoding,
).parse()
else:
request.POST = QueryDict(request.body, encoding=request.encoding)
return view_func(request, *args, **kwargs)
return cast(ViewFuncT, _wrapped_view_func) # https://github.com/python/mypy/issues/1927
示例4: parse_headers_and_body_with_django
# 需要导入模块: from django.http import multipartparser [as 别名]
# 或者: from django.http.multipartparser import MultiPartParser [as 别名]
def parse_headers_and_body_with_django(headers, body):
"""Parse `headers` and `body` with Django's :class:`MultiPartParser`.
`MultiPartParser` is a curiously ugly and RFC non-compliant concoction.
Amongst other things, it coerces all field names, field data, and
filenames into Unicode strings using the "replace" error strategy, so be
warned that your data may be silently mangled.
It also, in 1.3.1 at least, does not recognise any transfer encodings at
*all* because its header parsing code was broken.
I'm also fairly sure that it'll fall over on headers than span more than
one line.
In short, it's a piece of code that inspires little confidence, yet we
must work with it, hence we need to round-trip test multipart handling
with it.
"""
handler = MemoryFileUploadHandler()
meta = {
"CONTENT_TYPE": headers["Content-Type"],
"CONTENT_LENGTH": headers["Content-Length"],
}
parser = MultiPartParser(
META=meta, input_data=BytesIO(body), upload_handlers=[handler]
)
return parser.parse()
示例5: setUp
# 需要导入模块: from django.http import multipartparser [as 别名]
# 或者: from django.http.multipartparser import MultiPartParser [as 别名]
def setUp(self):
super().setUp()
# Django 1.8 and 1.11 need to be configured before we can use
# WSGIRequest and MultiPartParser.
if not django.conf.settings.configured:
django.conf.settings.configure(DEBUG=True)
示例6: parse_headers_and_body_with_django
# 需要导入模块: from django.http import multipartparser [as 别名]
# 或者: from django.http.multipartparser import MultiPartParser [as 别名]
def parse_headers_and_body_with_django(cls, headers, body):
"""Parse `headers` and `body` with Django's :class:`MultiPartParser`.
`MultiPartParser` is a curiously ugly and RFC non-compliant concoction.
Amongst other things, it coerces all field names, field data, and
filenames into Unicode strings using the "replace" error strategy, so
be warned that your data may be silently mangled.
It also, in 1.3.1 at least, does not recognise any transfer encodings
at *all* because its header parsing code was broken.
I'm also fairly sure that it'll fall over on headers than span more
than one line.
In short, it's a piece of code that inspires little confidence, yet we
must work with it, hence we need to round-trip test multipart handling
with it.
"""
handler = MemoryFileUploadHandler()
meta = {
"CONTENT_TYPE": headers["Content-Type"],
"CONTENT_LENGTH": headers["Content-Length"],
# To make things even more entertaining, 1.8 prefixed meta vars
# with "HTTP_" and 1.11 does not.
"HTTP_CONTENT_TYPE": headers["Content-Type"],
"HTTP_CONTENT_LENGTH": headers["Content-Length"],
}
parser = multipartparser.MultiPartParser(
META=meta,
input_data=BytesIO(body.encode("ascii")),
upload_handlers=[handler],
)
return parser.parse()