
    Bh                         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
 d dlmZmZ d dlmZ d	 Zd
 Zd Zd Zed        Zed        Zd Zd Zd Zy)    N)cache)import_module)apps)ImproperlyConfigured)module_has_submodule)CMSAppConfigCMSAppExtension)CMS_CONFIG_NAMEc                     g }t        j                  |       D ]C  \  }}t        j                  |      xr t        ||      xr ||k7  }|s3|j	                  |       E |S )z]
    Helper function.

    Returns a list of classes in module which inherit from klass.
    )inspect
getmembersisclass
issubclassappend)moduleklassclassesnameobjis_subclasss         D/home/dcms/DCMS/lib/python3.12/site-packages/cms/app_registration.py_find_subclassesr      sg     G''/  	c OOC LZU%;Lu 	 NN3  N    c                 |    t        | t              }t        |      dk(  r|d   S t        |      dkD  rt        d      y)z
    Helper function.

    Returns the class inheriting from CMSAppConfig in the given module.
    If no such class exists in the module, returns None.
    If multiple classes inherit from CMSAppConfig, raises
    ImproperlyConfigured exception.
       r   zUcms_config.py files can't define more than one class which inherits from CMSAppConfigN)r   r   lenr   )
cms_modulecms_config_classess     r   _find_configr      sO     **lC
!#!!$$		 1	$"56 	6 
%r   c                 |    t        | t              }t        |      dk(  r|d   S t        |      dkD  rt        d      y)a   
    Helper function.

    Returns the class inheriting from CMSAppExtension in the given module.
    If no such class exists in the module, returns None.
    If multiple classes inherit from CMSAppExtension, raises
    ImproperlyConfigured exception.
    r   r   zXcms_config.py files can't define more than one class which inherits from CMSAppExtensionN)r   r	   r   r   )r   cms_extension_classess     r   _find_extensionr"   1   sO     -ZI
 !Q&$Q''	"	#a	'"89 	9 
(r   c                  >   t        j                         D ]d  } 	 t        | j                   dt               }t        |      }t        |      }|r ||       | _        |r |       | _        |rX|r[t        d       y#  t        | j                  t              r Y xY w)z
    Find and import all cms_config.py files. Add a cms_app attribute
    to django's app config with an instance of the cms config.
    .zfcms_config.py files must define at least one class which inherits from CMSAppConfig or CMSAppExtensionN)r   get_app_configsr   r   r
   r   r"   
cms_configcms_extensionr   r   r   )
app_configr   config	extensions       r   autodiscover_cms_configsr+   C   s    
 **, '
	'&??#1_$568J "*-F'
3I (.z(:
%+4;
()*&' '/'	 $J$5$5G Hs   A==Bc                  j    t        j                         D  cg c]  } t        | d      r|  }} |S c c} w )zA
    Returns django app configs of apps with a cms extension
    r'   r   r%   hasattrr(   cms_appss     r   get_cms_extension_appsr1   e   s=     .2-A-A-C 9z:7  9H 9O9   0c                  j    t        j                         D  cg c]  } t        | d      r|  }} |S c c} w )z>
    Returns django app configs of apps with a cms config
    r&   r-   r/   s     r   get_cms_config_appsr4   q   s=     .2-A-A-C 6z:|4  6H 6O6r2   c                     | D ]`  }|j                    d}|j                  j                  }t               D ],  }t	        |j
                  |d      s ||j
                         . b y)z
    Check installed apps for apps that are configured to use cms addons
    and run code to register them with their config
    _enabledFN)labelr'   configure_appr4   getattrr&   )apps_with_featuresapp_with_featureenabled_propertyr8   r(   s        r   configure_cms_appsr=   }   sl    
 / 5.445X>(66DD-/ 	5Jz,,.>Fj334	5	5r   c                 F    | D ]  }|j                   j                           y)zRun ready() methods on every registered cms extension,
    so that final checks can happen after all apps have been configured
    N)r'   ready)r:   r;   s     r   ready_cms_appsr@      s&     / /&&,,./r   c                      dg} | D ]6  }t        j                         D ]  }	 t        |j                   d|         8 y# t        $ r t        |j                  |      r Y Ew xY w)a  
    Ensure that old ways of configuring and setting up things (plugin
    pools etc.) still work.

    NOTE: The autodiscover code has been copied over from
    django.utils.module_loading.autodiscover_modules
    This is because django's autodiscover function imports
    django.apps.apps from within the body of the function, which
    interferes with backwards compatibility testing. The testing is
    non-trivial and requires the patching of django.apps.apps (which
    is impossible when imports are done inside of functions).
    cms_wizardsr$   N)r   r%   r   r   	Exceptionr   r   )modules_to_autodiscoverr   r(   s      r   backwards_compatibility_configrE      s|       -o) 	..0 	J 16(;<		   (
(9(96B C	s   A   A#"A#)r   	functoolsr   	importlibr   django.appsr   django.core.exceptionsr   django.utils.module_loadingr   cms.app_baser   r	   cms.constantsr
   r   r   r"   r+   r1   r4   r=   r@   rE    r   r   <module>rN      si      #  7 < 6 )$6$9$'D    5/r   