|
23 | 23 | PY3min = (sys.version_info[0] >= 3) |
24 | 24 |
|
25 | 25 |
|
26 | | -def _get_home(): |
27 | | - """Find user's home directory if possible. |
28 | | - Otherwise, returns None. |
29 | | -
|
30 | | - :see: |
31 | | - http://mail.python.org/pipermail/python-list/2005-February/325395.html |
32 | | - """ |
33 | | - try: |
34 | | - if not PY3min and sys.platform == 'win32': |
35 | | - path = os.path.expanduser(b"~").decode(sys.getfilesystemencoding()) |
36 | | - else: |
37 | | - path = os.path.expanduser("~") |
38 | | - except ImportError: |
39 | | - # This happens on Google App Engine (pwd module is not present). |
40 | | - pass |
41 | | - else: |
42 | | - if os.path.isdir(path): |
43 | | - return path |
44 | | - for evar in ('HOME', 'USERPROFILE', 'TMP'): |
45 | | - path = os.environ.get(evar) |
46 | | - if path is not None and os.path.isdir(path): |
47 | | - return path |
48 | | - return None |
49 | | - |
50 | | - |
51 | 26 | def _get_xdg_cache_dir(): |
52 | 27 | """ |
53 | | - Returns the XDG cache directory, according to the `XDG |
54 | | - base directory spec |
55 | | - <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_. |
| 28 | + Return the XDG cache directory. |
| 29 | +
|
| 30 | + See https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
56 | 31 | """ |
57 | | - path = os.environ.get('XDG_CACHE_HOME') |
58 | | - if path is None: |
59 | | - path = _get_home() |
60 | | - if path is not None: |
61 | | - path = os.path.join(path, '.cache', 'matplotlib') |
62 | | - return path |
| 32 | + cache_dir = os.environ.get('XDG_CACHE_HOME') |
| 33 | + if not cache_dir: |
| 34 | + cache_dir = os.path.expanduser('~/.cache') |
| 35 | + if cache_dir.startswith('~/'): # Expansion failed. |
| 36 | + return None |
| 37 | + return os.path.join(cache_dir, 'matplotlib') |
63 | 38 |
|
64 | 39 |
|
65 | 40 | # SHA256 hashes of the FreeType tarballs |
|
0 commit comments