
}_k"                 @   s   d  Z  d d l m Z d d l Z d d l Z d d l m Z m Z d d l m	 Z	 m
 Z
 d d   Z d d	 d
  Z d d d  Z d d   Z d d   Z d d   Z e r y d d l Z e Z Wn e k
 r e Z Yn Xd d   Z d S)zd
This code was taken from https://github.com/ActiveState/appdirs and modified
to suit our purposes.
    )absolute_importN)WINDOWS
expanduser)PY2	text_typec             C   s   t  rZ t j j t d   } t r? t | t  r? t |  } t j j	 | |  d  } n` t
 j d k r t d  } t j j	 | |   } n- t j d t d   } t j j	 | |   } | S)a5  
    Return full path to the user-specific cache dir for this application.

        "appname" is the name of application.

    Typical user cache directories are:
        macOS:      ~/Library/Caches/<AppName>
        Unix:       ~/.cache/<AppName> (XDG default)
        Windows:    C:\Users\<username>\AppData\Local\<AppName>\Cache

    On Windows the only suggestion in the MSDN docs is that local settings go
    in the `CSIDL_LOCAL_APPDATA` directory. This is identical to the
    non-roaming app data dir (the default returned by `user_data_dir`). Apps
    typically put cache data somewhere *under* the given dir here. Some
    examples:
        ...\Mozilla\Firefox\Profiles\<ProfileName>\Cache
        ...\Acme\SuperApp\Cache\1.0

    OPINION: This function appends "Cache" to the `CSIDL_LOCAL_APPDATA` value.
    CSIDL_LOCAL_APPDATACachedarwinz~/Library/CachesXDG_CACHE_HOMEz~/.cache)r   ospathnormpath_get_win_folderr   
isinstancer   _win_path_to_bytesjoinsysplatformr   getenv)appnamer    r   0/tmp/pip-build-3_sjtvrs/pip/pip/utils/appdirs.pyuser_cache_dir   s    r   Fc             C   s   t  rB | r d p d } t j j t j j t |   |   } nT t j d k ro t j j t d  |   } n' t j j t j	 d t d   |   } | S)aS  
    Return full path to the user-specific data dir for this application.

        "appname" is the name of application.
            If None, just the system directory is returned.
        "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 data directories are:
        macOS:                  ~/Library/Application Support/<AppName>
        Unix:                   ~/.local/share/<AppName>    # or in
                                $XDG_DATA_HOME, if defined
        Win XP (not roaming):   C:\Documents and Settings\<username>\ ...
                                ...Application Data\<AppName>
        Win XP (roaming):       C:\Documents and Settings\<username>\Local ...
                                ...Settings\Application Data\<AppName>
        Win 7  (not roaming):   C:\Users\<username>\AppData\Local\<AppName>
        Win 7  (roaming):       C:\Users\<username>\AppData\Roaming\<AppName>

    For Unix, we follow the XDG spec and support $XDG_DATA_HOME.
    That means, by default "~/.local/share/<AppName>".
    CSIDL_APPDATAr   r	   z~/Library/Application Support/XDG_DATA_HOMEz~/.local/share)
r   r   r   r   r   r   r   r   r   r   )r   roamingconstr   r   r   r   user_data_dir>   s    *				r   Tc             C   sj   t  r t |  d | } nK t j d k r9 t |   } n- t j d t d   } t j j | |   } | S)ar  Return full path to the user-specific config dir for this application.

        "appname" is the name of application.
            If None, just the system directory is returned.
        "roaming" (boolean, default True) can be set False to not 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 data directories are:
        macOS:                  same as user_data_dir
        Unix:                   ~/.config/<AppName>
        Win *:                  same as user_data_dir

    For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME.
    That means, by default "~/.config/<AppName>".
    r   r	   XDG_CONFIG_HOMEz	~/.config)	r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   user_config_dirj   s    r   c                s   t  r9 t j j t d   } t j j |    g } n} t j d k rc t j j d    g } nS t j d d  } | r   f d d   | j	 t j
  D } n g  } | j d  | S)	a  Return a list of potential user-shared config dirs for this application.

        "appname" is the name of application.

    Typical user config directories are:
        macOS:      /Library/Application Support/<AppName>/
        Unix:       /etc or $XDG_CONFIG_DIRS[i]/<AppName>/ for each value in
                    $XDG_CONFIG_DIRS
        Win XP:     C:\Documents and Settings\All Users\Application ...
                    ...Data\<AppName>        Vista:      (Fail! "C:\ProgramData" is a hidden *system* directory
                    on Vista.)
        Win 7:      Hidden, but writeable on Win 7:
                    C:\ProgramData\<AppName>    CSIDL_COMMON_APPDATAr	   z/Library/Application SupportXDG_CONFIG_DIRSz/etc/xdgc                s+   g  |  ]! } t  j j t |      q Sr   )r   r   r   r   ).0x)r   r   r   
<listcomp>   s   	z$site_config_dirs.<locals>.<listcomp>z/etc)r   r   r   r   r   r   r   r   r   splitpathsepappend)r   r   pathlistxdg_config_dirsr   )r   r   site_config_dirs   s    r*   c             C   sY   d d l  } d d d d d d i |  } | j | j d	  } | j | |  \ } } | S)
z
    This is a fallback technique at best. I'm not sure if using the
    registry for this guarantees us the correct answer for all CSIDL_*
    names.
    r   Nr   AppDatar    zCommon AppDatar   zLocal AppDataz@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)_winregOpenKeyHKEY_CURRENT_USERQueryValueEx)
csidl_namer,   shell_folder_namekey	directory_typer   r   r   _get_win_folder_from_registry   s    		r5   c             C   s   d d d d d d i |  } t  j d  } t  j j j d  | d  d |  d	 } x' | D] } t |  d
 k rW d } PqW W| r t  j d  } t  j j j | j | d  r | } | j S)Nr      r    #   r      i   r   F   T)	ctypescreate_unicode_bufferwindllshell32SHGetFolderPathWordkernel32GetShortPathNameWvalue)r0   csidl_constbufhas_high_charcbuf2r   r   r   _get_win_folder_with_ctypes   s     	rH   c             C   sA   x: d D]2 } y |  j  |  SWq t t f k
 r8 Yq Xq W|  S)a  Encode Windows paths to bytes. Only used on Python 2.

    Motivation is to be consistent with other operating systems where paths
    are also returned as bytes. This avoids problems mixing bytes and Unicode
    elsewhere in the codebase. For more details and discussion see
    <https://github.com/pypa/pip/issues/3463>.

    If encoding using ASCII and MBCS fails, return the original Unicode path.
    ASCIIMBCS)rI   rJ   )encodeUnicodeEncodeErrorLookupError)r   encodingr   r   r   r      s    
	r   )__doc__
__future__r   r   r   
pip.compatr   r   Zpip._vendor.sixr   r   r   r   r   r*   r5   rH   r:   r   ImportErrorr   r   r   r   r   <module>   s$   0,!(
