o
    à;ïju  ã                   @   s&  d Z ddl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
¡p8ej ed¡Zegej d¡pBd 
d	¡ Zej d¡pSej ed¡Zej d¡paej ed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"„ 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.cacheÚXDG_STATE_HOMEÚstatec                 C   ó   g | ]}|r|‘qS © r   ©Ú.0Úxr   r   úZ/home/hd29/karthikselvaraju/venvs/deluge/lib/python3.10/site-packages/xdg/BaseDirectory.pyÚ
<listcomp>1   ó    r   c                 C   r   r   r   r   r   r   r   r   2   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_path4   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_pathL   ó   
r$   c                  G   r    )zœEnsure ``$XDG_STATE_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_state_homer   r   r   r   r   r   Úsave_state_pathW   r%   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_pathsb   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_configl   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_pathss   s   €€þr0   Tc                 C   sì   zt jd W S  tyu   | r‚ ddl}d| ¡  }d}zt  |¡}W n  tyC } zddl}|j|jkr8d}n‚ W Y d}~n*d}~ww t	 
|j¡sRt  |¡ d}n|jt  ¡ ksb|jt	jt	jB @ rit  |¡ d}|rqt  |d¡ | Y S 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-FTr   )r   ÚenvironÚKeyErrorÚgetpassÚgetuserÚlstatÚOSErrorÚerrnoÚENOENTÚstatÚS_ISDIRÚst_modeÚunlinkÚst_uidÚgetuidÚS_IRWXGÚS_IRWXOÚrmdirÚmkdir)Ústrictr4   ÚfallbackÚcreateÚstÚer8   r   r   r   Úget_runtime_dir|   s<   þ€ý
ÿ
àrI   )T)Ú__doc__r   r:   r   Ú
expanduserÚ_homer2   Úgetr   r!   Úsplitr.   r   r)   r#   r&   r   r"   r$   r'   r,   r-   r0   rI   r   r   r   r   Ú<module>   s>    ÿÿÿÿÿÿ
	