o
    [hQ&                     @   s   d Z ddlZddlZddlZddlZddlZddlm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mZ dZd	Zd
ZdZG dd deZG dd deZG dd dZG dd dZe ZdS )z
Settings and configuration for Django.

Read values from the module specified by the DJANGO_SETTINGS_MODULE environment
variable, and then from django.conf.global_settings; see the global_settings.py
for a list of all possible variables.
    N)Path)global_settings)ImproperlyConfigured)RemovedInDjango60Warning)
LazyObjectemptyZDJANGO_SETTINGS_MODULEdefaultZstaticfileszCThe FORMS_URLFIELD_ASSUME_HTTPS transitional setting is deprecated.c                   @   s    e Zd ZdZdd Zdd ZdS )SettingsReferencez
    String subclass which references a current settings value. It's treated as
    the value in memory but serializes to a settings.NAME attribute reference.
    c                 C   s   t | |S N)str__new__selfvaluesetting_name r   {/home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/django/conf/__init__.pyr   &   s   zSettingsReference.__new__c                 C   s
   || _ d S r
   )r   r   r   r   r   __init__)      
zSettingsReference.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r	       s    r	   c                       sr   e Zd ZdZdddZdd Zdd Z fd	d
Z fddZe	fddZ
edd Zedd Zdd Z  ZS )LazySettingsz
    A lazy proxy for either global Django settings or a custom settings object.
    The user can manually configure settings prior to using them. Otherwise,
    Django uses the settings module pointed to by DJANGO_SETTINGS_MODULE.
    Nc                 C   s>   t jt}|s|rd| nd}td|tf t|| _dS )z
        Load the settings module pointed to by the environment variable. This
        is used the first time settings are needed, if the user hasn't
        configured settings manually.
        z
setting %ssettingszRequested %s, but settings are not configured. You must either define the environment variable %s or call settings.configure() before accessing settings.N)osenvirongetENVIRONMENT_VARIABLEr   Settings_wrapped)r   namesettings_moduleZdescr   r   r   _setup4   s   zLazySettings._setupc                 C   s   | j tu rdS dd| j ji S )Nz<LazySettings [Unevaluated]>z$<LazySettings "%(settings_module)s">r"   )r    r   SETTINGS_MODULEr   r   r   r   __repr__F   s
   
zLazySettings.__repr__c                 C   sf   | j  }tu r| | | j }t||}|dv r"|dur"| |}n
|dkr,|s,td|| j|< |S )z<Return the value of a setting and cache it in self.__dict__.>   Z	MEDIA_URLZ
STATIC_URLNZ
SECRET_KEYz)The SECRET_KEY setting must not be empty.)r    r   r#   getattr_add_script_prefixr   __dict__)r   r!   r    valr   r   r   __getattr__N   s   


zLazySettings.__getattr__c                    s4   |dkr
| j   n| j |d t || dS )z
        Set the value of setting. Clear all cached values if _wrapped changes
        (@override_settings does this) or clear single values when set.
        r    N)r)   clearpopsuper__setattr__r   r!   r   	__class__r   r   r/   _   s   zLazySettings.__setattr__c                    s   t  | | j|d dS )z3Delete a setting and clear it from cache if needed.N)r.   __delattr__r)   r-   r   r!   r1   r   r   r3   j   s   zLazySettings.__delattr__c                 K   sV   | j tur	tdt|}| D ]\}}| std| t||| q|| _ dS )z
        Called to manually configure the settings. The 'default_settings'
        parameter sets where to retrieve any unspecified values from (its
        argument must support attribute access (__getattr__)).
        zSettings already configured.zSetting %r must be uppercase.N)r    r   RuntimeErrorUserSettingsHolderitemsisupper	TypeErrorsetattr)r   default_settingsoptionsZholderr!   r   r   r   r   	configureo   s   

zLazySettings.configurec                 C   s(   |  dr| S ddlm} d| | f S )z
        Add SCRIPT_NAME prefix to relative paths.

        Useful when the app is being served at a subpath and manually prefixing
        subpath to STATIC_URL and MEDIA_URL in settings is inconvenient.
        )zhttp://zhttps:///r   )get_script_prefixz%s%s)
startswithZdjango.urlsr?   )r   r?   r   r   r   r(   ~   s   
	zLazySettings._add_script_prefixc                 C   s
   | j tuS )z9Return True if the settings have already been configured.)r    r   r%   r   r   r   
