Skip to content
Myr

Encode Multipart Post data at Request creation

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This fixes #298 (File upload not working with HTTP digest authentication)

authored by Pierre Chapuis · committed by Pierre Chapuis · parent c3e6c41 · Browse files · 1 file+27 added−22 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+27 added−22 removed

  • other:+27 added−22 removed

1 file+27 added−22 removed

modified:requests/models.py+27 added-22 removed
78 unmodified lines
79 #: Dictionary of HTTP Headers to attach to the :class:`Request <Request>`.80 self.headers = dict(headers or [])8182 #: Dictionary of files to multipart upload (``{filename: content}``).83 self.files = files83 self.files = None8485 #: HTTP Method to use.86 self.method = method87
25 unmodified lines
113 self.proxies['https'] = os.environ['HTTPS_PROXY']114115 self.data, self._enc_data = self._encode_params(data)116 self.params, self._enc_params = self._encode_params(params)117 self.files, self._enc_files = self._encode_files(files)118119 #: :class:`Response <Response>` instance, containing120 #: content and metadata of HTTP Response, once :attr:`sent <send>`.121 self.response = Response()
207 unmodified lines
329 return result, urlencode(result, doseq=True)330 else:331 return data, data332333 def _encode_files(self,files):334335 if (not files) or isinstance(self.data, str):336 return None, None337338 try:339 fields = self.data.copy()340 except AttributeError:341 fields = dict(self.data)342343 for (k, v) in list(files.items()):344 # support for explicit filename345 if isinstance(v, (tuple, list)):346 fn, fp = v347 else:348 fn = guess_filename(v) or k349 fp = v350 fields.update({k: (fn, fp.read())})351352 (body, content_type) = encode_multipart_formdata(fields)353354 return files, (body, content_type)355356 @property357 def full_url(self):358 """Build the actual URL to use."""359
110 unmodified lines
470 content_type = None471472 # Multi-part file uploads.473 if self.files:450 if not isinstance(self.data, str):451452 try:453 fields = self.data.copy()454 except AttributeError:455 fields = dict(self.data)456457 for (k, v) in list(self.files.items()):458 # support for explicit filename459 if isinstance(v, (tuple, list)):460 fn, fp = v461 else:462 fn = guess_filename(v) or k463 fp = v464 fields.update({k: (fn, fp.read())})465466 (body, content_type) = encode_multipart_formdata(fields)467 else:468 pass469 # TODO: Conflict?474 (body, content_type) = self._enc_files475 else:476 if self.data:477478 body = self._enc_data
288 unmodified lines
767768 except AttributeError:769 self._content = None770766 self._content_consumed = True 771 self._content_consumed = True772 return self._content773774 def _detected_encoding(self):775 try:
59 unmodified lines