U
    Ïvagi"  ã                   @  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
 ejdkr^d	d
œdd„ZnddlmZ G dd„ de
ƒZddddœdd„Zdddœdd„ZdgZdS )zUnix.é    )ÚannotationsN)ÚConfigParser)ÚPathé   )ÚPlatformDirsABCÚwin32Úint©Úreturnc                  C  s   d} t | ƒ‚d S )Nzshould only be used on Unix)ÚRuntimeError)Úmsg© r   úQ/var/www/html/myvenv/lib/python3.8/site-packages/pip/_vendor/platformdirs/unix.pyÚgetuid   s    r   )r   c                   @  sb  e Zd ZdZeddœdd„ƒZeddœdd„ƒZdddœd	d
„Zeddœdd„ƒZeddœdd„ƒZ	eddœdd„ƒZ
eddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd „ƒZeddœd!d"„ƒZed#dœd$d%„ƒZed#dœd&d'„ƒZed#dœd(d)„ƒZdd#d*œd+d,„Zd-S ).Ú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 show 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>`.
    Ústrr	   c                 C  s,   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``
        ZXDG_DATA_HOMEÚ z~/.local/share©ÚosÚenvironÚgetÚstripÚpathÚ
expanduserÚ_append_app_name_and_version©Úselfr   r   r   r   Úuser_data_dir"   s    zUnix.user_data_dirc                 C  s.   t j dd¡}| ¡ s$dt j› d�}|  |¡S )aY  
        :return: data directories shared by users (if `multipath <platformdirs.api.PlatformDirsABC.multipath>` is
         enabled and ``XDG_DATA_DIR`` 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``
        ZXDG_DATA_DIRSr   z/usr/local/sharez
/usr/share)r   r   r   r   ÚpathsepÚ_with_multi_pathr   r   r   r   Úsite_data_dir-   s    zUnix.site_data_dir)r   r
   c                   s<   |  tj¡}ˆ js|dd… }‡ fdd„|D ƒ}tj |¡S )Nr   r   c                   s   g | ]}ˆ   tj |¡¡‘qS r   )r   r   r   r   )Ú.0Úp©r   r   r   Ú
<listcomp>>   s     z)Unix._with_multi_path.<locals>.<listcomp>)Úsplitr   r   Ú	multipathÚjoin)r   r   Ú	path_listr   r#   r   r   :   s
    zUnix._with_multi_pathc                 C  s,   t j dd¡}| ¡ s"t j d¡}|  |¡S )z•
        :return: config directory tied to the user, e.g. ``~/.config/$appname/$version`` or
         ``$XDG_CONFIG_HOME/$appname/$version``
        ZXDG_CONFIG_HOMEr   z	~/.configr   r   r   r   r   Úuser_config_dirA   s    zUnix.user_config_dirc                 C  s$   t j dd¡}| ¡ sd}|  |¡S )a/  
        :return: config directories shared by users (if `multipath <platformdirs.api.PlatformDirsABC.multipath>`
         is enabled and ``XDG_DATA_DIR`` 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``
        ZXDG_CONFIG_DIRSr   z/etc/xdg)r   r   r   r   r   r   r   r   r   Úsite_config_dirL   s    zUnix.site_config_dirc                 C  s,   t j dd¡}| ¡ s"t j d¡}|  |¡S )z”
        :return: cache directory tied to the user, e.g. ``~/.cache/$appname/$version`` or
         ``~/$XDG_CACHE_HOME/$appname/$version``
        ZXDG_CACHE_HOMEr   z~/.cacher   r   r   r   r   Úuser_cache_dirY   s    zUnix.user_cache_dirc                 C  s
   |   d¡S )zM:return: cache directory shared by users, e.g. ``/var/tmp/$appname/$version``z/var/tmp)r   r#   r   r   r   Úsite_cache_dird   s    zUnix.site_cache_dirc                 C  s,   t j dd¡}| ¡ s"t j d¡}|  |¡S )z˜
        :return: state directory tied to the user, e.g. ``~/.local/state/$appname/$version`` or
         ``$XDG_STATE_HOME/$appname/$version``
        ZXDG_STATE_HOMEr   z~/.local/stater   r   r   r   r   Úuser_state_diri   s    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   r'   r   r   r   r   Úuser_log_dirt   s    zUnix.user_log_dirc                 C  s
   t ddƒS )zC:return: documents directory tied to the user, e.g. ``~/Documents``ZXDG_DOCUMENTS_DIRz~/Documents©Ú_get_user_media_dirr#   r   r   r   Úuser_documents_dir|   s    zUnix.user_documents_dirc                 C  s
   t ddƒS )zC:return: downloads directory tied to the user, e.g. ``~/Downloads``ZXDG_DOWNLOAD_DIRz~/Downloadsr1   r#   r   r   r   Úuser_downloads_dir�   s    zUnix.user_downloads_dirc                 C  s
   t ddƒS )zA:return: pictures directory tied to the user, e.g. ``~/Pictures``ZXDG_PICTURES_DIRz
