Index: pykota/trunk/pykota/utils.py
===================================================================
--- pykota/trunk/pykota/utils.py (revision 3411)
+++ pykota/trunk/pykota/utils.py (revision 3413)
@@ -8,10 +8,10 @@
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
@@ -41,10 +41,10 @@
     try :
         charset = charset or locale.getpreferredencoding()
-    except locale.Error :    
+    except locale.Error :
         charset = sys.stdout.encoding or sys.getfilesystemencoding()
 
     if (not charset) or charset in ("ASCII", "ANSI_X3.4-1968") :
         charset = "UTF-8"
-        
+
     return (language, charset)
 
@@ -53,6 +53,6 @@
     if value is None :
         value = "None"
-    os.environ[varname] = value.encode(charset, "replace")    
-    
+    os.environ[varname] = value.encode(charset, "replace")
+
 def initgettext(lang, cset) :
     """Initializes gettext translations for PyKota."""
@@ -60,15 +60,15 @@
         try :
             trans = gettext.translation("pykota", \
-                                        languages=["%s.%s" % (lang, 
-                                                              cset)], 
+                                        languages=["%s.%s" % (lang,
+                                                              cset)],
                                         codeset=cset)
         except TypeError : # Python <2.4
-            trans = gettext.translation("pykota", 
-                                        languages=["%s.%s" % (lang, 
+            trans = gettext.translation("pykota",
+                                        languages=["%s.%s" % (lang,
                                                               cset)])
         trans.install(unicode=True)
     except :
         gettext.NullTranslations().install(unicode=True)
-        
+
 def getpreferredlanguage() :
     """Returns the preferred language."""
@@ -76,5 +76,5 @@
     langs = [l.strip().split(';')[0] for l in languages.split(",")]
     return langs[0].replace("-", "_")
-    
+
 def getpreferredcharset() :
     """Returns the preferred charset."""
@@ -83,8 +83,8 @@
     return charsets[0]
 
-def reinitcgilocale() :        
+def reinitcgilocale() :
     """Reinitializes the locale and gettext translations for CGI scripts, according to browser's preferences."""
     initgettext(*initlocale(getpreferredlanguage(), getpreferredcharset()))
-    
+
 def N_(message) :
     """Fake translation marker for translatable strings extraction."""
@@ -93,5 +93,5 @@
 def databaseToUnicode(text) :
     """Converts from database format (UTF-8) to unicode.
-    
+
        We use "replace" to accomodate legacy datas which may not
        have been recorded correctly.
@@ -100,40 +100,40 @@
         if not isinstance(text, UnicodeType) :
             return text.decode("UTF-8", "replace")
-        else :    
+        else :
             # MySQL already returns unicode objects
             return text
-    else : 
+    else :
         return None
-    
+
 def unicodeToDatabase(text) :
     """Converts from unicode to database format (UTF-8)."""
-    if text is not None : 
+    if text is not None :
         return text.encode("UTF-8")
-    else :    
+    else :
         return None
-            
-def getdefaultcharset() :            
+
+def getdefaultcharset() :
     """Returns the default charset to use."""
     return sys.stdout.encoding or locale.getlocale()[1] or "ANSI_X3.4-1968"
-    
+
 def logerr(text) :
     """Logs an unicode text to stderr."""
     sys.stderr.write(text.encode(getdefaultcharset(), "replace"))
     sys.stderr.flush()
-    
+
 def loginvalidparam(opt, value, defaultvalue=None, additionalinfo=None) :
     """Logs an error when an invalid parameter to a command line option
        is encountered.
-    """   
+    """
     message = _("Invalid value '%(value)s' for the %(opt)s command line option") \
                                 % locals()
-    if defaultvalue is not None :                            
+    if defaultvalue is not None :
         message += ", using default '%(defaultvalue)s' instead" % locals()
     if additionalinfo :
         logerr("%s (%s)\n" % (message, additionalinfo))
-    else :    
+    else :
         logerr("%s\n" % message)
-            
-def crashed(message="Bug in PyKota") :    
+
+def crashed(message="Bug in PyKota") :
     """Minimal crash method."""
     import traceback
@@ -146,15 +146,15 @@
     logerr(msg)
     return msg
-    
+
 def run(optparser, workclass, requireargs=False) :
     """Runs a PyKota command line tool."""
     appname = os.path.basename(sys.argv[0])
     retcode = 0
-    (options, arguments) = optparser.parse_args()                   
+    (options, arguments) = optparser.parse_args()
     if requireargs and not arguments :
         logerr("%s\n" % (_("%(appname)s requires arguments, please use --help") \
                             % locals()))
         retcode = -1
-    application = None    
+    application = None
     try :
         try :
@@ -162,11 +162,11 @@
             application.deferredInit()
             retcode = application.main(arguments, options)
-        except KeyboardInterrupt :        
+        except KeyboardInterrupt :
             logerr("\nInterrupted with Ctrl+C !\n")
             retcode = -3
-        except PyKotaCommandLineError, msg :    
+        except PyKotaCommandLineError, msg :
             logerr("%s : %s\n" % (sys.argv[0], msg))
             retcode = -2
-        except SystemExit :        
+        except SystemExit :
             pass
         except :
@@ -174,12 +174,12 @@
             try :
                 application.crashed(title)
-            except :    
+            except :
                 crashed(title)
             retcode = -1
-    finally :    
+    finally :
         try :
             application.storage.close()
-        except :    
+        except :
             pass
-            
-    sys.exit(retcode)    
+
+    sys.exit(retcode)
