
    HR-eq+                         d Z ddlZddlZddlZddlmZ g dZd ZddZddZ	 G d	 d
          Z
 G d de
          Z G d de
          ZddZdS )zwThis module contains functions to determine where configuration and
data/cache files used by Astropy should be placed.
    Nwraps)get_config_dirget_cache_dirset_temp_configset_temp_cachec                  P   	 t           j                            d          } n# t          $ r t           j        dk    r1dt           j        v rt           j        d         } nt          d          t           j        dk    rpdt           j        v r3t           j                            d          rt           j        d         } n_dt           j        v rPdt           j        v rBt           j                            t           j        d         t           j        d                   } nd	t           j        v r0t           j                            t           j        d	                   } n	 d
dl	}d}|
                    |j        |          }|                    |d          d
         } |                                 np# t          $ r3 dt           j        v rt           j        d         } nt          d          Y n4w xY wdt           j        v rt           j        d         } nt          d          Y nw xY w| S )a'  Locates and return the home directory (or best approximation) on this
    system.

    Raises
    ------
    OSError
        If the home directory cannot be located - usually means you are running
        Astropy on some obscure platform that doesn't have standard home
        directories.
    ~posixHOMEzCCould not find unix home directory to search for astropy config dirntMSYSTEM	HOMEDRIVEHOMEPATHUSERPROFILEr   Nz@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell FoldersPersonalzFCould not find windows home directory to search for astropy config dirzfCould not find a home directory to search for astropy config dir - are you on an unsupported platform?)ospath
expanduser	ExceptionnameenvironOSErrorgetjoinwinregOpenKeyHKEY_CURRENT_USERQueryValueExClose)homedirwregshell_folderskeys       4lib/python3.11/site-packages/astropy/config/paths.py
_find_homer&      s   2'$$S)) 0 0 07g##*V,)   W__BJ&&2:>>&+A+A& *V,
**zRZ/G/G',,rz+'>
:@VWW"*,,',,rz-'@AA))))$gM,,t'=}MMC"//Z@@CGIIKKKK    ++"$*V"4%<     ##*V,   Y0b Ns5   # D:H#AF0/H#0:G-*H#,G--3H#"H#astropyc                    d}t           j        ~t           j        }t          j                            ||           }t          j                            |          st          j        |           t          j                            |          S t          j        	                    d          }|t          j                            |          rt          j                            ||           }t          j        
                    |          s@t          j                            |          rt          j                            |          S |}t          j                            t          d||                     S )a  
    Determines the package configuration directory name and creates the
    directory if it doesn't exist.

    This directory is typically ``$HOME/.astropy/config``, but if the
    XDG_CONFIG_HOME environment variable is set and the
    ``$XDG_CONFIG_HOME/astropy`` directory exists, it will be that directory.
    If neither exists, the former will be created and symlinked to the latter.

    Parameters
    ----------
    rootname : str
        Name of the root configuration directory. For example, if ``rootname =
        'pkgname'``, the configuration directory would be ``<home>/.pkgname/``
        rather than ``<home>/.astropy`` (depending on platform).

    Returns
    -------
    configdir : str
        The absolute path to the configuration directory.

    NXDG_CONFIG_HOMEconfig)r   
_temp_pathr   r   r   existsmkdirabspathr   r   islink_find_or_create_root_dir)rootnamelinktoxchconfig_pathxchpths        r%   r   r   O   s   0 F !-(gll311w~~k** 	"H[!!!w{+++ *..*
+
+C
27>>#..c8,,w~~f%% 	 w~~f%%  wv...7??3HfhOOPPP    c                    d}t           j        ~t           j        }t          j                            ||           }t          j                            |          st          j        |           t          j                            |          S t          j        	                    d          }|t          j                            |          rt          j                            ||           }t          j        
                    |          s@t          j                            |          rt          j                            |          S |}t          j                            t          d||                     S )a  
    Determines the Astropy cache directory name and creates the directory if it
    doesn't exist.

    This directory is typically ``$HOME/.astropy/cache``, but if the
    XDG_CACHE_HOME environment variable is set and the
    ``$XDG_CACHE_HOME/astropy`` directory exists, it will be that directory.
    If neither exists, the former will be created and symlinked to the latter.

    Parameters
    ----------
    rootname : str
        Name of the root cache directory. For example, if
        ``rootname = 'pkgname'``, the cache directory will be
        ``<cache>/.pkgname/``.

    Returns
    -------
    cachedir : str
        The absolute path to the cache directory.

    NXDG_CACHE_HOMEcache)r   r+   r   r   r   r,   r-   r.   r   r   r/   r0   )r1   r2   r3   
