當前位置: 首頁>>代碼示例>>Python>>正文


Python parsers.FileUploadParser類代碼示例

本文整理匯總了Python中rest_framework.parsers.FileUploadParser的典型用法代碼示例。如果您正苦於以下問題:Python FileUploadParser類的具體用法?Python FileUploadParser怎麽用?Python FileUploadParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FileUploadParser類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_parse

 def test_parse(self):
     """ Make sure the `QueryDict` works OK """
     parser = FileUploadParser()
     self.stream.seek(0)
     data_and_files = parser.parse(self.stream, None, self.parser_context)
     file_obj = data_and_files.files['file']
     self.assertEqual(file_obj._size, 14)
開發者ID:etnperlong,項目名稱:mese2014,代碼行數:7,代碼來源:test_parsers.py

示例2: test_parse

 def test_parse(self):
     """
     Parse raw file upload.
     """
     parser = FileUploadParser()
     self.stream.seek(0)
     data_and_files = parser.parse(self.stream, None, self.parser_context)
     file_obj = data_and_files.files['file']
     assert file_obj._size == 14
開發者ID:YanyanZeng,項目名稱:django-rest-framework,代碼行數:9,代碼來源:test_parsers.py

示例3: test_parse_missing_filename

 def test_parse_missing_filename(self):
     """
     Parse raw file upload when filename is missing.
     """
     parser = FileUploadParser()
     self.stream.seek(0)
     self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = ''
     with self.assertRaises(ParseError):
         parser.parse(self.stream, None, self.parser_context)
開發者ID:99rockets,項目名稱:django-rest-framework,代碼行數:9,代碼來源:test_parsers.py

示例4: test_parse_missing_filename

 def test_parse_missing_filename(self):
     """
     Parse raw file upload when filename is missing.
     """
     parser = FileUploadParser()
     self.stream.seek(0)
     self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = ''
     with pytest.raises(ParseError) as excinfo:
         parser.parse(self.stream, None, self.parser_context)
     assert str(excinfo.value) == 'Missing filename. Request should include a Content-Disposition header with a filename parameter.'
開發者ID:YanyanZeng,項目名稱:django-rest-framework,代碼行數:10,代碼來源:test_parsers.py

示例5: test_get_encoded_filename

    def test_get_encoded_filename(self):
        parser = FileUploadParser()

        self.__replace_content_disposition('inline; filename*=utf-8\'\'ÀĥƦ.txt')
        filename = parser.get_filename(self.stream, None, self.parser_context)
        assert filename == 'ÀĥƦ.txt'

        self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8\'\'ÀĥƦ.txt')
        filename = parser.get_filename(self.stream, None, self.parser_context)
        assert filename == 'ÀĥƦ.txt'

        self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8\'en-us\'ÀĥƦ.txt')
        filename = parser.get_filename(self.stream, None, self.parser_context)
        assert filename == 'ÀĥƦ.txt'
開發者ID:YanyanZeng,項目名稱:django-rest-framework,代碼行數:14,代碼來源:test_parsers.py

示例6: test_parse_missing_filename_large_file

 def test_parse_missing_filename_large_file(self):
     """
     Parse raw file upload when filename is missing with TemporaryFileUploadHandler.
     """
     parser = FileUploadParser()
     self.stream.seek(0)
     self.parser_context["request"].upload_handlers = (TemporaryFileUploadHandler(),)
     self.parser_context["request"].META["HTTP_CONTENT_DISPOSITION"] = ""
     with pytest.raises(ParseError) as excinfo:
         parser.parse(self.stream, None, self.parser_context)
     assert (
         str(excinfo.value)
         == "Missing filename. Request should include a Content-Disposition header with a filename parameter."
     )
開發者ID:bmcool,項目名稱:django-rest-framework,代碼行數:14,代碼來源:test_parsers.py

示例7: test_parse_missing_filename_multiple_upload_handlers

 def test_parse_missing_filename_multiple_upload_handlers(self):
     """
     Parse raw file upload with multiple handlers when filename is missing.
     Regression test for #2109.
     """
     parser = FileUploadParser()
     self.stream.seek(0)
     self.parser_context['request'].upload_handlers = (
         MemoryFileUploadHandler(),
         MemoryFileUploadHandler()
     )
     self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = ''
     with self.assertRaises(ParseError):
         parser.parse(self.stream, None, self.parser_context)
