From: Kenneth Reitz Date: Fri, 25 Feb 2011 13:00:11 +0000 (-0500) Subject: allow files to be upload along with form data X-Git-Tag: v0.3.0^2~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b252cd84037053bd7675d1ff41c102ce237cd0ae;p=services%2Fpython-requests.git allow files to be upload along with form data --- diff --git a/requests/core.py b/requests/core.py index 13dc5c4..b426a4e 100644 --- a/requests/core.py +++ b/requests/core.py @@ -68,12 +68,13 @@ class Request(object): self.headers = headers self.files = files self.method = method + self.data = data # url encode data if it's a dict if hasattr(data, 'items'): - self.data = urllib.urlencode(data) + self._enc_data = urllib.urlencode(data) else: - self.data = data + self._enc_data = data self.response = Response() @@ -161,18 +162,20 @@ class Request(object): success = False if self.method in ('GET', 'HEAD', 'DELETE'): - req = _Request(self._build_url(self.url, self.data), method=self.method) + req = _Request(self._build_url(self.url, self._enc_data), method=self.method) else: + if self.files: register_openers() -# self.files + + if self.data: + self.files.update(self.data) + datagen, headers = multipart_encode(self.files) req = _Request(self.url, data=datagen, headers=headers, method=self.method) + else: - req = _Request(self.url, method=self.method) - - if self.data: - req.data = self.data + req = _Request(self.url, data=self._enc_data, method=self.method) if self.headers: req.headers = self.headers