auto
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Â606_‘I|¥‰ÓMdœv ©ƒ†ü+=ÂÁ ^    ‹      Õ—]oÚ0†ïû+<_ìŽ˜ªm­“©#HC£€h¦mšvabC¬†$rMÙ¯_‡�M°u’‰+àõá}üñJ¦¯üé ø6¢�ÁýÍ>�wùÒâ¾þ¡oumB†Œp�ÝR…Uô¬T­H0'¬ã>ÉAÉ,{W´úÎ»B4Œ—#¢ !Þ(áâ¥KDÒä’‹>ÙäŠÈ$Œ7\ˆ˜¤DKËÉ¤™M)ßVMí—5(uõ_²EÝ§*•G!BO,–«ÄÅ�fØ£r½B¹
]Ld˜&9YÄ,y´Vr‰‹ÁÅßGƒé�RWv­f{”¡H‰¥‹ßÜÉíÔ½ÃÞ„­%ì´æ^kÆ,´N¹\JÁÏŠ´øAþ<ßÐ×_ä¡’È49HI‰xŒ¦qž±’õº$ˆÔ±JKø¿Vƒ…¿-Æìn>œþh®—„W-îNoöfL‰�/•!UÛÆ°žý:YäÙíî#jì(¹Š {uÐIå0€x†c†àkpÒ}`EØ«‡c‡XrºŽÝ±�ŽÓEŽ}ãô:#ì[½Omy™WÞëÁ„÷žuÝž÷¨(c£¶ßT&lËi“ <à¼AÐ¥	Ç²Ûd�IÖ ÔÕîBÛL4Mmæ6´K‘Æñ¢.Íœ¥v"¶»Òº4sšÞ´É°P�B]]Á>V/4U¡j2SÛ$ØGªÁD}×¢ÿ£@5˜§È~Û&Ã>NÍ¥i»÷ {aŽ Í=ØGé…&)“±\h‚¦4“EÝ¿0¼ðGš.%õ™ýêþ³&# Ø       ˆÀ¿Ã531¾ÂÁ     ‹      Í•_oÚ0Åßû)<?ì-¹è*µŽ§Ž �¢©¶iÚƒ±â-‰#Û-í>ý*í`¤Jì)ÎõÉÍï'6y•LéçÙ½O¯Æhvón<  |ì ’4i'úa'N0Â¹sõ9Àjµ
W½P›%¤sÈ]YôÁ:£¸…˜ž�¦FOÉ%þŠˆS®�tT	y�t†@ß:«„ìn tiÁÊJdª�¡�¥sr­kÿ¡¹¬-¶ê>ÔFsp¹ñý+‹ŒÖn­›3#¡ÒB~³�éÊl%­.%pk	´ 6ld¡ÅCƒýxžb[¬)›¡¡ÄåèŽjYÅØéS¢Ê%²†Ç×•…EÁªïáRe±ÂÅøËh0ýêuž¡yš†<Lã·ƒxr1�L'¬”Ø~Í•×\b:fÖ¡R•))Š¯[ñµúq¸aÒji¹QµSºz”‚·¸k•ëÂÖÌ{=õr³«j%âOi0þ$ŒÙå|8I“Ñ¼�D4-éŽ²Ø˜ÎüTåP¢ŒäN›‡M-Üëjaë‹í-Ú¸5j™;L
Ð^å?Dää½Û�(ý”îg:ô_(¦Ï+»ÜÏ@»�èMu‚nEgç§]„9ê�}8–£°dõ¯®šê‹8ëFÇqVªjÏzmª/³f�ß8ûËß6�õ.L =8~Þózå›    B   ˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þchY¹DGÃ Â�ÏÅ„iÀ>×Ä_ŠI|¥�+Wé3ž¯ÄÃ ?÷     # Copyright (C) 2006-2011 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""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.
"""

import errno
import io
import os
import sys
import time

import _thread

import breezy
from ...lazy_import import lazy_import
lazy_import(globals(), """
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
""")
from ... import (
    errors,
    osutils,
    )

# Throughout this module buffer size parameters are either limited to be at
# most _MAX_READ_SIZE, or are ignored and _MAX_READ_SIZE is used instead.
# For this module's purposes, MAX_SOCKET_CHUNK is a reasonable size for reads
# from non-sockets as well.
_MAX_READ_SIZE = osutils.MAX_SOCKET_CHUNK


class HpssVfsRequestNotAllowed(errors.BzrError):

    _fmt = ("VFS requests over the smart server are not allowed. Encountered: "
            "%(method)s, %(arguments)s.")

    def __init__(self, method, arguments):
        self.method = method
        self.arguments = arguments


def _get_protocol_factory_for_bytes(bytes):
    """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