o
    iN/                     @  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
 ddlmZ ddlmZmZ d	d
lmZ d	dlmZ erDddlmZ ejdkrOd ddZnddlmZ G dd deZG dd deeZd!ddZd"ddZdgZdS )#zUnix.    )annotationsN)ConfigParser)cached_property)Path)
gettempdir)TYPE_CHECKINGNoReturn   )XDGMixin)PlatformDirsABC)Iteratorwin32returnr   c                  C  s   d} t | )Nzshould only be used on Unix)RuntimeError)msg r   O/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/platformdirs/unix.pygetuid   s   r   )r   c                   @  s  e Zd ZdZedCddZedDddZedEd
dZedDddZ	edEddZ
edDddZedDddZedDddZedDddZedDddZedDddZedDddZedDddZedDd d!ZedDd"d#ZedDd$d%ZedDd&d'ZedDd(d)ZedDd*d+ZedDd,d-ZedEd.d/ZedDd0d1ZedDd2d3ZedDd4d5ZedFd7d8ZedFd9d:ZedFd;d<Z dGd>d?Z!dGd@dAZ"dBS )H_UnixDefaultszDefault directories for Unix/Linux without XDG environment variable overrides.

    The XDG env var handling is in :class:`~platformdirs._xdg.XDGMixin`.

    r   boolc                 C  s   | j ot dkS )Nr   )use_site_for_rootr   selfr   r   r   	_use_site$   s   z_UnixDefaults._use_sitestrc                 C     |  tjdS )z|:returns: data directory tied to the user, e.g. ``~/.local/share/$appname/$version`` or ``$XDG_DATA_HOME/$appname/$version``~/.local/share_append_app_name_and_versionospath
expanduserr   r   r   r   user_data_dir(      z_UnixDefaults.user_data_dir	list[str]c                 C  s   |  d|  dgS )N/usr/local/share
/usr/sharer   r   r   r   r   _site_data_dirs-   s   z_UnixDefaults._site_data_dirsc                 C  r   )z{:returns: config directory tied to the user, e.g. ``~/.config/$appname/$version`` or ``$XDG_CONFIG_HOME/$appname/$version``	~/.configr   r   r   r   r   user_config_dir1   r#   z_UnixDefaults.user_config_dirc                 C  s   |  dgS )Nz/etc/xdgr'   r   r   r   r   _site_config_dirs6   s   z_UnixDefaults._site_config_dirsc                 C  r   )zx:returns: cache directory tied to the user, e.g. ``~/.cache/$appname/$version`` or ``$XDG_CACHE_HOME/$appname/$version``z~/.cacher   r   r   r   r   user_cache_dir:   r#   z_UnixDefaults.user_cache_dirc                 C  
   |  dS )zP:returns: cache directory shared by users, e.g. ``/var/cache/$appname/$version``z
/var/cacher'   r   r   r   r   site_cache_dir?      
z_UnixDefaults.site_cache_dirc                 C  r   )z~:returns: state directory tied to the user, e.g. ``~/.local/state/$appname/$version`` or ``$XDG_STATE_HOME/$appname/$version``z~/.local/stater   r   r   r   r   user_state_dirD   r#   z_UnixDefaults.user_state_dirc                 C  r-   )zN:returns: state directory shared by users, e.g. ``/var/lib/$appname/$version``z/var/libr'   r   r   r   r   site_state_dirI   r/   z_UnixDefaults.site_state_dirc                 C  s(   | j }| jrtj|d}| | |S )zh:returns: log directory tied to the user, same as `user_state_dir` if not opinionated else ``log`` in itlog)r0   opinionr   r    join_optionally_create_directoryr   r    r   r   r   user_log_dirN   s
   
z_UnixDefaults.user_log_dirc                 C  r-   )z:returns: log directory shared by users, e.g. ``/var/log/$appname/$version``

        Unlike `user_log_dir`, ``opinion`` has no effect since ``/var/log`` is inherently a log directory.

        z/var/logr'   r   r   r   r   site_log_dirW   s   
