Skip to content
Myr

Much nicer helper functions and constructors

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 efedbd9 · Browse files · 1 file+16 added−63 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+16 added−63 removed

  • other:+16 added−63 removed

1 file+16 added−63 removed

modified:requests/core.py+16 added-63 removed
7 unmodified lines
89 :copyright: (c) 2011 by Kenneth Reitz.10 :license: ISC, see LICENSE for more details.11"""1213from __future__ import absolute_import14import urllib15import urllib2161617from urllib2 import HTTPError1819try:20 import eventlet
7 unmodified lines
28 monkey.patch_all()29 except ImportError:30 pass313232from .packages.poster.encode import multipart_encode33from .packages.poster.streaminghttp import register_openers3435
7 unmodified lines
4344AUTOAUTHS = []45464748class _Request(urllib2.Request):49 """Hidden wrapper around the urllib2.Request object. Allows for manual50 setting of HTTP methods.51 """
15 unmodified lines
67 """68 69 _METHODS = ('GET', 'HEAD', 'PUT', 'POST', 'DELETE')70 71 def __init__(self):72 self.url = None73 self.headers = dict()74 self.files = None75 self.method = None76 self.params = {}77 self.data = {}71 def __init__(self, url=None, headers=dict(), files=None, method=None, params=dict(), data=dict(), auth=None, cookiejar=None):72 self.url = url73 self.headers = headers74 self.files = files75 self.method = method76 self.params = params77 self.data = data78 self.response = Response()79 80 self.auth = None81 self.cookiejar = None80 self.auth = auth81 self.cookiejar = cookiejar82 self.sent = False83 84 85 def __repr__(self):
216 unmodified lines
302 :param cookies: (optional) CookieJar object to send with the :class:`Request`.303 :param auth: (optional) AuthObject to enable Basic HTTP Auth.304 """305 306 r = Request()307 308 r.method = 'GET'309 r.url = url310 r.params = params311 r.headers = headers312 r.cookiejar = cookies313 r.auth = _detect_auth(url, auth)314 306 r = Request(method='GET', url=url, params=params, headers=headers, cookiejar=cookies, auth=_detect_auth(url, auth))307 r.send()308 309 return r.response310
6 unmodified lines
317 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.318 :param cookies: (optional) CookieJar object to send with the :class:`Request`.319 :param auth: (optional) AuthObject to enable Basic HTTP Auth.320 """329 330 r = Request()331 332 r.method = 'HEAD'333 r.url = url334 # return response object335 r.params = params336 r.headers = headers337 r.cookiejar = cookies338 r.auth = _detect_auth(url, auth)339 321 r = Request(method='HEAD', url=url, params=params, headers=headers, cookiejar=cookies, auth=_detect_auth(url, auth))322 r.send()323 324 return r.response325
8 unmodified lines
334 :param cookies: (optional) CookieJar object to send with the :class:`Request`.335 :param auth: (optional) AuthObject to enable Basic HTTP Auth.336 """337 356 r = Request()357 358 r.url = url359 r.method = 'POST'360 r.data = data361 362 if files:363 r.files = files364 365 r.headers = headers366 r.cookiejar = cookies367 r.auth = _detect_auth(url, auth)368 338 r = Request(method='POST', url=url, data=data, headers=headers, files=files, cookiejar=cookies, auth=_detect_auth(url, auth))339 r.send()340 341 return r.response342
7 unmodified lines
350 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.351 :param cookies: (optional) CookieJar object to send with the :class:`Request`.352 :param auth: (optional) AuthObject to enable Basic HTTP Auth.353 """384 385 r = Request()354387 r.url = url388 r.method = 'PUT'389 r.data = data390 r.files = files391 r.headers = headers392 r.cookiejar = cookies393 r.auth = _detect_auth(url, auth)394 355 r = Request(method='PUT', url=url, data=data, headers=headers, files=files, cookiejar=cookies, auth=_detect_auth(url, auth)) 356 r.send()357 358 return r.response359
7 unmodified lines
367 :param cookies: (optional) CookieJar object to send with the :class:`Request`.368 :param auth: (optional) AuthObject to enable Basic HTTP Auth.369 """370 410 r = Request()411412 r.url = url413 r.method = 'DELETE'414 415 r.headers = headers416 r.cookiejar = cookies417 r.auth = _detect_auth(url, auth)418 371 r = Request(method='DELETE', url=url, params=params, headers=headers, cookiejar=cookies, auth=_detect_auth(url, auth))372 r.send()373 374 return r.response375
51 unmodified lines