
    e7              	       j   d Z dZd                     eee                    ZddlZddlZej        d         dk    Z	e	reZ
 G d de          Zdd	Zd d
Zd!dZd!dZ G d de          Z G d de          Zd Zd Zd Zej        dk    r(	 ddlZeZn # e$ r 	 ddlZeZn# e$ r eZY nw xY wY nw xY wedk    rtdZdZdZ  e!d            eeed          Z"e D ]Z# e!e#d e$e"e#                      e!d            eee          Z"e D ]Z# e!e#d e$e"e#                     dS dS )"zyUtilities for determining application-specific dirs.

See <http://github.com/ActiveState/appdirs> for details and usage.
)          .r   N   c                       e Zd ZdS )AppDirsErrorN)__name__
__module____qualname__     6lib/python3.11/site-packages/repo_cli/utils/appdirs.pyr   r      s        Dr   r   Fc                 t   t           j                            d          rF|t          d          |rdpd}t          j                            t          |          ||           }nt           j        dk    r>t          j                            t          j                            d          |           }nbt          j                            t	          j	        dt          j                            d	                    | 
                                          }|r t          j                            ||          }|S )
a}  Return full path to the user-specific data dir for this application.

        "appname" is the name of application.
        "appauthor" (only required and used on Windows) is the name of the
            appauthor or distributing body for this application. Typically
            it is the owning company name.
        "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 "<major>.<minor>".
        "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
            <http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
            for a discussion of issues.

    Typical user data directories are:
        Mac OS X:               ~/Library/Application Support/<AppName>
        Unix:                   ~/.config/<appname>    # or in $XDG_CONFIG_HOME if defined
        Win XP (not roaming):   C:\Documents and Settings\<username>\Application Data\<AppAuthor>\<AppName>
        Win XP (roaming):       C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>
        Win 7  (not roaming):   C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>
        Win 7  (roaming):       C:\Users\<username>\AppData\Roaming\<AppAuthor>\<AppName>

    For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME. We don't
    use $XDG_DATA_HOME as that data dir is mostly used at the time of
    installation, instead of the application adding data during runtime.
    Also, in practice, Linux apps tend to store their data in
    "~/.config/<appname>" instead of "~/.local/share/<appname>".
    winN#must specify 'appauthor' on WindowsCSIDL_APPDATACSIDL_LOCAL_APPDATAdarwinz~/Library/Application Support/XDG_CONFIG_HOMEz	~/.configsysplatform
startswithr   ospathjoin_get_win_folder
expandusergetenvlower)appname	appauthorversionroamingconstr   s         r   user_data_dirr&      s   @ |u%% 
DEEE+OD/Dw||OE22IwGG		!	!w||G?@@'
 
 w||I'););K)H)HIIMMOO
 
  +w||D'**Kr   c                    t           j                            d          r@|t          d          t          j                            t          d          ||           }net           j        dk    r>t          j                            t          j                            d          |           }nd| 	                                z   }|r t          j                            ||          }|S )am  Return full path to the user-shared data dir for this application.

        "appname" is the name of application.
        "appauthor" (only required and used on Windows) is the name of the
            appauthor or distributing body for this application. Typically
            it is the owning company name.
        "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 "<major>.<minor>".

    Typical user data directories are:
        Mac OS X:   /Library/Application Support/<AppName>
        Unix:       /etc/xdg/<appname>
        Win XP:     C:\Documents and Settings\All Users\Application Data\<AppAuthor>\<AppName>
        Vista:      (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.)
        Win 7:      C:\ProgramData\<AppAuthor>\<AppName>   # Hidden, but writeable on Win 7.

    For Unix, this is using the $XDG_CONFIG_DIRS[0] default.

    WARNING: Do not use this on Windows. See the Vista-Fail note above for why.
    r   Nr   CSIDL_COMMON_APPDATAr   z/Library/Application Supportz	/etc/xdg/)
r   r   r   r   r   r   r   r   r   r    )r!   r"   r#   r   s       r   site_data_dirr)   R   s    . |u%% 	-DEEEw||O,BCCYPWXX		!	!w||BG../MNNPWXX W]]__, +w||D'**Kr   Tc                    t           j                            d          rb|t          d          t          j                            t          d          ||           }|r t          j                            |d          }nt           j        dk    r>t          j                            t          j                            d          |           }nbt          j                            t	          j	        dt          j                            d	                    | 
                                          }|r t          j                            ||          }|S )
aY  Return full path to the user-specific cache dir for this application.

        "appname" is the name of application.
        "appauthor" (only required and used on Windows) is the name of the
            appauthor or distributing body for this application. Typically
            it is the owning company name.
        "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 "<major>.<minor>".
        "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/<AppName>
        Unix:       ~/.cache/<appname> (XDG default)
        Win XP:     C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Cache
        Vista:      C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\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\<ProfileName>\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.
    r   Nr   r   Cacher   z~/Library/CachesXDG_CACHE_HOMEz~/.cacher   r!   r"   r#   opinionr   s        r   user_cache_dirr/   x   s   < |u%% 
DEEEw||O,ABBIwWW 	/7<<g..D		!	!w||BG../ABBGLLw||I&(:(::(F(FGG
 
  +w||D'**Kr   c                    t           j        dk    r>t          j                            t          j                            d          |           }n{t           j        dk    r6t          | ||          }d}|r t          j                            |d          }n5t          | ||          }d}|r t          j                            |d          }|r t          j                            ||          }|S )a  Return full path to the user-specific log dir for this application.

        "appname" is the name of application.
        "appauthor" (only required and used on Windows) is the name of the
            appauthor or distributing body for this application. Typically
            it is the owning company name.
        "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 "<major>.<minor>".
        "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 cache directories are:
        Mac OS X:   ~/Library/Logs/<AppName>
        Unix:       ~/.cache/<appname>/log  # or under $XDG_CACHE_HOME if defined
        Win XP:     C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Logs
        Vista:      C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\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/Logswin32FLogslog)r   r   r   r   r   r   r&   r/   r-   s        r   user_log_dirr4      s    : |xw||BG../?@@'JJ		 	 Wi99 	.7<<f--Dgy':: 	-7<<e,,D +w||D'**Kr   c                   l    e Zd Zd Zed             Zed             Zed             Zed             ZdS )
EnvAppDirsc                 0    || _         || _        || _        d S N)r!   r"   	root_path)selfr!   r"   r9   s       r   __init__zEnvAppDirs.__init__   s    ""r   c                 L    t           j                            | j        d          S Ndatar   r   r   r9   r:   s    r   r&   zEnvAppDirs.user_data_dir       w||DNF333r   c                 L    t           j                            | j        d          S r=   r?   r@   s    r   r)   zEnvAppDirs.site_data_dir   rA   r   c                 L    t           j                            | j        d          S )Ncacher?   r@   s    r   r/   zEnvAppDirs.user_cache_dir   s    w||DNG444r   c                 L    t           j                            | j        d          S )Nr3   r?   r@   s    r   r4   zEnvAppDirs.user_log_dir   s    w||DNE222r   N)	r	   r
   r   r;   propertyr&   r)   r/   r4   r   r   r   r6   r6      s        # # #
 4 4 X4 4 4 X4 5 5 X5 3 3 X3 3 3r   r6   c                   r    e Zd ZdZd	dZed             Zed             Zed             Zed             Z	dS )
AppDirsz1Convenience wrapper for getting application dirs.NFc                 >    || _         || _        || _        || _        d S r8   )r!   r"   r#   r$   )r:   r!   r"   r#   r$   s        r   r;   zAppDirs.__init__   s"    "r   c                 P    t          | j        | j        | j        | j                  S )N)r#   r$   )r&   r!   r"   r#   r$   r@   s    r   r&   zAppDirs.user_data_dir   s*    L$.$,
 
 
 	
r   c                 D    t          | j        | j        | j                  S Nr#   )r)   r!   r"   r#   r@   s    r   r)   zAppDirs.site_data_dir   s    T\4>4<PPPPr   c                 D    t          | j        | j        | j                  S rL   )r/   r!   r"   r#   r@   s    r   r/   zAppDirs.user_cache_dir   s    dlDNDLQQQQr   c                 D    t          | j        | j        | j                  S rL   )r4   r!   r"   r#   r@   s    r   r4   zAppDirs.user_log_dir  s    DL$.$,OOOOr   )NF)
r	   r
   r   __doc__r;   rF   r&   r)   r/   r4   r   r   r   rH   rH      s        ;;    
 
 X

 Q Q XQ R R XR P P XP P Pr   rH   c                     ddl }dddd|          }|                    |j        d          }|                    ||          \  }}|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.
    r   NAppDatazCommon AppDatazLocal AppDatar   r(   r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)_winregOpenKeyHKEY_CURRENT_USERQueryValueEx)
csidl_namerT   shell_folder_namekeydirtypes         r   _get_win_folder_from_registryr]     sn    
 NNN # 0.  	 //!K C $$S*;<<ICJr   c                 :   ddl m}m} |                    dt	          ||           dd          }	 t          |          }d}|D ]}t          |          dk    rd} n|r+	 dd l}|                    |          }n# t          $ r Y nw xY wn# t          $ r Y nw xY w|S )Nr   )shellshellconF   T)win32com.shellr_   r`   SHGetFolderPathgetattrunicodeordwin32apiGetShortPathNameImportErrorUnicodeError)rX   r_   r`   r[   has_high_charcrg   s          r   _get_win_folder_with_pywin32rm      s    ........


78Z#@#@!Q
G
GCcll  	 	A1vv|| $   	//44      Js5   /B  A: 9B :
BB BB 
BBc                 F   dd l }dddd|          } |j        d          }|j        j                            d |d d|           d}|D ]}t          |          dk    rd	} n|r8 |j        d          }|j        j                            |j        |d          r|}|j        S )
Nr      #      rS   i   Fra   T)	ctypescreate_unicode_bufferwindllshell32SHGetFolderPathWrf   kernel32GetShortPathNameWvalue)rX   rr   csidl_constbufrk   rl   buf2s          r   _get_win_folder_with_ctypesr}   =  s    MMM  "!  	K '&
&t
,
,C
M**4dAsKKK M  q66C<< ME   +v+D11=!33CItTJJ 	C9r   r1   __main__MyApp	MyCompany)r&   r)   r/   r4   z(-- app dirs (without optional 'version')z1.0rM   z: z&
-- app dirs (with optional 'version'))NNF)NN)NNT)%rP   __version_info__r   mapstr__version__r   r   version_infoPY3re   	Exceptionr   r&   r)   r/   r4   objectr6   rH   r]   rm   r}   r   rb   win32comr   ri   rr   r	   r!   r"   propsprintdirsproprd   r   r   r   <module>r      s     hhss3 01122 
			 



	qQ G	 	 	 	 	9 	 	 	0 0 0 0f# # # #L, , , ,^+ + + +\3 3 3 3 3 3 3 3.P P P P Pf P P P>  *  :  6 <7
<6 < < <	<MMM9OO 	< 	< 	<;OOO	<< zGIPE	E
455577Iu555D 6 6$$$d 3 3 345555	E
344477I&&D 6 6$$$d 3 3 345555 6 6s6   B B4B$#B4$B.+B4-B..B43B4