o
    2g                     @  sx   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ G d	d
 d
ZG dd dZdS )zAProvides the code to load PRAW's configuration file ``praw.ini``.    )annotationsN)Path)Lock)Any   )ClientExceptionc                   @  s$   e Zd Zd	ddZeZd
ddZdS )_NotSetreturnboolc                 C     dS )NF selfr   r   C/home/garg/my-data/venv/lib/python3.10/site-packages/praw/config.py__bool__      z_NotSet.__bool__strc                 C  r   )NNotSetr   r   r   r   r   __str__   r   z_NotSet.__str__N)r	   r
   r	   r   )__name__
__module____qualname__r   __nonzero__r   r   r   r   r   r      s    
r   c                   @  s   e Zd ZdZdZe Ze Ze	j
e	jdZed$dd	Zedd
d%ddZed&ddZ	d'd(ddZd)ddZddd*ddZd+d d!Zd"d# ZdS ),Configz7A class containing the configuration for a Reddit site.N)basicextendeditem
bool | strr	   r
   c                 C  s   t | tr| S |  dv S )N>   1onyestrue)
isinstancer
   lower)r   r   r   r   _config_boolean$   s   
zConfig._config_booleanconfig_interpolationr'   
str | Nonec                C  s   |dur| j |  }nd}tj|d}ttjt jj}dt	j
v r)tt	j
d }ndt	j
v r6tt	j
d }ndt	j
v rEtt	j
d d }nd}t|d dg}|dur]|dt|d  || || _dS )	z5Attempt to load settings from various praw.ini files.N)interpolationAPPDATAXDG_CONFIG_HOMEHOMEz.configzpraw.inir   )INTERPOLATION_LEVELconfigparserConfigParserr   sysmodulesr   __file__parentosenvironr   insertreadCONFIG)clsr'   interpolator_classconfig
module_diros_config_path	locationsr   r   r   _load_config*   s"   




zConfig._load_configr   c                 C  s   | j | ju rd}t|| j S )z]Return the short url.

        :raises: :class:`.ClientException` if it is not set.

        zNo short domain specified.)
_short_urlCONFIG_NOT_SETr   )r   msgr   r   r   	short_urlF   s   zConfig.short_url	site_namesettingsc                 K  s   t j t jdu r| j|d W d   n1 sw   Y  || _tt j|fi || _d | _ | _	| _
d | _ | _| _d | _ | _| _|   dS )z'Initialize a :class:`.Config` instance.Nr&   )r   LOCKr8   r?   	_settingsdictitemscustom	client_idclient_secret	oauth_url
reddit_urlrefresh_tokenredirect_uripassword
user_agentusername_initialize_attributes)r   rD   r'   rE   r   r   r   __init__R   s   
zConfig.__init__keyr   c                 C  s   | j | }| j |= |S N)rJ   )r   rV   valuer   r   r   _fetchf   s   
zConfig._fetchdefaultr[   bool | float | str | Nonec                C  s   || j vr|S | |S rW   )rJ   rY   )r   rV   r[   r   r   r   _fetch_defaultk   s   

zConfig._fetch_defaultAny | _NotSetc                 C  s<   || j v r
| |S td| }| |}|p|p| jS )Npraw_)rG   rY   r4   getenvr]   rA   )r   rV   	env_value	ini_valuer   r   r   _fetch_or_not_setr   s
   


zConfig._fetch_or_not_setc                   s0    dp j _  j ddd _  d _  j ddd _  j ddd _ j dd	d _	 fd
ddD  _
dD ]}t | | qGdD ]}t | | qUttd D ]-\}}zt ||t | W qh ty   d| d|j dt | d}t|d w d S )NrC   check_for_asyncTrZ   check_for_updateswarn_comment_sortwarn_additional_fetch_paramswindow_sizeiX  c                   s   i | ]}|  | d qS )_kind)rY   ).0xr   r   r   
<dictcomp>   s    z1Config._initialize_attributes.<locals>.<dictcomp>)commentmessageredditor
submission	subreddittrophy)rK   rL   rP   rO   rQ   rR   rS   )rM   ratelimit_secondsrN   timeout)rs   rt   z.An incorrect config type was given for option z. The expected type is z, but the given value is .)r]   rA   r@   r%   rd   rc   re   rf   rg   rh   kindssetattrrY   intrI   getattr
ValueErrorr   )r   	attributerequired_attribute
conversionrB   r   r   r   rT   |   sB   
	
 
zConfig._initialize_attributes)r   r   r	   r
   )r'   r(   r   rW   )rD   r   r'   r(   rE   r   )rV   r   r	   r   )rV   r   r[   r\   r	   r   )rV   r   r	   r^   )r   r   r   __doc__r8   r   rA   r   rF   r.   BasicInterpolationExtendedInterpolationr-   staticmethodr%   classmethodr?   propertyrC   rU   rY   r]   rc   rT   r   r   r   r   r      s*    


r   )r~   
__future__r   r.   r4   r0   pathlibr   	threadingr   typingr   
exceptionsr   r   r   r   r   r   r   <module>   s    
