U
    a"                     @   sB   d dl Z d dlmZ d dlmZ d dlmZ dZG dd dZdS )    N)import_module)ImproperlyConfigured)module_has_submodulemodelsc                   @   sX   e Zd ZdZdd Z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   sh   || _ || _d | _t| ds,|dd | _t| dsB| j | _t| dsX| || _	d | _
d | _d S )Nlabel.   verbose_namepath)namemoduleappshasattr
rpartitionr   titler
   _path_from_moduler   models_moduler   )selfapp_name
app_module r   /home/adriano.carvalho/ftp/files/BrinquedotecaVirtual/brinquedotecavirtual/venv/lib/python3.8/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__3   s    zAppConfig.__repr__c                 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|s|td|f |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   6   s&    zAppConfig._path_from_modulec           
   
   C   sp  zt |}W n. tk
r:   d}|d\}}}|s6 Y n<X z
|j}W n tk
rd   | || Y S X |d\}}}t |}zt||} W n\ tk
r   |dkrtdd |j D }|rt	d||d
|f t | n Y nX t| tst	d| z
| j}W n" tk
r.   t	d| Y nX zt |}	W n( tk
rd   t	d	|||f Y nX | ||	S )
zU
        Factory that creates an app config from an entry in INSTALLED_APPS.
        Nr   c                 s   s6   | ].\}}t |trt|tr|tk	rt|V  qd S )N)
isinstancetype
issubclassr   repr).0r   	candidater   r   r   	<genexpr>}   s
   

z#AppConfig.create.<locals>.<genexpr>z4'%s' does not contain a class '%s'. Choices are: %s.z, 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   ImportErrorr   Zdefault_app_configAttributeErrorr"   sorted__dict__itemsr   joinr+   r   r   )
clsentryr   Zmod_path_Zcls_namemod
candidatesr   r   r   r   r   createQ   sb    



  
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   r<   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   
__module____qualname____doc__r   r   r   classmethodr;   r@   rC   rE   rF   r   r   r   r   r   
   s   &
U

	r   )	r$   	importlibr   Zdjango.core.exceptionsr   Zdjango.utils.module_loadingr   rD   r   r   r   r   r   <module>   s
   