§
    cÌc´  ã                   óè  — d 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mZ  e e	¦   «         d¦  «         ddl
mZmZ ej        Z G d„ dej        ¦  «        Zd	„ Zd
„ Z G d„ d¦  «        Zej        fZej        dk    rdZeefz  Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ d¦  «        Z G d„ d¦  «        Z G d„ d¦  «        Zdada G d„ de¦  «        Z  G d„ de ¦  «        Z! G d„ d e!¦  «        Z" G d!„ d"¦  «        Z# G d#„ d$e!¦  «        Z$dZ%d%Z& G d&„ d'e!¦  «        Z' G d(„ d)e'¦  «        Z( G d*„ d+e'¦  «        Z) G d,„ d-ej*        ¦  «        Z+ G d.„ d/e¦  «        Z,dS )0as  The 'medium' layer for the smart servers and clients.

"Medium" here is the noun meaning "a means of transmission", not the adjective
for "the quality between big and small."

Media carry the bytes of the requests somehow (e.g. via TCP, wrapped in HTTP, or
over SSH), and pass them to and from the protocol logic.  See the overview in
breezy/transport/smart/__init__.py.
é    Né   )Úlazy_importa	  
import select
import socket
import weakref

from breezy import (
    debug,
    trace,
    transport,
    ui,
    urlutils,
    )
from breezy.i18n import gettext
from breezy.bzr.smart import client, protocol, request, signals, vfs
from breezy.transport import ssh
)ÚerrorsÚosutilsc                   ó   — e Zd ZdZd„ ZdS )ÚHpssVfsRequestNotAllowedz[VFS requests over the smart server are not allowed. Encountered: %(method)s, %(arguments)s.c                 ó"   — || _         || _        d S ©N)ÚmethodÚ	arguments)Úselfr   r   s      ú9/usr/lib/python3/dist-packages/breezy/bzr/smart/medium.pyÚ__init__z!HpssVfsRequestNotAllowed.__init__F   s   € ØˆŒØ"ˆŒˆˆó    N©Ú__name__Ú
__module__Ú__qualname__Ú_fmtr   © r   r   r   r   A   s*   € € € € € ð)€Dð#ð #ð #ð #ð #r   r   c                 óV  — |                       t          j        ¦  «        r.t          j        }| t	          t          j        ¦  «        d…         } nY|                       t          j        ¦  «        r.t          j        }| t	          t          j        ¦  «        d…         } nt          j        }|| fS )až  Determine the right protocol factory for 'bytes'.

    This will return an appropriate protocol factory depending on the version
    of the protocol being used, as determined by inspecting the given bytes.
    The bytes should have at least one newline byte (i.e. be a whole line),
    otherwise it's possible that a request will be incorrectly identified as
    version 1.

    Typical use would be::

         factory, unused_bytes = _get_protocol_factory_for_bytes(bytes)
         server_protocol = factory(transport, write_func, root_client_path)
         server_protocol.accept_bytes(unused_bytes)

    :param bytes: a str of bytes of the start of the request.
    :returns: 2-tuple of (protocol_factory, unused_bytes).  protocol_factory is
        a callable that takes three args: transport, write_func,
        root_client_path.  unused_bytes are any bytes that were not part of a
        protocol version marker.
    N)Ú
startswithÚprotocolÚMESSAGE_VERSION_THREEÚbuild_server_protocol_threeÚlenÚREQUEST_VERSION_TWOÚSmartServerRequestProtocolTwoÚSmartServerRequestProtocolOne)ÚbytesÚprotocol_factorys     r   Ú_get_protocol_factory_for_bytesr"   K   s˜   € ð* ×Ò�Ô6Ñ7Ô7ð BÝ#Ô?ÐØ•c�(Ô8Ñ9Ô9Ð:Ð:Ô;ˆˆØ	×	Ò	�(Ô6Ñ	7Ô	7ð BÝ#ÔAÐØ•c�(Ô6Ñ7Ô7Ð8Ð8Ô9ˆˆå#ÔAÐØ˜UÐ"Ð"r   c                 ó¼   — d}d}|dk    r5 | d¦  «        }||z  }|dk    r|dfS |                      d¦  «        }|dk    °5|d|dz   …         }||dz   d…         }||fS )zäRead bytes using read_bytes_func until a newline byte.

    This isn't particularly efficient, so should only be used when the
    expected size of the line is quite short.

    :returns: a tuple of two strs: (line, excess)
    éÿÿÿÿr   é   ó   
N)Úfind)Úread_bytes_funcÚnewline_posr    Ú	new_bytesÚlineÚexcesss         r   Ú	_get_liner-   k   s™   € ð €KØ€EØ
˜Ò
Ð
Ø#�O AÑ&Ô&ˆ	Ø�ÑˆØ˜ÒÐà˜#�:ÐØ—j’j Ñ'Ô'ˆð ˜Ò
Ð
ð Ð!�+ ‘/Ð!Ô"€DØ�; ‘?Ð#Ð#Ô$€FØ�ˆ<Ðr   c                   ó<   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	S )
ÚSmartMediumzBBase class for smart protocol media, both client- and server-side.c                 ó   — d | _         d S r
   )Ú_push_back_buffer©r   s    r   r   zSmartMedium.__init__„   s   € Ø!%ˆÔÐÐr   c                 ó¨   — t          |t          ¦  «        st          |¦  «        ‚| j        �t	          d| j        ›�¦  «        ‚|dk    rdS || _        dS )zœReturn unused bytes to the medium, because they belong to the next
        request(s).

        This sets the _push_back_buffer to the given bytes.
        Nz1_push_back called when self._push_back_buffer is r   )Ú
isinstancer    Ú	TypeErrorr1   ÚAssertionError)r   Údatas     r   Ú
_push_backzSmartMedium._push_back‡   sk   € õ ˜$¥Ñ&Ô&ð 	"Ý˜D‘/”/Ð!ØÔ!Ð-Ý �.àÔ)Ð)ð,ñ-ô -ð -ð �3Š;ˆ;ØˆFØ!%ˆÔÐÐr   c                 ó\   — | j         dk    rt          | ›d�¦  «        ‚| j         }d | _         |S )Nr   zS._push_back_buffer should never be the empty string, which can be confused with EOF)r1   r6   ©r   r    s     r   Ú_get_push_back_bufferz!SmartMedium._get_push_back_buffer—   sE   € ØÔ! SÒ(Ð(Ý à48°D°Dð;ñ<ô <ð <ð Ô&ˆØ!%ˆÔØˆr   c                 óŒ   — | j         �|                      ¦   «         S t          |t          ¦  «        }|                      |¦  «        S )z±Read some bytes from this medium.

        :returns: some bytes, possibly more or less than the number requested
            in 'desired_count' depending on the medium.
        )r1   r;   ÚminÚ_MAX_READ_SIZEÚ_read_bytes)r   Údesired_countÚbytes_to_reads      r   Ú
read_byteszSmartMedium.read_bytes    sB   € ð Ô!Ð-Ø×-Ò-Ñ/Ô/Ð/Ý˜M­>Ñ:Ô:ˆØ×Ò Ñ.Ô.Ð.r   c                 ó*   — t          | j        ¦  «        ‚r
   ©ÚNotImplementedErrorr?   ©r   Úcounts     r   r?   zSmartMedium._read_bytes«   s   € Ý! $Ô"2Ñ3Ô3Ð3r   c                 ó^   — t          | j        ¦  «        \  }}|                      |¦  «         |S )a
  Read bytes from this request's response until a newline byte.

        This isn't particularly efficient, so should only be used when the
        expected size of the line is quite short.

        :returns: a string of bytes ending in a newline (byte 0x0A).
        )r-   rB   r8   )r   r+   r,   s      r   r-   zSmartMedium._get_line®   s.   € õ ! ¤Ñ1Ô1‰ˆˆfØ�Š˜ÑÔÐØˆr   c                 óH   — t           j                             | ||¦  «         dS )aR  Notify that this medium has activity.

        Implementations should call this from all methods that actually do IO.
        Be careful that it's not called twice, if one method is implemented on
        top of another.

        :param bytes: Number of bytes read or written.
        :param direction: 'read' or 'write' or None.
        N)ÚuiÚ