z_UnixDefaults.site_log_dirc                 C  
   t ddS )zD:returns: 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 _UnixDefaults.user_documents_dirc                 C  r9   )zD:returns: downloads directory tied to the user, e.g. ``~/Downloads``XDG_DOWNLOAD_DIRz~/Downloadsr;   r   r   r   r   user_downloads_dire   r/   z _UnixDefaults.user_downloads_dirc                 C  r9   )zB:returns: pictures directory tied to the user, e.g. ``~/Pictures``XDG_PICTURES_DIRz
~/Picturesr;   r   r   r   r   user_pictures_dirj   r/   z_UnixDefaults.user_pictures_dirc                 C  r9   )z>:returns: videos directory tied to the user, e.g. ``~/Videos``XDG_VIDEOS_DIRz~/Videosr;   r   r   r   r   user_videos_diro   r/   z_UnixDefaults.user_videos_dirc                 C  r9   )z<:returns: music directory tied to the user, e.g. ``~/Music``XDG_MUSIC_DIRz~/Musicr;   r   r   r   r   user_music_dirt   r/   z_UnixDefaults.user_music_dirc                 C  r9   )z@:returns: desktop directory tied to the user, e.g. ``~/Desktop``XDG_DESKTOP_DIRz	~/Desktopr;   r   r   r   r   user_desktop_diry   r/   z_UnixDefaults.user_desktop_dirc                 C  s   t jdS )z?:returns: bin directory tied to the user, e.g. ``~/.local/bin``z~/.local/bin)r   r    r!   r   r   r   r   user_bin_dir~      z_UnixDefaults.user_bin_dirc                 C  s   dS )z@:returns: bin directory shared by users, e.g. ``/usr/local/bin``z/usr/local/binr   r   r   r   r   site_bin_dir   s   z_UnixDefaults.site_bin_dirc                 C  s   t jt jddS )zW:returns: applications directory tied to the user, e.g. ``~/.local/share/applications``r   applications)r   r    r4   r!   r   r   r   r   user_applications_dir   s   z#_UnixDefaults.user_applications_dirc                 C  s   dd dD S )Nc                 S  s   g | ]	}t j|d qS )rK   )r   r    r4   ).0pr   r   r   
<listcomp>   s    z9_UnixDefaults._site_applications_dirs.<locals>.<listcomp>)r%   r&   r   r   r   r   r   _site_applications_dirs   s   z%_UnixDefaults._site_applications_dirsc                 C  s    | j }| jrtj|S |d S )zR:returns: applications directory shared by users, e.g. ``/usr/share/applications``r   )rP   	multipathr   pathsepr4   )r   dirsr   r   r   site_applications_dir   s   z#_UnixDefaults.site_applications_dirc                 C  sj   t jdrdt  }nt jdrdt  }ndt  }t|tjs0t  dt  }| |S )ah  :returns: runtime directory tied to the user, e.g. ``$XDG_RUNTIME_DIR/$appname/$version``.

        If ``$XDG_RUNTIME_DIR`` is unset, tries the platform default (``/tmp/run/user/$(id -u)`` on OpenBSD, ``/var/run/user/$(id -u)`` on FreeBSD/NetBSD, ``/run/user/$(id -u)`` otherwise). If the default is not writable, falls back to a temporary directory.

        openbsdz/tmp/run/user/)freebsdnetbsdz/var/run/user/z
/run/user/z	/runtime-)	sysplatform
startswithr   r   accessW_OKr   r   r6   r   r   r   user_runtime_dir   s   
z_UnixDefaults.user_runtime_dirc                 C  s    t jdr	d}nd}| |S )aN  :returns: 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.

        )rV   rU   rW   z/var/runz/run)rX   rY   rZ   r   r6   r   r   r   site_runtime_dir   s   
