SCHEMAS
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 · parent cf37f63 · Browse files · 3 files·+16 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
3 files+16 added−16 removed
- other:+16 added−16 removed
Provenance
- Commit
fe10eeb- Tree
2c4ff8f- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
cf37f63
3 files changed+16 added−16 removed
modified:requests/defaults.py+4 added
17 unmodified lines18 :pool_maxsize: The maximium size of an HTTP connection pool.19 :pool_connections: The number of active HTTP connection pools to use.20 """21 22+SCHEMAS = ['http', 'https']23+24 from . import __version__25 26 defaults = dict()27 11 unmodified lines39 defaults['max_retries'] = 040 defaults['danger_mode'] = False41 defaults['safe_mode'] = False42 defaults['keep_alive'] = True43+44+modified:requests/models.py+3 added-2 removed
19 unmodified lines20 from .packages.urllib3.exceptions import SSLError as _SSLError21 from .packages.urllib3.exceptions import HTTPError as _HTTPError22 from .packages.urllib3 import connectionpool, poolmanager23 from .packages.urllib3.filepost import encode_multipart_formdata24+from .defaults import SCHEMAS25 from .exceptions import (26 ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,27 URLRequired, SSLError)28 from .utils import (29 get_encoding_from_headers, stream_untransfer, guess_filename, requote_uri,29- dict_from_string, supported_schemes, stream_decode_response_unicode)30+ dict_from_string, stream_decode_response_unicode)31 from .compat import (32 urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes,33 SimpleCookie, is_py2)34 276 unmodified lines311 312 if not scheme:313 raise ValueError("Invalid URL %r: No schema supplied" % url)314 314- if not scheme in supported_schemes():315+ if not scheme in SCHEMAS:316 raise ValueError("Invalid scheme %r" % scheme)317 318 netloc = netloc.encode('idna').decode('utf-8')319 470 unmodified linesmodified:requests/utils.py+9 added-14 removed
9 unmodified lines10 """11 12 import cgi13 import codecs14-import os14 import random15 import re16 import zlib17 18 from .compat import parse_http_list as _parse_list_header20-from .compat import quote, unquote, cookielib, SimpleCookie, is_py219+from .compat import quote, cookielib, SimpleCookie, is_py220 from .compat import basestring, bytes21 22 23 def dict_from_string(s):3 unmodified lines27 28 c = SimpleCookie()29 c.load(s)30 32- for k,v in list(c.items()):31+ for k, v in list(c.items()):32 cookies.update({k: v.value})33 34 return cookies35 36+37 def guess_filename(obj):38 """Tries to guess the filename of the given object."""39 name = getattr(obj, 'name', None)40 if name and name[0] != '<' and name[-1] != '>':41 return name42 43+44 # From mitsuhiko/werkzeug (used with permission).45 def parse_list_header(value):46 """Parse lists as described by RFC 2068 Section 2.47 121 unmodified lines169 if len(params):170 171 collector.append('; '.join(_params))172 172- if not len(headers) == i+1:173+ if not len(headers) == i + 1:174 collector.append(', ')175 175-176 # Remove trailing separators.177 if collector[-1] in (', ', '; '):178 del collector[-1]179 180 return ''.join(collector)181 182 183-183 def randombytes(n):184 """Return n random bytes."""185 if is_py2:186 L = [chr(random.randrange(0, 256)) for i in range(n)]152 unmodified lines339 return str(r.content, encoding, errors='replace')340 except TypeError:341 return r.content342 343+344 def stream_decompress(iterator, mode='gzip'):345 """346 Stream decodes an iterator over compressed data347 24 unmodified lines372 rv = buf + dec.flush()373 if rv:374 yield rv375 376+377 def stream_untransfer(gen, resp):378 if 'gzip' in resp.headers.get('content-encoding', ''):379 gen = stream_decompress(gen, mode='gzip')380 elif 'deflate' in resp.headers.get('content-encoding', ''):6 unmodified lines387 UNRESERVED_SET = frozenset(388 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"389 + "0123456789-._~")390 391+392 def unquote_unreserved(uri):393 """Un-escape any percent-escape sequences in a URI that are unreserved394 characters.395 This leaves all reserved, illegal and non-ASCII bytes encoded.10 unmodified lines406 else:407 parts[i] = '%' + parts[i]408 return ''.join(parts)409 410+411 def requote_uri(uri):412 """Re-quote the given URI.413 414 This function passes the given URI through an unquote/quote cycle to2 unmodified lines417 # Unquote only the unreserved characters418 # Then quote only illegal characters (do not quote reserved, unreserved,419 # or '%')420 return quote(unquote_unreserved(uri), safe="!#$%&'()*+,/:;=?@[]~")418- return "/".join(parts)419-420-def supported_schemes():421- """A list of schemes supported by requests.422-423- return: a list of strings.424- """425- return ["http","https"]