³ò
)SDEc           @   s>  d  Z  d d k Z d d k Z d d k Z d d k Z d d k l Z l Z l Z l	 Z	 l
 Z
 l Z l Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Td i g  Z e i ƒ  D] Z e e d d qÇ [ ƒ Z d d k l Z l Z d	 e f d
 „  ƒ  YZ e ƒ  Z d „  Z d d d d „ Z h  Z e e  f Z! x5 e i" i# ƒ  D]$ Z$ e% e$ e& ƒ o e! e e$ <qZqZWe i' h  e e f e( <e e f e) <e e f e* <e e f e+ <e e  f e, <e  e  f e- <ƒ e  e  f Z. d d d d „ Z/ e i0 d e i1 ƒ Z2 e i0 d e i1 ƒ Z3 d „  Z4 d S(   sn  
  This handler is conceptually similar to Zope's ZPublisher, except
  that it:

  1. Is written specifically for mod_python and is therefore much faster
  2. Does not require objects to have a documentation string
  3. Passes all arguments as simply string
  4. Does not try to match Python errors to HTTP errors
  5. Does not give special meaning to '.' and '..'.
iÿÿÿÿN(   t   existst   isabst   normpatht   splitt   isfilet   joint   dirname(   t   *t    i    i   (   t   ModuleCachet   NOT_INITIALIZEDt	   PageCachec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sO    This is the cache for page objects. Handles the automatic reloading of pages. c         C   s   | i  S(   s3    Extracts the normalized filename from the request (   t   filename(   t   selft   req(    (    s8   /usr/lib/python2.5/site-packages/mod_python/publisher.pyt   key7   s    c         C   sc   | i  ƒ  } t | i d d ƒ ƒ } | d j o | i t j	 o d  Sn t i |  | | | ƒ Sd  S(   Nt   PythonAutoReloadi   i    (   t
   get_configt   intt   gett   _valueR
   t   NoneR	   t   check(   R   R   R   t   entryt   configt
   autoreload(    (    s8   /usr/lib/python2.5/site-packages/mod_python/publisher.pyR   ;   s
    c         C   s   | i  ƒ  } t | i d d ƒ ƒ } | oL | i t j o | i d | i t i ƒ qw | i d | i t i ƒ n t	 i
 |  | | | | ƒ S(   Nt   PythonDebugi    s   Publisher loading page %ss   Publisher reloading page %s(   R   R   R   R   R
   t	   log_errorR   t   apachet   APLOG_NOTICER	   t   build(   R   R   R   t   openedR   R   t   log(    (    s8   /usr/lib/python2.5/site-packages/mod_python/publisher.pyR   E   s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s8   /usr/lib/python2.5/site-packages/mod_python/publisher.pyR   4   s   		
c         C   sŽ  |  i  d d d g ƒ |  i d j o t i t i ‚ n t i i |  i ƒ \ } } | p
 d } n d g } | |  i	 ƒ  i ƒ  7} |  i
 o | i |  i
 d ƒ n d d i | ƒ d	 } t i | ƒ } | i d
 | ƒ } d
 } |  i o0 |  i d } | d d j o | d  } qn | d | d |  _ t |  i ƒ pa | o | d | } n | } d } | d | d |  _ t |  i ƒ p t i t i ‚ q¤n | p
 d } n | i d d ƒ } t |  i ƒ |  _ t |  } t |  | ƒ \ } }	 }
 t |  | | | |	 |
 ƒ } t |  | ƒ } | oZ |  i d j oJ |  i d  j o: t |  i ƒ  i d d ƒ ƒ } | o |  i d ƒ q‡n t i  S(   Nt   GETt   POSTt   HEADt   indext   pyi   s   \.s   $|\.t   $t    iÿÿÿÿt   /s   .pyt   .i    R   s)   mod_python.publisher: nothing to publish.(   R$   R%   R&   (!   t   allow_methodst   methodR   t   SERVER_RETURNt   HTTP_METHOD_NOT_ALLOWEDt   ost   pathR   R   t   get_addhandler_extst	   extensiont   appendR   t   ret   compilet   subt	   path_infoR    t   HTTP_NOT_FOUNDt   replaceR   t
   page_cachet   process_autht   resolve_objectt   publish_objectt   _bytes_queuedt   nextR   R   R   R   R   t   OK(   R   R2   t   module_namet   suffixest   expt   suff_matchert	   func_patht   modulet   realmt   usert   passwdt   objectt	   publishedR    (    (    s8   /usr/lib/python2.5/site-packages/mod_python/publisher.pyt   handlern   sP    	
	
	



(t   unknownc      	      sb  d \ } } t  | d ƒ o | i } n d  } t | ƒ t j o
 | } n$ t | ƒ t i j o | i } n | oÒ | i ‰  | i	 } ‡  f d †  }	 |	 d ƒ \ } }
 | o, t |
 ƒ t i
 j o t i |
 | ƒ }
 n |	 d ƒ \ } } | o, t | ƒ t i
 j o t i | | ƒ } n |	 d ƒ \ } } | o
 | } qŽnG t  | d ƒ o | i }
 d } n t  | d ƒ o | i } d } n | p | ox | ol |  i i d ƒ oY y< |  i d d } t i | ƒ } | i d	 d ƒ \ } } Wqt i t i ‚ qXqn | oÆ | p* d
 | } | |  i d <t i t i ‚ n t |
 ƒ o |
 |  | | ƒ } n> t |
 ƒ t j o$ |
 i | ƒ o |
 | | j } n |
 } | p* d | } | |  i d <t i t i ‚ qán | om t | ƒ o | |  | ƒ } n0 t | ƒ t t f j o | | j } n | } | p t i t i ‚ qUn | | | f S(   Ni    t   __auth_realm__c            s¯   d  } |  ˆ  i j o t ˆ  i ƒ i |  ƒ } nT ˆ  i t ˆ  i ƒ j  o: ˆ  i ˆ  i } |  | j o t | ƒ i |  ƒ } q… n | d  j	 o d ˆ  i | d f Sn d S(   Ni   i    (   i    N(   R   t   co_namest   listR'   t   co_argcountt   lent   co_varnamest	   co_consts(   t   namet   it   names(   t	   func_code(    s8   /usr/lib/python2.5/site-packages/mod_python/publisher.pyt   lookupó   s    t   __auth__t
   __access__i   t   Authorizationi   t   :s   Basic realm="%s"s   WWW-Authenticates   Basic realm = "%s"(   i    i    (   t   hasattrRP   R   t   typet   FunctionTypet   typest
   MethodTypet   im_funcRZ   t   func_globalst   CodeTypet   newt   functionR\   R]   t
   headers_int   has_keyt   base64t   decodestringR   R   R/   t   HTTP_BAD_REQUESTt   err_headers_outt   HTTP_UNAUTHORIZEDt   callablet   DictionaryTypet   ListTypet	   TupleTypet   HTTP_FORBIDDEN(   R   RL   RI   RJ   RK   t
   found_autht   found_accesst   func_objectRf   R[   R\   R]   t   found_realmRP   t   st   rc(    (   RZ   s8   /usr/lib/python2.5/site-packages/mod_python/publisher.pyR=   ß   st    
			
	

$
c   
   
   C   sŠ  | i  d ƒ } t } x| D]} | d d j o3 |  i d | |  i f t i ƒ t i t i ‚ n | o
 t } nZ t	 i
 t | ƒ t ƒ }	 |	 d p6 |  i d | |  i | f t i ƒ t i t i ‚ n y t | | ƒ } Wn" t j
 o t i t i ‚ n Xt |  | | | | ƒ \ } } } q Wt	 i
 t | ƒ t ƒ }	 |	 d p6 |  i d | |  i | f t i ƒ t i t i ‚ n | S(   sq   
    This function traverses the objects separated by .
    (period) to find the last one we're looking for.
    R,   i    t   _s=   Cannot traverse %s in %s because it starts with an underscores?   Cannot traverse %s in %s because %s is not a traversable objecti   s5   Cannot publish %s in %s because %s is not publishable(   R   t   TrueR   t   unparsed_uriR   t   APLOG_WARNINGR/   Ru   t   Falset   tp_rulesR   Ra   t   default_tp_rulet   getattrt   AttributeErrorR:   R=   (
   R   t   objt
   object_strRI   RJ   RK   t   partst   first_objectt   obj_strt   rule(    (    s8   /usr/lib/python2.5/site-packages/mod_python/publisher.pyR>   k  s4     	
	%	s   </HTML\s*>\s*$s   charset\s*=\s*([^\s;]+)c         C   sg  t  | ƒ o> t i |  d d ƒ|  _ t |  t i | |  i d |  ƒƒ Sn| d  j o t Sn‹ t | t	 ƒ oh |  i
 oE t i |  i ƒ } | o | i d ƒ } qÅ d } |  i d 7_ n d } | i | ƒ } n d  } t | ƒ } |  i
 p[ t i | t | ƒ d ƒ o d |  _ n
 d |  _ | d  j	 o |  i d	 | 7_ qOn |  i | d
 ƒ t Sd  S(   Nt   keep_blank_valuesi   R   t   UTF8s   ; charset=UTF8id   s	   text/htmls
   text/plains   ; charset=%si    (   Rq   t   utilt   FieldStoraget   formR?   t   apply_fs_dataR   R€   t
   isinstancet   UnicodeTypet   _content_type_sett
   re_charsett   searcht   content_typet   groupt   encodet   strt   re_htmlRT   t   writeR}   (   R   RL   t   charsett   result(    (    s8   /usr/lib/python2.5/site-packages/mod_python/publisher.pyR?   ¢  s0    &

	
(5   R#   R   R   t   sysR1   t   os.pathR    R   R   R   R   R   R   t   impR6   Rl   Rh   Rc   t   _[1]t   get_suffixest   xt   imp_suffixest   cacheR	   R
   R   R<   RN   R   R=   R   R€   R}   t   default_builtins_tp_rulet   __dict__t   valuest   tR‘   Ra   t   updatet
   ModuleTypet   BuiltinFunctionTypet	   ClassTypet   TypeTypet   GeneratorTypet   InstanceTypeR‚   R>   R7   t   IRš   R”   R?   (    (    (    s8   /usr/lib/python2.5/site-packages/mod_python/publisher.pys   <module>   sF   4
8		qm 
4