Skip to content

Commit

Permalink
Upgrade setuptools, appdirs, cachecontrol, distro, ipaddress, pyparsi…
Browse files Browse the repository at this point in the history
…ng, and requests (#4342)

* Upgrade setuptools to 34.3.2
* Upgrade appdirs to 1.4.3
* Upgrade CacheControl to 0.12.1
* Upgrade distro to 1.0.2
* Upgrade ipaddress to 1.0.18
* Upgrade pyparsing to 2.2.0
* Upgrade requests to 2.13.0
* Remove patching of progress
* Don't translate imports that would be syntax errors
* Patch pkg_resources to handle packaging correctly
  • Loading branch information
dstufft committed Mar 18, 2017
1 parent ac55737 commit b005a9b
Show file tree
Hide file tree
Showing 61 changed files with 12,205 additions and 858 deletions.
86 changes: 71 additions & 15 deletions pip/_vendor/appdirs.py
Expand Up @@ -13,7 +13,7 @@
# - Mac OS X: http://developer.apple.com/documentation/MacOSX/Conceptual/BPFileSystem/index.html
# - XDG spec for Un*x: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

__version_info__ = (1, 4, 0)
__version_info__ = (1, 4, 3)
__version__ = '.'.join(map(str, __version_info__))


Expand Down Expand Up @@ -98,7 +98,7 @@ def user_data_dir(appname=None, appauthor=None, version=None, roaming=False):


def site_data_dir(appname=None, appauthor=None, version=None, multipath=False):
"""Return full path to the user-shared data dir for this application.
r"""Return full path to the user-shared data dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
Expand All @@ -117,7 +117,7 @@ def site_data_dir(appname=None, appauthor=None, version=None, multipath=False):
returned, or '/usr/local/share/<AppName>',
if XDG_DATA_DIRS is not set
Typical user data directories are:
Typical site data directories are:
Mac OS X: /Library/Application Support/<AppName>
Unix: /usr/local/share/<AppName> or /usr/share/<AppName>
Win XP: C:\Documents and Settings\All Users\Application Data\<AppAuthor>\<AppName>
Expand Down Expand Up @@ -184,13 +184,13 @@ def user_config_dir(appname=None, appauthor=None, version=None, roaming=False):
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
for a discussion of issues.
Typical user data directories are:
Typical user config directories are:
Mac OS X: same as user_data_dir
Unix: ~/.config/<AppName> # or in $XDG_CONFIG_HOME, if defined
Win *: same as user_data_dir
For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME.
That means, by deafult "~/.config/<AppName>".
That means, by default "~/.config/<AppName>".
"""
if system in ["win32", "darwin"]:
path = user_data_dir(appname, appauthor, None, roaming)
Expand All @@ -204,7 +204,7 @@ def user_config_dir(appname=None, appauthor=None, version=None, roaming=False):


def site_config_dir(appname=None, appauthor=None, version=None, multipath=False):
"""Return full path to the user-shared data dir for this application.
r"""Return full path to the user-shared data dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
Expand All @@ -222,7 +222,7 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False)
returned. By default, the first item from XDG_CONFIG_DIRS is
returned, or '/etc/xdg/<AppName>', if XDG_CONFIG_DIRS is not set
Typical user data directories are:
Typical site config directories are:
Mac OS X: same as site_data_dir
Unix: /etc/xdg/<AppName> or $XDG_CONFIG_DIRS[i]/<AppName> for each value in
$XDG_CONFIG_DIRS
Expand Down Expand Up @@ -311,6 +311,48 @@ def user_cache_dir(appname=None, appauthor=None, version=None, opinion=True):
return path


def user_state_dir(appname=None, appauthor=None, version=None, roaming=False):
r"""Return full path to the user-specific state dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
"appauthor" (only used on Windows) is the name of the
appauthor or distributing body for this application. Typically
it is the owning company name. This falls back to appname. You may
pass False to disable it.
"version" is an optional version path element to append to the
path. You might want to use this if you want multiple versions
of your app to be able to run independently. If used, this
would typically be "<major>.<minor>".
Only applied when appname is present.
"roaming" (boolean, default False) can be set True to use the Windows
roaming appdata directory. That means that for users on a Windows
network setup for roaming profiles, this user data will be
sync'd on login. See
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
for a discussion of issues.
Typical user state directories are:
Mac OS X: same as user_data_dir
Unix: ~/.local/state/<AppName> # or in $XDG_STATE_HOME, if defined
Win *: same as user_data_dir
For Unix, we follow this Debian proposal <https://wiki.debian.org/XDGBaseDirectorySpecification#state>
to extend the XDG spec and support $XDG_STATE_HOME.
That means, by default "~/.local/state/<AppName>".
"""
if system in ["win32", "darwin"]:
path = user_data_dir(appname, appauthor, None, roaming)
else:
path = os.getenv('XDG_STATE_HOME', os.path.expanduser("~/.local/state"))
if appname:
path = os.path.join(path, appname)
if appname and version:
path = os.path.join(path, version)
return path


def user_log_dir(appname=None, appauthor=None, version=None, opinion=True):
r"""Return full path to the user-specific log dir for this application.
Expand All @@ -329,7 +371,7 @@ def user_log_dir(appname=None, appauthor=None, version=None, opinion=True):
"Logs" to the base app data dir for Windows, and "log" to the
base cache dir for Unix. See discussion below.
Typical user cache directories are:
Typical user log directories are:
Mac OS X: ~/Library/Logs/<AppName>
Unix: ~/.cache/<AppName>/log # or under $XDG_CACHE_HOME if defined
Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Logs
Expand Down Expand Up @@ -364,8 +406,8 @@ def user_log_dir(appname=None, appauthor=None, version=None, opinion=True):

class AppDirs(object):
"""Convenience wrapper for getting application dirs."""
def __init__(self, appname, appauthor=None, version=None, roaming=False,
multipath=False):
def __init__(self, appname=None, appauthor=None, version=None,
roaming=False, multipath=False):
self.appname = appname
self.appauthor = appauthor
self.version = version
Expand Down Expand Up @@ -397,6 +439,11 @@ def user_cache_dir(self):
return user_cache_dir(self.appname, self.appauthor,
version=self.version)

@property
def user_state_dir(self):
return user_state_dir(self.appname, self.appauthor,
version=self.version)

@property
def user_log_dir(self):
return user_log_dir(self.appname, self.appauthor,
Expand All @@ -410,7 +457,10 @@ def _get_win_folder_from_registry(csidl_name):
registry for this guarantees us the correct answer for all CSIDL_*
names.
"""
import _winreg
if PY3:
import winreg as _winreg
else:
import _winreg

shell_folder_name = {
"CSIDL_APPDATA": "AppData",
Expand Down Expand Up @@ -500,7 +550,7 @@ def _get_win_folder_with_jna(csidl_name):
if has_high_char:
buf = array.zeros('c', buf_size)
kernel = win32.Kernel32.INSTANCE
if kernal.GetShortPathName(dir, buf, buf_size):
if kernel.GetShortPathName(dir, buf, buf_size):
dir = jna.Native.toString(buf.tostring()).rstrip("\0")

return dir
Expand All @@ -527,9 +577,15 @@ def _get_win_folder_with_jna(csidl_name):
appname = "MyApp"
appauthor = "MyCompany"

props = ("user_data_dir", "site_data_dir",
"user_config_dir", "site_config_dir",
"user_cache_dir", "user_log_dir")
props = ("user_data_dir",
"user_config_dir",
"user_cache_dir",
"user_state_dir",
"user_log_dir",
"site_data_dir",
"site_config_dir")

print("-- app dirs %s --" % __version__)

print("-- app dirs (with optional 'version')")
dirs = AppDirs(appname, appauthor, version="1.0")
Expand Down
2 changes: 1 addition & 1 deletion pip/_vendor/cachecontrol/__init__.py
Expand Up @@ -4,7 +4,7 @@
"""
__author__ = 'Eric Larson'
__email__ = 'eric@ionrock.org'
__version__ = '0.12.0'
__version__ = '0.12.1'

from .wrapper import CacheControl
from .adapter import CacheControlAdapter
Expand Down
13 changes: 9 additions & 4 deletions pip/_vendor/cachecontrol/adapter.py
Expand Up @@ -16,10 +16,12 @@ def __init__(self, cache=None,
controller_class=None,
serializer=None,
heuristic=None,
cacheable_methods=None,
*args, **kw):
super(CacheControlAdapter, self).__init__(*args, **kw)
self.cache = cache or DictCache()
self.heuristic = heuristic
self.cacheable_methods = cacheable_methods or ('GET',)

controller_factory = controller_class or CacheController
self.controller = controller_factory(
Expand All @@ -28,12 +30,13 @@ def __init__(self, cache=None,
serializer=serializer,
)

def send(self, request, **kw):
def send(self, request, cacheable_methods=None, **kw):
"""
Send a request. Use the request information to see if it
exists in the cache and cache the response if we need to and can.
"""
if request.method == 'GET':
cacheable = cacheable_methods or self.cacheable_methods
if request.method in cacheable:
cached_response = self.controller.cached_request(request)
if cached_response:
return self.build_response(request, cached_response,
Expand All @@ -48,14 +51,16 @@ def send(self, request, **kw):

return resp

def build_response(self, request, response, from_cache=False):
def build_response(self, request, response, from_cache=False,
cacheable_methods=None):
"""
Build a response by making a request or using the cache.
This will end up calling send and returning a potentially
cached response
"""
if not from_cache and request.method == 'GET':
cacheable = cacheable_methods or self.cacheable_methods
if not from_cache and request.method in cacheable:
# Check for any heuristics that might update headers
# before trying to cache.
if self.heuristic:
Expand Down
6 changes: 6 additions & 0 deletions pip/_vendor/cachecontrol/caches/file_cache.py
Expand Up @@ -5,6 +5,12 @@
from ..cache import BaseCache
from ..controller import CacheController

try:
FileNotFoundError
except NameError:
# py2.X
FileNotFoundError = IOError


def _secure_open_write(filename, fmode):
# We only want to write to this file, so open it in write only mode
Expand Down
9 changes: 6 additions & 3 deletions pip/_vendor/cachecontrol/controller.py
Expand Up @@ -30,10 +30,12 @@ def parse_uri(uri):
class CacheController(object):
"""An interface to see if request should cached or not.
"""
def __init__(self, cache=None, cache_etags=True, serializer=None):
def __init__(self, cache=None, cache_etags=True, serializer=None,
status_codes=None):
self.cache = cache or DictCache()
self.cache_etags = cache_etags
self.serializer = serializer or Serializer()
self.cacheable_status_codes = status_codes or (200, 203, 300, 301)

@classmethod
def _urlnorm(cls, uri):
Expand Down Expand Up @@ -220,15 +222,16 @@ def conditional_headers(self, request):

return new_headers

def cache_response(self, request, response, body=None):
def cache_response(self, request, response, body=None,
status_codes=None):
"""
Algorithm for caching requests.
This assumes a requests Response object.
"""
# From httplib2: Don't cache 206's since we aren't going to
# handle byte range requests
cacheable_status_codes = [200, 203, 300, 301]
cacheable_status_codes = status_codes or self.cacheable_status_codes
if response.status not in cacheable_status_codes:
logger.debug(
'Status code %s not in %s',
Expand Down
10 changes: 8 additions & 2 deletions pip/_vendor/cachecontrol/wrapper.py
Expand Up @@ -6,14 +6,20 @@ def CacheControl(sess,
cache=None,
cache_etags=True,
serializer=None,
heuristic=None):
heuristic=None,
controller_class=None,
adapter_class=None,
cacheable_methods=None):

cache = cache or DictCache()
adapter = CacheControlAdapter(
adapter_class = adapter_class or CacheControlAdapter
adapter = adapter_class(
cache,
cache_etags=cache_etags,
serializer=serializer,
heuristic=heuristic,
controller_class=controller_class,
cacheable_methods=cacheable_methods
)
sess.mount('http://', adapter)
sess.mount('https://', adapter)
Expand Down
2 changes: 1 addition & 1 deletion pip/_vendor/distro.py
Expand Up @@ -40,7 +40,7 @@
if not sys.platform.startswith('linux'):
raise ImportError('Unsupported platform: {0}'.format(sys.platform))

_UNIXCONFDIR = '/etc'
_UNIXCONFDIR = os.environ.get('UNIXCONFDIR', '/etc')
_OS_RELEASE_BASENAME = 'os-release'

#: Translation table for normalizing the "ID" attribute defined in os-release
Expand Down
10 changes: 5 additions & 5 deletions pip/_vendor/ipaddress.py
Expand Up @@ -14,7 +14,7 @@
import itertools
import struct

__version__ = '1.0.17'
__version__ = '1.0.18'

# Compatibility functions
_compat_int_types = (int,)
Expand Down Expand Up @@ -58,6 +58,8 @@ def _compat_to_bytes(intval, length, endianess):
return struct.pack(b'!QQ', intval >> 64, intval & 0xffffffffffffffff)
else:
raise NotImplementedError()


if hasattr(int, 'bit_length'):
# Not int.bit_length , since that won't work in 2.7 where long exists
def _compat_bit_length(i):
Expand Down Expand Up @@ -547,8 +549,7 @@ def _check_packed_address(self, address, expected_len):
msg = (
'%r (len %d != %d) is not permitted as an IPv%d address. '
'Did you pass in a bytes (str in Python 2) instead of'
' a unicode object?'
)
' a unicode object?')
raise AddressValueError(msg % (address, address_len,
expected_len, self._version))

Expand Down Expand Up @@ -1083,8 +1084,7 @@ def supernet(self, prefixlen_diff=1, new_prefix=None):
(self.prefixlen, prefixlen_diff))
return self.__class__((
int(self.network_address) & (int(self.netmask) << prefixlen_diff),
new_prefixlen
))
new_prefixlen))

@property
def is_multicast(self):
Expand Down

0 comments on commit b005a9b

Please sign in to comment.