Skip to content
Myr

Merge branch 'release/0.2.3'

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 ed909ea, d525680 · Browse files · 5 files+62 added−16 removed
This commit

State

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

Diff stats

5 files+62 added−16 removed

  • other:+62 added−16 removed

5 files+62 added−16 removed

modified:requests/core.py+22 added-13 removed
11 unmodified lines
1213import urllib14import urllib21516from urllib2 import HTTPError1718try:19 import eventlet20 eventlet.monkey_patch()
12 unmodified lines
33from .packages.poster.streaminghttp import register_openers343536__title__ = 'requests'36__version__ = '0.2.2'37__build__ = 0x00020237__version__ = '0.2.3'38__build__ = 0x00020339__author__ = 'Kenneth Reitz'40__license__ = 'ISC'41__copyright__ = 'Copyright 2011 Kenneth Reitz'42
116 unmodified lines
159 # url encode GET params if it's a dict160 if isinstance(self.params, dict):161 params = urllib.urlencode(self.params)162 else:162163 params = self.params164165 req = _Request(("%s?%s" % (self.url, params)), method=self.method)166
4 unmodified lines
171172 try:173 resp = opener(req)174 self._build_response(resp)175 success = True175 self.response.ok = True176177 except urllib2.HTTPError as why:178 self._build_response(why)179 success = False179 self.response.error = why180181182 elif self.method == 'PUT':183 if (not self.sent) or anyway:
19 unmodified lines
203 opener = self._get_opener()204 resp = opener(req)205206 self._build_response(resp)207 success = True207 self.response.ok = True208209 except urllib2.HTTPError as why:210 self._build_response(why)211 success = False211 self.response.error = why212213214 elif self.method == 'POST':215 if (not self.sent) or anyway:
16 unmodified lines
232 else:233 req.data = self.data234235 try:236236 opener = self._get_opener()237 resp = opener(req)238239 self._build_response(resp)241 success = True240 self.response.ok = True241242 except urllib2.HTTPError as why:243 self._build_response(why)245 success = False246244 self.response.error = why245 248 self.sent = True if success else False246 self.sent = self.response.ok247 250 return success248 return self.sent249 250251class Response(object):252 """The :class:`Request` object. All :class:`Request` objects contain a
5 unmodified lines
258 self.content = None259 self.status_code = None260 self.headers = dict()261 self.url = None262 self.ok = False263 self.error = None264 265 def __repr__(self):266 return '<Response [%s]>' % (self.status_code)267 268 def __nonzero__(self):269 """Returns true if status_code is 'OK'."""270 return not self.error271 272 def raise_for_status(self):273 """Raises stored HTTPError if one exists."""274 if self.error:275 raise self.error276277278 279class AuthObject(object):
193 unmodified lines
modified:AUTHORS+2 added-1 removed
8 unmodified lines
910Patches and Suggestions11```````````````````````1213- Various Pocoo Members13- Various Pocoo Members14- Chris Adams
modified:HISTORY.rst+10 added
1History2-------340.2.3 (2011-02-15)5++++++++++++++++++67* New HTTPHandling Methods8 - Reponse.__nonzero__ (false if bad HTTP Status)9 - Response.ok (True if expected HTTP Status)10 - Response.error (Logged HTTPError if bad HTTP Status)11 - Reponse.raise_for_status() (Raises stored HTTPError)1213140.2.2 (2011-02-14)15++++++++++++++++++1617* Still handles request in the event of an HTTPError. (Issue #2)
23 unmodified lines
modified:setup.py+1 added-1 removed
20 unmodified lines
21# if python > 2.6, require simplejson2223setup(24 name='requests',25 version='0.2.2',25 version='0.2.3',26 description='Awesome Python HTTP Library that\'s actually usable.',27 long_description=open('README.rst').read() + '\n\n' +28 open('HISTORY.rst').read(),29 author='Kenneth Reitz',
22 unmodified lines
modified:test_requests.py+27 added-1 removed
1#!/usr/bin/env python2# -*- coding: utf-8 -*-344import unittest5from cStringIO import StringIO67import requests
11 unmodified lines
19 20 def test_invalid_url(self):21 self.assertRaises(ValueError, requests.get, 'hiwpefhipowhefopw')222324 def test_HTTP_200_OK_GET(self):25 r = requests.get('http://google.com')26 self.assertEqual(r.status_code, 200)272829 def test_HTTPS_200_OK_GET(self):30 r = requests.get('https://google.com')31 self.assertEqual(r.status_code, 200)323334 def test_HTTP_200_OK_HEAD(self):35 r = requests.head('http://google.com')36 self.assertEqual(r.status_code, 200)373839 def test_HTTPS_200_OK_HEAD(self):40 r = requests.head('https://google.com')41 self.assertEqual(r.status_code, 200)424344 def test_AUTH_HTTPS_200_OK_GET(self):45 auth = requests.AuthObject('requeststest', 'requeststest')46 url = 'https://convore.com/api/account/verify.json'47 r = requests.get(url, auth=auth)4849 self.assertEqual(r.status_code, 200)505152 def test_POSTBIN_GET_POST_FILES(self):5354 bin = requests.post('http://www.postbin.org/')55 self.assertEqual(bin.status_code, 200)
4 unmodified lines
60 post2 = requests.post(bin.url, files={'some': StringIO('data')})61 self.assertEqual(post2.status_code, 201)626364 def test_nonzero_evaluation(self):65 r = requests.get('http://google.com/some-404-url')66 self.assertEqual(bool(r), False)67 68 r = requests.get('http://google.com/')69 self.assertEqual(bool(r), True)707172 def test_request_ok_set(self):73 r = requests.get('http://google.com/some-404-url')74 self.assertEqual(r.ok, False)757677 def test_status_raising(self):78 r = requests.get('http://google.com/some-404-url')79 self.assertRaises(requests.HTTPError, r.raise_for_status)8081 r = requests.get('http://google.com/')82 self.assertFalse(r.error)83 r.raise_for_status()848586if __name__ == '__main__':87 unittest.main()