DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (6a903248d8cd)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

# This file contains common code that is executed by every hgweb.wsgi
# WSGI entrypoint.

import errno
import os

# Set this before importing mercurial.* modules.
os.environ['HGENCODING'] = 'UTF-8'


from mercurial.hgweb import hgweb


# Set HTTPS_PROXY from /etc/environment value, if present. We don't
# source /etc/environment completely because we have no need for
# some of its variables. And HTTP_PROXY could confuse WSGI into
# thinking the client sent a "Proxy: " request header.
def set_env():
    try:
        with open('/etc/environment', 'rb') as fh:
            for line in fh:
                if not line.startswith(b'HTTPS_PROXY='):
                    continue

                value = line.strip().split(b'=', 1)[1]
                value = value.strip('"')

                os.environ['HTTPS_PROXY'] = value
                break

    except IOError as e:
        if e.errno != errno.ENOENT:
            raise


def make_application(wsgi_dir):
    set_env()

    config = os.path.join(wsgi_dir, 'hgweb.config')

    return hgweb(config)