ui_factoryÚreport_transport_activity)r   r    Ú	directions      r   Ú_report_activityzSmartMedium._report_activityº   s$   € õ 	Œ×/Ò/°°e¸YÑGÔGÐGÐGÐGr   N)r   r   r   Ú__doc__r   r8   r;   rB   r?   r-   rN   r   r   r   r/   r/   �   sˆ   € € € € € ØLÐLð&ð &ð &ð&ð &ð &ð ð ð ð	/ð 	/ð 	/ð4ð 4ð 4ð
ð 
ð 
ð
Hð 
Hð 
Hð 
Hð 
Hr   r/   Úwin32i6'  c                   ó^   — e Zd ZdZej        Zdd„Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ ZdS )ÚSmartServerStreamMediumaØ  Handles smart commands coming over a stream.

    The stream may be a pipe connected to sshd, or a tcp socket, or an
    in-process fifo for testing.

    One instance is created for each connected client; it can serve multiple
    requests in the lifetime of the connection.

    The server passes requests through to an underlying backing transport,
    which will typically be a LocalTransport looking at the server's filesystem.

    :ivar _push_back_buffer: a str of bytes that have been read from the stream
        but not used yet, or None if there are no buffered bytes.  Subclasses
        should make sure to exhaust this buffer before reading more bytes from
        the stream.  See also the _push_back method.
    ú/Nc                 óÄ   — || _         || _        d| _        |€t          d¦  «        ‚|| _        t          |dz  d¦  «        | _        t                               | ¦  «         dS )zeConstruct new server.

        :param backing_transport: Transport for the directory served.
        FNzYou must supply a timeout.g      $@g      ð?)	Úbacking_transportÚroot_client_pathÚfinishedr6   Ú_client_timeoutr=   Ú_client_poll_timeoutr/   r   )r   rU   rV   Útimeouts       r   r   z SmartServerStreamMedium.__init__ã   sg   € ð "3ˆÔØ 0ˆÔØˆŒØˆ?Ý Ð!=Ñ>Ô>Ð>Ø&ˆÔÝ$'¨°$©¸Ñ$<Ô$<ˆÔ!Ý×Ò˜TÑ"Ô"Ð"Ð"Ð"r   c                 ó  — ddl m} 	 | j        s0|                      ¦   «         }|                      |¦  «         | j        ¯0n®# t
          j        $ re}t                               d 	                    |¦  «        ¦  «         t           
                    ¦   «          |                      ¦   «          Y d}~dS d}~wt          $ r/}|                     d 	                    | |¦  «        ¦  «         ‚ d}~ww xY w|                      ¦   «          dS )z,Serve requests until the client disconnects.r   )Ústderrz{}Nz{} terminating on exception {}
)Úsysr\   rW   Ú_build_protocolÚ_serve_one_requestr   ÚConnectionTimeoutÚtraceÚnoteÚformatÚlog_exception_quietlyÚ_disconnect_clientÚ	ExceptionÚwrite)r   r\   Úserver_protocolÚes       r   ÚservezSmartServerStreamMedium.serveò   s  € ð 	ÐÐÐÐÐð	Ø”mð 9Ø"&×"6Ò"6Ñ"8Ô"8�Ø×'Ò'¨Ñ8Ô8Ð8ð ”mð 9øøõ Ô'ð 	ð 	ð 	Ý�JŠJ�t—{’{ 1‘~”~Ñ&Ô&Ð&Ý×'Ò'Ñ)Ô)Ð)Ø×#Ò#Ñ%Ô%Ð%àˆFˆFˆFˆFˆFøøøøÝð 	ð 	ð 	Ø�LŠLÐ;×BÒBÀ4ÈÑKÔKÑLÔLÐLØøøøøð	øøøð 	×ÒÑ!Ô!Ð!Ð!Ð!s$   ˆ7A  Á C+ÁAB/Â/C+Â<*C&Ã&C+c                 ón   — t                                d                     | ¦  «        ¦  «         d| _        dS )z3When we finish this message, stop looking for more.zStopping {}TN)ra   Úmutterrc   rW   r2   s    r   Ú_stop_gracefullyz(SmartServerStreamMedium._stop_gracefully  s-   € å�Š�]×)Ò)¨$Ñ/Ô/Ñ0Ô0Ð0ØˆŒˆˆr   c                 ó   — dS ©z>Close the current connection. We stopped due to a timeout/etc.Nr   r2   s    r   re   z*SmartServerStreamMedium._disconnect_client  ó   € € € r   c                 ó*   — t          | j        ¦  «        ‚)a‰  Wait for more bytes to be read, but timeout if none available.

        This allows us to detect idle connections, and stop trying to read from
        them, without setting the socket itself to non-blocking. This also
        allows us to specify when we watch for idle timeouts.

        :return: Did we timeout? (True if we timed out, False if there is data
            to be read)
        )rE   Ú_wait_for_bytes_with_timeout©r   Útimeout_secondss     r   rr   z4SmartServerStreamMedium._wait_for_bytes_with_timeout  s   € õ " $Ô"CÑDÔDÐDr   c                 óú   — |                       | j        ¦  «         | j        rdS |                      ¦   «         }t	          |¦  «        \  }} || j        | j        | j        ¦  «        }|                     |¦  «         |S )a3  Identifies the version of the incoming request, and returns an
        a protocol object that can interpret it.

        If more bytes than the version prefix of the request are read, they will
        be fed into the protocol before it is returned.

        :returns: a SmartServerRequestProtocol.
        N)	rr   rX   rW   r-   r"   rU   Ú
_write_outrV   Úaccept_bytes)r   r    r!   Úunused_bytesr   s        r   r^   z'SmartServerStreamMedium._build_protocol  sˆ   € ð 	×)Ò)¨$Ô*>Ñ?Ô?Ð?ØŒ=ð 	à�4Ø—’Ñ Ô ˆÝ)HÈÑ)OÔ)OÑ&Ð˜,Ø#Ð#ØÔ" D¤O°TÔ5JñLô Lˆà×Ò˜lÑ+Ô+Ð+Øˆr   c                 óR  — |                       ¦   «         |z   }t          || j        ¦  «        }dx}}|sØ|sÖ|                       ¦   «         |k     r¾| j        rdS 	 t                               |gg |g|¦  «        \  }}}nt# t
          $ r[}t          |dd¦  «        }	|	€t          |dd¦  «        �|j        d         }	|	t          v rY d}~dS |	t          j
        k    rY d}~Œ©‚ d}~wt          $ r Y dS w xY w|s|s|                       ¦   «         |k     °¾|s|rdS t          j        d|fz  ¦  «        ‚)zÖselect() on a file descriptor, waiting for nonblocking read()

        This will raise a ConnectionTimeout exception if we do not get a
        readable handle before timeout_seconds.
        :return: None
        NÚerrnoÚargsr   z'disconnecting client after %.1f seconds)Ú_timerr=   rY   rW   ÚselectÚOSErrorÚgetattrr{   Ú_bad_file_descriptorrz   ÚEINTRÚ
