Skip to content
Myr

Merge branch 'release/0.9.4'

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 53e785f, d3911da · Browse files · 10 files+353 added−364 removed
This commit

State

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

Diff stats

10 files+353 added−364 removed

  • other:+353 added−364 removed

10 files+353 added−364 removed

modified:requests/packages/poster/__init__.py+2 added
24 unmodified lines
25New releases of poster will always have a version number that compares greater26than an older version of poster.27New in version 0.6."""2829from __future__ import absolute_import3031from . import streaminghttp32from . import encode3334version = (0, 8, 0) # Thanks JP!
modified:requests/packages/__init__.py+2 added
1from __future__ import absolute_import23from . import poster
modified:requests/core.py+236 added-274 removed
8 unmodified lines
9 :copyright: (c) 2011 by Kenneth Reitz.10 :license: ISC, see LICENSE for more details.11"""1213from __future__ import absolute_import14import urllib15import urllib21617from urllib2 import HTTPError1819try:19 import eventlet20 eventlet.monkey_patch()20 import eventlet21 eventlet.monkey_patch()22except ImportError:22 pass23 pass2425if not 'eventlet' in locals():25 try:26 from gevent import monkey27 monkey.patch_all()28 except ImportError:29 pass26 try:27 from gevent import monkey28 monkey.patch_all()29 except ImportError:30 pass313132from .packages.poster.encode import multipart_encode33from .packages.poster.streaminghttp import register_openers3435
7 unmodified lines
4344AUTOAUTHS = []45464748class _Request(urllib2.Request):48 """Hidden wrapper around the urllib2.Request object. Allows for manual49 """Hidden wrapper around the urllib2.Request object. Allows for manual50 setting of HTTP methods.51 """51 52 def __init__(self, url, data=None, headers={}, origin_req_host=None, unverifiable=False, method=None):53 urllib2.Request.__init__( self, url, data, headers, origin_req_host, unverifiable)54 self.method = method52 53 def __init__(self, url, data=None, headers={}, origin_req_host=None,54 unverifiable=False, method=None):55 urllib2.Request.__init__(self, url, data, headers, origin_req_host, unverifiable)56 self.method = method5756 def get_method(self):57 if self.method:58 return self.method58 def get_method(self):59 if self.method:60 return self.method6160 return urllib2.Request.get_method(self)62 return urllib2.Request.get_method(self)636465class Request(object):64 """The :class:`Request` object. It carries out all functionality of66 """The :class:`Request` object. It carries out all functionality of67 Requests. Recommended interface is with the Requests functions.68 """69 67 68 _METHODS = ('GET', 'HEAD', 'PUT', 'POST', 'DELETE')69 70 def __init__(self):71 self.url = None72 self.headers = dict()73 self.files = None74 self.method = None75 self.params = {}76 self.data = {}77 self.response = Response()78 79 self.auth = None80 self.cookiejar = None81 self.sent = False82 83 84 def __repr__(self):85 return '<Request [%s]>' % (self.method)86 87 88 def __setattr__(self, name, value):89 if (name == 'method') and (value):90 if not value in self._METHODS:91 raise InvalidMethod()92 93 object.__setattr__(self, name, value)94 95 96 def _checks(self):97 """Deterministic checks for consistency."""70 _METHODS = ('GET', 'HEAD', 'PUT', 'POST', 'DELETE')71 72 def __init__(self, url=None, headers=dict(), files=None, method=None,73 params=dict(), data=dict(), auth=None, cookiejar=None):74 self.url = url75 self.headers = headers76 self.files = files77 self.method = method78 self.params = params79 self.data = data80 self.response = Response()81 82 self.auth = auth83 self.cookiejar = cookiejar84 self.sent = False85 86 87 def __repr__(self):88 return '<Request [%s]>' % (self.method)89 90 91 def __setattr__(self, name, value):92 if (name == 'method') and (value):93 if not value in self._METHODS:94 raise InvalidMethod()95 96 object.__setattr__(self, name, value)97 98 99 def _checks(self):100 """Deterministic checks for consistency."""10199 if not self.url:100 raise URLRequired102 if not self.url:103 raise URLRequired104102 103 def _get_opener(self):104 """Creates appropriate opener object for urllib2."""105 106 def _get_opener(self):107 """Creates appropriate opener object for urllib2."""108106 _handlers = []109 _handlers = []110108 if self.auth or self.cookiejar:111 if self.auth or self.cookiejar:112110 if self.auth:113 if self.auth:114112 authr = urllib2.HTTPPasswordMgrWithDefaultRealm()115 authr = urllib2.HTTPPasswordMgrWithDefaultRealm()116114 authr.add_password(None, self.url, self.auth.username, self.auth.password)115 auth_handler = urllib2.HTTPBasicAuthHandler(authr)117 authr.add_password(None, self.url, self.auth.username, self.auth.password)118 auth_handler = urllib2.HTTPBasicAuthHandler(authr)119117 _handlers.append(auth_handler)120 _handlers.append(auth_handler)121119 if self.cookiejar:122 if self.cookiejar:123121 cookie_handler = urllib2.HTTPCookieProcessor(cookiejar)122 _handlers.append(cookie_handler)124 cookie_handler = urllib2.HTTPCookieProcessor(cookiejar)125 _handlers.append(cookie_handler)126124 opener = urllib2.build_opener(*_handlers)125 return opener.open127 opener = urllib2.build_opener(*_handlers)128 return opener.open129127 else:128 return urllib2.urlopen130 else:131 return urllib2.urlopen132133131 def _build_response(self, resp):132 """Build internal Response object from given response."""133 134 self.response.status_code = resp.code135 self.response.headers = resp.info().dict136 self.response.content = resp.read()137 self.response.url = resp.url134 def _build_response(self, resp):135 """Build internal Response object from given response."""136 137 self.response.status_code = resp.code138 self.response.headers = resp.info().dict139 self.response.content = resp.read()140 self.response.url = resp.url141139 140 def send(self, anyway=False):141 """Sends the request. Returns True of successful, false if not.142 143 def send(self, anyway=False):144 """Sends the request. Returns True of successful, false if not.145 If there was an HTTPError during transmission,146 self.response.status_code will contain the HTTPError code.147148 Once a request is successfully sent, `sent` will equal True.
1 unmodified line
150 :param anyway: If True, request will be sent, even if it has151 already been sent.152 """153151 self._checks()154 self._checks()155153 success = False156 success = False157158156 if self.method in ('GET', 'HEAD', 'DELETE'):157 if (not self.sent) or anyway:159 if self.method in ('GET', 'HEAD', 'DELETE'):160 if (not self.sent) or anyway:161159 # url encode GET params if it's a dict160 if isinstance(self.params, dict):161 params = urllib.urlencode(self.params)162 else:163 params = self.params162 # url encode GET params if it's a dict163 if isinstance(self.params, dict):164 params = urllib.urlencode(self.params)165 else:166 params = self.params167165 req = _Request(("%s?%s" % (self.url, params)), method=self.method)168 req = _Request(("%s?%s" % (self.url, params)), method=self.method)169167 if self.headers:168 req.headers = self.headers170 if self.headers:171 req.headers = self.headers172170 opener = self._get_opener()173 opener = self._get_opener()174172 try:173 resp = opener(req)174 self._build_response(resp)175 self.response.ok = True175 try:176 resp = opener(req)177 self._build_response(resp)178 self.response.ok = True179177 except urllib2.HTTPError as why:178 self._build_response(why)179 self.response.error = why180 except urllib2.HTTPError as why:181 self._build_response(why)182 self.response.error = why183184182 elif self.method == 'PUT':183 if (not self.sent) or anyway:185 elif self.method == 'PUT':186 if (not self.sent) or anyway:187185 if self.files:186 register_openers()187 datagen, headers = multipart_encode(self.files)188 req = _Request(self.url, data=datagen, headers=headers, method='PUT')188 if self.files:189 register_openers()190 datagen, headers = multipart_encode(self.files)191 req = _Request(self.url, data=datagen, headers=headers, method='PUT')192190 if self.headers:191 req.headers.update(self.headers)193 if self.headers:194 req.headers.update(self.headers)195193 else:196 else:197195 req = _Request(self.url, method='PUT')198 req = _Request(self.url, method='PUT')199197 if self.headers:198 req.headers = self.headers200 if self.headers:201 req.headers = self.headers202200 req.data = self.data203 req.data = self.data204202 try:203 opener = self._get_opener()204 resp = opener(req)205 try:206 opener = self._get_opener()207 resp = opener(req)208206 self._build_response(resp)207 self.response.ok = True209 self._build_response(resp)210 self.response.ok = True211209 except urllib2.HTTPError as why:210 self._build_response(why)211 self.response.error = why212 except urllib2.HTTPError as why:213 self._build_response(why)214 self.response.error = why215216214 elif self.method == 'POST':215 if (not self.sent) or anyway:217 elif self.method == 'POST':218 if (not self.sent) or anyway:219217 if self.files:218 register_openers()219 datagen, headers = multipart_encode(self.files)220 req = _Request(self.url, data=datagen, headers=headers, method='POST')220 if self.files:221 register_openers()222 datagen, headers = multipart_encode(self.files)223 req = _Request(self.url, data=datagen, headers=headers, method='POST')224222 if self.headers:223 req.headers.update(self.headers)224 225 else:226 req = _Request(self.url, method='POST')227 req.headers = self.headers225 if self.headers:226 req.headers.update(self.headers)227 228 else:229 req = _Request(self.url, method='POST')230 req.headers = self.headers231229 # url encode form data if it's a dict230 if isinstance(self.data, dict):231 req.data = urllib.urlencode(self.data)232 else:233 req.data = self.data232 # url encode form data if it's a dict233 if isinstance(self.data, dict):234 req.data = urllib.urlencode(self.data)235 else:236 req.data = self.data237235 try:236 opener = self._get_opener()237 resp = opener(req)238 try:239 opener = self._get_opener()240 resp = opener(req)241239 self._build_response(resp)240 self.response.ok = True242 self._build_response(resp)243 self.response.ok = True244242 except urllib2.HTTPError as why:243 self._build_response(why)244 self.response.error = why245 246 self.sent = self.response.ok247 248 return self.sent249 245 except urllib2.HTTPError as why:246 self._build_response(why)247 self.response.error = why248 249 self.sent = self.response.ok250 251 return self.sent252 253254class Response(object):252 """The :class:`Request` object. All :class:`Request` objects contain a255 """The :class:`Request` object. All :class:`Request` objects contain a256 :class:`Request.response <response>` attribute, which is an instance of257 this class.258 """259257 def __init__(self):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.error260 def __init__(self):261 self.content = None262 self.status_code = None263 self.headers = dict()264 self.url = None265 self.ok = False266 self.error = None267 268 def __repr__(self):269 return '<Response [%s]>' % (self.status_code)270 271 def __nonzero__(self):272 """Returns true if status_code is 'OK'."""273 return not self.error274 275 def raise_for_status(self):276 """Raises stored HTTPError if one exists."""277 if self.error:278 raise self.error279280278 281 282class AuthObject(object):280 """The :class:`AuthObject` is a simple HTTP Authentication token. When283 """The :class:`AuthObject` is a simple HTTP Authentication token. When284 given to a Requests function, it enables Basic HTTP Authentication for that285 Request. You can also enable Authorization for domain realms with AutoAuth.286 See AutoAuth for more details.287 288 :param username: Username to authenticate with.289 :param password: Password for given username.290 """288 289 def __init__(self, username, password):290 self.username = username291 self.password = password291 292 def __init__(self, username, password):293 self.username = username294 self.password = password295296297298def get(url, params={}, headers={}, cookies=None, auth=None):296 """Sends a GET request. Returns :class:`Response` object.299 """Sends a GET request. Returns :class:`Response` object.300301 :param url: URL for the new :class:`Request` object.302 :param params: (optional) Dictionary of GET Parameters to send with the :class:`Request`.303 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.304 :param cookies: (optional) CookieJar object to send with the :class:`Request`.305 :param auth: (optional) AuthObject to enable Basic HTTP Auth.306 """304 305 r = Request()306 307 r.method = 'GET'308 r.url = url309 r.params = params310 r.headers = headers311 r.cookiejar = cookies312 r.auth = _detect_auth(url, auth)313 314 r.send()315 316 return r.response307 308 r = Request(method='GET', url=url, params=params, headers=headers,309 cookiejar=cookies, auth=_detect_auth(url, auth))310 r.send()311 312 return r.response313314315def head(url, params={}, headers={}, cookies=None, auth=None):320 """Sends a HEAD request. Returns :class:`Response` object.316 """Sends a HEAD request. Returns :class:`Response` object.317318 :param url: URL for the new :class:`Request` object.319 :param params: (optional) Dictionary of GET Parameters to send with the :class:`Request`.320 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.321 :param cookies: (optional) CookieJar object to send with the :class:`Request`.322 :param auth: (optional) AuthObject to enable Basic HTTP Auth.323 """328 329 r = Request()330 331 r.method = 'HEAD'332 r.url = url333 # return response object334 r.params = params335 r.headers = headers336 r.cookiejar = cookies337 r.auth = _detect_auth(url, auth)338 339 r.send()340 341 return r.response324 r = Request(method='HEAD', url=url, params=params, headers=headers,325 cookiejar=cookies, auth=_detect_auth(url, auth))326 r.send()327 328 return r.response329330331def post(url, data={}, headers={}, files=None, cookies=None, auth=None):345 """Sends a POST request. Returns :class:`Response` object.332 """Sends a POST request. Returns :class:`Response` object.333334 :param url: URL for the new :class:`Request` object.335 :param data: (optional) Dictionary of POST Data to send with the :class:`Request`.336 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.337 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.338 :param cookies: (optional) CookieJar object to send with the :class:`Request`.339 :param auth: (optional) AuthObject to enable Basic HTTP Auth.340 """354 355 r = Request()356 357 r.url = url358 r.method = 'POST'359 r.data = data360 361 if files:362 r.files = files363 364 r.headers = headers365 r.cookiejar = cookies366 r.auth = _detect_auth(url, auth)367 368 r.send()369 370 return r.response371 372 341 342 r = Request(method='POST', url=url, data=data, headers=headers,343 files=files, cookiejar=cookies, auth=_detect_auth(url, auth))344 r.send()345 346 return r.response347 348 349def put(url, data='', headers={}, files={}, cookies=None, auth=None):374 """Sends a PUT request. Returns :class:`Response` object.350 """Sends a PUT request. Returns :class:`Response` object.351352 :param url: URL for the new :class:`Request` object.353 :param data: (optional) Bytes of PUT Data to send with the :class:`Request`.354 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.355 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.356 :param cookies: (optional) CookieJar object to send with the :class:`Request`.357 :param auth: (optional) AuthObject to enable Basic HTTP Auth.358 """383 384 r = Request()359386 r.url = url387 r.method = 'PUT'388 r.data = data389 r.files = files390 r.headers = headers391 r.cookiejar = cookies392 r.auth = _detect_auth(url, auth)393 394 r.send()395 396 return r.response360 r = Request(method='PUT', url=url, data=data, headers=headers, files=files,361 cookiejar=cookies, auth=_detect_auth(url, auth))362 r.send()363 364 return r.response365398 366 367def delete(url, params={}, headers={}, cookies=None, auth=None):400 """Sends a DELETE request. Returns :class:`Response` object.368 """Sends a DELETE request. Returns :class:`Response` object.369370 :param url: URL for the new :class:`Request` object.371 :param params: (optional) Dictionary of GET Parameters to send with the :class:`Request`.372 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.373 :param cookies: (optional) CookieJar object to send with the :class:`Request`.374 :param auth: (optional) AuthObject to enable Basic HTTP Auth.375 """408 409 r = Request()376 377 r = Request(method='DELETE', url=url, params=params, headers=headers,378 cookiejar=cookies, auth=_detect_auth(url, auth))379 r.send()380 381 return r.response382411 r.url = url412 r.method = 'DELETE'413 414 r.headers = headers415 r.cookiejar = cookies416 r.auth = _detect_auth(url, auth)417 418 r.send()419 420 return r.response383422384def add_autoauth(url, authobject):424 """Registers given AuthObject to given URL domain. for auto-activation.385 """Registers given AuthObject to given URL domain. for auto-activation.386 Once a URL is registered with an AuthObject, the configured HTTP387 Authentication will be used for all requests with URLS containing the given388 URL string.389
6 unmodified lines
396 :param url: Base URL for given AuthObject to auto-activate for.397 :param authobject: AuthObject to auto-activate.398 """399439 global AUTOAUTHS440 441 AUTOAUTHS.append((url, authobject))400 global AUTOAUTHS401 402 AUTOAUTHS.append((url, authobject))403404405def _detect_auth(url, auth):445 """Returns registered AuthObject for given url if available, defaulting to406 """Returns registered AuthObject for given url if available, defaulting to407 given AuthObject.408 """409449 return _get_autoauth(url) if not auth else auth410 return _get_autoauth(url) if not auth else auth411451 412 413def _get_autoauth(url):453 """Returns registered AuthObject for given url if available."""454 455 for (autoauth_url, auth) in AUTOAUTHS:456 if autoauth_url in url: 457 return auth458 459 return None414 """Returns registered AuthObject for given url if available."""415 416 for (autoauth_url, auth) in AUTOAUTHS:417 if autoauth_url in url: 418 return auth419 420 return None421422423class RequestException(Exception):463 """There was an ambiguous exception that occured while handling your request."""424 """There was an ambiguous exception that occured while handling your425 request."""426427class AuthenticationError(RequestException):466 """The authentication credentials provided were invalid."""467 428 """The authentication credentials provided were invalid."""429 430class URLRequired(RequestException):469 """A valid URL is required to make a request."""470 431 """A valid URL is required to make a request."""432 433class InvalidMethod(RequestException):472 """An inappropriate method was attempted."""434 """An inappropriate method was attempted."""
modified:.gitignore+4 added-1 removed
1.idea2MANIFEST2MANIFEST3coverage.xml4nosetests.xml5pylint.txt
modified:HISTORY.rst+4 added-4 removed
3 unmodified lines
40.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)8 - 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++++++++++++++++++
25 unmodified lines
modified:README.rst+13 added-4 removed
83 unmodified lines
84 8586**Responses:**87 88 Request.status_code:88 Response.status_code:89 (Integer) Received HTTP Status Code Response9091 Request.headers:91 Response.headers:92 (Dictionary) Received HTTP Response Headers9394 Request.content:94 Response.content:95 (Bytes) Received Content9697 Request.url97 Response.url98 (String) URL of response. Useful for detecting redirects. 99 100 Response.ok101 (Bool) True if no errors occurred during the request, and the status_code is kosher.102 103 Response.error104 (HTTPError) If an HTTPError occurred (e.g. status of 404), Otherwise this is None.105 106 Response.raise_for_status()107 Raises HTTPError if a request is not kosher.108109110**HTTP Authentication Registry:**111
36 unmodified lines
modified:setup.py+31 added-31 removed
5 unmodified lines
67from distutils.core import setup8910 10 11if sys.argv[-1] == "publish":12 os.system("python setup.py sdist upload")13 sys.exit()12 os.system("python setup.py sdist upload")13 sys.exit()1415if sys.argv[-1] == "test":16 os.system("python test_requests.py")17 sys.exit()18 16 os.system("python test_requests.py")17 sys.exit()18 19required = []2021# if python > 2.6, require simplejson2223setup(24 name='requests',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',30 author_email='me@kennethreitz.com',31 url='https://github.com/kennethreitz/requests',32 packages= [33 'requests',34 'requests.packages',35 'requests.packages.poster'36 ],37 install_requires=required,38 license='ISC',39 classifiers=(40 # 'Development Status :: 5 - Production/Stable',41 'Intended Audience :: Developers',42 'Natural Language :: English',43 'License :: OSI Approved :: ISC License (ISCL)',44 'Programming Language :: Python',24 name='requests',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',30 author_email='me@kennethreitz.com',31 url='https://github.com/kennethreitz/requests',32 packages= [33 'requests',34 'requests.packages',35 'requests.packages.poster'36 ],37 install_requires=required,38 license='ISC',39 classifiers=(40 # 'Development Status :: 5 - Production/Stable',41 'Intended Audience :: Developers',42 'Natural Language :: English',43 'License :: OSI Approved :: ISC License (ISCL)',44 'Programming Language :: Python',45 # 'Programming Language :: Python :: 2.5',46 'Programming Language :: Python :: 2.6',47 'Programming Language :: Python :: 2.7',48 # 'Programming Language :: Python :: 3.0',49 # 'Programming Language :: Python :: 3.1',50 ),47 'Programming Language :: Python :: 2.7',48 # 'Programming Language :: Python :: 3.0',49 # 'Programming Language :: Python :: 3.1',50 ),51)
modified:test_requests.py+50 added-50 removed
6 unmodified lines
7import requests8910class RequestsTestSuite(unittest.TestCase):11 """Requests test cases."""12 13 def setUp(self):14 pass11 """Requests test cases."""12 13 def setUp(self):14 pass1516 def tearDown(self):17 """Teardown."""18 pass19 20 def test_invalid_url(self):21 self.assertRaises(ValueError, requests.get, 'hiwpefhipowhefopw')16 def tearDown(self):17 """Teardown."""18 pass19 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)24 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)29 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)34 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)39 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)44 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)49 self.assertEqual(r.status_code, 200)505152 def test_POSTBIN_GET_POST_FILES(self):52 def test_POSTBIN_GET_POST_FILES(self):5354 bin = requests.post('http://www.postbin.org/')55 self.assertEqual(bin.status_code, 200)54 bin = requests.post('http://www.postbin.org/')55 self.assertEqual(bin.status_code, 200)5657 post = requests.post(bin.url, data={'some': 'data'})58 self.assertEqual(post.status_code, 201)57 post = requests.post(bin.url, data={'some': 'data'})58 self.assertEqual(post.status_code, 201)5960 post2 = requests.post(bin.url, files={'some': StringIO('data')})61 self.assertEqual(post2.status_code, 201)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)64 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)72 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)77 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()81 r = requests.get('http://google.com/')82 self.assertFalse(r.error)83 r.raise_for_status()848586if __name__ == '__main__':87 unittest.main()87 unittest.main()
added:test_suite.sh+4 added
1tox 2coverage xml3rm -fr pylint.txt4pylint -d W0312 -d W0212 -d E1101 -d E0202 -d W0102 -d E0102 -f parseable ./requests > pylint.txt || true
added:tox.ini+7 added
1[tox]2envlist = py24,py25,py26,py2734[testenv]5commands=py.test --junitxml=junit-{envname}.xml6deps = 7 pytest