
    +h                         d dl Zd dlZ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mZ d dlmZ  G d de      Z G d d	e      Zy)
    N)util)Arbiter)Configget_default_config_file)debugc                   H    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zy)BaseApplicationzw
    An application interface for configuring and loading
    the various necessities for any given web framework.
    Nc                 j    || _         d | _        d | _        || _        d | _        | j                          y N)usagecfgcallableprogloggerdo_load_config)selfr   r   s      D/var/www/html/venv/lib/python3.12/site-packages/gunicorn/app/base.py__init__zBaseApplication.__init__   s1    
	    c                 &   	 | j                          | j                          y# t        $ rd}t        dt	        |      z  t
        j                         t
        j                  j                          t        j                  d       Y d}~yd}~ww xY w)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   zBaseApplication.do_load_config   sc    	$$& 	-#a&(szz:JJHHQKK	s    # 	BABBc                 P    t        | j                  | j                        | _        y )N)r   )r   r   r   r   r   s    r   r   z#BaseApplication.load_default_config*   s    $**4995r   c                     t         r   NotImplementedError)r   parseroptsargss       r   initzBaseApplication.init.       !!r   c                     t         r   r(   r&   s    r   loadzBaseApplication.load1   r.   r   c                     t         )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   zBaseApplication.load_config4   s
     "!r   c                 z    | j                          | j                  j                  rt        j                          y y r   )r   r   spewr   r&   s    r   reloadzBaseApplication.reload<   s'    88==JJL r   c                 \    | j                   | j                         | _         | j                   S r   )r   r0   r&   s    r   wsgizBaseApplication.wsgiA   s#    ==  IIKDM}}r   c                    	 t        |       j                          y # t        $ r[}t        d|z  t        j
                         t        j
                  j                          t	        j                  d       Y d }~y d }~ww xY w)Nz
Error: %s
r   r   )r   runRuntimeErrorr   r   r    r!   r"   r#   s     r   r8   zBaseApplication.runF   sW    	DM 	/A%CJJ7JJHHQKK	s    	B AA;;B )NN)__name__
__module____qualname____doc__r   r   r   r-   r0   r   r4   r6   r8    r   r   r	   r	      s4    
6"""

r   r	   c                   B     e Zd Zd Zd Zd Zd Zd Zd Z fdZ	 xZ
S )Applicationc                    t        j                  | j                  j                         | j                  j                  t        j                  vr5t        j                  j                  d| j                  j                         y y )Nr   )oschdirr   r   pathinsertr&   s    r   rC   zApplication.chdirT   sM     	  88>>)HHOOAtxx~~. *r   c                 N   t         j                  j                  |      st        d|z        t         j                  j	                  |      d   }	 d}|dv r!t
        j                  j                  ||      }nYd}t        j                  |       t
        j                  j                  ||      }t
        j                  j                  |||      }t
        j                  j                  |      }|t        j                  |<   |j                  j                  |       t/        |      S # t         $ rr t#        d|z  t        j$                         t'        j(                          t        j$                  j+                          t        j,                  d       Y t/              S w xY w)	Nz%r doesn't existr   
__config__)z.pyz.pycz9configuration file should have a valid Python extension.
)loaderzFailed to read config file: %sr   )rB   rD   existsr9   splitext	importlibr   spec_from_file_locationwarn	machinerySourceFileLoadermodule_from_specr   modulesrH   exec_moduler   r   r    	traceback	print_excr!   r"   vars)r   filenameextmodule_namespecmsgloader_mods           r   get_config_from_filenamez$Application.get_config_from_filename]   s>   ww~~h'1H<==ggx(+	&Ko% ~~==k8TR		##-->>{HU ~~==k8\c=d..11$7C'*CKK$KK##C( Cy  	2X=CJJO!JJHHQKCy	s   CD) )A.F$#F$c                 >    t        t        j                  |            S r   )rU   rK   import_module)r   rX   s     r   get_config_from_module_namez'Application.get_config_from_module_namex   s    I++K899r   c           	      "   |j                  d      r |t        d      d }| j                  |      }n3|j                  d      r|t        d      d }n|}| j                  |      }|j	                         D ]I  \  }}|| j
                  j                  vr	 | j
                  j                  |j                         |       K |S # t        $ rB t        d|d|dt        j                         t        j                  j                           w xY w)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lenr`   r]   itemsr   settingssetlowerr   r   r   r    r!   )r   locationrX   r   rV   kvs          r   (load_config_from_module_name_or_filenamez4Application.load_config_from_module_name_or_filename{   s     y)"3y>?3K22;?C""7+#CLM2#//9CIIK 		DAq)))QWWY*		 
  a;#**M

  "s   *CADc                 &    | j                  |      S )N)ri   )rl   )r   rV   s     r   load_config_from_filez!Application.load_config_from_file   s    <<h<OOr   c                    | j                   j                         }|j                         }| j                  |||j                        }| j                          |rB|j                         D ]/  \  }}| j                   j                  |j                         |       1 |j                  | j                   j                               }|j                  r| j                  |j                         nE|j                  r| j                  |j                         nt               }|| j                  |       t        |      j                         D ]8  \  }}|	|dk(  r| j                   j                  |j                         |       : t        |      j                         D ]8  \  }}|	|dk(  r| j                   j                  |j                         |       : | j                          y )Nr,   )r   r*   
parse_argsr-   r,   rC   re   rg   rh   get_cmd_args_from_envconfigrn   r   rU   )r   r*   r,   r   rj   rk   env_argsdefault_configs           r   r   zApplication.load_config   s   "  " iidii0 	

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

r   c                 x   | j                   j                  rt        | j                          | j                   j                  s| j                   j                  r&	 | j	                          t        j                  d       | j                   j                  rt        j                          | j                   j                  rft        j                   j#                  d      rd}t        |t        j                  d       t%        j&                  | j                   j(                         | j                   j*                  r~| j                   j*                  j-                  d	      }|D ]T  }t        j.                  j1                  |      }|t        j.                  vs5t        j.                  j3                  d|       V t4        | m          y # t
        $ rh d}t        |t        j                         t        j                          t        j                  j                          t        j                  d       Y w xY w)
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_configr0   r   r   r    rS   rT   r!   r"   r3   r   daemonrB   environgetr   	daemonizeenable_stdio_inheritance
pythonpathsplitrD   abspathrE   superr8   )r   rZ   pathsrD   r   	__class__s        r   r8   zApplication.run   sj   88  $((O88  DHH$9$9		 HHQK88==JJL88??zz~~o.Hc

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

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

  "s   G A-H98H9)r:   r;   r<   rC   r]   r`   rl   rn   r   r8   __classcell__)r   s   @r   r@   r@   O   s-    
/6::P-^" "r   r@   )importlib.utilrK   importlib.machineryrB   r   rS   gunicornr   gunicorn.arbiterr   gunicorn.configr   r   r   objectr	   r@   r>   r   r   <module>r      s=   
   	 
   $ ; ;f ;|]/ ]r   