Changeset 1851 for pykota/trunk

Show
Ignore:
Timestamp:
10/20/04 10:12:27 (20 years ago)
Author:
jalet
Message:

Another fix for charset detection and Python2.3

Files:
1 modified

Legend:

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

    r1850 r1851  
    2222# 
    2323# $Log$ 
     24# Revision 1.134  2004/10/20 08:12:27  jalet 
     25# Another fix for charset detection and Python2.3 
     26# 
    2427# Revision 1.133  2004/10/19 22:24:00  jalet 
    2528# Should fix the printer's hostname or IP address detection code. 
     
    542545        # Else we use the current locale's one. 
    543546        # If nothing is set, we use ISO-8859-15 widely used in western Europe. 
    544         localecharset = locale.getlocale()[1] 
    545547        try : 
    546             localecharset = localecharset or locale.getdefaultlocale()[1] 
    547         except ValueError :     
    548             pass        # Unknown locale, strange... 
     548            # preferred method with Python 2.3 and up 
     549            localecharset = locale.getpreferredencoding() 
     550        except AttributeError :     
     551            localecharset = locale.getlocale()[1] 
     552            try : 
     553                localecharset = localecharset or locale.getdefaultlocale()[1] 
     554            except ValueError :     
     555                pass        # Unknown locale, strange... 
    549556        self.charset = charset or os.environ.get("CHARSET") or localecharset or "ISO-8859-15" 
    550557