o
    ðT·jØB  ã                   @  s  U d Z ddlmZ ddlZddl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mZ ddlmZmZ dd	lmZ erEdd
lmZ ejdkrPd!dd„ZnddlmZ G dd„ deƒZG dd„ deeƒZe dej¡Zded< d"dd„Zd#dd „ZdgZ dS )$zUnix.é    )ÚannotationsN)ÚPath)Ú
gettempdir)ÚTYPE_CHECKINGÚFinalÚNoReturné   )ÚXDGMixinÚ_xdg_dir)ÚPlatformDirsABC)ÚIteratorÚwin32Úreturnr   c                  C  s   d} t | ƒ‚)Nzshould only be used on Unix)ÚRuntimeError)Úmsg© r   úT/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/platformdirs/unix.pyÚgetuid   s   r   )r   c                   @  s  e Zd ZdZedYdd„ƒZedZdd„ƒZed[d
d„ƒZedZdd„ƒZed[dd„ƒZ	edZdd„ƒZ
edZdd„ƒZedZdd„ƒZedZdd„ƒZedZdd„ƒZedZdd„ƒZedZdd„ƒZedZdd„ƒZedZd d!„ƒZedZd"d#„ƒZedZd$d%„ƒZedZd&d'„ƒZedZd(d)„ƒZedZd*d+„ƒZedZd,d-„ƒZd\d0d1„ZedZd2d3„ƒZedZd4d5„ƒZedZd6d7„ƒZedZd8d9„ƒZedZd:d;„ƒZed[d<d=„ƒZedZd>d?„ƒZ edZd@dA„ƒZ!dZdBdC„Z"edZdDdE„ƒZ#ed]dGdH„ƒZ$ed]dIdJ„ƒZ%d^dLdM„Z&d^dNdO„Z'd^dPdQ„Z(d^dRdS„Z)d^dTdU„Z*d^dVdW„Z+dXS )_Ú_UnixDefaultszžDefault 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 )zsData 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©Ú_join_app_name_and_versionr   r   r   r   Ú_site_data_dirs-   s   z_UnixDefaults._site_data_dirsc                 C  r   )zrConfig 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   )zoCache 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 )zGCache directory shared by users, e.g. ``/var/cache/$appname/$version``.z
/var/cache©r   r   r   r   r   Úsite_cache_dir?   ó   
z_UnixDefaults.site_cache_dirc                 C  r   )zuState 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.   )zEState directory shared by users, e.g. ``/var/lib/$appname/$version``.z/var/libr/   r   r   r   r   Úsite_state_dirI   r1   z_UnixDefaults.site_state_dirc                 C  s(   | j }| jrtj |d¡}|  |¡ |S )z_Log directory tied to the user, same as `user_state_dir` if not opinionated else ``log`` in it.Úlog)r2   Úopinionr   r    ÚjoinÚ_optionally_create_directory©r   r    r   r   r   Úuser_log_dirN   s
   
z_UnixDefaults.user_log_dirc                 C  r.   )z¹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  ó   |   dd¡S )z;Documents directory tied to the user, e.g. ``~/Documents``.ÚXDG_DOCUMENTS_DIRz~/Documents©Ú_user_media_dirr   r   r   r   Úuser_documents_dir`   ó   z _UnixDefaults.user_documents_dirc                 C  r;   )z;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  r;   )z9Pictures 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  r;   )z5Videos 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  r;   )z3Music 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  r;   )z7Desktop 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  r;   )z9Projects directory tied to the user, e.g. ``~/Projects``.ÚXDG_PROJECTS_DIRz
~/Projectsr=   r   r   r   r   Úuser_projects_dir~   r@   z_UnixDefaults.user_projects_dirc                 C  r;   )z;Public share directory tied to the user, e.g. ``~/Public``.ÚXDG_PUBLICSHARE_DIRz~/Publicr=   r   r   r   r   Úuser_publicshare_dirƒ   r@   z"_UnixDefaults.user_publicshare_dirc                 C  r;   )z;Templates directory tied to the user, e.g. ``~/Templates``.ÚXDG_TEMPLATES_DIRz~/Templatesr=   r   r   r   r   Úuser_templates_dirˆ   r@   z _UnixDefaults.user_templates_dirÚkeyÚdefaultc                 C  s&   t |ƒ }r|  |¡ |S tj |¡S ©N)Ú_get_user_dirs_folderÚ"_optionally_create_media_directoryr   r    r!   )r   rQ   rR   r    r   r   r   r>   �   s   
z_UnixDefaults._user_media_dirc                 C  s   t j d¡› d�S )z@Fonts directory tied to the user, e.g. ``~/.local/share/fonts``.r   z/fonts©r   r    r!   r   r   r   r   Úuser_fonts_dir“   r#   z_UnixDefaults.user_fonts_dirc                 C  s   | j S )zCPreference directory tied to the user, same as ``user_config_dir``.)r+   r   r   r   r   Úuser_preference_dir˜   s   z!_UnixDefaults.user_preference_dirc                 C  s   t j d¡S )z6Bin directory tied to the user, e.g. ``~/.local/bin``.z~/.local/binrV   r   r   r   r   Úuser_bin_dir�   r@   z_UnixDefaults.user_bin_dirc                 C  s   dS )z7Bin 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 )zNApplications directory tied to the user, e.g. ``~/.local/share/applications``.r   Úapplications)r   r    r6   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 )r[   )r   r    r6   )Ú.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 )zIApplications directory shared by users, e.g. ``/usr/share/applications``.r   )r`   Ú	multipathr   Úpathsepr6   )r   Údirsr   r   r   Úsite_applications_dir°   s   z#_UnixDefaults.site_applications_dirc                 C  s`   t j d¡rdtƒ › �}nt j d¡rdtƒ › �}ndtƒ › �}t |tj¡s+|  ¡ }|  |¡S )a  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 ``runtime-$(id -u)`` in the temporary directory, with mode ``0700`` under ``ensure_exists``.

        :raises PermissionError: if another user owns the temporary fallback directory.

        Úopenbsdz/tmp/run/user/)ÚfreebsdÚnetbsdz/var/run/user/z
