Commits

Patrick Mézard committed 9e722e8

Replace ConfigParser with mercurial.config when available

Mercurial >= 1.3 no longer uses ConfigParser, so the module is no longer
shipped by Windows py2exe binaries, which means forest no longer works with
them. Use mercurial.config instead.

  • Participants
  • Parent commits f544151

Comments (0)

Files changed (1)

 
 """
 
-import ConfigParser
 import errno
 import os
 import re
 if not hasattr(hgweb, 'protocol'):
     hgweb.protocol = hgweb.hgweb_mod.hgweb
 
-ConfigError = ConfigParser.Error
+# There are no issues with backward compatibility and ConfigParser.
+# But since it was replaced in mercurial >= 1.3, the module is not
+# longer shipped by Windows binary packages. In this case, use
+# mercurial.config instead.
+try:
+    from mercurial import config
+    ConfigError = error.ConfigError
 
-class SnapshotError(ConfigParser.NoSectionError):
+    def readconfig(path):
+        cfg = config.config()
+        try:
+            cfg.read(path)
+            return cfg
+        except IOError:
+            return None
+
+except (ImportError, AttributeError):
+    import ConfigParser
+    ConfigError = ConfigParser.Error    
+
+    def readconfig(path):
+        cfg = ConfigParser.RawConfigParser()
+        if not cfg.read([path]):
+            return None
+        return cfg
+
+class SnapshotError(ConfigError):
     pass
 
-def readconfig(path):
-    cfg = ConfigParser.RawConfigParser()
-    if not cfg.read([path]):
-        return None
-    return cfg
-
 def cmd_options(ui, cmd, remove=None, table=commands.table):
     aliases, spec = findcmd(ui, cmd, table)
     res = list(spec[1])