
    ucu                     (   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ej                            d          pej                            edd          Zd eD             Zd eD             Z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.cacheXDG_STATE_HOMEstatec                     g | ]}||S  r   .0xs     3/usr/lib/python3/dist-packages/xdg/BaseDirectory.py
<listcomp>r   1   s    ///qQ////    c                     g | ]}||S r   r   r   s     r   r   r   2   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"   4   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(   L   l     w|X&H""3'''''7<<11D7== 
DKr   c                  
   t          j        j        |  } |                     d          rJ t           j                            t          |           }t           j                            |          st          j        |           |S )zEnsure ``$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    s     r   save_state_pathr,   W   r)   r   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_pathsr1   b   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)r1   )r!   r   s     r   load_first_configr3   l   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_pathsr7   s   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)strictr<   fallbackcreatesterI   s          r   get_runtime_dirrQ   |   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   r?   r   
expanduser_homer:   getr   r$   splitr5   r   r.   r'   r+   r"   r%   r(   r,   r1   r3   r7   rQ   r   r   r   <module>rW      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11 3GLL'22  0/M///33o333
 
 

 
 
	 	 		 	 	, , ,  , , ,2 2 2 2 2 2r   