
    
_d                        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                  j                  d      rd dlmZ ndd	Z G d
 de	      ZddZdgZy)    )annotationsN)ConfigParser)Path   )PlatformDirsABClinux)getuidc                     t        d      )Nzshould only be used on Linux)RuntimeError     I/usr/lib/python3/dist-packages/pkg_resources/_vendor/platformdirs/unix.pyr	   r	      s    9::r   c                      e Zd ZdZedd       Zedd       Z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y)UnixaD  
    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>`.
    c                    t         j                  j                  dd      }|j                         st         j                  j                  d      }| j                  |      S )z
        :return: data directory tied to the user, e.g. ``~/.local/share/$appname/$version`` or
         ``$XDG_DATA_HOME/$appname/$version``
        XDG_DATA_HOME z~/.local/shareosenvirongetstrippath
expanduser_append_app_name_and_versionselfr   s     r   user_data_dirzUnix.user_data_dir   sG     zz~~or2zz|77%%&67D0066r   c                    t         j                  j                  dd      }|j                         sdt         j                   d}| j                  |      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``
        XDG_DATA_DIRSr   z/usr/local/sharez
/usr/share)r   r   r   r   pathsep_with_multi_pathr   s     r   site_data_dirzUnix.site_data_dir)   sD     zz~~or2zz|%bjj\<D$$T**r   c                    |j                  t        j                        }| j                  s|dd }|D cg c]0  }| j	                  t        j
                  j                  |            2 }}t        j                  j                  |      S c c}w )Nr   r   )splitr   r!   	multipathr   r   r   join)r   r   	path_listps       r   r"   zUnix._with_multi_path6   sm    JJrzz*	~~!!AIW`aRST66rww7I7I!7LMa	azzy)) bs   5Bc                    t         j                  j                  dd      }|j                         st         j                  j                  d      }| j                  |      S )z
        :return: config directory tied to the user, e.g. ``~/.config/$appname/$version`` or
         ``$XDG_CONFIG_HOME/$appname/$version``
        XDG_CONFIG_HOMEr   z	~/.configr   r   s     r   user_config_dirzUnix.user_config_dir=   sG     zz~~/4zz|77%%k2D0066r   c                    t         j                  j                  dd      }|j                         sd}| j	                  |      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``
        XDG_CONFIG_DIRSr   z/etc/xdg)r   r   r   r   r"   r   s     r   site_config_dirzUnix.site_config_dirH   s8     zz~~/4zz|D$$T**r   c                    t         j                  j                  dd      }|j                         st         j                  j                  d      }| j                  |      S )z
        :return: cache directory tied to the user, e.g. ``~/.cache/$appname/$version`` or
         ``~/$XDG_CACHE_HOME/$appname/$version``
        XDG_CACHE_HOMEr   z~/.cacher   r   s     r   user_cache_dirzUnix.user_cache_dirU   sG     zz~~.3zz|77%%j1D0066r   c                    t         j                  j                  dd      }|j                         st         j                  j                  d      }| j                  |      S )z
        :return: state directory tied to the user, e.g. ``~/.local/state/$appname/$version`` or
         ``$XDG_STATE_HOME/$appname/$version``
        XDG_STATE_HOMEr   z~/.local/stater   r   s     r   user_state_dirzUnix.user_state_dir`   sH     zz~~.3zz|77%%&67D0066r   c                v    | j                   }| j                  r t        j                  j	                  |d      }|S )zy
        :return: log directory tied to the user, same as `user_state_dir` if not opinionated else ``log`` in it
        log)r5   opinionr   r   r'   r   s     r   user_log_dirzUnix.user_log_dirk   s/    
 ""<<77<<e,Dr   c                    t        d      }|Ot        j                  j                  dd      j	                         }|st        j
                  j                  d      }|S )zU
        :return: documents directory tied to the user, e.g. ``~/Documents``
        XDG_DOCUMENTS_DIRr   z~/Documents)_get_user_dirs_folderr   r   r   r   r   r   )r   documents_dirs     r   user_documents_dirzUnix.user_documents_diru   sP    
 ..AB JJNN+>CIIKM  " 2 2= Ar   c                    t         j                  j                  dd      }|j                         sdt	                }| j                  |      S )z
        :return: runtime directory tied to the user, e.g. ``/run/user/$(id -u)/$appname/$version`` or
         ``$XDG_RUNTIME_DIR/$appname/$version``
        XDG_RUNTIME_DIRr   z
/run/user/)r   r   r   r   r	   r   r   s     r   user_runtime_dirzUnix.user_runtime_dir   sA     zz~~/4zz|z*D0066r   c                8    | j                  | 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   s    r   site_data_pathzUnix.site_data_path   s     44T5G5GHHr   c                8    | j                  | j                        S )zj:return: config path shared by the users. Only return first item, even if ``multipath`` is set to ``True``)rC   r/   rD   s    r   site_config_pathzUnix.site_config_path   s     44T5I5IJJr   c                t    | j                   r"|j                  t        j                        d   }t	        |      S )Nr   )r&   r%   r   r!   r   )r   	directorys     r   rC   z%Unix._first_item_as_path_if_multipath   s*    >>!

3A6IIr   N)returnstr)r   rK   rJ   rK   )rJ   r   )rI   rK   rJ   r   )__name__
__module____qualname____doc__propertyr   r#   r"   r,   r/   r2   r5   r9   r>   rA   rE   rG   rC   r   r   r   r   r      s    	 7 7 
+ 
+* 7 7 
+ 
+ 7 7 7 7   
 
 7 7 I I K Kr   r   c                   t         j                  j                  t               j                  d      }t         j                  j                  |      rt               }t        |      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   ZxY w)zjReturn directory from user-dirs.dirs config file. See https://freedesktop.org/wiki/Software/xdg-user-dirs/zuser-dirs.dirsz[top]
Ntop"z$HOME~)r   r   r'   r   r,   existsr   openread_stringreadr   replacer   )keyuser_dirs_config_pathparserstreamr   s        r   r<   r<      s    GGLL)?)?AQR	ww~~+,'( 	:F89	: fUm#e}S!'',||GRWW%7%7%<=	: 	:s   '#C##C,)rJ   int)rZ   rK   rJ   z
str | None)
__future__r   r   sysconfigparserr   pathlibr   apir   platform
startswithr	   r   r<   __all__r   r   r   <module>rg      sQ    " 	 
 %   <<7#;I? IX, r   