3
ûâde  ã               @   sª   d dl Z d dlZd dlmZ d dlmZmZ ddlmZ G dd„ deƒZ	e
e
dœd	d
„Ze
e
dœdd„Ze
e
dœdd„Zee
ge
f dœdd„Zedd�eƒ ƒZdgZdS )é    N)Ú	lru_cache)ÚCallableÚOptionalé   )ÚPlatformDirsABCc               @   sÎ   e Zd ZdZeedœdd„ƒZddœeee edœdd	„Zeedœd
d„ƒZ	eedœdd„ƒZ
eedœdd„ƒZeedœdd„ƒZeedœdd„ƒZeedœdd„ƒZeedœdd„ƒZeedœdd„ƒZdS )ÚWindowsaÅ  `MSDN on where to store app data files
    <http://support.microsoft.com/default.aspx?scid=kb;en-us;310294#XSLTH3194121123120121120120>`_.
    Makes use of the
    `appname <platformdirs.api.PlatformDirsABC.appname>`,
    `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`,
    `version <platformdirs.api.PlatformDirsABC.version>`,
    `roaming <platformdirs.api.PlatformDirsABC.roaming>`,
    `opinion <platformdirs.api.PlatformDirsABC.opinion>`.)Úreturnc             C   s(   | j r
dnd}tjjt|ƒƒ}| j|ƒS )z×
        :return: data directory tied to the user, e.g.
         ``%USERPROFILE%\AppData\Local\$appauthor\$appname`` (not roaming) or
         ``%USERPROFILE%\AppData\Roaming\$appauthor\$appname`` (roaming)
        ÚCSIDL_APPDATAÚCSIDL_LOCAL_APPDATA)ÚroamingÚosÚpathÚnormpathÚget_win_folderÚ_append_parts)ÚselfÚconstr   © r   ú?/tmp/pip-build-red6nood/pip/pip/_vendor/platformdirs/windows.pyÚuser_data_dir   s    zWindows.user_data_dirN)Úopinion_value)r   r   r   c            C   sr   g }| j r`| jdk	r*| jp| j }|j|ƒ |j| j ƒ |d k	rN| jrN|j|ƒ | jr`|j| jƒ tjj|f|žŽ S )NF)ÚappnameÚ	appauthorÚappendÚopinionÚversionr   r   Újoin)r   r   r   ÚparamsÚauthorr   r   r   r      s    


zWindows._append_partsc             C   s   t jjtdƒƒ}| j|ƒS )zT:return: data directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname``ÚCSIDL_COMMON_APPDATA)r   r   r   r   r   )r   r   r   r   r   Úsite_data_dir+   s    zWindows.site_data_dirc             C   s   | j S )zC:return: config directory tied to the user, same as `user_data_dir`)r   )r   r   r   r   Úuser_config_dir1   s    zWindows.user_config_dirc             C   s   | j S )zF:return: config directory shared by the users, same as `site_data_dir`)r    )r   r   r   r   Úsite_config_dir6   s    zWindows.site_config_dirc             C   s   t jjtdƒƒ}| j|dd�S )zÇ
        :return: cache directory tied to the user (if opinionated with ``Cache`` folder within ``$appname``) e.g.
         ``%USERPROFILE%\AppData\Local\$appauthor\$appname\Cache\$version``
        r
   ÚCache)r   )r   r   r   r   r   )r   r   r   r   r   Úuser_cache_dir;   s    zWindows.user_cache_dirc             C   s   | j S )zB:return: state directory tied to the user, same as `user_data_dir`)r   )r   r   r   r   Úuser_state_dirD   s    zWindows.user_state_dirc             C   s   | j }| jrtjj|dƒ}|S )zy
        :return: log directory tied to the user, same as `user_data_dir` if not opinionated else ``Logs`` in it
        ÚLogs)r   r   r   r   r   )r   r   r   r   r   Úuser_log_dirI   s    zWindows.user_log_dirc             C   s   t jjtdƒƒS )z`
        :return: documents directory tied to the user e.g. ``%USERPROFILE%\Documents``
        ÚCSIDL_PERSONAL)r   r   r   r   )r   r   r   r   Úuser_documents_dirS   s    zWindows.user_documents_dirc             C   s$   t jjt jjtdƒdƒƒ}| j|ƒS )z…
        :return: runtime directory tied to the user, e.g.
         ``%USERPROFILE%\AppData\Local\Temp\$appauthor\$appname``
        r
   ZTemp)r   r   r   r   r   r   )r   r   r   r   r   Úuser_runtime_dirZ   s    zWindows.user_runtime_dir)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚpropertyÚstrr   r   r   r    r!   r"   r$   r%   r'   r)   r*   r   r   r   r   r   	   s(   
	r   )Ú
csidl_namer   c             C   sr   | dkr$t jjt jjt jd ƒdƒS ddddœj| ƒ}|dkrLtd	| › �ƒ‚t jj|ƒ}|dkrntd
|› �ƒ‚|S )z&Get folder from environment variables.r(   ZUSERPROFILEZ	DocumentsÚAPPDATAZALLUSERSPROFILEÚLOCALAPPDATA)r	   r   r
   NzUnknown CSIDL name: zUnset environment variable: )r   r   r   r   ÚenvironÚgetÚ
ValueError)r1   Zenv_var_nameÚresultr   r   r   Úget_win_folder_from_env_varsd   s    r8   c             C   sX   dddddœj | ƒ}|dkr*td| › �ƒ‚ddl}|j|jd	ƒ}|j||ƒ\}}t|ƒS )
z¹Get folder from the registry.

    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.
    ÚAppDatazCommon AppDatazLocal AppDataZPersonal)r	   r   r
   r(   NzUnknown CSIDL name: r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)r5   r6   ÚwinregÚOpenKeyÚHKEY_CURRENT_USERÚQueryValueExr0   )r1   Úshell_folder_namer:   ÚkeyÚ	directoryÚ_r   r   r   Úget_win_folder_from_registryv   s    rB   c             C   sŠ   dddddœj | ƒ}|dkr*td| › �ƒ‚tjdƒ}ttd	ƒ}|jjd|dd
|ƒ tdd„ |D ƒƒr„tjdƒ}|jj	|j
|dƒr„|}|j
S )zGet folder with ctypes.é   é#   é   é   )r	   r   r
   r(   NzUnknown CSIDL name: i   Úwindllr   c             s   s   | ]}t |ƒd kV  qdS )éÿ   N)Úord)Ú.0Úcr   r   r   ú	<genexpr>�   s    z,get_win_folder_via_ctypes.<locals>.<genexpr>)r5   r6   ÚctypesÚcreate_unicode_bufferÚgetattrÚshell32ÚSHGetFolderPathWÚanyÚkernel32ÚGetShortPathNameWÚvalue)r1   Úcsidl_constÚbufrG   Úbuf2r   r   r   Úget_win_folder_via_ctypes�   s    


rY   )r   c              C   s8   t tdƒrtS ydd l} W n tk
r.   tS X tS d S )NrG   r   )ÚhasattrrM   rY   r:   ÚImportErrorr8   rB   )r:   r   r   r   Ú_pick_get_win_folder¥   s    
r\   )Úmaxsize)rM   r   Ú	functoolsr   Útypingr   r   Úapir   r   r0   r8   rB   rY   r\   r   Ú__all__r   r   r   r   Ú<module>   s   [