mercurial/sshpeer.py
changeset 36536 3cd245945ef3
parent 36533 1a36ef7df70a
child 36608 1151c731686e
equal deleted inserted replaced
36535:1c16324fdf05 36536:3cd245945ef3
    15     error,
    15     error,
    16     pycompat,
    16     pycompat,
    17     util,
    17     util,
    18     wireproto,
    18     wireproto,
    19     wireprotoserver,
    19     wireprotoserver,
       
    20     wireprototypes,
    20 )
    21 )
    21 
    22 
    22 def _serverquote(s):
    23 def _serverquote(s):
    23     """quote a string for the remote shell ... which we assume is sh"""
    24     """quote a string for the remote shell ... which we assume is sh"""
    24     if not s:
    25     if not s:
   255         stdin.flush()
   256         stdin.flush()
   256     except IOError:
   257     except IOError:
   257         badresponse()
   258         badresponse()
   258 
   259 
   259     # Assume version 1 of wire protocol by default.
   260     # Assume version 1 of wire protocol by default.
   260     protoname = wireprotoserver.SSHV1
   261     protoname = wireprototypes.SSHV1
   261     reupgraded = re.compile(b'^upgraded %s (.*)$' % re.escape(token))
   262     reupgraded = re.compile(b'^upgraded %s (.*)$' % re.escape(token))
   262 
   263 
   263     lines = ['', 'dummy']
   264     lines = ['', 'dummy']
   264     max_noise = 500
   265     max_noise = 500
   265     while lines[-1] and max_noise:
   266     while lines[-1] and max_noise:
   294 
   295 
   295     caps = set()
   296     caps = set()
   296 
   297 
   297     # For version 1, we should see a ``capabilities`` line in response to the
   298     # For version 1, we should see a ``capabilities`` line in response to the
   298     # ``hello`` command.
   299     # ``hello`` command.
   299     if protoname == wireprotoserver.SSHV1:
   300     if protoname == wireprototypes.SSHV1:
   300         for l in reversed(lines):
   301         for l in reversed(lines):
   301             # Look for response to ``hello`` command. Scan from the back so
   302             # Look for response to ``hello`` command. Scan from the back so
   302             # we don't misinterpret banner output as the command reply.
   303             # we don't misinterpret banner output as the command reply.
   303             if l.startswith('capabilities:'):
   304             if l.startswith('capabilities:'):
   304                 caps.update(l[:-1].split(':')[1].split())
   305                 caps.update(l[:-1].split(':')[1].split())
   553         protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
   554         protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
   554     except Exception:
   555     except Exception:
   555         _cleanuppipes(ui, stdout, stdin, stderr)
   556         _cleanuppipes(ui, stdout, stdin, stderr)
   556         raise
   557         raise
   557 
   558 
   558     if protoname == wireprotoserver.SSHV1:
   559     if protoname == wireprototypes.SSHV1:
   559         return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps,
   560         return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps,
   560                          autoreadstderr=autoreadstderr)
   561                          autoreadstderr=autoreadstderr)
   561     elif protoname == wireprotoserver.SSHV2:
   562     elif protoname == wireprototypes.SSHV2:
   562         return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps,
   563         return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps,
   563                          autoreadstderr=autoreadstderr)
   564                          autoreadstderr=autoreadstderr)
   564     else:
   565     else:
   565         _cleanuppipes(ui, stdout, stdin, stderr)
   566         _cleanuppipes(ui, stdout, stdin, stderr)
   566         raise error.RepoError(_('unknown version of SSH protocol: %s') %
   567         raise error.RepoError(_('unknown version of SSH protocol: %s') %