開發者ID:99rockets,項目名稱:django-rest-framework,代碼行數:14,代碼來源:test_parsers.py

示例8: test_parse_missing_filename_multiple_upload_handlers

 def test_parse_missing_filename_multiple_upload_handlers(self):
     """
     Parse raw file upload with multiple handlers when filename is missing.
     Regression test for #2109.
     """
     parser = FileUploadParser()
     self.stream.seek(0)
     self.parser_context['request'].upload_handlers = (
         MemoryFileUploadHandler(),
         MemoryFileUploadHandler()
     )
     self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = ''
     with pytest.raises(ParseError) as excinfo:
         parser.parse(self.stream, None, self.parser_context)
     assert str(excinfo.value) == 'Missing filename. Request should include a Content-Disposition header with a filename parameter.'
開發者ID:YanyanZeng,項目名稱:django-rest-framework,代碼行數:15,代碼來源:test_parsers.py

示例9: test_get_encoded_filename

    def test_get_encoded_filename(self):
        parser = FileUploadParser()

        self.__replace_content_disposition("inline; filename*=utf-8''ÀĥƦ.txt")
        filename = parser.get_filename(self.stream, None, self.parser_context)
        self.assertEqual(filename, "ÀĥƦ.txt")

        self.__replace_content_disposition("inline; filename=fallback.txt; filename*=utf-8''ÀĥƦ.txt")
        filename = parser.get_filename(self.stream, None, self.parser_context)
        self.assertEqual(filename, "ÀĥƦ.txt")

        self.__replace_content_disposition("inline; filename=fallback.txt; filename*=utf-8'en-us'ÀĥƦ.txt")
        filename = parser.get_filename(self.stream, None, self.parser_context)
        self.assertEqual(filename, "ÀĥƦ.txt")

        self.__replace_content_disposition("inline; filename=fallback.txt; filename*=utf-8--ÀĥƦ.txt")
        filename = parser.get_filename(self.stream, None, self.parser_context)
        self.assertEqual(filename, "fallback.txt")
開發者ID:GVRV,項目名稱:django-rest-framework,代碼行數:18,代碼來源:test_parsers.py

示例10: test_get_encoded_filename

    def test_get_encoded_filename(self):
        parser = FileUploadParser()

        self.__replace_content_disposition('inline; filename*=utf-8\'\'ÀĥƦ.txt')
        filename = parser.get_filename(self.stream, None, self.parser_context)
        self.assertEqual(filename, 'ÀĥƦ.txt')

        self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8\'\'ÀĥƦ.txt')
        filename = parser.get_filename(self.stream, None, self.parser_context)
        self.assertEqual(filename, 'ÀĥƦ.txt')

        self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8\'en-us\'ÀĥƦ.txt')
        filename = parser.get_filename(self.stream, None, self.parser_context)
        self.assertEqual(filename, 'ÀĥƦ.txt')

        self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8--ÀĥƦ.txt')
        filename = parser.get_filename(self.stream, None, self.parser_context)
        # Malformed. Either None or 'fallback.txt' will be acceptable.
        # See also https://code.djangoproject.com/ticket/24209
        self.assertIn(filename, ('fallback.txt', None))
開發者ID:awarnys,項目名稱:django-rest-framework,代碼行數:20,代碼來源:test_parsers.py

示例11: test_get_filename

 def test_get_filename(self):
     parser = FileUploadParser()
     filename = parser.get_filename(self.stream, None, self.parser_context)
     self.assertEqual(filename, 'file.txt'.encode('utf-8'))
開發者ID:etnperlong,項目名稱:mese2014,代碼行數:4,代碼來源:test_parsers.py

示例12: test_get_filename

 def test_get_filename(self):
     parser = FileUploadParser()
     filename = parser.get_filename(self.stream, None, self.parser_context)
     self.assertEqual(filename, "file.txt")
開發者ID:9gix,項目名稱:django-rest-framework,代碼行數:4,代碼來源:test_parsers.py

示例13: test_get_filename

 def test_get_filename(self):
     parser = FileUploadParser()
     filename = parser.get_filename(self.stream, None, self.parser_context)
     assert filename == 'file.txt'
開發者ID:YanyanZeng,項目名稱:django-rest-framework,代碼行數:4,代碼來源:test_parsers.py


注:本文中的rest_framework.parsers.FileUploadParser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。