Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: modules/hgweb/files/hgweb.fcgi

Issue 29323409: Issue 2867 - Introduce module hgweb and corresponding server role (Closed)
Left Patch Set: Issue 2867 - Remove double blank lines Created Aug. 17, 2015, 6:14 p.m.
Right Patch Set: Issue 2867 - Now the complete patch-set again Created Aug. 17, 2015, 6:17 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
LEFTRIGHT
(no file at all)
1 #!/usr/bin/env python
2 #
3 # An example CGI script to export multiple hgweb repos, edit as necessary
4
5 import re
6
7 # adjust python path if not a system-wide install:
8 #import sys
9 #sys.path.insert(0, "/path/to/python/lib")
10
11 # enable demandloading to reduce startup time
12 from mercurial import demandimport; demandimport.enable()
13
14 # Uncomment to send python tracebacks to the browser if an error occurs:
15 #import cgitb
16 #cgitb.enable()
17
18 # If you'd like to serve pages with UTF-8 instead of your default
19 # locale charset, you can do so by uncommenting the following lines.
20 # Note that this will cause your .hgrc files to be interpreted in
21 # UTF-8 and all your repo files to be displayed using UTF-8.
22 #
23 #import os
24 #os.environ["HGENCODING"] = "UTF-8"
25
26 from mercurial.hgweb.hgwebdir_mod import hgwebdir
27 from flup.server.fcgi import WSGIServer
28 from urllib import unquote
29 import sys
30
31 # Serialize ui.setconfig() accesses to avoid hitting http://bz.selenic.com/show_ bug.cgi?id=3953
32 from mercurial.ui import ui
33 import thread
34
35 config_lock = thread.allocate_lock()
36 orig_setconfig = ui.setconfig
37
38 def new_setconfig(*args, **kwargs):
39 with config_lock:
40 orig_setconfig(*args, **kwargs)
41
42 ui.setconfig = new_setconfig
43
44 # The config file looks like this. You can have paths to individual
45 # repos, collections of repos in a directory tree, or both.
46 #
47 # [paths]
48 # virtual/path1 = /real/path1
49 # virtual/path2 = /real/path2
50 # virtual/root = /real/root/*
51 # / = /real/root2/*
52 #
53 # [collections]
54 # /prefix/to/strip/off = /root/of/tree/full/of/repos
55 #
56 # paths example:
57 #
58 # * First two lines mount one repository into one virtual path, like
59 # '/real/path1' into 'virtual/path1'.
60 #
61 # * The third entry tells every mercurial repository found in
62 # '/real/root', recursively, should be mounted in 'virtual/root'. This
63 # format is preferred over the [collections] one, using absolute paths
64 # as configuration keys is not supported on every platform (including
65 # Windows).
66 #
67 # * The last entry is a special case mounting all repositories in
68 # '/real/root2' in the root of the virtual directory.
69 #
70 # collections example: say directory tree /foo contains repos /foo/bar,
71 # /foo/quux/baz. Give this config section:
72 # [collections]
73 # /foo = /foo
74 # Then repos will list as bar and quux/baz.
75 #
76 # Alternatively you can pass a list of ('virtual/path', '/real/path') tuples
77 # or use a dictionary with entries like 'virtual/path': '/real/path'
78
79 class hgwebdir_with_filter(hgwebdir):
80 def run_wsgi(self, req):
81 req.env['PATH_INFO'] = unquote(req.env.get('PATH_INFO'))
82 result = super(hgwebdir_with_filter, self).run_wsgi(req)
83 request_uri = req.env.get('REQUEST_URI')
84 if request_uri and request_uri.startswith("/subscriptionlist/"):
85 return self.do_filter(result, req)
86 else:
87 return result
88
89 def do_filter(self, iter, req):
90 for chunk in iter:
91 yield re.sub(r'\bemail=.*?([\r\n]|$)', r'email=xxxx\1', chunk)
92 if hasattr(iter, 'close'):
93 iter.close()
94
95 WSGIServer(hgwebdir_with_filter('/etc/hgweb.ini'), debug=False).run()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld