0x10000000
     ˆÅÄÃ503ÂÁÀ ÷    ‹      Í”QoÚ0…ßû+îü°7r	¥ÕÖ:™:‚4$
ˆ2MÓ4UNìkNÙ¦”ýú9T6Š¶=tÚS’ë“{¿sâ˜¾J¦ƒÅçÙ>,nÇ0ûø~< é ~: &‹¤]èÝq8!@
çê+Äõz¬Ïm–¸˜cáJÕGëŒÌ\À'ñmjñÐB0î¯@�tJÄ£Š‹GÐ9 ^9+¹ð�ëUªd¶/ ×¥E+*žK%.J6È´®ý ®3Û±VíÕ}|`•L±.j,5_)añMÐEQ¦‚SlÇzÜ‘ÐTóMþ{?sK·LÍ­‰©+à�)¹¬"âtMb*Ë%X“Ee¦+‹©bÕ·`)sL¹ˆ|¦_½]Ñ¼S…yDÞ¢Éõ4JH<a¥ Èž×ÜzÍ‰ÇÌ:ð”2—Ü	ñ]+¾“ßO7LZM"lfdí¤®ž¤è-ZÍ´²5ó^/¼ƒÂªZ	ÿ],û)ŒÙÍ|8Y$£y	oZ<Ñ½ø§%ñŒQ9H¤™Óf³óÞ‚¼®R[_ïaçÌÈeáHÐ�g•G®æ0�SQpi›�ÇïÓÍ}Édå<ûqí�þÜ^·wÙ	ÃNï-t/¯Â€ÿÂ—¨Žl•^ÞÕnqÜýü·çÅö üæ"3-‹    B   ˆl–äY>”JeJe@†à¸Û*bÑ¿�þ[(H³r…Â² ’Fšó¿„@|_Ä_ŠI|¥�+Wé3ž¯ÃÂ ?÷     # commandserver.py - communicate with Mercurial's API over a pipe
#
#  Copyright Olivia Mackall <olivia@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.


import gc
import os
import random
import selectors
import signal
import socket
import struct
import traceback

from .i18n import _
from .pycompat import getattr
from . import (
    encoding,
    error,
    loggingutil,
    pycompat,
    repocache,
    util,
    vfs as vfsmod,
)
from .utils import (
    cborutil,
    procutil,
)


class channeledoutput:
    """
    Write data to out in the following format:

    data length (unsigned int),
    data
    """

    def __init__(self, out, channel):
        self.out = out
        self.channel = channel

    @property
    def name(self):
        return b'<%c-channel>' % self.channel

    def write(self, data):
        if not data:
            return
        # single write() to guarantee the same atomicity as the underlying file
        self.out.write(struct.pack(b'>cI', self.channel, len(data)) + data)
        self.out.flush()

    def __getattr__(self, attr):
        if attr in ('isatty', 'fileno', 'tell', 'seek'):
            raise AttributeError(attr)
        return getattr(self.out, attr)


class channeledmessage:
    """
    Write encoded message and metadata to out in the following format:

    data length (unsigned int),
    encoded message and metadata, as a flat key-value dict.

    Each message should have 'type' attribute. Messages of unknown type
    should be ignored.
    """

    # teach ui that write() can take **opts
    structured = True

    def __init__(self, out, channel, encodename, encodefn):
        self._cout = channeledoutput(out, channel)
        self.encoding = encodename
        self._encodefn = encodefn

    def write(self, data, **opts):
        opts = pycompat.byteskwargs(opts)
        if data is not None:
            opts[b'data'] = data
        self._cout.write(self._encodefn(opts))

    def __getattr__(self, attr):
        return getattr(self._cout, attr)


class channeledinput:
    """
    Read data from in_.

    Requests for input are written to out in the following format:
    channel identifier - 'I' for plain input, 'L' line based (1 byte)
    how many bytes to send at most (unsigned int),

    The client replies with:
    data length (unsigned int), 0 meaning EOF
    data
    """

    maxchunksize = 4 * 1024

    def __init__(self, in_, out, channel):
        self.in_ = in_
        self.out = out
        self.channel = channel

    @property
    def name(self):
        return b'<%c-channel>' % self.channel

    def read(self, size=-1):
        if size < 0:
            # if we need to consume all the clients input, ask for 4k chunks
            # so the pipe doesn't fill up risking a deadlock
            size = self.maxchunksize
            s = self._read(size, self.channel)
            buf = s
            while s:
                s = self._read(size, self.channel)
                buf += s

            return buf
        else:
            return self._read(size, self.channel)

    def _read(self, size, channel):
        if not size:
            return b''
        assert size > 0

        # tell the client we need at most size bytes
        self.out.write(struct.pack(b'>cI', channel, size))
        self.out.flush()

        length = self.in_.read(4)
        length = struc