aboutsummaryrefslogtreecommitdiff
path: root/urllib3/util
diff options
context:
space:
mode:
authorSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:38 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:38 -0700
commit73be7d6cc85a90ab4f67ffc27dc7eae672f7741f (patch)
tree4030bad5fec3d40cf93a20a2e26a165adf1ddbbd /urllib3/util
parent35fb123b995cbbe27d3edd5ed14abc6e56b7ad13 (diff)
downloadpython-urllib3-73be7d6cc85a90ab4f67ffc27dc7eae672f7741f.tar
python-urllib3-73be7d6cc85a90ab4f67ffc27dc7eae672f7741f.tar.gz
Imported Upstream version 1.8.3
Diffstat (limited to 'urllib3/util')
-rw-r--r--urllib3/util/connection.py6
-rw-r--r--urllib3/util/request.py14
-rw-r--r--urllib3/util/timeout.py31
-rw-r--r--urllib3/util/url.py10
4 files changed, 33 insertions, 28 deletions
diff --git a/urllib3/util/connection.py b/urllib3/util/connection.py
index 8deeab5..c67ef04 100644
--- a/urllib3/util/connection.py
+++ b/urllib3/util/connection.py
@@ -8,6 +8,7 @@ except ImportError: # `poll` doesn't exist on OSX and other platforms
except ImportError: # `select` doesn't exist on AppEngine.
select = False
+
def is_connection_dropped(conn): # Platform-specific
"""
Returns True if the connection is dropped and should be closed.
@@ -22,7 +23,7 @@ def is_connection_dropped(conn): # Platform-specific
if sock is False: # Platform-specific: AppEngine
return False
if sock is None: # Connection already closed (such as by httplib).
- return False
+ return True
if not poll:
if not select: # Platform-specific: AppEngine
@@ -40,6 +41,3 @@ def is_connection_dropped(conn): # Platform-specific
if fno == sock.fileno():
# Either data is buffered (bad), or the connection is dropped.
return True
-
-
-
diff --git a/urllib3/util/request.py b/urllib3/util/request.py
index d48d651..bfd7a98 100644
--- a/urllib3/util/request.py
+++ b/urllib3/util/request.py
@@ -7,7 +7,7 @@ ACCEPT_ENCODING = 'gzip,deflate'
def make_headers(keep_alive=None, accept_encoding=None, user_agent=None,
- basic_auth=None, proxy_basic_auth=None):
+ basic_auth=None, proxy_basic_auth=None, disable_cache=None):
"""
Shortcuts for generating request headers.
@@ -29,8 +29,11 @@ def make_headers(keep_alive=None, accept_encoding=None, user_agent=None,
auth header.
:param proxy_basic_auth:
- Colon-separated username:password string for 'proxy-authorization: basic ...'
- auth header.
+ Colon-separated username:password string for
+ 'proxy-authorization: basic ...' auth header.
+
+ :param disable_cache:
+ If ``True``, adds 'cache-control: no-cache' header.
Example: ::
@@ -63,6 +66,7 @@ def make_headers(keep_alive=None, accept_encoding=None, user_agent=None,
headers['proxy-authorization'] = 'Basic ' + \
b64encode(six.b(proxy_basic_auth)).decode('utf-8')
- return headers
-
+ if disable_cache:
+ headers['cache-control'] = 'no-cache'
+ return headers
diff --git a/urllib3/util/timeout.py b/urllib3/util/timeout.py
index 4f947cb..aaadc12 100644
--- a/urllib3/util/timeout.py
+++ b/urllib3/util/timeout.py
@@ -94,17 +94,16 @@ class Timeout(object):
return '%s(connect=%r, read=%r, total=%r)' % (
type(self).__name__, self._connect, self._read, self.total)
-
@classmethod
def _validate_timeout(cls, value, name):
- """ Check that a timeout attribute is valid
+ """ Check that a timeout attribute is valid.
:param value: The timeout value to validate
- :param name: The name of the timeout attribute to validate. This is used
- for clear error messages
- :return: the value
- :raises ValueError: if the type is not an integer or a float, or if it
- is a numeric value less than zero
+ :param name: The name of the timeout attribute to validate. This is
+ used to specify in error messages.
+ :return: The validated and casted version of the given value.
+ :raises ValueError: If the type is not an integer or a float, or if it
+ is a numeric value less than zero.
"""
if value is _Default:
return cls.DEFAULT_TIMEOUT
@@ -123,7 +122,7 @@ class Timeout(object):
raise ValueError("Attempted to set %s timeout to %s, but the "
"timeout cannot be set to a value less "
"than 0." % (name, value))
- except TypeError: # Python 3
+ except TypeError: # Python 3
raise ValueError("Timeout value %s was %s, but it must be an "
"int or float." % (name, value))
@@ -135,12 +134,12 @@ class Timeout(object):
The timeout value used by httplib.py sets the same timeout on the
connect(), and recv() socket requests. This creates a :class:`Timeout`
- object that sets the individual timeouts to the ``timeout`` value passed
- to this function.
+ object that sets the individual timeouts to the ``timeout`` value
+ passed to this function.
- :param timeout: The legacy timeout value
+ :param timeout: The legacy timeout value.
:type timeout: integer, float, sentinel default object, or None
- :return: a Timeout object
+ :return: Timeout object
:rtype: :class:`Timeout`
"""
return Timeout(read=timeout, connect=timeout)
@@ -174,7 +173,7 @@ class Timeout(object):
def get_connect_duration(self):
""" Gets the time elapsed since the call to :meth:`start_connect`.
- :return: the elapsed time
+ :return: Elapsed time.
:rtype: float
:raises urllib3.exceptions.TimeoutStateError: if you attempt
to get duration for a timer that hasn't been started.
@@ -191,7 +190,7 @@ class Timeout(object):
This will be a positive float or integer, the value None
(never timeout), or the default system timeout.
- :return: the connect timeout
+ :return: Connect timeout.
:rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None
"""
if self.total is None:
@@ -214,7 +213,7 @@ class Timeout(object):
established, a :exc:`~urllib3.exceptions.TimeoutStateError` will be
raised.
- :return: the value to use for the read timeout
+ :return: Value to use for the read timeout.
:rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None
:raises urllib3.exceptions.TimeoutStateError: If :meth:`start_connect`
has not yet been called on this object.
@@ -223,7 +222,7 @@ class Timeout(object):
self.total is not self.DEFAULT_TIMEOUT and
self._read is not None and
self._read is not self.DEFAULT_TIMEOUT):
- # in case the connect timeout has not yet been established.
+ # In case the connect timeout has not yet been established.
if self._start_connect is None:
return self._read
return max(0, min(self.total - self.get_connect_duration(),
diff --git a/urllib3/util/url.py b/urllib3/util/url.py
index 362d216..122108b 100644
--- a/urllib3/util/url.py
+++ b/urllib3/util/url.py
@@ -2,16 +2,20 @@ from collections import namedtuple
from ..exceptions import LocationParseError
+url_attrs = ['scheme', 'auth', 'host', 'port', 'path', 'query', 'fragment']
-class Url(namedtuple('Url', ['scheme', 'auth', 'host', 'port', 'path', 'query', 'fragment'])):
+
+class Url(namedtuple('Url', url_attrs)):
"""
Datastructure for representing an HTTP URL. Used as a return value for
:func:`parse_url`.
"""
slots = ()
- def __new__(cls, scheme=None, auth=None, host=None, port=None, path=None, query=None, fragment=None):
- return super(Url, cls).__new__(cls, scheme, auth, host, port, path, query, fragment)
+ def __new__(cls, scheme=None, auth=None, host=None, port=None, path=None,
+ query=None, fragment=None):
+ return super(Url, cls).__new__(cls, scheme, auth, host, port, path,
+ query, fragment)
@property
def hostname(self):