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
Provenance
- Commit
1165bec- Tree
e0e33a9- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
8f20058- Parent 2
b79dea9
8 files changed+67 added−32 removed
modified:docs/dev/todo.rst-3 removed
5 unmodified lines6 7 What Needs to be Done8 ---------------------9 10-- 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 lines70 71 Configuring Requests72 --------------------73 74-Sometimes you may want to configure a request to customize it's behavior. To do74+Sometimes you may want to configure a request to customize its behavior. To do75 this, you can pass in a ``config`` dictionary to a request or session. See the :ref:`Configuration API Docs <configurations>` to learn more.76 77 78 Keep-Alive176 unmodified linesmodified:docs/user/quickstart.rst+13 added-8 removed
37 unmodified lines38 39 >>> r.content40 '[{"repository":{"open_issues":0,"url":"https://github.com/...41 42-Requests does its best to decode content from the server. Most unicode charsets, ``gzip``, and ``deflate`` encodings are all seamlessly decoded.42+Requests does its best to decode content from the server. Most unicode43+charsets, ``gzip``, and ``deflate`` encodings are all seamlessly decoded.44 45 46 Make a POST Request47 -------------------3 unmodified lines51 r = requests.post("http://httpbin.org/post")52 53 54 Typically, you want to send some form-encoded data — much like an HTML form.54-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::55+To do this, simply pass a dictionary to the `data` argument. Your56+dictionary of data will automatically be form-encoded when the request is made::57 58 >>> payload = {'key1': 'value1', 'key2': 'value2'}59 >>> r = requests.post("http://httpbin.org/post", data=payload)60 >>> print r.content54 unmodified lines115 >>> 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 lines237 238 >>> requests.get('https://api.github.com/user', auth=('user', 'pass'))239 <Response [200]>240 241+OAuth Authentication242+--------------------243 244+Miguel Araujo's `requests-oauth <http://pypi.python.org/pypi/requests-oauth>`_ project provides a simple interface for245+establishing OAuth connections. Documentation and examples can be found on the requests-oauth `git repository <https://github.com/maraujop/requests-oauth>`_.246+247 Digest Authentication248 ---------------------249 250 Another popular form of web service protection is Digest Authentication::9 unmodified lines260 Requests will automatically perform location redirection while using impodotent methods.261 262 GitHub redirects all HTTP requests to HTTPS. Let's see what happens::263 257- >>> r = request.get('http://github.com')264+ >>> r = requests.get('http://github.com')265 >>> r.url266 'https://github.com/'267 >>> r.status_code268 2005 unmodified lines274 275 If you're using GET, HEAD, or OPTIONS, you can disable redirection276 handling with the ``disable_redirects`` parameter::277 271- >>> r = request.get('http://github.com')278+ >>> r = requests.get('http://github.com')279 >>> r.status_code280 301281 >>> r.history282 []283 284 If you're using POST, PUT, PATCH, *&c*, you can also explicitly enable redirection as well::285 279- >>> 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 lines304 305 ``timeout`` only effects the connection process itself, not the downloading of the respone body.306 307 301-Note302-308 Errors and Exceptions309 ---------------------310 311 In the event of a network problem (e.g. DNS failure, refused connection, etc),15 unmodified linesmodified:docs/api.rst+3 added-3 removed
93 unmodified lines94 95 ::96 97 >>> requests.codes['temporary_redirect']98- 30198+ 30799 100 >>> requests.codes.teapot101- 416101+ 418102 103 >>> requests.codes['\o/']104- 416104+ 200105 106 Cookies107 ~~~~~~~108 36 unmodified linesmodified:docs/index.rst+1 added-1 removed
28 unmodified lines29 ...30 31 See `the same code, without Requests <https://gist.github.com/973705>`_.32 33-Requests allow you to send **HEAD**, **GET**, **POST**, **PUT**,33+Requests allows you to send **HEAD**, **GET**, **POST**, **PUT**,34 **PATCH**, and **DELETE** HTTP requests. You can add headers, form data,35 multipart files, and parameters with simple Python dictionaries, and access the36 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.37 80 unmodified linesmodified:requests/__init__.py+2 added-2 removed
13 unmodified lines14 15 """16 17 __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 linesmodified:requests/models.py+41 added-14 removed
9 unmodified lines10 import urllib11 import zlib12 13 from Cookie import SimpleCookie14-from urlparse import urlparse, urlunparse, urljoin14+from urlparse import urlparse, urlunparse, urljoin, urlsplit15 from datetime import datetime16 17 from .auth import dispatch as auth_dispatch18 from .hooks import dispatch_hook161 unmodified lines180 181 if is_error:182 response.error = resp183 184- response.url = self._build_url()184+ response.url = self.full_url185 186 return response187 188 49 unmodified lines238 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 )246 247 request.send()248 cookies.update(request.response.cookies)31 unmodified lines280 return result, urllib.urlencode(result, doseq=True)281 else:282 return data, data283 282-283- def _build_url(self):284+ @property285+ def full_url(self):286 """Build the actual URL to use."""287 288 if not self.url:289 raise URLRequired()9 unmodified lines299 if isinstance(path, unicode):300 path = path.encode('utf-8')301 302 path = urllib.quote(urllib.unquote(path))301- self.url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))303 304+ url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))305+306 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 url313 314+ @property315+ def path_url(self):316+ """Build the path URL to use."""317 318+ url = []319+320+ p = urlsplit(self.full_url)321+322+ # Proxies use full URLs.323+ if p.scheme in self.proxies:324+ return self.full_url325+326+ path = p.path327+ if not path:328+ path = '/'329+ url.append(path)330+331+ query = p.query332+ if query:333+ url.append('?')334+ url.append(query)335+336+ return ''.join(url)337+338+339+340 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 lines354 datetime.now().isoformat(), self.method, self.url355 ))356 357 # Build the URL330- url = self._build_url()358+ url = self.full_url359 360 # Nottin' on you.361 body = None362 content_type = None40 unmodified lines403 _p = urlparse(url)404 proxy = self.proxies.get(_p.scheme)405 406 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 lines431 self.headers['Cookie'] = cookie_header432 433 try:434 # Send the request.407-435 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 linesmodified:HISTORY.rst+6 added
1 History2 -------3 4+0.8.1 (2011-11-15)5+++++++++++++++++++6 7+* URL Request path fix8+* Proxy fix.9+* Timeouts fix.10+11 0.8.0 (2011-11-13)12 ++++++++++++++++++13 14 * Keep-alive support!248 unmodified lines