a
    hbòf'  ã                   @  s¨   d dl mZ d dlZd dlZd dlmZ d dlmZ ddlm	Z	 G dd„ de	ƒZ
d	d	d
œdd„Zd	d	d
œdd„Zd	d	d
œdd„Zddœdd„Zedd�eƒ ƒZdgZdS )é    )ÚannotationsN)Ú	lru_cache)ÚCallableé   )ÚPlatformDirsABCc                   @  sÊ   e Zd ZdZeddœdd„ƒZddœdddd	œd
d„Zeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZ	eddœdd„ƒZ
eddœdd„ƒZeddœdd„ƒZeddœdd„ƒZed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>`.Ústr©Úreturnc                 C  s(   | j r
dnd}tj t|ƒ¡}|  |¡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   ú]/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/pip/_vendor/platformdirs/windows.pyÚuser_data_dir   s    zWindows.user_data_dirN©Úopinion_valuez
str | None)r   r   r
   c                C  st   g }| j r`| jdur*| jp| j }| |¡ | | j ¡ |d urN| jrN| |¡ | jr`| | j¡ tjj|g|¢R Ž 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 tdƒ¡}|  |¡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_dir3   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_dir8   s    zWindows.site_config_dirc                 C  s   t 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   ÚCacher   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_dirF   s    zWindows.user_state_dirc                 C  s   | j }| jrtj |d¡}|S )zy
        :return: log directory tied to the user, same as `user_data_dir` if not opinionated else ``Logs`` in it
        ZLogs)r   r   r   r   r   r$   r   r   r   Úuser_log_dirK   s    zWindows.user_log_dirc                 C  s   t 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_dirU   s    zWindows.user_documents_dirc                 C  s$   t j t j tdƒd¡¡}|  |¡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   Úuser_runtime_dir\   s    zWindows.user_runtime_dir)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   r%   r(   r)   r+   r,   r-   r/   r0   r   r   r   r   r      s(   	
	r   r   )Ú
csidl_namer
   c                 C  sr   | dkr$t j t j t jd ¡d¡S ddddœ | ¡}|du rLtd	| › �ƒ‚t j |¡}|du rntd
|› �ƒ‚|S )z&Get folder from environment variables.r.   ÚUSERPROFILEZ	DocumentsÚAPPDATAZALLUSERSPROFILEÚLOCALAPPDATA)r   r"   r   NúUnknown CSIDL name: zUnset environment variable: )r   r   r   r   ÚenvironÚgetÚ
ValueError)r6   Zenv_var_nameÚresultr   r   r   Úget_win_folder_from_env_varsf   s    ýür?   c                 C  sX   dddddœ  | ¡}|du r*td| › �ƒ‚ddl}| |jd	¡}| ||¡\}}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.
    ZAppDatazCommon AppDatazLocal AppDataZPersonal©r   r"   r   r.   Nr:   r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)r<   r=   ÚwinregÚOpenKeyÚHKEY_CURRENT_USERÚQueryValueExr   )r6   Zshell_folder_namerA   ÚkeyÚ	directoryÚ_r   r   r   Úget_win_folder_from_registryx   s    üûrH   c                 C  sŠ   dddddœ  | ¡}|du r*td| › �ƒ‚t d¡}ttd	ƒ}|j d|dd
|¡ tdd„ |D ƒƒr„t d¡}|j 	|j
|d¡r„|}|j
S )zGet folder with ctypes.é   é#   é   é   r@   Nr:   i   Úwindllr   c                 s  s   | ]}t |ƒd kV  qdS )éÿ   N)Úord)Ú.0Úcr   r   r   Ú	<genexpr>Ÿ   ó    z,get_win_folder_via_ctypes.<locals>.<genexpr>)r<   r=   ÚctypesÚcreate_unicode_bufferÚgetattrZshell32ZSHGetFolderPathWÚanyZkernel32ZGetShortPathNameWÚvalue)r6   Zcsidl_constÚbufrM   Zbuf2r   r   r   Úget_win_folder_via_ctypes�   s"    üû


rZ   zCallable[[str], str]r	   c                  C  s:   t tdƒrtS zdd l} W n ty0   t Y S 0 tS d S )NrM   r   )ÚhasattrrT   rZ   rA   ÚImportErrorr?   rH   )rA   r   r   r   Ú_pick_get_win_folder§   s    

r]   )Úmaxsize)Ú
__future__r   rT   r   Ú	functoolsr   Útypingr   Úapir   r   r?   rH   rZ   r]   r   Ú__all__r   r   r   r   Ú<module>   s   [ÿ