changeset 1619:a103f4d38ce5

cosmetic changes
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 17 Oct 2006 16:36:05 +0200
parents e682a1ea7a68
children a86f20280204
files MoinMoin/Page.py MoinMoin/PageEditor.py
diffstat 2 files changed, 61 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Tue Oct 17 15:47:02 2006 +0200
+++ b/MoinMoin/Page.py	Tue Oct 17 16:36:05 2006 +0200
@@ -2,7 +2,8 @@
 """
     MoinMoin - Page class
 
-    @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>
+    @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>,
+                2005-2006 by MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -119,7 +120,7 @@
         """
         revfilename = os.path.join(pagedir, 'current')
         try:
-            revfile = open(revfilename)
+            revfile = file(revfilename)
             revstr = revfile.read().strip()
             revfile.close()
             rev = int(revstr)
@@ -155,11 +156,11 @@
         
         On case insensitive file system, "pagename" exists even if the
         real page name is "PageName" or "PAGENAME". This leads to
-        consufion in urls, links and logs.
+        confusion in urls, links and logs.
         See MoinMoinBugs/MacHfsPlusCaseInsensitive
         
         Correct the case of the page name. Elements created from the
-        page name in reset() are not updated because its too messy, and
+        page name in reset() are not updated because it's too messy, and
         this fix seems to be enough for 1.3.
         
         Problems to fix later:
@@ -170,10 +171,9 @@
         @param pagedir: the storage path to the page directory
         """
         realPath = filesys.realPathCase(pagedir)
-        if realPath is None:
-            return
-        realPath = wikiutil.unquoteWikiname(realPath)
-        self.page_name = realPath[-len(self.page_name):]
+        if not realPath is None:
+            realPath = wikiutil.unquoteWikiname(realPath)
+            self.page_name = realPath[-len(self.page_name):]
 
     def get_rev(self, use_underlay=-1, rev=0):
         """Get information about a revision.
@@ -587,7 +587,7 @@
         if self._raw_body is None:
             # try to open file
             try:
-                file = codecs.open(self._text_filename(), 'rb', config.charset)
+                f = codecs.open(self._text_filename(), 'rb', config.charset)
             except IOError, er:
                 import errno
                 if er.errno == errno.ENOENT:
@@ -600,11 +600,11 @@
 
             # read file content and make sure it is closed properly
             try:
-                text = file.read()
+                text = f.read()
                 text = self.decodeTextMimeType(text)
                 self.set_raw_body(text)
             finally:
-                file.close()
+                f.close()
 
         return self._raw_body
 
--- a/MoinMoin/PageEditor.py	Tue Oct 17 15:47:02 2006 +0200
+++ b/MoinMoin/PageEditor.py	Tue Oct 17 16:36:05 2006 +0200
@@ -3,6 +3,7 @@
     MoinMoin - PageEditor class
 
     @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>
+                2005-2006 by MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 
@@ -528,8 +529,7 @@
         try:
             # First save a final backup copy of the current page
             # (recreating the page allows access to the backups again)
-            msg = self.saveText(u"deleted\n", 0, comment=comment or u'',
-                    index=0)
+            msg = self.saveText(u"deleted\n", 0, comment=comment or u'', index=0)
             msg = msg.replace(
                 _("Thank you for your changes. Your attention to detail is appreciated."),
                 _('Page "%s" was successfully deleted!') % (self.page_name,))
@@ -861,7 +861,7 @@
             os.mkdir(pagedir)
         if not os.path.exists(revdir):
             os.mkdir(revdir)
-            f = open(cfn, 'w')
+            f = file(cfn, 'w')
             f.write('%08d\n' % 0)
             f.close()
 
@@ -869,56 +869,56 @@
         retry = 0
 
         try:
-                while not got_lock and retry < 100:
-                    retry += 1
-                    try:
-                        filesys.rename(cfn, clfn)
-                        got_lock = True
-                    except OSError, err:
-                        got_lock = False
-                        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
-
-                if not got_lock:
-                    raise self.CouldNotLock, _("Page could not get locked. Missing 'current' file?")
+            while not got_lock and retry < 100:
+                retry += 1
+                try:
+                    filesys.rename(cfn, clfn)
+                    got_lock = True
+                except OSError, err:
+                    got_lock = False
+                    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
 
-                # increment rev number of current(-locked) page
-                f = open(clfn)
-                revstr = f.read()
-                f.close()
-                rev = int(revstr)
-                if not was_deprecated:
-                    if self.do_revision_backup or rev == 0:
-                        rev += 1
-                revstr = '%08d' % rev
-                f = open(clfn, 'w')
-                f.write(revstr+'\n')
-                f.close()
+            if not got_lock:
+                raise self.CouldNotLock, _("Page could not get locked. Missing 'current' file?")
 
-                # save to page file
-                pagefile = os.path.join(revdir, revstr)
-                f = codecs.open(pagefile, 'wb', config.charset)
-                # Write the file using text/* mime type
-                f.write(self.encodeTextMimeType(text))
-                f.close()
-                mtime_usecs = wikiutil.timestamp2version(os.path.getmtime(pagefile))
-                # set in-memory content
-                self.set_raw_body(text)
+            # increment rev number of current(-locked) page
+            f = file(clfn)
+            revstr = f.read()
+            f.close()
+            rev = int(revstr)
+            if not was_deprecated:
+                if self.do_revision_backup or rev == 0:
+                    rev += 1
+            revstr = '%08d' % rev
+            f = file(clfn, 'w')
+            f.write(revstr+'\n')
+            f.close()
 
-                # reset page object
-                self.reset()
+            # save to page file
+            pagefile = os.path.join(revdir, revstr)
+            f = codecs.open(pagefile, 'wb', config.charset)
+            # Write the file using text/* mime type
+            f.write(self.encodeTextMimeType(text))
+            f.close()
+            mtime_usecs = wikiutil.timestamp2version(os.path.getmtime(pagefile))
+            # set in-memory content
+            self.set_raw_body(text)
 
-                # write the editlog entry
-                # for now simply make 2 logs, better would be some multilog stuff maybe
-                if self.do_revision_backup:
-                    # do not globally log edits with no revision backup (like /MoinEditorBackup pages)
-                    # if somebody edits a deprecated page, log it in global log, but not local log
-                    glog.add(self.request, mtime_usecs, rev, action, self.page_name, None, extra, comment)
-                if not was_deprecated and self.do_revision_backup:
-                    # if we did not create a new revision number, do not locally log it
-                    llog.add(self.request, mtime_usecs, rev, action, self.page_name, None, extra, comment)
+            # reset page object
+            self.reset()
+
+            # write the editlog entry
+            # for now simply make 2 logs, better would be some multilog stuff maybe
+            if self.do_revision_backup:
+                # do not globally log edits with no revision backup (like /MoinEditorBackup pages)
+                # if somebody edits a deprecated page, log it in global log, but not local log
+                glog.add(self.request, mtime_usecs, rev, action, self.page_name, None, extra, comment)
+            if not was_deprecated and self.do_revision_backup:
+                # if we did not create a new revision number, do not locally log it
+                llog.add(self.request, mtime_usecs, rev, action, self.page_name, None, extra, comment)
         finally:
             if got_lock:
                 filesys.rename(clfn, cfn)
@@ -975,8 +975,7 @@
                     other = True
                 next_line = line
             if next_line and next_line.is_from_current_user(self.request):
-                saved_page = Page(self.request, self.page_name,
-                                  rev=int(next_line.rev))
+                saved_page = Page(self.request, self.page_name, rev=int(next_line.rev))
                 if newtext == saved_page.get_raw_body():
                     msg = _("You already saved this page!")
                     return msg