added toa AUTHORS file
authorMichael Van Veen <michael@mvanveen.net>
Thu, 22 Sep 2011 10:38:58 +0000 (03:38 -0700)
committerMichael Van Veen <michael@mvanveen.net>
Thu, 22 Sep 2011 10:42:56 +0000 (03:42 -0700)
AUTHORS
requests/api.py
requests/config.py
requests/core.py
requests/exceptions.py
requests/models.py
requests/monkeys.py
requests/sessions.py
requests/status_codes.py
requests/structures.py
requests/utils.py

diff --git a/AUTHORS b/AUTHORS
index af00b19e01db17017a530b3eee7fdfa07e290cbc..0478a75160014626a7759735937cd723a46c22dc 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -43,5 +43,6 @@ Patches and Suggestions
 - Rick Mak
 - Johan Bergström
 - Josselin Jacquard
+- Michael Van Veen <michael@mvanveen.net>
 - Mike Waldner
-- Serge Domkowski
\ No newline at end of file
+- Serge Domkowski
index 60d0d85262ed87b97df8613d43a1f4559b909021..48823a9a4c8aa8bfa958de30a8be2c5b3e213be0 100644 (file)
@@ -54,17 +54,17 @@ def request(method, url,
             headers[k] = header_expand(v)
 
     args = dict(
-        method = method,
-        url = url,
-        data = data,
-        params = params,
-        headers = headers,
-        cookiejar = cookies,
-        files = files,
-        auth = auth,
-        timeout = timeout or config.settings.timeout,
-        allow_redirects = allow_redirects,
-        proxies = proxies or config.settings.proxies,
+        method=method,
+        url=url,
+        data=data,
+        params=params,
+        headers=headers,
+        cookiejar=cookies,
+        files=files,
+        auth=auth,
+        timeout=timeout or config.settings.timeout,
+        allow_redirects=allow_redirects,
+        proxies=proxies or config.settings.proxies,
     )
 
     # Arguments manipulation hook.
index 676a5f0e2ac04bd1e2b46b7d58d992f64708c639..55c1b88c382d0c8e3ad4eda741e2347ef5024e3d 100644 (file)
@@ -6,8 +6,23 @@ requests.config
 
 This module provides the Requests settings feature set.
 
+settings parameters:
+
+TODO: Verify!!!
+TODO: Make sure format is acceptabl/cool
+- :base_headers: - Sets default User-Agent to `python-requests.org`
+- :accept_gzip:  - Whether or not to accept gzip-compressed data
+- :proxies: - http proxies?
+- :verbose: - display verbose information?
+- :timeout: - timeout time until request terminates
+- :max_redirects: - maximum number of allowed redirects?
+- :decode_unicode: - whether or not to accept unicode?
+
+Used globally
+
 """
 
+
 class Settings(object):
 
     def __init__(self, **kwargs):
index e1ba1853369d30cfe6b890cf91d876371856c390..8f765ed1fe12cfe71f9119ba853ec24b01ad9ffc 100644 (file)
@@ -26,4 +26,4 @@ from sessions import session
 from status_codes import codes
 from config import settings
 
-import utils
\ No newline at end of file
+import utils
index c08c61480b307a3d67650c92b83986fcde0adeed..3a6502704335d3ec0f719e30d04e6c313f867d36 100644 (file)
@@ -6,21 +6,27 @@ requests.exceptions
 
 """
 
+
 class RequestException(Exception):
     """There was an ambiguous exception that occured while handling your
     request."""
 
+
 class AuthenticationError(RequestException):
     """The authentication credentials provided were invalid."""
-    
+
+
 class Timeout(RequestException):
     """The request timed out."""
 
+
 class URLRequired(RequestException):
     """A valid URL is required to make a request."""
 
+
 class InvalidMethod(RequestException):
     """An inappropriate method was attempted."""
 
+
 class TooManyRedirects(RequestException):
     """Too many redirects."""
index 742acf2c6c2173204b645e6a42244a002e350e13..f6d84ebd563bce0b95af5430aa8e1a68bec164b6 100644 (file)
@@ -30,7 +30,6 @@ from .exceptions import RequestException, AuthenticationError, Timeout, URLRequi
 REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)
 
 
