diff options
| author | Tom Christie | 2014-12-02 13:52:46 +0000 | 
|---|---|---|
| committer | Tom Christie | 2014-12-02 13:52:46 +0000 | 
| commit | 0359e9250d34e18aef2db6216f24c130a4f51fce (patch) | |
| tree | 9c78dbb87ec129ec21494a769afa587a76fa8899 /rest_framework/parsers.py | |
| parent | e30e3f6dfc8cdb47c1048bbe497599d250d7bf75 (diff) | |
| download | django-rest-framework-0359e9250d34e18aef2db6216f24c130a4f51fce.tar.bz2 | |
FileUploadParser. Raising StopFutureHandlers removes any handlers not yet run for the active set. Closes #2109.
Diffstat (limited to 'rest_framework/parsers.py')
| -rw-r--r-- | rest_framework/parsers.py | 13 | 
1 files changed, 7 insertions, 6 deletions
| diff --git a/rest_framework/parsers.py b/rest_framework/parsers.py index ccb82f03..d229abec 100644 --- a/rest_framework/parsers.py +++ b/rest_framework/parsers.py @@ -256,23 +256,24 @@ class FileUploadParser(BaseParser):          chunks = ChunkIter(stream, chunk_size)          counters = [0] * len(upload_handlers) -        for handler in upload_handlers: +        for index, handler in enumerate(upload_handlers):              try:                  handler.new_file(None, filename, content_type,                                   content_length, encoding)              except StopFutureHandlers: +                upload_handlers = upload_handlers[:index + 1]                  break          for chunk in chunks: -            for i, handler in enumerate(upload_handlers): +            for index, handler in enumerate(upload_handlers):                  chunk_length = len(chunk) -                chunk = handler.receive_data_chunk(chunk, counters[i]) -                counters[i] += chunk_length +                chunk = handler.receive_data_chunk(chunk, counters[index]) +                counters[index] += chunk_length                  if chunk is None:                      break -        for i, handler in enumerate(upload_handlers): -            file_obj = handler.file_complete(counters[i]) +        for index, handler in enumerate(upload_handlers): +            file_obj = handler.file_complete(counters[index])              if file_obj:                  return DataAndFiles(None, {'file': file_obj})          raise ParseError("FileUpload parse error - " | 
