Skip to content
Myr

all caps only for request methods

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 7de5726 · Browse files · 1 file+6 added−24 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+6 added−24 removed

  • other:+6 added−24 removed

1 file+6 added−24 removed

modified:requests/core.py+6 added-24 removed
42 unmodified lines
43class Request(object):44 """The :class:`Request` object. It's awesome.45 """46 47 _METHODS = ('get', 'head', 'put', 'post', 'delete')47 _METHODS = ('GET', 'HEAD', 'PUT', 'POST', 'DELETE')48 49 def __init__(self):50 self.url = None51 self.headers = dict()
6 unmodified lines
58 59 60 def __setattr__(self, name, value):61 if (name == 'method') and (value):62 if not value.lower() in self._METHODS:62 if not value in self._METHODS:63 raise InvalidMethod()64 65 object.__setattr__(self, name, value)66
27 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', 'delete'):98 if self.method 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):
1 unmodified line
104 else:105106 params = self.params107108 if self.method.lower() == 'get':109 req = _Request(("%s?%s" % (self.url, params)), method='GET')108 req = _Request(("%s?%s" % (self.url, params)), method=self.method)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')109110 if self.headers:111 req.headers = self.headers112
10 unmodified lines
123 except RequestException:124 raise RequestException125 126132 elif self.method.lower() == 'put':127 elif self.method == 'PUT':128 if (not self.sent) or anyway:129130 try:131 try:
21 unmodified lines
153 raise RequestException154155156 162 elif self.method.lower() == 'post':157 elif self.method == 'POST':158 if (not self.sent) or anyway:159 try:160161 req = _Request(self.url, method='POST')
19 unmodified lines
181182 except Exception:183 raise RequestException184190 elif self.method.lower() == 'delete':191 if (not self.sent) or anyway:192 try:193 pass194 195 success = True196197 except Exception:198 raise RequestException199 200 else:201 raise InvalidMethod202185 186 self.sent = True if success else False187 188 return success
138 unmodified lines