
    b_w                        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   Zej                            d
          pej                            ed          Zegej                            d          pd
                    d	          z   Zej                            d          pej                            ed          Zd eD             Zd eD             Zd Zd Zd Zd Zd Zd Z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                     g | ]}||S  r   .0xs     1lib/python3.11/site-packages/xdg/BaseDirectory.py
<listcomp>r   .   s    ///qQ////    c                     g | ]}||S r   r   r   s     r   r   r   /   s    33331333r   c                     t          j        j        |  } |                     d          rJ t           j                            t          |           }t           j                            |          st          j        |d           |S )zEnsure ``$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   s     r   save_config_pathr    1   sn    
 w|X&H""3'''''7<<22D7== !
D%   Kr   c                  
   t          j        j        |  } |                     d          rJ t           j                            t          |           }t           j                            |          st          j        |           |S )zEnsure ``$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   s     r   save_data_pathr#   =   sl    
 w|X&H""3'''''7<<x00D7== 
DKr   c                  
   t          j        j        |  } |                     d          rJ t           j                            t          |           }t           j                            |          st          j        |           |S )zEnsure ``$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   s     r   save_cache_pathr&   I   sl     w|X&H""3'''''7<<11D7== 
DKr   c               '      K   t          j        j        |  } t          D ]E}t           j                            ||           }t           j                            |          r|V  FdS )zReturns 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   s      r   load_config_pathsr+   T   sa      
 w|X&H% , ,
w||J117>>$+t, ,r   c                  $    t          |  D ]}|c S dS )zYReturns the first result from load_config_paths, or None if there is nothing
    to load.N)r+   )r   r   s     r   load_first_configr-   ^   s&     )  4r   c               '      K   t          j        j        |  } t          D ]E}t           j                            ||           }t           j                            |          r|V  FdS )zReturns 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   s      r   load_data_pathsr1   e   sa       w|X&H! , ,w||Hh//7>>$+t, ,r   Tc                 L   	 t           j        d         S # t          $ r | r ddl}d|                                z   }d}	 t          j        |          }t          j        |j                  st          j	        |           d}n|j
        t          j                    k    s!|j        t          j        t          j        z  z  rt          j        |           d}n/# t          $ r"}ddl}|j        |j        k    rd}n Y d}~nd}~ww xY w|rt          j        |d           |cY S w xY 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statS_ISDIRst_modeunlinkst_uidgetuidS_IRWXGS_IRWXOrmdirOSErrorerrnoENOENTmkdir)strictr6   fallbackcreatesterC   s          r   get_runtime_dirrK   n   sW    "z+,,       	58I8II	 (##B <
++ 	(###)ry{{***t| ;< +"""  	 	 	LLLw%,&& 	"  	&HXu%%%A s:    +D# CBD#
D"C?:D#?DD#"D#)T)__doc__r   r9   r   
expanduser_homer4   getr   r"   splitr/   r   r(   r%   r    r#   r&   r+   r-   r1   rK   r   r   r   <module>rQ      s   6 
3
// 3GLL'22  Z^^O$$E(ELLSQQR *..!233 +GLL	**  ##Z^^%&&4*;;C@@A  011 *GLL))  0/M///33o333
 
 

 
 
	 	 	, , ,  , , ,2 2 2 2 2 2r   