Patrick Mézard avatar 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.

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])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.