ValueErrorr   r`   )
r   Úfdrt   Út_endÚpoll_timeoutÚrsÚxsÚ_ri   Úerrs
             r   Ú_wait_on_descriptorz+SmartServerStreamMedium._wait_on_descriptor1  sƒ  € ð —’‘” Ñ/ˆÝ˜?¨DÔ,EÑFÔFˆØˆˆˆRØð 	˜Rð 	 D§K¢K¡M¤M°EÒ$9Ð$9ØŒ}ð Ø�ðÝ"ŸMšM¨2¨$°°R°D¸,ÑGÔG‘	��A�r�røÝð 
ð 
ð 
Ý˜a ¨$Ñ/Ô/�Ø�;¥7¨1¨f°dÑ#;Ô#;Ð#Gàœ& œ)�CØÕ.Ð.Ð.Ø�F�F�F�F�FØ�EœKÒ'Ð'à�H�H�H�HØøøøøÝð ð ð Ø��ðøøøð! ð 	˜Rð 	 D§K¢K¡M¤M°EÒ$9Ð$9ð$ ð 	�ð 	ØˆFÝÔ&Ð'PØ*9Ð);ñ(<ñ =ô =ð 	=s*   Á#A; Á;
C,Â:CÃCÃCÃC,Ã+C,c                 ó¦   — |€dS 	 |                       |¦  «         dS # t          $ r ‚ t          $ r}|                      ¦   «          Y d}~dS d}~ww xY w)z|Read one request from input, process, send back a response.

        :param protocol: a SmartServerRequestProtocol.
        N)Ú_serve_one_request_unguardedÚKeyboardInterruptrf   Úterminate_due_to_error)r   r   ri   s      r   r_   z*SmartServerStreamMedium._serve_one_requestR  s†   € ð
 ÐØˆFð	*Ø×-Ò-¨hÑ7Ô7Ð7Ð7Ð7øÝ ð 	ð 	ð 	ØÝð 	*ð 	*ð 	*Ø×'Ò'Ñ)Ô)Ð)Ð)Ð)Ð)Ð)Ð)Ð)øøøøð	*øøøs   † �A±AÁAc                 ó*   — t          | j        ¦  «        ‚)z<Called when an unhandled exception from the protocol occurs.)rE   rŽ   r2   s    r   rŽ   z.SmartServerStreamMedium.terminate_due_to_error`  s   € å! $Ô"=Ñ>Ô>Ð>r   c                 ó*   — t          | j        ¦  «        ‚)zhGet some bytes from the medium.

        :param desired_count: number of bytes we want to read.
        rD   ©r   r@   s     r   r?   z#SmartServerStreamMedium._read_bytesd  s   € õ
 " $Ô"2Ñ3Ô3Ð3r   ©rS   N)r   r   r   rO   Útimer|   r   rj   rm   re   rr   r^   rŠ   r_   rŽ   r?   r   r   r   rR   rR   Ï   sÉ   € € € € € ðð ð" ŒY€Fð#ð #ð #ð #ð"ð "ð "ð(ð ð ð
Mð Mð Mð
Eð 
Eð 
Eðð ð ð(=ð =ð =ðB*ð *ð *ð?ð ?ð ?ð4ð 4ð 4ð 4ð 4r   rR   c                   óJ   — e Zd Z	 	 dd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd	„ Z	d
„ Z
d„ ZdS )ÚSmartServerSocketStreamMediumrS   Nc                 óÞ   — t                                | |||¬¦  «         |                     d¦  «         || _        	 |                     ¦   «         | _        dS # t          $ r d| _        Y dS w xY w)z�Constructor.

        :param sock: the socket the server will read from.  It will be put
            into blocking mode.
        )rV   rZ   Tz	<unknown>N)rR   r   ÚsetblockingÚsocketÚgetpeernameÚ_client_infor~   )r   ÚsockrU   rV   rZ   s        r   r   z&SmartServerSocketStreamMedium.__init__n  s•   € õ 	 ×(Ò(ØÐ#Ð6FØð 	)ñ 	ô 	ð 	ð 	×Ò˜ÑÔÐØˆŒð	,Ø $× 0Ò 0Ñ 2Ô 2ˆDÔÐÐøÝð 	,ð 	,ð 	,Ø +ˆDÔÐÐÐð	,øøøs   ¼A ÁA,Á+A,c                 óL   — d                      | j        j        | j        ¦  «        S )Nz{}(client={}))rc   Ú	__class__r   rš   r2   s    r   Ú__str__z%SmartServerSocketStreamMedium.__str__€  s    € Ø×%Ò% d¤nÔ&=¸tÔ?PÑQÔQÐQr   c                 óX   — d                      | j        | j        j        | j        ¦  «        S )Nz{}.{}(client={}))rc   r   r�   r   rš   r2   s    r   Ú__repr__z&SmartServerSocketStreamMedium.__repr__ƒ  s+   € Ø!×(Ò(¨¬¸$¼.Ô:QØ%)Ô%6ñ8ô 8ð 	8r   c                 ó  — |                      ¦   «         rW|                      t          j        ¦  «        }|dk    r	d| _        d S |                     |¦  «         |                      ¦   «         °W|                      |j        ¦  «         d S )Nr   T)Únext_read_sizerB   r   ÚMAX_SOCKET_CHUNKrW   rw   r8   Úunused_data)r   r   r    s      r   rŒ   z:SmartServerSocketStreamMedium._serve_one_request_unguarded‡  sˆ   € Ø×%Ò%Ñ'Ô'ð 	)ð —O’O¥GÔ$<Ñ=Ô=ˆEØ˜Š|ˆ|Ø $�”Ø�Ø×!Ò! %Ñ(Ô(Ð(ð ×%Ò%Ñ'Ô'ð 	)ð 	�Š˜Ô,Ñ-Ô-Ð-Ð-Ð-r   c                 ó8   — | j                              ¦   «          dS ro   )r˜   Úcloser2   s    r   re   z0SmartServerSocketStreamMedium._disconnect_client”  s   € àŒ×ÒÑÔÐÐÐr   c                 ó8   — |                       | j        |¦  «        S )á�  Wait for more bytes to be read, but timeout if none available.

        This allows us to detect idle connections, and stop trying to read from
        them, without setting the socket itself to non-blocking. This also
        allows us to specify when we watch for idle timeouts.

        :return: None, this will raise ConnectionTimeout if we time out before
            data is available.
        )rŠ   r˜   rs   s     r   rr   z:SmartServerSocketStreamMedium._wait_for_bytes_with_timeout˜  s   € ð ×'Ò'¨¬°_ÑEÔEÐEr   c                 ó@   — t          j        | j        | j        ¦  «        S r
   )r   Úread_bytes_from_socketr˜   rN   r‘   s     r   r?   z)SmartServerSocketStreamMedium._read_bytes¤  s!   € ÝÔ-ØŒK˜Ô.ñ0ô 0ð 	0r   c                 óF   — | j                              ¦   «          d| _        d S ©NT)r˜   r¦   rW   r2   s    r   rŽ   z4SmartServerSocketStreamMedium.terminate_due_to_error¨  s#   € ð 	Œ×ÒÑÔÐØˆŒˆˆr   c                 ó6  — t          j        ¦   «         }t          j        | j        || j        ¦  «         dt
          j        v rWt          j        ¦   «         }t           
                    dd|t          |¦  «        t          j        ¦   «         |z
  fz  ¦  «         d S d S )NÚhpssz*%12s: [%s] %d bytes to the socket in %.3fsÚwrote)r   Úperf_counterÚsend_allr˜   rN   ÚdebugÚdebug_flagsÚ_threadÚ	get_identra   rl   r   )r   r    ÚtstartÚ	thread_ids       r   rv   z(SmartServerSocketStreamMedium._write_out®  s™   € ÝÔ%Ñ'Ô'ˆÝÔ˜œ e¨TÔ-BÑCÔCÐCØ•UÔ&Ð&Ð&ÝÔ)Ñ+Ô+ˆIÝ�LŠLÐEØ# Yµ°E±
´
Ý#Ô0Ñ2Ô2°VÑ;ð=ñ=ñ >ô >ð >ð >ð >ð 'Ð&r   r’   )r   r   r   r   rž   r    rŒ   re   rr   r?   rŽ   rv   r   r   r   r•   r•   l  s¬   € € € € € àADØð,ð ,ð ,ð ,ð$Rð Rð Rð8ð 8ð 8ð.ð .ð .ðð ð ð
Fð 
Fð 
Fð0ð 0ð 0ðð ð ð>ð >ð >ð >ð >r   r•   c                   óJ   ‡ — e Zd Zd
d„Zˆ fd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
ˆ xZS )ÚSmartServerPipeStreamMediumNc                 ó  — t                                | ||¬¦  «         t          j        dk    rFddl}||fD ]=}t          |dd¦  «        }|r(|                      |¦   «         t          j        ¦  «         Œ>|| _	        || _
        dS )zãConstruct new server.

        :param in_file: Python file from which requests can be read.
        :param out_file: Python file to write responses.
        :param backing_transport: Transport for the directory served.
        )rZ   rP   r   NÚfileno)rR   r   r]   ÚplatformÚmsvcrtr   ÚsetmodeÚosÚO_BINARYÚ_inÚ_out)r   Úin_fileÚout_filerU   rZ   r½   Úfr»   s           r   r   z$SmartServerPipeStreamMedium.__init__º  s›   € õ 	 ×(Ò(¨Ð/@Ø18ð 	)ñ 	:ô 	:ð 	:åŒ<˜7Ò"Ð"àˆMˆMˆMØ˜xÐ(ð :ð :�Ý   H¨dÑ3Ô3�Øð :Ø—N’N 6 6¡8¤8­R¬[Ñ9Ô9Ð9øØˆŒØˆŒ	ˆ	ˆ	r   c                 óJ  •— | j         }t                               t          | ¦  «        |¦  «         	 t	          ¦   «                              ¦   «         t                               t          | ¦  «        ¦  «         S # t                               t          | ¦  «        ¦  «         w xY w)z!See SmartServerStreamMedium.serve)rm   ÚsignalsÚregister_on_hangupÚidÚsuperrj   Úunregister_on_hangup)r   Ústop_gracefullyr�   s     €r   rj   z!SmartServerPipeStreamMedium.serveÍ  sz   ø€ ð Ô/ˆÝ×"Ò"¥2 d¡8¤8¨_Ñ=Ô=Ð=ð	3Ý‘7”7—=’=‘?”?å×(Ò(­¨D©¬Ñ2Ô2Ð2Ð2ø�G×(Ò(­¨D©¬Ñ2Ô2Ð2Ð2øøøs   ²A9 Á9)B"c                 ó  — 	 |                      ¦   «         }|dk    r| j                             ¦   «          d S |                      |¦  «        }|dk    r"d| _        | j                             ¦   «          d S |                     |¦  «         Œˆ)NTr   r   )r¢   rÂ   ÚflushrB   rW   rw   )r   r   rA   r    s       r   rŒ   z8SmartServerPipeStreamMedium._serve_one_request_unguardedØ  s�   € ð	)ð %×3Ò3Ñ5Ô5ˆMØ Ò!Ð!à”	—’Ñ!Ô!Ð!Ø�Ø—O’O MÑ2Ô2ˆEØ˜Š|ˆ|à $�”Ø”	—’Ñ!Ô!Ð!Ø�Ø×!Ò! %Ñ(Ô(Ð(ð	)r   c                 óœ   — | j                              ¦   «          | j                             ¦   «          | j                             ¦   «          d S r
   )rÁ   r¦   rÂ   rÎ   r2   s    r   re   z.SmartServerPipeStreamMedium._disconnect_clientê  s>   € ØŒ�ŠÑÔÐØŒ	�ŠÑÔÐØŒ	�ŠÑÔÐÐÐr   c                 ó¶   — t          | j        dd¦  «        �t          j        dk    rdS 	 |                      | j        |¦  «        S # t
          j        $ r Y dS w xY w)r¨   r»   NrP   )r   rÁ   r]   r¼   rŠ   ÚioÚUnsupportedOperationrs   s     r   rr   z8SmartServerPipeStreamMedium._wait_for_bytes_with_timeoutï  sl   € õ �D”H˜h¨Ñ-Ô-Ð5Ý”< 7Ò*Ð*àˆFð	Ø×+Ò+¨D¬H°oÑFÔFÐFøÝÔ&ð 	ð 	ð 	ØˆFˆFð	øøøs   ªA ÁAÁAc                 ó6   — | j                              |¦  «        S r
   )rÁ   Úreadr‘   s     r   r?   z'SmartServerPipeStreamMedium._read_bytes  s   € ØŒx�}Š}˜]Ñ+Ô+Ð+r   c                 óF   — | j                              ¦   «          d| _        d S r¬   )rÂ   r¦   rW   r2   s    r   rŽ   z2SmartServerPipeStreamMedium.terminate_due_to_error  s!   € ð 	Œ	�ŠÑÔÐØˆŒˆˆr   c                 ó:   — | j                              |¦  «         d S r
   )rÂ   rg   r:   s     r   rv   z&SmartServerPipeStreamMedium._write_out  s   € ØŒ	�Š˜ÑÔÐÐÐr   r
   )r   r   r   r   rj   rŒ   re   rr   r?   rŽ   rv   Ú__classcell__©r�   s   @r   r¹   r¹   ¸  s¦   ø€ € € € € ðð ð ð ð&	3ð 	3ð 	3ð 	3ð 	3ð)ð )ð )ð$ð ð ð
ð ð ð&,ð ,ð ,ðð ð ðð ð ð ð ð ð r   r¹   c                   óT   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ ZdS )ÚSmartClientMediumRequestaM  A request on a SmartClientMedium.

    Each request allows bytes to be provided to it via accept_bytes, and then
    the response bytes to be read via read_bytes.

    For instance:
    request.accept_bytes('123')
    request.finished_writing()
    result = request.read_bytes(3)
    request.finished_reading()

    It is up to the individual SmartClientMedium whether multiple concurrent
    requests can exist. See SmartClientMedium.get_request to obtain instances
    of SmartClientMediumRequest, and the concrete Medium you are using for
    details on concurrency and pipelining.
    c                 ó"   — || _         d| _        dS )z;Construct a SmartClientMediumRequest for the medium medium.ÚwritingN)Ú_mediumÚ_state©r   Úmediums     r   r   z!SmartClientMediumRequest.__init__!  s   € àˆŒð  ˆŒˆˆr   c                 ón   — | j         dk    rt          j        | ¦  «        ‚|                      |¦  «         dS )ap  Accept bytes for inclusion in this request.

        This method may not be called after finished_writing() has been
        called.  It depends upon the Medium whether or not the bytes will be
        immediately transmitted. Message based Mediums will tend to buffer the
        bytes until finished_writing() is called.

        :param bytes: A bytestring.
        rÜ   N)rÞ   r   ÚWritingCompletedÚ_accept_bytesr:   s     r   rw   z%SmartClientMediumRequest.accept_bytes)  s<   € ð Œ;˜)Ò#Ð#ÝÔ)¨$Ñ/Ô/Ð/Ø×Ò˜5Ñ!Ô!Ð!Ð!Ð!r   c                 ó*   — t          | j        ¦  «        ‚)z×Helper for accept_bytes.

        Accept_bytes checks the state of the request to determing if bytes
        should be accepted. After that it hands off to _accept_bytes to do the
        actual acceptance.
        )rE   rã   r:   s     r   rã   z&SmartClientMediumRequest._accept_bytes7  s   € õ " $Ô"4Ñ5Ô5Ð5r   c                 ó¸   — | j         dk    rt          j        | ¦  «        ‚| j         dk    rt          j        | ¦  «        ‚d| _         |                      ¦   «          dS )a  Inform the request that all desired data has been read.

        This will remove the request from the pipeline for its medium (if the
        medium supports pipelining) and any further calls to methods on the
        request will raise ReadingCompleted.
        rÜ   ÚreadingÚdoneN)rÞ   r   ÚWritingNotCompleteÚReadingCompletedÚ_finished_readingr2   s    r   Úfinished_readingz)SmartClientMediumRequest.finished_reading@  s_   € ð Œ;˜)Ò#Ð#ÝÔ+¨DÑ1Ô1Ð1ØŒ;˜)Ò#Ð#ÝÔ)¨$Ñ/Ô/Ð/ØˆŒØ×ÒÑ Ô Ð Ð Ð r   c                 ó*   — t          | j        ¦  «        ‚)zßHelper for finished_reading.

        finished_reading checks the state of the request to determine if
        finished_reading is allowed, and if it is hands off to _finished_reading
        to perform the action.
        )rE   rê   r2   s    r   rê   z*SmartClientMediumRequest._finished_readingN  ó   € õ " $Ô"8Ñ9Ô9Ð9r   c                 óz   — | j         dk    rt          j        | ¦  «        ‚d| _         |                      ¦   «          dS )zÎFinish the writing phase of this request.

        This will flush all pending data for this request along the medium.
        After calling finished_writing, you may not call accept_bytes anymore.
        rÜ   ræ   N)rÞ   r   râ   Ú_finished_writingr2   s    r   Úfinished_writingz)SmartClientMediumRequest.finished_writingW  sA   € ð Œ;˜)Ò#Ð#ÝÔ)¨$Ñ/Ô/Ð/ØˆŒØ×ÒÑ Ô Ð Ð Ð r   c                 ó*   — t          | j        ¦  «        ‚)zßHelper for finished_writing.

        finished_writing checks the state of the request to determine if
        finished_writing is allowed, and if it is hands off to _finished_writing
        to perform the action.
        )rE   rï   r2   s    r   rï   z*SmartClientMediumRequest._finished_writingb  rí   r   c                 ó¨   — | j         dk    rt          j        | ¦  «        ‚| j         dk    rt          j        | ¦  «        ‚|                      |¦  «        S )a>  Read bytes from this requests response.

        This method will block and wait for count bytes to be read. It may not
        be invoked until finished_writing() has been called - this is to ensure
        a message-based approach to requests, for compatibility with message
        based mediums like HTTP.
        rÜ   ræ   )rÞ   r   rè   ré   r?   rF   s     r   rB   z#SmartClientMediumRequest.read_bytesk  sT   € ð Œ;˜)Ò#Ð#ÝÔ+¨DÑ1Ô1Ð1ØŒ;˜)Ò#Ð#ÝÔ)¨$Ñ/Ô/Ð/Ø×Ò Ñ&Ô&Ð&r   c                 ó6   — | j                              |¦  «        S )aV  Helper for SmartClientMediumRequest.read_bytes.

        read_bytes checks the state of the request to determing if bytes
        should be read. After that it hands off to _read_bytes to do the
        actual read.

        By default this forwards to self._medium.read_bytes because we are
        operating on the medium's stream.
        )rÝ   rB   rF   s     r   r?   z$SmartClientMediumRequest._read_bytesy  s   € ð Œ|×&Ò& uÑ-Ô-Ð-r   c                 ó€   — |                       ¦   «         }|                     d¦  «        st          j        d¦  «        ‚|S )Nr&   zkUnexpected end of message. Please check connectivity and permissions, and report a bug if problems persist.)Ú
_read_lineÚendswithr   ÚConnectionReset)r   r+   s     r   Ú	read_linez"SmartClientMediumRequest.read_line…  sK   € Ø�ŠÑ Ô ˆØ�}Š}˜UÑ#Ô#ð 	JåÔ(ðIñJô Jð Jð ˆr   c                 ó4   — | j                              ¦   «         S )z¬Helper for SmartClientMediumRequest.read_line.

        By default this forwards to self._medium._get_line because we are
        operating on the medium's stream.
        )rÝ   r-   r2   s    r   rõ   z#SmartClientMediumRequest._read_lineŽ  s   € ð Œ|×%Ò%Ñ'Ô'Ð'r   N)r   r   r   rO   r   rw   rã   rë   rê   rð   rï   rB   r?   rø   rõ   r   r   r   rÚ   rÚ     sÃ   € € € € € ðð ð" ð  ð  ð"ð "ð "ð6ð 6ð 6ð!ð !ð !ð:ð :ð :ð	!ð 	!ð 	!ð:ð :ð :ð'ð 'ð 'ð
.ð 
.ð 
.ðð ð ð(ð (ð (ð (ð (r   rÚ   c                   ó   — e Zd ZdZd„ Zd„ ZdS )Ú_VfsRefuserz.An object that refuses all VFS requests.

    c                 ó\   — t           j        j                             d| j        d¦  «         d S )NÚcallzvfs refuser)ÚclientÚ_SmartClientÚhooksÚinstall_named_hookÚ	check_vfsr2   s    r   r   z_VfsRefuser.__init__œ  s3   € ÝÔÔ!×4Ò4Ø�D”N Mñ	3ô 	3ð 	3ð 	3ð 	3r   c                 óÜ   — 	 t           j                             |j        ¦  «        }n# t          $ r Y d S w xY wt          |t          j        ¦  «        rt          |j        |j	        ¦  «        ‚d S r
   )
ÚrequestÚrequest_handlersÚgetr   ÚKeyErrorÚ
issubclassÚvfsÚ
VfsRequestr   r{   )r   ÚparamsÚrequest_methods      r   r  z_VfsRefuser.check_vfs   sz   € ð	Ý$Ô5×9Ò9¸&¼-ÑHÔHˆNˆNøÝð 	ð 	ð 	àˆFˆFð	øøøõ �n¥c¤nÑ5Ô5ð 	GÝ*¨6¬=¸&¼+ÑFÔFÐFð	Gð 	Gs   ‚$' §
5´5N)r   r   r   rO   r   r  r   r   r   rû   rû   —  sA   € € € € € ðð ð3ð 3ð 3ðGð Gð Gð Gð Gr   rû   c                   ó0   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZdS )Ú_DebugCounterzñAn object that counts the HPSS calls made to each client medium.

    When a medium is garbage-collected, or failing that when
    breezy.global_state exits, the total number of calls made on that medium
    are reported via trace.note.
    c                 óø   — t                                ¦   «         | _        t          j        j                             d| j        d¦  «         t          j	        ¦   «         j
                             | j        ¦  «         d S )Nrý   zhpss call counter)ÚweakrefÚWeakKeyDictionaryÚcountsrþ   rÿ   r   r  Úincrement_call_countÚbreezyÚget_global_stateÚ
exit_stackÚcallbackÚ	flush_allr2   s    r   r   z_DebugCounter.__init__²  si   € Ý×/Ò/Ñ1Ô1ˆŒÝÔÔ!×4Ò4Ø�DÔ-Ð/Bñ	Dô 	Dð 	DåÔÑ!Ô!Ô,×5Ò5°d´nÑEÔEÐEÐEÐEr   c                 ó˜   — t          |¦  «        }t          dd|¬¦  «        | j        |<   t                               || j        ¦  «        }dS )z”Start tracking calls made to a medium.

        This only keeps a weakref to the medium, so shouldn't affect the
        medium's lifetime.
        r   )rG   Ú	vfs_countÚmedium_reprN)ÚreprÚdictr  r  Úrefrç   )r   rà   r  r  s       r   Útrackz_DebugCounter.track¸  sL   € õ ˜6‘l”lˆå"¨°aØ/:ð<ñ <ô <ˆŒ�FÑõ �kŠk˜& $¤)Ñ,Ô,ˆˆˆr   c                 ó  — | j         |j                 }|dxx         dz  cc<   	 t          j                             |j        ¦  «        }n# t          $ r Y d S w xY wt          |t          j	        ¦  «        r|dxx         dz  cc<   d S d S )NrG   r%   r  )
r  rà   r  r  r  r   r  r  r	  r
  )r   r  Úvaluer  s       r   r  z"_DebugCounter.increment_call_countÈ  s©   € à”˜FœMÔ*ˆØˆgˆˆŒ˜!Ñˆˆ‰ð	Ý$Ô5×9Ò9¸&¼-ÑHÔHˆNˆNøÝð 	ð 	ð 	àˆFˆFð	øøøõ �n¥c¤nÑ5Ô5ð 	$Ø�+ÐÐÔ !Ñ#ÐÐÑÐÐð	$ð 	$s   ¤$A	 Á	
