o
    LK&h)                     @  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jd	kr5d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)IteratorNoReturn   )PlatformDirsABCwin32returnr   c                  C  s   d} t | )Nzshould only be used on Unix)RuntimeError)msg r   W/var/www/html/venv/lib/python3.10/site-packages/setuptools/_vendor/platformdirs/unix.pygetuid   s   r   )r   c                   @  sT  e Zd ZdZed9ddZed:ddZed9d	d
Zed9ddZed:ddZ	ed9ddZ
ed9ddZed9ddZed9ddZed9ddZed9ddZed9ddZed9ddZed9dd Zed9d!d"Zed9d#d$Zed9d%d&Zed9d'd(Zed;d*d+Zed;d,d-Zed;d.d/Zd<d1d2Zd=d4d5Zd=d6d7Zd8S )>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>4       z(Unix._site_data_dirs.<locals>.<listcomp>)r   r   r   r   pathsepsplitr   r   r(   r   _site_data_dirs/   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_dir6      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_dirC   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)   S   r*   z*Unix._site_config_dirs.<locals>.<listcomp>)r   r   r   r   r,   r+   r   r   r(   r   _site_config_dirsN   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   )r8   r/   r   r+   r0   r1   r   r   r   site_config_dirU   r4   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_dirb   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_dirm      
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_dirr   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   r0   _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  rD   )zC:return: downloads directory tied to the user, e.g. ``~/Downloads``XDG_DOWNLOAD_DIRz~/DownloadsrF   r(   r   r   r   user_downloads_dir   r=   zUnix.user_downloads_dirc                 C  rD   )zA:return: pictures directory tied to the user, e.g. ``~/Pictures``XDG_PICTURES_DIRz
~/PicturesrF   r(   r   r   r   user_pictures_dir   r=   zUnix.user_pictures_dirc                 C  rD   )z=:return: videos directory tied to the user, e.g. ``~/Videos``XDG_VIDEOS_DIRz~/VideosrF   r(   r   r   r   user_videos_dir   r=   zUnix.user_videos_dirc                 C  rD   )z;:return: music directory tied to the user, e.g. ``~/Music``XDG_MUSIC_DIRz~/MusicrF   r(   r   r   r   user_music_dir   r=   zUnix.user_music_dirc                 C  rD   )z?:return: desktop directory tied to the user, e.g. ``~/Desktop``XDG_DESKTOP_DIRz	~/DesktoprF   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.
        rS   r   rT   z/var/runz/run)r   r   r   r   rX   rY   rZ   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_multipathr3   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_   r9   r(   r   r   r   site_config_path   ra   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   ra   zUnix.site_cache_path	directoryc                 C  s   | j r|tjd }t|S )Nr   )r/   r,   r   r+   r   )r   rd   r   r   r   r_      s   z%Unix._first_item_as_path_if_multipathIterator[str]c                 c      | j V  | jE dH  dS )z4:yield: all user and site configuration directories.N)r6   r8   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   )rd   r   r
   r   )r
   re   )__name__
__module____qualname____doc__propertyr   r-   r3   r6   r8   r9   r;   r<   r?   rC   rH   rJ   rL   rN   rP   rR   r\   r]   r`   rb   rc   r_   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   rG      s   rG   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   r6   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   rX   configparserr   pathlibr   typingr   r   apir   rY   r   r   rG   rq   __all__r   r   r   r   <module>   s"    
 
X

