Ticket #7651: 7651-fixes.diff
File 7651-fixes.diff, 5.5 KB (added by , 16 years ago) |
---|
-
django/http/multipartparser.py
136 136 # since we cannot be sure a file is complete until 137 137 # we hit the next boundary/part of the multipart content. 138 138 self.handle_file_complete(old_field_name, counters) 139 old_field_name = None 139 140 140 141 try: 141 142 disposition = meta_data['content-disposition'][1] -
django/test/client.py
90 90 """ 91 91 lines = [] 92 92 to_str = lambda s: smart_str(s, settings.DEFAULT_CHARSET) 93 for (key, value) in data.items(): 94 if isinstance(value, file):95 93 94 def encode_file(key, value): 95 lines.extend([ 96 96 '--' + boundary, 97 97 'Content-Disposition: form-data; name="%s"; filename="%s"' \ 98 98 % (to_str(key), to_str(os.path.basename(value.name))), 99 99 'Content-Type: application/octet-stream', 100 100 '', 101 101 value.read() 102 ]) 102 ]) 103 104 for (key, value) in data.items(): 105 if isinstance(value, file): 106 encode_file(key, value) 107 elif not isinstance(value, basestring) and is_iterable(value): 108 for item in value: 109 if isinstance(item, file): 110 encode_file(key, item) 111 else: 112 lines.extend([ 113 '--' + boundary, 114 'Content-Disposition: form-data; name="%s"' % to_str(key), 115 '', 116 to_str(item) 117 ]) 103 118 else: 104 if not isinstance(value, basestring) and is_iterable(value): 105 for item in value: 106 lines.extend([ 107 '--' + boundary, 108 'Content-Disposition: form-data; name="%s"' % to_str(key), 109 '', 110 to_str(item) 111 ]) 112 else: 113 lines.extend([ 119 lines.extend([ 114 120 '--' + boundary, 115 121 'Content-Disposition: form-data; name="%s"' % to_str(key), 116 122 '', 117 123 to_str(value) 118 ])124 ]) 119 125 120 126 lines.extend([ 121 127 '--' + boundary + '--', -
tests/regressiontests/file_uploads/views.py
67 67 """ 68 68 response = file_upload_echo(request) 69 69 request.upload_handlers.insert(0, QuotaUploadHandler()) 70 return response 71 No newline at end of file 70 return response 71 72 def file_upload_getlist_count(request): 73 """ 74 Check the .getlist() function to ensure we receive the correct number of files. 75 """ 76 file_counts = {} 77 78 for key in request.FILES.keys(): 79 file_counts[key] = len(request.FILES.getlist(key)) 80 return HttpResponse(simplejson.dumps(file_counts)) -
tests/regressiontests/file_uploads/tests.py
147 147 def test_broken_custom_upload_handler(self): 148 148 f = tempfile.NamedTemporaryFile() 149 149 f.write('a' * (2 ** 21)) 150 150 151 151 # AttributeError: You cannot alter upload handlers after the upload has been processed. 152 152 self.assertRaises( 153 153 AttributeError, 154 154 self.client.post, 155 '/file_uploads/quota/broken/', 155 '/file_uploads/quota/broken/', 156 156 {'f': open(f.name)} 157 ) 158 159 No newline at end of file 157 ) 158 159 def test_fileupload_getlist(self): 160 file1 = tempfile.NamedTemporaryFile() 161 file1.write('a' * (2 ** 23)) 162 163 file2 = tempfile.NamedTemporaryFile() 164 file2.write('a' * (2 * 2 ** 18)) 165 166 file2a = tempfile.NamedTemporaryFile() 167 file2a.write('a' * (5 * 2 ** 20)) 168 169 response = self.client.post('/file_uploads/getlist_count/', { 170 'file1': open(file1.name), 171 'field1': u'test', 172 'field2': u'test3', 173 'field3': u'test5', 174 'field4': u'test6', 175 'field5': u'test7', 176 'file2': (open(file2.name), open(file2a.name)) 177 }) 178 got = simplejson.loads(response.content) 179 180 self.assert_(got.get('file1', 0) == 1 and got.get('file2', 0) == 2) -
tests/regressiontests/file_uploads/urls.py
7 7 (r'^echo/$', views.file_upload_echo), 8 8 (r'^quota/$', views.file_upload_quota), 9 9 (r'^quota/broken/$', views.file_upload_quota_broken), 10 (r'^getlist_count/$', views.file_upload_getlist_count), 10 11 )