Skip to content
Myr

Merge branch 'develop'

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 · parents 8f20058, b79dea9 · Browse files · 8 files+67 added−32 removed
This commit

State

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

Diff stats

8 files+67 added−32 removed

  • other:+67 added−32 removed

8 files+67 added−32 removed

modified:docs/dev/todo.rst-3 removed
5 unmodified lines
67What Needs to be Done8---------------------910- OAuth Support (`#65 <https://github.com/kennethreitz/requests/issues/65>`_)10- HTTP Cert Checking (`#30 <https://github.com/kennethreitz/requests/issues/30>`_)12- Removal of Poster (`#68 <https://github.com/kennethreitz/requests/issues/68>`_)11- Python 3.x Support (`#70 <https://github.com/kennethreitz/requests/issues/70>`_)12- Kerberos Support (`#47 <https://github.com/kennethreitz/requests/issues/47>`_)15- More Flexible Context Manager (`#69 <https://github.com/kennethreitz/requests/issues/69>`_)
modified:docs/user/advanced.rst+1 added-1 removed
69 unmodified lines
7071Configuring Requests72--------------------7374Sometimes you may want to configure a request to customize it's behavior. To do74Sometimes you may want to configure a request to customize its behavior. To do75this, you can pass in a ``config`` dictionary to a request or session. See the :ref:`Configuration API Docs <configurations>` to learn more.767778Keep-Alive
176 unmodified lines
modified:docs/user/quickstart.rst+13 added-8 removed
37 unmodified lines
3839 >>> r.content40 '[{"repository":{"open_issues":0,"url":"https://github.com/...4142Requests does its best to decode content from the server. Most unicode charsets, ``gzip``, and ``deflate`` encodings are all seamlessly decoded.42Requests does its best to decode content from the server. Most unicode43charsets, ``gzip``, and ``deflate`` encodings are all seamlessly decoded.444546Make a POST Request47-------------------
3 unmodified lines
51 r = requests.post("http://httpbin.org/post")525354Typically, you want to send some form-encoded data — much like an HTML form.54To do this, simply pass a dictionary to the `data` argument. Your dictionary of data will automatically be form-encoded when the request is made::55To do this, simply pass a dictionary to the `data` argument. Your56dictionary of data will automatically be form-encoded when the request is made::5758 >>> payload = {'key1': 'value1', 'key2': 'value2'}59 >>> r = requests.post("http://httpbin.org/post", data=payload)60 >>> print r.content
54 unmodified lines
115 >>> r.content116 {117 "origin": "179.13.100.4",118 "files": {117 "hmm": "<censored...binary...data>"119 "report.xls": "<censored...binary...data>"120 },121 "form": {},122 "url": "http://httpbin.org/post",123 "args": {},
113 unmodified lines
237238 >>> requests.get('https://api.github.com/user', auth=('user', 'pass'))239 <Response [200]>240241OAuth Authentication242--------------------243244Miguel Araujo's `requests-oauth <http://pypi.python.org/pypi/requests-oauth>`_ project provides a simple interface for245establishing OAuth connections. Documentation and examples can be found on the requests-oauth `git repository <https://github.com/maraujop/requests-oauth>`_.246247Digest Authentication248---------------------249250Another popular form of web service protection is Digest Authentication::
9 unmodified lines
260Requests will automatically perform location redirection while using impodotent methods.261262GitHub redirects all HTTP requests to HTTPS. Let's see what happens::263257 >>> r = request.get('http://github.com')264 >>> r = requests.get('http://github.com')265 >>> r.url266 'https://github.com/'267 >>> r.status_code268 200
5 unmodified lines
274275If you're using GET, HEAD, or OPTIONS, you can disable redirection276handling with the ``disable_redirects`` parameter::277271 >>> r = request.get('http://github.com')278 >>> r = requests.get('http://github.com')279 >>> r.status_code280 301281 >>> r.history282 []283284If you're using POST, PUT, PATCH, *&c*, you can also explicitly enable redirection as well::285279 >>> r = request.post('http://github.com')286 >>> r = requests.post('http://github.com', allow_redirects=True)287 >>> r.url288 'https://github.com/'289 >>> r.history290 [<Response [301]>]
13 unmodified lines
304305 ``timeout`` only effects the connection process itself, not the downloading of the respone body.306307301Note302308Errors and Exceptions309---------------------310311In the event of a network problem (e.g. DNS failure, refused connection, etc),
15 unmodified lines
modified:docs/api.rst+3 added-3 removed
93 unmodified lines
9495::9697 >>> requests.codes['temporary_redirect']98 30198 30799100 >>> requests.codes.teapot101 416101 418102103 >>> requests.codes['\o/']104 416104 200105106Cookies107~~~~~~~108
36 unmodified lines
modified:docs/index.rst+1 added-1 removed
28 unmodified lines
29 ...3031See `the same code, without Requests <https://gist.github.com/973705>`_.3233Requests allow you to send **HEAD**, **GET**, **POST**, **PUT**,33Requests allows you to send **HEAD**, **GET**, **POST**, **PUT**,34**PATCH**, and **DELETE** HTTP requests. You can add headers, form data,35multipart files, and parameters with simple Python dictionaries, and access the36response data in the same way. It's powered by :py:class:`httplib` and :py:class:`urllib3`, and it strives to be as elegant and approachable as possible.37
80 unmodified lines
modified:requests/__init__.py+2 added-2 removed
13 unmodified lines
1415"""1617__title__ = 'requests'18__version__ = '0.8.0'19__build__ = 0x00080018__version__ = '0.8.1'19__build__ = 0x00080120__author__ = 'Kenneth Reitz'21__license__ = 'ISC'22__copyright__ = 'Copyright 2011 Kenneth Reitz'23
10 unmodified lines
modified:requests/models.py+41 added-14 removed
9 unmodified lines
10import urllib11import zlib1213from Cookie import SimpleCookie14from urlparse import urlparse, urlunparse, urljoin14from urlparse import urlparse, urlunparse, urljoin, urlsplit15from datetime import datetime1617from .auth import dispatch as auth_dispatch18from .hooks import dispatch_hook
161 unmodified lines
180181 if is_error:182 response.error = resp183184 response.url = self._build_url()184 response.url = self.full_url185186 return response187188
49 unmodified lines
238 auth=self._auth,239 cookies=cookies,240 redirect=True,241 config=self.config,242 timeout=self.timeout,242 _poolmanager=self._poolmanager243 _poolmanager=self._poolmanager,244 proxies = self.proxies,245 )246247 request.send()248 cookies.update(request.response.cookies)
31 unmodified lines
280 return result, urllib.urlencode(result, doseq=True)281 else:282 return data, data283282283 def _build_url(self):284 @property285 def full_url(self):286 """Build the actual URL to use."""287288 if not self.url:289 raise URLRequired()
9 unmodified lines
299 if isinstance(path, unicode):300 path = path.encode('utf-8')301302 path = urllib.quote(urllib.unquote(path))301 self.url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))303304 url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))305306 if self._enc_params:304 if urlparse(self.url).query:305 return '%s&%s' % (self.url, self._enc_params)307 if urlparse(url).query:308 return '%s&%s' % (url, self._enc_params)309 else:307 return '%s?%s' % (self.url, self._enc_params)310 return '%s?%s' % (url, self._enc_params)311 else:309 return self.url312 return url313314 @property315 def path_url(self):316 """Build the path URL to use."""317318 url = []319320 p = urlsplit(self.full_url)321322 # Proxies use full URLs.323 if p.scheme in self.proxies:324 return self.full_url325326 path = p.path327 if not path:328 path = '/'329 url.append(path)330331 query = p.query332 if query:333 url.append('?')334 url.append(query)335336 return ''.join(url)337338339340 def send(self, anyway=False, prefetch=False):341 """Sends the request. Returns True of successful, false if not.342 If there was an HTTPError during transmission,343 self.response.status_code will contain the HTTPError code.
10 unmodified lines
354 datetime.now().isoformat(), self.method, self.url355 ))356357 # Build the URL330 url = self._build_url()358 url = self.full_url359360 # Nottin' on you.361 body = None362 content_type = None
40 unmodified lines
403 _p = urlparse(url)404 proxy = self.proxies.get(_p.scheme)405406 if proxy:379 conn = poolmanager.proxy_from_url(url)407 conn = poolmanager.proxy_from_url(proxy)408 else:409 # Check to see if keep_alive is allowed.410 if self.config.get('keep_alive'):411 conn = self._poolmanager.connection_from_url(url)
19 unmodified lines
431 self.headers['Cookie'] = cookie_header432433 try:434 # Send the request.407435 r = conn.urlopen(436 method=self.method,410 url=url,437 url=self.path_url,438 body=body,439 headers=self.headers,440 redirect=False,441 assert_same_host=False,
177 unmodified lines
modified:HISTORY.rst+6 added
1History2-------340.8.1 (2011-11-15)5++++++++++++++++++67* URL Request path fix8* Proxy fix.9* Timeouts fix.10110.8.0 (2011-11-13)12++++++++++++++++++1314* Keep-alive support!
248 unmodified lines