From ffa2d2e3d7a6af2a5fa1f5612af6ac95c4b8e987 Mon Sep 17 00:00:00 2001
From: TK Kocheran <rfkrocktk@gmail.com>
Date: Tue, 12 Mar 2013 19:17:45 -0700
Subject: [PATCH] Modified upload handler API to be able to invoke callbacks
when new fields/variables are successfully parsed from
multipart POST request. Fix for #20034.
---
django/core/files/uploadhandler.py | 6 ++++++
django/http/multipartparser.py | 7 +++++++
2 files changed, 13 insertions(+)
diff --git a/django/core/files/uploadhandler.py b/django/core/files/uploadhandler.py
index f5e95cf..080b5d3 100644
a
|
b
|
class FileUploadHandler(object):
|
84 | 84 | """ |
85 | 85 | pass |
86 | 86 | |
| 87 | def variable_complete(self, variable_name, variable_value): |
| 88 | """ |
| 89 | Signal that a new variable has been parsed from the multipart request. |
| 90 | """ |
| 91 | pass |
| 92 | |
87 | 93 | def new_file(self, field_name, file_name, content_type, content_length, charset=None): |
88 | 94 | """ |
89 | 95 | Signal that a new file has been started. |
diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py
index 070874f..dc66cc3 100644
a
|
b
|
class MultiPartParser(object):
|
167 | 167 | |
168 | 168 | self._post.appendlist(field_name, |
169 | 169 | force_text(data, encoding, errors='replace')) |
| 170 | |
| 171 | for handler in handlers: |
| 172 | try : |
| 173 | handler.variable_complete(field_name, force_text(data, encoding, errors='replace')) |
| 174 | except StopFutureHandlers: |
| 175 | break |
| 176 | |
170 | 177 | elif item_type == FILE: |
171 | 178 | # This is a file, use the handler... |
172 | 179 | file_name = disposition.get('filename') |