
Qc           @   sq
  d  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 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 e j d k rd d l Z n d d l Z e j Z e j Z e j Z e j Z e j Z e j Z e j  Z  e j! Z! e j" Z" e j# Z# e j$ Z$ e j% Z% e j& Z& e j' Z' e j( Z( e j) Z) e j* Z* e j+ Z+ e j, Z, e j- Z- e j. Z. e j/ Z/ e j0 Z0 e j1 Z1 e j2 Z2 e j3 Z3 e j4 Z4 e j5 Z5 e j6 Z6 e j7 Z7 e j8 Z8 e j9 Z9 e j: Z: e j; Z; e j< Z< e j= Z= e j> Z> e j? Z? e j@ Z@ e jA ZA eB e d e jC  ZC e jD ZD e jE ZE e jF ZF e jG ZG e jH ZH e jI ZI e jJ ZJ e jK ZK eL   ZM d   ZN d d  aO d d	  aP y
 eQ ZQ Wn? eR k
 r^e
 jS d
 d k  rOd
 d  ZQ n d
 d  ZQ n Xd d lT ZT e j d k ZU eV eW d  ZX eV eW d  ZY eV eW d  ZZ d   Z[ d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* f Z\ e\ d+ d, d- d. f Z] d/   Z^ y e j_ j` e j_ Z_ Wn* ea k
 r`d0 e j_ f d1     YZ_ n Xd2 eL f d3     YZb d4   Zc d5 eL f d6     YZd d7   Ze d8   Zf i ef d9 6ee d: 6Zg d;   Zh d<   Zi d= d> d?  Zj e jk Zk d@   Zl dA   Zm dB   Zn eV ao dC   Zp dD   Zq dE   Zr i  eV eV eV eV dF  Zs dG   Zt dH   Zu eV dI  Zv dJ j@   Zw dK Zx dL   Zy e j d k rey Zz n	 e jz Zz dM   Z{ dN   Z| dO   Z} dP   Z~ y d d l Z eV a Wn e k
 reW a n Xd
 dQ  Z i  Z dR   Z dS   Z dT   Z dU   Z dV   Z eW eV dW  Z dX eL f dY     YZ eV eW dZ  Z eV d[  Z d\   Z d]   Z d^   Z d_ eL f d`     YZ d> eV da  Z db   Z eV dc dd  Z eV de  Z g  df  Z eV i  dg  Z dh   Z di   Z dj   Z dk   Z dl   Z dm dn  Z do   Z e dp dq dr >e ds  f dt dq dr >e du  f dq dq dr >e dv  f dp dq dw >e dx  f dt dq dw >e dy  f dq dq dw >e dz  f dp dq dt >e d{  f dt dq dt >e d|  f dq dq dt >e d}  f dq dq e d~  f 
 Z d   Z d   a d d d  Z d   Z d   Z d   Z d   Z y e e f \ Z Z Wn# eR k
 rd   Z d   Z n XeV eW d  Z d   Z i
 e d 6e d 6e d 6e d 6e d 6eW d 6eW d 6eW d 6eW d 6eW d 6Z d   Z d Z e d   e D  Z d   Z d eL f d     YZ d   Z d   Z d   Z d   Z d   Z d   Z e dq d e d  f dp dq e d  f dt dq e d  f dq dq e d  f dp d e d  f dt d e d  f dq d e d  f dp d e d  f dt d e d  f dq d e d  f dp d e d  f dt d e d  f dq d e d  f  Z d
 g Z d   Z d S(   s   Mercurial utility functions and platform specific implementations.

This contains helper routines that are independent of the SCM core and
hide platform-specific details from the core.
i(   t   _Nt   ntt	   statfilesc         C   s   t  |  | t  t k	 S(   N(   t   getattrt   _notset(   t   thingt   attr(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   safehasattrQ   s    t    c         C   s
   t  |   S(   s   
    Low-overhead wrapper around Python's SHA support

    >>> f = _fastsha1
    >>> a = sha1()
    >>> a = f()
    >>> a.hexdigest()
    'da39a3ee5e6b4b0d3255bfef95601890afd80709'
    (   t	   _fastsha1(   t   s(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   sha1T   s    c         C   sF   t  j d k r" d d l m } n d d l m } | a a | |   S(   Ni   i   i(   R   (   t   sha(   i   i   (   t   syst   version_infot   hashlibR   R   R	   (   R
   t   _sha1(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR	   a   s
    
i    i   c         C   s   |  | S(   N(    (   t	   sliceablet   offset(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   bufferq   s    c         C   s   t  |   | S(   N(   t
   memoryview(   R   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR   t   s    t   posixc         C   sO   t  j |  d t d d d t d t  j d t  j d | d | } | j | j f S(	   Nt   shellt   bufsizeit	   close_fdst   stdint   stdoutt   universal_newlinest   env(   t
   subprocesst   Popent   Truet   closefdst   PIPER   R   (   t   cmdR   t   newlinest   p(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   popen2z   s    	c         C   s+   t  |  | |  \ } } } } | | | f S(   N(   t   popen4(   R"   R   R#   R   R   t   stderrR$   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   popen3   s    c         C   sa   t  j |  d t d d d t d t  j d t  j d t  j d | d	 | } | j | j | j | f S(
   NR   R   iR   R   R   R'   R   R   (   R   R   R   R    R!   R   R   R'   (   R"   R   R#   R$   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR&      s    		c          C   s0   y d d l  }  |  j SWn t k
 r+ d SXd S(   s(   Return version information if available.iNt   unknown(   t   __version__t   versiont   ImportError(   R*   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR+      s
    s   %Y-%m-%d %H:%M:%Ss   %Y-%m-%d %I:%M:%S%ps   %Y-%m-%d %H:%Ms   %Y-%m-%d %I:%M%ps   %Y-%m-%ds   %m-%ds   %m/%ds   %m/%d/%ys   %m/%d/%Ys   %a %b %d %H:%M:%S %Ys   %a %b %d %I:%M:%S%p %Ys   %a, %d %b %Y %H:%M:%Ss   %b %d %H:%M:%S %Ys   %b %d %I:%M:%S%p %Ys   %b %d %H:%M:%Ss   %b %d %I:%M:%S%ps   %b %d %H:%Ms   %b %d %I:%M%ps   %b %d %Ys   %b %ds   %H:%M:%Ss
   %I:%M:%S%ps   %H:%Ms   %I:%M%ps   %Ys   %Y-%ms   %bs   %b %Yc            sC   i     j  j d k r-    f d   } n    f d   } | S(   s"   cache the result of function callsi   c            s'   |    k r  |     |  <n    |  S(   N(    (   t   arg(   t   cachet   func(    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   f   s    c             s'   |    k r  |      |  <n    |  S(   N(    (   t   args(   R.   R/   (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR0      s    (   t	   func_codet   co_argcount(   R/   R0   (    (   R.   R/   s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   cachefunc   s
    t   dequec           B   s   e  Z d    Z RS(   c         C   s8   x1 t  |   D]# \ } } | | k r |  | =Pq q Wd  S(   N(   t	   enumerate(   t   selft   valt   it   v(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   remove   s    (   t   __name__t
   __module__R;   (    (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR5      s   t   lrucachedictc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s6   cache most recent gets from or sets to this dictionaryc         C   s"   i  |  _  | |  _ t   |  _ d  S(   N(   t   _cachet   _maxsizeR5   t   _order(   R7   t   maxsize(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   __init__   s    		c         C   s1   |  j  | } |  j j |  |  j j |  | S(   N(   R?   RA   R;   t   append(   R7   t   keyt   value(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   __getitem__   s    c         C   sq   | |  j  k r@ t |  j   |  j k rP |  j  |  j j   =qP n |  j j |  | |  j  | <|  j j |  d  S(   N(   R?   t   lenR@   RA   t   popleftR;   RD   (   R7   RE   RF   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   __setitem__   s    c         C   s   | |  j  k S(   N(   R?   (   R7   RE   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   __contains__   s    (   R<   R=   t   __doc__RC   RG   RJ   RK   (    (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR>      s
   				c            sR   i    t      j j d k r9     f d   } n     f d   } | S(   s+   cache most recent results of function callsi   c            sc   |    k rA t     d k r.    j   =n   |     |  <n  j |    j |     |  S(   Ni   (   RH   RI   R;   RD   (   R-   (   R.   R/   t   order(    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR0      s    c             sc   |    k rA t     d k r.    j   =n   |      |  <n  j |    j |     |  S(   Ni   (   RH   RI   R;   RD   (   R1   (   R.   R/   RM   (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR0     s    (   R5   R2   R3   (   R/   R0   (    (   R.   R/   RM   s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   lrucachefunc   s    	

t   propertycachec           B   s&   e  Z d    Z d d  Z d   Z RS(   c         C   s   | |  _  | j |  _ d  S(   N(   R/   R<   t   name(   R7   R/   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRC     s    	c         C   s#   |  j  |  } |  j | |  | S(   N(   R/   t
   cachevalue(   R7   t   objt   typet   result(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   __get__  s    c         C   s   t  | |  j |  d  S(   N(   t   setattrRP   (   R7   RR   RF   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRQ     s    N(   R<   R=   RC   t   NoneRU   RQ   (    (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRO     s   	c      
   C   sF   t  j | d t d t d t  j d t  j } | j |   \ } } | S(   s9   filter string S through command CMD, returning its outputR   R   R   R   (   R   R   R   R    R!   t   communicate(   R
   R"   R$   t   poutt   perr(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt
   pipefilter  s    c   	      C   s  d \ } } zt j d d  \ } } t j | d  } | j |   | j   t j d d  \ } } t j |  | j d |  } | j d |  } t j |  } t	 j
 d k r | d @r d	 } n  | r t t d
  | t |  f   n  t | d  } | j   } | j   | SWd y | r;t j |  n  Wn t k
 rOn Xy | rit j |  n  Wn t k
 r}n XXd S(   s   filter string S through a pair of temporary files with CMD.
    CMD is used as a template to create the real command to be run,
    with the strings INFILE and OUTFILE replaced by the real names of
    the temporary files generated.t   prefixs   hg-filter-in-t   wbs   hg-filter-out-t   INFILEt   OUTFILEt   OpenVMSi   i    s   command '%s' failed: %st   rbN(   NN(   RW   t   tempfilet   mkstempt   ost   fdopent   writet   closet   replacet   systemR   t   platformt   AbortR    t   explainexitt   opent   readt   unlinkt   OSError(	   R
   R"   t   innamet   outnamet   infdt   fpt   outfdt   codet   r(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt
   tempfilter#  s<    
	
s	   tempfile:s   pipe:c         C   sV   xF t  j   D]8 \ } } | j |  r | |  | t |  j    Sq Wt |  |  S(   sI   filter a string through a command that transforms its input to its output(   t   filtertablet	   iteritemst
   startswithRH   t   lstripR[   (   R
   R"   RP   t   fn(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   filterM  s    !c         C   s   t  |  o d |  k  S(   s&   return true if a string is binary datat    (   t   bool(   R
   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   binaryT  s    i   i   c         c   s   d   } g  } d } x |  D] } | j  |  | t |  7} | | k r | | k  r | d >} d | |  >} | | k r | } n  | | k r | } q n  d j |  Vd } g  } q q W| r d j |  Vn  d S(   sr   return no less than min bytes per chunk while data remains,
    doubling min after each chunk until it reaches maxc         S   s9   |  s
 d Sd } x |  r0 |  d L}  | d 7} q W| d S(   Ni    i   (    (   t   xR9   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   log2[  s    	
i    i   R   N(   RD   RH   t   join(   t   sourcet   mint   maxR   t   buft   blent   chunkt   nmin(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   increasingchunksX  s&    		
	c         C   s   t  S(   N(   R   (   R}   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   alwaysy  s    c         C   s   t  S(   N(   t   False(   R}   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   never|  s    c         C   s!  | s t  |  St j j |  r t j j |   d t j j |  d k rg t j j |  t  |   Sd j t |   | f  } n  t |  | j d  } } | j	   | j	   x8 | r | r | d | d k r | j
   | j
   q W| j	   t j j d g t |  |  p d S(   sa  return the relative path from one place to another.
    root should use os.sep to separate directories
    n1 should use os.sep to separate directories
    n2 should use "/" to separate directories
    returns an os.sep-separated path.

    If n1 is a relative path, it's assumed it's
    relative to root.
    n2 should always be relative to root.
    i    t   /is   ..t   .(   t	   localpathRd   t   patht   isabst
   splitdriveR   t   pconvertt	   splitpatht   splitt   reverset   popt   sepRH   (   t   roott   n1t   n2t   at   b(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   pathto  s    
,

#

c           C   s+   t  t d  p* t  t d  p* t j d  S(   s   return True if we are a frozen executable.

    The code supports py2exe (most common, Windows only) and tools/freeze
    (portable, not much used).
    t   frozent	   importerst   __main__(   R   R   t   impt	   is_frozen(    (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt
   mainfrozen  s    c          C   s   t  d k r t j j d  }  t j d } |  r> t |   q t   rW t t j	  q t j
 j t | d d   d k r t | j  q t d  p t j
 j t j d  } t |  n  t  S(   s]   return location of the 'hg' executable.

    Defaults to $HG or 'hg' in the search path.
    t   HGR   t   __file__R   t   hgi    N(   t   _hgexecutableRW   Rd   t   environt   getR   t   modulest   _sethgexecutableR   t
   executableR   t   basenameR   R   t   findexet   argv(   R   t   mainmodt   exe(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   hgexecutable  s    	$%c         C   s
   |  a  d S(   s#   set location of the 'hg' executableN(   R   (   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR     s    c            s'  y t  j j   Wn t k
 r$ n Xd     |  } t |   }  t  j d k r} | d k	 rk t j |  n  t j	 |   } nt
 t j  } | j   f d   | j   D  t   | d <| d k s | t  j k rt j |  d t d t d | d | } nm t j |  d t d t d | d | d	 t j d
 t j }	 x |	 j D] }
 | j |
  qDW|	 j   |	 j } t  j d k r| d @rd } n  | r#| r#d t j j | j d d  d  t |  d f } | rd | | f } n  y | j | d  Wq#t k
 r| |   q#Xn  | S(   s  enhanced shell command execution.
    run with environment maybe modified, maybe in different dir.

    if command fails and onerr is None, return status.  if ui object,
    print error message and return status, else raise onerr object as
    exception.

    if out is specified, it is assumed to be a file-like object that has a
    write() method. stdout and stderr will be redirected to out.c         S   s6   |  d k s |  t k r d S|  t k r, d St |   S(   s9   convert python object into string that is useful to shellt   0t   1N(   RW   R   R   t   str(   R8   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   py2shell  s
    t   plan9c         3   s'   |  ] \ } } |   |  f Vq d  S(   N(    (   t   .0t   kR:   (   R   (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pys	   <genexpr>  s    R   R   R   R   t   cwdR   R'   R`   i   i    s   %s %ss   %s: %ss   