z_UnixDefaults.site_runtime_dirr   c                 C     |  | jS )zi:returns: data path shared by users. Only return the first item, even if ``multipath`` is set to ``True``) _first_item_as_path_if_multipathsite_data_dirr   r   r   r   site_data_path   rI   z_UnixDefaults.site_data_pathc                 C  r_   )zg:returns: config path shared by users, returns the first item, even if ``multipath`` is set to ``True``)r`   site_config_dirr   r   r   r   site_config_path   rI   z_UnixDefaults.site_config_pathc                 C  r_   )zj:returns: 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   rI   z_UnixDefaults.site_cache_pathIterator[str]c                 c      | j V  | jE dH  dS )z4:yield: all user and site configuration directories.N)r*   r+   r   r   r   r   iter_config_dirs      z_UnixDefaults.iter_config_dirsc                 c  rg   )z+:yield: all user and site data directories.N)r"   r(   r   r   r   r   iter_data_dirs   ri   z_UnixDefaults.iter_data_dirsN)r   r   r   r   )r   r$   )r   r   )r   rf   )#__name__
__module____qualname____doc__r   r   propertyr"   r(   r*   r+   r,   r.   r0   r1   r7   r8   r=   r?   rA   rC   rE   rG   rH   rJ   rL   rP   rT   r]   r^   rb   rd   re   rh   rj   r   r   r   r   r      st    
r   c                      s   e Zd ZdZed fddZed fddZed fdd	Zed fd
dZed fddZ	ed fddZ
ed fddZed fddZ  ZS )Unixaf  On Unix/Linux, we follow the `XDG Basedir Spec <https://specifications.freedesktop.org/basedir/latest/>`_.

    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   r   c                      | j r| jS t jS )zb:returns: data directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   ra   superr"   r   	__class__r   r   r"         zUnix.user_data_dirc                   rr   )zd:returns: config directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   rc   rs   r*   r   rt   r   r   r*      rv   zUnix.user_config_dirc                   rr   )zc:returns: cache directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   r.   rs   r,   r   rt   r   r   r,      rv   zUnix.user_cache_dirc                   rr   )zc:returns: state directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   r1   rs   r0   r   rt   r   r   r0      rv   zUnix.user_state_dirc                   rr   )za:returns: log directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   r8   rs   r7   r   rt   r   r   r7      rv   zUnix.user_log_dirc                   rr   )zj:returns: applications directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   rT   rs   rL   r   rt   r   r   rL      rv   zUnix.user_applications_dirc                   rr   )ze:returns: runtime directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   r^   rs   r]   r   rt   r   r   r]      rv   zUnix.user_runtime_dirc                   rr   )za:returns: bin directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   rJ   rs   rH   r   rt   r   r   rH     rv   zUnix.user_bin_dirrk   )rl   rm   rn   ro   rp   r"   r*   r,   r0   r7   rL   r]   rH   __classcell__r   r   rt   r   rq      s$    
rq   env_varr   fallback_tilde_pathc                 C  s   t |  }r|S tj|S )N)_get_user_dirs_folderr   r    r!   )rx   ry   	media_dirr   r   r   r<     s   r<   key
str | Nonec                 C  s   t tjdd }| rJt }| }|d|   W d   n1 s*w   Y  | |d vr7dS |d |  	d}|
dtjdS dS )	zvReturn directory from user-dirs.dirs config file.

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

    r)   zuser-dirs.dirsz[top]
Ntop"z$HOME~)r   r   r    r!   existsr   openread_stringreadstripreplace)r|   user_dirs_config_pathparserstreamr    r   r   r   rz     s   
rz   )r   r   )rx   r   ry   r   r   r   )r|   r   r   r}   )ro   
__future__r   r   rX   configparserr   	functoolsr   pathlibr   tempfiler   typingr   r   _xdgr
   apir   collections.abcr   rY   r   r   rq   r<   rz   __all__r   r   r   r   <module>   s.    
 7
4
