disabled
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«À542_‘I|¥‰ÓMdœv ©ƒ†ü+=ÅÄ     ‹      Õ•K�Ó0…÷ó+Œì’Û´3NÐÐT¢R§­:E!T9¶“XMâÈv)å×ã4­& VÀ‚Ç¬âÇñõùŽ#›<‹ç£Õ‡Å½]ÝOÑâÝ›éd„°ð~0ˆWq;1ô{Àx†Î­­o v»�¿øJg°ZBnËbÆjÉ¬Ï-ÇÑiÆ¢+DrA¹û"b¥-D4©¸ø‚TŠ@m­‘\¸Êõ6)$; W¥#*žÊBø\”ÊÏ�Ï”ªÝF\1ãSœÔC¨µb`síöñŒ(RÐJY0{¥âÛB@!¦Ù Ï\Qf¥ª�ÖŒ³G$Q|ßØþ‹ÎÉ!6šœ6M›£Ï´�Yb«jYfÈhb�Ì­ƒ¤ ÕÆÏdŠ-lˆ?NFóONçöoVG„"g$ñëQ8»�‡1Žf´èyÍ½ÓÜáhJ�EÎ­L¥àÅ­øA~½\0n5±0LËº�}”‚Cì¢2U˜š:ÖkG�ë®ª•ðŸ¥AÙwa,î–ãÙ*ž,ÛHxSâÑÝ¿8p-¨•E±Ôîì•Þãh½=¯Sßžºè«e–[!ä¡³ÊßHh[m*µ«º!¹8Ïz�l³õá‡ÄQ§Ó5üƒÃ~¯ÿÂú^/@ÁË›þ5B—P‚Weãòwî�cóib˜}yÂh›OcÝ¼!Uf:8§¡?�õ‹÷od‡'ƒ@ûÒ}Êr«L    B   ˆl–äY>”JeJe@†à¸Û*bÑ¿�þ\|"Y¹BáYI#MùÃ„�>÷Â_ŠI|¥�+Wé3ž¯ÇÆ ?÷     # wireprotov1server.py - Wire protocol version 1 server functionality
#
# Copyright 2005-2010 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 binascii
import os

from .i18n import _
from .node import hex
from .pycompat import getattr

from . import (
    bundle2,
    bundlecaches,
    changegroup as changegroupmod,
    discovery,
    encoding,
    error,
    exchange,
    pushkey as pushkeymod,
    pycompat,
    requirements as requirementsmod,
    streamclone,
    util,
    wireprototypes,
)

from .utils import (
    procutil,
    stringutil,
)

urlerr = util.urlerr
urlreq = util.urlreq

bundle2requiredmain = _(b'incompatible Mercurial client; bundle2 required')
bundle2requiredhint = _(
    b'see https://www.mercurial-scm.org/wiki/IncompatibleClient'
)
bundle2required = b'%s\n(%s)\n' % (bundle2requiredmain, bundle2requiredhint)


def clientcompressionsupport(proto):
    """Returns a list of compression methods supported by the client.

    Returns a list of the compression methods supported by the client
    according to the protocol capabilities. If no such capability has
    been announced, fallback to the default of zlib and uncompressed.
    """
    for cap in proto.getprotocaps():
        if cap.startswith(b'comp='):
            return cap[5:].split(b',')
    return [b'zlib', b'none']


# wire protocol command can either return a string or one of these classes.


def getdispatchrepo(repo, proto, command):
    """Obtain the repo used for processing wire protocol commands.

    The intent of this function is to serve as a monkeypatch point for
    extensions that need commands to operate on different repo views under
    specialized circumstances.
    """
    viewconfig = repo.ui.config(b'server', b'view')
    return repo.filtered(viewconfig)


def dispatch(repo, proto, command):
    repo = getdispatchrepo(repo, proto, command)

    func, spec = commands[command]
    args = proto.getargs(spec)

    return func(repo, proto, *args)


def options(cmd, keys, others):
    opts = {}
    for k in keys:
        if k in others:
            opts[k] = others[k]
            del others[k]
    if others:
        procutil.stderr.write(
            b"warning: %s ignored unexpected arguments %s\n"
            % (cmd, b",".join(others))
        )
    return opts


def bundle1allowed(repo, action):
    """Whether a bundle1 operation is allowed from the server.

    Priority is:

    1. server.bundle1gd.<action> (if generaldelta active)
    2. server.bundle1.<action>
    3. server.bundle1gd (if generaldelta active)
    4. server.bundle1
    """
    ui = repo.ui
    gd = requirementsmod.GENERALDELTA_REQUIREMENT in repo.requirements

    if gd:
        v = ui.configbool(b'server', b'bundle1gd.%s' % action)
        if v is not None:
            return v

    v = ui.configbool(b'server', b'bundle1.%s' % action)
    if v is not None:
        return v

    if gd:
        v = ui.configbool(b'server', b'bundle1gd')
        if v is not None:
            return v

    return ui.configbool(b'server', b'bundle1')


commands = wireprototypes.commanddict()


def wireprotocommand(name, args=None, permission=b'push'):
    """Decorator to declare a wire protocol command.

    ``name`` is the name of the wire protocol command being prov