N(    R   R   t   flusht	   Exceptiont   quotecommandRj   RW   Rd   t   chdirRi   t   dictR   t   updateRz   R   t
   __stdout__R   t   callR   R    R   R!   t   STDOUTRf   t   waitt
   returncodeR   R   R   Rl   t   warnt   AttributeError(   R"   R   R   t   onerrt	   errprefixt   outt   origcmdt   rcR   t   proct   linet   errmsg(    (   R   s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRi     sH    
	#
		"c            s     f d   } | S(   s5   wrap a function with code to check for calling errorsc             s]   y   |  |   SWnE t  k
 rX t t j t j   d   d k rR t j  n    n Xd  S(   Ni   i   (   t	   TypeErrorRH   t	   tracebackt
   extract_tbR   t   exc_infot   errort   SignatureError(   R1   t   kwargs(   R/   (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   check  s    %(    (   R/   R   (    (   R/   s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   checksignature  s    c         C   s   t  j j |  r t |  n  t  j j |   rM t  j t  j |   |  nO y$ t j |  |  t j	 |  |  Wn( t j
 k
 r } t t |    n Xd S(   s,   copy a file, preserving mode and atime/mtimeN(   Rd   R   t   lexistsRo   t   islinkt   symlinkt   readlinkt   shutilt   copyfilet   copymodet   ErrorRk   R   (   t   srct   destt   inst(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR     s    c   	      C   sA  | d k r? t j |   j t j t j j |   j k } n  d } t j j |   r t j |  x t j	 |   D]X \ } } t j j
 |  |  } t j j
 | |  } t | | |  \ } } | | 7} qt Wnd | ry t |  |  Wq-t t f k
 rt } t j |  |  q-Xn t j |  |  | d 7} | | f S(   s1   Copy a directory tree using hardlinks if possiblei    i   N(   RW   Rd   t   statt   st_devR   t   dirnamet   isdirt   mkdirt   osutilt   listdirR   t	   copyfilest   oslinkt   IOErrorRp   R   R   t   copy(	   R   t   dstt   hardlinkt   numRP   t   kindt   srcnamet   dstnamet   n(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR     s(    $
sq   con prn aux nul
    com1 com2 com3 com4 com5 com6 com7 com8 com9
    lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9s   :*?"<>|c         C   s   x |  j  d d  j d  D] } | s. q n  xH | D]@ } | t k rU t d  | St |  d k r5 t d  | Sq5 W| j d  d } | r | j   t k r t d  | S| d } | d	 k r | d
 k r t d  | Sq Wd S(   s  Check that the base-relative path is a valid filename on Windows.
    Returns None if the path is ok, or a UI string describing the problem.

    >>> checkwinfilename("just/a/normal/path")
    >>> checkwinfilename("foo/bar/con.xml")
    "filename contains 'con', which is reserved on Windows"
    >>> checkwinfilename("foo/con.xml/bar")
    "filename contains 'con', which is reserved on Windows"
    >>> checkwinfilename("foo/bar/xml.con")
    >>> checkwinfilename("foo/bar/AUX/bla.txt")
    "filename contains 'AUX', which is reserved on Windows"
    >>> checkwinfilename("foo/bar/bla:.txt")
    "filename contains ':', which is reserved on Windows"
    >>> checkwinfilename("foo/bar/bla.txt")
    "filename contains '\\x07', which is invalid on Windows"
    >>> checkwinfilename("foo/bar/bla ")
    "filename ends with ' ', which is not allowed on Windows"
    >>> checkwinfilename("../bar")
    s   \R   s4   filename contains '%s', which is reserved on Windowsi   s1   filename contains %r, which is invalid on WindowsR   i    is   . s   ..s8   filename ends with '%s', which is not allowed on WindowsN(   Rh   R   t   _winreservedcharsR    t   ordt   lowert   _winreservednames(   R   R   t   ct   baset   t(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   checkwinfilename/  s$    "				
	c         C   s   y t  j |  |  SWn; t k
 rA } | j t j k rR   qR n t k
 rQ n Xt  j | t  j t  j Bt  j	 B } t  j
 | |   t  j |  d  S(   N(   Rd   R   Rp   t   errnot   EEXISTR   Rm   t   O_CREATt   O_WRONLYt   O_EXCLRf   Rg   (   t   infot   pathnamet   whyt   ld(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   makelock[  s    	#c         C   s~   y t  j |   SWnD t k
 rG } | j t j t j f k rX   qX n t k
 rW n Xt |   } | j   } | j	   | S(   N(
   Rd   R   Rp   R  t   EINVALt   ENOSYSR   t	   posixfileRn   Rg   (   R  R	  Rt   Rw   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   readlockh  s    	
c         C   s<   y t  j |  j    SWn t k
 r7 t  j |  j  SXd S(   s1   stat file object that may not have fileno method.N(   Rd   t   fstatt   filenoR   R   RP   (   Rt   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR  u  s    c         C   s   t  j |   } t  j j |   \ } } | j   } | | k r^ | j   } | | k r^ t Sn  t  j j | |  } y' t  j |  } | | k r t St SWn t	 k
 r t SXd S(   s   
    Return true if the given path is on a case-sensitive filesystem

    Requires a path (like /foo/.hg) ending with a foldable final
    directory component.
    N(
   Rd   R   R   R   t   upperR   R   R   R   Rp   (   R   t   s1t   dR   t   b2t   p2t   s2(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   checkcase~  s    c         C   s   t  d k r: y t j t a  Wq: t k
 r6 t a  q: Xn  t  r | t j t j	 B@d k r | t j @ru d |  }  n  | t j	 @r d |  }  n  y t j |   SWq t j
 k
 r q Xn  t j |  |  S(   s   Compile a regular expression, using re2 if possible

    For best performance, use only re2-compatible regexp features. The
    only flags from the re module that are re2-compatible are
    IGNORECASE and MULTILINE.i    s   (?i)s   (?m)N(   t   _re2RW   t   re2t   compileR   R,   R   t   ret
   IGNORECASEt	   MULTILINER   (   t   patt   flags(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   compilere  s     
!c         C   sF  d   } t  j } t  j r+ | t  j } n  | j d d  t j d | | f  } t  j j |  } g  } x | j |   D] \ } } | r | j	 |  q| n  | t
 k r t  j |  t
 | <n  t
 | }	 | | |	  }
 |
 st  j |  }	 |	 t
 | <| | |	  }
 n  | j	 |
 p|  t  j j | |  } q| Wd j |  S(   s4  Get name in the case stored in the filesystem

    The name should be relative to root, and be normcase-ed for efficiency.

    Note that this function is unnecessary, and should not be
    called, for case-sensitive filesystems (simply because it's expensive).

    The root should be normcase-ed, too.
    c         S   s+   x$ | D] } t  |  |  k r | Sq Wd  S(   N(   t   normcaseRW   (   R$   t   contentsR   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   find  s    s   \s   \\s   ([^%s]+)|([%s]+)R   (   Rd   R   t   altsepRh   R  R  R   t   normpatht   findallRD   t   _fspathcacheR   R   (   RP   R   R$  t   sepst   patternt   dirRT   t   partR   R#  t   found(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   fspath  s.    
			

c      	   C   s   |  d } t  j j |  r  t Sy t | d  j   Wn t k
 rK t SX|  d } d } zF y t | |  Wn t	 k
 r t SXt |  } t
 |  d k SWd | d k	 r | j   n  x9 | | f D]+ } y t  j |  Wq t	 k
 r q Xq WXd S(   s5   check whether hardlink count reporting works properlys   .hgtmp1t   ws   .hgtmp2i   N(   Rd   R   R   R   R  Rg   R   RW   R   Rp   t   nlinksRo   (   t   testfilet   f1t   f2t   fdR0   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt
   checknlink  s.    

c         C   s+   |  j  t j  p* t j o* |  j  t j  S(   s)   Check path ends with os.sep or os.altsep.(   t   endswithRd   R   R%  (   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   endswithsep  s    c         C   s   |  j  t j  S(   s   Split path by os.sep.
    Note that this function does not use os.altsep because this is
    an alternative of simple "xxx.split(os.sep)".
    It is recommended to use os.path.normpath() before using this
    function if need.(   R   Rd   R   (   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR     s    c           C   sh   t  j d k rE d t j k r" t St t d d  r> t j   St	 Sn t j
 d k pc t j j d  Sd S(   s   Are we running in a GUI?t   darwint   SSH_CONNECTIONt   isguiR   t   DISPLAYN(   R   Rj   Rd   R   R   R   R   RW   R:  R   RP   R   (    (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   gui  s    
c         C   sB  t  j j |   \ } } t j d d | d |  \ } } t  j |  t |  | |  | ra | Sy y t |  d  } WnJ t k
 r } | j	 t	 j
 k r | St | d d  s |  | _ n    n Xt | d  }	 x! t |  D] }
 |	 j |
  q W| j   |	 j   Wn/ y t  j |  Wn t k
 r6n X  n X| S(   s  Create a temporary file with the same contents from name

    The permission bits are copied from the original file.

    If the temporary file is going to be truncated immediately, you
    can use emptyok=True as an optimization.

    Returns the name of the temporary file.
    R\   s   .%s-R+  Ra   t   filenameR]   N(   Rd   R   R   Rb   Rc   Rg   R   R  R   R  t   ENOENTR   RW   R=  t   filechunkiterRf   Ro   Rp   (   RP   t   emptyokt
   createmodeR  R}   R4  t   tempt   ifpR   t   ofpR   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt
   mktempcopy  s6    
"
  t   atomictempfilec           B   s8   e  Z d  Z d d d  Z d   Z d   Z d   Z RS(   sf  writable file object that atomically updates a file

    All writes will go to a temporary copy of the original file. Call
    close() when you are done writing, and atomictempfile will rename
    the temporary copy to the original name, making the changes
    visible. If the object is destroyed without being closed, all your
    writes are discarded.
    s   w+bc         C   s   | |  _  t | d d | k d | |  _ t |  j |  |  _ |  j j |  _ |  j j |  _ |  j j |  _ |  j j |  _ d  S(   NR@  R/  RA  (	   t   _atomictempfile__nameRE  t	   _tempnameR  t   _fpRf   t   seekt   tellR  (   R7   RP   t   modeRA  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRC   O  s    	c         C   s9   |  j  j s5 |  j  j   t |  j t |  j   n  d  S(   N(   RI  t   closedRg   t   renameRH  R   RG  (   R7   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRg   [  s    c         C   sH   |  j  j sD y t j |  j  Wn t k
 r3 n X|  j  j   n  d  S(   N(   RI  RM  Rd   Ro   RH  Rp   Rg   (   R7   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   discard`  s    c         C   s    t  |  d  r |  j   n  d  S(   NRI  (   R   RO  (   R7   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   __del__h  s    N(   R<   R=   RL   RW   RC   Rg   RO  RP  (    (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRF  F  s
   		c         C   s   y t  |  |  Wn t k
 r } | j t j k r9 d S| j t j k sR |  rX   n  t j j t j j |    } | |  k r   n  t	 | | |  t  |  |  n X| d k	 r t j |  |  n  d S(   s9   recursive directory creation with parent mode inheritanceN(   t   makedirRp   R  R  R>  Rd   R   R   t   abspatht   makedirsRW   t   chmod(   RP   RL  t
   notindexedt   errt   parent(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRS  l  s    c         C   s   t  j j |   r d St  j j t  j j |    } | |  k rP t | |  n  y t  j |   Wn> t k
 r } | j t j	 k r t  j j |   r d S  n X| d k	 r t  j |  |  n  d S(   s&   race-safe recursive directory creationN(   Rd   R   R   R   RR  t
   ensuredirsR   Rp   R  R  RW   RT  (   RP   RL  RW  RV  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRX  }  s    $c         C   s/   t  |  d  } z | j   SWd  | j   Xd  S(   NRa   (   Rm   Rn   Rg   (   R   Rt   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   readfile  s    c         C   s2   t  |  d  } z | j |  Wd  | j   Xd  S(   NR]   (   Rm   Rf   Rg   (   R   t   textRt   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   writefile  s    c         C   s2   t  |  d  } z | j |  Wd  | j   Xd  S(   Nt   ab(   Rm   Rf   Rg   (   R   RZ  Rt   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt
   appendfile  s    t   chunkbufferc           B   s    e  Z d  Z d   Z d   Z RS(   so   Allow arbitrary sized chunks of data to be efficiently read from an
    iterator over chunks of arbitrary size.c         C   s(   d   } | |  |  _  t   |  _ d S(   sz   in_iter is the iterator that's iterating over the input chunks.
        targetsize is how big a buffer to try to maintain.c         s   sj   xc |  D][ } t  |  d k r] d } x: | t  |  k  rY | d } | | | !V| } q( Wq | Vq Wd  S(   Ni   i   i    i   i   i   (   RH   (   t   chunksR   t   post   end(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   splitbig  s    
N(   t   iterR5   t   _queue(   R7   t   in_iterRb  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRC     s    	
c         C   s   | } g  } |  j  } x | d k r | s~ d } x> |  j D]3 } | j |  | t |  8} | d k r: Pq: q: W| s~ Pq~ n  | j   } | t |  8} | d k  r | j | |  | j | |   q | j |  q Wd j |  S(   su   Read L bytes of data from the iterator of chunks of data.
        Returns less than L bytes if the iterator runs dry.i    i   i   R   i   (   Rd  Rc  RD   RH   RI   t
   appendleftR   (   R7   t   lt   leftR   t   queuet   targetR   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRn     s(    	(   R<   R=   RL   RC   Rn   (    (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR^    s   	c         c   s   | d k s t   | d k s0 | d k s0 t   xk t r | d k rN | } n t | |  } | oo |  j |  } | s| Pn  | r | t |  8} n  | Vq3 Wd S(   sX  Create a generator that produces the data in the file size
    (default 65536) bytes at a time, up to optional limit (default is
    to read all data).  Chunks may be less than size bytes if the
    chunk is the last chunk in the file, or the file is a socket or
    some other type of file that sometimes reads less data than is
    requested.i    N(   t   AssertionErrorRW   R   R   Rn   RH   (   R0   t   sizet   limitt   nbytesR
   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR?    s    		c          C   s   t  j    }  |  d k  rC t d  } t t d  |  d |  n  t j j |   t j j |   } | j d | j } |  | f S(   Ni    s   check your clocks   negative timestamp: %dt   hintiQ (   t   timeR    Rk   t   datetimet   utcfromtimestampt   fromtimestampt   dayst   seconds(   t   ctRo  t   deltat   tz(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   makedate  s    s   %a %b %d %H:%M:%S %Y %1%2c      
   C   s  |  p t    \ } } | d k  r0 d } d } n  d | k sH d | k r | d k rZ d p] d } t |  d } | j d d | | d f  } | j d d | d  } n  y t j t |  |  } Wn# t k
 r t j t j  } n Xt j	 | |  } | S(	   s   represent a (unixtime, offset) tuple as a localized time.
    unixtime is seconds since the epoch, and offset is the time zone's
    number of seconds away from UTC. if timezone is false, do not
    append time zone to string.i    s   %1s   %2t   -t   +i<   s   %c%02ds   %02d(
   Ry  t   absRh   Rp  t   gmtimet   floatt
   ValueErrorR   t   maxintt   strftime(   t   datet   formatR   Rx  t   signt   minutesR
   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   datestr  s    	 c         C   s   t  |  d d S(   s1   turn (timestamp, tzoff) tuple into iso 8631 date.R  s   %Y-%m-%d(   R  (   R  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   shortdate  s    c         C   s$  d   } | |   |  } } | d k	 rD d j |  j   d   } n  t } xn d D]f } g  | D] } d
 | | k r^ t ^ q^ }	 |	 s | d | | | 7} | d | d 7} qQ t } qQ Wt j | |  }
 t t j	 |
   } | d k rt t j
 |
   } | | } n
 | | } | | f S(   s~   parse a localized time string and return a (unixtime, offset) tuple.
    if the string cannot be parsed, ValueError is raised.c         S   s   |  j    d } | d d k r t |  d k r | d j   r | d d k rX d p[ d } t | d d ! } t | d d ! } | | d | d S| d	 k s | d
 k r d Sd  S(   Nii    s   +-i   i   R{  i   i<   t   GMTt   UTC(   R   RH   t   isdigitt   intRW   (   t   stringRx  R  t   hoursR  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   timezone  s    2t    it   St   Mt   HIR  t   mbt   yYt   %t   @s   @%i    N(   R  R  s   HIR  s   mbR  (   RW   R   R   R   R   Rp  t   strptimeR  t   calendart   timegmt   mktime(   R  R  t   defaultsR  R   R  t   usenowR,  R$   R-  t	   timetuplet   localunixtimet   unixtime(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   strdate  s$    	)

c         C   sp  |  s
 d St  |  t  r/ t |   d k r/ |  S| s> t } n  |  j   }  |  t d  k rc t   S|  t d  k r t j j	   j
 d  }  n= |  t d  k r t j j	   t j d d  j
 d  }  n  y" t t |  j d	   \ } } Wn t k
 rt   } i  } xr d D]j } | j |  } | d k rX| d d k rOd } qXd } n  t | d | d  }	 | |	 f | | <qWx_ | D]= }
 y t |  |
 |  \ } } Wn t t f k
 rqXPqWt t d  |    n Xt |  d k rt t d  |   n  | d k  r5t t d  |   n  | d k  sM| d k rft t d  |   n  | | f S(   s  parse a localized date/time and return a (unixtime, offset) tuple.

    The date may be a "unixtime offset" string or in one of the specified
    formats. If the date already is a (unixtime, offset) tuple, it is returned.

    >>> parsedate(' today ') == parsedate(                                  datetime.date.today().strftime('%b %d'))
    True
    >>> parsedate( 'yesterday ') == parsedate((datetime.date.today() -                                               datetime.timedelta(days=1)                                              ).strftime('%b %d'))
    True
    >>> now, tz = makedate()
    >>> strnow, strtz = parsedate('now')
    >>> (strnow - now) < 1
    True
    >>> tz == strtz
    True
    i    i   t   nowt   todays   %b %dt	   yesterdayRt  i   R  R  R  R  R  R  R  t   HMSt   00R   R  s   invalid date: %ris   date exceeds 32 bits: %ds   negative date value: %di ;i  s   impossible time zone offset: %d(   i    i    (   R  s   mbs   yYs   HIR  R  N(   t
   isinstancet   tupleRH   t   defaultdateformatst   stripR    Ry  Rq  R  R  R  t	   timedeltat   mapR  R   R  R   RW   R  R  t   OverflowErrorRk   R|  (   R  t   formatst   biast   whenR   R  R  R,  R   R   R  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   parsedate5  sR    !	"			c            s  d   } d   } |  j    }  |  s9 t t d    n|  d d k r |  d sh t t d    n  | |  d    f d   S|  d d	 k r |  d s t t d
    n  | |  d    f d   S|  d d k rry t |  d  } Wn+ t k
 r"t t d  |  d   n X| d k  rLt t d  |  d   n  t   d | d d   f d   Sd |  k r|  j d  \ } } | |  | |        f d   S| |   | |         f d   Sd S(   sA  Return a function that matches a given date match specifier

    Formats include:

    '{date}' match a given date to the accuracy provided

    '<{date}' on or before a given date

    '>{date}' on or after a given date

    >>> p1 = parsedate("10:29:59")
    >>> p2 = parsedate("10:30:00")
    >>> p3 = parsedate("10:30:59")
    >>> p4 = parsedate("10:31:00")
    >>> p5 = parsedate("Sep 15 10:30:00 1999")
    >>> f = matchdate("10:30")
    >>> f(p1[0])
    False
    >>> f(p2[0])
    True
    >>> f(p3[0])
    True
    >>> f(p4[0])
    False
    >>> f(p5[0])
    False
    c         S   s)   t  d d d d  } t |  t |  d S(   NR  R   R  i    (   R   R  t   extendeddateformats(   R  R  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR     s    c      	   S   s   t  d d d d d d d d  } xD d D]< } y" | | d <t |  t |  d SWq( t k
 rc q( Xq( Wd | d <t |  t |  d S(   NR  t   12R  t   23R  t   59R  t   31t   30t   29R  i    t   28(   R  R  R  (   R   R  R  Rk   (   R  R  Rt  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR    s    !

s+   dates cannot consist entirely of whitespacei    t   <i   s   invalid day spec, use '<DATE'c            s
   |    k S(   N(    (   R   (   R  (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   <lambda>  s    t   >s   invalid day spec, use '>DATE'c            s
   |    k S(   N(    (   R   (   R  (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR    s    Rz  s   invalid day spec: %ss,   %s must be nonnegative (see 'hg help dates')i  i   c            s
   |    k S(   N(    (   R   (   R  (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR    s    s    to c            s   |    k o |   k S(   N(    (   R   (   t   startt   stop(    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR    s    c            s   |    k o |   k S(   N(    (   R   (   R  R  (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR    s    N(   R  Rk   R    R  R  Ry  R   (   R  R   R  Rt  R   R   (    (   R  R  R  s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   matchdate  s>    		

c         C   s   |  j  d  } | d k r( |  |  }  n  |  j  d  } | d k rT |  | d }  n  |  j  d  } | d k r| |  |  }  n  |  j  d  } | d k r |  |  }  n  |  S(   s>   Return a short representation of a user name or email address.R  i    R  i   R  R   (   R$  (   t   userR0   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   shortuser  s    c         C   sX   |  j  d  } | d k r( |  |  }  n  |  j  d  } | d k rT |  | d }  n  |  S(   s,   Return the user portion of an email address.R  i    R  i   (   R$  (   R  R0   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   emailuser  s    c         C   s<   |  j  d  } | d k r$ d } n  |  |  j  d  d | !S(   s   get email of author.R  iR  i   N(   R$  RW   (   t   authorRw   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   email  s    	c         C   s6   t  |   | k r |  t f Sd |  | d  t f Sd  S(   Ns   %s...i   (   RH   R   R   (   RZ  t	   maxlength(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   _ellipsis  s    
i  c         C   sk   y? t  |  j t j  |  \ } } | s. |  S| j t j  SWn% t t f k
 rf t  |  |  d SXd S(   s;   Trim string to at most maxlength (default: 400) characters.i    N(   R  t   decodet   encodingt   encodet   UnicodeDecodeErrort   UnicodeEncodeError(   RZ  R  t   utextt	   truncated(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   ellipsis  s    c             s     f d   } | S(   s@   return a function that renders a readable count of some quantityc            sL   x9   D]1 \ } } } |  | | k r | |  t  |  Sq W  d d |  S(   Nii   (   R~  (   t   countt
   multipliert   divisorR  (   t	   unittable(    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   go  s    (    (   R  R  (    (   R  s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   unitcountfn  s    id   i   i   s   %.0f GBi
   s   %.1f GBs   %.2f GBi   s   %.0f MBs   %.1f MBs   %.2f MBs   %.0f KBs   %.1f KBs   %.2f KBs
   %.0f bytesc         C   s   t  |   j d d  S(   Ns   \\s   \(   t   reprRh   (   R
   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   uirepr  s    c          K   s)   d t  j f d     Y} | a | |    S(   Nt   twc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s8  
        Extend TextWrapper for width-awareness.

        Neither number of 'bytes' in any encoding nor 'characters' is
        appropriate to calculate terminal columns for specified string.

        Original TextWrapper implementation uses built-in 'len()' directly,
        so overriding is needed to use width information of each characters.

        In addition, characters classified into 'ambiguous' width are
        treated as wide in East Asian area, but as narrow in other.

        This requires use decision to determine width of such characters.
        c         [   sG   t  j j |  |  t |  d d   d  k rC | j d t  |  _ n  d  S(   Nt   drop_whitespace(   t   textwrapt   TextWrapperRC   R   RW   R   R   R  (   R7   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRC   .  s    c         S   sh   d } t  j } xL t t |   D]8 } | | | |  7} | | k  r" | |  | | f Sq" W| d f S(   Ni    R   (   R  t	   ucolwidtht   xrangeRH   (   R7   t   ucstrt
   space_leftRg  t   colwidthR9   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   _cutdown5  s    	c         S   sr   t  | | d  } |  j rR |  j | d |  \ } } | j |  | | d <n | sn | j | j    n  d  S(   Ni   i(   R   t   break_long_wordsR  RD   R   (   R7   t   reversed_chunkst   cur_linet   cur_lent   widthR  t   cutt   res(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   _handle_long_word?  s    	c   	   	   S   s  t  j } g  } |  j d k r4 t d |  j   n  | j   xH| rg  } d } | re |  j } n	 |  j } |  j t |  } |  j r | d j	   d k r | r | d =n  xK | r | | d  } | | | k r | j
 | j    | | 7} q Pq W| r3| | d  | k r3|  j | | | |  n  |  j rb| rb| d j	   d k rb| d =n  | rA | j
 | d j |   qA qA W| S(   Ni    s   invalid width %r (must be > 0)iR   (   R  R  R  R  R   t   subsequent_indentt   initial_indentRH   R  R  RD   R   R  R   (	   R7   R_  R  t   linesR  R  t   indentR  Rg  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   _wrap_chunksK  s8    	
		%
		
!(   R<   R=   RL   RC   R  R  R  (    (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR    s
   		
	(   R  R  t   MBTextWrapper(   R   R  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR    s    jc         C   s   t  t |  t |   } | | k r= t  d | d  } n  |  j t j t j  }  | j t j t j  } | j t j t j  } t d | d | d |  } | j |   j t j  S(   NiN   i   R  R  R  (   R   RH   R  R  t   encodingmodeR  t   fillR  (   R   R  t
   initindentt
   hangindentt	   maxindentt   wrapper(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   wrap  s    	c         c   s1   x* |  D]" } x | j    D] } | Vq Wq Wd  S(   N(   t
   splitlines(   t   iteratorR   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   iterlines  s    c         C   s   t  j j t  j j |    S(   N(   Rd   R   t
   expandusert
   expandvars(   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt
   expandpath  s    c           C   s   t    r t j g St   S(   s   Return the command used to execute current hg

    This is different from hgexecutable() because on Windows we want
    to avoid things opening new shell windows like batch files, so we
    get either the python call or current executable.
    (   R   R   R   t   gethgcmd(    (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   hgcmd  s    	
c            s   t        f d   } d } t t d d  } | d k	 rQ t j | |  } n  zX t |   } xA |   s |   k s t |  r |   r d St j d  qc W| SWd | d k	 r t j t j |  n  Xd S(   s_  Execute the argument list in a detached process.

    condfn is a callable which is called repeatedly and should return
    True once the child process is known to have started successfully.
    At this point, the child process PID is returned. If the child
    process fails to start or finishes before condfn() evaluates to
    True, return -1.
    c            s     j  t j    d  S(   N(   t   addRd   R   (   t   signumt   frame(   t
   terminated(    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   handler  s    t   SIGCHLDig?N(	   t   setRW   R   t   signalt   spawndetachedt   testpidRp  t   sleepR  (   R1   t   condfnR  t   prevhandlerR  t   pid(    (   R   s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   rundetached  s     	
c         C   s   x |  D] } | r t  Sq Wt S(   N(   R   R   (   t   iterableR9   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   any  s    c         C   s   x |  D] } | s t  Sq Wt S(   N(   R   R   (   R  R9   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   all  s    c            s     p d     d j   j    } | rj | d |  7} t |   d k rW |  d } n |  } |  | <n  t j d |  | f  } | j    f d   |  S(   s  Return the result of interpolating items in the mapping into string s.

    prefix is a single character string, or a two character string with
    a backslash as the first character if the prefix needs to be escaped in
    a regular expression.

    fn is an optional function that will be applied to the replacement text
    just before replacement.

    escape_prefix is an optional flag that allows using doubled prefix for
    its escaping.
    c         S   s   |  S(   N(    (   R
   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR    s    t   |i   s   %s(%s)c            s      |  j    d  S(   Ni   (   t   group(   R   (   R}   t   mapping(    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR    s    (   R   t   keysRH   R  R  t   sub(   R\   R  R
   R}   t   escape_prefixt   patternst   prefix_charRw   (    (   R}   R  s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   interpolate  s    c         C   sd   y t  |   SWn t k
 r! n Xy t j |   SWn* t j k
 r_ t t d  |    n Xd S(   s   Return the port for a given network service.

    If port is an integer, it's returned as is. If it's a string, it's
    looked up using socket.getservbyname(). If there's no matching
    service, util.Abort is raised.
    s+   no port number associated with service '%s'N(   R  R  t   sockett   getservbynameR   Rk   R    (   t   port(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   getport  s    R   t   yest   truet   onR   R   t   not   falset   offR   c         C   s   t  j |  j   d  S(   sL   Parse s into a boolean.

    If s is not a valid boolean, returns None.
    N(   t	   _booleansR   R   RW   (   R
   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   parsebool  s    t   0123456789ABCDEFabcdefc         c   s?   |  ]5 } t  D]( } | | t t | | d    f Vq q d S(   i   N(   t   _hexdigt   chrR  (   R   R   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pys	   <genexpr>  s   c         C   s   |  j  d  } t |  d k r% |  S| d }  x | d D]{ } y |  t | d  | d 7}  Wq: t k
 r |  d | 7}  q: t k
 r |  t t | d  d   | d 7}  q: Xq: W|  S(   sQ   Decode HTTP/HTML % encoding.

    >>> _urlunquote('abc%20def')
    'abc def'
    R  i   i    i   i   (   R   RH   t	   _hextochrt   KeyErrorR  t   unichrR  (   R
   R  t   item(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   _urlunquote  s    
-t   urlc           B   sh   e  Z d  Z d Z d Z e j d  j Z e	 e	 d  Z
 d   Z d   Z d   Z d   Z d	   Z RS(
   s  Reliable URL parser.

    This parses URLs and provides attributes for the following
    components:

    <scheme>://<user>:<passwd>@<host>:<port>/<path>?<query>#<fragment>

    Missing components are set to None. The only exception is
    fragment, which is set to '' if present but empty.

    If parsefragment is False, fragment is included in query. If
    parsequery is False, query is included in path. If both are
    False, both fragment and query are included in path.

    See http://www.ietf.org/rfc/rfc2396.txt for more information.

    Note that for backward compatibility reasons, bundle URLs do not
    take host names. That means 'bundle://../' has a path of '../'.

    Examples:

    >>> url('http://www.ietf.org/rfc/rfc2396.txt')
    <url scheme: 'http', host: 'www.ietf.org', path: 'rfc/rfc2396.txt'>
    >>> url('ssh://[::1]:2200//home/joe/repo')
    <url scheme: 'ssh', host: '[::1]', port: '2200', path: '/home/joe/repo'>
    >>> url('file:///home/joe/repo')
    <url scheme: 'file', path: '/home/joe/repo'>
    >>> url('file:///c:/temp/foo/')
    <url scheme: 'file', path: 'c:/temp/foo/'>
    >>> url('bundle:foo')
    <url scheme: 'bundle', path: 'foo'>
    >>> url('bundle://../foo')
    <url scheme: 'bundle', path: '../foo'>
    >>> url(r'c:\foo\bar')
    <url path: 'c:\\foo\\bar'>
    >>> url(r'\\blah\blah\blah')
    <url path: '\\\\blah\\blah\\blah'>
    >>> url(r'\\blah\blah\blah#baz')
    <url path: '\\\\blah\\blah\\blah', fragment: 'baz'>

    Authentication credentials:

    >>> url('ssh://joe:xyz@x/repo')
    <url scheme: 'ssh', user: 'joe', passwd: 'xyz', host: 'x', path: 'repo'>
    >>> url('ssh://joe@x/repo')
    <url scheme: 'ssh', user: 'joe', host: 'x', path: 'repo'>

    Query strings and fragments:

    >>> url('http://host/a?b#c')
    <url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'>
    >>> url('http://host/a?b#c', parsequery=False, parsefragment=False)
    <url scheme: 'http', host: 'host', path: 'a?b#c'>
    s   !~*'()+s	   /!~*'()+:s   ^[a-zA-Z0-9+.\-]+:c         C   s  d  |  _ |  _ |  _ |  _ d  |  _ |  _ |  _ |  _ t	 |  _
 d |  _ | |  _ | r d | k r | j d d  \ } |  _ | s d  } q n  t |  s | j d  r | |  _ d  S| j d  r	d |  _ | d } | j d  r | d	 } n  | |  _ d  S|  j |  rR| j d
 d  } | d rR| \ |  _ } t |  _
 qRn  | swd  } |  j
 rd |  _ d  SnF|  j
 r| |  _ d  S| rd | k r| j d d  \ } |  _ | sd  } n  |  j sd  |  _ qn  | r{| j d  r{| d	 j d d  } t |  d k r0| \ |  _ } n | d |  _ d  } |  j s{d  |  _ | rxt |  rxd | } qxq{n  |  j rd |  j k r|  j j d d  \ |  _ |  _ d
 |  j k r|  j j d
 d  \ |  _ |  _ n  |  j sd  |  _ qn  |  j rd
 |  j k r|  j j d  o8|  j j d  r|  j |  _ |  j j d
 d  \ |  _ |  _ |  j sd  |  _ qn  |  j r|  j d k r|  j d k rt t d    n  | |  _ xB d D]: } t |  |  } | d  k	 rt |  | t |   qqWd  S(   NR   t   #i   s   \\s   bundle:t   bundlei   s   //i   t   :i    t   ?R   R  t   [t   ]t   filet	   localhosts	   127.0.0.1s   [::1]s(   file:// URLs can only refer to localhostR  t   passwdt   hostR  R   t   fragment(   R4  s	   127.0.0.1s   [::1](   s   users   passwds   hosts   ports   paths   fragment(   RW   t   schemeR  R5  R6  R  R   t   queryR7  R   t
   _localpatht	   _hostportt	   _origpathR   t   hasdriveletterR{   t   _matchschemeR   RH   t   rsplitR6  Rk   R    R   RV   R+  (   R7   R   t
   parsequeryt   parsefragmentt   partsR   R:   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRC   g  s    					
	
								!$	%!		
c         C   s]   g  } xC d D]; } t  |  |  } | d  k	 r | j d	 | | f  q q Wd
 d j |  S(   NR8  R  R5  R6  R  R   R9  R7  s   %s: %rs   <url %s>s   , (   s   schemes   users   passwds   hosts   ports   paths   querys   fragment(   R   RW   RD   R   (   R7   t   attrsR   R:   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   __repr__  s    
c         C   sm  |  j  rO |  j } |  j d k r. d | } n  |  j rK | d |  j 7} n  | S|  j d } |  j sw |  j sw |  j r | d 7} n] |  j r |  j s |  j j d  s t |  j  r | d 7} t |  j  r | d 7} q n  |  j r| t	 j
 |  j d |  j 7} n  |  j r;| d t	 j
 |  j d |  j 7} n  |  j sM|  j rZ| d 7} n  |  j r|  j j d	  o|  j j d
  s| t	 j
 |  j  7} q| |  j 7} n  |  j r| d t	 j
 |  j  7} n  |  j r| d 7} n  |  j r| t	 j
 |  j d |  j 7} n  |  j r4| d |  j 7} n  |  j d k	 ri| d t	 j
 |  j d |  j 7} n  | S(   so  Join the URL's components back into a URL string.

        Examples:

        >>> str(url('http://user:pw@host:80/c:/bob?fo:oo#ba:ar'))
        'http://user:pw@host:80/c:/bob?fo:oo#ba:ar'
        >>> str(url('http://user:pw@host:80/?foo=bar&baz=42'))
        'http://user:pw@host:80/?foo=bar&baz=42'
        >>> str(url('http://user:pw@host:80/?foo=bar%3dbaz'))
        'http://user:pw@host:80/?foo=bar%3dbaz'
        >>> str(url('ssh://user:pw@[::1]:2200//home/joe#'))
        'ssh://user:pw@[::1]:2200//home/joe#'
        >>> str(url('http://localhost:80//'))
        'http://localhost:80//'
        >>> str(url('http://localhost:80/'))
        'http://localhost:80/'
        >>> str(url('http://localhost:80'))
        'http://localhost:80/'
        >>> str(url('bundle:foo'))
        'bundle:foo'
        >>> str(url('bundle://../foo'))
        'bundle:../foo'
        >>> str(url('path'))
        'path'
        >>> str(url('file:///tmp/foo/bar'))
        'file:///tmp/foo/bar'
        >>> str(url('file:///c:/tmp/foo/bar'))
        'file:///c:/tmp/foo/bar'
        >>> print url(r'bundle:foo\bar')
        bundle:foo\bar
        R.  s   bundle:R-  R/  s   //R   t   safeR  R1  R2  R0  N(   R:  R   R8  R7  R  R5  R6  R{   R=  t   urllibt   quotet
   _safecharsR6  R  t   _safepcharsR9  RW   (   R7   R
   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   __str__  sH     			%
	"	&	$			"	&c         C   s   |  j  |  j } } z" d \ |  _  |  _ t |   } Wd  | | |  _  |  _ X|  j  s_ | d  f S| d  | |  j f |  j  |  j p d f f S(   NR   (   NN(   R  R5  RW   R   R6  (   R7   R  R5  R
   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   authinfo  s    	
c         C   s_   |  j  r |  j  d k r t St |  j  r/ t S|  j j d  rE t S|  j j d  r[ t St S(   NR3  s   \\R   (   R8  R   R=  R   R{   R   (   R7   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR   )  s    c         C   s   |  j  d k s |  j  d k r |  j p* d } t |  j  rS |  j d |  j } n2 |  j d  k	 r |  j r t |  r d | } n  | S|  j S(   NR3  R.  R   (   R8  R   R=  R;  R6  RW   R<  (   R7   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR   4  s    (   R<   R=   RL   RH  RI  R  R  t   matchR>  R   RC   RD  RJ  RK  R   R   (    (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR,  +  s   6^			K		c         C   s   t  t |   j  S(   N(   R   R,  R8  (   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt	   hasschemeA  s    c         C   s*   |  o) |  d d !d k o) |  d d !j    S(   Ni   i   R/  i    (   t   isalpha(   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR=  D  s    c         C   s   t  |  d t d t j   S(   NR@  RA  (   R,  R   R   (   R   (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   urllocalpathG  s    c         C   s+   t  |   }  |  j r! d |  _ n  t |   S(   s$   hide user credential in a url strings   ***(   R,  R5  R   (   t   u(    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   hidepasswordJ  s    	c         C   s&   t  |   }  d |  _ |  _ t |   S(   s7   remove all authentication information from a url stringN(   R,  RW   R  R5  R   (   RP  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt
   removeauthQ  s    c         C   s'   y |  j    SWn t k
 r" t SXd  S(   N(   t   isattyR   R   (   R4  (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyRS  W  s    g     @@s   %.0f ss   %.1f ss   %.2f ss   %.3f sgMbP?s   %.1f mss   %.2f mss   %.3f msgư>s   %.1f uss   %.2f uss   %.3f usg&.>s   %.1f nss   %.2f nss   %.3f nsc            s     f d   } | S(   s   Report the execution time of a function call to stderr.

    During development, use as a decorator when you need to measure
    the cost of a function, e.g. as follows:

    @util.timed
    def foo(a, b, c):
        pass
    c       	      s   t  j    } d } t d c | 7<z   |  |   SWd  t  j    | } t d c | 8<t j j d d t d   j t |  f  Xd  S(   Ni   i    s	   %s%s: %s
R  (   Rp  t   _timenestingR   R'   Rf   R<   t	   timecount(   R1   R   R  R  t   elapsed(   R/   (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyR  z  s    (    (   R/   R  (    (   R/   s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   timedo  s    (   RL   t   i18nR    R   R   R  t   collectionsR  R  R   R   Rb   R   Rd   Rp  Rq  R  R  R  R   R  RF  RP   t   windowsRj   R   t	   cachestatt	   checkexect	   checklinkR   t   executablepatht   expandglobsRl   R   R  t   getusert   groupmemberst	   groupnamet
   hidewindowt   isexect   isownerR   t	   lookupregRQ  R0  R&  R"  t   openhardlinksR   t   parsepatchoutputR   t   popenR  R   t   realpathRN  t
   samedevicet   samefilet   samestatt	   setbinaryt   setflagst   setsignalhandlert
   shellquoteR  R   t   sshargsR   R   t
   statisexect
   statislinkt	   termwidthR  t   umaskRo   t
   unlinkpatht   usernamet   objectR   R   R   R	   R   t	   NameErrorR   R   R    RW   R   R%   R(   R&   R+   R  R  R4   R5   R;   R   R>   RN   RO   R[   Rx   Ry   R~   R   R   Rk   R   R   R   R   R   R   R   Ri   R   R   R   R   R   R  t   checkosfilenameR  R  R  R  R  R  R,   R!  R(  R.  R5  R7  R   R<  RE  RF  RS  RX  RY  R[  R]  R^  R?  Ry  R  R  R  R  R  R  R  R  R  R  R  t	   bytecountR  R  R  R  R  R  R  R  R  R  R  R   R"  R#  R%  R   R'  R+  R,  RM  R=  RO  RQ  RR  RS  RU  RT  RW  (    (    (    s2   /sys/lib/python2.7/site-packages/mercurial/util.pyt   <module>   s  0HH$																																																		
		
	
	
			%
							
		9			'							

	.	"			'&			0	
)M	L		
					n				#		&
			 							