~/Picturesr1   r#   r   r   r   Úuser_pictures_dir†   s    zUnix.user_pictures_dirc                 C  s
   t ddƒS )z=:return: videos directory tied to the user, e.g. ``~/Videos``ZXDG_VIDEOS_DIRz~/Videosr1   r#   r   r   r   Úuser_videos_dir‹   s    zUnix.user_videos_dirc                 C  s
   t ddƒS )z;:return: music directory tied to the user, e.g. ``~/Music``ZXDG_MUSIC_DIRz~/Musicr1   r#   r   r   r   Úuser_music_dir�   s    zUnix.user_music_dirc                 C  s^   t j dd¡}| ¡ sTtj d¡rHdtƒ › �}t|ƒ 	¡ sTd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.
        ZXDG_RUNTIME_DIRr   )ZfreebsdZopenbsdZ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_dirr   c                 C  s   |   | j¡S )zd:return: data path shared by users. Only return first item, even if ``multipath`` is set to ``True``)Ú _first_item_as_path_if_multipathr    r#   r   r   r   Úsite_data_path©   s    zUnix.site_data_pathc                 C  s   |   | j¡S )zj:return: config path shared by the users. Only return first item, even if ``multipath`` is set to ``True``)r=   r*   r#   r   r   r   Úsite_config_path®   s    zUnix.site_config_pathc                 C  s   |   | j¡S )ze:return: cache path shared by users. Only return first item, even if ``multipath`` is set to ``True``)r=   r,   r#   r   r   r   Úsite_cache_path³   s    zUnix.site_cache_path)Ú	directoryr
   c                 C  s   | j r| tj¡d }t|ƒS )Nr   )r&   r%   r   r   r   )r   rA   r   r   r   r=   ¸   s    z%Unix._first_item_as_path_if_multipathN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r    r   r)   r*   r+   r,   r-   r0   r3   r4   r5   r6   r7   r<   r>   r?   r@   r=   r   r   r   r   r      sJ   



r   r   )Úenv_varÚfallback_tilde_pathr
   c                 C  s6   t | ƒ}|d kr2tj | d¡ ¡ }|s2tj |¡}|S )Nr   )Ú_get_user_dirs_folderr   r   r   r   r   r   )rG   rH   Z	media_dirr   r   r   r2   ¿   s    r2   z
str | None)Úkeyr
   c              	   C  s€   t tƒ jƒd }| ¡ r|tƒ }| ¡ �}| d| ¡ › �¡ W 5 Q R X | |d krVdS |d |   d¡}| 	dt
j d¡¡S dS )zkReturn directory from user-dirs.dirs config file. See https://freedesktop.org/wiki/Software/xdg-user-dirs/.zuser-dirs.dirsz[top]
ÚtopNú"z$HOMEú~)r   r   r)   r;   r   ÚopenÚread_stringÚreadr   Úreplacer   r   r   )rJ   Zuser_dirs_config_pathÚparserÚstreamr   r   r   r   rI   É   s    
rI   )rE   Ú
__future__r   r   r8   Úconfigparserr   Úpathlibr   Úapir   r9   r   r   r2   rI   Ú__all__r   r   r   r   Ú<module>   s   
 +
ÿ