Skip to content
Myr

multipart_files support!

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

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 7dd37d5 · Browse files · 1 file+23 added−10 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+23 added−10 removed

  • other:+23 added−10 removed

1 file+23 added−10 removed

modified:requests/core.py+23 added-10 removed
11 unmodified lines
1213import urllib14import urllib21516from poster.encode import multipart_encode17from poster.streaminghttp import register_openers16from .packages.poster.encode import multipart_encode17from .packages.poster.streaminghttp import register_openers181920__title__ = 'requests'21__version__ = '0.2.0'
31 unmodified lines
53 54 def __init__(self):55 self.url = None56 self.headers = dict()57 self.multipart_files = None58 self.method = None59 self.params = {}60 self.data = {}61 self.response = Response()
113 unmodified lines
175176 elif self.method == 'POST':177 if (not self.sent) or anyway:178179 if self.multipart_files:180 register_openers()181 datagen, headers = multipart_encode(self.multipart_files)178 req = _Request(self.url, method='POST')182 req = _Request(self.url, data=datagen, headers=headers, method='POST')183180 if self.headers:184 if self.headers:185 req.headers.update(self.headers)186 187 else:188 req = _Request(self.url, method='POST')189 req.headers = self.headers190191 if isinstance(self.data, dict):192 req.data = urllib.urlencode(self.data)193 else:194 req.data = self.data195 196 # url encode form data if it's a dict184 if isinstance(self.data, dict):185 req.data = urllib.urlencode(self.data)186 else:187 req.data = self.data197198199 try:200201 opener = self._get_opener()202 resp = opener(req)
92 unmodified lines
295 296 return r.response297298289def post(url, data={}, headers={}, multipart_files={}, auth=None):299def post(url, data={}, headers={}, multipart_files=None, auth=None):300 """Sends a POST request. Returns :class:`Response` object.301302 :param url: URL for the new :class:`Request` object.303 :param data: (optional) Dictionary of POST Data to send with the :class:`Request`.
2 unmodified lines
306 :param auth: (optional) AuthObject to enable Basic HTTP Auth.307 """308 309 r = Request()300310 311 r.url = url312 r.method = 'POST'313 r.data = data314 315 if multipart_files:316 r.multipart_files = multipart_files317 318 r.headers = headers319 r.auth = _detect_auth(url, auth)320 321 r.send()
100 unmodified lines