changeset 489:9082a95430db

fixed (wrong) cyclic usage exception imported from: moin--main--1.5--patch-493
author Thomas Waldmann <tw@waldmann-edv.de>
date Tue, 21 Mar 2006 19:56:04 +0000
parents fa890b814205
children ca35d9e6d63e
files ChangeLog MoinMoin/i18n/__init__.py docs/CHANGES
diffstat 3 files changed, 37 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Mar 21 16:40:32 2006 +0000
+++ b/ChangeLog	Tue Mar 21 19:56:04 2006 +0000
@@ -2,6 +2,20 @@
 # arch-tag: automatic-ChangeLog--arch@arch.thinkmo.de--2003-archives/moin--main--1.5
 #
 
+2006-03-21 20:56:04 GMT	Thomas Waldmann <tw@waldmann-edv.de>	patch-493
+
+    Summary:
+      fixed (wrong) cyclic usage exception
+    Revision:
+      moin--main--1.5--patch-493
+
+    fixed (wrong) cyclic usage exception
+    
+
+    modified files:
+     ChangeLog MoinMoin/i18n/__init__.py docs/CHANGES
+
+
 2006-03-21 17:40:32 GMT	Thomas Waldmann <tw@waldmann-edv.de>	patch-492
 
     Summary:
--- a/MoinMoin/i18n/__init__.py	Tue Mar 21 16:40:32 2006 +0000
+++ b/MoinMoin/i18n/__init__.py	Tue Mar 21 19:56:04 2006 +0000
@@ -25,6 +25,7 @@
     @copyright: 2005 by Thomas Waldmann
     @license: GNU GPL, see COPYING for details.
 """
+debug = 0
 
 import os
 
@@ -51,9 +52,6 @@
 # also cache the unformatted strings...
 _unformatted_text_cache = {}
 
-# remember what has been marked up correctly already
-_done_markups = {}
-
 def filename(lang):
     """
     Return the filename for lang
@@ -123,13 +121,17 @@
 
     """
     from MoinMoin import caching
+    # farm notice: for persistent servers, only the first wiki requesting some language
+    # gets its cache updated - a bit strange and redundant, but no problem.
     cache = caching.CacheEntry(request, arena='i18n', key=lang)
     langfilename = os.path.join(os.path.dirname(__file__), filename(lang) + '.py')
     needsupdate = cache.needsUpdate(langfilename)
+    if debug: request.log("i18n: langfilename %s needsupdate %d" % (langfilename, needsupdate))
     if not needsupdate:
         try:
             (uc_texts, uc_unformatted) = pickle.loads(cache.content())
-        except (IOError,ValueError,pickle.UnpicklingError): # bad pickle data, no pickle
+        except (IOError, ValueError, pickle.UnpicklingError): # bad pickle data, no pickle
+            if debug: request.log("i18n: pickle %s load failed" % lang)
             needsupdate = 1
 
     if needsupdate:    
@@ -139,37 +141,35 @@
             # Language module without text dict will raise AttributeError
             texts = pysupport.importName(lang_module, "text")
         except ImportError:
-            return (None, None)
+            if debug: request.log("i18n: import of module %s failed." % lang_module)
+            return None, None
         meta = pysupport.importName(lang_module, "meta") 
         encoding = meta['encoding']
 
         # convert to unicode
-        uc_texts = {}
+        if debug: request.log("i18n: processing unformatted texts of lang %s" % lang)
+        uc_unformatted = {}
         for idx in texts:
             uidx = idx.decode(encoding)
             utxt = texts[idx].decode(encoding)
-            uc_texts[uidx] = utxt
-        uc_unformatted = uc_texts.copy()
+            uc_unformatted[uidx] = utxt
 
-        # is this already on wiki markup?
         if meta.get('wikimarkup', False):
+            if debug: request.log("i18n: processing formatted texts of lang %s" % lang)
             # use the wiki parser now to replace some wiki markup with html
-            text = ""
-            global _done_markups
-            if not _done_markups.has_key(lang):
-                _done_markups[lang] = 1
-                for key in uc_texts:
-                    text = uc_texts[key]
+            uc_texts = {}
+            for key, text in uc_unformatted.items():
+                try:
                     uc_texts[key] = formatMarkup(request, text)
-                _done_markups[lang] = 2
-            else:
-                if _done_markups[lang] == 1:
-                    raise Exception("Cyclic usage detected; you cannot have translated texts include translated texts again! "
-                                    "This error might also occur because of things that are interpreted wiki-like inside translated strings. "
-                                    "This time the error occurred while formatting %s." % text)
+                except: # infinite recursion or crash
+                    request.log("i18n: crashes in language %s on string: %s" % (lang, text))
+                    uc_texts[key] = "FIXME: %s" % text
+        else:
+            uc_texts = uc_unformatted
+        if debug: request.log("i18n: dumping lang %s" % lang)
         cache.update(pickle.dumps((uc_texts, uc_unformatted), PICKLE_PROTOCOL))
 
-    return (uc_texts, uc_unformatted)
+    return uc_texts, uc_unformatted
 
 
 def requestLanguage(request):
--- a/docs/CHANGES	Tue Mar 21 16:40:32 2006 +0000
+++ b/docs/CHANGES	Tue Mar 21 19:56:04 2006 +0000
@@ -105,6 +105,7 @@
       the strange effects happening when using "Save as" on attachments.
     * Not a moin bug, but rather a workaround for non-standard non-ASCII DNS
       hostnames: we just use the IP instead of crashing now.
+    * Spurious cyclic error in i18n fixed.
 
   Other:
     * Added css classes for the rst admonitions. Thanks to TiagoMacambira!