Skip to content
Myr

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

22 files+208 added−63 removed

modified:docs/dev/todo.rst+2 added-2 removed
21 unmodified lines
22------------------------2324You'll need to install py.test in order to run the Requests' test suite::2526 $ 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 lines
modified:docs/conf.py-1 removed
132 unmodified lines
133# typographically correct entities.134#html_use_smartypants = True135136# Custom sidebar templates, maps document names to template names.137# Custom sidebar templates, maps document names to template names.137html_sidebars = {138 'index': ['sidebarintro.html', 'sourcelink.html', 'searchbox.html'],139 '**': ['sidebarlogo.html', 'localtoc.html', 'relations.html',140 'sourcelink.html', 'searchbox.html']
103 unmodified lines
modified:requests/packages/charade/__init__.py+6 added-1 removed
13 unmodified lines
14# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA15# 02110-1301 USA16######################### END LICENSE BLOCK #########################1718__version__ = "1.0.1"18__version__ = "1.0.3"19from sys import version_info202122def 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')2627 from . import universaldetector28 u = universaldetector.UniversalDetector()29 u.reset()30 u.feed(aBuf)
2 unmodified lines
modified:requests/packages/charade/chardistribution.py+2 added-1 removed
38 unmodified lines
3940ENOUGH_DATA_THRESHOLD = 102441SURE_YES = 0.9942SURE_NO = 0.0143MINIMUM_DATA_THRESHOLD = 3444546class CharDistributionAnalysis:47 def __init__(self):
34 unmodified lines
82 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_NO8889 if self._mTotalChars != self._mFreqChars:90 r = (self._mFreqChars / ((self._mTotalChars - self._mFreqChars)
141 unmodified lines
modified:requests/packages/charade/compat.py+10 added-2 removed
16 unmodified lines
17# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA18# 02110-1301 USA19######################### END LICENSE BLOCK #########################2021import sys222324if sys.version_info < (3, 0):25 base_str = (str, unicode)26else:27 base_str = (bytes, str)282930def 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 a
added: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 #########################2728from .mbcharsetprober import MultiByteCharSetProber29from .codingstatemachine import CodingStateMachine30from .chardistribution import EUCKRDistributionAnalysis31from .mbcssm import CP949SMModel323334class 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()4243 def get_charset_name(self):44 return "CP949"
modified:requests/packages/charade/langcyrillicmodel.py-2 removed
23 unmodified lines
24# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25# 02110-1301 USA26######################### END LICENSE BLOCK #########################2728from . import constants2928# KOI8-R language model29# Character Mapping Table:30KOI8R_CharToOrderMap = (31255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00
298 unmodified lines
modified:requests/packages/charade/langgreekmodel.py-2 removed
23 unmodified lines
24# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25# 02110-1301 USA26######################### END LICENSE BLOCK #########################2728from . import constants2928# 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 - 9
194 unmodified lines
modified:requests/packages/charade/langhebrewmodel.py-2 removed
25 unmodified lines
26# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA27# 02110-1301 USA28######################### END LICENSE BLOCK #########################2930from . import constants3130# 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 - 9
168 unmodified lines
modified:requests/packages/charade/langhungarianmodel.py-2 removed
23 unmodified lines
24# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25# 02110-1301 USA26######################### END LICENSE BLOCK #########################2728from . import constants2928# 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 - 9
194 unmodified lines
modified:requests/packages/charade/mbcsgroupprober.py+2 added
31 unmodified lines
32from .sjisprober import SJISProber33from .eucjpprober import EUCJPProber34from .gb2312prober import GB2312Prober35from .euckrprober import EUCKRProber36from .cp949prober import CP949Prober37from .big5prober import Big5Prober38from .euctwprober import EUCTWProber3940
5 unmodified lines
46 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 lines
77 'stateTable': BIG5_st,78 'charLenTable': Big5CharLenTable,79 'name': 'Big5'}8081# CP9498283CP949_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)101102CP949_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)112113CP949CharLenTable = (0, 1, 2, 0, 1, 1, 2, 2, 0, 2)114115CP949SMModel = {'classTable': CP949_cls,116 'classFactor': 10,117 'stateTable': CP949_st,118 'charLenTable': CP949CharLenTable,119 'name': 'CP949'}120121# EUC-JP122123EUCJP_cls = (124 4,4,4,4,4,4,4,4, # 00 - 07
451 unmodified lines
modified:requests/packages/charade/universaldetector.py+8 added-7 removed
26 unmodified lines
27######################### END LICENSE BLOCK #########################2829from . import constants30import sys31import codecs32from .latin1prober import Latin1Prober # windows-125233from .mbcsgroupprober import MBCSGroupProber # multi-byte character sets34from .sbcsgroupprober import SBCSGroupProber # single-byte character sets35from .escprober import EscCharSetProber # ISO-2122, etc.
34 unmodified lines
70 return7172 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}101102 self._mGotData = True
70 unmodified lines
modified:requests/adapters.py+19 added
42 unmodified lines
434445class HTTPAdapter(BaseAdapter):46 """Built-In HTTP Adapter for Urllib3."""47 __attrs__ = ['max_retries', 'config', '_pool_connections', '_pool_maxsize']4849 def __init__(self, pool_connections=DEFAULT_POOLSIZE, pool_maxsize=DEFAULT_POOLSIZE):50 self.max_retries = DEFAULT_RETRIES51 self.config = {}5253 super(HTTPAdapter, self).__init__()5455 self._pool_connections = pool_connections56 self._pool_maxsize = pool_maxsize5758 self.init_poolmanager(pool_connections, pool_maxsize)5960 def __getstate__(self):61 return dict((attr, getattr(self, attr, None)) for attr in62 self.__attrs__)6364 def __setstate__(self, state):65 for attr, value in state.items():66 setattr(self, attr, value)6768 self.init_poolmanager(self._pool_connections, self._pool_maxsize)6970 def init_poolmanager(self, connections, maxsize):71 # save these values for pickling72 self._pool_connections = connections73 self._pool_maxsize = maxsize7475 self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize)7677 def cert_verify(self, conn, url, verify, cert):78 if url.startswith('https') and verify:
183 unmodified lines
modified:requests/models.py+10 added-3 removed
18 unmodified lines
19from .cookies import cookiejar_from_dict, get_cookie_header20from .packages.urllib3.filepost import encode_multipart_formdata21from .exceptions import HTTPError, RequestException, MissingSchema, InvalidURL22from .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)26from .compat import (27 cookielib, urlparse, urlunparse, urlsplit, urlencode, str, bytes, StringIO,
191 unmodified lines
219 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)226227 # This MUST go after prepare_auth. Authenticators could add a hook228 p.prepare_hooks(self.hooks)229230 return p
164 unmodified lines
395 self.headers['Content-Length'] = str(len(body))396 elif self.method not in ('GET', 'HEAD'):397 self.headers['Content-Length'] = '0'398398 def prepare_auth(self, auth):399 def prepare_auth(self, auth, url=''):400 """Prepares the given HTTP auth data."""401402 # 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 None406407 if auth:408 if isinstance(auth, tuple) and len(auth) == 2:409 # special-case basic HTTP auth410 auth = HTTPBasicAuth(*auth)
260 unmodified lines
modified:requests/sessions.py+7 added-3 removed
88 unmodified lines
89 prepared_request.headers = req.headers.copy()90 prepared_request.hooks = req.hooks91 prepared_request.method = req.method92 prepared_request.url = req.url93 cookiejar = resp.cookies9394 cookiejar = cookiejar_from_dict({})95 cookiejar.update(self.cookies)96 cookiejar.update(resp.cookies)9798 # ((resp.status_code is codes.see_other))99 while (('location' in resp.headers and resp.status_code in REDIRECT_STATI)):100101 resp.content # Consume socket so it can be released
77 unmodified lines
179 200180 """181182 __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']186187 def __init__(self):188189 #: A case-insensitive dictionary of headers to be sent on each
287 unmodified lines
modified:.travis.yml+2 added-3 removed
1language: python2python:3 - 2.64 - 2.75 - 3.25 - 3.36env: HTTPBIN_URL=http://httpbin.org/8script: make test7script: invoke test8install:10 - make test-deps9 - pip install -r requirements.txt10notifications:11 email: false
added:invokefile.py+5 added
1from invoke import run, task23@task4def build():5 print("Building!")
deleted:Makefile-30 removed
1SHELL := /bin/bash23test:4 py.test56test-deps:7 pip install -r requirements.txt89six:10 python test_requests.py11 python3 test_requests.py1213deps: urllib3 certs charade1415urllib3: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 urllib32122charade: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 charade2829certs:30 cd requests && curl -O https://raw.github.com/kennethreitz/certifi/master/certifi/cacert.pem
modified:requirements.txt+3 added-2 removed
1pytest2sphinx1py==1.4.122pytest==2.3.43invoke==0.2.0
added:tasks.py+32 added
1# -*- coding: utf-8 -*-23import requests4from invoke import run, task56@task7def test():8 run('py.test', pty=True)910@task11def deps():12 print('Vendoring urllib3...')1314 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')1819 print('Vendoring Charade...')2021 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')2526@task27def certs():28 print('Grabbing latest CA Bundle...')29 r = requests.get('https://raw.github.com/kennethreitz/certifi/master/certifi/cacert.pem')3031 with open('requests/cacert.pem', 'w') as f:32 f.write(r.content)
modified:test_requests.py+16 added
5 unmodified lines
6from __future__ import division7import json8import os9import unittest10import pickle1112import requests13from requests.auth import HTTPDigestAuth14from requests.compat import str
102 unmodified lines
117 url = httpbin('cookies/set?foo=bar')118 r = s.get(url)119 self.assertTrue(s.cookies['foo'] == 'bar')120121 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"])126127 def test_user_agent_transfers(self):128129 heads = {130 'User-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'
251 unmodified lines
382 error = requests.exceptions.HTTPError('message', response=response)383 self.assertEqual(str(error), 'message')384 self.assertEqual(error.response, response)385386 def test_session_pickling(self):387 r = requests.Request('GET', httpbin('get'))388 s = requests.Session()389390 s = pickle.loads(pickle.dumps(s))391392 r = s.send(r.prepare())393 self.assertEqual(r.status_code, 200)394395396if __name__ == '__main__':397 unittest.main()