本文整理匯總了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()