MCPcopy
hub / github.com/django/django / _parse

Method _parse

django/http/multipartparser.py:133–371  ·  view source on GitHub ↗

Parse the POST data and break it into a FILES MultiValueDict and a POST MultiValueDict. Return a tuple containing the POST and FILES dictionary, respectively.

(self)

Source from the content-addressed store, hash-verified

131 raise
132
133 def _parse(self):
134 """
135 Parse the POST data and break it into a FILES MultiValueDict and a POST
136 MultiValueDict.
137
138 Return a tuple containing the POST and FILES dictionary, respectively.
139 """
140 from django.http import QueryDict
141
142 encoding = self._encoding
143 handlers = self._upload_handlers
144
145 # HTTP spec says that Content-Length >= 0 is valid
146 # handling content-length == 0 before continuing
147 if self._content_length == 0:
148 return QueryDict(encoding=self._encoding), MultiValueDict()
149
150 # See if any of the handlers take care of the parsing.
151 # This allows overriding everything if need be.
152 for handler in handlers:
153 result = handler.handle_raw_input(
154 self._input_data,
155 self._meta,
156 self._content_length,
157 self._boundary,
158 encoding,
159 )
160 # Check to see if it was handled
161 if result is not None:
162 return result[0], result[1]
163
164 # Create the data structures to be used later.
165 self._post = QueryDict(mutable=True)
166 self._files = MultiValueDict()
167
168 # Instantiate the parser and stream:
169 stream = LazyStream(ChunkIter(self._input_data, self._chunk_size))
170
171 # Whether or not to signal a file-completion at the beginning of the
172 # loop.
173 old_field_name = None
174 counters = [0] * len(handlers)
175
176 # Number of bytes that have been read.
177 num_bytes_read = 0
178 # To count the number of keys in the request.
179 num_post_keys = 0
180 # To count the number of files in the request.
181 num_files = 0
182 # To limit the amount of data read from the request.
183 read_size = None
184 # Whether a file upload is finished.
185 uploaded_file = True
186
187 try:
188 for item_type, meta_data, field_stream in Parser(stream, self._boundary):
189 if old_field_name:
190 # We run this at the beginning of the next loop

Callers 1

parseMethod · 0.95

Calls 15

handle_file_completeMethod · 0.95
sanitize_file_nameMethod · 0.95
_close_filesMethod · 0.95
QueryDictClass · 0.90
MultiValueDictClass · 0.90
TooManyFieldsSentClass · 0.90
force_strFunction · 0.90
RequestDataTooBigClass · 0.90
TooManyFilesSentClass · 0.90
LazyStreamClass · 0.85
ChunkIterClass · 0.85

Tested by

no test coverage detected