cache_pathr5   s        r%   r   r   ~   s   0 F  ,'W\\#x00
w~~j)) 	!HZ   wz*** *..)
*
*C
27>>#..c8,,w~~f%% 	 w~~f%%  wv...7??3GVXNNOOOr6   c                   0    e Zd ZdZdZddZd Zd Zd ZdS )_SetTempPathNFc                     |t           j                            |          }|| _        || _        | j        j        | _        d S N)r   r   r.   _path_delete	__class__r+   
_prev_path)selfr   deletes      r%   __init__z_SetTempPath.__init__   s9    7??4((D
.3r6   c                     | j         | j        _        	 |                     d          S # t          $ r | j        | j        _         w xY w)Nr'   )r?   rA   r+   _default_path_getterr   rB   )rC   s    r%   	__enter__z_SetTempPath.__enter__   sQ    $(J!	,,Y777 	 	 	(,DN%	s	   ( Ac                 ~    | j         | j        _        | j        r"| j        t          j        | j                   d S d S d S r>   )rB   rA   r+   r@   r?   shutilrmtree)rC   argss     r%   __exit__z_SetTempPath.__exit__   sG    $(O!< 	&DJ2M$*%%%%%	& 	&22r6   c                 @     t                     fd            }|S )zImplements use as a decorator.c                  N    5   | i | d d d            d S # 1 swxY w Y   d S r>    )rL   kwargsfuncrC   s     r%   wrapperz&_SetTempPath.__call__.<locals>.wrapper   s     & &d%f%%%& & & & & & & & & & & & & & & & & &s   	r   )rC   rR   rS   s   `` r%   __call__z_SetTempPath.__call__   s;     
t	& 	& 	& 	& 	& 
	& r6   )NF)	__name__
__module____qualname__r+   rG   rE   rH   rM   rT   rP   r6   r%   r<   r<      s`        J4 4 4 4  & & &    r6   r<   c                   B     e Zd ZdZ ee          Z fdZ fdZ xZ	S )r   a  
    Context manager to set a temporary path for the Astropy config, primarily
    for use with testing.

    If the path set by this context manager does not already exist it will be
    created, if possible.

    This may also be used as a decorator on a function to set the config path
    just within that function.

    Parameters
    ----------
    path : str, optional
        The directory (which must exist) in which to find the Astropy config
        files, or create them if they do not already exist.  If None, this
        restores the config path to the user's default config path as returned
        by `get_config_dir` as though this context manager were not in effect
        (this is useful for testing).  In this case the ``delete`` argument is
        always ignored.

    delete : bool, optional
        If True, cleans up the temporary directory after exiting the temp
        context (default: False).
    c                     ddl m} |                                | _        |                                 t                                                      S N   )_cfgobjs)configurationr\   copy_cfgobjs_copyclearsuperrH   )rC   r\   rA   s     r%   rH   zset_temp_config.__enter__   sM    
 	,+++++%]]__ww  """r6   c                     ddl m} |                                 |                    | j                   | ` t                      j        |  d S rZ   )r]   r\   r`   updater_   ra   rM   )rC   rL   r\   rA   s      r%   rM   zset_temp_config.__exit__   sZ    ++++++*+++$r6   )
rU   rV   rW   __doc__staticmethodr   rG   rH   rM   __classcell__)rA   s   @r%   r   r      sm         2 (<77	# 	# 	# 	# 	#                 r6   r   c                   (    e Zd ZdZ ee          ZdS )r   a.  
    Context manager to set a temporary path for the Astropy download cache,
    primarily for use with testing (though there may be other applications
    for setting a different cache directory, for example to switch to a cache
    dedicated to large files).

    If the path set by this context manager does not already exist it will be
    created, if possible.

    This may also be used as a decorator on a function to set the cache path
    just within that function.

    Parameters
    ----------
    path : str
        The directory (which must exist) in which to find the Astropy cache
        files, or create them if they do not already exist.  If None, this
        restores the cache path to the user's default cache path as returned
        by `get_cache_dir` as though this context manager were not in effect
        (this is useful for testing).  In this case the ``delete`` argument is
        always ignored.

    delete : bool, optional
        If True, cleans up the temporary directory after exiting the temp
        context (default: False).
    N)rU   rV   rW   rd   re   r   rG   rP   r6   r%   r   r     s,         6 (<66r6   r   c           	          t           j                            t                      d|           }t           j                            t                      d| |           }t           j                            |          s9t           j                            |          sF	 t          j        |           nh# t          $ r# t           j                            |          s Y n<w xY wt           j                            |          st          d| d|  d| d          	 t          j        |           n0# t          $ r# t           j                            |          s Y nw xY wt          j	        
                    d          s6|4t           j                            |          st          j        ||           n8t           j                            |          st          d| d|  d| d          t           j                            |          S )N.z	Intended  z directory z is actually a file.win)r   r   r   r&   r,   r-   r   isdirsysplatform
startswithsymlinkr.   )dirnmr2   pkgnameinnerdirmaindirs        r%   r0   r0   "  s	   w||JLL-g--88Hgll:<<W>>G7>>'"" 
w~~h'' 		""""   w}}X..   x(( 	UGUUeUUUUU  	HW 	 	 	7==))  	
 ''..	("GNN6** # Jw'''W]]7## 
QQQ%QQGQQQ
 
 	
 7??7###s$    B5 5*C"!C"D3 3*E E )r'   )rd   r   rJ   rm   	functoolsr   __all__r&   r   r   r<   r   r   r0   rP   r6   r%   <module>rw      s'    
			  



      
R
R
R> > >B,Q ,Q ,Q ,Q^-P -P -P -P`" " " " " " " "J-  -  -  -  - l -  -  - `7 7 7 7 7\ 7 7 7>#$ #$ #$ #$ #$ #$r6   