-
 class Request(object):
     """The :class:`Request <Request>` object. It carries out all functionality of
     Requests. Recommended interface is with the Requests functions.
@@ -96,7 +95,6 @@ class Request(object):
         #: True if Request has been sent.
         self.sent = False
 
-
         # Header manipulation and defaults.
 
         if settings.accept_gzip:
@@ -113,18 +111,15 @@ class Request(object):
 
         self.headers = headers
 
-
     def __repr__(self):
         return '<Request [%s]>' % (self.method)
 
-
     def _checks(self):
         """Deterministic checks for consistency."""
 
         if not self.url:
             raise URLRequired
 
-
     def _get_opener(self):
         """Creates appropriate opener object for urllib2."""
 
@@ -173,13 +168,11 @@ class Request(object):
 
         return opener.open
 
-
     def _build_response(self, resp, is_error=False):
         """Build internal :class:`Response <Response>` object
         from given response.
         """
 
-
         def build(resp):
 
             response = Response()
@@ -193,7 +186,6 @@ class Request(object):
 
                     response.cookies = dict_from_cookiejar(self.cookiejar)
 
-
             except AttributeError:
                 pass
 
@@ -204,7 +196,6 @@ class Request(object):
 
             return response
 
-
         history = []
 
         r = build(resp)
@@ -258,7 +249,6 @@ class Request(object):
         self.response = r
         self.response.request = self
 
-
     @staticmethod
     def _encode_params(data):
         """Encode parameters in a piece of data.
@@ -276,22 +266,28 @@ class Request(object):
             for k, vs in data.items():
                 for v in isinstance(vs, list) and vs or [vs]:
                     result.append((k.encode('utf-8') if isinstance(k, unicode) else k,
-                                   v.encode('utf-8') if isinstance(v, unicode) else v))
-            return result, urllib.urlencode(result, doseq=True)
+                                   v.encode('utf-8') if isinstance(v, unicode) else v)
+                    )
+            return (result, urllib.urlencode(result, doseq=True))
+
         else:
             return data, data
 
-
     def _build_url(self):
         """Build the actual URL to use."""
 
         # Support for unicode domain names and paths.
         scheme, netloc, path, params, query, fragment = urlparse(self.url)
         netloc = netloc.encode('idna')
+
         if isinstance(path, unicode):
             path = path.encode('utf-8')
+
         path = urllib.quote(path, safe="%/:=&?~#+!$,;'@()*[]")
-        self.url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))
+
+        self.url = str(urlunparse(
+          [scheme, netloc, path, params, query, fragment]
+         ))
 
         if self._enc_params:
             if urlparse(self.url).query:
@@ -301,7 +297,6 @@ class Request(object):
         else:
             return self.url
 
-
     def send(self, anyway=False):
         """Sends the request. Returns True of successful, false if not.
         If there was an HTTPError during transmission,
@@ -321,7 +316,6 @@ class Request(object):
                 datetime.now().isoformat(), self.method, self.url
             ))
 
-
         url = self._build_url()
         if self.method in ('GET', 'HEAD', 'DELETE'):
             req = _Request(url, method=self.method)
@@ -340,7 +334,7 @@ class Request(object):
                 req = _Request(url, data=self._enc_data, method=self.method)
 
         if self.headers:
-            for k,v in self.headers.iteritems():
+            for k, v in self.headers.iteritems():
                 req.add_header(k, v)
 
         if not self.sent or anyway:
@@ -381,17 +375,17 @@ class Request(object):
                 self._build_response(resp)
                 self.response.ok = True
 
-
         self.sent = self.response.ok
 
         return self.sent
 
 
 class Response(object):
-    """The core :class:`Response <Response>` object. All
-    :class:`Request <Request>` objects contain a
-    :class:`response <Response>` attribute, which is an instance
-    of this class.
+    """The core :class:`Response <Response>` object.
+
+
+    All :class:`Request <Request>` objects contain a :class:`response
+    <Response>` attribute, which is an instance of this class.
     """
 
     def __init__(self):
@@ -430,11 +424,9 @@ class Response(object):
         #: A dictionary of Cookies the server sent back.
         self.cookies = None
 
-
     def __repr__(self):
         return '<Response [%s]>' % (self.status_code)
 
-
     def __nonzero__(self):
         """Returns true if :attr:`status_code` is 'OK'."""
 
@@ -496,14 +488,12 @@ class Response(object):
         self._content_consumed = True
         return self._content
 
-
     def raise_for_status(self):
         """Raises stored :class:`HTTPError` or :class:`URLError`, if one occured."""
         if self.error:
             raise self.error
 
 
-
 class AuthManager(object):
     """Requests Authentication Manager."""
 
@@ -516,16 +506,13 @@ class AuthManager(object):
 
         return singleton
 
-
     def __init__(self):
         self.passwd = {}
         self._auth = {}
 
-
     def __repr__(self):
         return '<AuthManager [%s]>' % (self.method)
 
-
     def add_auth(self, uri, auth):
         """Registers AuthObject to AuthManager."""
 
@@ -540,7 +527,6 @@ class AuthManager(object):
 
         self._auth[uri] = auth
 
-
     def add_password(self, realm, uri, user, passwd):
         """Adds password to AuthManager."""
         # uri could be a single URI or a sequence