AÁAc                 óì   — | j         |         }|d         |d         |d         }}}d|d<   d|d<   |dk    r>t                               t          d¦  «                             |||¦  «        ¦  «         d S d S )NrG   r  r  r   zHPSS calls: {0} ({1} vfs) {2})r  ra   rb   Úgettextrc   )r   r  r!  rG   r  r  s         r   rç   z_DebugCounter.doneÔ  s“   € Ø”˜CÔ ˆà�'ŒN˜E +Ô.°°mÔ0Dð &ˆyˆð
 ˆˆg‰ØˆˆkÑØ�AŠ:ˆ:Ý�JŠJ•wÐ>Ñ?Ô?×FÒFØ˜i¨ñ6ô 6ñ 7ô 7ð 7ð 7ð 7ð ˆ:r   c                 ó‚   — t          | j                             ¦   «         ¦  «        D ]}|                      |¦  «         Œd S r
   )Úlistr  Úkeysrç   )r   r  s     r   r  z_DebugCounter.flush_allá  sB   € Ý˜œ×(Ò(Ñ*Ô*Ñ+Ô+ð 	ð 	ˆCØ�IŠI�c‰NŒNˆNˆNð	ð 	r   N)	r   r   r   rO   r   r  r  rç   r  r   r   r   r  r  ª  sl   € € € € € ðð ðFð Fð Fð-ð -ð -ð 
$ð 
$ð 
$ð7ð 7ð 7ðð ð ð ð r   r  c                   óF   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
ˆ xZS )	ÚSmartClientMediumzBSmart client is a medium for sending smart protocol requests over.c                 óV  •— t          ¦   «                              ¦   «          || _        d | _        d | _        d| _        d | _        dt          j        v r/t          €t          ¦   «         a	t                               | ¦  «         dt          j        v rt          €t          ¦   «         ad S d S d S )NFr®   Úhpss_client_no_vfs)rÊ   r   ÚbaseÚ_protocol_version_errorÚ_protocol_versionÚ_done_helloÚ_remote_version_is_beforer²   r³   Ú_debug_counterr  r  Ú_vfs_refuserrû   )r   r+  r�   s     €r   r   zSmartClientMedium.__init__í  s¢   ø€ Ý‰Œ×ÒÑÔÐØˆŒ	Ø'+ˆÔ$Ø!%ˆÔØ ˆÔð
 *.ˆÔ&à•UÔ&Ð&Ð&åÐ%Ý!.¡¤�Ý× Ò  Ñ&Ô&Ð&Ø¥5Ô#4Ð4Ð4åÐ#Ý*™}œ}���ð 5Ð4à#Ð#r   c                 ó*   — | j         €dS || j         k    S )aþ  Is it possible the remote side supports RPCs for a given version?

        Typical use::

            needed_version = (1, 2)
            if medium._is_remote_before(needed_version):
                fallback_to_pre_1_2_rpc()
            else:
                try:
                    do_1_2_rpc()
                except UnknownSmartMethod:
                    medium._remember_remote_is_before(needed_version)
                    fallback_to_pre_1_2_rpc()

        :seealso: _remember_remote_is_before
        NF)r/  ©r   Úversion_tuples     r   Ú_is_remote_beforez#SmartClientMedium._is_remote_before  s    € ð" Ô)Ð1à�5Ø Ô >Ò>Ð>r   c                 óð   — | j         �g|| j         k    r\t                               d|| j         ¦  «         dt          j        v r+t
          j                             d|›d| j         ›d�¦  «         dS || _         dS )zoTell this medium that the remote side is older the given version.

        :seealso: _is_remote_before
        Nz`_remember_remote_is_before(%r) called, but _remember_remote_is_before(%r) was called previously.r®   z_remember_remote_is_before(z)) called, but _remember_remote_is_before(z) was called previously.)r/  ra   rl   r²   r³   rJ   rK   Úshow_warningr3  s     r   Ú_remember_remote_is_beforez,SmartClientMedium._remember_remote_is_before  s¤   € ð
 Ô*Ð6Ø Ô >Ò>Ð>õ
 �LŠLðHØIVÐX\ÔXvñxô xð xð �Ô*Ð*Ð*Ý”×*Ò*Ð*ð %�}�} dÔ&DÐ&DÐ&DðFñGô Gð Gð ˆFØ)6ˆÔ&Ð&Ð&r   c                 ó  — | j         �| j         ‚| j        sj	 |                      ¦   «         }t                               |¦  «        }|                     ¦   «          d| _        n# t          j        $ r}|| _         ‚ d}~ww xY wdS )z(Find out if 'hello' smart request works.NTÚ2)r,  r.  Úget_requestr   ÚSmartClientRequestProtocolOneÚquery_versionr   ÚSmartProtocolError)r   Úmedium_requestÚclient_protocolri   s       r   Úprotocol_versionz"SmartClientMedium.protocol_version/  s¢   € àÔ'Ð3ØÔ.Ð.ØÔð 	ðØ!%×!1Ò!1Ñ!3Ô!3�õ #+×"HÒ"HØ"ñ#$ô #$�à×-Ò-Ñ/Ô/Ð/Ø#'�Ô Ð øÝÔ,ð ð ð ð 01�Ô,Øøøøøð	øøøð
 ˆss   —A	A! Á!A=Á0A8Á8A=c                 ó   — dS )aŠ  Should RemoteBzrDirFormat.probe_transport send a smart request on
        this medium?

        Some transports are unambiguously smart-only; there's no need to check
        if the transport is able to carry smart requests, because that's all
        it is for.  In those cases, this method should return False.

        But some HTTP transports can sometimes fail to carry smart requests,
        but still be usuable for accessing remote bzrdirs via plain file
        accesses.  So for those transports, their media should return True here
        so that RemoteBzrDirFormat can determine if it is appropriate for that
        transport.
        Fr   r2   s    r   Úshould_probezSmartClientMedium.should_probeC  s	   € ð ˆur   c                 ó   — dS )zvIf this medium maintains a persistent connection, close it.

        The default implementation does nothing.
        Nr   r2   s    r   Ú
disconnectzSmartClientMedium.disconnectS  rp   r   c                 ó¶   — t                                | j        d¦  «        }t                                ||j        ¦  «        }t                                |¦  «        S )a  Convert transport into a path suitable for using in a request.

        Note that the resulting remote path doesn't encode the host name or
        anything but path, so it is only safe to use it in requests sent over
        the medium from the matching transport.
        rS   )ÚurlutilsÚjoinr+  Úrelative_urlÚunquote)r   Ú	transportÚmedium_baseÚrel_urls       r   Úremote_path_from_transportz,SmartClientMedium.remote_path_from_transportY  sD   € õ —m’m D¤I¨sÑ3Ô3ˆÝ×'Ò'¨°Y´^ÑDÔDˆÝ×Ò Ñ(Ô(Ð(r   )r   r   r   rO   r   r5  r8  rA  rC  rE  rN  r×   rØ   s   @r   r(  r(  ê  s˜   ø€ € € € € ØLÐLð-ð -ð -ð -ð -ð,?ð ?ð ?ð,7ð 7ð 7ð,ð ð ð(ð ð ð ð ð ð	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)r   r(  c                   ó6   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	dS )	ÚSmartClientStreamMediuma  Stream based medium common class.

    SmartClientStreamMediums operate on a stream. All subclasses use a common
    SmartClientStreamMediumRequest for their requests, and should implement
    _accept_bytes and _read_bytes to allow the request objects to send and
    receive bytes.
    c                 óJ   — t                                | |¦  «         d | _        d S r
   )r(  r   Ú_current_request©r   r+  s     r   r   z SmartClientStreamMedium.__init__n  s&   € Ý×"Ò" 4¨Ñ.Ô.Ð.Ø $ˆÔÐÐr   c                 ó0   — |                       |¦  «         d S r
   )rã   r:   s     r   rw   z$SmartClientStreamMedium.accept_bytesr  s   € Ø×Ò˜5Ñ!Ô!Ð!Ð!Ð!r   c                 ó.   — |                       ¦   «          dS )zgThe SmartClientStreamMedium knows how to close the stream when it is
        finished with it.
        N)rE  r2   s    r   Ú__del__zSmartClientStreamMedium.__del__u  s   € ð 	�ŠÑÔÐÐÐr   c                 ó*   — t          | j        ¦  «        ‚)zÀFlush the output stream.

        This method is used by the SmartClientStreamMediumRequest to ensure that
        all data for a request is sent, to avoid long timeouts or deadlocks.
        )rE   Ú_flushr2   s    r   rX  zSmartClientStreamMedium._flush{  s   € õ " $¤+Ñ.Ô.Ð.r   c                 ó    — t          | ¦  «        S )z—See SmartClientMedium.get_request().

        SmartClientStreamMedium always returns a SmartClientStreamMediumRequest
        for get_request.
        )ÚSmartClientStreamMediumRequestr2   s    r   r;  z#SmartClientStreamMedium.get_requestƒ  s   € õ .¨dÑ3Ô3Ð3r   c                 ó<   — |                       ¦   «          d| _        dS )zWe have been disconnected, reset current state.

        This resets things like _current_request and connected state.
        N)rE  rR  r2   s    r   ÚresetzSmartClientStreamMedium.reset‹  s"   € ð
 	�ŠÑÔÐØ $ˆÔÐÐr   N)
r   r   r   rO   r   rw   rV  rX  r;  r\  r   r   r   rP  rP  e  sx   € € € € € ðð ð%ð %ð %ð"ð "ð "ðð ð ð/ð /ð /ð4ð 4ð 4ð%ð %ð %ð %ð %r   rP  c                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )ÚSmartSimplePipesClientMediumzyA client medium using simple pipes.

    This client does not manage the pipes: it assumes they will always be open.
    c                 óX   — t                                | |¦  «         || _        || _        d S r
   )rP  r   Ú_readable_pipeÚ_writeable_pipe)r   Úreadable_pipeÚwriteable_piper+  s       r   r   z%SmartSimplePipesClientMedium.__init__š  s.   € Ý×(Ò(¨¨tÑ4Ô4Ð4Ø+ˆÔØ-ˆÔÐÐr   c                 ó  — 	 | j                              |¦  «         nG# t          $ r:}|j        t          j        t          j        fv rt          j        d|¦  «        ‚‚ d}~ww xY w|                      t          |¦  «        d¦  «         dS )ú)See SmartClientStreamMedium.accept_bytes.z#Error trying to write to subprocessNrg   )
ra  rg   r~   rz   ÚEINVALÚEPIPEr   r÷   rN   r   )r   r7   ri   s      r   rã   z*SmartSimplePipesClientMedium._accept_bytesŸ  s—   € ð	ØÔ ×&Ò& tÑ,Ô,Ð,Ð,øÝð 	ð 	ð 	ØŒw�5œ<­¬Ð5Ð5Ð5ÝÔ,Ø9¸1ñ>ô >ð >àøøøøð		øøøð
 	×Ò�c $™iœi¨Ñ1Ô1Ð1Ð1Ð1s   ‚ �
A!§5AÁA!c                 ó8   — | j                              ¦   «          dS ©z%See SmartClientStreamMedium._flush().N)ra  rÎ   r2   s    r   rX  z#SmartSimplePipesClientMedium._flushª  s   € ð
 	Ô×"Ò"Ñ$Ô$Ð$Ð$Ð$r   c                 óª   — t          |t          ¦  «        }| j                             |¦  «        }|                      t          |¦  «        d¦  «         |S )z(See SmartClientStreamMedium._read_bytes.rÔ   )r=   r>   r`  rÔ   rN   r   )r   rG   rA   r7   s       r   r?   z(SmartSimplePipesClientMedium._read_bytes±  sH   € å˜E¥>Ñ2Ô2ˆØÔ"×'Ò'¨Ñ6Ô6ˆØ×Ò�c $™iœi¨Ñ0Ô0Ð0Øˆr   N)r   r   r   rO   r   rã   rX  r?   r   r   r   r^  r^  ”  sZ   € € € € € ðð ð
.ð .ð .ð
	2ð 	2ð 	2ð%ð %ð %ðð ð ð ð r   r^  c                   ó   — e Zd ZdZ	 	 dd„ZdS )Ú	SSHParamsz6A set of parameters for starting a remote bzr via SSH.NÚbzrc                 óL   — || _         || _        || _        || _        || _        d S r
   )ÚhostÚportÚusernameÚpasswordÚbzr_remote_path)r   ro  rp  rq  rr  rs  s         r   r   zSSHParams.__init__¼  s,   € àˆŒ	ØˆŒ	Ø ˆŒØ ˆŒØ.ˆÔÐÐr   )NNNrm  )r   r   r   rO   r   r   r   r   rl  rl  ¹  s4   € € € € € Ø@Ð@à@DØ!&ð/ð /ð /ð /ð /ð /r   rl  c                   ó>   — e Zd ZdZd
