
^rEc           @   s  d  d l  m Z d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d  d l Z d  d l Z y d  d l Z Wn d  d l Z n Xd e f d     YZ i  Z e d  Z e d  Z d   Z d	 d
  Z e e _ i  Z d   Z d   Z d   Z d   Z e e _ e e _ e e _ e j e _ d   Z  d   Z! e e e d  Z e e _ d f  d     YZ" d f  d     YZ# d f  d     YZ$ e$   Z% d   Z& e% j' e _' e% j( e _( e% j) e _) d f  d     YZ* d f  d     YZ+ e j, j- d	 e+    d f  d     YZ. e j/ e _0 e.   e _/ e j1 Z1 e1 j2 e1 _3 e1 j4 e1 _5 e1 j6 e1 _7 e1 j8 e1 _9 e1 j: e1 _; e1 j< e1 _= d e> e j?  d  Z@ i e jA e jB g d! 6e jA g d" 6e jA g d# 6e jA e jB g d$ 6e jA e jB g d% 6e jA e jB g d& 6e jA g d' 6e jA g d( 6e jA g d) 6e jA e jB g d* 6e jA e jB g d+ 6e jA e jB g d, 6ZC d-   ZD d.   ZE d/   Z2 d0   Z4 d1   Z6 e jF e2 e1 e jG  e1 _2 e jF e4 e1 e jG  e1 _4 e jF e6 e1 e jG  e1 _6 d2   Z8 e jF e8 e1 e jG  e1 _8 d3   Z: e jF e: e1 e jG  e1 _: e e e d4 d4 d	 d5  Z< e jF e< e1 e jG  e1 _< d S(6   i(   t   apache(   t	   publisherNt   _module_cachec           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR   <   s    c         C   s&   |  p t  j   }  t j |  d   d  S(   N(   t	   threadingt   currentThreadt   _request_modules_cachet   popt   None(   t   thread(    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _cleanup_request_modules_cache@   s    c         C   sb   t  j   } t j |  s^ t   t | <d t | _ d t | _ |  r^ |  j t |  q^ n  d  S(   Ni    (	   R   R   R   t   has_keyR   t
   generationt   ctimet   register_cleanupR   (   t   reqR
   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _setup_request_modules_cacheD   s    c          C   s   t  j   }  t j |  d   S(   N(   R   R   R   t   getR	   (   R
   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _get_request_modules_cacheM   s    i    c         C   s~  t  j    } t   } | d IJ| d IJx>| j   D]0} | j } | j } |  r| j j } t j t j	 | j
   } t j t j	 | j   } t j t j	 | j   }	 | j }
 | j } | j } | j } d } | d 7} | d 7} | | | | | | |	 |
 | | | f	 IJn d } | | | | f IJ| j j } x" | D] } | d | | f IJqHWq6 W| d IJ| j   S(	   Ns   digraph REQUEST {s   node [shape=box];s3   %s [label="%s\nmtime = %s\nctime = %s\natime = %s\ns-   generation = %d, direct = %d, indirect = %d\ns   path = %s"];s   %s [label="%s"];s   %s -> %st   }(   t   StringIOR   t   valuesR   t   __file__t   __mp_info__t   cachet   timet   asctimet	   localtimeR   t   mtimet   atimeR   t   directt   indirectt   __mp_path__t   childrent   getvalue(   t   verboset   outputt   modulest   modulet   namet   filenameR   R   R   R   R   R   R    t   patht   messageR"   t
   child_name(    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   request_modules_graphQ   s8    	

						


c         C   sr   t  j   } | r' t j j |  } n  t j | d  } |  d  k r[ | d  k r[ t | =n |  | | f t | <| S(   N(   NNN(   R   R   t   osR*   t   normpatht   _current_cacheR   R	   (   t   configt   optionst	   directoryR
   R   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _setup_current_cache   s    
