Show
Ignore:
Timestamp:
09/27/08 22:02:37 (16 years ago)
Author:
jerome
Message:

Removed unnecessary spaces at EOL.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/utils.py

    r3411 r3413  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    4141    try : 
    4242        charset = charset or locale.getpreferredencoding() 
    43     except locale.Error :     
     43    except locale.Error : 
    4444        charset = sys.stdout.encoding or sys.getfilesystemencoding() 
    4545 
    4646    if (not charset) or charset in ("ASCII", "ANSI_X3.4-1968") : 
    4747        charset = "UTF-8" 
    48          
     48 
    4949    return (language, charset) 
    5050 
     
    5353    if value is None : 
    5454        value = "None" 
    55     os.environ[varname] = value.encode(charset, "replace")     
    56      
     55    os.environ[varname] = value.encode(charset, "replace") 
     56 
    5757def initgettext(lang, cset) : 
    5858    """Initializes gettext translations for PyKota.""" 
     
    6060        try : 
    6161            trans = gettext.translation("pykota", \ 
    62                                         languages=["%s.%s" % (lang,  
    63                                                               cset)],  
     62                                        languages=["%s.%s" % (lang, 
     63                                                              cset)], 
    6464                                        codeset=cset) 
    6565        except TypeError : # Python <2.4 
    66             trans = gettext.translation("pykota",  
    67                                         languages=["%s.%s" % (lang,  
     66            trans = gettext.translation("pykota", 
     67                                        languages=["%s.%s" % (lang, 
    6868                                                              cset)]) 
    6969        trans.install(unicode=True) 
    7070    except : 
    7171        gettext.NullTranslations().install(unicode=True) 
    72          
     72 
    7373def getpreferredlanguage() : 
    7474    """Returns the preferred language.""" 
     
    7676    langs = [l.strip().split(';')[0] for l in languages.split(",")] 
    7777    return langs[0].replace("-", "_") 
    78      
     78 
    7979def getpreferredcharset() : 
    8080    """Returns the preferred charset.""" 
     
    8383    return charsets[0] 
    8484 
    85 def reinitcgilocale() :         
     85def reinitcgilocale() : 
    8686    """Reinitializes the locale and gettext translations for CGI scripts, according to browser's preferences.""" 
    8787    initgettext(*initlocale(getpreferredlanguage(), getpreferredcharset())) 
    88      
     88 
    8989def N_(message) : 
    9090    """Fake translation marker for translatable strings extraction.""" 
     
    9393def databaseToUnicode(text) : 
    9494    """Converts from database format (UTF-8) to unicode. 
    95      
     95 
    9696       We use "replace" to accomodate legacy datas which may not 
    9797       have been recorded correctly. 
     
    100100        if not isinstance(text, UnicodeType) : 
    101101            return text.decode("UTF-8", "replace") 
    102         else :     
     102        else : 
    103103            # MySQL already returns unicode objects 
    104104            return text 
    105     else :  
     105    else : 
    106106        return None 
    107      
     107 
    108108def unicodeToDatabase(text) : 
    109109    """Converts from unicode to database format (UTF-8).""" 
    110     if text is not None :  
     110    if text is not None : 
    111111        return text.encode("UTF-8") 
    112     else :     
     112    else : 
    113113        return None 
    114              
    115 def getdefaultcharset() :             
     114 
     115def getdefaultcharset() : 
    116116    """Returns the default charset to use.""" 
    117117    return sys.stdout.encoding or locale.getlocale()[1] or "ANSI_X3.4-1968" 
    118      
     118 
    119119def logerr(text) : 
    120120    """Logs an unicode text to stderr.""" 
    121121    sys.stderr.write(text.encode(getdefaultcharset(), "replace")) 
    122122    sys.stderr.flush() 
    123      
     123 
    124124def loginvalidparam(opt, value, defaultvalue=None, additionalinfo=None) : 
    125125    """Logs an error when an invalid parameter to a command line option 
    126126       is encountered. 
    127     """    
     127    """ 
    128128    message = _("Invalid value '%(value)s' for the %(opt)s command line option") \ 
    129129                                % locals() 
    130     if defaultvalue is not None :                             
     130    if defaultvalue is not None : 
    131131        message += ", using default '%(defaultvalue)s' instead" % locals() 
    132132    if additionalinfo : 
    133133        logerr("%s (%s)\n" % (message, additionalinfo)) 
    134     else :     
     134    else : 
    135135        logerr("%s\n" % message) 
    136              
    137 def crashed(message="Bug in PyKota") :     
     136 
     137def crashed(message="Bug in PyKota") : 
    138138    """Minimal crash method.""" 
    139139    import traceback 
     
    146146    logerr(msg) 
    147147    return msg 
    148      
     148 
    149149def run(optparser, workclass, requireargs=False) : 
    150150    """Runs a PyKota command line tool.""" 
    151151    appname = os.path.basename(sys.argv[0]) 
    152152    retcode = 0 
    153     (options, arguments) = optparser.parse_args()                    
     153    (options, arguments) = optparser.parse_args() 
    154154    if requireargs and not arguments : 
    155155        logerr("%s\n" % (_("%(appname)s requires arguments, please use --help") \ 
    156156                            % locals())) 
    157157        retcode = -1 
    158     application = None     
     158    application = None 
    159159    try : 
    160160        try : 
     
    162162            application.deferredInit() 
    163163            retcode = application.main(arguments, options) 
    164         except KeyboardInterrupt :         
     164        except KeyboardInterrupt : 
    165165            logerr("\nInterrupted with Ctrl+C !\n") 
    166166            retcode = -3 
    167         except PyKotaCommandLineError, msg :     
     167        except PyKotaCommandLineError, msg : 
    168168            logerr("%s : %s\n" % (sys.argv[0], msg)) 
    169169            retcode = -2 
    170         except SystemExit :         
     170        except SystemExit : 
    171171            pass 
    172172        except : 
     
    174174            try : 
    175175                application.crashed(title) 
    176             except :     
     176            except : 
    177177                crashed(title) 
    178178            retcode = -1 
    179     finally :     
     179    finally : 
    180180        try : 
    181181            application.storage.close() 
    182         except :     
     182        except : 
    183183            pass 
    184              
    185     sys.exit(retcode)     
     184 
     185    sys.exit(retcode)