ó
ŸçƒQc           @   sí   d  d l  Z  d  d l Z d  d l Z d Z d Z d Z d Z d Z d Z d Z	 d	 Z
 d
 „  Z d „  Z e g Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d d „ Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d S(   iÿÿÿÿNiÈ   i0  i  i‘  i“  i”  i•  iô  c         C   s   | d g k p | | k S(   sÑ   Check if username is a member of userlist.

    If userlist has a single '*' member, all users are considered members.
    Can be overriden by extensions to provide more complex authorization
    schemes.
    t   *(    (   t   uit   usernamet   userlist(    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt   ismember   s    c   
      C   sá  | j  j d ƒ } |  j d d ƒ } | r[ | sI t |  j j | | ƒ r[ t t d ƒ ‚ n  |  j d d ƒ } | rž t |  j j | | ƒ rž t t d ƒ ‚ n  | d k rÆ |  j rÆ t t d ƒ ‚ n | d k sÞ | d k râ d S| j  d	 d
 k rd } t t
 | ƒ ‚ n  | j  j d ƒ } |  j d d t ƒ rR| d k rRt t d ƒ ‚ n  |  j d d ƒ } | r›| s‰t |  j j | | ƒ r›t t d ƒ ‚ n  |  j d d ƒ }	 |	 oÈt |  j j | |	 ƒ sÝt t d ƒ ‚ n  d S(   sš   Check permission for operation based on request data (including
    authentication info). Return if op allowed, else raise an ErrorResponse
    exception.t   REMOTE_USERt   webt	   deny_reads   read not authorizedt
   allow_readt   pulls   pull not authorizedNt   REQUEST_METHODt   POSTs   push requires POST requests   wsgi.url_schemet   push_sslt   httpss   ssl requiredt	   deny_pushs   push not authorizedt
   allow_push(   t   envt   gett
   configlistR   t   repoR   t   ErrorResponset   HTTP_UNAUTHORIZEDt	   allowpullt   Nonet   HTTP_METHOD_NOT_ALLOWEDt
   configboolt   Truet   HTTP_FORBIDDEN(
   t   hgwebt   reqt   opt   userR   R   t   msgt   schemet   denyt   allow(    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt
   checkauthz   s.    %!%R   c           B   s    e  Z d g  d  „ Z d „  Z RS(   c         C   sG   | d  k r t | ƒ } n  t j |  ƒ | |  _ | |  _ | |  _ d  S(   N(   R   t   _statusmessaget	   Exceptiont   __init__t   codet   messaget   headers(   t   selfR(   R)   R*   (    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyR'   P   s    		c         C   s   |  j  S(   N(   R)   (   R+   (    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt   __str__W   s    N(   t   __name__t
   __module__R   R'   R,   (    (    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyR   O   s   t   continuereaderc           B   s&   e  Z d  „  Z d d „ Z d „  Z RS(   c         C   s   | |  _  | |  _ t |  _ d  S(   N(   t   ft   _writet   Falset	   continued(   R+   R0   t   write(    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyR'   [   s    		iÿÿÿÿc         C   s2   |  j  s" t |  _  |  j d ƒ n  |  j j | ƒ S(   Ns   HTTP/1.1 100 Continue

(   R3   R   R1   R0   t   read(   R+   t   amt(    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyR5   `   s    		c         C   s&   | d k r t  |  j | ƒ St ‚ d  S(   Nt   closet   readlinet	   readlinest   __iter__(   s   closes   readlines	   readliness   __iter__(   t   getattrR0   t   AttributeError(   R+   t   attr(    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt   __getattr__f   s    (   R-   R.   R'   R5   R>   (    (    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyR/   Z   s   	c         C   s-   d d l  m } | j } | j |  d ƒ d S(   Niÿÿÿÿ(   t   BaseHTTPRequestHandlert   Errors   Unknown errori    (   s   Errors   Unknown error(   t   BaseHTTPServerR?   t	   responsesR   (   R(   R?   RB   (    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyR%   k   s    	c         C   s   d |  | p t  |  ƒ f S(   Ns   %d %s(   R%   (   R(   R)   (    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt   statusmessagep   s    c         C   sE   t  j j |  d ƒ } t  j j | ƒ r4 t  j | ƒ St  j |  ƒ Sd S(   s,   stat changelog if it exists, spath otherwises   00changelog.iN(   t   ost   patht   joint   existst   stat(   t   spatht   cl_path(    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt   get_stats   s    c         C   s   t  |  ƒ j S(   N(   RK   t   st_mtime(   RI   (    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt	   get_mtime{   s    c         C   s¦  | j  d ƒ } xZ | D]R } | d t j t j f k sd t j | k sd t j d k	 r t j | k r d Sq Wt j j | Œ  } t	 |  t
 ƒ r™ |  g }  n  x9 |  D]1 } t j j | | ƒ } t j j | ƒ r  Pq  q  Wye t j | ƒ t j | ƒ d pû d } t | d ƒ }	 |	 j ƒ  }
 |	 j ƒ  | j t | d |
 ƒWne t k
 r\t t d ƒ ‚ nF t k
 r¡} | j t j k rŒt t ƒ ‚ q¢t t | j ƒ ‚ n Xd S(	   s+  return a file inside directory with guessed Content-Type header

    fname always uses '/' as directory separator and isn't allowed to
    contain unusual path components.
    Content-Type is guessed using the mimetypes module.
    Return an empty string if fname is illegal or file not found.

    t   /t    Ni    s
   text/plaint   rbt   bodys   illegal filename(   t   splitRD   t   curdirt   pardirt   sept   altsepR   RE   RF   t
   isinstancet   strRG   RH   t	   mimetypest
   guess_typet   openR5   R7   t   respondt   HTTP_OKt	   TypeErrorR   t   HTTP_SERVER_ERRORt   OSErrort   errnot   ENOENTt   HTTP_NOT_FOUNDt   strerror(   t	   directoryt   fnameR   t   partst   partt   fpatht   dRE   t   ctt   fpt   datat   err(    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt
   staticfile~   s2    	-
i    c         c   s€   |  r/ | r/ |  | |  } |  | |  d @} n d } d } x> t  r{ | V| d 7} |  r> | |  k r> d | } d } q> q> Wd S(   s5   count parity of horizontal stripes for easier readingi   i    N(   R   (   t   stripecountt   offsett   countt   parity(    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt	   paritygen¢   s    	

c         C   s4   |  d d ƒ p3 |  d d ƒ p3 t  j j d ƒ p3 d S(   s¾   Return repo contact information or empty string.

    web.contact is the primary source, but if that is not set, try
    ui.username or $EMAIL as a fallback to display something useful.
    R   t   contactR   R   t   EMAILRO   (   RD   t   environR   (   t   config(    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt   get_contact²   s    c         C   sP   t  |  j ƒ } | j j d ƒ | k r6 t t ƒ ‚ n  | j j d | f ƒ d  S(   Nt   HTTP_IF_NONE_MATCHt   ETag(   RX   t   mtimeR   R   R   t   HTTP_NOT_MODIFIEDR*   t   append(   R   R   t   tag(    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt   caching¼   s    (   Ra   RY   RD   R]   R}   t   HTTP_BAD_REQUESTR   R   Rc   R   R_   R   R$   t	   permhooksR&   R   t   objectR/   R%   R   RC   RK   RM   Ro   Rt   Ry   R€   (    (    (    s:   /sys/lib/python2.7/site-packages/mercurial/hgweb/common.pyt   <module>	   s*   $			.					$	
