a „oeÄã@s°ddlmZddlZddlZddlZddlmZddlmZddl m Z Gdd„de ƒZ d d d œd d „Z d d d œd d„Z d d d œdd„Zddœdd„Zedd�eƒƒZdgZdS)é)Ú annotationsN)Ú lru_cache)ÚCallableé)ÚPlatformDirsABCc@sÊeZdZdZeddœdd„ƒZddœdddd œd d „Zeddœd d „ƒZeddœdd„ƒZeddœdd„ƒZ eddœdd„ƒZ eddœdd„ƒZ eddœdd„ƒZ eddœdd„ƒZ eddœdd„ƒZdS)ÚWindowsaÅ`MSDN on where to store app data files `_. Makes use of the `appname `, `appauthor `, `version `, `roaming `, `opinion `.Ústr©ÚreturncCs(|jr dnd}tj 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)ZroamingÚosÚpathÚnormpathÚget_win_folderÚ _append_parts)ÚselfÚconstr©rúKC:\Program Files\Certbot\pkgs\pkg_resources\_vendor\platformdirs\windows.pyÚ user_data_dirszWindows.user_data_dirN©Ú opinion_valuez str | None)rrr cCstg}|jr`|jdur*|jp|j}| |¡| |j¡|durN|jrN| |¡|jr`| |j¡tjj|g|¢RŽS)NF)ZappnameZ appauthorÚappendÚopinionÚversionr rÚjoin)rrrÚparamsZauthorrrrr!s      zWindows._append_partscCstj tdƒ¡}| |¡S)zT:return: data directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname``ÚCSIDL_COMMON_APPDATA©r rrrr©rrrrrÚ site_data_dir.szWindows.site_data_dircCs|jS)zC:return: config directory tied to the user, same as `user_data_dir`©r©rrrrÚuser_config_dir4szWindows.user_config_dircCs|jS)zF:return: config directory shared by the users, same as `site_data_dir`)r!r#rrrÚsite_config_dir9szWindows.site_config_dircCstj tdƒ¡}|j|dd�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 ZCacherrr rrrÚuser_cache_dir>szWindows.user_cache_dircCs|jS)zB:return: state directory tied to the user, same as `user_data_dir`r"r#rrrÚuser_state_dirGszWindows.user_state_dircCs|j}|jrtj |d¡}|S)zy :return: log directory tied to the user, same as `user_data_dir` if not opinionated else ``Logs`` in it ZLogs)rrr rrr rrrÚ user_log_dirLszWindows.user_log_dircCstj tdƒ¡S)z` :return: documents directory tied to the user e.g. ``%USERPROFILE%\Documents`` ÚCSIDL_PERSONAL)r rrrr#rrrÚuser_documents_dirVszWindows.user_documents_dircCs$tj tj tdƒd¡¡}| |¡S)z… :return: runtime directory tied to the user, e.g. ``%USERPROFILE%\AppData\Local\Temp\$appauthor\$appname`` r ZTemp)r rrrrrr rrrÚuser_runtime_dir]szWindows.user_runtime_dir)Ú__name__Ú __module__Ú __qualname__Ú__doc__Úpropertyrrr!r$r%r&r'r(r*r+rrrrr s(    rr)Ú csidl_namer cCsr|dkr$tj tj tjd¡d¡Sddddœ |¡}|durLtd |›�ƒ‚tj |¡}|durntd |›�ƒ‚|S) z&Get folder from environment variables.r)Ú USERPROFILEZ DocumentsÚAPPDATAZALLUSERSPROFILEZ LOCALAPPDATA)r rr NúUnknown CSIDL name: zUnset environment variable: )r rrrÚenvironÚgetÚ ValueError)r1Z env_var_nameÚresultrrrÚget_win_folder_from_env_varsgsýü r9cCsfdddddœ |¡}|dur*td|›�ƒ‚tjdkr8t‚d dl}| |jd ¡}| ||¡\}}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. ZAppDatazCommon AppDataz Local AppDataZPersonal©r rr r)Nr4Úwin32rz@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders) r6r7ÚsysÚplatformÚNotImplementedErrorÚwinregÚOpenKeyÚHKEY_CURRENT_USERÚ QueryValueExr)r1Zshell_folder_namer?ÚkeyZ directoryÚ_rrrÚget_win_folder_from_registryysüû rEcCsŠdddddœ |¡}|dur*td|›�ƒ‚t d¡}ttd ƒ}|j d|dd |¡td d „|Dƒƒr„t d¡}|j  |j |d¡r„|}|j S) zGet folder with ctypes.éé#éér:Nr4iÚwindllrcss|]}t|ƒdkVqdS)éÿN)Úord)Ú.0ÚcrrrÚ ¡óz,get_win_folder_via_ctypes..) r6r7ÚctypesZcreate_unicode_bufferÚgetattrZshell32ZSHGetFolderPathWÚanyZkernel32ZGetShortPathNameWÚvalue)r1Z csidl_constÚbufrJZbuf2rrrÚget_win_folder_via_ctypes‘s"üû   rVzCallable[[str], str]r cCs:ttdƒrtSz ddl}Wnty0tYS0tSdS)NrJr)ÚhasattrrQrVr?Ú ImportErrorr9rE)r?rrrÚ_pick_get_win_folder©s    rY)Úmaxsize)Z __future__rrQr r<Ú functoolsrÚtypingrZapirrr9rErVrYrÚ__all__rrrrÚs    [ ÿ