3
g3                 @   sr   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
 d dlmZmZ dZdZG d	d
 d
ZdS )    N)import_module)ImproperlyConfigured)RemovedInDjango41Warning)cached_property)import_stringmodule_has_submoduleappsmodelsc               @   sp   e Zd ZdZdd Zdd Zedd Zedd	 Z	d
d Z
edd ZdddZdddZdd Zdd ZdS )	AppConfigz>Class representing a Django application and its configuration.c             C   s   || _ || _d | _t| ds,|jdd | _| jj sDtd| j t| dsZ| jj | _	t| dsp| j
|| _d | _d | _d S )Nlabel.   z4The app label '%s' is not a valid Python identifier.verbose_namepath)namemoduler   hasattr
rpartitionr   isidentifierr   titler   _path_from_moduler   models_moduler	   )selfapp_name
app_module r   P/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/apps/config.py__init__   s    



zAppConfig.__init__c             C   s   d| j j| jf S )Nz<%s: %s>)	__class____name__r   )r   r   r   r   __repr__<   s    zAppConfig.__repr__c             C   s   ddl m} |jS )Nr   )settings)Zdjango.confr!   ZDEFAULT_AUTO_FIELD)r   r!   r   r   r   default_auto_field?   s    zAppConfig.default_auto_fieldc             C   s   | j jtjk	S )N)r   r"   r
   )r   r   r   r   !_is_default_auto_field_overriddenD   s    z+AppConfig._is_default_auto_field_overriddenc             C   s   t t|dg }t|dkrLt|dd}|dk	r@tjj|g}nt t|}t|dkrjtd||f n|sztd| |d S )z;Attempt to determine app's filesystem path from its module.__path__   __file__NzThe app module %r has multiple filesystem locations (%r); you must configure this app with an AppConfig subclass with a 'path' class attribute.zThe app module %r has no filesystem location, you must configure this app with an AppConfig subclass with a 'path' class attribute.r   )listgetattrlenosr   dirnamesetr   )r   r   pathsfilenamer   r   r   r   H   s    zAppConfig._path_from_modulec          +      s  d}d}d}d}yt |}W n tk
r2   Y n`X t|trd|tf }t |} fddtj|tjD }t|dkr|d d }d||d d f }nndd |D }t|dkrdd |D }	td	|d
j	|	f n.t|dkr|d d }d||d d f }y
|j
}
W n( tk
r>   |dkr: }|}Y nTX d||
f }|
|kr`|d7 }n|d|rrd| nd 7 }tj|tdd |
}d}|dkryt|}W n tk
r   Y nX |dkrR|dkrR|jd\}}}|rJ|d j rJt |} fddtj|tjD }	d||f }|	r@|dd
j	|	 7 }t|nt | t|tsjtd| |dkry
|j}W n" tk
r   td| Y nX yt |}W n, tk
r   td||j|jf Y nX |||S )zU
        Factory that creates an app config from an entry in INSTALLED_APPS.
        Nz%s.%sc                s6   g | ].\}}t | r| k	rt|d dr||fqS )defaultT)
issubclassr(   ).0r   	candidate)clsr   r   
<listcomp>   s   
z$AppConfig.create.<locals>.<listcomp>r%   r   c             S   s$   g | ]\}}t |d dr||fqS )r/   F)r(   )r1   r   r2   r   r   r   r4      s   c             S   s   g | ]\}}t |qS r   )repr)r1   r   _r   r   r   r4      s    z0%r declares more than one default AppConfig: %s.z, z$%r defines default_app_config = %r. zWDjango now detects this configuration automatically. You can remove default_app_config.zHowever, Django's automatic detection %s. You should move the default config class to the apps submodule of your application and, if this module defines several config classes, mark the default one with default = True.z picked another configuration, %rzdid not find this configurationr   )
stacklevelr   c                s*   g | ]"\}}t | r| k	rt|qS r   )r0   r5   )r1   r   r2   )r3   r   r   r4      s   z*Module '%s' does not contain a '%s' class.z Choices are: %s.z#'%s' isn't a subclass of AppConfig.z"'%s' must supply a name attribute.z7Cannot import '%s'. Check that '%s.%s.name' is correct.)r   	Exceptionr   APPS_MODULE_NAMEinspect
getmembersisclassr)   RuntimeErrorjoinZdefault_app_configAttributeErrorwarningswarnr   r   r   isupperImportErrorr0   r
   r   r   
__module____qualname__)r3   entryZapp_config_classZapp_config_namer   r   Zmod_pathmodZapp_configs
candidatesZ	new_entrymessager6   Zcls_namemsgr   )r3   r   createc   s    










zAppConfig.createTc             C   sT   |r| j j  n
| j j  y| j|j  S  tk
rN   td| j|f Y nX dS )z
        Return the model with the given case-insensitive model_name.

        Raise LookupError if no model exists with this name.
        z#App '%s' doesn't have a '%s' model.N)r   check_models_readyZcheck_apps_readyr	   lowerKeyErrorLookupErrorr   )r   Z
model_nameZrequire_readyr   r   r   	get_model  s    
zAppConfig.get_modelFc             c   sH   | j j  x8| jj D ]*}|jjr*| r*q|jjr:| r:q|V  qW dS )a  
        Return an iterable of models.

        By default, the following models aren't included:

        - auto-created models for many-to-many relations without
          an explicit intermediate table,
        - models that have been swapped out.

        Set the corresponding keyword argument to True to include such models.
        Keyword arguments aren't documented; they're a private API.
        N)r   rL   r	   valuesZ_metaZauto_createdZswapped)r   Zinclude_auto_createdZinclude_swappedmodelr   r   r   
get_models  s    
zAppConfig.get_modelsc             C   s8   | j j| j | _t| jtr4d| jtf }t|| _	d S )Nz%s.%s)
r   Z
all_modelsr   r	   r   r   MODELS_MODULE_NAMEr   r   r   )r   Zmodels_module_namer   r   r   import_models&  s    zAppConfig.import_modelsc             C   s   dS )zT
        Override this method in subclasses to run code when Django starts.
        Nr   )r   r   r   r   ready/  s    zAppConfig.readyN)T)FF)r   rD   rE   __doc__r   r    r   r"   propertyr#   r   classmethodrK   rP   rS   rU   rV   r   r   r   r   r
      s   * 

	r
   )r:   r*   r@   	importlibr   Zdjango.core.exceptionsr   Zdjango.utils.deprecationr   Zdjango.utils.functionalr   Zdjango.utils.module_loadingr   r   r9   rT   r
   r   r   r   r   <module>   s   