Documentation update.
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 4018276 · Browse files · 1 file·+63 added−14 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+63 added−14 removed
- other:+63 added−14 removed
Provenance
- Commit
e796aae- Tree
3aa9442- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
4018276
1 file changed+63 added−14 removed
modified:requests/core.py+63 added-14 removed
24 unmodified lines25 AUTOAUTHS = []26 27 28 class _Request(urllib2.Request):29- def __init__(self, url, data=None, headers={},30- origin_req_host=None, unverifiable=False, method=None):31- urllib2.Request.__init__(self, url, data, headers, origin_req_host, unverifiable)32- self.method = method29+ """Hidden wrapper around the urllib2.Request object. Allows for manual30+ setting of HTTP methods.31+ """32+ 33+ def __init__(self, url,34+ data=None, headers={}, origin_req_host=None,35+ unverifiable=False, method=None):36+ urllib2.Request.__init__( self, url, data, headers, origin_req_host,37+ unverifiable)38+ self.method = method39 34- def get_method(self):35- if self.method:36- return self.method40+ def get_method(self):41+ if self.method:42+ return self.method43 38- return urllib2.Request.get_method(self)44+ return urllib2.Request.get_method(self)45 46 47 class Request(object):42- """The :class:`Request` object. It's awesome.48+ """The :class:`Request` object. It carries out all functionality of49+ Requests. Recommended interface is with the Requests functions.50+51+ 52 """53 54 _METHODS = ('GET', 'HEAD', 'PUT', 'POST', 'DELETE')55 42 unmodified lines98 return urllib2.urlopen99 100 101 def send(self, anyway=False):93- """Sends the request. 102+ """Sends the request. Returns True of successfull, false if not.103+ If there was an HTTPError during transmission,104+ self.response.status_code will contain the HTTPError code.105+106+ Once a request is successfully sent, `sent` will equal True.107 95- :param anyway: If True, request will be sent, even if it has already been sent.108+ :param anyway: If True, request will be sent, even if it has109+ already been sent.110 """111 self._checks()112 113 success = False87 unmodified lines201 return success202 203 204 class Response(object):191- """The :class:`Request` object. It's awesome.205+ """The :class:`Request` object. All :class:`Request` objects contain a206+ :class:`Request.response <response>` attribute, which is an instance of207+ this class.208 """209 210 def __init__(self):211 self.content = None1 unmodified line213 self.headers = dict()214 215 216 class AuthObject(object):201- """The :class:`AuthObject` is a simple HTTP Authentication token.217+ """The :class:`AuthObject` is a simple HTTP Authentication token. When218+ given to a Requests function, it enables Basic HTTP Authentication for that219+ Request. You can also enable Authorization for domain realms with AutoAuth.220+ See AutoAuth for more details.s221 222 :param username: Username to authenticate with.223 :param password: Password for given username.205- """224+ """225 226 def __init__(self, username, password):227 self.username = username228 self.password = password1 unmodified line230 231 232 def get(url, params={}, headers={}, auth=None):233 """Sends a GET request. Returns :class:`Response` object.234+235+ :param url: URL for the new :class:`Request` object.236+ :param params: (optional) Dictionary of GET Parameters to send with the :class:`Request`.237+ :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.238+ :param auth: (optional) AuthObject to enable Basic HTTP Auth.239 """240+ 241 r = Request()242 243 r.method = 'GET'244 r.url = url7 unmodified lines252 253 254 def head(url, params={}, headers={}, auth=None):255 """Sends a HEAD request. Returns :class:`Response` object.256+257+ :param url: URL for the new :class:`Request` object.258+ :param params: (optional) Dictionary of GET Parameters to send with the :class:`Request`.259+ :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.260+ :param auth: (optional) AuthObject to enable Basic HTTP Auth.261 """262+ 263 r = Request()264 265 r.method = 'HEAD'266 r.url = url8 unmodified lines275 276 277 def post(url, data={}, headers={}, auth=None):278 """Sends a POST request. Returns :class:`Response` object.279+280+ :param url: URL for the new :class:`Request` object.281+ :param data: (optional) Dictionary of POST Data to send with the :class:`Request`.282+ :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.283+ :param auth: (optional) AuthObject to enable Basic HTTP Auth.284 """285+ 286 r = Request()287 288 r.url = url289 r.method = 'POST'8 unmodified lines298 299 300 def put(url, data='', headers={}, auth=None):301 """Sends a PUT request. Returns :class:`Response` object.302+303+ :param url: URL for the new :class:`Request` object.304+ :param data: (optional) Bytes of PUT Data to send with the :class:`Request`.305+ :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.306+ :param auth: (optional) AuthObject to enable Basic HTTP Auth.307 """308+ 309 r = Request()310 311 r.url = url312 r.method = 'PUT'8 unmodified lines321 322 323 def delete(url, params={}, headers={}, auth=None):324 """Sends a DELETE request. Returns :class:`Response` object.325+326+ :param url: URL for the new :class:`Request` object.327+ :param params: (optional) Dictionary of GET Parameters to send with the :class:`Request`.328+ :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.329+ :param auth: (optional) AuthObject to enable Basic HTTP Auth.330 """331+ 332 r = Request()333 334 r.url = url335 r.method = 'DELETE'39 unmodified lines