3
W­E^Ë!  ã               @   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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)ÚRemovedInDjango31Warning)Ú
LazyObjectÚemptyZDJANGO_SETTINGS_MODULEzqThe FILE_CHARSET setting is deprecated. Starting with Django 3.1, all files read from disk must be UTF-8 encoded.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 j| |ƒS )N)ÚstrÚ__new__)ÚselfÚvalueÚsetting_name© r   ú6/tmp/pip-build-78s3knkw/Django/django/conf/__init__.pyr
   #   s    zSettingsReference.__new__c             C   s
   || _ d S )N)r   )r   r   r   r   r   r   Ú__init__&   s    zSettingsReference.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   r   r      s   r   c                   sj   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‡  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jtƒ}|s0|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Úsettingsz™Requested %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_moduleÚdescr   r   r   Ú_setup0   s    zLazySettings._setupc             C   s   | j tk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__A   s    
zLazySettings.__repr__c             C   s.   | j tkr| j|ƒ t| j |ƒ}|| j|< |S )z<Return the value of a setting and cache it in self.__dict__.)r   r   r    ÚgetattrÚ__dict__)r   r   Úvalr   r   r   Ú__getattr__I   s
    


zLazySettings.__getattr__c                s4   |dkr| j jƒ  n| j j|dƒ tƒ j||ƒ 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*   Q   s    zLazySettings.__setattr__c                s   t ƒ j|ƒ | jj|dƒ dS )z3Delete a setting and clear it from cache if needed.N)r)   Ú__delattr__r$   r(   )r   r   )r+   r   r   r,   \   s    zLazySettings.__delattr__c             K   sZ   | j tk	rtdƒ‚t|ƒ}x4|jƒ D ](\}}|jƒ s@td| ƒ‚t|||ƒ q$W || _ 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   Ú	configurea   s    
zLazySettings.configurec             C   s
   | j tk	S )z9Return True if the settings have already been configured.)r   r   )r   r   r   r   Ú
configuredp   s    zLazySettings.configuredc             C   sF   t jƒ }|d \}}}}|jtjjtjƒƒs<tj	t
tdd� | jdƒS )Né   )Ú
stacklevelÚFILE_CHARSETéþÿÿÿ)Ú	tracebackÚextract_stackÚ
startswithr   ÚpathÚdirnameÚdjangoÚ__file__ÚwarningsÚwarnÚFILE_CHARSET_DEPRECATED_MSGr   r&   )r   ÚstackÚfilenameZ_line_numberZ_function_nameZ_textr   r   r   r9   u   s    zLazySettings.FILE_CHARSET)N)r   r   r   r   r    r"   r&   r*   r,   r   r5   Úpropertyr6   r9   Ú__classcell__r   r   )r+   r   r   *   s   
r   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )r   c             C   s6  x*t tƒD ]}|jƒ r
t| |tt|ƒƒ q
W || _tj| jƒ}d}tƒ | _	x^t |ƒD ]R}|jƒ rTt||ƒ}||krŽt
|ttfƒ rŽtd| ƒ‚t| ||ƒ | j	j|ƒ qTW | js¸tdƒ‚| jdƒrÎtjttƒ ttdƒoÜ| j�r2tdƒ}|j| jjd	ƒŽ }|jƒ �r|jƒ  �rtd
| j ƒ‚| jtjd< tjƒ  d S )NÚINSTALLED_APPSÚTEMPLATE_DIRSÚLOCALE_PATHSz*The %s setting must be a list or a tuple. z)The SECRET_KEY setting must not be empty.r9   Útzsetz/usr/share/zoneinfoú/zIncorrect timezone setting: %sZTZ)rI   rJ   rK   ) Údirr   r0   r2   r#   r!   Ú	importlibÚimport_moduleÚsetÚ_explicit_settingsÚ
isinstanceÚlistÚtupler   ÚaddZ
SECRET_KEYÚis_overriddenrB   rC   rD   r   ÚhasattrÚtimeZ	TIME_ZONEr   ZjoinpathÚsplitÚexistsÚ
ValueErrorr   r   rL   )r   r   ÚsettingÚmodZtuple_settingsZsetting_valueZzoneinfo_rootZzone_info_filer   r   r   r   …   s8      

zSettings.__init__c             C   s
   || j kS )N)rR   )r   r]   r   r   r   rW   ²   s    zSettings.is_overriddenc             C   s   d| j j| jdœ S )Nz<%(cls)s "%(settings_module)s">)Úclsr   )r+   r   r!   )r   r   r   r   r"   µ   s    zSettings.__repr__N)r   r   r   r   rW   r"   r   r   r   r   r   „   s   -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 )r.   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)rQ   r$   r3   )r   r3   r   r   r   r   Â   s    zUserSettingsHolder.__init__c             C   s$   |j ƒ  s|| jkrt‚t| j|ƒS )N)r0   r`   ÚAttributeErrorr#   r3   )r   r   r   r   r   r&   Ê   s    zUserSettingsHolder.__getattr__c                s2   | j j|ƒ |dkr tjttƒ tƒ j||ƒ d S )Nr9   )r`   ÚdiscardrB   rC   rD   r   r)   r*   )r   r   r   )r+   r   r   r*   Ï   s    zUserSettingsHolder.__setattr__c                s&   | j j|ƒ t| |ƒr"tƒ j|ƒ d S )N)r`   rV   rX   r)   r,   )r   r   )r+   r   r   r,   Õ   s    
zUserSettingsHolder.__delattr__c                s"   t ‡ fdd„ˆ jtˆ jƒ•D ƒƒS )Nc             3   s   | ]}|ˆ j kr|V  qd S )N)r`   )Ú.0Ús)r   r   r   ú	<genexpr>Ü   s    z-UserSettingsHolder.__dir__.<locals>.<genexpr>)Úsortedr$   rN   r3   )r   r   )r   r   Ú__dir__Ú   s    zUserSettingsHolder.__dir__c             C   s6   || j k}|| jk}t| jddd„ ƒ|ƒ}|p4|p4|S )NrW   c             S   s   dS )NFr   )rd   r   r   r   Ú<lambda>ã   s    z2UserSettingsHolder.is_overridden.<locals>.<lambda>)r`   r$   r#   r3   )r   r]   ZdeletedZset_locallyZset_on_defaultr   r   r   rW   à   s    

z UserSettingsHolder.is_overriddenc             C   s   dd| j ji S )Nz	<%(cls)s>r_   )r+   r   )r   r   r   r   r"   æ   s    zUserSettingsHolder.__repr__)r   r   r   r   r!   r   r&   r*   r,   rg   rW   r"   rH   r   r   )r+   r   r.   ¼   s   r.   )r   rO   r   rY   r;   rB   Zpathlibr   r@   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.utils.deprecationr   Zdjango.utils.functionalr   r   r   rD   r	   r   r   r   r.   r   r   r   r   r   Ú<module>   s$   Z80