Skip to content
Myr

FIXED

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 71df02d · Browse files · 1 file+25 added−35 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+25 added−35 removed

  • other:+25 added−35 removed

1 file+25 added−35 removed

modified:requests/core.py+25 added-35 removed
93 unmodified lines
94 :param anyway: If True, request will be sent, even if it has already been sent.95 """96 self._checks()97 98 if self.method.lower() in ('get', 'head'):98 if self.method.lower() in ('get', 'head', 'delete'):99 if (not self.sent) or anyway:100 try:101 # url encode GET params if it's a dict102 if isinstance(self.params, dict):
3 unmodified lines
106 params = self.params107108 if self.method.lower() == 'get':109 req = _Request(("%s?%s" % (self.url, params)), method='GET')110 else:110 elif self.method.lower() == 'head':111 req = _Request(("%s?%s" % (self.url, params)), method='HEAD')112 elif self.method.lower() == 'delete':113 req = _Request(("%s?%s" % (self.url, params)), method='DELETE')114115 if self.headers:116 req.headers = self.headers117
6 unmodified lines
124 self.response.content = resp.read()125126 success = True127126 except RequestException:128 except Exception:129 raise RequestException130 131132 elif self.method.lower() == 'put':133 if (not self.sent) or anyway:134135 try:136 try:137134 req = _Request(self.url, method='PUT')135 req.data = self.data136 137# if self.method.lower() == 'head':138# req.get_method = lambda : 'PUT'138 req = _Request(self.url, method='PUT')139140 if self.headers:141 req.headers = self.headers140 if self.headers:141 req.headers = self.headers142143 opener = self._get_opener()144 resp = opener(req)143 req.data = self.data144146 self.response.status_code = resp.code147 self.response.headers = resp.info().dict148 if self.method.lower() == 'get':145 opener = self._get_opener()146 resp = opener(req)147148 self.response.status_code = resp.code149 self.response.headers = resp.info().dict150 self.response.content = resp.read()151151 success = True152 success = True153 except Exception:154 raise RequestException155156 except urllib2.HTTPError:157 self.resonse.status_code = 405158154 except RequestException:155 raise RequestException159 160 elif self.method.lower() == 'post':161 if (not self.sent) or anyway:162 try:163161 req = urllib2.Request(self.url)164 req = _Request(self.url, method='POST')165166 if self.headers:164 r.headers = self.headers167 req.headers = self.headers168169 # url encode form data if it's a dict170 if isinstance(self.data, dict):171 req.data = urllib.urlencode(self.data)172 else:173 req.data = self.data174175173 if self.auth:176 opener = self._get_opener()177 resp = opener(req)178175 # create a password manager176 password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()177178 # Add the username and password.179 # If we knew the realm, we could use it instead of ``None``.180 password_mgr.add_password(None, self.url, self.auth.username, self.auth.password)181 handler = urllib2.HTTPBasicAuthHandler(password_mgr)182 opener = urllib2.build_opener(handler)183184 # use the opener to fetch a URL185 resp = opener.open(req)186 else:187 resp = urllib2.urlopen(req)188179 self.response.status_code = resp.code180 self.response.headers = resp.info().dict181 self.response.content = resp.read()182
159 unmodified lines