Index: branches/mbutscher/work/lib/pwiki/wikidata/WikiDataManager.py
===================================================================
--- branches/mbutscher/work/lib/pwiki/wikidata/WikiDataManager.py (revision 247)
+++ branches/mbutscher/work/lib/pwiki/wikidata/WikiDataManager.py (revision 263)
@@ -3,5 +3,5 @@
 
 from weakref import WeakValueDictionary
-import os, os.path, time, shutil, traceback
+import os, os.path, time, shutil, traceback, ConfigParser
 from threading import RLock, Thread, Condition
 # from collections import deque
@@ -131,41 +131,47 @@
     else:
         wikiConfigFilename = wikiCombinedFilename
-    wikiWord = None
-
-    while True:
-        try:
-            # config.read(wikiConfigFile)
-            wikiConfig.loadConfig(wikiConfigFilename)
-            return wikiConfigFilename, wikiWord
-        except Exception, e:
-            # try to recover by checking if the parent dir contains the real wiki file
-            # if it does the current wiki file must be a wiki word file, so open the
-            # real wiki to the wiki word.
-#                 try:
-            parentDir = os.path.dirname(os.path.dirname(wikiConfigFilename))
-            if parentDir:
-                try:
-                    wikiFiles = [file for file in os.listdir(parentDir) \
-                            if file.endswith(".wiki")]
-                    if len(wikiFiles) > 0:
-                        wikiWord = os.path.basename(wikiConfigFilename)
-                        wikiWord = wikiWord[0 : len(wikiWord) - 5]
-
-                        # if this is win95 or < the file name could be a 8.3 alias, file~1 for example
-                        windows83Marker = wikiWord.find("~")
-                        if windows83Marker != -1:
-                            wikiWord = wikiWord[0:windows83Marker]
-                            matchingFiles = [file for file in wikiFiles \
-                                    if file.lower().startswith(wikiWord)]
-                            if matchingFiles:
-                                wikiWord = matchingFiles[0]
-                        wikiConfigFilename = os.path.join(parentDir, wikiFiles[0])
-                        continue
-                except (WindowsError, IOError, OSError):
-                    # something went wrong -> give up
-                    traceback.print_exc()
-                    return None, None
-
-            return None, None
+
+    try:
+        wikiConfig.loadConfig(wikiConfigFilename)
+        return wikiConfigFilename, None
+    except ConfigParser.ParsingError, e:
+        # try to recover by checking if the parent dir contains the real wiki file
+        # if it does the current wiki file must be a wiki word file, so open the
+        # real wiki to the wiki word.
+        wikiWord = None
+        parentDir = os.path.dirname(os.path.dirname(wikiConfigFilename))
+        if parentDir:
+            try:
+                wikiFiles = [file for file in os.listdir(parentDir) \
+                        if file.endswith(".wiki")]
+                if len(wikiFiles) > 0:
+                    wikiWord = os.path.basename(wikiConfigFilename)
+                    wikiWord = wikiWord[0 : len(wikiWord) - 5]
+
+                    # if this is win95 or < the file name could be a 8.3 alias, file~1 for example
+                    windows83Marker = wikiWord.find("~")
+                    if windows83Marker != -1:
+                        wikiWord = wikiWord[0:windows83Marker]
+                        matchingFiles = [file for file in wikiFiles \
+                                if file.lower().startswith(wikiWord)]
+                        if matchingFiles:
+                            wikiWord = matchingFiles[0]
+
+                    wikiConfig.loadConfig(os.path.join(parentDir, wikiFiles[0]))
+                    return os.path.join(parentDir, wikiFiles[0]), wikiWord
+            except:
+                pass
+
+        # Either parent directory couldn't be constructed or something went
+        # wrong in parent directory so return initial wikiConfigFilename
+        # although the file is obviously corrupted but this is handled by
+        # code PersonalWikiFrame.openWiki
+        return wikiConfigFilename, None
+
+    except Exception, e:
+        # Something else went wrong (file not present or not accessible)
+        traceback.print_exc()
+        return None, None
+
     
     
@@ -311,5 +317,9 @@
         self.writeAccessDenied = False
 
-        wikiConfig.loadConfig(wikiConfigFilename)
+        try:
+            wikiConfig.loadConfig(wikiConfigFilename)
+        except ConfigParser.ParsingError, e:
+            raise BadConfigurationFileException(
+                    _(u"Wiki configuration file is corrupted"))
 
         # config variables
@@ -733,5 +743,5 @@
 
 
-    def makeRelUrlAbsolute(self, relurl):
+    def makeRelUrlAbsolute(self, relurl, addSafe=''):
         """
         Return the absolute file: URL for a rel: URL
@@ -741,10 +751,10 @@
         url = u"file:" + urlFromPathname(
                 os.path.abspath(os.path.join(os.path.dirname(
-                        self.getWikiConfigPath()), relpath)))
+                        self.getWikiConfigPath()), relpath)), addSafe=addSafe)
 
         return url
 
 
-    def makeAbsPathRelUrl(self, absPath):
+    def makeAbsPathRelUrl(self, absPath, addSafe=''):
         """
         Return the rel: URL for an absolute file path or None if
@@ -761,5 +771,5 @@
             return None
 
-        return u"rel://" + urlFromPathname(relPath)
+        return u"rel://" + urlFromPathname(relPath, addSafe=addSafe)
 
 
