U n a e @sdZdZdeeeZddlZddlZejddkZ e r>eZ ej drddl Z e ddZe drrdZqe d rd Zqd Zn ej d krejd krdZnej Zd8ddZd9ddZd:ddZd;ddZdddZGdddeZd d!Zd"d#Zd$d%Zd&d'Zedkrzdd(lmZeZ WnBe!k r~zddl"Z#eZ Wne!k rxeZ YnXYnXd)d*Z$e%d+kr~d,Z&d-Z'd.Z(e)d/ee)d0ee&e'd1d2Z*e(D]Z+e)d3e+e,e*e+fqe)d4ee&e'Z*e(D]Z+e)d3e+e,e*e+fqe)d5ee&Z*e(D]Z+e)d3e+e,e*e+fq*e)d6ee&dd7Z*e(D]Z+e)d3e+e,e*e+fq`dS)?zyUtilities for determining application-specific dirs. See for details and usage. ).NrjavaWindowswin32ZMacdarwinZlinux2clintFcCstdkr^|dkr|}|rdpd}tjt|}|r|dk rNtj|||}qtj||}nNtdkrtjd}|rtj||}n&tdtjd }|rtj||}|r|rtj||}|S) aReturn 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. "appauthor" (only used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be ".". Only applied when appname is present. "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 for a discussion of issues. Typical user data directories are: Mac OS X: ~/Library/Application Support/ # or ~/.config/, if the other does not exist Unix: ~/.local/share/ # or in $XDG_DATA_HOME, if defined Win XP (not roaming): C:\Documents and Settings\\Application Data\\ Win XP (roaming): C:\Documents and Settings\\Local Settings\Application Data\\ Win 7 (not roaming): C:\Users\\AppData\Local\\ Win 7 (roaming): C:\Users\\AppData\Roaming\\ For Unix, we follow the XDG spec and support $XDG_DATA_HOME. That means, by default "~/.local/share/". rN CSIDL_APPDATACSIDL_LOCAL_APPDATAFr z~/Library/Application Support/ XDG_DATA_HOMEz~/.local/share)systemospathnormpath_get_win_folderjoin expandusergetenv)appname appauthorversionroamingconstrrTC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-6mt8ur68\pip\_vendor\appdirs.py user_data_dir1s&   rcs tdkrR|dkr}tjtd}r|dk rBtj||}qtj|}ntdkrztjd}rtj|}nttdtjdd g}d d | tjD}r|rtj|fd d |D}|rtj|}n|d }|Sr|rtj||}|S)aiReturn full path to the user-shared data dir for this application. "appname" is the name of application. If None, just the system directory is returned. "appauthor" (only used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be ".". Only applied when appname is present. "multipath" is an optional parameter only applicable to *nix which indicates that the entire list of data dirs should be returned. By default, the first item from XDG_DATA_DIRS is returned, or '/usr/local/share/', if XDG_DATA_DIRS is not set Typical site data directories are: Mac OS X: /Library/Application Support/ Unix: /usr/local/share/ or /usr/share/ Win XP: C:\Documents and Settings\All Users\Application Data\\ Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.) Win 7: C:\ProgramData\\ # Hidden, but writeable on Win 7. For Unix, this is using the $XDG_DATA_DIRS[0] default. WARNING: Do not use this on Windows. See the Vista-Fail note above for why. rNCSIDL_COMMON_APPDATAFr z/Library/Application Support XDG_DATA_DIRSz/usr/local/sharez /usr/sharecSs g|]}tj|tjqSrrrrrstripsep.0xrrr sz!site_data_dir..csg|]}tj|qSrrrrr$rrrr'sr) rrrrrrrrpathsepsplitrrr multipathrpathlistrr)r site_data_dirhs6  r/cCsXtdkrt||d|}n&tdtjd}|r>tj||}|rT|rTtj||}|S)aReturn 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. "appauthor" (only used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be ".". Only applied when appname is present. "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 for a discussion of issues. Typical user config directories are: Mac OS X: same as user_data_dir Unix: ~/.config/ # or in $XDG_CONFIG_HOME, if defined Win *: same as user_data_dir For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME. That means, by default "~/.config/". rr NXDG_CONFIG_HOMEz ~/.configrrrrrrrrrrrrrrruser_config_dirsr4cstdkr*t|}r|rtj||}nftdp6d}dd|tjD}rv|rdtj|fdd|D}|rtj|}n|d}|S)aReturn full path to the user-shared data dir for this application. "appname" is the name of application. If None, just the system directory is returned. "appauthor" (only used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be ".". Only applied when appname is present. "multipath" is an optional parameter only applicable to *nix which indicates that the entire list of config dirs should be returned. By default, the first item from XDG_CONFIG_DIRS is returned, or '/etc/xdg/', if XDG_CONFIG_DIRS is not set Typical site config directories are: Mac OS X: same as site_data_dir Unix: /etc/xdg/ or $XDG_CONFIG_DIRS[i]/ for each value in $XDG_CONFIG_DIRS Win *: same as site_data_dir Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.) For Unix, this is using the $XDG_CONFIG_DIRS[0] default, if multipath=False WARNING: Do not use this on Windows. See the Vista-Fail note above for why. r0XDG_CONFIG_DIRSz/etc/xdgcSs$g|]}|rtj|tjqSrr!r$rrrr'sz#site_config_dir..csg|]}tj|qSrr(r$r)rrr'sr)rr/rrrrr+r*r,rr)rsite_config_dirs r6TcCstdkrz|dkr|}tjtd}ts:t|tr:t|}|r|dk rXtj |||}ntj ||}|rtj |d}nNtdkrtj d}|rtj ||}n&t dtj d }|rtj ||}|r|rtj ||}|S) aReturn full path to the user-specific cache dir for this application. "appname" is the name of application. If None, just the system directory is returned. "appauthor" (only used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be ".". Only applied when appname is present. "opinion" (boolean) can be False to disable the appending of "Cache" to the base app data dir for Windows. See discussion below. Typical user cache directories are: Mac OS X: ~/Library/Caches/ Unix: ~/.cache/ (XDG default) Win XP: C:\Documents and Settings\\Local Settings\Application Data\\\Cache Vista: C:\Users\\AppData\Local\\\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` above). Apps typically put cache data somewhere *under* the given dir here. Some examples: ...\Mozilla\Firefox\Profiles\\Cache ...\Acme\SuperApp\Cache\1.0 OPINION: This function appends "Cache" to the `CSIDL_LOCAL_APPDATA` value. This can be disabled with the `opinion=False` option. rNr FCacher z~/Library/CachesXDG_CACHE_HOMEz~/.cache) rrrrrPY3 isinstanceunicode_win_path_to_bytesrrrrrropinionrrrruser_cache_dirs,! r?cCsXtdkrt||d|}n&tdtjd}|r>tj||}|rT|rTtj||}|S)aReturn full path to the user-specific state dir for this application. "appname" is the name of application. If None, just the system directory is returned. "appauthor" (only used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be ".". Only applied when appname is present. "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 for a discussion of issues. Typical user state directories are: Mac OS X: same as user_data_dir Unix: ~/.local/state/ # or in $XDG_STATE_HOME, if defined Win *: same as user_data_dir For Unix, we follow this Debian proposal to extend the XDG spec and support $XDG_STATE_HOME. That means, by default "~/.local/state/". r0NXDG_STATE_HOMEz~/.local/stater2r3rrruser_state_dirEsrAcCstdkr tjtjd|}nNtdkrLt|||}d}|rntj|d}n"t|||}d}|rntj|d}|r|rtj||}|S)aReturn full path to the user-specific log dir for this application. "appname" is the name of application. If None, just the system directory is returned. "appauthor" (only used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be ".". Only applied when appname is present. "opinion" (boolean) can be False to disable the appending of "Logs" to the base app data dir for Windows, and "log" to the base cache dir for Unix. See discussion below. Typical user log directories are: Mac OS X: ~/Library/Logs/ Unix: ~/.cache//log # or under $XDG_CACHE_HOME if defined Win XP: C:\Documents and Settings\\Local Settings\Application Data\\\Logs Vista: C:\Users\\AppData\Local\\\Logs On Windows the only suggestion in the MSDN docs is that local settings go in the `CSIDL_LOCAL_APPDATA` directory. (Note: I'm interested in examples of what some windows apps use for a logs dir.) OPINION: This function appends "Logs" to the `CSIDL_LOCAL_APPDATA` value for Windows and appends "log" to the user cache dir for Unix. This can be disabled with the `opinion=False` option. r z~/Library/LogsrFLogslog)rrrrrrr?r=rrr user_log_diros"    rDc@sneZdZdZdddZeddZedd Zed d Zed d Z eddZ eddZ eddZ dS)AppDirsz1Convenience wrapper for getting application dirs.NFcCs"||_||_||_||_||_dS)N)rrrrr-)selfrrrrr-rrr__init__s zAppDirs.__init__cCst|j|j|j|jdSN)rr)rrrrrrFrrrrs zAppDirs.user_data_dircCst|j|j|j|jdSN)rr-)r/rrrr-rIrrrr/s zAppDirs.site_data_dircCst|j|j|j|jdSrH)r4rrrrrIrrrr4s zAppDirs.user_config_dircCst|j|j|j|jdSrJ)r6rrrr-rIrrrr6s zAppDirs.site_config_dircCst|j|j|jdSNr)r?rrrrIrrrr?s zAppDirs.user_cache_dircCst|j|j|jdSrK)rArrrrIrrrrAs zAppDirs.user_state_dircCst|j|j|jdSrK)rDrrrrIrrrrDs zAppDirs.user_log_dir)NNNFF) __name__ __module__ __qualname____doc__rGpropertyrr/r4r6r?rArDrrrrrEs&       rEcCsHtrddl}nddl}dddd|}||jd}|||\}}|S)zThis 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. rNAppDatazCommon AppDataz Local AppDatar rr z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)r9winreg_winregOpenKeyHKEY_CURRENT_USER QueryValueEx) csidl_namerUshell_folder_namekeydirtyperrr_get_win_folder_from_registrys r^cCsddlm}m}|dt||dd}z^t|}d}|D]}t|dkr8d}qRq8|rzddl}||}Wnt k rYnXWnt k rYnX|S)Nr)shellconshellFT) win32com.shellr_r`SHGetFolderPathgetattrr;ordwin32apiGetShortPathName ImportError UnicodeError)rYr_r`r\ has_high_charcrfrrr_get_win_folder_with_pywin32s$  rlcCsddl}dddd|}|d}|jjd|dd|d}|D]}t|dkr@d }qZq@|r|d}|jj|j|dr|}|jS) Nr#rSiFraT) ctypescreate_unicode_bufferwindllshell32SHGetFolderPathWrekernel32GetShortPathNameWvalue)rYrp csidl_constbufrjrkbuf2rrr_get_win_folder_with_ctypess&   r{c Csddl}ddlm}ddlm}|jjd}|d|}|jj }| dt |j |d|j j ||j|d}d}|D]} t| dkr|d }qq||r|d|}|jj } | |||r|j|d}|S) Nr)jna)rrkFraT)arraycom.sunr|com.sun.jna.platformrWinDefMAX_PATHzerosShell32INSTANCErcrdShlObjSHGFP_TYPE_CURRENTNativetoStringtostringr"reKernel32rg) rYrr|rbuf_sizeryr`r\rjrkkernelrrr_get_win_folder_with_jnas&      r)rrc Cs8dD].}z||WSttfk r0YqXq|S)aEncode 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 . If encoding using ASCII and MBCS fails, return the original Unicode path. )ASCIIMBCS)encodeUnicodeEncodeError LookupError)rencodingrrrr<Es r<__main__ZMyAppZ MyCompany)rr4r?rArDr/r6z-- app dirs %s --z%-- app dirs (with optional 'version')z1.0rLz%s: %sz) -- app dirs (without optional 'version')z+ -- app dirs (without optional 'appauthor')z( -- app dirs (with disabled 'appauthor'))r)NNNF)NNNF)NNNF)NNNF)NNNT)NNNF)NNNT)-rP__version_info__rmapstr __version__sysr version_infor9r;platform startswithjava_veros_namernamerr/r4r6r?rArDobjectrEr^rlr{rrprrrrhZ com.sun.jnacomr<rMrrpropsprintdirsproprdrrrrs|     7 B * 4 = * 30