From a74568d8d5bc3cc47679261467485f944833cb93 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 22 Oct 2011 21:10:24 -0400 Subject: [PATCH] simplify request dispatch flow --- requests/models.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/requests/models.py b/requests/models.py index 65c047c5..a6a2c01e 100644 --- a/requests/models.py +++ b/requests/models.py @@ -331,24 +331,27 @@ class Request(object): datetime.now().isoformat(), self.method, self.url )) - # Build the URL url = self._build_url() - + # Attach uploaded files. if self.files: register_openers() + # Add form-data to the multipart. if self.data: self.files.update(self.data) - datagen, headers = multipart_encode(self.files) - req = _Request(url, data=datagen, headers=headers, method=self.method) + data, headers = multipart_encode(self.files) else: - req = _Request(url, data=self._enc_data, method=self.method) + data = self._enc_data + headers = {} + # Build the Urllib2 Request. + req = _Request(url, data=data, headers=headers, method=self.method) + # Add the headers to the request. if self.headers: for k,v in self.headers.iteritems(): req.add_header(k, v)