
u^!                 @   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 Gd
 d   d e  Z Gd d   d e  Z Gd d   d  Z Gd 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-8lau8j11/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                   s   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	 d d  Z
 e d d    Z e d d    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   sW   t  j j t  } | sD | 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_moduledescr   r   r   _setup0   s    zLazySettings._setupc             C   s'   |  j  t k r d Sd 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                sF   | 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   s}   |  j  t k	 r t d   t |  } xF | j   D]8 \ } } | j   s\ t d |   t | | |  q4 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   sc   t  j   } | d \ } } } } | j t j j t j   sV 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)r   r   r   r   r    r"   r&   r*   r,   r   r5   propertyr6   r9   r   r   )r+   r   r   *   s   r   c               @   s4   e  Z d  Z d d   Z d d   Z d d   Z d S)r   c             C   s  x9 t  t  D]+ } | j   r t |  | t t |   q W| |  _ t j |  j  } d } t   |  _	 x t  |  D]s } | j   rv t | |  } | | k r t
 | t t f  r t d |   t |  | |  |  j	 j |  qv W|  j st d   |  j d  r!t j t t  t t d  r|  j rt 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)rH   rI   rJ   ) 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   rK   )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)rQ   )r   r\   r   r   r   rV      s    zSettings.is_overriddenc             C   s   d d |  j  j d |  j i 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   rV   r"   r   r   r   r   r      s   -r   c                   s|   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   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)rP   r$   r3   )r   r3   r   r   r   r      s    zUserSettingsHolder.__init__c             C   s2   | 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                sC   |  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                s3   |  j  j |  t |  |  r/ t   j |  d  S)N)r_   rU   rW   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$   rM   r3   )r   r   )r   r   __dir__   s    zUserSettingsHolder.__dir__c             C   sO   | |  j  k } | |  j k } t |  j d d d    |  } | pN | pN | S)NrV   c             S   s   d S)NFr   )rc   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   rV      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,   rf   rV   r"   r   r   )r+   r   r.      s   r.   )r   rN   r   rX   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