Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c90c610cd | ||
|
|
1a85e110b8 | ||
|
|
12fa108ede | ||
|
|
9c3ca6e740 | ||
|
|
12ada03548 | ||
|
|
daa4fbf4e2 | ||
|
|
7ce305fa89 | ||
|
|
04cdd0f2e7 | ||
|
|
33ee732082 | ||
|
|
cf36d8c753 | ||
|
|
bd562a7ab3 | ||
|
|
72c8163aee | ||
|
|
2bae57e0a6 | ||
|
|
f7968b6797 | ||
|
|
4cae63a297 | ||
|
|
628325ae90 | ||
|
|
b3e2410f44 | ||
|
|
a02189a8e9 | ||
|
|
d343fda7f0 | ||
|
|
f9bcf7c611 | ||
|
|
23b0535a0d | ||
|
|
32c7cbf1ad | ||
|
|
8fe6f8c618 | ||
|
|
80c55f5767 | ||
|
|
3efd5dbab4 | ||
|
|
eaf1264879 | ||
|
|
f5592ceb48 | ||
|
|
e32840f631 | ||
|
|
4596c02339 | ||
|
|
4fcf14e124 | ||
|
|
797301a63b | ||
|
|
3615cbc9df | ||
|
|
e43b438729 | ||
|
|
8836c4b12a | ||
|
|
3a4f6ba8b3 | ||
|
|
6ac1e02691 | ||
|
|
6140fac6aa | ||
|
|
73ed950e70 | ||
|
|
6ef5094be6 | ||
|
|
077758f713 | ||
|
|
c108c5300f | ||
|
|
84e89429f0 |
5
AUTHORS
5
AUTHORS
@@ -46,4 +46,7 @@ Patches and Suggestions
|
||||
- Josselin Jacquard
|
||||
- Travis N. Vaught
|
||||
- Fredrik Möllerstrand
|
||||
- Daniel Hengeveld
|
||||
- Daniel Hengeveld
|
||||
- Dan Head
|
||||
- Bruno Renié
|
||||
- David Fischer
|
||||
16
HISTORY.rst
16
HISTORY.rst
@@ -1,6 +1,22 @@
|
||||
History
|
||||
-------
|
||||
|
||||
0.7.6 (2011-11-07)
|
||||
++++++++++++++++++
|
||||
|
||||
* Digest authentication bugfix (attach query data to path)
|
||||
|
||||
0.7.5 (2011-11-04)
|
||||
++++++++++++++++++
|
||||
|
||||
* Response.content = None if there was an invalid repsonse.
|
||||
* Redirection auth handling.
|
||||
|
||||
0.7.4 (2011-10-26)
|
||||
++++++++++++++++++
|
||||
|
||||
* Sesion Hooks fix.
|
||||
|
||||
0.7.3 (2011-10-23)
|
||||
++++++++++++++++++
|
||||
|
||||
|
||||
@@ -93,8 +93,10 @@ But, you really shouldn't do that.
|
||||
Contribute
|
||||
----------
|
||||
|
||||
If you'd like to contribute, simply fork `the repository`_, commit your changes to the **develop** branch (or branch off of it), and send a pull request. Make sure you add yourself to AUTHORS_.
|
||||
|
||||
#. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug. There is a Contributor Friendly tag for issues that should be ideal for people who are not very familiar with the codebase yet.
|
||||
#. Fork `the repository`_ on Github to start making your changes to the **develop** branch (or branch off of it).
|
||||
#. Write a test which shows that the bug was fixed or that the feature works as expected.
|
||||
#. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to AUTHORS_.
|
||||
|
||||
.. _`the repository`: http://github.com/kennethreitz/requests
|
||||
.. _AUTHORS: http://github.com/kennethreitz/requests/blob/master/AUTHORS
|
||||
|
||||
7
docs/_themes/kr/layout.html
vendored
7
docs/_themes/kr/layout.html
vendored
@@ -2,18 +2,19 @@
|
||||
{%- block extrahead %}
|
||||
{{ super() }}
|
||||
{% if theme_touch_icon %}
|
||||
<link rel="apple-touch-icon" href="{{ pathto('_static/' ~ theme_touch_icon, 1) }}" />
|
||||
<link rel="apple-touch-icon" href="{{ pathto('_static/' ~ theme_touch_icon, 1) }}" />
|
||||
{% endif %}
|
||||
<link media="only screen and (max-device-width: 480px)" href="{{
|
||||
pathto('_static/small_flask.css', 1) }}" type= "text/css" rel="stylesheet" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">
|
||||
{% endblock %}
|
||||
{%- block relbar2 %}{% endblock %}
|
||||
{%- block footer %}
|
||||
<div class="footer">
|
||||
© Copyright {{ copyright }}.
|
||||
</div>
|
||||
<a href="https://github.com/kennethreitz/requests">
|
||||
<img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" />
|
||||
<a href="https://github.com/kennethreitz/requests" class="github">
|
||||
<img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" class="github"/>
|
||||
</a>
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
13
docs/_themes/kr/static/flasky.css_t
vendored
13
docs/_themes/kr/static/flasky.css_t
vendored
@@ -393,6 +393,11 @@ a:hover tt {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div.document {
|
||||
width: 100%;
|
||||
|
||||
}
|
||||
|
||||
div.documentwrapper {
|
||||
margin-left: 0;
|
||||
margin-top: 0;
|
||||
@@ -415,6 +420,10 @@ a:hover tt {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.footer {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.bodywrapper {
|
||||
margin: 0;
|
||||
}
|
||||
@@ -423,7 +432,9 @@ a:hover tt {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
|
||||
.github {
|
||||
display: none;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
20
docs/_themes/kr/static/small_flask.css
vendored
20
docs/_themes/kr/static/small_flask.css
vendored
@@ -68,3 +68,23 @@ div.body {
|
||||
min-height: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.rtd_doc_footer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.document {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.footer {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.footer {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.github {
|
||||
display: none;
|
||||
}
|
||||
@@ -7,6 +7,8 @@ Modules
|
||||
- `fullerene <https://github.com/bitprophet/fullerene>`_, a Graphite Dashboard.
|
||||
- `urbanairship-python <https://github.com/benjaminws/urbanairship-python>`_, a fork of the Urban Airship API wrapper.
|
||||
- `WhitespaceBot <https://github.com/Gunio/WhitespaceBot/>`_, a project that automatically forks repos, strips trailing whitespace, and sends a pull request.
|
||||
- `python-rexster <https://github.com/CulturePlex/python-rexster>`_, Rexter client that provides a simple interface for graph databases.
|
||||
- `daikon <https://github.com/neogenix/daikon>`_, a CLI for ElasticSearch.
|
||||
|
||||
Articles & Talks
|
||||
================
|
||||
@@ -16,6 +18,7 @@ Articles & Talks
|
||||
- `Issac Kelly's 'Consuming Web APIs' talk <http://issackelly.github.com/Consuming-Web-APIs-with-Python-Talk/slides/slides.html>`_
|
||||
- `Blog post about Requests via Yum <http://arunsag.wordpress.com/2011/08/17/new-package-python-requests-http-for-humans/>`_
|
||||
- `Russian blog post introducing Requests <http://habrahabr.ru/blogs/python/126262/>`_
|
||||
- `French blog post introducing Requests <http://www.nicosphere.net/requests-urllib2-de-python-simplifie-2432/>`_
|
||||
|
||||
|
||||
Integrations
|
||||
|
||||
@@ -39,7 +39,7 @@ all the hard work and crazy hacks for you.
|
||||
Testimonials
|
||||
------------
|
||||
|
||||
`Twitter, Inc <http://twitter.com>`_,
|
||||
`The Washington Post <http://www.washingtonpost.com/>`_, `Twitter, Inc <http://twitter.com>`_,
|
||||
a U.S. Federal Institution,
|
||||
NIH,
|
||||
`Readability <http://readability.com>`_, and
|
||||
|
||||
@@ -164,4 +164,4 @@ Requests supports it!::
|
||||
|
||||
-----------------------
|
||||
|
||||
Ready for more? Check out the advanced_ section.
|
||||
Ready for more? Check out the :ref:`advanced <advanced>` section.
|
||||
|
||||
@@ -15,15 +15,15 @@ requests
|
||||
"""
|
||||
|
||||
__title__ = 'requests'
|
||||
__version__ = '0.7.3'
|
||||
__build__ = 0x000703
|
||||
__version__ = '0.7.6'
|
||||
__build__ = 0x000706
|
||||
__author__ = 'Kenneth Reitz'
|
||||
__license__ = 'ISC'
|
||||
__copyright__ = 'Copyright 2011 Kenneth Reitz'
|
||||
|
||||
|
||||
from . import utils
|
||||
from .models import HTTPError, Request, Response
|
||||
from .models import Request, Response
|
||||
from .api import request, get, head, post, patch, put, delete
|
||||
from .sessions import session
|
||||
from .status_codes import codes
|
||||
|
||||
@@ -29,6 +29,23 @@ def request(method, url,
|
||||
hooks=None,
|
||||
return_response=True,
|
||||
config=None):
|
||||
"""Constructs and sends a :class:`Request <Request>`.
|
||||
Returns :class:`Response <Response>` object.
|
||||
|
||||
:param method: method for the new :class:`Request` object.
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
:param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
|
||||
:param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.
|
||||
:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
|
||||
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
|
||||
:param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.
|
||||
:param auth: (optional) Auth typle to enable Basic/Digest/Custom HTTP Auth.
|
||||
:param timeout: (optional) Float describing the timeout of the request.
|
||||
:param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.
|
||||
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
|
||||
:param return_response: (optional) If False, an un-sent Request object will returned.
|
||||
:param config: (optional) A configuration dictionary.
|
||||
"""
|
||||
|
||||
s = session()
|
||||
return s.request(
|
||||
|
||||
@@ -32,7 +32,10 @@ def patched(f):
|
||||
"""Patches a given API function to not send."""
|
||||
|
||||
def wrapped(*args, **kwargs):
|
||||
return f(*args, return_response=False, **kwargs)
|
||||
|
||||
kwargs['return_response'] = False
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrapped
|
||||
|
||||
|
||||
@@ -67,7 +67,8 @@ def http_digest(r, username, password):
|
||||
|
||||
# XXX not implemented yet
|
||||
entdig = None
|
||||
path = urlparse(r.request.url).path
|
||||
p_parsed = urlparse(r.request.url)
|
||||
path = p_parsed.path + p_parsed.query
|
||||
|
||||
A1 = "%s:%s:%s" % (username, realm, password)
|
||||
A2 = "%s:%s" % (r.request.method, path)
|
||||
|
||||
@@ -26,6 +26,7 @@ defaults = dict()
|
||||
defaults['base_headers'] = {
|
||||
'User-Agent': 'python-requests/%s' % __version__,
|
||||
'Accept-Encoding': ', '.join(('identity', 'deflate', 'compress', 'gzip')),
|
||||
'Accept': '*/*'
|
||||
}
|
||||
|
||||
defaults['proxies'] = {}
|
||||
|
||||
@@ -12,21 +12,22 @@ import urllib2
|
||||
import socket
|
||||
import zlib
|
||||
|
||||
from urllib2 import HTTPError
|
||||
from urlparse import urlparse, urlunparse, urljoin
|
||||
from datetime import datetime
|
||||
|
||||
from .auth import dispatch as auth_dispatch
|
||||
from .hooks import dispatch_hook
|
||||
from .structures import CaseInsensitiveDict
|
||||
from .packages.poster.encode import multipart_encode
|
||||
from .packages.poster.streaminghttp import register_openers, get_handlers
|
||||
from .utils import (dict_from_cookiejar, get_unicode_from_response, stream_decode_response_unicode, decode_gzip, stream_decode_gzip)
|
||||
from .status_codes import codes
|
||||
from .exceptions import Timeout, URLRequired, TooManyRedirects
|
||||
from .monkeys import Request as _Request
|
||||
from .monkeys import HTTPRedirectHandler
|
||||
from .utils import (
|
||||
dict_from_cookiejar, get_unicode_from_response,
|
||||
stream_decode_response_unicode, decode_gzip, stream_decode_gzip)
|
||||
|
||||
from .auth import dispatch as auth_dispatch
|
||||
|
||||
REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)
|
||||
|
||||
@@ -95,6 +96,7 @@ class Request(object):
|
||||
self.response = Response()
|
||||
|
||||
#: Authentication tuple to attach to :class:`Request <Request>`.
|
||||
self._auth = auth
|
||||
self.auth = auth_dispatch(auth)
|
||||
|
||||
#: CookieJar to attach to :class:`Request <Request>`.
|
||||
@@ -236,7 +238,7 @@ class Request(object):
|
||||
method=method,
|
||||
# data=self.data,
|
||||
# params=self.params,
|
||||
auth=self.auth,
|
||||
auth=self._auth,
|
||||
cookies=self.cookies,
|
||||
redirect=True,
|
||||
config=self.config
|
||||
@@ -495,7 +497,11 @@ class Response(object):
|
||||
'already consumed')
|
||||
|
||||
# Read the contents.
|
||||
self._content = self.raw.read()
|
||||
try:
|
||||
self._content = self.raw.read()
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
|
||||
# Decode GZip'd content.
|
||||
if 'gzip' in self.headers.get('content-encoding', ''):
|
||||
|
||||
@@ -51,7 +51,9 @@ def merge_kwargs(local_kwarg, default_kwarg):
|
||||
class Session(object):
|
||||
"""A Requests session."""
|
||||
|
||||
__attrs__ = ['headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks', 'params', 'config']
|
||||
__attrs__ = [
|
||||
'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',
|
||||
'params', 'config']
|
||||
|
||||
|
||||
def __init__(self,
|
||||
@@ -62,7 +64,8 @@ class Session(object):
|
||||
proxies=None,
|
||||
hooks=None,
|
||||
params=None,
|
||||
config=None):
|
||||
config=None,
|
||||
keep_alive=True):
|
||||
|
||||
self.headers = headers or {}
|
||||
self.cookies = cookies or {}
|
||||
@@ -72,6 +75,7 @@ class Session(object):
|
||||
self.hooks = hooks or {}
|
||||
self.params = params or {}
|
||||
self.config = config or {}
|
||||
self.keep_alive = keep_alive
|
||||
|
||||
for (k, v) in defaults.items():
|
||||
self.config.setdefault(k, v)
|
||||
@@ -157,8 +161,9 @@ class Session(object):
|
||||
|
||||
args[attr] = merge_kwargs(local_val, session_val)
|
||||
|
||||
|
||||
# Arguments manipulation hook.
|
||||
args = dispatch_hook('args', hooks, args)
|
||||
args = dispatch_hook('args', args['hooks'], args)
|
||||
|
||||
r = Request(**args)
|
||||
|
||||
@@ -169,7 +174,6 @@ class Session(object):
|
||||
# Send the HTTP Request.
|
||||
r.send()
|
||||
|
||||
|
||||
return r.response
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import unittest
|
||||
|
||||
import requests
|
||||
import envoy
|
||||
from urllib2 import HTTPError
|
||||
|
||||
try:
|
||||
import omnijson as json
|
||||
@@ -239,7 +240,7 @@ class RequestsTestSuite(unittest.TestCase):
|
||||
|
||||
def test_status_raising(self):
|
||||
r = requests.get(httpbin('status', '404'))
|
||||
self.assertRaises(requests.HTTPError, r.raise_for_status)
|
||||
self.assertRaises(HTTPError, r.raise_for_status)
|
||||
|
||||
r = requests.get(httpbin('status', '200'))
|
||||
self.assertFalse(r.error)
|
||||
@@ -528,6 +529,11 @@ class RequestsTestSuite(unittest.TestCase):
|
||||
assert params3['b'] in r3.content
|
||||
assert params3['c'] in r3.content
|
||||
|
||||
def test_invalid_content(self):
|
||||
|
||||
r = requests.get('http://somedomainthatclearlydoesntexistg.com')
|
||||
assert r.content == None
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user