disabled
     =ˆËÊÏ485ÉÀÌ å    =‹      ­”]oÛ †ïû+»‹�óÑMm1SGZ´4‰ROÛ4í‚bh°€,í~ýpœªî”tŸWû9¯ß—�él˜}ž�Ð»ìj‚æÞNÆC„; ûC€4K›ƒ(îŒ¦aé}u°Ýn£m?2¶€lÒ¯Ë8oUî#î9¦'¤~GO‘‚ñðDÄ+_
:Ö\Ü!³B`6Þ).°qœdV€6\Ü8(gNFÊ•B^hJƒìÕÈÒðûú'Ý¿u;Kl¹Ó­‡–/Ñ7VªB'Ø›
S¢Ör6O0¨ÜhË’éÛ¨P+ŒXéüe<œ}xYWSÂ�´b•à7Ãdz1K.1�²µ À3W3aÎ£µáj¥?
_7ðµú~\0m˜T¸ÜªÊ+£QÛQsSºŠ…¬§!�´mªAø¯VƒåOc~¹M³t¼h–„×�îži¦ó0Ó¥ÊŠÜ{¿wÝH¼ÔKW]<LÑÞ“U…ô˜"ÔAÉ?âÅ�oÉ>e#¨z«E7Ó‡QÛçOÆzqïU'~Ý‰¨×?ïv:v£þûM°Ñ·Úlu;DèôÁUè+D0o4¦íÙÿsz?ÓŽßÜ}°?—vÇœ@s—ü g0à®    N   ?ˆl–äY>”JeJe@†à¸Û*bÑ¿�þDR²³r…Â² ’FšóÑ„€ÐÃa–ßi~” T¾R( 	ÅõÆEpO©‹FÿÎ .ã    ?# wireprotolfsserver.py - lfs protocol server side implementation
#
# Copyright 2018 Matt Harbison <matt_harbison@yahoo.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 datetime
import errno
import json
import traceback

from mercurial.hgweb import common as hgwebcommon

from mercurial import (
    exthelper,
    pycompat,
    util,
    wireprotoserver,
)

from . import blobstore

HTTP_OK = hgwebcommon.HTTP_OK
HTTP_CREATED = hgwebcommon.HTTP_CREATED
HTTP_BAD_REQUEST = hgwebcommon.HTTP_BAD_REQUEST
HTTP_NOT_FOUND = hgwebcommon.HTTP_NOT_FOUND
HTTP_METHOD_NOT_ALLOWED = hgwebcommon.HTTP_METHOD_NOT_ALLOWED
HTTP_NOT_ACCEPTABLE = hgwebcommon.HTTP_NOT_ACCEPTABLE
HTTP_UNSUPPORTED_MEDIA_TYPE = hgwebcommon.HTTP_UNSUPPORTED_MEDIA_TYPE

eh = exthelper.exthelper()


@eh.wrapfunction(wireprotoserver, b'handlewsgirequest')
def handlewsgirequest(orig, rctx, req, res, checkperm):
    """Wrap wireprotoserver.handlewsgirequest() to possibly process an LFS
    request if it is left unprocessed by the wrapped method.
    """
    if orig(rctx, req, res, checkperm):
        return True

    if not rctx.repo.ui.configbool(b'experimental', b'lfs.serve'):
        return False

    if not util.safehasattr(rctx.repo.svfs, 'lfslocalblobstore'):
        return False

    if not req.dispatchpath:
        return False

    try:
        if req.dispatchpath == b'.git/info/lfs/objects/batch':
            checkperm(rctx, req, b'pull')
            return _processbatchrequest(rctx.repo, req, res)
        # TODO: reserve and use a path in the proposed http wireprotocol /api/
        #       namespace?
        elif req.dispatchpath.startswith(b'.hg/lfs/objects'):
            return _processbasictransfer(
                rctx.repo, req, res, lambda perm: checkperm(rctx, req, perm)
            )
        return False
    except hgwebcommon.ErrorResponse as e:
        # XXX: copied from the handler surrounding wireprotoserver._callhttp()
        #      in the wrapped function.  Should this be moved back to hgweb to
        #      be a common handler?
        for k, v in e.headers:
            res.headers[k] = v
        res.status = hgwebcommon.statusmessage(e.code, pycompat.bytestr(e))
        res.setbodybytes(b'0\n%s\n' % pycompat.bytestr(e))
        return True


def _sethttperror(res, code, message=None):
    res.status = hgwebcommon.statusmessage(code, message=message)
    res.headers[b'Content-Type'] = b'text/plain; charset=utf-8'
    res.setbodybytes(b'')


def _logexception(req):
    """Write information about the current exception to wsgi.errors."""
    tb = pycompat.sysbytes(traceback.format_exc())
    errorlog = req.rawenv[b'wsgi.errors']

    uri = b''
    if req.apppath:
        uri += req.apppath
    uri += b'/' + req.dispatchpath

    errorlog.write(
        b"Exception happened while processing request '%s':\n%s" % (uri, tb)
    )


def _processbatchrequest(repo, req, res):
    """Handle a request for the Batch API, which is the gateway to granting file
    access.

    https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md
    """

    # Mercurial client request:
    #
    #   HOST: localhost:$HGPORT
    #   ACCEPT: application/vnd.git-lfs+json
    #   ACCEPT-ENCODING: identity
    #   USER-AGENT: git-lfs/2.3.4 (Mercurial 4.5.2+1114-f48b9754f04c+20180316)
    #   Content-Length: 125
    #   Content-Type: application/vnd.git-lfs+jso