§
    	^µca  ã                   óâ   — d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZ  G d„ de¦  «        Z G d„ d	e¦  «        Z G d
„ d¦  «        Z G d„ d¦  «        Zdd„Z G d„ de¦  «        ZdS )é    N)Úhex)Úopen)Úpycompat)ÚhashutilÚprocutilc                   ó   — e Zd ZdS )ÚBundleWriteExceptionN©Ú__name__Ú
__module__Ú__qualname__© ó    ú:/usr/lib/python3/dist-packages/hgext/infinitepush/store.pyr	   r	      ó   € € € € € Ø€Dr   r	   c                   ó   — e Zd ZdS )ÚBundleReadExceptionNr
   r   r   r   r   r      r   r   r   c                   ó`   — e Zd ZdZej        Zej        d„ ¦   «         Zej        d„ ¦   «         Z	dS )Úabstractbundlestorea6  Defines the interface for bundle stores.

    A bundle store is an entity that stores raw bundle data. It is a simple
    key-value store. However, the keys are chosen by the store. The keys can
    be any Python object understood by the corresponding bundle index (see
    ``abstractbundleindex`` below).
    c                 ó   — dS )zÇWrite bundle data to the store.

        This function receives the raw data to be written as a str.
        Throws BundleWriteException
        The key of the written data MUST be returned.
        Nr   )ÚselfÚdatas     r   Úwritezabstractbundlestore.write'   ó   € € € r   c                 ó   — dS )zÕObtain bundle data for a key.

        Returns None if the bundle isn't known.
        Throws BundleReadException
        The returned object should be a file object supporting read()
        and close().
        Nr   )r   Úkeys     r   Úreadzabstractbundlestore.read0   r   r   N)
r   r   r   Ú__doc__ÚabcÚABCMetaÚ__metaclass__Úabstractmethodr   r   r   r   r   r   r      sc   € € € € € ðð ð ”K€MàÔðð ñ Ôðð 	Ôðð ñ Ôðð ð r   r   c                   ó0   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZdS )Úfilebundlestorezkbundle store in filesystem

    meant for storing bundles somewhere on disk and on network filesystems
    c                 ó.  — || _         || _        |                     dd¦  «        | _        | j        s%| j        j                             dd¦  «        | _        t          j                             | j        ¦  «        st          j	        | j        ¦  «         d S d S )Ns   scratchbranchs	   storepaths   scratchbranchess   filebundlestore)
ÚuiÚrepoÚ
configpathÚ	storepathÚvfsÚjoinÚosÚpathÚexistsÚmakedirs)r   r&   r'   s      r   Ú__init__zfilebundlestore.__init__A   s�   € ØˆŒØˆŒ	ØŸšÐ'7¸ÑFÔFˆŒØŒ~ð 	Ø!œYœ]×/Ò/Ø"Ð$6ñô ˆDŒNõ Œw�~Š~˜dœnÑ-Ô-ð 	(ÝŒK˜œÑ'Ô'Ð'Ð'Ð'ð	(ð 	(r   c                 ón   — t           j                             | j        |dd…         |dd…         ¦  «        S )zŽFirst two bytes of the hash are the name of the upper
        level directory, next two bytes are the name of the
        next level directoryr   é   é   )r,   r-   r+   r)   )r   Ú	hashvalues     r   Ú_dirpathzfilebundlestore._dirpathL   s.   € õ Œw�|Š|˜DœN¨I°a¸°c¬N¸IÀaÈÀc¼NÑKÔKÐKr   c                 óh   — t           j                             |                      |¦  «        |¦  «        S )N)r,   r-   r+   r5   )r   Úfilenames     r   Ú	_filepathzfilebundlestore._filepathR   s$   € ÝŒw�|Š|˜DŸMšM¨(Ñ3Ô3°XÑ>Ô>Ð>r   c                 óœ  — t          t          j        |¦  «                             ¦   «         ¦  «        }|                      |¦  «        }t
          j                             |¦  «        st          j        |¦  «         t          |  
                    |¦  «        d¦  «        5 }|                     |¦  «         d d d ¦  «         n# 1 swxY w Y   |S )Ns   wb)r   r   Úsha1Údigestr5   r,   r-   r.   r/   r   r8   r   )r   r   r7   ÚdirpathÚfs        r   r   zfilebundlestore.writeU   sà   € Ý•x”} TÑ*Ô*×1Ò1Ñ3Ô3Ñ4Ô4ˆØ—-’- Ñ)Ô)ˆåŒw�~Š~˜gÑ&Ô&ð 	!ÝŒK˜Ñ Ô Ð å�$—.’. Ñ*Ô*¨EÑ2Ô2ð 	°aØ�GŠG�D‰MŒMˆMð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð ˆs   ÂCÃCÃCc                 óÈ   — 	 t          |                      |¦  «        d¦  «        5 }|                     ¦   «         cd d d ¦  «         S # 1 swxY w Y   d S # t          $ r Y d S w xY w)Ns   rb)r   r8   r   ÚIOError)r   r   r=   s      r   r   zfilebundlestore.reada   s±   € ð	Ý�d—n’n SÑ)Ô)¨5Ñ1Ô1ð  °QØ—v’v‘x”xð ð  ð  ð  ñ  ô  ð  ð  ð  ð  ð  ð  øøøð  ð  ð  ð  ð  ð  øåð 	ð 	ð 	Ø�4�4ð	øøøs3   ‚#A ¥A¹A ÁA
Á
A ÁA
ÁA Á
A!Á A!N)	r   r   r   r   r0   r5   r8   r   r   r   r   r   r$   r$   ;   sl   € € € € € ðð ð
	(ð 	(ð 	(ðLð Lð Lð?ð ?ð ?ð
ð 
ð 
ðð ð ð ð r   r$   c                 ó¶   — g }| D ]S}|r|dk    r|                      |¦  «         Œ |r|dk    r|                      |¦  «         Œ>|                      |¦  «         ŒT|S )z‚Formats `args` with Infinitepush replacements.

    Hack to get `str.format()`-ed strings working in a BC way with
    bytes.
    s
   {filename}s   {handle})Úappend)Úargsr7   ÚhandleÚformatted_argsÚargs        r   Úformat_placeholders_argsrF   i   s‡   € ð €NØð 'ð 'ˆØð 	'˜˜}Ò,Ð,Ø×!Ò! (Ñ+Ô+Ð+Ð+Øð 	'˜˜{Ò*Ð*Ø×!Ò! &Ñ)Ô)Ð)Ð)à×!Ò! #Ñ&Ô&Ð&Ð&ØÐr   c                   ó&   — e Zd Zd„ Zd„ Zd„ Zd„ ZdS )Úexternalbundlestorec                 ó>   — || _         || _        || _        || _        dS )a6  
        `put_binary` - path to binary file which uploads bundle to external
            storage and prints key to stdout
        `put_args` - format string with additional args to `put_binary`
                     {filename} replacement field can be used.
        `get_binary` - path to binary file which accepts filename and key
            (in that order), downloads bundle from store and saves it to file
        `get_args` - format string with additional args to `get_binary`.
                     {filename} and {handle} replacement field can be used.
        N)Úput_argsÚget_argsÚ
put_binaryÚ
get_binary)r   rL   rJ   rM   rK   s        r   r0   zexternalbundlestore.__init__{   s$   € ð !ˆŒØ ˆŒØ$ˆŒØ$ˆŒˆˆr   c                 óÚ   — t          j        t          j        t          j        |¦  «        t           j        t           j        d¬¦  «        }|                     ¦   «         \  }}|j        }|||fS )NT)ÚstdoutÚstderrÚ	close_fds)	Ú
subprocessÚPopenr   Úrapplyr   ÚtonativestrÚPIPEÚcommunicateÚ
returncode)r   rB   ÚprO   rP   rX   s         r   Ú_call_binaryz externalbundlestore._call_binaryŒ   s_   € ÝÔÝŒO�HÔ0°$Ñ7Ô7Ý”?Ý”?Øð	
ñ 
ô 
ˆð Ÿš™œ‰ˆ�Ø”\ˆ
Ø˜6 6Ð)Ð)r   c                 ó  — t          j        ¦   «         5 }|                     |¦  «         |                     ¦   «          |                     d¦  «         t          | j        |j        ¬¦  «        }|                      | j	        g|z   ¦  «        \  }}}|dk    rt          d|z  ¦  «        ‚|                     ¦   «         }t          |¦  «        dk    r|d         cd d d ¦  «         S t          d| j	        |fz  ¦  «        ‚# 1 swxY w Y   d S )Nr   )r7   s&   Failed to upload to external store: %sé   s   Bad output from %s: %s)r   Únamedtempfiler   ÚflushÚseekrF   rJ   ÚnamerZ   rL   r	   Ú
splitlinesÚlen)r   r   ÚtemprD   rX   rO   rP   Ústdout_liness           r   r   zexternalbundlestore.write—   s_  € õ
 Ô#Ñ%Ô%ð 	¨Ø�JŠJ�tÑÔÐØ�JŠJ‰LŒLˆLØ�IŠI�a‰LŒLˆLÝ5Ø”¨¬	ðñ ô ˆNð *.×):Ò):Ø”Ð! NÑ2ñ*ô *Ñ&ˆJ˜ ð ˜QŠˆÝ*Ø=ÀÑFñô ð ð "×,Ò,Ñ.Ô.ˆLÝ�<Ñ Ô  AÒ%Ð%Ø# A”ð#	ð 	ð 	ð 	ñ 	ô 	ð 	ð 	õ& +Ø-°´À&Ð0IÑIñô ð ð'	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s   ”CC<Ã#C<Ã<D ÄD c                 ó0  — t          j        ¦   «         5 }t          | j        |j        |¬¦  «        }|                      | j        g|z   ¦  «        \  }}}|dk    rt          d|z  ¦  «        ‚|                     ¦   «         cd d d ¦  «         S # 1 swxY w Y   d S )N)r7   rC   r   s*   Failed to download from external store: %s)	r   r]   rF   rK   r`   rZ   rM   r   r   )r   rC   rc   rD   rX   rO   rP   s          r   r   zexternalbundlestore.read³   sð   € õ Ô#Ñ%Ô%ð 	¨Ý5Ø”¨¬	¸&ðñ ô ˆNð *.×):Ò):Ø”Ð! NÑ2ñ*ô *Ñ&ˆJ˜ ð ˜QŠˆÝ)ØAÀFÑJñô ð ð —9’9‘;”;ð	ð 	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s   ”A*BÂBÂBN)r   r   r   r0   rZ   r   r   r   r   r   rH   rH   z   sP   € € € € € ð%ð %ð %ð"	*ð 	*ð 	*ðð ð ð8ð ð ð ð r   rH   )NN)r   r,   rR   Úmercurial.noder   Úmercurial.pycompatr   Ú	mercurialr   Úmercurial.utilsr   r   Ú	Exceptionr	   r   r   r$   rF   rH   r   r   r   ú<module>rk      s{  ðð €
€
€
Ø 	€	€	€	Ø Ð Ð Ð à Ð Ð Ð Ð Ð Ø #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð	ð 	ð 	ð 	ð 	˜9ñ 	ô 	ð 	ð	ð 	ð 	ð 	ð 	˜)ñ 	ô 	ð 	ðð ð ð ð ñ ô ð ð>+ð +ð +ð +ð +ñ +ô +ð +ð\ð ð ð ð"Hð Hð Hð Hð HÐ-ñ Hô Hð Hð Hð Hr   