[PATCH] Use a case-sensitive version of SafeConfigParser everywhere
Alexis S. L. Carvalho
alexis at cecm.usp.br
Sun Oct 15 20:08:44 UTC 2006
Comments? This may break some setups, but I think it's the right thing
to do.
(As a minor implementation issue: after this patch, importing util.py
will also import ConfigParser. This should not be very problematic,
since ConfigParser would be imported anyway when we create a ui object.
A possible fix would be to create a regular SafeConfigParser and then
monkey-patch the optionxform method, instead of subclassing
SafeConfigParser.)
Alexis
# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Date 1160941400 10800
# Node ID 7c6c34cdd11d949c56f50f1672be2708fb02e246
# Parent 5dbb3a991bbf722b4aa4a37dc33d3f8d4fc8c2b8
Use a case-sensitive version of SafeConfigParser everywhere
This change has the potential to break existing setups, but the current
behaviour (the keys in configuration files are always lower-cased) can
bite us in a few places:
- no way to use a Command in [defaults]
- hgext.Extension doesn't work in [extensions]
- you can't use an Upper/case/PATH in the [paths] section of hgweb.config
- you can't (easily) protect paths with upper-case letters with the
acl extension
- you can't specify a /Path/TO/a/rEPO in the [reposubs] section for
the notify extension
diff -r 5dbb3a991bbf -r 7c6c34cdd11d mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py Sun Oct 15 21:09:56 2006 +0200
+++ b/mercurial/hgweb/hgwebdir_mod.py Sun Oct 15 16:43:20 2006 -0300
@@ -8,7 +8,7 @@
import os
from mercurial.demandload import demandload
-demandload(globals(), "ConfigParser mimetools cStringIO")
+demandload(globals(), "mimetools cStringIO")
demandload(globals(), "mercurial:ui,hg,util,templater")
demandload(globals(), "mercurial.hgweb.hgweb_mod:hgweb")
demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile,style_map")
@@ -30,7 +30,7 @@ class hgwebdir(object):
self.repos = cleannames(config.items())
self.repos.sort()
else:
- cp = ConfigParser.SafeConfigParser()
+ cp = util.configparser()
cp.read(config)
self.repos = []
if cp.has_section('web'):
diff -r 5dbb3a991bbf -r 7c6c34cdd11d mercurial/ui.py
--- a/mercurial/ui.py Sun Oct 15 21:09:56 2006 +0200
+++ b/mercurial/ui.py Sun Oct 15 16:43:20 2006 -0300
@@ -11,7 +11,7 @@ demandload(globals(), "ConfigParser trac
demandload(globals(), "ConfigParser traceback util")
def dupconfig(orig):
- new = ConfigParser.SafeConfigParser(orig.defaults())
+ new = util.configparser(orig.defaults())
updateconfig(orig, new)
return new
@@ -37,7 +37,7 @@ class ui(object):
self.debugflag = debug
self.interactive = interactive
self.traceback = traceback
- self.cdata = ConfigParser.SafeConfigParser()
+ self.cdata = util.configparser()
self.readconfig(util.rcpath())
self.updateopts(verbose, debug, quiet, interactive)
else:
@@ -126,7 +126,7 @@ class ui(object):
def setconfig(self, section, name, value):
if not self.overlay:
- self.overlay = ConfigParser.SafeConfigParser()
+ self.overlay = util.configparser()
for cdata in (self.overlay, self.cdata):
if not cdata.has_section(section):
cdata.add_section(section)
diff -r 5dbb3a991bbf -r 7c6c34cdd11d mercurial/util.py
--- a/mercurial/util.py Sun Oct 15 21:09:56 2006 +0200
+++ b/mercurial/util.py Sun Oct 15 16:43:20 2006 -0300
@@ -15,7 +15,7 @@ from i18n import gettext as _
from i18n import gettext as _
from demandload import *
demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile")
-demandload(globals(), "os threading time calendar")
+demandload(globals(), "os threading time calendar ConfigParser")
# used by parsedate
defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M',
@@ -23,6 +23,11 @@ defaultdateformats = ('%Y-%m-%d %H:%M:%S
class SignalInterrupt(Exception):
"""Exception raised on SIGTERM and SIGHUP."""
+
+# like SafeConfigParser but with case-sensitive keys
+class configparser(ConfigParser.SafeConfigParser):
+ def optionxform(self, optionstr):
+ return optionstr
def cachefunc(func):
'''cache the result of function calls'''
diff -r 5dbb3a991bbf -r 7c6c34cdd11d tests/test-config-case
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-config-case Sun Oct 15 16:43:20 2006 -0300
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+echo '[Section]' >> $HGRCPATH
+echo 'KeY = Case Sensitive' >> $HGRCPATH
+echo 'key = lower case' >> $HGRCPATH
+
+hg showconfig
diff -r 5dbb3a991bbf -r 7c6c34cdd11d tests/test-config-case.out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-config-case.out Sun Oct 15 16:43:20 2006 -0300
@@ -0,0 +1,2 @@
+Section.KeY=Case Sensitive
+Section.key=lower case
More information about the Mercurial-devel
mailing list