当前位置: 首页>>代码示例>>Python>>正文


Python multipartparser.MultiPartParserError方法代码示例

本文整理汇总了Python中django.http.multipartparser.MultiPartParserError方法的典型用法代码示例。如果您正苦于以下问题:Python multipartparser.MultiPartParserError方法的具体用法?Python multipartparser.MultiPartParserError怎么用?Python multipartparser.MultiPartParserError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.http.multipartparser的用法示例。


在下文中一共展示了multipartparser.MultiPartParserError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse

# 需要导入模块: from django.http import multipartparser [as 别名]
# 或者: from django.http.multipartparser import MultiPartParserError [as 别名]
def parse(self, stream, media_type=None, parser_context=None):
        """
        Parses the incoming bytestream as a multipart encoded form,
        and returns a DataAndFiles object.

        `.data` will be a `QueryDict` containing all the form parameters.
        `.files` will be a `QueryDict` containing all the form files.
        """
        parser_context = parser_context or {}
        request = parser_context['request']
        encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
        meta = request.META.copy()
        meta['CONTENT_TYPE'] = media_type
        upload_handlers = request.upload_handlers

        try:
            parser = DjangoMultiPartParser(meta, stream, upload_handlers, encoding)
            data, files = parser.parse()
            return DataAndFiles(data, files)
        except MultiPartParserError as exc:
            raise ParseError('Multipart form parse error - %s' % six.text_type(exc)) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:23,代码来源:parsers.py

示例2: _load_post_and_files

# 需要导入模块: from django.http import multipartparser [as 别名]
# 或者: from django.http.multipartparser import MultiPartParserError [as 别名]
def _load_post_and_files(self):
        """Populate self._post and self._files if the content-type is a form type"""
        if self.method != 'POST':
            self._post, self._files = QueryDict('', encoding=self._encoding), MultiValueDict()
            return
        if self._read_started and not hasattr(self, '_body'):
            self._mark_post_parse_error()
            return

        if self.META.get('CONTENT_TYPE', '').startswith('multipart/form-data'):
            if hasattr(self, '_body'):
                # Use already read data
                data = BytesIO(self._body)
            else:
                data = self
            try:
                self._post, self._files = self.parse_file_upload(self.META, data)
            except MultiPartParserError:
                # An error occurred while parsing POST data. Since when
                # formatting the error the request handler might access
                # self.POST, set self._post and self._file to prevent
                # attempts to parse POST data again.
                # Mark that an error occurred. This allows self.__repr__ to
                # be explicit about it instead of simply representing an
                # empty POST
                self._mark_post_parse_error()
                raise
        elif self.META.get('CONTENT_TYPE', '').startswith('application/x-www-form-urlencoded'):
            self._post, self._files = QueryDict(self.body, encoding=self._encoding), MultiValueDict()
        else:
            self._post, self._files = QueryDict('', encoding=self._encoding), MultiValueDict() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:33,代码来源:request.py

示例3: _load_post_and_files

# 需要导入模块: from django.http import multipartparser [as 别名]
# 或者: from django.http.multipartparser import MultiPartParserError [as 别名]
def _load_post_and_files(self):
        """Populate self._post and self._files if the content-type is a form type"""
        if self.method != 'POST':
            self._post, self._files = QueryDict(encoding=self._encoding), MultiValueDict()
            return
        if self._read_started and not hasattr(self, '_body'):
            self._mark_post_parse_error()
            return

        if self.content_type == 'multipart/form-data':
            if hasattr(self, '_body'):
                # Use already read data
                data = BytesIO(self._body)
            else:
                data = self
            try:
                self._post, self._files = self.parse_file_upload(self.META, data)
            except MultiPartParserError:
                # An error occurred while parsing POST data. Since when
                # formatting the error the request handler might access
                # self.POST, set self._post and self._file to prevent
                # attempts to parse POST data again.
                # Mark that an error occurred. This allows self.__repr__ to
                # be explicit about it instead of simply representing an
                # empty POST
                self._mark_post_parse_error()
                raise
        elif self.content_type == 'application/x-www-form-urlencoded':
            self._post, self._files = QueryDict(self.body, encoding=self._encoding), MultiValueDict()
        else:
            self._post, self._files = QueryDict(encoding=self._encoding), MultiValueDict() 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:33,代码来源:request.py

示例4: test_multi_part_parser_error

# 需要导入模块: from django.http import multipartparser [as 别名]
# 或者: from django.http.multipartparser import MultiPartParserError [as 别名]
def test_multi_part_parser_error(self):
        self.assertLogsRequest(
            url='/multi_part_parser_error/',
            level='WARNING',
            status_code=400,
            msg='Bad request (Unable to parse request body): /multi_part_parser_error/',
            exc_class=MultiPartParserError,
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例5: multi_part_parser_error

# 需要导入模块: from django.http import multipartparser [as 别名]
# 或者: from django.http.multipartparser import MultiPartParserError [as 别名]
def multi_part_parser_error(request):
    raise MultiPartParserError('parsing error') 
开发者ID:nesdis,项目名称:djongo,代码行数:4,代码来源:views.py


注:本文中的django.http.multipartparser.MultiPartParserError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。