d„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
dS )ÚSmartSSHClientMediumzžA client medium using SSH.

    It delegates IO to a SmartSimplePipesClientMedium or
    SmartClientAlreadyConnectedSocketMedium (depending on platform).
    Nc                 ó‚   — d| _         || _        d| _        t                               | |¦  «         || _        d| _        dS )z÷Creates a client that will connect on the first use.

        :param ssh_params: A SSHParams instance.
        :param vendor: An optional override for the ssh vendor to use. See
            breezy.transport.ssh for details on ssh vendors.
        Nzbzr+ssh)Ú_real_mediumÚ_ssh_paramsÚ_schemerP  r   Ú_vendorÚ_ssh_connection)r   r+  Ú
ssh_paramsÚvendors       r   r   zSmartSSHClientMedium.__init__Ì  sJ   € ð !ˆÔØ%ˆÔð !ˆŒõ 	 ×(Ò(¨¨tÑ4Ô4Ð4ØˆŒØ#ˆÔÐÐr   c                 óÞ   — | j         j        €d}nd| j         j        z  }| j         j        €d}nd| j         j        z  }d                     | j        j        | j        || j         j        |¦  «        S )NÚ z:%sz%s@z{}({}://{}{}{}/))rx  rp  rq  rc   r�   r   ry  ro  )r   Ú
maybe_portÚ
maybe_users      r   r    zSmartSSHClientMedium.__repr__ß  s|   € ØÔÔ Ð(ØˆJˆJà Ô!1Ô!6Ñ6ˆJØÔÔ$Ð,ØˆJˆJà Ô!1Ô!:Ñ:ˆJØ!×(Ò(ØŒNÔ#ØŒLØØÔÔ!Øñô ð 	r   c                 ób   — |                       ¦   «          | j                             |¦  «         dS )re  N)Ú_ensure_connectionrw  rw   r:   s     r   rã   z"SmartSSHClientMedium._accept_bytesï  s1   € à×ÒÑ!Ô!Ð!ØÔ×&Ò& uÑ-Ô-Ð-Ð-Ð-r   c                 ó¦   — | j         � | j                              ¦   «          d| _         | j        �"| j                             ¦   «          d| _        dS dS )ú#See SmartClientMedium.disconnect().N)rw  rE  r{  r¦   r2   s    r   rE  zSmartSSHClientMedium.disconnectô  s\   € àÔÐ(ØÔ×(Ò(Ñ*Ô*Ð*Ø $ˆDÔØÔÐ+ØÔ ×&Ò&Ñ(Ô(Ð(Ø#'ˆDÔ Ð Ð ð ,Ð+r   c                 óZ  — | j         �dS | j        €t                               ¦   «         }n| j        }|                     | j        j        | j        j        | j        j        | j        j	        | j        j
        ddddg¬¦  «        | _        | j                             ¦   «         \  }}|dk    rt          | j        |¦  «        | _         nA|dk    r!|\  }}t          ||| j        ¦  «        | _         nt!          d	|›d
| j        ›�¦  «        ‚t"          j        j        d         D ]} || ¦  «         ŒdS )ú-Connect this medium if not already connected.Nrj   z--inetz--directory=/z--allow-writes)Úcommandr˜   ÚpipeszUnexpected io_kind z from Úpost_connect)rw  rz  ÚsshÚ_get_ssh_vendorÚconnect_sshrx  rq  rr  ro  rp  rs  r{  Úget_sock_or_pipesÚ'SmartClientAlreadyConnectedSocketMediumr+  r^  r6   rK  Ú	Transportr   )r   r}  Úio_kindÚ	io_objectÚ	read_fromÚwrite_toÚhooks          r   rƒ  z'SmartSSHClientMedium._ensure_connectioný  sb  € àÔÐ(ØˆFØŒ<ÐÝ×(Ò(Ñ*Ô*ˆFˆFà”\ˆFØ%×1Ò1°$Ô2BÔ2KØ26Ô2BÔ2KÈTÔM]ÔMbØ26Ô2BÔ2GØ;?Ô;KÔ;[Ð]dÐfnØ;JÐL\ð;^ð  2ñ  _ô  _ˆÔð
 "Ô1×CÒCÑEÔEÑˆ�Ø�hÒÐÝ GØ”	˜9ñ!&ô !&ˆDÔÐà˜ÒÐØ"+ÑˆI�xÝ <Ø˜8 T¤Yñ!0ô !0ˆDÔÐõ !�.à�7�7˜DÔ0Ð0ð2ñ3ô 3ð 3õ Ô'Ô-¨nÔ=ð 	ð 	ˆDØˆD�‰JŒJˆJˆJð	ð 	r   c                 ó8   — | j                              ¦   «          dS ri  )rw  rX  r2   s    r   rX  zSmartSSHClientMedium._flush  s   € àÔ× Ò Ñ"Ô"Ð"Ð"Ð"r   c                 ól   — | j         €t          j        | ¦  «        ‚| j                              |¦  «        S )z'See SmartClientStreamMedium.read_bytes.)rw  r   ÚMediumNotConnectedrB   rF   s     r   r?   z SmartSSHClientMedium._read_bytes  s3   € àÔÐ$ÝÔ+¨DÑ1Ô1Ð1ØÔ ×+Ò+¨EÑ2Ô2Ð2r   r
   )r   r   r   rO   r   r    rã   rE  rƒ  rX  r?   r   r   r   ru  ru  Å  sŒ   € € € € € ðð ð$ð $ð $ð $ð&ð ð ð .ð .ð .ð
(ð (ð (ðð ð ð8#ð #ð #ð3ð 3ð 3ð 3ð 3r   ru  i;  c                   ó6   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	dS )	ÚSmartClientSocketMediumzoA client medium using a socket.

    This class isn't usable directly.  Use one of its subclasses instead.
    c                 óX   — t                                | |¦  «         d | _        d| _        d S )NF)rP  r   Ú_socketÚ
_connectedrS  s     r   r   z SmartClientSocketMedium.__init__/  s*   € Ý×(Ò(¨¨tÑ4Ô4Ð4ØˆŒØˆŒˆˆr   c                 ón   — |                       ¦   «          t          j        | j        || j        ¦  «         dS )z#See SmartClientMedium.accept_bytes.N)rƒ  r   r±   rœ  rN   r:   s     r   rã   z%SmartClientSocketMedium._accept_bytes4  s4   € à×ÒÑ!Ô!Ð!ÝÔ˜œ u¨dÔ.CÑDÔDÐDÐDÐDr   c                 ó*   — t          | j        ¦  «        ‚)r‡  )rE   rƒ  r2   s    r   rƒ  z*SmartClientSocketMedium._ensure_connection9  s   € å! $Ô"9Ñ:Ô:Ð:r   c                 ó   — dS )zÝSee SmartClientStreamMedium._flush().

        For sockets we do no flushing. For TCP sockets we may want to turn off
        TCP_NODELAY and add a means to do a flush, but that can be done in the
        future.
        Nr   r2   s    r   rX  zSmartClientSocketMedium._flush=  rp   r   c                 óv   — | j         st          j        | ¦  «        ‚t          j        | j        | j        ¦  «        S )z!See SmartClientMedium.read_bytes.)r�  r   r˜  r   rª   rœ  rN   rF   s     r   r?   z#SmartClientSocketMedium._read_bytesE  s<   € àŒð 	2ÝÔ+¨DÑ1Ô1Ð1ÝÔ-ØŒL˜$Ô/ñ1ô 1ð 	1r   c                 óf   — | j         sdS | j                             ¦   «          d| _        d| _         dS )r…  NF)r�  rœ  r¦   r2   s    r   rE  z"SmartClientSocketMedium.disconnectL  s7   € àŒð 	ØˆFØŒ×ÒÑÔÐØˆŒØˆŒˆˆr   N)
