ó
œçƒQc           @   sw   d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l Z d d l	 Z	 d e	 j	 f d „  ƒ  YZ
 d S(   s4   remote largefile store; the base class for wirestoreiÿÿÿÿN(   t   util(   t   _(   t   remotebatcht   remotestorec           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s)   a largefile store accessed over a networkc         C   s    t  t |  ƒ j | | | ƒ d  S(   N(   t   superR   t   __init__(   t   selft   uit   repot   url(    (    s@   /sys/lib/python2.7/site-packages/hgext/largefiles/remotestore.pyR      s    c         C   s^   |  j  | | ƒ r7 t j t d ƒ | |  j f ƒ ‚ n  |  j j t d ƒ | |  j f ƒ d  S(   Ns0   remotestore: could not put %s to remote store %ss&   remotestore: put %s to remote store %s(   t   sendfileR    t   AbortR   R	   R   t   debug(   R   t   sourcet   hash(    (    s@   /sys/lib/python2.7/site-packages/hgext/largefiles/remotestore.pyt   put   s    		c         C   s#   t  d „  |  j | ƒ j ƒ  Dƒ ƒ S(   Nc         s   s'   |  ] \ } } | | d  k f Vq d S(   i    N(    (   t   .0t   ht   s(    (    s@   /sys/lib/python2.7/site-packages/hgext/largefiles/remotestore.pys	   <genexpr>    s    (   t   dictt   _statt	   iteritems(   R   t   hashes(    (    s@   /sys/lib/python2.7/site-packages/hgext/largefiles/remotestore.pyt   exists   s    c         C   s£   |  j  j d | | f ƒ d  } zh y t j |  j  | ƒ } Wn8 t k
 rv } t j t d ƒ | t	 | ƒ f ƒ ‚ n X|  j
 | | ƒ SWd  | rž | j ƒ  n  Xd  S(   Ns   remotestore: sendfile(%s, %s)
s'   remotestore: could not open file %s: %s(   R   R   t   Nonet   lfutilt   httpsendfilet   IOErrorR    R   R   t   strt   _putt   close(   R   t   filenameR   t   fdt   e(    (    s@   /sys/lib/python2.7/site-packages/hgext/largefiles/remotestore.pyR
   "   s    	c         C   sÄ   y |  j  | ƒ } Wnž t j k
 rL } t j | | |  j t | ƒ ƒ ‚ nh t j k
 r€ } t j	 d |  j | j
 f ƒ ‚ n4 t k
 r³ } t j | | |  j t | ƒ ƒ ‚ n Xt j | | ƒ S(   Ns   %s: %s(   t   _gett   urllib2t	   HTTPErrort	   basestoret
   StoreErrorR	   R   t   URLErrorR    R   t   reasonR   R   t   copyandhash(   R   t   tmpfileR   R   t   chunksR!   (    (    s@   /sys/lib/python2.7/site-packages/hgext/largefiles/remotestore.pyt   _getfile1   s    $"%c         C   sù   t  j | ƒ } | s t S| | } | | j ƒ  f } | | k rE t S| j | ƒ | j ƒ  d d !}	 |  j |	 g ƒ |	 }
 |
 s… t S|
 d k rµ |  j j t	 d ƒ | | f ƒ t
 S|
 d k rå |  j j t	 d ƒ | | f ƒ t
 St d |
 ƒ ‚ d  S(   Ni    i(   i   s"   changeset %s: %s: contents differ
i   s   changeset %s: %s missing
s6   verify failed: unexpected response from statlfile (%r)(   R   t   splitstandint   Falset   filenodet   addt   dataR   R   t   warnR   t   Truet   RuntimeError(   R   t   cctxt   csett   contentst   standint   verifiedR   t   fctxt   keyt
   expecthasht   stat(    (    s@   /sys/lib/python2.7/site-packages/hgext/largefiles/remotestore.pyt   _verifyfileB   s0    
				c         C   s
   t  |  ƒ S(   s   Support for remote batching.(   R   (   R   (    (    s@   /sys/lib/python2.7/site-packages/hgext/largefiles/remotestore.pyt   batch_   s    (
   t   __name__t
   __module__t   __doc__R   R   R   R
   R,   R>   R?   (    (    (    s@   /sys/lib/python2.7/site-packages/hgext/largefiles/remotestore.pyR      s   						(   RB   R#   t	   mercurialR    t   mercurial.i18nR   t   mercurial.wireprotoR   R   R%   R   (    (    (    s@   /sys/lib/python2.7/site-packages/hgext/largefiles/remotestore.pyt   <module>   s   