diff --git a/HISTORY.rst b/HISTORY.rst index 05ba2f49..8eecf875 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,12 @@ History ------- +0.8.1 (2011-11-15) +++++++++++++++++++ + +* URL Request path fix +* Proxy fix. +* Timeouts fix. 0.8.0 (2011-11-13) ++++++++++++++++++ diff --git a/docs/api.rst b/docs/api.rst index f77fc0ad..499ffd3c 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -95,13 +95,13 @@ Status Code Lookup :: >>> requests.codes['temporary_redirect'] - 301 + 307 >>> requests.codes.teapot - 416 + 418 >>> requests.codes['\o/'] - 416 + 200 Cookies ~~~~~~~ diff --git a/docs/dev/todo.rst b/docs/dev/todo.rst index 8a631d88..91c99749 100644 --- a/docs/dev/todo.rst +++ b/docs/dev/todo.rst @@ -7,9 +7,6 @@ Requests is under active development, and contributions are more than welcome! What Needs to be Done --------------------- -- OAuth Support (`#65 `_) - HTTP Cert Checking (`#30 `_) -- Removal of Poster (`#68 `_) - Python 3.x Support (`#70 `_) - Kerberos Support (`#47 `_) -- More Flexible Context Manager (`#69 `_) \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index bab640b0..5491e98b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -30,7 +30,7 @@ Things shouldn’t be this way. Not in Python. See `the same code, without Requests `_. -Requests allow you to send **HEAD**, **GET**, **POST**, **PUT**, +Requests allows you to send **HEAD**, **GET**, **POST**, **PUT**, **PATCH**, and **DELETE** HTTP requests. You can add headers, form data, multipart files, and parameters with simple Python dictionaries, and access the response 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. diff --git a/docs/user/advanced.rst b/docs/user/advanced.rst index 70514ef7..0c26f2d3 100644 --- a/docs/user/advanced.rst +++ b/docs/user/advanced.rst @@ -71,7 +71,7 @@ You can override this default behavior with the ``prefetch`` parameter:: Configuring Requests -------------------- -Sometimes you may want to configure a request to customize it's behavior. To do +Sometimes you may want to configure a request to customize its behavior. To do this, you can pass in a ``config`` dictionary to a request or session. See the :ref:`Configuration API Docs ` to learn more. diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 4ead8755..542a5bc6 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -39,7 +39,8 @@ We can read the content of the server's response:: >>> r.content '[{"repository":{"open_issues":0,"url":"https://github.com/... -Requests does its best to decode content from the server. Most unicode charsets, ``gzip``, and ``deflate`` encodings are all seamlessly decoded. +Requests does its best to decode content from the server. Most unicode +charsets, ``gzip``, and ``deflate`` encodings are all seamlessly decoded. Make a POST Request @@ -51,7 +52,8 @@ POST requests are equally simple:: Typically, you want to send some form-encoded data — much like an HTML form. -To do this, simply pass a dictionary to the `data` argument. Your dictionary of data will automatically be form-encoded when the request is made:: +To do this, simply pass a dictionary to the `data` argument. Your +dictionary of data will automatically be form-encoded when the request is made:: >>> payload = {'key1': 'value1', 'key2': 'value2'} >>> r = requests.post("http://httpbin.org/post", data=payload) @@ -114,7 +116,7 @@ Requests makes it simple to upload Multipart-encoded files:: { "origin": "179.13.100.4", "files": { - "hmm": "" + "report.xls": "" }, "form": {}, "url": "http://httpbin.org/post", @@ -236,6 +238,11 @@ Making requests with Basic Auth is extremely simple:: >>> requests.get('https://api.github.com/user', auth=('user', 'pass')) +OAuth Authentication +-------------------- + +Miguel Araujo's `requests-oauth `_ project provides a simple interface for +establishing OAuth connections. Documentation and examples can be found on the requests-oauth `git repository `_. Digest Authentication --------------------- @@ -254,7 +261,7 @@ Requests will automatically perform location redirection while using impodotent GitHub redirects all HTTP requests to HTTPS. Let's see what happens:: - >>> r = request.get('http://github.com') + >>> r = requests.get('http://github.com') >>> r.url 'https://github.com/' >>> r.status_code @@ -268,7 +275,7 @@ The :class:`Response.history` list contains a list of the If you're using GET, HEAD, or OPTIONS, you can disable redirection handling with the ``disable_redirects`` parameter:: - >>> r = request.get('http://github.com') + >>> r = requests.get('http://github.com') >>> r.status_code 301 >>> r.history @@ -276,7 +283,7 @@ handling with the ``disable_redirects`` parameter:: If you're using POST, PUT, PATCH, *&c*, you can also explicitly enable redirection as well:: - >>> r = request.post('http://github.com') + >>> r = requests.post('http://github.com', allow_redirects=True) >>> r.url 'https://github.com/' >>> r.history @@ -298,8 +305,6 @@ You can tell requests to stop waiting for a response after a given number of sec ``timeout`` only effects the connection process itself, not the downloading of the respone body. -Note - Errors and Exceptions --------------------- diff --git a/requests/__init__.py b/requests/__init__.py index e3a9d2a0..b42d1210 100644 --- a/requests/__init__.py +++ b/requests/__init__.py @@ -15,8 +15,8 @@ requests """ __title__ = 'requests' -__version__ = '0.8.0' -__build__ = 0x000800 +__version__ = '0.8.1' +__build__ = 0x000801 __author__ = 'Kenneth Reitz' __license__ = 'ISC' __copyright__ = 'Copyright 2011 Kenneth Reitz' diff --git a/requests/models.py b/requests/models.py index 34de8005..97237e77 100644 --- a/requests/models.py +++ b/requests/models.py @@ -11,7 +11,7 @@ import urllib import zlib from Cookie import SimpleCookie -from urlparse import urlparse, urlunparse, urljoin +from urlparse import urlparse, urlunparse, urljoin, urlsplit from datetime import datetime from .auth import dispatch as auth_dispatch @@ -181,7 +181,7 @@ class Request(object): if is_error: response.error = resp - response.url = self._build_url() + response.url = self.full_url return response @@ -239,7 +239,9 @@ class Request(object): cookies=cookies, redirect=True, config=self.config, - _poolmanager=self._poolmanager + timeout=self.timeout, + _poolmanager=self._poolmanager, + proxies = self.proxies, ) request.send() @@ -279,8 +281,8 @@ class Request(object): else: return data, data - - def _build_url(self): + @property + def full_url(self): """Build the actual URL to use.""" if not self.url: @@ -298,15 +300,41 @@ class Request(object): path = path.encode('utf-8') path = urllib.quote(urllib.unquote(path)) - self.url = str(urlunparse([ scheme, netloc, path, params, query, fragment ])) + + url = str(urlunparse([ scheme, netloc, path, params, query, fragment ])) if self._enc_params: - if urlparse(self.url).query: - return '%s&%s' % (self.url, self._enc_params) + if urlparse(url).query: + return '%s&%s' % (url, self._enc_params) else: - return '%s?%s' % (self.url, self._enc_params) + return '%s?%s' % (url, self._enc_params) else: - return self.url + return url + + @property + def path_url(self): + """Build the path URL to use.""" + + url = [] + + p = urlsplit(self.full_url) + + # Proxies use full URLs. + if p.scheme in self.proxies: + return self.full_url + + path = p.path + if not path: + path = '/' + url.append(path) + + query = p.query + if query: + url.append('?') + url.append(query) + + return ''.join(url) + def send(self, anyway=False, prefetch=False): @@ -327,7 +355,7 @@ class Request(object): )) # Build the URL - url = self._build_url() + url = self.full_url # Nottin' on you. body = None @@ -376,7 +404,7 @@ class Request(object): proxy = self.proxies.get(_p.scheme) if proxy: - conn = poolmanager.proxy_from_url(url) + conn = poolmanager.proxy_from_url(proxy) else: # Check to see if keep_alive is allowed. if self.config.get('keep_alive'): @@ -404,10 +432,9 @@ class Request(object): try: # Send the request. - r = conn.urlopen( method=self.method, - url=url, + url=self.path_url, body=body, headers=self.headers, redirect=False,