mercurial/hgweb/hgweb_mod.py
changeset 11582 26c7d4fc31bf
parent 11370 db3f6f0e4e7d
child 11584 1af96b090116
equal deleted inserted replaced
11581:4530b3307fb9 11582:26c7d4fc31bf
     5 #
     5 #
     6 # This software may be used and distributed according to the terms of the
     6 # This software may be used and distributed according to the terms of the
     7 # GNU General Public License version 2 or any later version.
     7 # GNU General Public License version 2 or any later version.
     8 
     8 
     9 import os
     9 import os
    10 from mercurial import ui, hg, hook, error, encoding, templater
    10 from mercurial import ui, hg, hook, error, encoding, templater, wireproto
    11 from common import get_mtime, ErrorResponse, permhooks
    11 from common import get_mtime, ErrorResponse, permhooks
    12 from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
    12 from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
    13 from request import wsgirequest
    13 from request import wsgirequest
    14 import webcommands, protocol, webutil
    14 import webcommands, protocol, webutil
    15 
    15 
    19     'stream_out': 'pull',
    19     'stream_out': 'pull',
    20     'listkeys': 'pull',
    20     'listkeys': 'pull',
    21     'unbundle': 'push',
    21     'unbundle': 'push',
    22     'pushkey': 'push',
    22     'pushkey': 'push',
    23 }
    23 }
       
    24 
       
    25 class webproto(object):
       
    26     def __init__(self, req):
       
    27         self.req = req
       
    28         self.response = ''
       
    29     def getargs(self, args):
       
    30         data = {}
       
    31         keys = args.split()
       
    32         for k in keys:
       
    33             if k == '*':
       
    34                 star = {}
       
    35                 for key in self.req.form.keys():
       
    36                     if key not in keys:
       
    37                         star[key] = self.req.form[key][0]
       
    38                 data['*'] = star
       
    39             else:
       
    40                 data[k] = self.req.form[k][0]
       
    41         return [data[k] for k in keys]
       
    42     def respond(self, s):
       
    43         HGTYPE = 'application/mercurial-0.1'
       
    44         self.req.respond(HTTP_OK, HGTYPE, length=len(s))
       
    45         self.response = s
       
    46 
       
    47 def callproto(repo, req, cmd):
       
    48     p = webproto(req)
       
    49     r = wireproto.dispatch(repo, p, cmd)
       
    50     yield p.response
    24 
    51 
    25 class hgweb(object):
    52 class hgweb(object):
    26     def __init__(self, repo, name=None, baseui=None):
    53     def __init__(self, repo, name=None, baseui=None):
    27         if isinstance(repo, str):
    54         if isinstance(repo, str):
    28             if baseui:
    55             if baseui:
   121                         self.check_perm(req, perms[cmd])
   148                         self.check_perm(req, perms[cmd])
   122                     except ErrorResponse, inst:
   149                     except ErrorResponse, inst:
   123                         if cmd == 'unbundle':
   150                         if cmd == 'unbundle':
   124                             req.drain()
   151                             req.drain()
   125                         raise
   152                         raise
       
   153                 if cmd in wireproto.commands:
       
   154                     return callproto(self.repo, req, cmd)
   126                 method = getattr(protocol, cmd)
   155                 method = getattr(protocol, cmd)
   127                 return method(self.repo, req)
   156                 return method(self.repo, req)
   128             except ErrorResponse, inst:
   157             except ErrorResponse, inst:
   129                 req.respond(inst, protocol.HGTYPE)
   158                 req.respond(inst, protocol.HGTYPE)
   130                 if not inst.message:
   159                 if not inst.message: