Show
Ignore:
Timestamp:
01/24/08 10:12:48 (16 years ago)
Author:
jerome
Message:

It seems that the lead developer can eat his own food again...
More testing needs to be done but printing should now work again at
least with the PostgreSQL backend.

Files:
1 modified

Legend:

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

    r3295 r3298  
    4040        charset = sys.stdout.encoding or sys.getfilesystemencoding() 
    4141 
    42     # Dirty hack : if the charset is ASCII, we can safely use UTF-8 instead 
    43     # This has the advantage of allowing transparent support for recent 
    44     # versions of CUPS which (en-)force charset to UTF-8 when printing. 
    45     # This should be needed only when printing, but is probably (?) safe 
    46     # to do when using interactive commands. 
    47     if charset.upper() in ('ASCII', 'ANSI_X3.4-1968') : 
     42    if (not charset) or charset in ("ASCII", "ANSI_X3.4-1968") : 
    4843        charset = "UTF-8" 
     44         
    4945    return (language, charset) 
    5046 
     47def setenv(varname, value, charset) : 
     48    """Sets an environment variable.""" 
     49    if value is None : 
     50        value = "None" 
     51    os.environ[varname] = value.encode(charset, "replace")     
     52     
    5153def initgettext(lang, cset) : 
    5254    """Initializes gettext translations for PyKota.""" 
     
    8688 
    8789def databaseToUnicode(text) : 
    88     """Converts from database format (UTF-8) to unicode.""" 
     90    """Converts from database format (UTF-8) to unicode. 
     91     
     92       We use "replace" to accomodate legacy datas which may not 
     93       have been recorded correctly. 
     94    """ 
    8995    if text is not None : 
    9096        return text.decode("UTF-8", "replace") 
     
    95101    """Converts from unicode to database format (UTF-8).""" 
    96102    if text is not None :  
    97         return text.encode("UTF-8", "replace") 
     103        return text.encode("UTF-8") 
    98104    else :     
    99105        return None 
     
    101107def logerr(text) : 
    102108    """Logs an unicode text to stderr.""" 
    103     sys.stderr.write(text.encode(sys.stdout.encoding or locale.getlocale()[1], \ 
     109    sys.stderr.write(text.encode(sys.stdout.encoding \ 
     110                                     or locale.getlocale()[1] \ 
     111                                     or "ANSI_X3.4-1968", \ 
    104112                                 "replace")) 
    105113    sys.stderr.flush()