
    2Bh                         S SK rS SKrS SKrS SKrS SKrS SK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	\5      rg)
    N)util)Arbiter)Configget_default_config_file)debugc                   R    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rSrg)BaseApplication   zk
An application interface for configuring and loading
the various necessities for any given web framework.
Nc                 f    Xl         S U l        S U l        X l        S U l        U R                  5         g N)usagecfgcallableprogloggerdo_load_config)selfr   r   s      C/var/www/html/env/lib/python3.13/site-packages/gunicorn/app/base.py__init__BaseApplication.__init__   s-    
	    c                 $    U R                  5         U R                  5         g! [         ab  n[        S[	        U5      -  [
        R                  S9  [
        R                  R                  5         [
        R                  " S5         SnAgSnAff = f)z
Loads the configuration
z

Error: %sfile   N)	load_default_configload_config	Exceptionprintstrsysstderrflushexitr   es     r   r   BaseApplication.do_load_config   sc    	$$& 	-#a&(szz:JJHHQKK	s    # 
BAB

Bc                 J    [        U R                  U R                  S9U l        g )N)r   )r   r   r   r   r   s    r   r   #BaseApplication.load_default_config)   s    $**4995r   c                     [         er   NotImplementedError)r   parseroptsargss       r   initBaseApplication.init-       !!r   c                     [         er   r,   r)   s    r   loadBaseApplication.load0   r3   r   c                     [         e)z
This method is used to load the configuration from one or several input(s).
Custom Command line, configuration file.
You have to override this method in your class.
r,   r)   s    r   r   BaseApplication.load_config3   s
     "!r   c                     U R                  5         U R                  R                  (       a  [        R                  " 5         g g r   )r   r   spewr   r)   s    r   reloadBaseApplication.reload;   s'    88==JJL r   c                 ^    U R                   c  U R                  5       U l         U R                   $ r   )r   r5   r)   s    r   wsgiBaseApplication.wsgi@   s#    ==  IIKDM}}r   c                     [        U 5      R                  5         g ! [         aY  n[        SU-  [        R
                  S9  [        R
                  R                  5         [        R                  " S5         S nAg S nAff = f)Nz
Error: %s
r   r   )r   runRuntimeErrorr   r!   r"   r#   r$   r%   s     r   rA   BaseApplication.runE   sW    	DM 	/A%CJJ7JJHHQKK	s    
A?AA::A?)r   r   r   r   r   )NN)__name__
__module____qualname____firstlineno____doc__r   r   r   r1   r5   r   r;   r>   rA   __static_attributes__ r   r   r	   r	      s4    
6"""

r   r	   c                   L   ^  \ rS rSrS rS rS rS rS rS r	U 4S jr
S	rU =r$ )
ApplicationN   c                    [         R                  " U R                  R                  5        U R                  R                  [        R                  ;  a5  [        R                  R                  SU R                  R                  5        g g )Nr   )oschdirr   r!   pathinsertr)   s    r   rP   Application.chdirS   sM     	  88>>)HHOOAtxx~~. *r   c                 >   [         R                  R                  U5      (       d  [        SU-  5      e[         R                  R	                  U5      S   n SnUS;   a   [
        R                  R                  X15      nOUSn[        R                  " U5        [
        R                  R                  X15      n[
        R                  R                  X1US9n[
        R                  R                  U5      nU[        R                  U'   UR                  R                  U5        [/        W5      $ ! [          ag    [#        SU-  [        R$                  S9  [&        R(                  " 5         [        R$                  R+                  5         [        R,                  " S5         N{f = f)	Nz%r doesn't existr   
__config__)z.pyz.pycz9configuration file should have a valid Python extension.
)loaderzFailed to read config file: %sr   )rO   rQ   existsrB   splitext	importlibr   spec_from_file_locationwarn	machinerySourceFileLoadermodule_from_specr!   modulesrV   exec_moduler   r   r"   	traceback	print_excr#   r$   vars)r   filenameextmodule_namespecmsgloader_mods           r   get_config_from_filename$Application.get_config_from_filename\   s1   ww~~h''1H<==ggx(+	&Ko% ~~==kTR		##-->>{U ~~==k\c=d..11$7C'*CKK$KK##C( Cy  	2X=CJJO!JJHHQK		s   C
D+ +A.FFc                 @    [        [        R                  " U5      5      $ r   )rc   rY   import_module)r   rf   s     r   get_config_from_module_name'Application.get_config_from_module_namew   s    I++K899r   c           	      <   UR                  S5      (       a   U[        S5      S nU R                  U5      nO8UR                  S5      (       a  U[        S5      S nOUnU R                  U5      nUR	                  5        HK  u  pVXPR
                  R                  ;  a  M    U R
                  R                  UR                  5       U5        MM     U$ ! [         aA    [        SU< SU< S3[        R                  S9  [        R                  R                  5         e f = f)z
Loads the configuration file: the file is a python file, otherwise raise an RuntimeError
Exception or stop the process if the configuration file contains a syntax error.
zpython:Nzfile:zInvalid value for z: 
r   )
startswithlenro   rk   itemsr   settingssetlowerr   r   r!   r"   r#   )r   locationrf   r   rd   kvs          r   (load_config_from_module_name_or_filename4Application.load_config_from_module_name_or_filenamez   s     y))"3y>?3K22;?C""7++#CLM2#//9CIIKDA)))QWWY*   
  a;#**M

  "s    *CADc                      U R                  US9$ )N)ry   )r|   )r   rd   s     r   load_config_from_file!Application.load_config_from_file   s    <<h<OOr   c                 
   U R                   R                  5       nUR                  5       nU R                  XUR                  5      nU R                  5         U(       aC  UR                  5        H/  u  pEU R                   R                  UR                  5       U5        M1     UR                  U R                   R                  5       5      nUR                  (       a  U R                  UR                  5        OKUR                  (       a  U R                  UR                  5        O[        5       nUb  U R                  U5        [        U5      R                  5        H<  u  pEUc  M
  US:X  a  M  U R                   R                  UR                  5       U5        M>     [        U5      R                  5        H<  u  pEUc  M
  US:X  a  M  U R                   R                  UR                  5       U5        M>     U R                  5         g )Nr0   )r   r.   
parse_argsr1   r0   rP   ru   rw   rx   get_cmd_args_from_envconfigr   r   rc   )r   r.   r0   r   rz   r{   env_argsdefault_configs           r   r   Application.load_config   sr   "  " iidii0 	

 		QWWY* $ $$TXX%C%C%EF;;&&t{{3__&&x746N)**>: N((*DAyF{HHLLA& + J$$&DAyF{HHLLA& ' 	

r   c                   > U R                   R                  (       a  [        U R                   5        U R                   R                  (       d  U R                   R                  (       a'   U R	                  5         [        R                  " S5        U R                   R                  (       a  [        R                  " 5         U R                   R                  (       ai  [        R                   R#                  S5      (       a  Sn[        U[        R                  SS9  [$        R&                  " U R                   R(                  5        U R                   R*                  (       a  U R                   R*                  R-                  S	5      nU HX  n[        R.                  R1                  U5      nU[        R.                  ;  d  M8  [        R.                  R3                  SU5        MZ     [4        TU ]m  5         g ! [
         ag    Sn[        U[        R                  S9  [        R                  " 5         [        R                  R                  5         [        R                  " S5         GNf = f)
Nz&
Error while loading the application:
r   r   r   NOTIFY_SOCKETz]Warning: you shouldn't specify `daemon = True` when launching by systemd with `Type = notify`T)r   r#   ,)r   print_configr   check_configr5   r   r!   r"   ra   rb   r#   r$   r:   r   daemonrO   environgetr   	daemonizeenable_stdio_inheritance
pythonpathsplitrQ   abspathrR   superrA   )r   rh   pathsrQ   r   	__class__s        r   rA   Application.run   sh   88  $((O88  DHH$9$9		 HHQK88==JJL88??zz~~o..Hc

$7NN488<<= 88HH''--c2EWW__T2
SXX-HHOOAz2 
 	7  @c

+##%

  "s   )G0 0A-I! I!rJ   )rD   rE   rF   rG   rP   rk   ro   r|   r   r   rA   rI   __classcell__)r   s   @r   rL   rL   N   s-    
/6::P-^" "r   rL   )importlib.utilrY   importlib.machineryrO   r!   ra   gunicornr   gunicorn.arbiterr   gunicorn.configr   r   r   r	   rL   rJ   r   r   <module>r      s;      	 
   $ ; ; ;|]/ ]r   