Skip to content
Myr

urllib3 update

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

fixes #664

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 6b1e81c · Browse files · 4 files+45 added−57 removed
This commit

State

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

Diff stats

4 files+45 added−57 removed

  • other:+45 added−57 removed

4 files+45 added−57 removed

deleted:requests/packages/urllib3/packages/mimetools_choose_boundary/__init__.py-47 removed
1"""The function mimetools.choose_boundary() from Python 2.7, which seems to2have disappeared in Python 3 (although email.generator._make_boundary() might3work as a replacement?).45Tweaked to use lock from threading rather than thread.6"""7import os8from threading import Lock9_counter_lock = Lock()1011_counter = 012def _get_next_counter():13 global _counter14 with _counter_lock:15 _counter += 116 return _counter1718_prefix = None1920def choose_boundary():21 """Return a string usable as a multipart boundary.2223 The string chosen is unique within a single program run, and24 incorporates the user id (if available), process id (if available),25 and current time. So it's very unlikely the returned string appears26 in message text, but there's no guarantee.2728 The boundary contains dots so you have to quote it in the header."""2930 global _prefix31 import time32 if _prefix is None:33 import socket34 try:35 hostid = socket.gethostbyname(socket.gethostname())36 except socket.gaierror:37 hostid = '127.0.0.1'38 try:39 uid = repr(os.getuid())40 except AttributeError:41 uid = '1'42 try:43 pid = repr(os.getpid())44 except AttributeError:45 pid = '1'46 _prefix = hostid + '.' + uid + '.' + pid47 return "%s.%.3f.%d" % (_prefix, time.time(), _get_next_counter())
modified:requests/packages/urllib3/connectionpool.py+4 added-1 removed
256 unmodified lines
257 sock = getattr(conn, 'sock', False) # AppEngine doesn't have sock attr.258 if sock:259 sock.settimeout(timeout)260261 try: # Python 2.7+, use buffering of HTTP responses262 httplib_response = conn.getresponse(buffering=True)263 except TypeError: # Python 2.6 and older261 httplib_response = conn.getresponse()264 httplib_response = conn.getresponse()265266 # AppEngine doesn't have a version attr.267 http_version = getattr(conn, '_http_vsn_str', 'HTTP/?'),268 log.debug("\"%s %s %s\" %s %s" % (method, url, http_version,
257 unmodified lines
modified:requests/packages/urllib3/filepost.py+8 added-5 removed
5 unmodified lines
67import codecs8import mimetypes910try:11 from mimetools import choose_boundary12except ImportError:13 from .packages.mimetools_choose_boundary import choose_boundary1410from uuid import uuid411from io import BytesIO1213from .packages import six14from .packages.six import b1516writer = codecs.lookup('utf-8')[3]171819def choose_boundary():20 """21 Our embarassingly-simple replacement for mimetools.choose_boundary.22 """23 return uuid4().hex242526def get_content_type(filename):27 return mimetypes.guess_type(filename)[0] or 'application/octet-stream'2829
62 unmodified lines
modified:requests/packages/urllib3/util.py+33 added-4 removed
70 unmodified lines
7172 return headers737475def split_first(s, delims):76 """77 Given a string and an iterable of delimiters, split on the first found78 delimiter. Return two split parts.7980 If not found, then the first part is the full input string.8182 Scales linearly with number of delims. Not ideal for large number of delims.83 """84 min_idx = None85 for d in delims:86 idx = s.find(d)87 if idx < 0:88 continue8990 if not min_idx:91 min_idx = idx92 else:93 min_idx = min(idx, min_idx)9495 if min_idx < 0:96 return s, ''9798 return s[:min_idx], s[min_idx+1:]99100101def get_host(url):102 """103 Given a url, return its scheme, host and port (None if it's not there).104
11 unmodified lines
116 scheme = 'http'117118 if '://' in url:119 scheme, url = url.split('://', 1)94 if '/' in url:95 url, _path = url.split('/', 1)120121 # Find the earliest Authority Terminator122 # http://tools.ietf.org/html/rfc3986#section-3.2123 url, _path = split_first(url, ['/', '?', '#'])124125 if '@' in url:126 _auth, url = url.split('@', 1)127 if ':' in url:128 url, port = url.split(':', 1)
17 unmodified lines
146 Note: For platforms like AppEngine, this will always return ``False`` to147 let the platform handle connection recycling transparently for us.148 """149 sock = getattr(conn, 'sock', False)121 if not sock: #Platform-specific: AppEngine150 if not sock: # Platform-specific: AppEngine151 return False152153 if not poll: # Platform-specific125 if not select: #Platform-specific: AppEngine154 if not select: # Platform-specific: AppEngine155 return False156157 return select([sock], [], [], 0.0)[0]158
7 unmodified lines