Merge branch 'master' of git://github.com/kennethreitz/requests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Ovidiu Negrut · committed by Ovidiu Negrut · parents e752455, 12ef43e · Browse files · 22 files·+208 added−63 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
22 files+208 added−63 removed
- other:+208 added−63 removed
Provenance
- Commit
186a589- Tree
0cffc6c- Author
Ovidiu Negrut <ovidiu@rohost.com>- Committer
Ovidiu Negrut <ovidiu@rohost.com>- Parent 1
e752455- Parent 2
12ef43e
22 files changed+208 added−63 removed
modified:docs/dev/todo.rst+2 added-2 removed
21 unmodified lines22 ------------------------23 24 You'll need to install py.test in order to run the Requests' test suite::25 26- $ make test-deps27- $ make test26+ $ pip install -r requirements.txt27+ $ invoke test28 py.test29 platform darwin -- Python 2.7.3 -- pytest-2.3.430 collected 25 items31 24 unmodified linesmodified:docs/conf.py-1 removed
132 unmodified lines133 # typographically correct entities.134 #html_use_smartypants = True135 136 # Custom sidebar templates, maps document names to template names.137-# Custom sidebar templates, maps document names to template names.137 html_sidebars = {138 'index': ['sidebarintro.html', 'sourcelink.html', 'searchbox.html'],139 '**': ['sidebarlogo.html', 'localtoc.html', 'relations.html',140 'sourcelink.html', 'searchbox.html']103 unmodified linesmodified:requests/packages/charade/__init__.py+6 added-1 removed
13 unmodified lines14 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA15 # 02110-1301 USA16 ######################### END LICENSE BLOCK #########################17 18-__version__ = "1.0.1"18+__version__ = "1.0.3"19+from sys import version_info20 21 22 def detect(aBuf):23+ if ((version_info < (3, 0) and isinstance(aBuf, unicode)) or24+ (version_info >= (3, 0) and not isinstance(aBuf, bytes))):25+ raise ValueError('Expected a bytes object, not a unicode object')26+27 from . import universaldetector28 u = universaldetector.UniversalDetector()29 u.reset()30 u.feed(aBuf)2 unmodified linesmodified:requests/packages/charade/chardistribution.py+2 added-1 removed
38 unmodified lines39 40 ENOUGH_DATA_THRESHOLD = 102441 SURE_YES = 0.9942 SURE_NO = 0.0143+MINIMUM_DATA_THRESHOLD = 344 45 46 class CharDistributionAnalysis:47 def __init__(self):34 unmodified lines82 def get_confidence(self):83 """return confidence based on existing data"""84 # if we didn't receive any character in our consideration range,85 # return negative answer85- if self._mTotalChars <= 0:86+ if self._mTotalChars <= 0 or self._mFreqChars <= MINIMUM_DATA_THRESHOLD:87 return SURE_NO88 89 if self._mTotalChars != self._mFreqChars:90 r = (self._mFreqChars / ((self._mTotalChars - self._mFreqChars)141 unmodified linesmodified:requests/packages/charade/compat.py+10 added-2 removed
16 unmodified lines17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA18 # 02110-1301 USA19 ######################### END LICENSE BLOCK #########################20 21+import sys22 23+24+if sys.version_info < (3, 0):25+ base_str = (str, unicode)26+else:27+ base_str = (bytes, str)28+29+30 def wrap_ord(a):23- if isinstance(a, str):31+ if sys.version_info < (3, 0) and isinstance(a, base_str):32 return ord(a)25- elif isinstance(a, int):33+ else:34 return aadded:requests/packages/charade/cp949prober.py+44 added
1+######################## BEGIN LICENSE BLOCK ########################2+# The Original Code is mozilla.org code.3+#4+# The Initial Developer of the Original Code is5+# Netscape Communications Corporation.6+# Portions created by the Initial Developer are Copyright (C) 19987+# the Initial Developer. All Rights Reserved.8+#9+# Contributor(s):10+# Mark Pilgrim - port to Python11+#12+# This library is free software; you can redistribute it and/or13+# modify it under the terms of the GNU Lesser General Public14+# License as published by the Free Software Foundation; either15+# version 2.1 of the License, or (at your option) any later version.16+#17+# This library is distributed in the hope that it will be useful,18+# but WITHOUT ANY WARRANTY; without even the implied warranty of19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU20+# Lesser General Public License for more details.21+#22+# You should have received a copy of the GNU Lesser General Public23+# License along with this library; if not, write to the Free Software24+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25+# 02110-1301 USA26+######################### END LICENSE BLOCK #########################27+28+from .mbcharsetprober import MultiByteCharSetProber29+from .codingstatemachine import CodingStateMachine30+from .chardistribution import EUCKRDistributionAnalysis31+from .mbcssm import CP949SMModel32+33+34+class CP949Prober(MultiByteCharSetProber):35+ def __init__(self):36+ MultiByteCharSetProber.__init__(self)37+ self._mCodingSM = CodingStateMachine(CP949SMModel)38+ # NOTE: CP949 is a superset of EUC-KR, so the distribution should be39+ # not different.40+ self._mDistributionAnalyzer = EUCKRDistributionAnalysis()41+ self.reset()42+43+ def get_charset_name(self):44+ return "CP949"modified:requests/packages/charade/langcyrillicmodel.py-2 removed
23 unmodified lines24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25 # 02110-1301 USA26 ######################### END LICENSE BLOCK #########################27 28-from . import constants29-28 # KOI8-R language model29 # Character Mapping Table:30 KOI8R_CharToOrderMap = (31 255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00298 unmodified linesmodified:requests/packages/charade/langgreekmodel.py-2 removed
23 unmodified lines24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25 # 02110-1301 USA26 ######################### END LICENSE BLOCK #########################27 28-from . import constants29-28 # 255: Control characters that usually does not exist in any text29 # 254: Carriage/Return30 # 253: symbol (punctuation) that does not belong to word31 # 252: 0 - 9194 unmodified linesmodified:requests/packages/charade/langhebrewmodel.py-2 removed
25 unmodified lines26 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA27 # 02110-1301 USA28 ######################### END LICENSE BLOCK #########################29 30-from . import constants31-30 # 255: Control characters that usually does not exist in any text31 # 254: Carriage/Return32 # 253: symbol (punctuation) that does not belong to word33 # 252: 0 - 9168 unmodified linesmodified:requests/packages/charade/langhungarianmodel.py-2 removed
23 unmodified lines24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25 # 02110-1301 USA26 ######################### END LICENSE BLOCK #########################27 28-from . import constants29-28 # 255: Control characters that usually does not exist in any text29 # 254: Carriage/Return30 # 253: symbol (punctuation) that does not belong to word31 # 252: 0 - 9194 unmodified linesmodified:requests/packages/charade/mbcsgroupprober.py+2 added
31 unmodified lines32 from .sjisprober import SJISProber33 from .eucjpprober import EUCJPProber34 from .gb2312prober import GB2312Prober35 from .euckrprober import EUCKRProber36+from .cp949prober import CP949Prober37 from .big5prober import Big5Prober38 from .euctwprober import EUCTWProber39 40 5 unmodified lines46 SJISProber(),47 EUCJPProber(),48 GB2312Prober(),49 EUCKRProber(),50+ CP949Prober(),51 Big5Prober(),52 EUCTWProber()53 ]54 self.reset()modified:requests/packages/charade/mbcssm.py+40 added
76 unmodified lines77 'stateTable': BIG5_st,78 'charLenTable': Big5CharLenTable,79 'name': 'Big5'}80 81+# CP94982+83+CP949_cls = (84+ 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,0,0, # 00 - 0f85+ 1,1,1,1,1,1,1,1, 1,1,1,0,1,1,1,1, # 10 - 1f86+ 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, # 20 - 2f87+ 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, # 30 - 3f88+ 1,4,4,4,4,4,4,4, 4,4,4,4,4,4,4,4, # 40 - 4f89+ 4,4,5,5,5,5,5,5, 5,5,5,1,1,1,1,1, # 50 - 5f90+ 1,5,5,5,5,5,5,5, 5,5,5,5,5,5,5,5, # 60 - 6f91+ 5,5,5,5,5,5,5,5, 5,5,5,1,1,1,1,1, # 70 - 7f92+ 0,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6, # 80 - 8f93+ 6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6, # 90 - 9f94+ 6,7,7,7,7,7,7,7, 7,7,7,7,7,8,8,8, # a0 - af95+ 7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7, # b0 - bf96+ 7,7,7,7,7,7,9,2, 2,3,2,2,2,2,2,2, # c0 - cf97+ 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, # d0 - df98+ 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, # e0 - ef99+ 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,0, # f0 - ff100+)101+102+CP949_st = (103+#cls= 0 1 2 3 4 5 6 7 8 9 # previous state =104+ eError,eStart, 3,eError,eStart,eStart, 4, 5,eError, 6, # eStart105+ eError,eError,eError,eError,eError,eError,eError,eError,eError,eError, # eError106+ eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe, # eItsMe107+ eError,eError,eStart,eStart,eError,eError,eError,eStart,eStart,eStart, # 3108+ eError,eError,eStart,eStart,eStart,eStart,eStart,eStart,eStart,eStart, # 4109+ eError,eStart,eStart,eStart,eStart,eStart,eStart,eStart,eStart,eStart, # 5110+ eError,eStart,eStart,eStart,eStart,eError,eError,eStart,eStart,eStart, # 6111+)112+113+CP949CharLenTable = (0, 1, 2, 0, 1, 1, 2, 2, 0, 2)114+115+CP949SMModel = {'classTable': CP949_cls,116+ 'classFactor': 10,117+ 'stateTable': CP949_st,118+ 'charLenTable': CP949CharLenTable,119+ 'name': 'CP949'}120+121 # EUC-JP122 123 EUCJP_cls = (124 4,4,4,4,4,4,4,4, # 00 - 07451 unmodified linesmodified:requests/packages/charade/universaldetector.py+8 added-7 removed
26 unmodified lines27 ######################### END LICENSE BLOCK #########################28 29 from . import constants30 import sys31+import codecs32 from .latin1prober import Latin1Prober # windows-125233 from .mbcsgroupprober import MBCSGroupProber # multi-byte character sets34 from .sbcsgroupprober import SBCSGroupProber # single-byte character sets35 from .escprober import EscCharSetProber # ISO-2122, etc.34 unmodified lines70 return71 72 if not self._mGotData:73 # If the data starts with BOM, we know it is UTF73- if aBuf[:3] == '\xEF\xBB\xBF':74+ if aBuf[:3] == codecs.BOM:75 # EF BB BF UTF-8 with BOM76 self.result = {'encoding': "UTF-8", 'confidence': 1.0}76- elif aBuf[:4] == '\xFF\xFE\x00\x00':77+ elif aBuf[:4] == codecs.BOM_UTF32_LE:78 # FF FE 00 00 UTF-32, little-endian BOM79 self.result = {'encoding': "UTF-32LE", 'confidence': 1.0}79- elif aBuf[:4] == '\x00\x00\xFE\xFF':80+ elif aBuf[:4] == codecs.BOM_UTF32_BE:81 # 00 00 FE FF UTF-32, big-endian BOM82 self.result = {'encoding': "UTF-32BE", 'confidence': 1.0}82- elif aBuf[:4] == '\xFE\xFF\x00\x00':83+ elif aBuf[:4] == b'\xFE\xFF\x00\x00':84 # FE FF 00 00 UCS-4, unusual octet order BOM (3412)85 self.result = {86 'encoding': "X-ISO-10646-UCS-4-3412",87 'confidence': 1.088 }88- elif aBuf[:4] == '\x00\x00\xFF\xFE':89+ elif aBuf[:4] == b'\x00\x00\xFF\xFE':90 # 00 00 FF FE UCS-4, unusual octet order BOM (2143)91 self.result = {92 'encoding': "X-ISO-10646-UCS-4-2143",93 'confidence': 1.094 }94- elif aBuf[:2] == '\xFF\xFE':95+ elif aBuf[:2] == codecs.BOM_LE:96 # FF FE UTF-16, little endian BOM97 self.result = {'encoding': "UTF-16LE", 'confidence': 1.0}97- elif aBuf[:2] == '\xFE\xFF':98+ elif aBuf[:2] == codecs.BOM_BE:99 # FE FF UTF-16, big endian BOM100 self.result = {'encoding': "UTF-16BE", 'confidence': 1.0}101 102 self._mGotData = True70 unmodified linesmodified:requests/adapters.py+19 added
42 unmodified lines43 44 45 class HTTPAdapter(BaseAdapter):46 """Built-In HTTP Adapter for Urllib3."""47+ __attrs__ = ['max_retries', 'config', '_pool_connections', '_pool_maxsize']48+49 def __init__(self, pool_connections=DEFAULT_POOLSIZE, pool_maxsize=DEFAULT_POOLSIZE):50 self.max_retries = DEFAULT_RETRIES51 self.config = {}52 53 super(HTTPAdapter, self).__init__()54 55+ self._pool_connections = pool_connections56+ self._pool_maxsize = pool_maxsize57+58 self.init_poolmanager(pool_connections, pool_maxsize)59 60+ def __getstate__(self):61+ return dict((attr, getattr(self, attr, None)) for attr in62+ self.__attrs__)63+64+ def __setstate__(self, state):65+ for attr, value in state.items():66+ setattr(self, attr, value)67+68+ self.init_poolmanager(self._pool_connections, self._pool_maxsize)69+70 def init_poolmanager(self, connections, maxsize):71+ # save these values for pickling72+ self._pool_connections = connections73+ self._pool_maxsize = maxsize74+75 self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize)76 77 def cert_verify(self, conn, url, verify, cert):78 if url.startswith('https') and verify:183 unmodified linesmodified:requests/models.py+10 added-3 removed
18 unmodified lines19 from .cookies import cookiejar_from_dict, get_cookie_header20 from .packages.urllib3.filepost import encode_multipart_formdata21 from .exceptions import HTTPError, RequestException, MissingSchema, InvalidURL22 from .utils import (23- stream_untransfer, guess_filename, requote_uri,23+ stream_untransfer, guess_filename, get_auth_from_url, requote_uri,24 stream_decode_response_unicode, to_key_val_list, parse_header_links,25 iter_slices, guess_json_utf, super_len)26 from .compat import (27 cookielib, urlparse, urlunparse, urlsplit, urlencode, str, bytes, StringIO,191 unmodified lines219 p.prepare_url(self.url, self.params)220 p.prepare_headers(self.headers)221 p.prepare_cookies(self.cookies)222 p.prepare_body(self.data, self.files)223+ p.prepare_auth(self.auth, self.url)224 # Note that prepare_auth must be last to enable authentication schemes225 # such as OAuth to work on a fully prepared request.225- p.prepare_auth(self.auth)226+227 # This MUST go after prepare_auth. Authenticators could add a hook228 p.prepare_hooks(self.hooks)229 230 return p164 unmodified lines395 self.headers['Content-Length'] = str(len(body))396 elif self.method not in ('GET', 'HEAD'):397 self.headers['Content-Length'] = '0'398 398- def prepare_auth(self, auth):399+ def prepare_auth(self, auth, url=''):400 """Prepares the given HTTP auth data."""401+402+ # If no Auth is explicitly provided, extract it from the URL first.403+ if auth is None:404+ url_auth = get_auth_from_url(self.url)405+ auth = url_auth if any(url_auth) else None406+407 if auth:408 if isinstance(auth, tuple) and len(auth) == 2:409 # special-case basic HTTP auth410 auth = HTTPBasicAuth(*auth)260 unmodified linesmodified:requests/sessions.py+7 added-3 removed
88 unmodified lines89 prepared_request.headers = req.headers.copy()90 prepared_request.hooks = req.hooks91 prepared_request.method = req.method92 prepared_request.url = req.url93- cookiejar = resp.cookies93 94+ cookiejar = cookiejar_from_dict({})95+ cookiejar.update(self.cookies)96+ cookiejar.update(resp.cookies)97+98 # ((resp.status_code is codes.see_other))99 while (('location' in resp.headers and resp.status_code in REDIRECT_STATI)):100 101 resp.content # Consume socket so it can be released77 unmodified lines179 200180 """181 182 __attrs__ = [180- 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks', 181- 'params', 'verify', 'cert', 'prefetch']183+ 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',184+ 'params', 'verify', 'cert', 'prefetch', 'adapters', 'stream',185+ 'trust_env']186 187 def __init__(self):188 189 #: A case-insensitive dictionary of headers to be sent on each287 unmodified linesmodified:.travis.yml+2 added-3 removed
1 language: python2 python:3 - 2.64 - 2.75- - 3.25 - 3.36 env: HTTPBIN_URL=http://httpbin.org/8-script: make test7+script: invoke test8 install:10- - make test-deps9+ - pip install -r requirements.txt10 notifications:11 email: falseadded:invokefile.py+5 added
1+from invoke import run, task2+3+@task4+def build():5+ print("Building!")deleted:Makefile-30 removed
1-SHELL := /bin/bash2-3-test:4- py.test5-6-test-deps:7- pip install -r requirements.txt8-9-six:10- python test_requests.py11- python3 test_requests.py12-13-deps: urllib3 certs charade14-15-urllib3:16- rm -fr requests/packages/urllib317- git clone https://github.com/shazow/urllib3.git18- cd urllib3 && git checkout master && cd ..19- mv urllib3/urllib3 requests/packages/20- rm -fr urllib321-22-charade:23- rm -fr requests/packages/charade24- git clone https://github.com/sigmavirus24/charade.git25- cd charade && git checkout master && cd ..26- mv charade/charade requests/packages/27- rm -fr charade28-29-certs:30- cd requests && curl -O https://raw.github.com/kennethreitz/certifi/master/certifi/cacert.pemmodified:requirements.txt+3 added-2 removed
1-pytest2-sphinx1+py==1.4.122+pytest==2.3.43+invoke==0.2.0added:tasks.py+32 added
1+# -*- coding: utf-8 -*-2+3+import requests4+from invoke import run, task5+6+@task7+def test():8+ run('py.test', pty=True)9+10+@task11+def deps():12+ print('Vendoring urllib3...')13+14+ run('rm -fr requests/packages/urllib3')15+ run('git clone https://github.com/shazow/urllib3.git')16+ run('mv urllib3/urllib3 requests/packages/')17+ run('rm -fr urllib3')18+19+ print('Vendoring Charade...')20+21+ run('rm -fr requests/packages/charade')22+ run('git clone https://github.com/sigmavirus24/charade.git')23+ run('mv charade/charade requests/packages/')24+ run('rm -fr charade')25+26+@task27+def certs():28+ print('Grabbing latest CA Bundle...')29+ r = requests.get('https://raw.github.com/kennethreitz/certifi/master/certifi/cacert.pem')30+31+ with open('requests/cacert.pem', 'w') as f:32+ f.write(r.content)modified:test_requests.py+16 added
5 unmodified lines6 from __future__ import division7 import json8 import os9 import unittest10+import pickle11 12 import requests13 from requests.auth import HTTPDigestAuth14 from requests.compat import str102 unmodified lines117 url = httpbin('cookies/set?foo=bar')118 r = s.get(url)119 self.assertTrue(s.cookies['foo'] == 'bar')120 121+ def test_cookie_sent_on_redirect(self):122+ s = requests.session()123+ s.get(httpbin('cookies/set?foo=bar'))124+ r = s.get(httpbin('redirect/1')) # redirects to httpbin('get')125+ self.assertTrue("Cookie" in r.json()["headers"])126+127 def test_user_agent_transfers(self):128 129 heads = {130 'User-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'251 unmodified lines382 error = requests.exceptions.HTTPError('message', response=response)383 self.assertEqual(str(error), 'message')384 self.assertEqual(error.response, response)385 386+ def test_session_pickling(self):387+ r = requests.Request('GET', httpbin('get'))388+ s = requests.Session()389 390+ s = pickle.loads(pickle.dumps(s))391+392+ r = s.send(r.prepare())393+ self.assertEqual(r.status_code, 200)394+395+396 if __name__ == '__main__':397 unittest.main()