c          C   s=   t  j   }  t j |  t j j   d  d  f  \ } } } | S(   N(   R   R   R0   R   R    t   main_servert
   get_configR	   (   R
   R1   R2   R3   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   get_current_config   s    	$c          C   s=   t  j   }  t j |  d  t j j   d  f  \ } } } | S(   N(   R   R   R0   R   R	   R    R5   t   get_options(   R
   R1   R2   R3   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   get_current_options   s    	$c          C   s+   t  j   }  t j |  d  \ } } } | S(   N(   NNN(   R   R   R0   R   R	   (   R
   R1   R2   R3   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   get_handler_root   s    	c          C   s   y
 t   WnX t j   d j j }  x< |  r` |  j j d  r` |  j d t k r` |  j }  q) Wn X|  r |  j j d  r |  j d } |  j d } | | f Sd S(   Ni   R   R   R!   (   NN(	   t	   Exceptiont   syst   exc_infot   tb_framet   f_backt	   f_globalsR   R   R	   (   t   parentt   parent_infot   parent_path(    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _parent_context   s    

c         C   s   x | D] } | d  k	 r | d k rF t   } | d  k	 r | } q nD | d  d k r t   } | d  k	 r t j j | | d  } q n  t j j | |   d } t j j |  r | Sq q Wd  S(   Nt   ~i   s   ~/s   .py(   R	   R:   R.   R*   t   joint   exists(   t   module_nameR*   R3   t   roott   file(    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _find_module   s    		c         C   sS  d  } g  } t j j |   r' |  } n |  d  d k rk t   } | d  k	 r%t j j | |  d  } q%n |  d  d k r t   \ } } | d  k	 r%t j j | j  } t j j | |  d  } q%n[ |  d  d k r%t   \ } } | d  k	 r%t j j | j  } t j j | |   } q%n  | d  k rg  }	 | d  k	 rS|	 j	 |  n  t   \ } } | d  k	 rt j j | j  } |	 j
 |  n  | d  k	 r|	 j	 |  n  t   }
 |
 j d  rt |
 d  } |	 j	 |  n  |	 rt |  |	  } qn | d  k	 r| } n  | d  k	 r9t j | | | |  St |  i  i  d g  Sd  S(   Ni   s   ~/s   ./i   s   ../s   mod_python.importer.patht   *(   R	   R.   R*   t   isabsR:   RF   RD   t   dirnameRJ   t   extendt   appendR9   R   t   evalRK   t   _global_modules_cachet   import_modulet
   __import__(   RH   t
   autoreloadt   logR*   RJ   t   import_pathR3   RB   RC   t   search_pathR2   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyRS      sP    						
t
   _CacheInfoc           B   s   e  Z d    Z RS(   c         C   s   | |  _  | |  _ | |  _ d  |  _ d |  _ d |  _ i  |  _ g  |  _ d |  _	 d |  _
 d |  _ d |  _ d |  _ t j   |  _ d  S(   Ni    (   t   labelRJ   R   R	   R'   t   instanceR   R"   R*   R   R   R   R    t   reloadR   t   Lockt   lock(   t   selfRZ   RJ   R   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   __init__8  s    													(   R   R   R`   (    (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyRY   6  s   t   _InstanceInfoc           B   s   e  Z d    Z RS(   c         C   s(   | |  _  | |  _ | |  _ i  |  _ d  S(   N(   RZ   RJ   R   R"   (   R_   RZ   RJ   R   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR`   J  s    			(   R   R   R`   (    (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyRa   H  s   t   _ModuleCachec           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d d	  Z
 d
   Z e e e d  Z d   Z d   Z d   Z RS(   t   _mp_c         C   sF   i  |  _  t j   |  _ t j   |  _ d |  _ t |  _ i  |  _ d  S(   Ni    (	   t   _cacheR   R]   t   _lock1t   _lock2t   _generationt   Falset   _frozent   _directories(   R_   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR`   T  s    			c         C   sP   t  j   } t j } t j t j B} d | | | f } t j j | |  d  S(   Ns'   mod_python (pid=%d, interpreter=%s): %s(   R.   t   getpidR    t   interpretert   APLOG_NOERRNOt   APLOG_NOTICER5   t	   log_error(   R_   t   msgt   pidR(   t   flagst   text(    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _log_notice\  s
    	c         C   sP   t  j   } t j } t j t j B} d | | | f } t j j | |  d  S(   Ns'   mod_python (pid=%d, interpreter=%s): %s(   R.   Rk   R    Rl   Rm   t   APLOG_WARNINGR5   Ro   (   R_   Rp   Rq   R(   Rr   Rs   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _log_warningc  s
    	c   	      C   s   t  j   } t j } t j t j B} d } d | | | f } t j j | |  t j	   \ } } } x4 t
 j | | |  D] } t j j | d  |  q} Wd  } d  S(   Ns   Application errors'   mod_python (pid=%d, interpreter=%s): %si(   R.   Rk   R    Rl   Rm   t	   APLOG_ERRR5   Ro   R<   R=   t	   tracebackt   format_exceptionR	   (	   R_   Rq   R(   Rr   Rp   Rs   t   etypet   evaluet   etb(    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _log_exceptionj  s    	c         C   s3   |  j  j   z |  j j   SWd  |  j  j   Xd  S(   N(   Re   t   acquireRd   t   keyst   release(   R_   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   cached_modulesv  s    c         C   s1   |  j  j   z |  j | SWd  |  j  j   Xd  S(   N(   Re   R~   Rd   R   (   R_   RZ   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   module_info}  s    c         C   s   t  |  _ d  S(   N(   t   TrueRi   (   R_   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   freeze_modules  s    i    c         C   s  |  j  j   zst j   } |  j } | d IJ| d IJx/| j   D]!} | j } | j } | rt j t j	 | j
   } t j t j	 | j   } t j t j	 | j   }	 | j }
 | j } | j } | j } d } | d 7} | d 7} | | | | | | |	 |
 | | | f	 IJn d } | | | | f IJ| j } x" | D] } | d | | f IJqIWqF W| d IJ| j   SWd  |  j  j   Xd  S(	   Ns   digraph GLOBAL {s   node [shape=box];s'   %s [label="%s\nmtime = %s\nctime = %s\ns)   atime = %s\ngeneration = %d, direct = %d,s   indirect = %d\npath = %s"];s   %s [label="%s"];s   %s -> %sR   (   Re   R~   R   Rd   R   RZ   RJ   R   R   R   R   R   R   R   R   R    R*   R"   R#   R   (   R_   R$   R%   R&   R   R(   R)   R   R   R   R   R   R    R*   R+   R"   R,   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   modules_graph  s<    	

						

	
c         C   sr   t  j j |  } | |  j k rn d  |  j | <| t j k rn d } | d } | d | } |  j |  qn n  d  S(   Ns'   Module directory listed in "sys.path". s,   This may cause problems. Please check code. s   File being imported is "%s".(   R.   R*   RN   Rj   R	   R<   Rv   (   R_   RJ   R3   Rp   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _check_directory  s    
c         C   s  t  j j |  } | d  k s* | d  k r t   } | d  k rZ t | j d d   } n  | d  k r t | j d d   } q n  | r |  j |  n  t   \ } } | r | | j	 k s t
 d |   n  t   } |  j |  }	 | d  k	 r+| j |	  r+| r t j   | j |	 <n  | |	 Sn  zd  }
 |  j | |	 | |  \ }
 } |
 j j   | j d k r|  j | _ t j   | _ n  | rT|
 j d |
 _ d |
 _ t j |	  } |
 j d  k rt |
 j d  ry4 | rd | } |  j |  n  |
 j j |  Wq|  j   | r?d | } |  j |  n  t |
 j d	  ryy |
 j j   Wqy|  j   qyXn  d  |
 _ t j |	  } qXn  | r|
 j d  k rd
 | } |  j |  qd | } |  j |  qn  | rd
 | } |  j |  n  | | _  t! |	 | |
  } | | _" | d  k r=g  } n  t# |  | _$ | d  k	 re| | |	 <n  t j   } | r| | j |	 <n  y t% | | j&  Wn& |
 j d  k r|  j' |	 =n    n X| |
 _ d |
 _ t( | j" j  |
 _ | j$ |
 _ |  j) j   |  j d |  _ |  j |
 _ |  j) j*   | |
 _ | |
 _+ d |
 _, d |
 _- n] |
 j } | d  k	 rv| | |	 <n  t j   } | r| | j |	 <n  | |
 _+ |
 j, d |
 _, | SWd  |
 d  k	 r|
 j j*   n  Xd  S(   Nt   PythonAutoReloadi   t   PythonDebugi    s   Import cycle in %s.t   __mp_clone__s   Cloning module '%s's   Purging module '%s't   __mp_purge__s   Importing module '%s's   Reimporting module '%s'(.   R.   R*   R/   R	   R7   t   intR   R   RD   RJ   t   AssertionErrorR   t   _module_labelR   R   R"   t   _reload_requiredR^   R~   R   Rg   R   R[   R\   t   impt
   new_moduleR'   t   hasattrRt   R   R}   R   R   Ra   R   t   listR!   t   execfilet   __dict__Rd   t   dictRf   R   R   R   R    (   R_   RJ   RU   RV   R*   R1   RB   RC   R&   RZ   R   t   loadR'   Rp   R[   R   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyRS     s    	"			


	


				
			
				
	c         C   s  z|  j  j   |  j j |  s] t j j |  } t | | |  } | |  j | <| t f S|  j | } | j	 s |  j
 s | r | t f Sn  y t j j |  } Wn9 d } | d } | d | } |  j |  | t f SX| j	 s | | j k r| | _ | t f S| j ri  } | g }	 xb | j D]T }
 |  j j |
  sQ| t f S|  j |
 } |  j | | | | |	  r/| t f Sq/Wn  | t f SWd  |  j  j   Xd  S(   Ns#   Module code file has been removed. s.   This may cause problems. Using cached module. s   File being imported "%s".(   Re   R~   Rd   R   R.   R*   t   getmtimeRY   R   R\   Ri   Rh   Rv   R   R"   t   _check_moduleR   (   R_   R&   RZ   RJ   RU   R   R   Rp   t   visitedt	   ancestorst   tagt   child(    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR     sD    
	
	
		
c   
      C   s  | j  d | _  t j   | _ | j r, t S| j | j k rB t S| j | j  rX t Sy, t	 j
 j | j  } | | j k r t SWnU d } | d } | d | j } |  j |  | d  k	 r | j | | j <n  t SX| j r| | j g } x | j j   D] } | | k rId } | d } | d | j } |  j |  t S|  j j |  s_t S|  j | }	 |  j | | |	 | |  rt SqWn  | | | j <| d  k	 r| j | | j <n  t S(   Ni   s#   Module code file has been removed. s.   This may cause problems. Using cached module. s   File being imported "%s".s#   Module imports an ancestor module. s,   This may cause problems. Please check code. s   File doing import is "%s".(   R    R   R   R\   R   R   R   RZ   Rh   R.   R*   R   RJ   R   Rv   R	   R'   R"   R   Rd   R   (
   R_   R&   RA   t   currentR   R   R   Rp   RZ   R   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR   Z  sN    	
	
c         C   s   |  j  t j |  j   S(   N(   t   _prefixt   md5t   newt	   hexdigest(   R_   RJ   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR     s    	(   R   R   R   R`   Rt   Rv   R}   R   R   R   R   R   R	   RS   R   R   R   (    (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyRb   P  s   							+	 H	U	ic           C   s   t  S(   N(   RR   (    (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _get_global_modules_cache  s    t   _ModuleLoaderc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t   _ModuleLoader__file(   R_   RJ   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR`     s    c         C   s   t  j |  j  S(   N(   RR   RS   R   (   R_   t   fullname(    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   load_module  s    (   R   R   R`   R   (    (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR     s   	t   _ModuleImporterc           B   s   e  Z d d   Z RS(   c   	      C   s   d | k r d  St   \ } } | d  k r/ d  Sg  } t j j | j  } | j |  | d  k	 rs | j |  n  t   } | j	 d  r t
 | d  } | j |  n  | s d  St | |  } | d  k	 r t |  Sd  S(   Nt   .s   mod_python.importer.path(   R	   RD   R.   R*   RN   RJ   RP   RO   R9   R   RQ   RK   R   (	   R_   R   R*   RB   RC   RX   R3   R2   RJ   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   find_module  s(    			
N(   R   R   R	   R   (    (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR     s   t
   _PageCachec           B   s   e  Z d    Z RS(   c         C   s   t  | j  S(   N(   RS   R)   (   R_   R   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   __getitem__"  s    (   R   R   R   (    (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR   !  s   s   Handler has returned result or raised SERVER_RETURN
exception with argument having non integer type. Type of value returned
was %s, whereas expected R   t   postreadrequesthandlert   transhandlert   maptostoragehandlert   inithandlert   headerparserhandlert   accesshandlert   authenhandlert   authzhandlert   typehandlert   fixuphandlert
   loghandlert   handlerc   
      C   sF  y t  |  j d d   } t j d  } | r | r t j   } | j   t j | j	  z | |  } Wd  d | _
 t j d   Xn | |  } Wnh t j k
 r } | s   n  t | j  d k r | j \ } }	 |	 r |	 | _ q q| j d } n X| s| | k rBt |  t j k sBt t t |    n  | S(   Nt   PythonEnablePdbt   0t   ONE_PROCESSi   i   i    (   R   R   R    t   exists_config_definet   pdbt   Pdbt   resetR<   t   settracet   trace_dispatcht   quittingR	   t   SERVER_RETURNt   lent   argst   statust   typet   typest   IntTypeR   t   _result_warning(
   R1   R   t   objectt   argt	   pdb_debugt   one_processt   debuggert   resultt   valueR   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _execute_targetJ  s.    	
	.c         C   s  t  |  s| j d d  } | d } t |  d k rC | }	 n
 | d }	 |  j d  r t j j   zF |  d }
 t j j |
  s t |
  } d  t j |
 <| t
 j (n  Wd  t j j   Xn  g  } | r | g } n  t | d | } t j | |	 | d | } n | } t j | d   } | s9t j | k rEt j } n	 t j } | d  k	 sa| rt |  | | |  } | r| | k rt | f Sn  t | f S(   Ns   ::i   i    t
   PythonPathR*   t   silent(   t   callablet   splitR   R   R    t   _path_cache_lockR~   t   _path_cacheRQ   R	   R<   R*   R   RS   t   resolve_objectt   _status_valuesR   t   DECLINEDt   OKR   R   Rh   (   R1   R   R3   R   t   defaultR   R   t   partsRH   t
   object_strt
   pathstringt   newpathR*   R'   R   t   expectedR   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   _process_target  s<    
	

	c         C   s  d } t  j } t   y zs | j j   } | j j   } t | | d
  } t d | d d
 d d
 d | j	 j
 d | d | d d	  \ } } Wd
 t |   t   XWn t  j k
 r"} t | j d d	   }	 zF | \ }
 } } |  j |
 | | d | d d d | j	 j
 d |	 } Wd
 d
 } Xnu t | j d d	   }	 zL t j   \ }
 } } |  j |
 | | d | d d d | j	 j
 d |	 } Wd
 d
 } Xn X| S(   s>        
    This is the dispatcher for connection handlers.
    t   connectionhandlerR1   R   R3   R   R   R   R   i    NR   t   connt   phaset   ConnectionHandlert   hnamet   debug(   R    t   HTTP_INTERNAL_SERVER_ERRORR   t   base_serverR6   R8   R4   R	   R   t   hlistR   R   t   PROG_TRACEBACKR   R   t   ReportErrorR<   R=   (   R_   R   t   default_handlerR   R1   R2   R   t   abortedt
   traceblockR   t   exc_typet	   exc_valuet   exc_traceback(    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   ConnectionDispatch  s<    	

c         C   s  | j  r d } n d } t | j  yz| j } | j } | d k r | j } x8 | d k	 r | j d k	 r} | j } Pn  | j } qU Wn  | d k r | j j   } n  t	 |  t
 j k r5| d  d k r | d k	 r2t j j | | d  } q2q5| d  d k r5| d k	 r2t j j | |  } q2q5n  | j j   } | j j   } t | | |  } t d | d | j d	 | d
 | d | d | d d  \ }	 }
 | j s| j   n  Wd t |   XWn t j k
 r^} t | j d d   } | j   zS | \ } } } |  j | | | d | j d | d d | j d | j d | }
 Wd d } Xn t | j d d   } | j   zY t j   \ } } } |  j | | | d | j d | d d | j d | j d | }
 Wd d } Xn Xt j S(   s?        
    This is the dispatcher for input/output filters.
    t   inputfiltert   outputfilteri   s   ./i   s   ../R1   R   R3   R   R   R   R   i    NR   t   filterR   s   Filter (%s)R   R   s   Filter: (   t   is_inputR   R   t   dirR   R	   RA   R3   t   document_rootR   R   t
   StringTypeR.   R*   RF   R6   R8   R4   R   t   closedt   flushR    R   R   R   t   disableR   R(   R<   R=   R   (   R_   R   R   R3   R   RA   R1   R2   R   R   R   R   R   R   R   R   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   FilterDispatch&  sn    							


c         C   s  | j  } | t d  j   } t j } t |  | j   } | j   } yt | j	 } } | j
 }	 | j }
 x" |
 d k	 r |
 j
 }	 |
 j }
 qr W|	 d k r | j   }	 n  xv| r'| j d k	 r'zDd } | j
 } | j } | d k r3| j }
 x8 |
 d k	 r/|
 j
 d k	 r#|
 j
 } Pn  |
 j }
 q Wn  t |  t j k r| d  d k r| d k	 rt j j | | d  } qq| d  d k r| d k	 rt j j | |  } qqn  t | | |	  } t d | d | d | d	 | d
 | d | d | j  \ } } Wd t |   X| j   q WWn t j k
 r} t | j d d   } zC | \ } } } |  j | | | d | d | d | j d | } Wd d } Xnr t | j d d   } zI t j   \ } } } |  j | | | d | d | d | j d | } Wd d } Xn X| S(   s9        
    This is the dispatcher for handler phases.
    t   pythoni   s   ./i   s   ../R1   R   R3   R   R   R   R   NR   i    R   R   R   (   R   R   t   lowerR    R   R   R6   R8   Rh   R   R3   RA   R	   R   R   R   R   R   R.   R*   RF   R4   R   R   t   nextR   R   R   R   R<   R=   (   R_   R   R   R   R   R1   R2   R   R   RI   RA   R   R3   R   R   R   R   R   R   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   HandlerDispatch  sr    		
							"
c         B   s  e  | j  yz]| j j   } | j j   } e | | d   } e | j d d   } e | j d  s| i  | j _	 n  | | j j	 d <d d d     Y} | j j
 | j j	 d <| d  | j j
 d   | j j	 d <g  | j j	 d	 <| j d
 d  j   } | d k rEe | | j j	  }	 |	 d  k	 rb| j e |	   qbn | d k rb| | j j	 Un  | j   Wd  d  | j j	 d <e |   XWnc zO e j   \ }
 } } |  j |
 | | d | d | j d | j j
 d | }	 Wd  d  } X  n Xe j S(   NR   i    t   ssi_globalsR   Ra   c           B   s   e  Z d    Z RS(   c         S   s(   | |  _  | |  _ | |  _ i  |  _ d  S(   N(   RZ   RJ   R   R"   (   R_   RZ   RJ   R   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR`   M  s    			(   R   R   R`   (    (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyRa   K  s   R   R   R!   s   
s   
RQ   t   execR   R   R   (    (   R   R   R6   R8   R4   R	   R   R   R   R  R)   t   replacet   rstripRQ   t   writet   strR   R<   R=   R   R(   R    R   (   R_   R   R   t   codeR1   R2   R   R   Ra   R   R   R   R   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   IncludeDispatch/  sD    c   
      C   s#  t  j j   } t | j d d   } | j d  r t  j j   zF | d } t  j j |  s t	 |  } d  t  j | <| t j (n  Wd  t  j j   Xn  | j d d  } | d } d  } t |  d k r | d } n  z6 t   t | d | }	 | rt |	 |    n  Wd  t   Xd  S(   NR   R   R   s   ::i   i    RV   (   R    R5   R6   R   R   R   R   R~   R   RQ   R	   R<   R*   R   R   R   R   RS   t   getattrR   (
   R_   R(   R1   R   R   R   t   lRH   t	   func_nameR'   (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   ImportDispatch{  s,    

s   N/Ac
   -      C   s  zyt  |  d k r7 t  |  d  d k r7 d }	 n  | rP | rP | j } n  | rb | j }
 n | rt | j }
 n t j j }
 t j   } t j } t j t j	 B} d | | f } | d | | f } | d } |
 | |  | rd  } d  } | j } | r8x | j d  k r"| j } qW| j } | j } n  | j j } | j   } |
 d | |  |
 d	 | |  |
 d
 | j |  |
 d | |  |
 d | |  |
 d | j |  |
 d | j |  n  t j | | |  } x | D] } |
 | d  |  qW|	 s| r&t j St j   } t j | _ d | _ | J| d IJ| d IJ| J| d | IJ| d | IJ| r| J| d | IJ| d | IJ| J| d | j IJ| d | IJ| d | IJ| d | j IJ| d | j IJn  | J| d | IJ| d t j t |   IJ| Jx! | D] } | t j |  IJq>Wt   } | j d k rqt  j! t  j" | j   } | J| d IJ| J| d | IJ| d  | j# IJ| Ji  } | j$   } x% | D] } | | } | | | j% <qW| j$   } | j&   x[| D]P} | | } | | } | j' } | j% } | j( j) }  t  j! t  j" |  j   }! t  j! t  j" |  j*   }" t  j! t  j" |  j+   }# |  j, }$ |  j# }% |  j- }& |  j. }' | j/ }( | d! | IJ| d" | IJ| d# |$ I|$ d$ k r,|  j0 s|% | j# k r,| d% IJn) |  j0 sD|% | j# k rQ| d& IJn | J| d' |% I|  j0 ry| d( IJn | J|  j* r| d) |" IJn  |  j r| d* |! IJn  |( rd+ j1 t2 t |(   } | d, | IJn  g  }) g  }* |  j0 r,x | j( j3 D]# }+ | |+ j( j4 }, |* j5 |,  qWn x4 | j( j) j3 D]# }+ | |+ j( j4 }, |* j5 |,  q<Wx | j( j3 D]v }+ |+ | j( j) j3 k rpy! | |+ j( j4 }, |) j5 |,  Wqy# t j6 |+  j4 }, |) j5 |,  WqqXqXqpqpW|* j&   |) j&   |* r-d+ j1 t2 t |*   } | d- | IJn  |) r\d+ j1 t2 t |)   } | d. | IJn  | d/ IJ| JqWn  | d0 IJ| j7   } | r| j8 |  | j9   n | j8 |  t j: SWn t j;   t< j= j9   n XWd  d  } Xd  S(1   Ns   exceptions.IOErrori   t   Writei    s$   mod_python (pid=%d, interpreter=%s, s   phase=%s, handler=%s)s   : Application errors   ServerName: %ss   DocumentRoot: %ss   URI: %ss   Location: %ss   Directory: %ss   Filename: %ss   PathInfo: %sis	   text/htmls   <pre>s   MOD_PYTHON ERRORs   ProcessId:      %ss   Interpreter:    %ss   ServerName:     %ss   DocumentRoot:   %ss   URI:            %ss   Location:       %ss   Directory:      %ss   Filename:       %ss   PathInfo:       %ss   Phase:          %ss   Handler:        %ss   MODULE CACHE DETAILSs   Accessed:       %ss   Generation:     %ss   %s {s     FileName:     %ss     Instance:     %si   s   [IMPORT]s   [RELOAD]s     Generation:   %ss   [ERROR]s     Modified:     %ss     Imported:     %ss   ,
                s     ModulePath:   %ss     Children:     %ss     Friends:      %sR   s   </pre>(>   R	  R   Ro   R    R5   R.   Rk   Rl   Rm   Rw   R	   R   RA   t   locationR3   t   servert   server_hostnameR   t   uriR)   t	   path_infoRx   Ry   R   R   R   t   content_typet   cgit   escapet   reprR   R   R   R   R   R   R   R   t   sortR   R   R   R   R   R[   R   R    R!   R\   RF   t   mapR"   RJ   RP   R   R#   R  R   t   DONEt	   print_excR<   t   stderr(-   R_   Rz   R{   R|   R   R   R   R   R   R   Ro   Rq   t   inameRr   Rs   R  R3   t   contextt   hostnameRI   t   tbt   lineR%   R&   t   accessedt   labelsR   t   keyR'   RZ   R(   R)   R   R   R   R   R[   R   R   R    R*   t   friendsR"   R   t   entry(    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyR     s<   		
			

	




											




(H   t
   mod_pythonR    R   R.   R<   R   R   R   R   R   R   t   stringR   Rx   R  R   t   dummy_threadingR   R   R   R	   R   R   R   R-   R0   R4   R7   R9   R:   RS   t   ximport_moduleRD   RK   RY   Ra   Rb   RR   R   R   R   R   R   R   t	   meta_patht   insertR   t
   page_cachet   xpage_cachet	   _callbackR   t   xConnectionDispatchR   t   xFilterDispatchR  t   xHandlerDispatchR  t   xIncludeDispatchR  t   xImportDispatchR   t   xReportErrorR	  R   R   R   R   R   R   R   t   instancemethodt   CallBack(    (    (    s7   /usr/lib/python2.7/dist-packages/mod_python/importer.pyt   <module>   s   		(										]	  		9		=	P	O	s		I	1	