
    Tf                         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dS )
    N)util)Arbiter)Configget_default_config_file)debugc                   J    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dS )BaseApplicationzw
    An application interface for configuring and loading
    the various necessities for any given web framework.
    Nc                 t    || _         d | _        d | _        || _        d | _        |                                  d S N)usagecfgcallableprogloggerdo_load_config)selfr   r   s      C/var/www/html/env/lib/python3.11/site-packages/gunicorn/app/base.py__init__zBaseApplication.__init__   s=    
	    c                 B   	 |                                   |                                  dS # t          $ rh}t          dt	          |          z  t
          j                   t
          j                                         t          j        d           Y d}~dS 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   s    	$$&&& 	 	 	-#a&&(sz::::JHQKKKKKKKKK	s   (, 
BABBc                 F    t          | j        | j                  | _        d S )N)r   )r   r   r   r   r   s    r   r   z#BaseApplication.load_default_config*   s    $*4955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                 p    |                                   | j        j        rt          j                     d S d S r   )r   r   spewr   r&   s    r   reloadzBaseApplication.reload<   s9    8= 	JLLLLL	 	r   c                 P    | j         |                                 | _         | j         S r   )r   r0   r&   s    r   wsgizBaseApplication.wsgiA   s!    =  IIKKDM}r   c                    	 t          |                                            d S # t          $ r[}t          d|z  t          j                   t          j                                         t	          j        d           Y d }~d S 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   s    	DMM 	 	 	/A%CJ7777JHQKKKKKKKKK	s   !% 
B
ABB
)NN)__name__
__module____qualname____doc__r   r   r   r-   r0   r   r4   r6   r8    r   r   r	   r	      s            
 
 
6 6 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r,t          j                            d| j        j                   d S d S )Nr   )oschdirr   r   pathinsertr&   s    r   rC   zApplication.chdirT   sS     	    8>))HOOAtx~..... *)r   c                 D   t           j                            |          st          d|z            t           j                            |          d         }	 d}|dv r!t
          j                            ||          }nXd}t          j        |           t
          j	        
                    ||          }t
          j                            |||          }t
          j                            |          }|t          j        |<   |j                            |           ns# t           $ rf t#          d|z  t          j                   t'          j                     t          j                                         t          j        d           Y nw xY wt/          |          S )	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]   sm   w~~h'' 	>1H<===gx((+	&Ko%% ~==k8TTR	##->>{HUU ~==k8\c=dd.11$77C'*CK$K##C(((( 	 	 	2X=CJOOOO!!!JHQKKKKK		 Cyys   CD   A-FFc                 D    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8999r   c           	      ^   |                     d          r-|t          d          d         }|                     |          }nD|                     d          r|t          d          d         }n|}|                     |          }|                                D ]\  }}|| j        j        vr	 | j                            |                                |           C# t          $ rB t          d|d|dt          j                   t          j                                          w xY w|S )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{   s8    y)) 	:"3y>>??3K22;??CC""7++ $#CLLMM2#//99CIIKK 		 		DAq)))QWWYY****   aaa;#*MMMM
  """
 
s   0-CAD*c                 .    |                      |          S )N)ri   )rl   )r   rV   s     r   load_config_from_filez!Application.load_config_from_file   s    <<h<OOOr   c                    | j                                         }|                                }|                     |||j                  }|                                  |rG|                                D ]2\  }}| j                             |                                |           3|                    | j         	                                          }|j
        r|                     |j
                   nG|j
        r|                     |j
                   n%t                      }||                     |           t          |                                          D ]<\  }}||dk    r| j                             |                                |           =t          |                                          D ]<\  }}||dk    r| j                             |                                |           =|                                  d S )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di00 	

  	+		 + +1QWWYY****$$TX%C%C%E%EFF; 	;&&t{3333_ 	;&&x7777466N)**>::: NN((** 	' 	'DAqyF{{HLLA&&&& JJ$$&& 	' 	'DAqyF{{HLLA&&&& 	

r   c                    | j         j        rt          | j                    | j         j        s| j         j        r	 |                                  nr# t
          $ re d}t          |t          j                   t          j	                     t          j        
                                 t          j        d           Y nw xY wt          j        d           | j         j        rt          j                     | j         j        r[t          j                            d          rd}t          |t          j        d           t%          j        | j         j                   | j         j        rq| j         j                            d	          }|D ]O}t          j                            |          }|t          j        vr t          j                            d|           Pt5                                                       d S )
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   s   8  	$(OOO8  		DH$9 				   @c
++++#%%%
  """ HQKKK8= 	JLLL8? 	>z~~o.. 8Hc
$7777N48<=== 8 	3H'--c22E 3 3W__T22
SX--HOOAz222s   A A,B?>B?)r:   r;   r<   rC   r]   r`   rl   rn   r   r8   __classcell__)r   s   @r   r@   r@   O   s        
/ / /  6: : :  :P P 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   