ó
)SDEc           @   s(  d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z m Z m Z m	 Z	 m
 Z
 m Z 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 Td j g  e j ƒ  D] Z e d d ^ qÃ ƒ Z d d l m Z m Z d	 e f d
 „  ƒ  YZ e ƒ  Z d „  Z d d d d „ Z i  Z e e f Z  x3 e j! j" ƒ  D]" Z# e$ e# e% ƒ rRe  e e# <qRqRWe j& i e e f e' 6e e f e( 6e e f e) 6e e f e* 6e e f e+ 6e e f e, 6ƒ e e f Z- d d d d „ Z. e j/ d e j0 ƒ Z1 e j/ d e j0 ƒ Z2 d „  Z3 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   | j  S(   s3    Extracts the normalized filename from the request (   t   filename(   t   selft   req(    (    s8   /usr/lib/python2.7/dist-packages/mod_python/publisher.pyt   key7   s    c         C   s]   | j  ƒ  } t | j d d ƒ ƒ } | d k rC | j t k	 rC d  St j |  | | | ƒ 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.7/dist-packages/mod_python/publisher.pyR   ;   s
    c         C   sŒ   | j  ƒ  } t | j d d ƒ ƒ } | rs | j t k rV | j d | j t j ƒ qs | j d | j t j ƒ n  t	 j
 |  | | | | ƒ 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.7/dist-packages/mod_python/publisher.pyR   E   s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/mod_python/publisher.pyR   4   s   		
c         C   sv  |  j  d d d g ƒ |  j d k r7 t j t j ‚ n  t j j |  j ƒ \ } } | sa d } n  d g } | |  j	 ƒ  j ƒ  7} |  j
 r  | j |  j
 d ƒ n  d d j | ƒ d	 } t j | ƒ } | j d
 | ƒ } d
 } |  j r|  j d } | d d k r| d  } qn  | d | d |  _ t |  j ƒ s”| rO| d | } n | } d } | d | d |  _ t |  j ƒ s”t j t j ‚ q”n  | s£d } n  | j d d ƒ } t |  j ƒ |  _ t |  } t |  | ƒ \ } }	 }
 t |  | | | |	 |
 ƒ } t |  | ƒ } | ro|  j d k ro|  j d  k rot |  j ƒ  j d d ƒ ƒ } | ro|  j d ƒ qon  t j  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.7/dist-packages/mod_python/publisher.pyt   handlern   sP    						
	
%t   unknownc            s5  d \ } } t  | d ƒ r' | j } n  d  } t | ƒ t k rH | } n! t | ƒ t j k ri | j } n  | r8| j ‰  | j	 } ‡  f d †  }	 |	 d ƒ \ } }
 | rÒ t |
 ƒ t j
 k rÒ t j |
 | ƒ }
 n  |	 d ƒ \ } } | rt | ƒ t j
 k rt j | | ƒ } n  |	 d ƒ \ } } | rz| } qznB t  | d ƒ rY| j }
 d } n  t  | d ƒ rz| j } d } n  | s†| rú| rú|  j j d ƒ rúy< |  j d d } t j | ƒ } | j d	 d ƒ \ } } Wq÷t j t j ‚ q÷Xqún  | r¼| s/d
 | } | |  j d <t j t j ‚ n  t |
 ƒ rP|
 |  | | ƒ } n: t |
 ƒ t k r„|
 j | ƒ o~|
 | | k } n |
 } | s¼d | } | |  j d <t j t j ‚ q¼n  | r(t | ƒ rà| |  | ƒ } n- t | ƒ t t f k r| | k } n | } | s(t j t j ‚ q(n  | | | f S(   Ni    t   __auth_realm__c            s¤   d  } |  ˆ  j k r0 t ˆ  j ƒ j |  ƒ } nO ˆ  j t ˆ  j ƒ k  r ˆ  j ˆ  j } |  | k r t | ƒ j |  ƒ } q n  | d  k	 r  d ˆ  j | d f Sd 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.7/dist-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.7/dist-packages/mod_python/publisher.pyR=   ß   st    							
"
c   
      C   s€  | j  d ƒ } t } x| D]} | d d k rd |  j d | |  j f t j ƒ t j t j ‚ n  | rs t } nW t	 j
 t | ƒ t ƒ }	 |	 d sÊ |  j d | |  j | f t j ƒ t j t j ‚ n  y t | | ƒ } Wn  t k
 rÿ t j t j ‚ n Xt |  | | | | ƒ \ } } } q Wt	 j
 t | ƒ t ƒ }	 |	 d s||  j d | |  j | f t j ƒ t j t j ‚ 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.7/dist-packages/mod_python/publisher.pyR>   k  s2    		
	%
	s   </HTML\s*>\s*$s   charset\s*=\s*([^\s;]+)c         C   sQ  t  | ƒ rF t j |  d d ƒ|  _ t |  t j | |  j d |  ƒƒ S| d  k rV t St | t	 ƒ rÈ |  j
 r° t j |  j ƒ } | r˜ | j d ƒ } q¶ d } |  j d 7_ n d } | j | ƒ } n d  } t | ƒ } |  j
 s9t j | t | ƒ d ƒ rd |  _ n	 d |  _ | d  k	 r9|  j d	 | 7_ q9n  |  j | 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.7/dist-packages/mod_python/publisher.pyR?   ¢  s0    "			
(4   R#   R   R   t   sysR1   t   os.pathR    R   R   R   R   R   R   t   impR6   Rl   Rh   Rc   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.7/dist-packages/mod_python/publisher.pyt   <module>   sD   4
0		qm	4