Show More
@@ -22,10 +22,7 b' cgitb.enable()' | |||
|
22 | 22 | #os.environ["HGENCODING"] = "UTF-8" |
|
23 | 23 | |
|
24 | 24 | from mercurial.hgweb.hgweb_mod import hgweb |
|
25 | from mercurial.hgweb.request import wsgiapplication | |
|
26 | 25 | import mercurial.hgweb.wsgicgi as wsgicgi |
|
27 | 26 | |
|
28 | def make_web_app(): | |
|
29 | return hgweb("/path/to/repo", "repository name") | |
|
30 | ||
|
31 | wsgicgi.launch(wsgiapplication(make_web_app)) | |
|
27 | application = hgweb("/path/to/repo", "repository name") | |
|
28 | wsgicgi.launch(application) |
@@ -22,7 +22,6 b' cgitb.enable()' | |||
|
22 | 22 | #os.environ["HGENCODING"] = "UTF-8" |
|
23 | 23 | |
|
24 | 24 | from mercurial.hgweb.hgwebdir_mod import hgwebdir |
|
25 | from mercurial.hgweb.request import wsgiapplication | |
|
26 | 25 | import mercurial.hgweb.wsgicgi as wsgicgi |
|
27 | 26 | |
|
28 | 27 | # The config file looks like this. You can have paths to individual |
@@ -44,7 +43,5 b' import mercurial.hgweb.wsgicgi as wsgicg' | |||
|
44 | 43 | # Alternatively you can pass a list of ('virtual/path', '/real/path') tuples |
|
45 | 44 | # or use a dictionary with entries like 'virtual/path': '/real/path' |
|
46 | 45 | |
|
47 | def make_web_app(): | |
|
48 | return hgwebdir("hgweb.config") | |
|
49 | ||
|
50 | wsgicgi.launch(wsgiapplication(make_web_app)) | |
|
46 | application = hgwebdir('hgweb.config') | |
|
47 | wsgicgi.launch(application) |
@@ -13,6 +13,7 b' from mercurial.i18n import gettext as _' | |||
|
13 | 13 | from mercurial import mdiff, ui, hg, util, archival, streamclone, patch |
|
14 | 14 | from mercurial import revlog, templater |
|
15 | 15 | from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen |
|
16 | from request import wsgirequest | |
|
16 | 17 | |
|
17 | 18 | def _up(p): |
|
18 | 19 | if p[0] != "/": |
@@ -671,10 +672,12 b' class hgweb(object):' | |||
|
671 | 672 | if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): |
|
672 | 673 | raise RuntimeError("This function is only intended to be called while running as a CGI script.") |
|
673 | 674 | import mercurial.hgweb.wsgicgi as wsgicgi |
|
674 | from request import wsgiapplication | |
|
675 | def make_web_app(): | |
|
676 | return self | |
|
677 | wsgicgi.launch(wsgiapplication(make_web_app)) | |
|
675 | wsgicgi.launch(self) | |
|
676 | ||
|
677 | def __call__(self, env, respond): | |
|
678 | req = wsgirequest(env, respond) | |
|
679 | self.run_wsgi(req) | |
|
680 | return req | |
|
678 | 681 | |
|
679 | 682 | def run_wsgi(self, req): |
|
680 | 683 | def header(**map): |
@@ -11,6 +11,7 b' from mercurial.i18n import gettext as _' | |||
|
11 | 11 | from mercurial import ui, hg, util, templater |
|
12 | 12 | from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen |
|
13 | 13 | from hgweb_mod import hgweb |
|
14 | from request import wsgirequest | |
|
14 | 15 | |
|
15 | 16 | # This is a stopgap |
|
16 | 17 | class hgwebdir(object): |
@@ -60,10 +61,12 b' class hgwebdir(object):' | |||
|
60 | 61 | if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): |
|
61 | 62 | raise RuntimeError("This function is only intended to be called while running as a CGI script.") |
|
62 | 63 | import mercurial.hgweb.wsgicgi as wsgicgi |
|
63 | from request import wsgiapplication | |
|
64 | def make_web_app(): | |
|
65 | return self | |
|
66 | wsgicgi.launch(wsgiapplication(make_web_app)) | |
|
64 | wsgicgi.launch(self) | |
|
65 | ||
|
66 | def __call__(self, env, respond): | |
|
67 | req = wsgirequest(env, respond) | |
|
68 | self.run_wsgi(req) | |
|
69 | return req | |
|
67 | 70 | |
|
68 | 71 | def run_wsgi(self, req): |
|
69 | 72 | def header(**map): |
@@ -10,15 +10,8 b' import socket, cgi, errno' | |||
|
10 | 10 | from mercurial.i18n import gettext as _ |
|
11 | 11 | from common import ErrorResponse, statusmessage |
|
12 | 12 | |
|
13 |
class wsgi |
|
|
14 |
def __init__(self, |
|
|
15 | self.destmaker = destmaker | |
|
16 | ||
|
17 | def __call__(self, wsgienv, start_response): | |
|
18 | return _wsgirequest(self.destmaker(), wsgienv, start_response) | |
|
19 | ||
|
20 | class _wsgirequest(object): | |
|
21 | def __init__(self, destination, wsgienv, start_response): | |
|
13 | class wsgirequest(object): | |
|
14 | def __init__(self, wsgienv, start_response): | |
|
22 | 15 | version = wsgienv['wsgi.version'] |
|
23 | 16 | if (version < (1, 0)) or (version >= (2, 0)): |
|
24 | 17 | raise RuntimeError("Unknown and unsupported WSGI version %d.%d" |
@@ -33,7 +26,6 b' class _wsgirequest(object):' | |||
|
33 | 26 | self.form = cgi.parse(self.inp, self.env, keep_blank_values=1) |
|
34 | 27 | self.start_response = start_response |
|
35 | 28 | self.headers = [] |
|
36 | destination.run_wsgi(self) | |
|
37 | 29 | |
|
38 | 30 | out = property(lambda self: self) |
|
39 | 31 | |
@@ -92,3 +84,9 b' class _wsgirequest(object):' | |||
|
92 | 84 | if length: |
|
93 | 85 | headers.append(('Content-length', str(length))) |
|
94 | 86 | self.header(headers) |
|
87 | ||
|
88 | def wsgiapplication(app_maker): | |
|
89 | application = app_maker() | |
|
90 | def run_wsgi(env, respond): | |
|
91 | application(env, respond) | |
|
92 | return run_wsgi |
@@ -10,7 +10,6 b' import os, sys, errno, urllib, BaseHTTPS' | |||
|
10 | 10 | from mercurial import ui, hg, util, templater |
|
11 | 11 | from hgweb_mod import hgweb |
|
12 | 12 | from hgwebdir_mod import hgwebdir |
|
13 | from request import wsgiapplication | |
|
14 | 13 | from mercurial.i18n import gettext as _ |
|
15 | 14 | |
|
16 | 15 | def _splitURI(uri): |
@@ -121,10 +120,7 b' class _hgwebhandler(object, BaseHTTPServ' | |||
|
121 | 120 | self.saved_headers = [] |
|
122 | 121 | self.sent_headers = False |
|
123 | 122 | self.length = None |
|
124 |
|
|
|
125 | for data in req: | |
|
126 | if data: | |
|
127 | self._write(data) | |
|
123 | self.server.application(env, self._start_response) | |
|
128 | 124 | |
|
129 | 125 | def send_headers(self): |
|
130 | 126 | if not self.saved_status: |
@@ -250,7 +246,7 b' def create_server(ui, repo):' | |||
|
250 | 246 | raise hg.RepoError(_("There is no Mercurial repository here" |
|
251 | 247 | " (.hg not found)")) |
|
252 | 248 | return hgwebobj |
|
253 |
self. |
|
|
249 | self.application = make_handler() | |
|
254 | 250 | |
|
255 | 251 | addr = address |
|
256 | 252 | if addr in ('', '::'): |
@@ -11,7 +11,6 b' hg tip' | |||
|
11 | 11 | cat > request.py <<EOF |
|
12 | 12 | from mercurial import dispatch |
|
13 | 13 | from mercurial.hgweb.hgweb_mod import hgweb |
|
14 | from mercurial.hgweb.request import _wsgirequest | |
|
15 | 14 | from mercurial.ui import ui |
|
16 | 15 | from mercurial import hg |
|
17 | 16 | from StringIO import StringIO |
@@ -62,7 +61,7 b' env = {' | |||
|
62 | 61 | 'SERVER_PROTOCOL': 'HTTP/1.0' |
|
63 | 62 | } |
|
64 | 63 | |
|
65 |
|
|
|
64 | hgweb('.')(env, startrsp) | |
|
66 | 65 | print '---- ERRORS' |
|
67 | 66 | print errors.getvalue() |
|
68 | 67 | EOF |
General Comments 0
You need to be logged in to leave comments.
Login now