o
    	ÁP‘  ã                   @   sú   d Z ddlZej d¡Zej d¡pej edd¡Zegej d¡p#d 	d	¡ Z
ej d
¡p4ej ed¡Zegej d¡p>d 	d	¡ Zej d¡pOej ed¡Zdd„ e
D ƒZ
dd„ eD ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd"d d!„ZdS )#a  
This module is based on a rox module (LGPL):

http://cvs.sourceforge.net/viewcvs.py/rox/ROX-Lib2/python/rox/basedir.py?rev=1.9&view=log

The freedesktop.org Base Directory specification provides a way for
applications to locate shared data and configuration:

    http://standards.freedesktop.org/basedir-spec/

(based on version 0.6)

This module can be used to load and save from and to these directories.

Typical usage:

    from rox import basedir
    
    for dir in basedir.load_config_paths('mydomain.org', 'MyProg', 'Options'):
        print "Load settings from", dir

    dir = basedir.save_config_path('mydomain.org', 'MyProg')
    print >>file(os.path.join(dir, 'Options'), 'w'), "foo=2"

Note: see the rox.Options module for a higher-level API for managing options.
é    Nú~ÚXDG_DATA_HOMEz.localÚshareÚXDG_DATA_DIRSz/usr/local/share:/usr/shareú:ÚXDG_CONFIG_HOMEz.configÚXDG_CONFIG_DIRSz/etc/xdgÚXDG_CACHE_HOMEz.cachec                 C   ó   g | ]}|r|‘qS © r   ©Ú.0Úxr   r   úC/var/www/html/env/lib/python3.10/site-packages/xdg/BaseDirectory.pyÚ
<listcomp>.   ó    r   c                 C   r
   r   r   r   r   r   r   r   /   r   c                  G   sD   t jj| Ž } |  d¡rJ ‚t j t| ¡}t j |¡s t  |d¡ |S )zºEnsure ``$XDG_CONFIG_HOME/<resource>/`` exists, and return its path.
    'resource' should normally be the name of your application. Use this
    when saving configuration settings.
    ú/éÀ  )ÚosÚpathÚjoinÚ
startswithÚxdg_config_homeÚisdirÚmakedirs©Úresourcer   r   r   r   Úsave_config_path1   s   r   c                  G   óB   t jj| Ž } |  d¡rJ ‚t j t| ¡}t j |¡st  |¡ |S )zÓEnsure ``$XDG_DATA_HOME/<resource>/`` exists, and return its path.
    'resource' should normally be the name of your application or a shared
    resource. Use this when saving or updating application data.
    r   )r   r   r   r   Úxdg_data_homer   r   r   r   r   r   Úsave_data_path=   s   
r    c                  G   r   )zœEnsure ``$XDG_CACHE_HOME/<resource>/`` exists, and return its path.
    'resource' should normally be the name of your application or a shared
    resource.r   )r   r   r   r   Úxdg_cache_homer   r   r   r   r   r   Úsave_cache_pathI   s   
r"   c                  g   ó<   � t jj| Ž } tD ]}t j || ¡}t j |¡r|V  q	dS )zïReturns an iterator which gives each directory named 'resource' in the
    configuration search path. Information provided by earlier directories should
    take precedence over later ones, and the user-specific config dir comes
    first.N)r   r   r   Úxdg_config_dirsÚexists)r   Ú
config_dirr   r   r   r   Úload_config_pathsT   s   €€þr'   c                  G   s   t | Ž D ]}|  S dS )zYReturns the first result from load_config_paths, or None if there is nothing
    to load.N)r'   )r   r   r   r   r   Úload_first_config^   s   r(   c                  g   r#   )zÀReturns an iterator which gives each directory named 'resource' in the
    application data search path. Information provided by earlier directories
    should take precedence over later ones.N)r   r   r   Úxdg_data_dirsr%   )r   Údata_dirr   r   r   r   Úload_data_pathse   s   €€þr+   Tc                 C   s²   zt jd W S  tyX   | r‚ ddl}d| ¡  }zt  |d¡ W | Y S  tyW } z&ddl}|j|jkrIddl	}t  
||j|jB |jB ¡ n‚ W Y d}~| Y S d}~ww w )a   Returns the value of $XDG_RUNTIME_DIR, a directory path.
    
    This directory is intended for 'user-specific non-essential runtime files
    and other file objects (such as sockets, named pipes, ...)', and
    'communication and synchronization purposes'.
    
    As of late 2012, only quite new systems set $XDG_RUNTIME_DIR. If it is not
    set, with ``strict=True`` (the default), a KeyError is raised. With 
    ``strict=False``, PyXDG will create a fallback under /tmp for the current
    user. This fallback does *not* provide the same guarantees as the
    specification requires for the runtime directory.
    
    The strict default is deliberately conservative, so that application
    developers can make a conscious decision to allow the fallback.
    ÚXDG_RUNTIME_DIRr   Nz /tmp/pyxdg-runtime-dir-fallback-r   )r   ÚenvironÚKeyErrorÚgetpassÚgetuserÚmkdirÚOSErrorÚerrnoÚEEXISTÚstatÚchmodÚS_IRUSRÚS_IWUSRÚS_IXUSR)Ústrictr/   ÚfallbackÚer3   r5   r   r   r   Úget_runtime_dirn   s*   
÷
þ€÷ør=   )T)Ú__doc__r   r   Ú
expanduserÚ_homer-   Úgetr   r   Úsplitr)   r   r$   r!   r   r    r"   r'   r(   r+   r=   r   r   r   r   Ú<module>   s6    ÿÿÿÿÿ
	