
    3i/                       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rddlmZ ej,                  dk(  rddZnddlmZ  G d de      Z G d dee      ZddZddZdgZy)zUnix.    )annotationsN)ConfigParser)cached_property)Path)
gettempdir)TYPE_CHECKINGNoReturn   )XDGMixin)PlatformDirsABC)Iteratorwin32c                     d} t        |       )Nzshould only be used on Unix)RuntimeError)msgs    D/var/www/opsc/venv/lib/python3.12/site-packages/platformdirs/unix.pygetuidr      s    +3    )r   c                     e Zd ZdZed d       Zed!d       Zed"d       Zed!d       Z	ed"d       Z
ed!d       Zed!d       Zed!d	       Zed!d
       Zed!d       Zed!d       Zed!d       Zed!d       Zed!d       Zed!d       Zed!d       Zed!d       Zed!d       Zed!d       Zed!d       Zed"d       Zed!d       Zed!d       Zed!d       Zed#d       Zed#d       Zed#d       Z d$dZ!d$dZ"y)%_UnixDefaultszDefault directories for Unix/Linux without XDG environment variable overrides.

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

    c                8    | j                   xr t               dk(  S )Nr   )use_site_for_rootr   selfs    r   	_use_sitez_UnixDefaults._use_site$   s    %%7&(a-7r   c                ^    | j                  t        j                  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   s    r   user_data_dirz_UnixDefaults.user_data_dir(   %     001C1CDT1UVVr   c                F    | j                  d      | j                  d      gS )N/usr/local/share
/usr/sharer   r   s    r   _site_data_dirsz_UnixDefaults._site_data_dirs-   s%    112DEtGhGhiuGvwwr   c                ^    | j                  t        j                  j                  d            S )z{:returns: config directory tied to the user, e.g. ``~/.config/$appname/$version`` or ``$XDG_CONFIG_HOME/$appname/$version``	~/.configr   r   s    r   user_config_dirz_UnixDefaults.user_config_dir1   s$     001C1CK1PQQr   c                &    | j                  d      gS )Nz/etc/xdgr(   r   s    r   _site_config_dirsz_UnixDefaults._site_config_dirs6   s    11*=>>r   c                ^    | j                  t        j                  j                  d            S )zx:returns: cache directory tied to the user, e.g. ``~/.cache/$appname/$version`` or ``$XDG_CACHE_HOME/$appname/$version``z~/.cacher   r   s    r   user_cache_dirz_UnixDefaults.user_cache_dir:   s$     001C1CJ1OPPr   c                $    | j                  d      S )zP:returns: cache directory shared by users, e.g. ``/var/cache/$appname/$version``z
/var/cacher(   r   s    r   site_cache_dirz_UnixDefaults.site_cache_dir?   s     00>>r   c                ^    | j                  t        j                  j                  d            S )z~:returns: state directory tied to the user, e.g. ``~/.local/state/$appname/$version`` or ``$XDG_STATE_HOME/$appname/$version``z~/.local/stater   r   s    r   user_state_dirz_UnixDefaults.user_state_dirD   r$   r   c                $    | j                  d      S )zN:returns: state directory shared by users, e.g. ``/var/lib/$appname/$version``z/var/libr(   r   s    r   site_state_dirz_UnixDefaults.site_state_dirI   s     00<<r   c                    | j                   }| j                  r1t        j                  j	                  |d      }| j                  |       |S )zh:returns: log directory tied to the user, same as `user_state_dir` if not opinionated else ``log`` in itlog)r4   opinionr    r!   join_optionally_create_directoryr   r!   s     r   user_log_dirz_UnixDefaults.user_log_dirN   s=     ""<<77<<e,D--d3r   c                $    | j                  d      S )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   s    r   site_log_dirz_UnixDefaults.site_log_dirW   s     00<<r   c                    t        dd      S )zD:returns: documents directory tied to the user, e.g. ``~/Documents``XDG_DOCUMENTS_DIRz~/Documents_get_user_media_dirr   s    r   user_documents_dirz _UnixDefaults.user_documents_dir`   s     ##6FFr   c                    t        dd      S )zD:returns: downloads directory tied to the user, e.g. ``~/Downloads``XDG_DOWNLOAD_DIRz~/DownloadsrB   r   s    r   user_downloads_dirz _UnixDefaults.user_downloads_dire   s     ##5}EEr   c                    t        dd      S )zB:returns: pictures directory tied to the user, e.g. ``~/Pictures``XDG_PICTURES_DIRz
~/PicturesrB   r   s    r   user_pictures_dirz_UnixDefaults.user_pictures_dirj   s     ##5|DDr   c                    t        dd      S )z>:returns: videos directory tied to the user, e.g. ``~/Videos``XDG_VIDEOS_DIRz~/VideosrB   r   s    r   user_videos_dirz_UnixDefaults.user_videos_diro   s     ##3Z@@r   c                    t        dd      S )z<:returns: music directory tied to the user, e.g. ``~/Music``XDG_MUSIC_DIRz~/MusicrB   r   s    r   user_music_dirz_UnixDefaults.user_music_dirt   s     #?I>>r   c                    t        dd      S )z@:returns: desktop directory tied to the user, e.g. ``~/Desktop``XDG_DESKTOP_DIRz	~/DesktoprB   r   s    r   user_desktop_dirz_UnixDefaults.user_desktop_diry   s     ##4kBBr   c                @    t         j                  j                  d      S )z?:returns: bin directory tied to the user, e.g. ``~/.local/bin``z~/.local/bin)r    r!   r"   r   s    r   user_bin_dirz_UnixDefaults.user_bin_dir~   s     ww!!.11r   c                     y)z@:returns: bin directory shared by users, e.g. ``/usr/local/bin``z/usr/local/bin r   s    r   site_bin_dirz_UnixDefaults.site_bin_dir   s      r   c                |    t         j                  j                  t         j                  j                  d      d      S )zW:returns: applications directory tied to the user, e.g. ``~/.local/share/applications``r   applications)r    r!   r:   r"   r   s    r   user_applications_dirz#_UnixDefaults.user_applications_dir   s)     ww||BGG../?@.QQr   c                h    dD cg c]"  }t         j                  j                  |d      $ c}S c c}w )N)r&   r'   rZ   )r    r!   r:   )r   ps     r   _site_applications_dirsz%_UnixDefaults._site_applications_dirs   s%    9[\AQ/\\\s   '/c                z    | j                   }| j                  rt        j                  j	                  |      S |d   S )zR:returns: applications directory shared by users, e.g. ``/usr/share/applications``r   )r^   	multipathr    pathsepr:   )r   dirss     r   site_applications_dirz#_UnixDefaults.site_applications_dir   s1     ++(,rzzt$CDGCr   c                h   t         j                  j                  d      rdt                }n:t         j                  j                  d      rdt                }ndt                }t	        j
                  |t        j                        st                dt                }| j                  |      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   r<   s     r   user_runtime_dirz_UnixDefaults.user_runtime_dir   s     <<""9-#FH:.D\\$$%:;#FH:.Dz*Dyyrww' l^9VXJ7D0066r   c                l    t         j                  j                  d      rd}nd}| j                  |      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.

        )rf   re   rg   z/var/runz/run)rh   ri   rj   r   r<   s     r   site_runtime_dirz_UnixDefaults.site_runtime_dir   s2     <<""#CDDD0066r   c                8    | j                  | 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   s    r   site_data_pathz_UnixDefaults.site_data_path   s     44T5G5GHHr   c                8    | j                  | j                        S )zg:returns: config path shared by users, returns the first item, even if ``multipath`` is set to ``True``)rq   site_config_dirr   s    r   site_config_pathz_UnixDefaults.site_config_path   s     44T5I5IJJr   c                8    | j                  | j                        S )zj:returns: cache path shared by users. Only return the first item, even if ``multipath`` is set to ``True``)rq   r2   r   s    r   site_cache_pathz_UnixDefaults.site_cache_path   s     44T5H5HIIr   c              #  T   K   | j                    | j                  E d{    y7 w)z4:yield: all user and site configuration directories.N)r,   r.   r   s    r   iter_config_dirsz_UnixDefaults.iter_config_dirs   s!     """))))   (&(c              #  T   K   | j                    | j                  E d{    y7 w)z+:yield: all user and site data directories.N)r#   r)   r   s    r   iter_data_dirsz_UnixDefaults.iter_data_dirs   s!        ''''r{   N)returnboolr~   str)r~   z	list[str])r~   r   )r~   zIterator[str])#__name__
__module____qualname____doc__r   r   propertyr#   r)   r,   r.   r0   r2   r4   r6   r=   r?   rD   rG   rJ   rM   rP   rS   rU   rX   r[   r^   rc   rm   ro   rs   rv   rx   rz   r}   rW   r   r   r   r      sM    8 8 W W x x R R ? ? Q Q ? ? W W = =   = = G G F F E E A A ? ? C C 2 2     R R ] ] D D
 7 7  7 7  I I K K J J*
(r   r   c                       e Zd ZdZed
 fd       Zed
 fd       Zed
 fd       Zed
 fd       Zed
 fd       Z	ed
 fd       Z
ed
 fd       Zed
 fd	       Z x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>`.

    c                H    | j                   r| j                  S t        |   S )zb:returns: data directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   rr   superr#   r   	__class__s    r   r#   zUnix.user_data_dir   s!     &*^^t!!N9NNr   c                H    | j                   r| j                  S t        |   S )zd:returns: config directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   ru   r   r,   r   s    r   r,   zUnix.user_config_dir   s!     (,~~t##R57;RRr   c                H    | j                   r| j                  S t        |   S )zc:returns: cache directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   r2   r   r0   r   s    r   r0   zUnix.user_cache_dir   !     '+nnt""P%':PPr   c                H    | j                   r| j                  S t        |   S )zc:returns: state directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   r6   r   r4   r   s    r   r4   zUnix.user_state_dir   r   r   c                H    | j                   r| j                  S t        |   S )za:returns: log directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   r?   r   r=   r   s    r   r=   zUnix.user_log_dir   !     %)NNt  L8LLr   c                H    | j                   r| j                  S t        |   S )zj:returns: applications directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   rc   r   r[   r   s    r   r[   zUnix.user_applications_dir   s!     .2^^t))^A^^r   c                H    | j                   r| j                  S t        |   S )ze:returns: runtime directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   ro   r   rm   r   s    r   rm   zUnix.user_runtime_dir   s!     )-t$$TEG<TTr   c                H    | j                   r| j                  S t        |   S )za:returns: bin directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   rX   r   rU   r   s    r   rU   zUnix.user_bin_dir  r   r   r   )r   r   r   r   r   r#   r,   r0   r4   r=   r[   rm   rU   __classcell__)r   s   @r   r   r      s     O O S S Q Q Q Q M M _ _ U U M Mr   r   c                ^    t        |       x}r|S t        j                  j                  |      S )N)_get_user_dirs_folderr    r!   r"   )env_varfallback_tilde_path	media_dirs      r   rC   rC     s.    )'22y277122r   c                   t         j                  j                  dd      j                         xs t         j                  j                  d      }t        |      dz  }|j                         rt               }|j                         5 }|j                  d|j                                 ddd       | |d   vry|d   |    j                  d      }|j                  d	t         j                  j                  d
            S y# 1 sw Y   XxY w)zvReturn directory from user-dirs.dirs config file.

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

    XDG_CONFIG_HOME r+   zuser-dirs.dirsz[top]
Ntop"z$HOME~)r    environgetstripr!   r"   r   existsr   openread_stringreadreplace)keyconfig_homeuser_dirs_config_pathparserstreamr!   s         r   r   r     s     **..!2B7==?b277CUCUVaCbK -0@@##%"'') 	:V89	: fUm#e}S!'',||GRWW%7%7%<==	: 	:s   #DD)r~   r	   )r   r   r   r   r~   r   )r   r   r~   z
str | None)r   
__future__r   r    rh   configparserr   	functoolsr   pathlibr   tempfiler   typingr   r	   _xdgr   apir   collections.abcr   ri   r   r   r   rC   r   __all__rW   r   r   <module>r      sx     " 	 
 % %   *   (<<7 
 s(O s(l1M8] 1Mh30 r   