[PATCH 07 of 11 RFC] hgweb: use url.url when setting CGI environment variables
Brodie Rao
brodie at bitheap.org
Sat Mar 26 01:29:42 CDT 2011
# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1301119172 25200
# Node ID 8c42ec63cc5bd43e7c9fe53356c77daf1c72c0a5
# Parent 0d00117ca9e59ac3ada914368365f582bbe3f387
hgweb: use url.url when setting CGI environment variables
diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -6,10 +6,10 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
-import os, re, time, urlparse
+import os, re, time
from mercurial.i18n import _
from mercurial import ui, hg, util, templater
-from mercurial import error, encoding
+from mercurial import error, encoding, url
from common import ErrorResponse, get_mtime, staticfile, paritygen, \
get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
from hgweb_mod import hgweb
@@ -358,17 +358,9 @@ class hgwebdir(object):
return tmpl
def updatereqenv(self, env):
- def splitnetloc(netloc):
- if ':' in netloc:
- return netloc.split(':', 1)
- else:
- return (netloc, None)
-
if self._baseurl is not None:
- urlcomp = urlparse.urlparse(self._baseurl)
- host, port = splitnetloc(urlcomp[1])
- path = urlcomp[2]
- env['SERVER_NAME'] = host
- if port:
- env['SERVER_PORT'] = port
- env['SCRIPT_NAME'] = path
+ u = url.url(self._baseurl)
+ env['SERVER_NAME'] = u.host
+ if u.port:
+ env['SERVER_PORT'] = u.port
+ env['SCRIPT_NAME'] = '/' + u.path
More information about the Mercurial-devel
mailing list