o
    6‘ðiÚ(  ã                   @  s´   d Z 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
mZ ddlmZ e
r2dd	lmZ ejd
kr=ddd„ZnddlmZ G dd„ deƒZddd„Zddd„ZdgZdS )zUnix.é    )ÚannotationsN)ÚConfigParser)ÚPath)ÚTYPE_CHECKINGÚNoReturné   )ÚPlatformDirsABC)ÚIteratorÚwin32Úreturnr   c                  C  s   d} t | ƒ‚)Nzshould only be used on Unix)ÚRuntimeError)Úmsg© r   ú\/root/parts/websockify/install/lib/python3.10/site-packages/pip/_vendor/platformdirs/unix.pyÚgetuid   s   r   )r   c                   @  sJ  e Zd ZdZed6dd„ƒZed7dd„ƒZed6d	d
„ƒZed6dd„ƒZed7dd„ƒZ	ed6dd„ƒZ
ed6dd„ƒZed6dd„ƒZed6dd„ƒZed6dd„ƒZed6dd„ƒZed6dd„ƒZed6dd„ƒZed6dd „ƒZed6d!d"„ƒZed6d#d$„ƒZed6d%d&„ƒZed6d'd(„ƒZed8d*d+„ƒZed8d,d-„ƒZed8d.d/„ƒZd9d1d2„Zd9d3d4„Zd5S ):ÚUnixa†  
    On Unix/Linux, we follow the `XDG Basedir Spec <https://specifications.freedesktop.org/basedir-spec/basedir-spec-
    latest.html>`_.

    The spec allows overriding directories with environment variables. The examples shown are the default values,
    alongside the name of the environment variable that overrides them. Makes use of the `appname
    <platformdirs.api.PlatformDirsABC.appname>`, `version <platformdirs.api.PlatformDirsABC.version>`, `multipath
    <platformdirs.api.PlatformDirsABC.multipath>`, `opinion <platformdirs.api.PlatformDirsABC.opinion>`, `ensure_exists
    <platformdirs.api.PlatformDirsABC.ensure_exists>`.

    r   Ústrc                 C  ó,   t j dd¡}| ¡ st j d¡}|  |¡S )z–
        :return: data directory tied to the user, e.g. ``~/.local/share/$appname/$version`` or
         ``$XDG_DATA_HOME/$appname/$version``
        ÚXDG_DATA_HOMEÚ z~/.local/share©ÚosÚenvironÚgetÚstripÚpathÚ
expanduserÚ_append_app_name_and_version©Úselfr   r   r   r   Úuser_data_dir'   ó   
zUnix.user_data_dirú	list[str]c                   s>   t j dd¡}| ¡ sdt j› d�}‡ fdd„| t j¡D ƒS )NÚXDG_DATA_DIRSr   z/usr/local/sharez
/usr/sharec                   ó   g | ]}ˆ   |¡‘qS r   ©r   ©Ú.0Úp©r   r   r   Ú
<listcomp>7   ó    z(Unix._site_data_dirs.<locals>.<listcomp>)r   r   r   r   ÚpathsepÚsplitr   r   r)   r   Ú_site_data_dirs2   s   zUnix._site_data_dirsc                 C  ó    | j }| js
|d S tj |¡S )aZ  
        :return: data directories shared by users (if `multipath <platformdirs.api.PlatformDirsABC.multipath>` is
         enabled and ``XDG_DATA_DIRS`` is set and a multi path the response is also a multi path separated by the
         OS path separator), e.g. ``/usr/local/share/$appname/$version`` or ``/usr/share/$appname/$version``
        r   )r.   Ú	multipathr   r,   Újoin©r   Údirsr   r   r   Úsite_data_dir9   ó   zUnix.site_data_dirc                 C  r   )z•
        :return: config directory tied to the user, e.g. ``~/.config/$appname/$version`` or
         ``$XDG_CONFIG_HOME/$appname/$version``
        ÚXDG_CONFIG_HOMEr   z	~/.configr   r   r   r   r   Úuser_config_dirF   r!   zUnix.user_config_dirc                   s4   t j dd¡}| ¡ sd}‡ fdd„| t j¡D ƒS )NÚXDG_CONFIG_DIRSr   z/etc/xdgc                   r$   r   r%   r&   r)   r   r   r*   V   r+   z*Unix._site_config_dirs.<locals>.<listcomp>)r   r   r   r   r-   r,   r   r   r)   r   Ú_site_config_dirsQ   s   zUnix._site_config_dirsc                 C  r/   )a2  
        :return: config directories shared by users (if `multipath <platformdirs.api.PlatformDirsABC.multipath>`
         is enabled and ``XDG_CONFIG_DIRS`` is set and a multi path the response is also a multi path separated by
         the OS path separator), e.g. ``/etc/xdg/$appname/$version``
        r   )r9   r0   r   r,   r1   r2   r   r   r   Úsite_config_dirX   r5   zUnix.site_config_dirc                 C  r   )z”
        :return: cache directory tied to the user, e.g. ``~/.cache/$appname/$version`` or
         ``~/$XDG_CACHE_HOME/$appname/$version``
        ÚXDG_CACHE_HOMEr   z~/.cacher   r   r   r   r   Úuser_cache_dire   r!   zUnix.user_cache_dirc                 C  s
   |   d¡S )zO:return: cache directory shared by users, e.g. ``/var/cache/$appname/$version``z
/var/cacher%   r)   r   r   r   Úsite_cache_dirp   ó   
zUnix.site_cache_dirc                 C  r   )z˜
        :return: state directory tied to the user, e.g. ``~/.local/state/$appname/$version`` or
         ``$XDG_STATE_HOME/$appname/$version``
        ÚXDG_STATE_HOMEr   z~/.local/stater   r   r   r   r   Úuser_state_diru   r!   zUnix.user_state_dirc                 C  s(   | j }| jrtj |d¡}|  |¡ |S )zg:return: log directory tied to the user, same as `user_state_dir` if not opinionated else ``log`` in itÚlog)r@   Úopinionr   r   r1   Ú_optionally_create_directoryr   r   r   r   Úuser_log_dir€   s
   
zUnix.user_log_dirc                 C  ó
   t ddƒS )zC:return: documents directory tied to the user, e.g. ``~/Documents``ÚXDG_DOCUMENTS_DIRz~/Documents©Ú_get_user_media_dirr)   r   r   r   Úuser_documents_dir‰   r>   zUnix.user_documents_dirc                 C  rE   )zC:return: downloads directory tied to the user, e.g. ``~/Downloads``ÚXDG_DOWNLOAD_DIRz~/DownloadsrG   r)   r   r   r   Úuser_downloads_dirŽ   r>   zUnix.user_downloads_dirc                 C  rE   )zA:return: pictures directory tied to the user, e.g. ``~/Pictures``ÚXDG_PICTURES_DIRz
~/PicturesrG   r)   r   r   r   Úuser_pictures_dir“   r>   zUnix.user_pictures_dirc                 C  rE   )z=:return: videos directory tied to the user, e.g. ``~/Videos``ÚXDG_VIDEOS_DIRz~/VideosrG   r)   r   r   r   Úuser_videos_dir˜   r>   zUnix.user_videos_dirc                 C  rE   )z;:return: music directory tied to the user, e.g. ``~/Music``ÚXDG_MUSIC_DIRz~/MusicrG   r)   r   r   r   Úuser_music_dir�   r>   zUnix.user_music_dirc                 C  rE   )z?:return: desktop directory tied to the user, e.g. ``~/Desktop``ÚXDG_DESKTOP_DIRz	~/DesktoprG   r)   r   r   r   Úuser_desktop_dir¢   r>   zUnix.user_desktop_dirc                 C  s^   t j dd¡}| ¡ s*tj d¡r$dtƒ › �}t|ƒ 	¡ s#dtƒ › �}ndtƒ › �}|  
|¡S )az  
        :return: runtime directory tied to the user, e.g. ``/run/user/$(id -u)/$appname/$version`` or
         ``$XDG_RUNTIME_DIR/$appname/$version``.

         For FreeBSD/OpenBSD/NetBSD, it would return ``/var/run/user/$(id -u)/$appname/$version`` if
         exists, otherwise ``/tmp/runtime-$(id -u)/$appname/$version``, if``$XDG_RUNTIME_DIR``
         is not set.
        ÚXDG_RUNTIME_DIRr   ©ÚfreebsdÚopenbsdÚnetbsdz/var/run/user/z/tmp/runtime-z
/run/user/)r   r   r   r   ÚsysÚplatformÚ
startswithr   r   Úexistsr   r   r   r   r   Úuser_runtime_dir§   s   
€
zUnix.user_runtime_dirc                 C  s6   t j dd¡}| ¡ stj d¡rd}nd}|  |¡S )am  
        :return: runtime directory shared by users, e.g. ``/run/$appname/$version`` or         ``$XDG_RUNTIME_DIR/$appname/$version``.

        Note that this behaves almost exactly like `user_runtime_dir` if ``$XDG_RUNTIME_DIR`` is set, but will
        fall back to paths associated to the root user instead of a regular logged-in user if it's not set.

        If you wish to ensure that a logged-in root user path is returned e.g. ``/run/user/0``, use `user_runtime_dir`
        instead.

        For FreeBSD/OpenBSD/NetBSD, it would return ``/var/run/$appname/$version`` if ``$XDG_RUNTIME_DIR`` is not set.
        rT   r   rU   z/var/runz/run)r   r   r   r   rY   rZ   r[   r   r   r   r   r   Úsite_runtime_dir»   s   
zUnix.site_runtime_dirr   c                 C  ó   |   | j¡S )zh:return: data path shared by users. Only return the first item, even if ``multipath`` is set to ``True``)Ú _first_item_as_path_if_multipathr4   r)   r   r   r   Úsite_data_pathÑ   ó   zUnix.site_data_pathc                 C  r_   )zj:return: config path shared by the users, returns the first item, even if ``multipath`` is set to ``True``)r`   r:   r)   r   r   r   Úsite_config_pathÖ   rb   zUnix.site_config_pathc                 C  r_   )zi:return: cache path shared by users. Only return the first item, even if ``multipath`` is set to ``True``)r`   r=   r)   r   r   r   Úsite_cache_pathÛ   rb   zUnix.site_cache_pathúIterator[str]c                 c  ó   � | j V  | jE dH  dS )z4:yield: all user and site configuration directories.N)r7   r9   r)   r   r   r   Úiter_config_dirsà   ó   €zUnix.iter_config_dirsc                 c  rf   )z+:yield: all user and site data directories.N)r    r.   r)   r   r   r   Úiter_data_dirså   rh   zUnix.iter_data_dirsN)r   r   )r   r"   )r   r   )r   re   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr    r.   r4   r7   r9   r:   r<   r=   r@   rD   rI   rK   rM   rO   rQ   rS   r]   r^   ra   rc   rd   rg   ri   r   r   r   r   r      s\    




r   Úenv_varr   Úfallback_tilde_pathc                 C  s6   t | ƒ}|d u rtj | d¡ ¡ }|stj |¡}|S )Nr   )Ú_get_user_dirs_folderr   r   r   r   r   r   )ro   rp   Ú	media_dirr   r   r   rH   ë   s   rH   Úkeyú
str | Nonec                 C  s”   t tƒ jƒd }| ¡ rHtƒ }| ¡ �}| d| ¡ › �¡ W d  ƒ n1 s(w   Y  | |d vr5dS |d |   d¡}| 	dt
j d¡¡S dS )z{
    Return directory from user-dirs.dirs config file.

    See https://freedesktop.org/wiki/Software/xdg-user-dirs/.

    zuser-dirs.dirsz[top]
NÚtopú"z$HOMEú~)r   r   r7   r\   r   ÚopenÚread_stringÚreadr   Úreplacer   r   r   )rs   Úuser_dirs_config_pathÚparserÚstreamr   r   r   r   rq   õ   s   
þrq   )r   r   )ro   r   rp   r   r   r   )rs   r   r   rt   )rm   Ú
__future__r   r   rY   Úconfigparserr   Úpathlibr   Útypingr   r   Úapir   Úcollections.abcr	   rZ   r   r   rH   rq   Ú__all__r   r   r   r   Ú<module>   s&    
 
R

ÿ