Permalink
Browse files

Merge branch 'release/0.3.0'

  • Loading branch information...
kennethreitz committed Feb 25, 2011
2 parents 8b3c4da + f8032e0 commit 044252ea7b6518137c134412dd6192020b069f82
Showing with 429 additions and 272 deletions.
  1. +2 −0 AUTHORS
  2. +15 −0 HACKING
  3. +12 −0 HISTORY.rst
  4. +33 −30 README.rst
  5. +48 −0 requests/async.py
  6. +279 −218 requests/core.py
  7. +7 −5 requests/packages/poster/streaminghttp.py
  8. +33 −19 test_requests.py
View
@@ -12,3 +12,5 @@ Patches and Suggestions
- Various Pocoo Members
- Chris Adams
+- Flavio Percoco Premoli
+- Dj Gilcrease
View
15 HACKING
@@ -0,0 +1,15 @@
+Where possible, please follow PEP8 with regard to coding style. Sometimes the
+line length restriction is too hard to follow, so don't bend over backwards
+there.
+
+Triple-quotes should always be """, single quotes are ' unless using " would
+result in less escaping within the string.
+
+All modules, functions, and methods should be well documented reStructuredText
+for Sphinx AutoDoc.
+
+All functionality should be available in pure Python. Optional C (via Cython)
+implementations may be written for performance reasons, but should never
+replace the Python implementation.
+
+Lastly, don't take yourself too seriously :)
View
@@ -1,6 +1,18 @@
History
-------
+0.3.0 (2011-02-25)
+++++++++++++++++++
+
+* Automatic Authentication API Change
+* Smarter Query URL Parameterization
+* Allow file uploads and POST data together
+* New Authentication Manager System
+ - Simpler Basic HTTP System
+ - Supports all build-in urllib2 Auths
+ - Allows for custom Auth Handlers
+
+
0.2.4 (2011-02-19)
++++++++++++++++++
View
@@ -1,11 +1,11 @@
Requests: The Simple (e.g. usable) HTTP Module
==============================================
-Most existing Python modules for dealing HTTP requests are insane. I have to look up *everything* that I want to do. Most of my worst Python experiences are a result of the various built-in HTTP libraries (yes, even worse than Logging).
+Most existing Python modules for dealing HTTP requests are insane. I have to look up *everything* that I want to do. Most of my worst Python experiences are a result of the various built-in HTTP libraries (yes, even worse than Logging).
But this one's different. This one's going to be awesome. And simple.
-Really simple.
+Really simple.
Features
--------
@@ -15,8 +15,8 @@ Features
+ Simple Data/Params Request Attachment
+ Simple Multipart File Uploads
+ CookieJar Support
-
-- Simple Basic HTTP Authentication
+
+- Simple Authentication
+ Simple URL + HTTP Auth Registry
@@ -30,79 +30,82 @@ It couldn't be simpler. ::
HTTPS? Basic Authentication? ::
-
+
>>> r = requests.get('https://convore.com/api/account/verify.json')
>>> r.status_code
401
-
+
Uh oh, we're not authorized! Let's add authentication. ::
-
- >>> conv_auth = requests.AuthObject('requeststest', 'requeststest')
+
+ >>> conv_auth = ('requeststest', 'requeststest')
>>> r = requests.get('https://convore.com/api/account/verify.json', auth=conv_auth)
-
+
>>> r.status_code
- 200
-
+ 200
+
>>> r.headers['content-type']
'application/json'
-
+
>>> r.content
'{"username": "requeststest", "url": "/users/requeststest/", "id": "9408", "img": "censored-long-url"}'
API
---
-
+
**Requests:**
All request functions return a Response object (see below).
If a {filename: fileobject} dictionary is passed in (files=...), a multipart_encode upload will be performed.
If CookieJar object is is passed in (cookies=...), the cookies will be sent with the request.
-
+
GET Requests
>>> request.get(url, params={}, headers={}, cookies=None, auth=None)
<request object>
-
+
HEAD Requests
>>> request.head(url, params={}, headers={}, cookies=None, auth=None)
<request object>
-
+
PUT Requests
>>> request.put(url, data='', headers={}, files={}, cookies=None, auth=None)
<request object>
-
+
POST Requests
>>> request.post(url, data={}, headers={}, files={}, cookies=None, auth=None)
<request object>
-
+
DELETE Requests
>>> request.delete(url, params={}, headers={}, cookies=None, auth=None)
<request object>
-
+
**Responses:**
-
- Response.status_code:
+
+ Response.status_code
(Integer) Received HTTP Status Code Response
- Response.headers:
+ Response.headers
(Dictionary) Received HTTP Response Headers
- Response.content:
+ Response.content
(Bytes) Received Content
Response.url
- (String) URL of response. Useful for detecting redirects.
-
+ (String) URL of response. Useful for detecting redirects.
+
Response.ok
(Bool) True if no errors occurred during the request, and the status_code is kosher.
-
+
+ Response.cached
+ (Bool) True if Response.content is stored within the object.
+
Response.error
(HTTPError) If an HTTPError occurred (e.g. status of 404), Otherwise this is None.
-
+
Response.raise_for_status()
Raises HTTPError if a request is not kosher.
@@ -111,7 +114,7 @@ If CookieJar object is is passed in (cookies=...), the cookies will be sent with
You can register AuthObjects to automatically enable HTTP Authentication on requests that contain a registered base URL string.
- >>> requests.add_autoauth(url, authobject)
+ >>> requests.auth_manager.add_auth(url, authobject)
@@ -121,13 +124,13 @@ Installation
To install requests, simply: ::
$ pip install requests
-
+
Or, if you absolutely must: ::
$ easy_install requests
But, you really shouldn't do that.
-
+
Contribute
View
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+
+"""
+ requests.async
+ ~~~~~~~~~~~~~~
+
+ This module implements the main Requests system, after monkey-patching
+ the urllib2 module with eventlet or gevent..
+
+ :copyright: (c) 2011 by Kenneth Reitz.
+ :license: ISC, see LICENSE for more details.
+"""
+
+
+from __future__ import absolute_import
+
+import urllib
+import urllib2
+
+from urllib2 import HTTPError
+
+
+try:
+ import eventlet
+ eventlet.monkey_patch()
+except ImportError:
+ pass
+
+if not 'eventlet' in locals():
+ try:
+ from gevent import monkey
+ monkey.patch_all()
+ except ImportError:
+ pass
+
+
+if not 'eventlet' in locals():
+ raise ImportError('No Async adaptations of urllib2 found!')
+
+
+from .core import *
+
+
+__all__ = [
+ 'Request', 'Response', 'request', 'get', 'head', 'post', 'put', 'delete',
+ 'auth_manager', 'AuthObject','RequestException', 'AuthenticationError',
+ 'URLRequired', 'InvalidMethod', 'HTTPError'
+]
Oops, something went wrong.

0 comments on commit 044252e

Please sign in to comment.