changeset 5711:58a9aa0d67bd

Raise exceptions as recommended in PEP 8.
author Pascal Volk <user@localhost.localdomain.org>
date Mon, 05 Jul 2010 23:21:21 +0000
parents 011bbc010d40
children 7a83cc907f68
files MoinMoin/PageEditor.py MoinMoin/formatter/dom_xml.py MoinMoin/parser/text_rst.py MoinMoin/security/__init__.py MoinMoin/util/filesys.py
diffstat 5 files changed, 19 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Sun Jun 27 12:44:38 2010 +0200
+++ b/MoinMoin/PageEditor.py	Mon Jul 05 23:21:21 2010 +0000
@@ -601,7 +601,7 @@
         if not (request.user.may.delete(self.page_name)
                 and request.user.may.write(newpagename)):
             msg = _('You are not allowed to rename this page!')
-            raise self.AccessDenied, msg
+            raise self.AccessDenied(msg)
 
         if not newpagename:
             return False, _("You can't rename to an empty pagename.")
@@ -708,7 +708,7 @@
         if not (request.user.may.write(self.page_name)
                 and request.user.may.delete(self.page_name)):
             msg = _('You are not allowed to delete this page!')
-            raise self.AccessDenied, msg
+            raise self.AccessDenied(msg)
 
         try:
             msg = self.saveText(u"deleted\n", 0, comment=comment or u'', deleted=True, notify=False)
@@ -959,10 +959,10 @@
                     if err.errno == 2: # there was no 'current' file
                         time.sleep(0.1)
                     else:
-                        raise self.CouldNotLock, _("Page could not get locked. Unexpected error (errno=%d).") % err.errno
+                        raise self.CouldNotLock(_("Page could not get locked. Unexpected error (errno=%d).") % err.errno)
 
             if not got_lock:
-                raise self.CouldNotLock, _("Page could not get locked. Missing 'current' file?")
+                raise self.CouldNotLock(_("Page could not get locked. Missing 'current' file?"))
 
             # increment rev number of current(-locked) page
             f = file(clfn)
@@ -971,7 +971,7 @@
             try:
                 rev = int(revstr)
             except ValueError, err:
-                raise self.SaveError, _("Unable to determine current page revision from the 'current' file. The page %s is damaged and cannot be edited right now.") % self.page_name
+                raise self.SaveError(_("Unable to determine current page revision from the 'current' file. The page %s is damaged and cannot be edited right now.") % self.page_name)
 
             if not was_deprecated:
                 if self.do_revision_backup or rev == 0:
@@ -989,9 +989,9 @@
                     pass # we don't care for errors in the os.remove
                 # throw a nicer exception
                 if err.errno == errno.ENOSPC:
-                    raise self.SaveError, _("Cannot save page %s, no storage space left.") % self.page_name
+                    raise self.SaveError(_("Cannot save page %s, no storage space left.") % self.page_name)
                 else:
-                    raise self.SaveError, _("An I/O error occurred while saving page %s (errno=%d)") % (self.page_name, err.errno)
+                    raise self.SaveError(_("An I/O error occurred while saving page %s (errno=%d)") % (self.page_name, err.errno))
             # atomically put it in place (except on windows)
             else:
                 filesys.rename(cltfn, clfn)
@@ -1065,13 +1065,13 @@
         msg = ""
         if not request.user.may.save(self, newtext, rev, **kw):
             msg = _('You are not allowed to edit this page!')
-            raise self.AccessDenied, msg
+            raise self.AccessDenied(msg)
         elif not self.isWritable():
             msg = _('Page is immutable!')
-            raise self.Immutable, msg
+            raise self.Immutable(msg)
         elif not newtext:
             msg = _('You cannot save empty pages.')
-            raise self.EmptyPage, msg
+            raise self.EmptyPage(msg)
         elif rev != 0 and rev != self.current_rev():
             # check if we already saved that page
             other = False