r   r   r   rO   r   rã   rƒ  rX  r?   rE  r   r   r   rš  rš  )  s{   € € € € € ðð ð
 ð  ð  ð
Eð Eð Eð
;ð ;ð ;ðð ð ð1ð 1ð 1ð ð  ð  ð  ð  r   rš  c                   ó   — e Zd ZdZd„ Zd„ ZdS )ÚSmartTCPClientMediumz.A client medium that creates a TCP connection.c                 óX   — t                                | |¦  «         || _        || _        dS )z4Creates a client that will connect on the first use.N)rš  r   Ú_hostÚ_port)r   ro  rp  r+  s       r   r   zSmartTCPClientMedium.__init__X  s*   € å×(Ò(¨¨tÑ4Ô4Ð4ØˆŒ
ØˆŒ
ˆ
ˆ
r   c                 ó  — | j         rdS | j        €t          }nt          | j        ¦  «        }	 t                               | j        |t          j        t          j        dd¦  «        }n@# t          j	        $ r.}|j
        \  }}t          j        d| j        ||fz  ¦  «        ‚d}~ww xY wt                               d| j        z  ¦  «        }|D ]µ\  }}}	}
}	 t                               |||	¦  «        | _        | j                             t          j        t          j        d¦  «         | j                             |¦  «         n@# t&          $ r3}| j        �| j                             ¦   «          d| _        |}Y d}~Œ­d}~ww xY w | j        €Nt+          |j
        t,          ¦  «        r|j
        }n|j
        d         }t          j        d| j        ||fz  ¦  «        ‚d| _         t.          j        j        d         D ]} || ¦  «         ŒdS )	r‡  Nr   zfailed to lookup %s:%d: %szno address found for %sr%   zfailed to connect to %s:%d: %sTrŠ  )r�  r§  ÚBZR_DEFAULT_PORTÚintr˜   Úgetaddrinfor¦  Ú	AF_UNSPECÚSOCK_STREAMÚgaierrorr{   r   ÚConnectionErrorÚerrorrœ  Ú
setsockoptÚIPPROTO_TCPÚTCP_NODELAYÚconnectr~   r¦   r4   ÚstrrK  r�  r   )r   rp  Ú	sockaddrsÚxxx_todo_changemeÚerr_numÚerr_msgÚlast_errÚfamilyÚsocktypeÚprotoÚ	canonnameÚsockaddrr‰   r•  s                 r   rƒ  z'SmartTCPClientMedium._ensure_connection^  sB  € àŒ?ð 	ØˆFØŒ:ÐÝ#ˆDˆDå�t”z‘?”?ˆDð	FÝ×*Ò*¨4¬:°t½VÔ=MÝ+1Ô+=¸qÀ!ñEô EˆIˆIøåŒð 	Fð 	Fð 	FØ!2Ô!7ÑˆW�gÝÔ(Ð)EØ*.¬*°d¸GÐ)Dñ*Eñ Fô Fð Føøøøð	Føøøõ
 —<’<Ð 9¸D¼JÑ FÑGÔGˆØ>Gð 	ð 	Ñ:ˆV�X˜u i°ð
Ý%Ÿ}š}¨V°X¸uÑEÔE�”Ø”×'Ò'­Ô(:Ý(.Ô(:¸Añ?ô ?ð ?à”×$Ò$ XÑ.Ô.Ð.Ð.øÝð ð ð Ø”<Ð+Ø”L×&Ò&Ñ(Ô(Ð(Ø#�”Ø�Ø����øøøøðøøøð ØŒ<Ðõ ˜(œ-­Ñ-Ô-ð +Ø"œ-��à"œ-¨Ô*�ÝÔ(Ð)IØ*.¬*°d¸GÐ)Dñ*Eñ Fô Fð FàˆŒÝÔ'Ô-¨nÔ=ð 	ð 	ˆDØˆD�‰JŒJˆJˆJð	ð 	s0   ®8A' Á'B$Á6)BÂB$ÃA+E Å 
E=Å
)E8Å8E=N©r   r   r   rO   r   rƒ  r   r   r   r¤  r¤  U  s8   € € € € € Ø8Ð8ðð ð ð)ð )ð )ð )ð )r   r¤  c                   ó   — e Zd ZdZd„ Zd„ ZdS )r�  z¯A client medium for an already connected socket.

    Note that this class will assume it "owns" the socket, so it will close it
    when its disconnect method is called.
    c                 óX   — t                                | |¦  «         || _        d| _        d S r¬   )rš  r   rœ  r�  )r   r+  r›   s      r   r   z0SmartClientAlreadyConnectedSocketMedium.__init__‘  s*   € Ý×(Ò(¨¨tÑ4Ô4Ð4ØˆŒØˆŒˆˆr   c                 ó   — d S r
   r   r2   s    r   rƒ  z:SmartClientAlreadyConnectedSocketMedium._ensure_connection–  s   € àˆr   NrÀ  r   r   r   r�  r�  Š  s<   € € € € € ðð ðð ð ð
ð ð ð ð r   r�  c                   ó   — e Zd ZdZd„ ZdS )ÚTooManyConcurrentRequestsz�The medium '%(medium)s' has reached its concurrent request limit. Be sure to finish_writing and finish_reading on the currently open request.c                 ó   — || _         d S r
   )rà   rß   s     r   r   z"TooManyConcurrentRequests.__init__¡  s   € ØˆŒˆˆr   Nr   r   r   r   rÅ  rÅ  ›  s*   € € € € € ð'€Dðð ð ð ð r   rÅ  c                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )rZ  zFA SmartClientMediumRequest that works with an SmartClientStreamMedium.c                 ó”   — t                                | |¦  «         | j        j        �t	          | j        ¦  «        ‚| | j        _        d S r
   )rÚ   r   rÝ   rR  rÅ  rß   s     r   r   z'SmartClientStreamMediumRequest.__init__¨  sE   € Ý ×)Ò)¨$°Ñ7Ô7Ð7ð Œ<Ô(Ð4Ý+¨D¬LÑ9Ô9Ð9Ø(,ˆŒÔ%Ð%Ð%r   c                 ó:   — | j                              |¦  «         dS )z¡See SmartClientMediumRequest._accept_bytes.

        This forwards to self._medium._accept_bytes because we are operating
        on the mediums stream.
        N)rÝ   rã   r:   s     r   rã   z,SmartClientStreamMediumRequest._accept_bytes³  s    € ð 	Œ×"Ò" 5Ñ)Ô)Ð)Ð)Ð)r   c                 óV   — | j         j        | urt          ¦   «         ‚d| j         _        dS )z See SmartClientMediumRequest._finished_reading.

        This clears the _current_request on self._medium to allow a new
        request to be created.
        N)rÝ   rR  r6   r2   s    r   rê   z0SmartClientStreamMediumRequest._finished_reading»  s0   € ð Œ<Ô(°Ð4Ð4Ý Ñ"Ô"Ð"Ø(,ˆŒÔ%Ð%Ð%r   c                 ó8   — | j                              ¦   «          dS )z‡See SmartClientMediumRequest._finished_writing.

        This invokes self._medium._flush to ensure all bytes are transmitted.
        N)rÝ   rX  r2   s    r   rï   z0SmartClientStreamMediumRequest._finished_writingÅ  s   € ð
 	Œ×ÒÑÔÐÐÐr   N)r   r   r   rO   r   rã   rê   rï   r   r   r   rZ  rZ  ¥  sV   € € € € € ØPÐPð	-ð 	-ð 	-ð*ð *ð *ð-ð -ð -ðð ð ð ð r   rZ  )-rO   rz   rÑ   r¿   r]   r“   r´   r  r   Úglobalsr  r   r   r£   r>   ÚBzrErrorr   r"   r-   r/   ÚEBADFr€   r¼   ÚWSAENOTSOCKrR   r•   r¹   rÚ   rû   r  r0  r1  r(  rP  r^  rl  ru  ÚBZR_DEFAULT_INTERFACEr©  rš  r¤  r�  ÚInternalBzrErrorrÅ  rZ  r   r   r   ú<module>rÒ     sq  ðð"ð ð €€€Ø 	€	€	€	Ø 	€	€	€	Ø 
€
€
€
Ø €€€à €€€à €€€Ø &Ð &Ð &Ð &Ð &Ð &Ø €ˆGˆG‰IŒIð ñ ô ð ð ð ð ð ð ð ð ð ð Ô)€ð#ð #ð #ð #ð #˜vœñ #ô #ð #ð#ð #ð #ð@ð ð ð,CHð CHð CHð CHð CHñ CHô CHð CHðL œ�~Ð Ø„<�7ÒÐð €KØ˜[˜NÑ*ÐðZ4ð Z4ð Z4ð Z4ð Z4˜kñ Z4ô Z4ð Z4ðzI>ð I>ð I>ð I>ð I>Ð$;ñ I>ô I>ð I>ðXTð Tð Tð Tð TÐ"9ñ Tô Tð TðnE(ð E(ð E(ð E(ð E(ñ E(ô E(ð E(ðPGð Gð Gð Gð Gñ Gô Gð Gð&9ð 9ð 9ð 9ð 9ñ 9ô 9ð 9ðx €Ø€ðx)ð x)ð x)ð x)ð x)˜ñ x)ô x)ð x)ðv,%ð ,%ð ,%ð ,%ð ,%Ð/ñ ,%ô ,%ð ,%ð^"ð "ð "ð "ð "Ð#:ñ "ô "ð "ðJ	/ð 	/ð 	/ð 	/ð 	/ñ 	/ô 	/ð 	/ð\3ð \3ð \3ð \3ð \3Ð2ñ \3ô \3ð \3ð@ Ð ØÐ ð) ð ) ð ) ð ) ð ) Ð5ñ ) ô ) ð ) ðX2ð 2ð 2ð 2ð 2Ð2ñ 2ô 2ð 2ðjð ð ð ð Ð.Eñ ô ð ð"ð ð ð ð  Ô 7ñ ô ð ð%ð %ð %ð %ð %Ð%=ñ %ô %ð %ð %ð %r   