Skip to content
Myr

Merge branch 'develop' of https://github.com/atdt/requests into develop

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Conflicts: AUTHORS.rst

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 75dc012, f214b91 · Browse files · 4 files+45 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+45 added−1 removed

  • other:+45 added−1 removed

4 files+45 added−1 removed

modified:docs/user/advanced.rst+21 added
241 unmodified lines
242 >>> requests.get('http://pizzabin.org/admin', auth=PizzaAuth('kenneth'))243 <Response [200]>244245246Streaming Requests247------------------248249With ``requests.Response.iter_lines()`` you can easily iterate over streaming 250APIs such as the `Twitter Streaming API <https://dev.twitter.com/docs/streaming-api>`_.251252To use the Twitter Streaming API to track the keyword "requests":253254::255256 import requests257 import json258259 r = requests.post('https://stream.twitter.com/1/statuses/filter.json',260 data={'track': 'requests'}, auth=('username', 'password'))261262 for line in r.iter_lines():263 if line: # filter out keep-alive new lines264 print json.loads(line)265266267Verbose Logging268---------------269270If you want to get a good look at what HTTP requests are being sent
8 unmodified lines
modified:requests/models.py+6 added-1 removed
595 unmodified lines
596597 def generate():598 chunk = []599600 while 1:600 while True:601 c = self.raw.read(1)602 if not c:603 break604
2 unmodified lines
607 chunk = []608 else:609 chunk.append(c)610611 # Yield the remainder, in case the response612 # did not terminate with a newline613 if chunk:614 yield ''.join(chunk)615616 self._content_consumed = True617618 gen = generate()619
75 unmodified lines
modified:AUTHORS.rst+1 added
65 unmodified lines
66- Ed Summers67- Chris Van Horne68- Christopher Davis69- Ori Livneh70- Jason Emerick
modified:test_requests.py+17 added
1 unmodified line
2# -*- coding: utf-8 -*-34from __future__ import with_statement56import StringIO7import time8import os9import unittest10
592 unmodified lines
603 len_lines = len([l for l in r.iter_lines()])604605 self.assertEqual(i, len_lines)606607 # Test 'dangling' fragment in responses that do not terminate in608 # a newline.609 quote = (610 '''Why will he not upon our fair request\n'''611 '''Untent his person and share the air with us?'''612 )613614 # Make a request and monkey-patch its contents615 r = requests.get(httpbin('get'))616 r.raw = StringIO.StringIO(quote)617618 # Make sure iter_lines doesn't chop the trailing bit619 lines = '\n'.join(r.iter_lines())620 self.assertEqual(lines, quote)621622623if __name__ == '__main__':624 unittest.main()