Support repos with semi-strange characters.
Sun Jul 3 21:39:57 UTC 2005 Alberto Bertogli <albertogli@telpin.com.ar>
* Support repos with semi-strange characters.
Implement support for repo names with semi-strange characters (ie. at least -
and _). It could use more improvement, but it'll do for most repos.
diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi
--- old-darcsweb/darcsweb.cgi 2015-04-15 14:35:49.000000000 +0000
+++ new-darcsweb/darcsweb.cgi 2015-04-15 14:35:50.000000000 +0000
@@ -15,6 +15,7 @@
import stat
import cgi
import cgitb; cgitb.enable()
+import urllib
import xml.sax
from xml.sax.saxutils import escape
@@ -1118,7 +1119,7 @@
else: print '<tr class="light">'
alt = not alt
print """
-<td><a class="list" href="%(myname)s?r=%(name)s;a=summary">%(name)s</a></td>
+<td><a class="list" href="%(myname)s?r=%(name)s;a=summary">%(dname)s</a></td>
<td>%(desc)s</td>
<td class="link"><a href="%(myname)s?r=%(name)s;a=summary">summary</a> |
<a href="%(myname)s?r=%(name)s;a=shortlog">shortlog</a> |
@@ -1128,7 +1129,8 @@
</tr>
""" % {
'myname': all_configs.base.myname,
- 'name': name,
+ 'dname': name,
+ 'name': urllib.quote(name),
'desc': shorten_str(desc, 60)
}
print "</table>"
@@ -1146,12 +1148,12 @@
break
else:
# not found
- raise
+ raise "RepoNotFound", name
# fill the configuration
base = all_configs.base
config.myname = base.myname
- config.myreponame = base.myname + '?r=' + name
+ config.myreponame = base.myname + '?r=' + urllib.quote(name)
config.myurl = base.myurl
config.darcslogo = base.darcslogo
config.darcsfav = base.darcsfav
@@ -1175,7 +1177,7 @@
sys.exit(0)
# get the repo configuration and fill the config class
-current_repo = form['r'].value
+current_repo = urllib.unquote(form['r'].value)
fill_config(current_repo)
diff -rN -u old-darcsweb/mkconfig.py new-darcsweb/mkconfig.py
--- old-darcsweb/mkconfig.py 2015-04-15 14:35:49.000000000 +0000
+++ new-darcsweb/mkconfig.py 2015-04-15 14:35:49.000000000 +0000
@@ -26,12 +26,24 @@
import sys
import os
+import string
+import urllib
def help():
print "Error: wrong parameter count"
print __doc__
+def filter_class(s):
+ "Filter s so the new string can be used as a class name."
+ allowed = string.ascii_letters + string.digits + '_'
+ l = [c for c in s if c in allowed]
+ return string.join(l, "")
+
+def filter_url(s):
+ "Filter s so the new string can be used in a raw url."
+ return urllib.quote_plus(s, ':/')
+
# check parameters
if len(sys.argv) != 5:
@@ -48,17 +60,18 @@
continue
s = \
"""
-class %(name)s:
+class %(classname)s:
reponame = '%(name)s'
repodesc = '%(desc)s'
repodir = '%(dir)s'
repourl = '%(url)s'
repoencoding = '%(encoding)s'
""" % {
+ 'classname': filter_class(d),
'name': d,
'desc': basedesc.replace('NAME', d),
'dir': os.path.abspath(basepath + '/' + d),
- 'url': baseurl.replace('NAME', d),
+ 'url': filter_url(baseurl.replace('NAME', d)),
'encoding': baseencoding,
}
print s