
    hE                     |    S SK r S SKrS SKrS SKrS SKJrJr  S SK Jr  S SKJ	r	J
r
  SSKJr   " S S5      r\" SS	9rg)
    N)Counterdefaultdict)partial)AppRegistryNotReadyImproperlyConfigured   )	AppConfigc                       \ rS rSrSrSS jrSS jrS rS rS r	S	 r
\R                  SS
 j5       rSS jrS rS rS rS r\R                  S 5       rS rS rS rS rS rS rS rSrg)Apps   z
A registry that stores the configuration of installed applications.

It also keeps track of models, e.g. to provide reverse relations.
c                    Uc1  [        [        R                  [           S5      (       a  [	        S5      e[        [        5      U l        0 U l        / U l	        S=U l
        =U l        U l        [        R                  " 5       U l        [        R                   " 5       U l        SU l        [        [&        5      U l        Ub  U R+                  U5        g g )Nappsz+You must supply an installed_apps argument.F)hasattrsysmodules__name__RuntimeErrorr   dict
all_modelsapp_configsstored_app_configs
apps_readymodels_readyready	threadingEventready_eventRLock_lockloadinglist_pending_operationspopulate)selfinstalled_appss     F/var/www/html/env/lib/python3.13/site-packages/django/apps/registry.py__init__Apps.__init__   s     !gckk(.CV&L&LLMM &d+  #% <A@@$+dj$??, __&

 $/t#4  %MM.) &    Nc                 ,   U R                   (       a  gU R                     U R                   (       a
   SSS5        gU R                  (       a  [        S5      eSU l        U H  n[	        U[
        5      (       a  UnO[
        R                  " U5      nUR                  U R                  ;   a  [        SUR                  -  5      eX0R                  UR                  '   Xl
        M     [        S U R                  R                  5        5       5      nUR                  5        VVs/ s H  u  pVUS:  d  M  UPM     nnnU(       a  [        SSR                  U5      -  5      eSU l        U R                  R                  5        H  nUR!                  5         M     U R#                  5         SU l        U R'                  5        H  nUR                  5         M     SU l         U R(                  R+                  5         SSS5        gs  snnf ! , (       d  f       g= f)	z
Load application configurations and models.

Import each application module and then each model module.

It is thread-safe and idempotent, but not reentrant.
Nzpopulate() isn't reentrantTz0Application labels aren't unique, duplicates: %sc              3   8   #    U  H  oR                   v   M     g 7fNname).0
app_configs     r&   	<genexpr> Apps.populate.<locals>.<genexpr>f   s      2KJ2Ks   r   z/Application names aren't unique, duplicates: %s, )r   r   r    r   
isinstancer	   createlabelr   r   r   r   valuesmost_commonjoinr   import_modelsclear_cacher   get_app_configsr   set)r$   r%   entryr0   countsr.   count
duplicatess           r&   r#   Apps.populate=   s    :: ZZzz Z || ##?@@DL (eY//!&J!*!1!1%!8J##t'7'77.)+5+;+;< 
 6@  !1!12"& (  262B2B2I2I2K F 392D2D2FT2F;4%RS)$2FJT*%'+yy'<= 
 #DO #..557
((* 8  $D #224
  " 5 DJ  "k Z> U? Zs*   HC'H"G?2G?8B>H?H
Hc                 `    U R                   (       d  SSKJn  UR                    [	        S5      eg)z9Raise an exception if all apps haven't been imported yet.r   )settingszApps aren't loaded yet.N)r   django.confrD   INSTALLED_APPSr   )r$   rD   s     r&   check_apps_readyApps.check_apps_ready   s(    ,
 ##%&?@@ r)   c                 <    U R                   (       d  [        S5      eg)z;Raise an exception if all models haven't been imported yet.zModels aren't loaded yet.N)r   r   r$   s    r&   check_models_readyApps.check_models_ready   s      %&ABB !r)   c                 V    U R                  5         U R                  R                  5       $ )z:Import applications and return an iterable of app configs.)rG   r   r7   rJ   s    r&   r<   Apps.get_app_configs   s#    &&((r)   c                     U R                  5          U R                  U   $ ! [         aL    SU-  nU R                  5        H'  nUR                  U:X  d  M  USUR
                  -  -  n  O   [        U5      ef = f)z
Import applications and returns an app config for the given label.

Raise LookupError if no application exists with this label.
z!No installed app with label '%s'.z Did you mean '%s'?)rG   r   KeyErrorr<   r.   r6   LookupError)r$   	app_labelmessager0   s       r&   get_app_configApps.get_app_config   s     		'##I.. 	'9IEG"224
??i/4z7G7GGGG 5 g&&	's   ! 0A7"A7c                     U R                  5         / nU R                  R                  5        H#  nUR                  UR	                  X5      5        M%     U$ )a$  
Return a list of all installed 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.
)rK   r   r7   extend
get_models)r$   include_auto_createdinclude_swappedresultr0   s        r&   rX   Apps.get_models   sK     	!**113JMM*//0DVW 4r)   c                    U(       a  U R                  5         OU R                  5         Uc  UR                  S5      u  pU R                  U5      nU(       d  UR                  c  UR                  5         UR                  X#S9$ )ar  
Return the model matching the given app_label and model_name.

As a shortcut, app_label may be in the form <app_label>.<model_name>.

model_name is case-insensitive.

Raise LookupError if no application exists with this label, or no
model exists with this name in the application. Raise ValueError if
called with a single argument that doesn't contain exactly one dot.
.)require_ready)rK   rG   splitrT   modelsr:   	get_model)r$   rR   
model_namer_   r0   s        r&   rb   Apps.get_model   st     ##%!!#$-OOC$8!I((3
!2!2!:$$&##J#LLr)   c                    UR                   R                  nU R                  U   nX4;   az  UR                  XC   R                  :X  a@  UR                  XC   R                  :X  a$  [
        R                  " SU< SU< S3[        SS9  O[        SU< SU< SXC   < S	U< S3	5      eX$U'   U R                  U5        U R                  5         g )
NModel 'r^   z~' was already registered. Reloading models is not advised as it can lead to inconsistencies, most notably with related models.   )
stacklevelzConflicting 'z' models in application 'z': z and )_metarc   r   r   
__module__warningswarnRuntimeWarningr   do_pending_operationsr;   )r$   rR   modelrc   
app_modelss        r&   register_modelApps.register_model   s     [[++
__Y/
#*"8"A"AA$$
(>(I(II *3J@ #  #!9j.DeM  "':""5)r)   c                 ~   ^ U R                  5         [        U4S jU R                  R                  5        5       5      $ )z
Check whether an application with this name exists in the registry.

app_name is the full name of the app e.g. 'django.contrib.admin'.
c              3   @   >#    U  H  oR                   T:H  v   M     g 7fr,   r-   )r/   acapp_names     r&   r1   $Apps.is_installed.<locals>.<genexpr>   s     K1J277h&1Js   )rG   anyr   r7   )r$   rv   s    `r&   is_installedApps.is_installed   s1     	K1A1A1H1H1JKKKr)   c                 R   U R                  5         / nU R                  R                  5        Hb  nUR                  UR                  5      (       d  M%  UR                  UR                  5      nUS:X  d  US   S:X  d  MQ  UR                  U5        Md     U(       a  [        US S9S   $ g)z
Look for an app config containing a given object.

object_name is the dotted Python path to the object.

Return the app config for the inner application in case of nesting.
Return None if the object isn't in any registered app config.
 r   r^   c                 .    [        U R                  5      * $ r,   )lenr.   )ru   s    r&   <lambda>0Apps.get_containing_app_config.<locals>.<lambda>  s    c"''l]r)   )keyN)rG   r   r7   
startswithr.   removeprefixappendsorted)r$   object_name
candidatesr0   subpaths        r&   get_containing_app_configApps.get_containing_app_config   s     	
**113J%%joo66%22:??Cb=GAJ#$5%%j1	 4
 **BCAFF r)   c                     U R                   U   R                  UR                  5       5      nUc  [        SU< SU< S35      eU$ )z
Similar to get_model(), but doesn't require that an app exists with
the given app_label.

It's safe to call this method at import time, even while the registry
is being populated.
rf   r^   z' not registered.)r   getlowerrQ   )r$   rR   rc   ro   s       r&   get_registered_modelApps.get_registered_model  s@     	*..z/?/?/AB=JWXXr)   c                    UR                  5       nU R                  SS9 H  nUR                  R                  nU(       a,  UR                  5       U:X  a  UR                  R                  s  $ UR                  R                  (       d  Mi  UR                  R
                  U:X  d  M  UR                  R                  s  $    g)a  
For a given model string (e.g. "auth.User"), return the name of the
corresponding settings name if it refers to a swappable model. If the
referred model is not swappable, return None.

This method is decorated with @functools.cache because it's performance
critical when it comes to migrations. Since the swappable settings don't
change after Django has loaded the settings, there is no reason to get
the respective settings attribute over and over again.
T)rZ   N)r   rX   ri   swapped	swappablelabel_lower)r$   	to_stringro   r   s       r&   get_swappable_settings_name Apps.get_swappable_settings_name  s     OO%	__T_:Ekk))G7==?i7{{,,,{{$$$)@)@I)M{{,,, ; r)   c                    [        U5      nU R                  5        Vs1 s H  o"R                  iM     nnUR                  U5      (       d  [	        SSR                  X-
  5      -  5      eU R                  R                  U R                  5        U R                  R                  5        VVs0 s H  u  pBUR                  U;   d  M  XB_M     snnU l        U R                  5         gs  snf s  snnf )aD  
Restrict the set of installed apps used by get_app_config[s].

available must be an iterable of application names.

set_available_apps() must be balanced with unset_available_apps().

Primarily used for performance optimization in TransactionTestCase.

This method is safe in the sense that it doesn't trigger any imports.
z?Available apps isn't a subset of installed apps, extra apps: %sr3   N)r=   r<   r.   issubset
ValueErrorr9   r   r   r   itemsr;   )r$   	availabler0   	installedr6   s        r&   set_available_appsApps.set_available_apps2  s     	N	7;7K7K7MN7M__7M	N!!),,Q))I123 
 	&&t'7'78 &*%5%5%;%;%=
%=!)+ E%=

 	 O
s   C&,C+C+c                 b    U R                   R                  5       U l        U R                  5         g)z/Cancel a previous call to set_available_apps().N)r   popr   r;   rJ   s    r&   unset_available_appsApps.unset_available_appsN  s%    22668r)   c                    U R                   (       d  [        S5      eU R                  R                  U R                  5        0 U l        S=U l        =U l        =U l        U l         U R                  5         U R                  U5        g)a  
Enable a different set of installed apps for get_app_config[s].

installed must be an iterable in the same format as INSTALLED_APPS.

set_installed_apps() must be balanced with unset_installed_apps(),
even if it exits with an exception.

Primarily used as a receiver of the setting_changed signal in tests.

This method may trigger new imports, which may add new models to the
registry of all imported models. They will stay in the registry even
after unset_installed_apps(). Since it isn't possible to replay
imports safely (e.g. that could lead to registering listeners twice),
models are registered when they're imported and never removed.
zApp registry isn't ready yet.FN)
r   r   r   r   r   r   r   r    r;   r#   )r$   r   s     r&   set_installed_appsApps.set_installed_appsS  sn    " zz%&EFF&&t'7'78JOOO$+OdlTZi r)   c                     U R                   R                  5       U l        S=U l        =U l        U l        U R                  5         g)z/Cancel a previous call to set_installed_apps().TN)r   r   r   r   r   r   r;   rJ   s    r&   unset_installed_appsApps.unset_installed_appsl  s;    22668;???$+djr)   c                 2   U R                   R                  5         U R                  R                  5         U R                  (       aR  U R                  R                  5        H3  nUR                  SS9 H  nUR                  R                  5         M     M5     gg)zd
Clear all internal caches, for methods that alter the app registry.

This is mostly used in tests.
T)rY   N)r   cache_clearrX   r   r   r7   ri   _expire_cache)r$   r0   ro   s      r&   r;   Apps.clear_cacher  sx     	((446 	##%:: #..557
'222MEKK--/ N 8 r)   c                    ^ ^^ U(       d  U" 5         gUtnmUUU 4S jmUTl          T R                  " U6 nT" U5        g! [         a!    T R                  U   R	                  T5         gf = f)a0  
Take a function and a number of ("app_label", "modelname") tuples, and
when all the corresponding models have been imported and registered,
call the function with the model classes as its arguments.

The function passed to this method must accept exactly n models as
arguments, where n=len(model_keys).
c                 X   > [        TR                  U 5      nTR                  " U/TQ76   g r,   )r   funclazy_model_operation)ro   next_functionapply_next_modelmore_modelsr$   s     r&   r   3Apps.lazy_model_operation.<locals>.apply_next_model  s)     '(8(=(=u E))-F+Fr)   N)r   r   rQ   r"   r   )r$   function
model_keys
next_modelmodel_classr   r   s   `    @@r&   r   Apps.lazy_model_operation  sv     J (2$J
G %-!."77D !-  N((4;;<LMNs   ? (A*)A*c                     UR                   R                  UR                   R                  4nU R                  R	                  U/ 5       H  nU" U5        M     g)z
Take a newly-prepared model and pass it to each function waiting for
it. This is called at the very end of Apps.register_model().
N)ri   rR   rc   r"   r   )r$   ro   r   r   s       r&   rn   Apps.do_pending_operations  sF    
 kk##U[[%;%;;0044S"=HUO >r)   )
r   r"   r   r   r   r    r   r   r   r   ) r,   )FF)NT)r   rj   __qualname____firstlineno____doc__r'   r#   rG   rK   r<   rT   	functoolscacherX   rb   rq   ry   r   r   r   r   r   r   r   r;   r   rn   __static_attributes__r   r)   r&   r   r      s    '*RB#H	AC
)
'$ __ &M66LG& __ ,8
!20"&.Pr)   r   )r%   )r   r   r   rk   collectionsr   r   r   django.core.exceptionsr   r   configr	   r   r   r   r)   r&   <module>r      s6     
   ,  L e eP 4 r)   