changeset 6774:0dbb56e90a71

hgweb: move shortcut expansion to request instantiation
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Thu, 26 Jun 2008 13:45:39 +0200
parents 8b09b0864781
children 54ccf41761c9
files mercurial/hgweb/hgweb_mod.py mercurial/hgweb/request.py
diffstat 2 files changed, 26 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py	Wed Jun 25 12:53:57 2008 -0700
+++ b/mercurial/hgweb/hgweb_mod.py	Thu Jun 26 13:45:39 2008 +0200
@@ -16,21 +16,6 @@
 from request import wsgirequest
 import webcommands, protocol, webutil
 
-shortcuts = {
-    'cl': [('cmd', ['changelog']), ('rev', None)],
-    'sl': [('cmd', ['shortlog']), ('rev', None)],
-    'cs': [('cmd', ['changeset']), ('node', None)],
-    'f': [('cmd', ['file']), ('filenode', None)],
-    'fl': [('cmd', ['filelog']), ('filenode', None)],
-    'fd': [('cmd', ['filediff']), ('node', None)],
-    'fa': [('cmd', ['annotate']), ('filenode', None)],
-    'mf': [('cmd', ['manifest']), ('manifest', None)],
-    'ca': [('cmd', ['archive']), ('node', None)],
-    'tags': [('cmd', ['tags'])],
-    'tip': [('cmd', ['changeset']), ('node', ['tip'])],
-    'static': [('cmd', ['static']), ('file', None)]
-}
-
 class hgweb(object):
     def __init__(self, repo, name=None):
         if isinstance(repo, str):
@@ -104,16 +89,6 @@
 
         self.refresh()
 
-        # expand form shortcuts
-
-        for k in shortcuts.iterkeys():
-            if k in req.form:
-                for name, value in shortcuts[k]:
-                    if value is None:
-                        value = req.form[k]
-                    req.form[name] = value
-                del req.form[k]
-
         # work with CGI variables to create coherent structure
         # use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME
 
--- a/mercurial/hgweb/request.py	Wed Jun 25 12:53:57 2008 -0700
+++ b/mercurial/hgweb/request.py	Thu Jun 26 13:45:39 2008 +0200
@@ -9,6 +9,31 @@
 import socket, cgi, errno
 from common import ErrorResponse, statusmessage
 
+shortcuts = {
+    'cl': [('cmd', ['changelog']), ('rev', None)],
+    'sl': [('cmd', ['shortlog']), ('rev', None)],
+    'cs': [('cmd', ['changeset']), ('node', None)],
+    'f': [('cmd', ['file']), ('filenode', None)],
+    'fl': [('cmd', ['filelog']), ('filenode', None)],
+    'fd': [('cmd', ['filediff']), ('node', None)],
+    'fa': [('cmd', ['annotate']), ('filenode', None)],
+    'mf': [('cmd', ['manifest']), ('manifest', None)],
+    'ca': [('cmd', ['archive']), ('node', None)],
+    'tags': [('cmd', ['tags'])],
+    'tip': [('cmd', ['changeset']), ('node', ['tip'])],
+    'static': [('cmd', ['static']), ('file', None)]
+}
+
+def expand(form):
+    for k in shortcuts.iterkeys():
+        if k in form:
+            for name, value in shortcuts[k]:
+                if value is None:
+                    value = form[k]
+                form[name] = value
+            del form[k]
+    return form
+
 class wsgirequest(object):
     def __init__(self, wsgienv, start_response):
         version = wsgienv['wsgi.version']
@@ -21,7 +46,7 @@
         self.multiprocess = wsgienv['wsgi.multiprocess']
         self.run_once = wsgienv['wsgi.run_once']
         self.env = wsgienv
-        self.form = cgi.parse(self.inp, self.env, keep_blank_values=1)
+        self.form = expand(cgi.parse(self.inp, self.env, keep_blank_values=1))
         self._start_response = start_response
         self.server_write = None
         self.headers = []