@@ -553,7 +539,6 @@ class AuthManager(object):
             self.passwd[reduced_uri] = {}
         self.passwd[reduced_uri] = (user, passwd)
 
-
     def find_user_password(self, realm, authuri):
         for uris, authinfo in self.passwd.iteritems():
             reduced_authuri = self.reduce_uri(authuri, False)
@@ -563,7 +548,6 @@ class AuthManager(object):
 
         return (None, None)
 
-
     def get_auth(self, uri):
         (in_domain, in_path) = self.reduce_uri(uri, False)
 
@@ -574,7 +558,6 @@ class AuthManager(object):
                 if path in in_path:
                     return authority
 
-
     def reduce_uri(self, uri, default_port=True):
         """Accept authority or URI and extract only the authority and path."""
 
@@ -603,7 +586,6 @@ class AuthManager(object):
 
         return authority, path
 
-
     def is_suburi(self, base, test):
         """Check if test is below base in a URI tree
 
@@ -618,11 +600,9 @@ class AuthManager(object):
             return True
         return False
 
-
     def empty(self):
         self.passwd = {}
 
-
     def remove(self, uri, realm=None):
         # uri could be a single URI or a sequence
         if isinstance(uri, basestring):
@@ -632,7 +612,6 @@ class AuthManager(object):
             reduced_uri = tuple([self.reduce_uri(u, default_port) for u in uri])
             del self.passwd[reduced_uri][realm]
 
-
     def __contains__(self, uri):
         # uri could be a single URI or a sequence
         if isinstance(uri, basestring):
@@ -648,12 +627,12 @@ class AuthManager(object):
 auth_manager = AuthManager()
 
 
-
 class AuthObject(object):
-    """The :class:`AuthObject` is a simple HTTP Authentication token. When
-    given to a Requests function, it enables Basic HTTP Authentication for that
-    Request. You can also enable Authorization for domain realms with AutoAuth.
-    See AutoAuth for more details.
+    """The :class:`AuthObject` is a simple HTTP Authentication token.
+
+    When given to a Requests function, it enables Basic HTTP Authentication
+    for that Request. You can also enable Authorization for domain realms
+    with AutoAuth. See AutoAuth for more details.
 
     :param username: Username to authenticate with.
     :param password: Password for given username.
index c83807112db4d24a2cd35046904def18e0832aa8..8f10d29fcf2626dee40207efb66bf218e08838ac 100644 (file)
@@ -8,8 +8,9 @@ Urllib2 Monkey patches.
 
 """
 
-import urllib2
 import re
+import urllib2
+
 
 class Request(urllib2.Request):
     """Hidden wrapper around the urllib2.Request object. Allows for manual
@@ -35,7 +36,6 @@ class HTTPRedirectHandler(urllib2.HTTPRedirectHandler):
     http_error_302 = http_error_303 = http_error_307 = http_error_301
 
 
-
 class HTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler):
     """HTTP Basic Auth Handler with authentication loop fixes."""
 
@@ -44,14 +44,12 @@ class HTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler):
         self.retried_req = None
         self.retried = 0
 
-
     def reset_retry_count(self):
         # Python 2.6.5 will call this on 401 or 407 errors and thus loop
         # forever. We disable reset_retry_count completely and reset in
         # http_error_auth_reqed instead.
         pass
 
-
     def http_error_auth_reqed(self, auth_header, host, req, headers):
         # Reset the retry counter once for each request.
         if req is not self.retried_req:
@@ -63,7 +61,6 @@ class HTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler):
         )
 
 
-
 class HTTPForcedBasicAuthHandler(HTTPBasicAuthHandler):
     """HTTP Basic Auth Handler with forced Authentication."""
 
@@ -71,10 +68,9 @@ class HTTPForcedBasicAuthHandler(HTTPBasicAuthHandler):
     rx = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+'
                     'realm=(["\'])(.*?)\\2', re.I)
 
-    def __init__(self,  *args, **kwargs):
+    def __init__(self, *args, **kwargs):
         HTTPBasicAuthHandler.__init__(self, *args, **kwargs)
 
-
     def http_error_401(self, req, fp, code, msg, headers):
         url = req.get_full_url()
         response = self._http_error_auth_reqed('www-authenticate', url, req, headers)
@@ -83,7 +79,6 @@ class HTTPForcedBasicAuthHandler(HTTPBasicAuthHandler):
 
     http_error_404 = http_error_401
 
-
     def _http_error_auth_reqed(self, authreq, host, req, headers):
 
         authreq = headers.get(authreq, None)
@@ -116,7 +111,6 @@ class HTTPForcedBasicAuthHandler(HTTPBasicAuthHandler):
             return response
 
 
-
 class HTTPDigestAuthHandler(urllib2.HTTPDigestAuthHandler):
 
     def __init__(self, *args, **kwargs):
@@ -145,4 +139,4 @@ class HTTPDigestAuthHandler(urllib2.HTTPDigestAuthHandler):
             arg = inst.args[0]
             if arg.startswith("AbstractDigestAuthHandler doesn't know "):
                 return
-            raise
\ No newline at end of file
+            raise
index 50b09f612de83e2eb1e524b8e58f8fccf69e939a..7145d278c0d815f280560359ac4179dc56aa8ad7 100644 (file)
@@ -15,13 +15,11 @@ from . import api
 from .utils import add_dict_to_cookiejar
 
 
-
 class Session(object):
     """A Requests session."""
 
     __attrs__ = ['headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks']
 
-
     def __init__(self, **kwargs):
 
         # Set up a CookieJar to be used by default
@@ -34,7 +32,6 @@ class Session(object):
         # Map and wrap requests.api methods
         self._map_api_methods()
 
-
     def __repr__(self):
         return '<requests-client at 0x%x>' % (id(self))
 
@@ -45,7 +42,6 @@ class Session(object):
         # print args
         pass
 
-
     def _map_api_methods(self):
         """Reads each available method from requests.api and decorates
         them with a wrapper, which inserts any instance-local attributes
@@ -81,4 +77,4 @@ class Session(object):
 def session(**kwargs):
     """Returns a :class:`Session` for context-managment."""
 
-    return Session(**kwargs)
\ No newline at end of file
+    return Session(**kwargs)
index a809de6ab959f94dab1f824caa5952a9c9667eb6..025dc28f83cf7acb4e34a24b91eee2d32093ea7f 100644 (file)
@@ -80,4 +80,4 @@ for (code, titles) in _codes.items():
     for title in titles:
         setattr(codes, title, code)
         if not title.startswith('\\'):
-            setattr(codes, title.upper(), code)
\ No newline at end of file
+            setattr(codes, title.upper(), code)
index d068bf9cddf2d10f46c2142480ccb2bb1d1fd627..b16e75dfc9e74d5b7d1c883d081d805ab7d7ce66 100644 (file)
@@ -8,6 +8,7 @@ Datastructures that power Requests.
 
 """
 
+
 class CaseInsensitiveDict(dict):
     """Case-insensitive Dictionary
 
@@ -46,6 +47,7 @@ class CaseInsensitiveDict(dict):
         else:
             return default
 
+
 class LookupDict(dict):
     """Dictionary lookup object."""
 
@@ -62,4 +64,4 @@ class LookupDict(dict):
         return self.__dict__.get(key, None)
 
     def get(self, key, default=None):
-        return self.__dict__.get(key, default)
\ No newline at end of file
+        return self.__dict__.get(key, default)
index 17f79a8ac8e2ffc423985bcd52effa2f3d7d6221..7a5c6d70522fcb2614a9a165f6f09c3dc431930e 100644 (file)
@@ -51,10 +51,9 @@ def header_expand(headers):
 
             collector.append('; '.join(_params))
 
-            if not len(headers) == i+1:
+        if not len(headers) == i + 1:
                 collector.append(', ')
 
-
     # Remove trailing seperators.
     if collector[-1] in (', ', '; '):
         del collector[-1]
@@ -62,7 +61,6 @@ def header_expand(headers):
     return ''.join(collector)
 
 
-
 def dict_from_cookiejar(cj):
     """Returns a key/value dictionary from a CookieJar.
 
@@ -235,8 +233,8 @@ def decode_gzip(content):
     :param content: bytestring to gzip-decode.
     """
 
-    return zlib.decompress(content, 16+zlib.MAX_WBITS)
-    return zlib.decompress(content, 16+zlib.MAX_WBITS)
+    return zlib.decompress(content, 16 + zlib.MAX_WBITS)
+    return zlib.decompress(content, 16 + zlib.MAX_WBITS)
     return zlib.decompress(content, 16 + zlib.MAX_WBITS)
 
 
@@ -255,6 +253,7 @@ def stream_decode_gzip(iterator):
     except zlib.error:
         pass
 
+
 def curl_from_request(request):
     """Returns a curl command from the request.
 
@@ -276,10 +275,13 @@ def curl_from_request(request):
     #: -u/--user - Specify the user name and password to use for server auth.
     #: Basic Auth only for now
     auth = ''
+
     if request.auth is not None:
-       auth = '-u "%s:%s" ' % (request.auth.username, request.auth.password)
+
+        auth = '-u "%s:%s" ' % (request.auth.username, request.auth.password)
 
     method = ''
+
     if request.method.upper() == 'HEAD':
         #: -I/--head - fetch headers only.
         method = '-I '
@@ -321,4 +323,3 @@ def curl_from_request(request):
 
     #: Params handled in _build_url
     return curl + auth + method + header + cookies + form + '"' + request._build_url() + '"'
-