1111
1212import cgi
1313import codecs
14- import os
1514import random
1615import re
1716import zlib
1817
1918from .compat import parse_http_list as _parse_list_header
20- from .compat import quote , unquote , cookielib , SimpleCookie , is_py2
19+ from .compat import quote , cookielib , SimpleCookie , is_py2
2120from .compat import basestring , bytes
2221
2322
@@ -29,17 +28,19 @@ def dict_from_string(s):
2928 c = SimpleCookie ()
3029 c .load (s )
3130
32- for k ,v in list (c .items ()):
31+ for k , v in list (c .items ()):
3332 cookies .update ({k : v .value })
3433
3534 return cookies
3635
36+
3737def guess_filename (obj ):
3838 """Tries to guess the filename of the given object."""
3939 name = getattr (obj , 'name' , None )
4040 if name and name [0 ] != '<' and name [- 1 ] != '>' :
4141 return name
4242
43+
4344# From mitsuhiko/werkzeug (used with permission).
4445def parse_list_header (value ):
4546 """Parse lists as described by RFC 2068 Section 2.
@@ -169,18 +170,16 @@ def header_expand(headers):
169170
170171 collector .append ('; ' .join (_params ))
171172
172- if not len (headers ) == i + 1 :
173+ if not len (headers ) == i + 1 :
173174 collector .append (', ' )
174175
175-
176176 # Remove trailing separators.
177177 if collector [- 1 ] in (', ' , '; ' ):
178178 del collector [- 1 ]
179179
180180 return '' .join (collector )
181181
182182
183-
184183def randombytes (n ):
185184 """Return n random bytes."""
186185 if is_py2 :
@@ -341,6 +340,7 @@ def get_unicode_from_response(r):
341340 except TypeError :
342341 return r .content
343342
343+
344344def stream_decompress (iterator , mode = 'gzip' ):
345345 """
346346 Stream decodes an iterator over compressed data
@@ -373,6 +373,7 @@ def stream_decompress(iterator, mode='gzip'):
373373 if rv :
374374 yield rv
375375
376+
376377def stream_untransfer (gen , resp ):
377378 if 'gzip' in resp .headers .get ('content-encoding' , '' ):
378379 gen = stream_decompress (gen , mode = 'gzip' )
@@ -387,6 +388,7 @@ def stream_untransfer(gen, resp):
387388 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
388389 + "0123456789-._~" )
389390
391+
390392def unquote_unreserved (uri ):
391393 """Un-escape any percent-escape sequences in a URI that are unreserved
392394 characters.
@@ -405,6 +407,7 @@ def unquote_unreserved(uri):
405407 parts [i ] = '%' + parts [i ]
406408 return '' .join (parts )
407409
410+
408411def requote_uri (uri ):
409412 """Re-quote the given URI.
410413
@@ -415,11 +418,3 @@ def requote_uri(uri):
415418 # Then quote only illegal characters (do not quote reserved, unreserved,
416419 # or '%')
417420 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" ]
0 commit comments