
1!V                 @   s   d  d l  Z  d  d l Z d  d l m Z d d l m Z Gd d   d e  Z Gd d   d e  Z	 Gd	 d
   d
 e j
 e	   Z d S)    N)ImproperlyConfigured   )import_attributec               @   s7   e  Z d  Z d d d  Z d d   Z d d   Z d S)AppConfOptionsNc             C   sg   | |  _  t | d d  |  _ t |  j  |  _ t | d d  |  _ t | d g   |  _ i  |  _ d  S)Nholderzdjango.conf.settingsproxyFrequired)prefixgetattrholder_pathr   r   r   r   configured_data)selfmetar	    r   6/tmp/pip-build-0sboevxh/django-appconf/appconf/base.py__init__   s    	zAppConfOptions.__init__c             C   s9   | j  |  j j    r | Sd |  j j   | j   f S)Nz%s_%s)
startswithr	   upper)r   namer   r   r   prefixed_name   s    zAppConfOptions.prefixed_namec             C   s   |  | _  i  |  _ i  |  _ d  S)N)_metanamesdefaults)r   clsr   r   r   r   contribute_to_class   s    		z"AppConfOptions.contribute_to_class)__name__
__module____qualname__r   r   r   r   r   r   r   r   
   s   r   c                   s:   e  Z d  Z   f d d   Z d d   Z d d   Z   S)AppConfMetaClassc                s  t  t |   j } d d   | D } | s> | |  | | |  S| j d  } | |  | | i | d 6 } | j d d   } | r | }	 n' t d t f i   } t | d d   }	 t |	 d t |	 d d    }
 |
 d  k rt j | j	 } | j
 j d  d }
 n  | j d	 t |	 |
   | j d |  xx | d  d  d  D]c } t | d	  rA| j j j | j j  | j j j | j j  | j j j | j j  qAqAWxa t t j t | j     D]A } | j j |  } | | j j | <| j |  | j j | <qWx* | j   D] \ } } | j | |  qW| j   x[ t j | j j  D]D \ } } | j j |  } t | j j | |  | j | |  qYWxN | j j  D]@ } | j j |  } t | j j |  st! d |   qqW| S)Nc             S   s%   g  |  ] } t  | t  r |  q Sr   )
isinstancer   ).0br   r   r   
<listcomp>#   s   	 z,AppConfMetaClass.__new__.<locals>.<listcomp>r   ZMetar	   Z	app_label.   r   r   z#The required setting %s is missing.)"superr   __new__poptypeobjectr
   sysmodulesr   r   splitadd_to_classr   hasattrr   r   updater   r   filterstrisupperlistkeysr   items
_configuresix	iteritemssetattrr   r   r   )r   r   basesattrsZ	super_newparentsmodule	new_classZ	attr_metar   r	   Zmodel_moduleparentr   value)	__class__r   r   r(   !   sP    	%
"zAppConfMetaClass.__new__c             C   s6   t  | d  r" | j |  |  n t |  | |  d  S)Nr   )r0   r   r;   )r   r   rB   r   r   r   r/   Z   s    zAppConfMetaClass.add_to_classc             C   s   |    } x t  j | j j  D] \ } } | j j j |  } t | j j | |  } t | d | j   d   } t	 |  r | |  } n  | |  j j
 | <q W| j   |  j _
 d  S)Nzconfigure_%s)r9   r:   r   r   r   getr
   r   lowercallabler   	configure)r   objr   r   default_valuerB   callbackr   r   r   r8   `   s    	"zAppConfMetaClass._configure)r   r   r   r(   r/   r8   r   r   )rC   r   r      s   9r   c               @   sv   e  Z d  Z d Z d d   Z d d   Z e d d    Z e d d	    Z d
 d   Z	 d d   Z
 d d   Z d S)AppConfz~
    An app setting object to be used for handling app setting defaults
    gracefully and providing a nice API for them.
    c             K   s4   x- t  j |  D] \ } } t |  | |  q Wd  S)N)r9   r:   r;   )r   kwargsr   rB   r   r   r   r   r   s    zAppConf.__init__c             C   s"   t  t t |  j j j      S)N)sortedr5   setr   r   r6   )r   r   r   r   __dir__v   s    zAppConf.__dir__c             C   s
   |  j  j S)N)r   r   )r   r   r   r   r   z   s    zAppConf.configured_datac             C   s
   |  j    S)N)rO   )r   r   r   r   __members__   s    zAppConf.__members__c             C   s?   |  j  j r t |  j  j |  St d | |  j  j f   d  S)Nz%s not found. Use '%s' instead.)r   r   r
   r   AttributeErrorr   )r   r   r   r   r   __getattr__   s    zAppConf.__getattr__c             C   sN   | | j    k r7 t |  j j |  j j |  |  n  t j |  | |  d  S)N)r   r;   r   r   r   r+   __setattr__)r   r   rB   r   r   r   rS      s    zAppConf.__setattr__c             C   s   |  j  S)zx
        Hook for doing any extra configuration, returning a dictionary
        containing the configured data.
        )r   )r   r   r   r   rG      s    zAppConf.configureN)r   r   r   __doc__r   rO   propertyr   rP   rR   rS   rG   r   r   r   r   rK   m   s   rK   )r,   r9   Zdjango.core.exceptionsr   utilsr   r+   r   r*   r   with_metaclassrK   r   r   r   r   <module>   s   N