
    1iN/                    
   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dS ) zUnix.    )annotationsN)ConfigParser)cached_property)Path)
gettempdir)TYPE_CHECKINGNoReturn   )XDGMixin)PlatformDirsABC)Iteratorwin32returnr	   c                 $    d} t          |           )Nzshould only be used on Unix)RuntimeError)msgs    O/var/www/html/speakWrite/venv/lib/python3.11/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"d%S )+_UnixDefaultszDefault directories for Unix/Linux without XDG environment variable overrides.

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

    r   boolc                4    | j         ot                      dk    S )Nr   )use_site_for_rootr   selfs    r   	_use_sitez_UnixDefaults._use_site$   s    %7&((a-7r   strc                f    |                      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   s    r   user_data_dirz_UnixDefaults.user_data_dir(   )     001C1CDT1U1UVVVr   	list[str]c                V    |                      d          |                      d          gS )N/usr/local/share
/usr/sharer"   r   s    r   _site_data_dirsz_UnixDefaults._site_data_dirs-   s+    112DEEtGhGhiuGvGvwwr   c                f    |                      t          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1C1CK1P1PQQQr   c                .    |                      d          gS )Nz/etc/xdgr,   r   s    r   _site_config_dirsz_UnixDefaults._site_config_dirs6   s    11*==>>r   c                f    |                      t          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1C1CJ1O1OPPPr   c                ,    |                      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                f    |                      t          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                ,    |                      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        r5t          j                            |d          }|                     |           |S )zh:returns: log directory tied to the user, same as `user_state_dir` if not opinionated else ``log`` in itlog)r8   opinionr#   r$   join_optionally_create_directoryr   r$   s     r   user_log_dirz_UnixDefaults.user_log_dirN   sD     "< 	47<<e,,D--d333r   c                ,    |                      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FFr   c                "    t          dd          S )zD:returns: downloads directory tied to the user, e.g. ``~/Downloads``XDG_DOWNLOAD_DIRz~/DownloadsrF   r   s    r   user_downloads_dirz _UnixDefaults.user_downloads_dire   s     ##5}EEEr   c                "    t          dd          S )zB:returns: pictures directory tied to the user, e.g. ``~/Pictures``XDG_PICTURES_DIRz
~/PicturesrF   r   s    r   user_pictures_dirz_UnixDefaults.user_pictures_dirj   s     ##5|DDDr   c                "    t          dd          S )z>:returns: videos directory tied to the user, e.g. ``~/Videos``XDG_VIDEOS_DIRz~/VideosrF   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~/MusicrF   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	~/DesktoprF   r   s    r   user_desktop_dirz_UnixDefaults.user_desktop_diry   s     ##4kBBBr   c                @    t           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     w!!.111r   c                    dS )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                            t           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+     w||BG../?@@.QQQr   c                    d dD             S )Nc                N    g | ]"}t           j                            |d           #S )r^   )r#   r$   r>   ).0ps     r   
<listcomp>z9_UnixDefaults._site_applications_dirs.<locals>.<listcomp>   s(    \\\AQ//\\\r   )r*   r+   r[   r   s    r   _site_applications_dirsz%_UnixDefaults._site_applications_dirs   s    \\9[\\\\r   c                l    | j         }| j        rt          j                            |          n|d         S )zR:returns: applications directory shared by users, e.g. ``/usr/share/applications``r   )re   	multipathr#   pathsepr>   )r   dirss     r   site_applications_dirz#_UnixDefaults.site_applications_dir   s0     +(,Crzt$$$DGCr   c                   t           j                            d          rdt                       }nBt           j                            d          rdt                       }ndt                       }t	          j        |t          j                  st                       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"   r@   s     r   user_runtime_dirz_UnixDefaults.user_runtime_dir   s     <""9-- 	+.FHH..DD\$$%:;; 	+.FHH..DD***Dyrw'' 	8 ll77VXX77D00666r   c                t    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.

        )rm   rl   rn   z/var/runz/run)ro   rp   rq   r"   r@   s     r   site_runtime_dirz_UnixDefaults.site_runtime_dir   s=     <""#CDD 	DDD00666r   r   c                6    |                      | 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4T5GHHHr   c                6    |                      | j                  S )zg:returns: config path shared by users, returns the first item, even if ``multipath`` is set to ``True``)rx   site_config_dirr   s    r   site_config_pathz_UnixDefaults.site_config_path   s     44T5IJJJr   c                6    |                      | j                  S )zj:returns: cache path shared by users. Only return the first item, even if ``multipath`` is set to ``True``)rx   r6   r   s    r   site_cache_pathz_UnixDefaults.site_cache_path   s     44T5HIIIr   Iterator[str]c              #  6   K   | j         V  | j        E d{V  dS )z4:yield: all user and site configuration directories.N)r0   r2   r   s    r   iter_config_dirsz_UnixDefaults.iter_config_dirs   s6      """"))))))))))r   c              #  6   K   | j         V  | j        E d{V  dS )z+:yield: all user and site data directories.N)r&   r-   r   s    r   iter_data_dirsz_UnixDefaults.iter_data_dirs   s6          ''''''''''r   N)r   r   r   r   )r   r(   )r   r   )r   r   )#__name__
__module____qualname____doc__r   r   propertyr&   r-   r0   r2   r4   r6   r8   r:   rA   rC   rH   rK   rN   rQ   rT   rW   rY   r\   r_   re   rj   rt   rv   rz   r}   r   r   r   r[   r   r   r   r      s         8 8 8 _8 W W W XW x x x Xx R R R XR ? ? ? X? Q Q Q XQ ? ? ? X? W W W XW = = = X=    X = = = X= G G G XG F F F XF E E E XE A A A XA ? ? ? X? C C C XC 2 2 2 X2       X  R R R XR ] ] ] X] D D D XD
 7 7 7 X7  7 7 7 X7  I I I XI K K K XK J J J X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>`.

    r   r   c                F    | j         r| j        nt                      j        S )zb:returns: data directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   ry   superr&   r   	__class__s    r   r&   zUnix.user_data_dir   s!     &*^Nt!!9NNr   c                F    | j         r| j        nt                      j        S )zd:returns: config directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   r|   r   r0   r   s    r   r0   zUnix.user_config_dir   s!     (,~Rt##577;RRr   c                F    | j         r| j        nt                      j        S )zc:returns: cache 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_cache_dir   !     '+nPt""%'':PPr   c                F    | j         r| j        nt                      j        S )zc:returns: state directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   r:   r   r8   r   s    r   r8   zUnix.user_state_dir   r   r   c                F    | j         r| j        nt                      j        S )za:returns: log directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   rC   r   rA   r   s    r   rA   zUnix.user_log_dir   !     %)NLt  8LLr   c                F    | j         r| j        nt                      j        S )zj:returns: applications directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   rj   r   r_   r   s    r   r_   zUnix.user_applications_dir   s!     .2^^t))A^^r   c                F    | j         r| j        nt                      j        S )ze:returns: runtime directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   rv   r   rt   r   s    r   rt   zUnix.user_runtime_dir   s!     )-Tt$$EGG<TTr   c                F    | j         r| j        nt                      j        S )za:returns: bin directory tied to the user, or site equivalent when root with ``use_site_for_root``)r   r\   r   rY   r   s    r   rY   zUnix.user_bin_dir  r   r   r   )r   r   r   r   r   r&   r0   r4   r8   rA   r_   rt   rY   __classcell__)r   s   @r   r   r      s         O O O O O XO S S S S S XS Q Q Q Q Q XQ Q Q Q Q Q XQ M M M M M XM _ _ _ _ _ X_ U U U U U XU M M M M M XM M M M Mr   r   env_varr   fallback_tilde_pathc                f    t          |           x}r|S t          j                            |          S )N)_get_user_dirs_folderr#   r$   r%   )r   r   	media_dirs      r   rG   rG     s4    )'222y 71222r   key
str | Nonec                   t          t          j                            d                    dz  }|                                rt                      }|                                5 }|                    d|                                            ddd           n# 1 swxY w Y   | |d         vrd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$   s        r   r   r     s)    !!3!3K!@!@AADTT##%% 
>"'')) 	:V888999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: fUm##4e}S!'',,||GRW%7%7%<%<===4s   &+BB!$B!)r   r	   )r   r   r   r   r   r   )r   r   r   r   )r   
__future__r   r#   ro   configparserr   	functoolsr   pathlibr   tempfiler   typingr   r	   _xdgr   apir   collections.abcr   rp   r   r   r   rG   r   __all__r[   r   r   <module>r      s    " " " " " " 				 



 % % % % % % % % % % % %             * * * * * * * *                   )((((((<7         
 s( s( s( s( s(O s( s( s(l1M 1M 1M 1M 1M8] 1M 1M 1Mh3 3 3 3   . r   