changeset 1045:4725c8ac809a

Fixed Python 2.5 incompatibility issues (avoid str exceptions), made the bytecode more resistant for people using data directoriees with different MoinMoin versions.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Sat, 22 Jul 2006 13:25:36 +0200
parents 0f7f98a19685
children 9a124201327c
files MoinMoin/Page.py MoinMoin/formatter/text_python.py
diffstat 2 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sat Jul 22 13:24:39 2006 +0200
+++ b/MoinMoin/Page.py	Sat Jul 22 13:25:36 2006 +0200
@@ -1036,7 +1036,7 @@
                 except wikiutil.PluginMissingError:
                     pass
             else:
-                raise "Plugin missing error!" # XXX what now?
+                raise NotImplementedError("Plugin missing error!") # XXX what now?
         request.formatter = self.formatter
         self.formatter.setPage(self)
         if self.hilite_re:
@@ -1247,7 +1247,7 @@
             except wikiutil.PluginMissingError:
                 pass
         else:
-            raise "No matching parser" # XXX what do we use if nothing at all matches?
+            raise NotImplementedError("No matching parser") # XXX what do we use if nothing at all matches?
             
         # start wiki content div
         request.write(self.formatter.startContent(content_id))
@@ -1339,7 +1339,7 @@
                     except wikiutil.PluginMissingError:
                         pass
                 else:
-                    raise "no matching parser" # XXX what now?
+                    raise NotImplementedError("no matching parser") # XXX what now?
             return getattr(parser, 'caching', False)
         return False
 
@@ -1362,11 +1362,15 @@
             try:
                 code = self.loadCache(request)
                 self.execute(request, parser, code)
-            except 'CacheNeedsUpdate':
+            except Exception, (msg, ):
+                if msg != 'CacheNeedsUpdate':
+                    raise
                 try:
                     code = self.makeCache(request, parser)
                     self.execute(request, parser, code)
-                except 'CacheNeedsUpdate':
+                except Exception, (msg, ):
+                    if msg != 'CacheNeedsUpdate':
+                        raise
                     request.log('page cache failed after creation')
                     self.format(parser)
         
@@ -1392,19 +1396,21 @@
         cache = caching.CacheEntry(request, self, self.getFormatterName(), scope='item')
         attachmentsPath = self.getPagePath('attachments', check_create=0)
         if cache.needsUpdate(self._text_filename(), attachmentsPath):
-            raise 'CacheNeedsUpdate'
+            raise Exception('CacheNeedsUpdate')
         
         import marshal
         try:
             return marshal.loads(cache.content())
+        except "CacheNeedsUpdate": # convert old exception into a new one
+            raise Exception('CacheNeedsUpdate')
         except (EOFError, ValueError, TypeError):
             # Bad marshal data, must update the cache.
             # See http://docs.python.org/lib/module-marshal.html
-            raise 'CacheNeedsUpdate'
+            raise Exception('CacheNeedsUpdate')
         except Exception, err:
             request.log('fail to load "%s" cache: %s' % 
                         (self.page_name, str(err)))
-            raise 'CacheNeedsUpdate'
+            raise Exception('CacheNeedsUpdate')
 
     def makeCache(self, request, parser):
         """ Format content into code, update cache and return code """
--- a/MoinMoin/formatter/text_python.py	Sat Jul 22 13:24:39 2006 +0200
+++ b/MoinMoin/formatter/text_python.py	Sat Jul 22 13:25:36 2006 +0200
@@ -54,8 +54,9 @@
         waspcode_timestamp = int(time.time())
         source = ["""
 moincode_timestamp = int(os.path.getmtime(os.path.dirname(__file__)))
-if moincode_timestamp > %d or request.cfg.cfg_mtime > %d:
-    raise "CacheNeedsUpdate"
+cfg_mtime = getattr(request.cfg, "cfg_mtime", None)
+if moincode_timestamp > %d or cfg_mtime is None or cfg_mtime > %d:
+    raise Exception("CacheNeedsUpdate")
 """ % (waspcode_timestamp, waspcode_timestamp)]