mercurial/commandserver.py
changeset 29433 33770d2b6cf9
parent 29366 d269e7db2f55
child 29511 540c01a18bb7
equal deleted inserted replaced
29432:34b914ac573e 29433:33770d2b6cf9
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from __future__ import absolute_import
     8 from __future__ import absolute_import
     9 
     9 
    10 import SocketServer
       
    11 import errno
    10 import errno
    12 import os
    11 import os
    13 import struct
    12 import struct
    14 import sys
    13 import sys
    15 import traceback
    14 import traceback
    18 from . import (
    17 from . import (
    19     encoding,
    18     encoding,
    20     error,
    19     error,
    21     util,
    20     util,
    22 )
    21 )
       
    22 
       
    23 socketserver = util.socketserver
    23 
    24 
    24 logfile = None
    25 logfile = None
    25 
    26 
    26 def log(*args):
    27 def log(*args):
    27     if not logfile:
    28     if not logfile:
   328             sv = server(ui, self.repo, fin, fout)
   329             sv = server(ui, self.repo, fin, fout)
   329             return sv.serve()
   330             return sv.serve()
   330         finally:
   331         finally:
   331             _restoreio(ui, fin, fout)
   332             _restoreio(ui, fin, fout)
   332 
   333 
   333 class _requesthandler(SocketServer.StreamRequestHandler):
   334 class _requesthandler(socketserver.StreamRequestHandler):
   334     def handle(self):
   335     def handle(self):
   335         ui = self.server.ui
   336         ui = self.server.ui
   336         repo = self.server.repo
   337         repo = self.server.repo
   337         sv = None
   338         sv = None
   338         try:
   339         try:
   364     """
   365     """
   365     def __init__(self, ui, repo, opts):
   366     def __init__(self, ui, repo, opts):
   366         self.ui = ui
   367         self.ui = ui
   367         self.repo = repo
   368         self.repo = repo
   368         self.address = opts['address']
   369         self.address = opts['address']
   369         if not util.safehasattr(SocketServer, 'UnixStreamServer'):
   370         if not util.safehasattr(socketserver, 'UnixStreamServer'):
   370             raise error.Abort(_('unsupported platform'))
   371             raise error.Abort(_('unsupported platform'))
   371         if not self.address:
   372         if not self.address:
   372             raise error.Abort(_('no socket path specified with --address'))
   373             raise error.Abort(_('no socket path specified with --address'))
   373 
   374 
   374     def init(self):
   375     def init(self):
   375         class cls(SocketServer.ForkingMixIn, SocketServer.UnixStreamServer):
   376         class cls(socketserver.ForkingMixIn, socketserver.UnixStreamServer):
   376             ui = self.ui
   377             ui = self.ui
   377             repo = self.repo
   378             repo = self.repo
   378         self.server = cls(self.address, _requesthandler)
   379         self.server = cls(self.address, _requesthandler)
   379         self.ui.status(_('listening at %s\n') % self.address)
   380         self.ui.status(_('listening at %s\n') % self.address)
   380         self.ui.flush()  # avoid buffering of status message
   381         self.ui.flush()  # avoid buffering of status message