configured   s   
zLazySettings.configuredc                 C   sD   t  }|d \}}}}|tjtjs tj	||dd d S d S )N   )
stacklevel)
	tracebackextract_stackr@   r   pathdirnamedjango__file__warningswarn)r   messagecategorystackfilename_r   r   r   _show_deprecation_warning   s
   z&LazySettings._show_deprecation_warningr
   )r   r   r   r   r#   r&   r+   r/   r3   r   r=   staticmethodr(   propertyrA   rR   __classcell__r   r   r1   r   r   -   s    


r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )r   c                 C   s  t tD ]}| rt| |tt| q|| _t| j}d}t | _	t |D ](}| rOt||}||v rCt
|ttfsCtd| t| || | j	| q'| dr[ttt ttdr| jrtd}|j| jd }| r| std| j | jtjd< t  d S d S d S )	N)ZALLOWED_HOSTSZINSTALLED_APPSZTEMPLATE_DIRSZLOCALE_PATHSZSECRET_KEY_FALLBACKSz)The %s setting must be a list or a tuple.FORMS_URLFIELD_ASSUME_HTTPStzsetz/usr/share/zoneinfor>   zIncorrect timezone setting: %sZTZ)dirr   r8   r:   r'   r$   	importlibimport_moduleset_explicit_settings
isinstancelisttupler   addis_overriddenrK   rL   *FORMS_URLFIELD_ASSUME_HTTPS_DEPRECATED_MSGr   hasattrtimeZ	TIME_ZONEr   joinpathsplitexists
ValueErrorr   r   rW   )r   r"   settingmodZtuple_settingsZsetting_valueZzoneinfo_rootZzone_info_filer   r   r   r      sB   


zSettings.__init__c                 C   s
   || j v S r
   )r\   )r   ri   r   r   r   ra      r   zSettings.is_overriddenc                 C   s   d| j j| jd S )Nz<%(cls)s "%(settings_module)s">)clsr"   )r2   r   r$   r%   r   r   r   r&      s   zSettings.__repr__N)r   r   r   r   ra   r&   r   r   r   r   r      s    2r   c                       sX   e Zd ZdZdZdd Zdd Z fddZ fd	d
Zdd Z	dd Z
dd Z  ZS )r6   z$Holder for user configured settings.Nc                 C   s   t  | jd< || _dS )z
        Requests for configuration variables not in this class are satisfied
        from the module specified in default_settings (if possible).
        _deletedN)r[   r)   r;   )r   r;   r   r   r   r      s   
zUserSettingsHolder.__init__c                 C   s"   |  r	|| jv rtt| j|S r
   )r8   rl   AttributeErrorr'   r;   r4   r   r   r   r+      s   zUserSettingsHolder.__getattr__c                    s2   | j | |dkrttt t || d S )NrV   )rl   discardrK   rL   rb   r   r.   r/   r0   r1   r   r   r/      s   zUserSettingsHolder.__setattr__c                    s*   | j | t| |rt | d S d S r
   )rl   r`   rc   r.   r3   r4   r1   r   r   r3      s   
zUserSettingsHolder.__delattr__c                    s&   t  fddg  jt jD S )Nc                 3   s    | ]
}| j vr|V  qd S r
   )rl   ).0sr%   r   r   	<genexpr>   s    
z-UserSettingsHolder.__dir__.<locals>.<genexpr>)sortedr)   rX   r;   r%   r   r%   r   __dir__   s   zUserSettingsHolder.__dir__c                 C   s6   || j v }|| jv }t| jddd |}|p|p|S )Nra   c                 S   s   dS )NFr   )rp   r   r   r   <lambda>  s    z2UserSettingsHolder.is_overridden.<locals>.<lambda>)rl   r)   r'   r;   )r   ri   ZdeletedZset_locallyZset_on_defaultr   r   r   ra     s   

z UserSettingsHolder.is_overriddenc                 C   s   dd| j ji S )Nz	<%(cls)s>rk   )r2   r   r%   r   r   r   r&   
  s   zUserSettingsHolder.__repr__)r   r   r   r   r$   r   r+   r/   r3   rs   ra   r&   rU   r   r   r1   r   r6      s    	r6   )r   rY   r   rd   rE   rK   pathlibr   rI   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.utils.deprecationr   Zdjango.utils.functionalr   r   r   ZDEFAULT_STORAGE_ALIASZSTATICFILES_STORAGE_ALIASrb   r   r	   r   r   r6   r   r   r   r   r   <module>   s,    o=
7