/run/user/)	ÚsysÚplatformÚ
startswithr   r   ÚaccessÚW_OKÚ_temp_runtime_dirr   r8   r   r   r   Úuser_runtime_dir¶   s   
z_UnixDefaults.user_runtime_dirc                 C  sª   t ƒ › dtƒ  }› �}| jrt|ƒjddd� zt|ƒ ¡ }W n ty*   | Y S w |j|krAd|› d|j› d|› d�}t|ƒ‚| jrSt	 
|j¡d	@ rSt|ƒ d¡ |S )
Nz	/runtime-iÀ  T)ÚmodeÚexist_okzruntime directory z is owned by uid z, not z; set XDG_RUNTIME_DIR insteadé?   )r   r   Úensure_existsr   ÚmkdirÚlstatÚFileNotFoundErrorÚst_uidÚPermissionErrorÚstatÚS_IMODEÚst_modeÚchmod)r   Úuidr    Úinfor   r   r   r   rm   Ë   s   ÿ
z_UnixDefaults._temp_runtime_dirc                 C  s    t j d¡r	d}nd}|  |¡S )aT  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   r8   r   r   r   Úsite_runtime_dirÜ   s   
z_UnixDefaults.site_runtime_dirr   c                 C  ó   |   | j¡S )z`Data path shared by users. Only return the first item, even if ``multipath`` is set to ``True``.)Ú_first_site_dir_as_pathr)   r   r   r   r   Úsite_data_pathï   r@   z_UnixDefaults.site_data_pathc                 C  r   )z^Config path shared by users, returns the first item, even if ``multipath`` is set to ``True``.)r€   r,   r   r   r   r   Úsite_config_pathô   r@   z_UnixDefaults.site_config_pathúIterator[str]c                 c  ó&   � | j s| jV  |  | j¡E d H  d S rS   )r   r+   Ú_create_as_yieldedr,   r   r   r   r   Ú_iter_config_dirsù   s   €z_UnixDefaults._iter_config_dirsc                 c  r„   rS   )r   r"   r…   r)   r   r   r   r   Ú_iter_data_dirs   s   €z_UnixDefaults._iter_data_dirsc                 c  ó   � | j s| jV  | jV  d S rS   )r   r-   r0   r   r   r   r   Ú_iter_cache_dirs  ó   €z_UnixDefaults._iter_cache_dirsc                 c  rˆ   rS   )r   r2   r3   r   r   r   r   Ú_iter_state_dirs
  rŠ   z_UnixDefaults._iter_state_dirsc                 c  rˆ   rS   )r   r9   r:   r   r   r   r   Ú_iter_log_dirs  rŠ   z_UnixDefaults._iter_log_dirsc                 c  s    � | j V  | js| jV  d S d S rS   )rn   r   r~   r   r   r   r   Ú_iter_runtime_dirs  s
   €ÿz _UnixDefaults._iter_runtime_dirsN)r   r   ©r   r   )r   r$   )rQ   r   rR   r   r   r   ©r   r   )r   rƒ   ),Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r"   r)   r+   r,   r-   r0   r2   r3   r9   r:   r?   rB   rD   rF   rH   rJ   rL   rN   rP   r>   rW   rX   rY   rZ   r\   r`   rd   rn   rm   r~   r�   r‚   r†   r‡   r‰   r‹   rŒ   r�   r   r   r   r   r      s�    






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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 )zYData directory tied to the user, or site equivalent when root with ``use_site_for_root``.)r   Úsite_data_dirÚsuperr"   r   ©Ú	__class__r   r   r"   %  ó   zUnix.user_data_dirc                   r–   )z[Config directory tied to the user, or site equivalent when root with ``use_site_for_root``.)r   Úsite_config_dirr˜   r+   r   r™   r   r   r+   *  r›   zUnix.user_config_dirc                   r–   )zZCache directory tied to the user, or site equivalent when root with ``use_site_for_root``.)r   r0   r˜   r-   r   r™   r   r   r-   /  r›   zUnix.user_cache_dirc                   r–   )zZState directory tied to the user, or site equivalent when root with ``use_site_for_root``.)r   r3   r˜   r2   r   r™   r   r   r2   4  r›   zUnix.user_state_dirc                   r–   )zXLog directory tied to the user, or site equivalent when root with ``use_site_for_root``.)r   r:   r˜   r9   r   r™   r   r   r9   9  r›   zUnix.user_log_dirc                   r–   )zaApplications directory tied to the user, or site equivalent when root with ``use_site_for_root``.)r   rd   r˜   r\   r   r™   r   r   r\   >  r›   zUnix.user_applications_dirc                   s   | j r	tt| ƒjS tƒ jS )z\Runtime directory tied to the user, or site equivalent when root with ``use_site_for_root``.)r   r˜   r	   r~   rn   r   r™   r   r   rn   C  s   zUnix.user_runtime_dirc                   r–   )zXBin directory tied to the user, or site equivalent when root with ``use_site_for_root``.)r   rZ   r˜   rY   r   r™   r   r   rY   I  r›   zUnix.user_bin_dirr   c                   r–   )zYData path tied to the user, or the first site entry when root with ``use_site_for_root``.)r   r�   r˜   Úuser_data_pathr   r™   r   r   r�   N  r›   zUnix.user_data_pathc                   r–   )z[Config path tied to the user, or the first site entry when root with ``use_site_for_root``.)r   r‚   r˜   Úuser_config_pathr   r™   r   r   rž   S  r›   zUnix.user_config_pathc                   r–   )zfPreference path tied to the user, or the first site config entry when root with ``use_site_for_root``.)r   r‚   r˜   Úuser_preference_pathr   r™   r   r   rŸ   X  r›   zUnix.user_preference_pathc                   r–   )zaApplications path tied to the user, or the first site entry when root with ``use_site_for_root``.)r   Úsite_applications_pathr˜   Úuser_applications_pathr   r™   r   r   r¡   ]  r›   zUnix.user_applications_pathrŽ   r�   )r�   r‘   r’   r“   r”   r"   r+   r-   r2   r9   r\   rn   rY   r�   rž   rŸ   r¡   Ú__classcell__r   r   r™   r   r•     s4    
r•   aˆ  
    [ \t]*(?P<key>\w+)[ \t]*=[ \t]*  # KEY=, blanks allowed around the key and after the =
    (?:
        "(?P<quoted>(?:[^"\\]|\\.)*)"  # a double-quoted value with backslash escapes, text after it ignored
        |(?P<bare>[^"\s].*?)          # or an unquoted value, up to
        (?:[ \t]+\#.*|[ \t]*)$         # a comment, which sh starts at a word-initial #, or the line end
    )
    r   Ú_USER_DIRS_LINErQ   r   ú
str | Nonec                 C  s˜   t dƒp	tj d¡}t|ƒd }| ¡ sdS d}|jt ¡ dd��!}|D ]}t	 
|¡ }r9|d | kr9t|ƒp8|}q$W d  ƒ |S 1 sEw   Y  |S )a  Return directory from user-dirs.dirs config file.

    ``xdg-user-dirs-update`` writes shell assignments, so match each line like ``xdg-user-dir`` does and keep the last
    valid assignment to ``key``.

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

    ÚXDG_CONFIG_HOMEr*   zuser-dirs.dirsNÚsurrogateescape)ÚencodingÚerrorsrQ   )r
   r   r    r!   r   ÚexistsÚopenrh   Úgetfilesystemencodingr£   ÚmatchÚ_resolve_user_dirs_value)rQ   Úconfig_homeÚuser_dirs_config_pathÚfolderÚstreamÚlineÚentryr   r   r   rT   p  s   	€þ
ÿürT   r³   úre.Match[str]c                 C  s~   | d d u r
| d n| d }|dks|  d¡r$tj d¡| d¡}}n
|  d¡r,d}nd S | d d ur;t dd	|¡}|| S )
NÚquotedÚbarez$HOMEz$HOME/ú~ú/Ú z\\(.)z\1)rj   r   r    r!   ÚremoveprefixÚreÚsub)r³   ÚvalueÚprefixr   r   r   r­   †  s   
r­   )r   r   )rQ   r   r   r¤   )r³   r´   r   r¤   )!r“   Ú
__future__r   r   r»   rx   rh   Úpathlibr   Útempfiler   Útypingr   r   r   Ú_xdgr	   r
   Úapir   Úcollections.abcr   ri   r   r   r•   ÚcompileÚVERBOSEr£   Ú__annotations__rT   r­   Ú__all__r   r   r   r   Ú<module>   s6    
 ~I÷

ÿ