U
    |®cö3  ã                   @   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,| d¡d | _| j ¡ sDtd| j ƒ‚t| dƒsZ| j ¡ | _	t| dƒsp|  
|¡| _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   ú6/tmp/pip-unpacked-wheel-7m9rsep5/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 |¡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__Nz�The app module %r has multiple filesystem locations (%r); you must configure this app with an AppConfig subclass with a 'path' class attribute.zƒThe 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}zt |ƒ}W n tk
r2   Y �n`X t|tƒ�rd|tf }t |ƒ}‡ fdd„t |tj¡D ƒ}t|ƒdkrž|d d }d||d d f }nndd„ |D ƒ}t|ƒdkrÞdd„ |D ƒ}	td	|d
 	|	¡f ƒ‚n.t|ƒdk�r|d d }d||d d f }z
|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�rÀzt|ƒ}W n tk
�r¾   Y nX |dk�rR|dk�rR| d¡\}}}|�rJ|d  ¡ �rJt |ƒ}‡ fdd„t |tj¡D ƒ}	d||f }|	�r@|dd
 	|	¡ 7 }t|ƒ‚nt |ƒ t|tƒ�sjtd| ƒ‚|dk�r¢z
|j}W n" tk
�r    td| ƒ‚Y nX z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.
        Nú%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 )r1   F)r)   r3   r   r   r   r8   Ž   s   þc                 S   s   g | ]\}}t |ƒ‘qS r   )Úrepr)r4   r   Ú_r   r   r   r8   ”   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.zÚHowever, 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   )r2   r9   r3   r6   r   r   r8   Õ   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ÚImportErrorr2   r
   r   r   Ú
__module__Ú__qualname__)r7   ÚentryZapp_config_classZapp_config_namer   r   Zmod_pathÚmodZapp_configsÚ
candidatesZ	new_entryÚmessager:   Zcls_nameÚmsgr   r6   r   Úcreatec   s¶    
þ	þÿÿ



ÿ
ÿÿùÿ

þ
ÿ

ÿ
ýÿ
	zAppConfig.createTc                 C   sV   |r| j  ¡  n
| j  ¡  z| j| ¡  W S  tk
rP   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   s@   | j  ¡  | j ¡ D ]&}|jjr&|s&q|jjr4|s4q|V  q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   rP   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 )Nr0   )
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   rH   rI   Ú__doc__r   r!   r   r#   Úpropertyr$   r   ÚclassmethodrO   rT   rW   rY   rZ   r   r   r   r   r
      s   *


 

	r
   )r>   r+   rD   Ú	importlibr   Zdjango.core.exceptionsr   Zdjango.utils.deprecationr   Zdjango.utils.functionalr   Zdjango.utils.module_loadingr   r   r=   rX   r
   r   r   r   r   Ú<module>   s   