mercurial/wireprotoserver.py
branchstable
changeset 49366 288de6f5d724
parent 49284 d44e3c45f0e4
child 50416 3b199593fedd
equal deleted inserted replaced
49364:e8ea403b1c46 49366:288de6f5d724
     2 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
     2 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
     3 #
     3 #
     4 # This software may be used and distributed according to the terms of the
     4 # This software may be used and distributed according to the terms of the
     5 # GNU General Public License version 2 or any later version.
     5 # GNU General Public License version 2 or any later version.
     6 
     6 
     7 from __future__ import absolute_import
       
     8 
     7 
     9 import contextlib
     8 import contextlib
    10 import struct
     9 import struct
    11 import threading
    10 import threading
    12 
    11 
    55 
    54 
    56     return b''.join(chunks)
    55     return b''.join(chunks)
    57 
    56 
    58 
    57 
    59 @interfaceutil.implementer(wireprototypes.baseprotocolhandler)
    58 @interfaceutil.implementer(wireprototypes.baseprotocolhandler)
    60 class httpv1protocolhandler(object):
    59 class httpv1protocolhandler:
    61     def __init__(self, req, ui, checkperm):
    60     def __init__(self, req, ui, checkperm):
    62         self._req = req
    61         self._req = req
    63         self._ui = ui
    62         self._ui = ui
    64         self._checkperm = checkperm
    63         self._checkperm = checkperm
    65         self._protocaps = None
    64         self._protocaps = None
   373     fout.write(b'\n')
   372     fout.write(b'\n')
   374     fout.flush()
   373     fout.flush()
   375 
   374 
   376 
   375 
   377 @interfaceutil.implementer(wireprototypes.baseprotocolhandler)
   376 @interfaceutil.implementer(wireprototypes.baseprotocolhandler)
   378 class sshv1protocolhandler(object):
   377 class sshv1protocolhandler:
   379     """Handler for requests services via version 1 of SSH protocol."""
   378     """Handler for requests services via version 1 of SSH protocol."""
   380 
   379 
   381     def __init__(self, ui, fin, fout):
   380     def __init__(self, ui, fin, fout):
   382         self._ui = ui
   381         self._ui = ui
   383         self._fin = fin
   382         self._fin = fin
   389         return wireprototypes.SSHV1
   388         return wireprototypes.SSHV1
   390 
   389 
   391     def getargs(self, args):
   390     def getargs(self, args):
   392         data = {}
   391         data = {}
   393         keys = args.split()
   392         keys = args.split()
   394         for n in pycompat.xrange(len(keys)):
   393         for n in range(len(keys)):
   395             argline = self._fin.readline()[:-1]
   394             argline = self._fin.readline()[:-1]
   396             arg, l = argline.split()
   395             arg, l = argline.split()
   397             if arg not in keys:
   396             if arg not in keys:
   398                 raise error.Abort(_(b"unexpected parameter %r") % arg)
   397                 raise error.Abort(_(b"unexpected parameter %r") % arg)
   399             if arg == b'*':
   398             if arg == b'*':
   400                 star = {}
   399                 star = {}
   401                 for k in pycompat.xrange(int(l)):
   400                 for k in range(int(l)):
   402                     argline = self._fin.readline()[:-1]
   401                     argline = self._fin.readline()[:-1]
   403                     arg, l = argline.split()
   402                     arg, l = argline.split()
   404                     val = self._fin.read(int(l))
   403                     val = self._fin.read(int(l))
   405                     star[arg] = val
   404                     star[arg] = val
   406                 data[b'*'] = star
   405                 data[b'*'] = star
   519             raise error.ProgrammingError(
   518             raise error.ProgrammingError(
   520                 b'unhandled ssh server state: %s' % state
   519                 b'unhandled ssh server state: %s' % state
   521             )
   520             )
   522 
   521 
   523 
   522 
   524 class sshserver(object):
   523 class sshserver:
   525     def __init__(self, ui, repo, logfh=None):
   524     def __init__(self, ui, repo, logfh=None):
   526         self._ui = ui
   525         self._ui = ui
   527         self._repo = repo
   526         self._repo = repo
   528         self._fin, self._fout = ui.protectfinout()
   527         self._fin, self._fout = ui.protectfinout()
   529 
   528