
    Kd                        d dl mZ d dl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e
          ZddZddZddZddZ  ed           e                      ZdgZdS )    )annotationsN)	lru_cache)Callable   )PlatformDirsABCc                     e Zd ZdZedd            Zdddd
Zedd            Zedd            Zedd            Z	edd            Z
edd            Zedd            Zedd            Zedd            Ze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>`,
    `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
    returnstrc                    | 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   s      FF:\djangOuth\env\Lib\site-packages\pip/_vendor/platformdirs/windows.pyuser_data_dirzWindows.user_data_dir   sF     $(<J5Jwu 5 566!!$'''    Nopinion_valuer   r   
str | Nonec               z   g }| j         r| j        dur#| j        p| j         }|                    |           |                    | j                    || j        r|                    |           | j        r|                    | j                   t          j        j        |g|R  }|                     |           |S )NF)	appname	appauthorappendopinionversionr   r   join_optionally_create_directory)r   r   r   paramsauthors        r   r   zWindows._append_parts#   s    < 	,~U**74<f%%%MM$,'''(T\(m,,,| ,dl+++w|D*6***))$///r   c                    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   s     r   site_data_dirzWindows.site_data_dir2   s6     w/E F FGG!!$'''r   c                    | j         S )zC:return: config directory tied to the user, same as `user_data_dir`r   r   s    r   user_config_dirzWindows.user_config_dir8        !!r   c                    | j         S )zF:return: config directory shared by the users, same as `site_data_dir`)r+   r.   s    r   site_config_dirzWindows.site_config_dir=   r0   r   c                    t           j                            t          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*   s     r   user_cache_dirzWindows.user_cache_dirB   s;     w/D E EFF!!$g!>>>r   c                    t           j                            t          d                    }|                     |d          S )zd:return: cache directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname\Cache\$version``r(   r4   r   r)   r*   s     r   site_cache_dirzWindows.site_cache_dirK   s;     w/E F FGG!!$g!>>>r   c                    | j         S )zB:return: state directory tied to the user, same as `user_data_dir`r-   r.   s    r   user_state_dirzWindows.user_state_dirQ   r0   r   c                    | j         }| j        r5t          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*   s     r   user_log_dirzWindows.user_log_dirV   sD    
 !< 	47<<f--D--d333r   c                Z    t           j                            t          d                    S )z`
        :return: documents directory tied to the user e.g. ``%USERPROFILE%\Documents``
        CSIDL_PERSONAL)r   r   r   r   r.   s    r   user_documents_dirzWindows.user_documents_dira   s#    
 w/? @ @AAAr   c                    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   Temp)r   r   r   r#   r   r   r*   s     r   user_runtime_dirzWindows.user_runtime_dirh   sG     w^<Q-R-RTZ [ [\\!!$'''r   )r
   r   )r   r   r   r   r
   r   )__name__
__module____qualname____doc__propertyr   r   r+   r/   r2   r5   r7   r9   r<   r?   rB    r   r   r	   r	      s       	 	 ( ( ( X( GK       ( ( ( X(
 " " " X" " " " X" ? ? ? X? ? ? ? X?
 " " " X"    X B B B XB ( ( ( X( ( (r   r	   
csidl_namer   r
   c                l   | dk    rMt           j                            t           j                            t           j        d                   d          S dddd                    |           }|t          d	|            t           j                            |          }|t          d
|           |S )z&Get folder from environment variables.r>   USERPROFILE	DocumentsAPPDATAALLUSERSPROFILELOCALAPPDATA)r   r(   r   NUnknown CSIDL name: zUnset environment variable: )r   r   r#   r   environget
ValueError)rI   env_var_nameresults      r   get_win_folder_from_env_varsrV   r   s    %%%w||BG,,RZ-FGGUUU # 1-  
c*oo	 
 <
<<===Z^^L))F~FFFGGGMr   c                   ddddd                     |           }|t          d|            t          j        dk    rt          d	dl}|                    |j        d
          }|                    ||          \  }}t          |          S )zGet 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 AppDataPersonalr   r(   r   r>   NrP   win32r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)
rR   rS   sysplatformNotImplementedErrorwinregOpenKeyHKEY_CURRENT_USERQueryValueExr   )rI   shell_folder_namer_   key	directory_s         r   get_win_folder_from_registryrg      s     # 0.$	 
 
c*oo   <
<<===
|w!!MMM
..13v
w
wC&&s,=>>LIqy>>r   c                   ddddd                     |           }|t          d|            t          j        d          }t	          t          d	          }|j                            d|dd
|           t          d |D                       r7t          j        d          }|j        	                    |j
        |d          r|}|j
        S )zGet folder with ctypes.   #         rZ   NrP   i   windllr   c              3  <   K   | ]}t          |          d k    V  dS )   N)ord).0cs     r   	<genexpr>z,get_win_folder_via_ctypes.<locals>.<genexpr>   s,      
%
%A3q66C<
%
%
%
%
%
%r   )rR   rS   ctypescreate_unicode_buffergetattrshell32SHGetFolderPathWanykernel32GetShortPathNameWvalue)rI   csidl_constbufrm   buf2s        r   get_win_folder_via_ctypesr      s      "!	 
 
c*oo  <
<<===

&t
,
,CVX&&F
N##D+tQDDD 
%
%
%
%
%%% +D11?,,SYdCC 	C9r   Callable[[str], str]c                     t          t          d          rt          S 	 dd l} t          S # t
          $ r
 t          cY S w xY w)Nrm   r   )hasattrrt   r   r_   rg   ImportErrorrV   )r_   s    r   _pick_get_win_folderr      sY    vx   )((, ,+  , , ,++++,s   ) ==)maxsize)rI   r   r
   r   )r
   r   )
__future__r   rt   r   r\   	functoolsr   typingr   apir   r	   rV   rg   r   r   r   __all__rH   r   r   <module>r      s#   " " " " " "  				 



                        c( c( c( c( c(o c( c( c(L   $   0   0, , , , )4((()=)=)?)?@@ r   