ó
ŸçƒQc           @   s"  d  d l  Z  d  d l Z d  d l Z d  d l m Z d  d l m Z m Z m Z m	 Z	 m
 Z
 d  d l m Z m Z d  d l m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z m Z d  d l m Z d  d l Z d „  Z d	 „  Z d
 „  Z d „  Z  d e! f d „  ƒ  YZ" d S(   iÿÿÿÿN(   t   _(   t   uit   hgt   scmutilt   utilt	   templater(   t   errort   encoding(	   t   ErrorResponset	   get_mtimet
   staticfilet	   paritygent   ismembert   get_contactt   HTTP_OKt   HTTP_NOT_FOUNDt   HTTP_SERVER_ERROR(   t   hgwebt   makebreadcrumb(   t   wsgirequestc         C   s5   g  |  D]* \ } } t  j | ƒ j d ƒ | f ^ q S(   Nt   /(   R   t   pconvertt   strip(   t   itemst   namet   path(    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt
   cleannames   s    c         C   s×   g  } xÊ t  |  ƒ D]¼ \ } } t j j | ƒ \ } } y i t d 6t d 6| } Wn' t k
 r| | j | | f ƒ q n Xt j j t j j	 | ƒ ƒ } t
 j | d t d | ƒ}  | j t | | |  ƒ ƒ q W| S(   Nt   *s   **t	   followsymt   recurse(   R   t   osR   t   splitt   Falset   Truet   KeyErrort   appendt   normpatht   abspathR   t	   walkrepost   extendt   urlrepos(   t   pathst   repost   prefixt   roott   rootheadt   roottailR   (    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt	   findrepos   s    c         c   s_   xX | D]P } t  j j | ƒ } |  d t j | t | ƒ ƒ j d ƒ j d ƒ | f Vq Wd S(   sˆ  yield url paths and filesystem paths from a list of repo paths

    >>> conv = lambda seq: [(v, util.pconvert(p)) for v,p in seq]
    >>> conv(urlrepos('hg', '/opt', ['/opt/r', '/opt/r/r', '/opt']))
    [('hg/r', '/opt/r'), ('hg/r/r', '/opt/r/r'), ('hg', '/opt')]
    >>> conv(urlrepos('', '/opt', ['/opt/r', '/opt/r/r', '/opt']))
    [('r', '/opt/r'), ('r/r', '/opt/r/r'), ('', '/opt')]
    R   N(   R   R   R$   R   R   t   lent   lstripR   (   R+   R-   R)   R   (    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyR(   (   s    	c         C   sq   t  j |  ƒ } | j p d } | j r3 | j } n  | j p? d } | j d ƒ s^ d | } n  | t | ƒ | f S(   sê  
    Extract CGI variables from baseurl

    >>> geturlcgivars("http://host.org/base", "80")
    ('host.org', '80', '/base')
    >>> geturlcgivars("http://host.org:8000/base", "80")
    ('host.org', '8000', '/base')
    >>> geturlcgivars('/base', 8000)
    ('', '8000', '/base')
    >>> geturlcgivars("base", '8000')
    ('', '8000', '/base')
    >>> geturlcgivars("http://host", '8000')
    ('host', '8000', '/')
    >>> geturlcgivars("http://host/", '8000')
    ('host', '8000', '/')
    t    R   (   R   t   urlt   hostt   portR   t
   startswitht   str(   t   baseurlR5   t   uR   R   (    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt   geturlcgivars6   s    	t   hgwebdirc           B   se   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d d „ Z
 d	 „  Z d
 „  Z RS(   i   c         C   s2   | |  _  | |  _ d |  _ d  |  _ |  j ƒ  d  S(   Ni    (   t   conft   baseuit   lastrefresht   Nonet   motdt   refresh(   t   selfR<   R=   (    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt   __init__T   s
    				c         C   sc  |  j  |  j t j ƒ  k r  d  S|  j r; |  j j ƒ  } n2 t j ƒ  } | j d d d ƒ | j d d d ƒ t |  j t	 t
 t f ƒ s>i d d 6} t j j |  j ƒ sÉ t j t d ƒ |  j ƒ ‚ n  | j |  j d	 | d
 t ƒg  } x˜ | j d ƒ D]< \ } } x- | j d | ƒ D] } | j | | f ƒ qWqû WnH t |  j t
 t f ƒ rb|  j } n$ t |  j t	 ƒ r†|  j j ƒ  } n  t | ƒ } x« | j d ƒ D]š \ } }	 t j | ƒ } x| t j |	 d t ƒD]e } t j j | ƒ }
 t j |
 ƒ } | j | ƒ r| t | ƒ } n  | j | j d ƒ |
 f ƒ qÓWq¢W| |  _  | |  _ |  j j! d d t" j" ƒ t" _" |  j j! d d d ƒ |  _# |  j j! d d d  ƒ |  _% |  j j! d d d ƒ |  _& |  j& rßt' |  j& ƒ |  _& n  |  j j! d d ƒ |  _( |  j j! d d d ƒ } | j d ƒ r+| d } n  | j) d ƒ rG| d  } n  | |  _* t j ƒ  |  _  d  S(   NR   t   report_untrustedt   offt   nonttyt   trues   hgweb-pathsR)   s   config file %s not found!t   remapt   trustt   collectionsR   R   t   webR   t   stylet   papert	   templatest   stripesi   R8   R+   R2   iÿÿÿÿ(+   R>   t   refreshintervalt   timeR=   t   copyR   t	   setconfigt
   isinstanceR<   t   dictt   listt   tupleR   R   t   existsR   t   AbortR    t
   readconfigR!   t   configitemst
   configlistR#   R   R/   R   R   R&   R$   R6   R0   R1   R*   t   configR   RL   R?   t   templatepatht   stripecountt   intt   _baseurlt   endswithR+   (   RB   R9   t   mapR)   R   t   ignoredR   R*   R+   R,   t   repo(    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyRA   [   s\    	$				c         C   sP   t  j j d d ƒ j d ƒ s- t d ƒ ‚ n  d d  l j j } | j |  ƒ d  S(   Nt   GATEWAY_INTERFACER2   s   CGI/1.sJ   This function is only intended to be called while running as a CGI script.iÿÿÿÿ(	   R   t   environt   getR6   t   RuntimeErrort   mercurial.hgweb.wsgicgiR   t   wsgicgit   launch(   RB   Rk   (    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt   run   s    c         C   s   t  | | ƒ } |  j | ƒ S(   N(   R   t   run_wsgi(   RB   t   envt   respondt   req(    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt   __call__—   s    c         C   s†   | j  j d ƒ } | j d d d t ƒ} | rM | sI t | | | ƒ rM t S| j d d d t ƒ} | s~ t | | | ƒ r‚ t St S(   s  Check allow_read and deny_read config options of a repo's ui object
        to determine user permissions.  By default, with neither option set (or
        both empty), allow all users to read the repo.  There are two ways a
        user can be denied read access:  (1) deny_read is not empty, and the
        user is unauthenticated or deny_read contains user (or *), and (2)
        allow_read is not empty and the user is not in allow_read.  Return True
        if user is allowed to read the repo, else return False.t   REMOTE_USERRK   t	   deny_readt	   untrustedt
   allow_read(   Ro   Rh   R\   R!   R   R    (   RB   R   Rq   t   userRt   Rv   (    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt   read_allowed›   s    	c         C   s  zyÌ|  j  ƒ  | j j d d ƒ j d ƒ } |  j | ƒ } | d d t j ƒ} t j | ƒ } | j d ƒ s d | j k r?| j d ƒ r› | d } n | j d d	 } |  j	 j
 d
 d d  d t ƒ} | s+|  j pâ t j ƒ  } t | t ƒ r | g } n  g  | D] } t j j | d ƒ ^ q} n  t | | | ƒ g  S| se| j t | ƒ |  j | | ƒ St |  j ƒ }	 | }
 xÜ |
 rX|	 j |
 ƒ } | r,|
 | j d <y, t j |  j	 | ƒ } t | ƒ j | ƒ SWq,t k
 rþ} | j } t t  | ƒ ‚ q,t! j" k
 r(} t t  t | ƒ ƒ ‚ q,Xn  |
 j# d ƒ } | d	 k  rKPn  |
 |  }
 q}W| d } g  |	 D] } | j | ƒ rj| ^ qjr®| j t | ƒ |  j | | | ƒ S| j t$ | ƒ | d d | ƒSWn9 t k
 r
} | j | | ƒ | d d | j% pd ƒSXWd  d  } Xd  S(   Nt	   PATH_INFOR2   R   t   mimetypeR   s   static/t   statici   i    RK   Ru   t	   REPO_NAMEt   notfoundRe   R   (&   RA   Ro   Rh   R   R   R   t	   stringifyR6   t   formR   R]   R?   R    R^   RT   R7   R   R   t   joinR
   Rp   R   t	   makeindexRU   R*   R   t
   repositoryR   Rn   t   IOErrort   strerrorR   R   R   t	   RepoErrort   rfindR   t   message(   RB   Rq   t   virtualt   tmplt   ctypet   fnameR{   t   tpt   pR*   t   virtualrepot   realRe   t   instt   msgt   upt   subdirt   rt   err(    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyRn   ±   sf    
	+		
(R2   c   
         sn  d „  ‰  d ‡  ‡ ‡ f d † ‰ d  t f ‰ d t d ‡ ‡ ‡ f d † } ˆ j ƒ  d d d d g } ˆ \ } } d	 ˆ j k rÍ ˆ j d	 d
 } | j d ƒ } | rµ | d } n  | | k rÍ d } qÍ n  g  | D]9 } d | d | rý | | k rý d p d | f f ^ qÔ }	 ˆ j ƒ  ˆ j ˆ j ƒ | d d | d | d t d | ˆ j ƒ d | d | t	 |	 ƒ S(   Nc         S   s    |  j  d d d t ƒ} g  } x{ d d d g D]j } | d
 | k sd |  j d d | d
 d t ƒr. | j i | d
 d 6| d d 6| d 6| d 6ƒ q. q. W| S(   NRK   t   allow_archiveRu   t   zips   .zipt   gzs   .tar.gzt   bz2s   .tar.bz2i    t   allowt   typei   t	   extensiont   nodeR3   (   s   zips   .zip(   s   gzs   .tar.gz(   s   bz2s   .tar.bz2(   R\   R!   t
   configboolR#   (   R   t   nodeidR3   t   allowedt   archivest   i(    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt   archivelistø   s    '	R2   c         ;   sr  ˆ j  j d d t ƒ } ˆ j  j d d t ƒ } t ƒ  } t ƒ  } x)ˆ j D]\ } } | j |  ƒ sm qL n  | t |  ƒ } t } d | k r| s› qL n  | j d ƒ }	 |	 d }
 | s½ q|
 | k rÏ qL q|
 | k rÞ qt } |
 } d j	 |	 d ƒ } | t | ƒ d  } n  | g } d ˆ j
 k rP| j d ˆ j
 d j d ƒ ƒ n  ˆ j
 d rw| j d ˆ j
 d ƒ n  t j d	 d d j	 | ƒ d ƒ } | rIy  t | ƒ t j ƒ  d f } Wn t k
 rÕqL n Xt d
 d d d d | d d | d | d d d d d | d | d | d d g  d t ƒ } | j | ƒ | VqL n  ˆ j  j ƒ  ‰  y# ˆ  j t j j	 | d d ƒ ƒ Wn3 t k
 r°} ˆ  j t d ƒ | | f ƒ qL n Xd  ‡  f d † } ˆ  j d d d t ƒráqL n  ˆ j ˆ  ˆ ƒ sùqL n  y t j ˆ j  | ƒ } WnX t  k
 r?ˆ  j t d ƒ | ƒ qL n. t! j" k
 rlˆ  j t d ƒ | ƒ qL n Xy# t | j# ƒ t j ƒ  d f } Wn t k
 r¦qL n Xt$ | ƒ } | d d d ƒ } | d d | ƒ } t d
 | pæd d | j% ƒ  pød d | d | d | d | pd d | j% ƒ  p(d d | d | d | d d ˆ ˆ  d | ƒ ƒ 
} | j | ƒ | VqL Wd  S(   NRK   t   descendt   collapseR   i    i   Ry   t   SCRIPT_NAMEs   /+t   contactR2   t   contact_sortR   t	   name_sortR3   t   descriptiont   description_sortt
   lastchanget   lastchange_sortR¡   t   isdirectorys   .hgt   hgrcs   error reading %s/.hg/hgrc: %s
c            s   ˆ  j  |  | | d t ƒS(   NRu   (   R]   R!   (   t   sectionR   t   default(   R9   (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyRh   M  s    t   hiddenRu   s!   error accessing repository at %s
t   unknownt   tip(&   R   Rž   R!   R    t   setR*   R6   R0   R   R€   Ro   t   insertt   rstript   ret   subR	   R   t   makedatet   OSErrorRU   t   addRR   RZ   R   R   t	   Exceptiont   warnR    R?   Rx   R   R‚   Rƒ   R   R…   t   spathR   t   upper(   R“   Rc   R¤   R¥   t	   seenrepost   seendirsR   R   t	   directoryt	   namepartst   rootnamet	   discardedt   partsR3   t   dt   rowt   eRh   R”   R§   Rª   (   R£   Rq   RB   (   R9   s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt
   rawentries  s®    		
	#" 
	##c         ;   s”   ˆ d | |  } |  rX ˆ |  | f k rX d |  ‰  t  | d ‡  f d †  d | ƒ} n  x5 t | t ˆ j ƒ ƒ D] \ } } | | d <| Vqq Wd  S(   NR“   s   %s_sortt   keyc            s   |  ˆ  S(   N(    (   t   x(   t   sortkey(    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt   <lambda>{  s    t   reverset   parity(   t   sortedR—   R   R_   (   t
   sortcolumnt
   descendingR“   Rc   t   rowsRÉ   RÑ   (   RË   RB   t   sortdefault(   RÎ   s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt   entriesv  s    
%
R   Rª   R§   R¬   t   sorti    t   -i   s   sort_%ss   %s%st   indexR×   R“   t   pathdefR   RÓ   RÔ   (
   R?   R    RA   R   R6   t   updatereqenvRo   R   R+   RU   (
   RB   Rq   R‰   R“   R×   t   sortableRÓ   RÔ   t   columnRØ   (    (   R£   RË   Rq   RB   RÖ   s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyR   ö   s,    	
s
C
	c      	      sÊ  ‡ f d †  } ‡ f d †  } ‡  ‡ f d †  } d  t ‡ f d † ‰  ˆ j | j ƒ | j j d d ƒ } | j d ƒ s† | d 7} n  i  } | j j d d  g ƒ d	 ˆ  d
 d ƒ d f } t j | ˆ j	 ƒ \ } }	 | | d	 k rò | | d <n  | d d k rd pd }
 t
 j | |
 ƒ } ˆ  d
 d d ƒ } ˆ  d
 d d ƒ } ˆ  d
 d ƒ pZ| d } | j d ƒ sy| d 7} n  t j |	 d i | d 6| d 6| d 6| d 6| d 6| d 6| d 6| d 6ƒ‰ ˆ S(   Nc          ;   s   ˆ  d d t  j  |  Vd  S(   Nt   headerR   (   R   (   Rc   (   R‰   (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyRß   ›  s    c          ;   s   ˆ  d |   Vd  S(   Nt   footer(    (   Rc   (   R‰   (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyRà   ž  s    c          ;   s/   ˆ j  d  k	 r ˆ j  Vn ˆ  d d d ƒ Vd  S(   NRK   R@   R2   (   R@   R?   (   Rc   (   R]   RB   (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyR@   ¡  s    c            s   ˆ  j  j |  | | | ƒ S(   N(   R   R]   (   R°   R   R±   Ru   (   RB   (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyR]   §  s    R¦   R2   R   RL   i    RK   RM   iÿÿÿÿt   ?t   &t   logourls   http://mercurial.selenic.com/t   logoimgs
   hglogo.pngt	   staticurls   static/t   defaultsRß   Rà   R@   R3   t   sessionvars(   R?   R!   RÜ   Ro   Rh   Rb   R   R   t   stylemapR^   t   webutilRç   (   RB   Rq   Rß   Rà   R@   R3   t   varst   stylesRL   t   mapfilet   startRç   Rã   Rä   Rå   (    (   R]   RB   R‰   s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyR   ™  s@    	
c         C   sS   |  j  d  k	 rO t |  j  | d ƒ \ } } } | | d <| | d <| | d <n  d  S(   Nt   SERVER_PORTt   SERVER_NAMER¦   (   Ra   R?   R:   (   RB   Ro   R   R5   R   (    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyRÜ   Í  s
    

N(   t   __name__t
   __module__RP   R?   RC   RA   Rm   Rr   Rx   Rn   R   R   RÜ   (    (    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyR;   Q   s   	5				E£	4(#   R   R¸   RQ   t   mercurial.i18nR    t	   mercurialR   R   R   R   R   R   R   t   commonR   R	   R
   R   R   R   R   R   R   t	   hgweb_modR   R   t   requestR   Ré   R   R/   R(   R:   t   objectR;   (    (    (    s@   /sys/lib/python2.7/site-packages/mercurial/hgweb/hgwebdir_mod.pyt   <module>	   s   $(@				