@@ -1090,16 +1090,16 @@
                     return msg
                 else:
                     msg = _("You already edited this page! Please do not use the back button.")
-                    raise self.EditConflict, msg
+                    raise self.EditConflict(msg)
 
                 msg = _("""Someone else saved this page while you were editing!
 Please review the page and save then. Do not save this page as it is!""")
 
-            raise self.EditConflict, msg
+            raise self.EditConflict(msg)
         elif newtext == self.get_raw_body():
             msg = _('You did not change the page content, not saved!')
             self.lock.release()
-            raise self.Unchanged, msg
+            raise self.Unchanged(msg)
         else:
             from MoinMoin.security import parseACL
             # Get current ACL and compare to new ACL from newtext. If
@@ -1111,7 +1111,7 @@
                 parseACL(request, newtext).acl != acl.acl and
                 action != "SAVE/REVERT"):
                 msg = _("You can't change ACLs on this page since you have no admin rights on it!")
-                raise self.NoAdmin, msg
+                raise self.NoAdmin(msg)
 
         presave = PagePreSaveEvent(request, self, newtext)
         results = send_event(presave)
--- a/MoinMoin/formatter/dom_xml.py	Sun Jun 27 12:44:38 2010 +0200
+++ b/MoinMoin/formatter/dom_xml.py	Mon Jul 05 23:21:21 2010 +0000
@@ -98,7 +98,7 @@
         if tag == 'p':
             FormatterBase.paragraph(self, 0)
         if self.tag_stack[-1][0] != tag:
-            raise ValueError, "closing of <%s> expected, but <%s> closed" % (self.tag_stack[-1][0], tag)
+            raise ValueError("closing of <%s> expected, but <%s> closed" % (self.tag_stack[-1][0], tag))
         self.position = self.position.parentNode
         return self.tag_stack.pop()
 
@@ -157,7 +157,7 @@
                 else:
                     self.request.write("tag_stack: %r\n" % self.tag_stack)
                     self.request.write(self.document.documentElement.toprettyxml(" "))
-                    raise ValueError, "closing of <%s> expected, but <%s> closed" % (last_tag, tag)
+                    raise ValueError("closing of <%s> expected, but <%s> closed" % (last_tag, tag))
             self._close_tag(tag)
             tags_to_reopen.reverse()
             for tag_name, args in tags_to_reopen:
--- a/MoinMoin/parser/text_rst.py	Sun Jun 27 12:44:38 2010 +0200
+++ b/MoinMoin/parser/text_rst.py	Mon Jul 05 23:21:21 2010 +0000
@@ -152,7 +152,7 @@
         if current_version < required_version:
             err = 'ERROR: The installed docutils version is %s;' % ('.'.join([str(i) for i in current_version]))
             err += ' version %s or later is required.' % ('.'.join([str(i) for i in required_version]))
-            raise RuntimeError, err
+            raise RuntimeError(err)
 
     def translate(self):
         visitor = MoinTranslator(self.document,
--- a/MoinMoin/security/__init__.py	Sun Jun 27 12:44:38 2010 +0200
+++ b/MoinMoin/security/__init__.py	Mon Jul 05 23:21:21 2010 +0000
@@ -146,7 +146,7 @@
         """
         request = self.request
         if attr not in request.cfg.acl_rights_valid:
-            raise AttributeError, attr
+            raise AttributeError(attr)
         return lambda pagename: _check(self.request, pagename, self.name, attr)
 
 
--- a/MoinMoin/util/filesys.py	Sun Jun 27 12:44:38 2010 +0200
+++ b/MoinMoin/util/filesys.py	Mon Jul 05 23:21:21 2010 +0000
@@ -358,7 +358,7 @@
         except (IOError, os.error), why:
             errors.append((srcname, dstname, why))
     if errors:
-        raise EnvironmentError, errors
+        raise EnvironmentError(str(errors))
 
 # Code could come from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203