Changeset 3294 for pykota/trunk/pykota/tool.py
- Timestamp:
- 01/18/08 23:39:41 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/tool.py
r3288 r3294 29 29 import getopt 30 30 import smtplib 31 import gettext32 31 import locale 33 32 import socket … … 109 108 self.logger = logger.openLogger("stderr") 110 109 111 # locale stuff 112 try : 113 locale.setlocale(locale.LC_ALL, (lang, charset)) 114 except (locale.Error, IOError) : 115 locale.setlocale(locale.LC_ALL, None) 110 # Saves a copy of the locale settings 116 111 (self.language, self.charset) = locale.getlocale() 117 self.language = self.language or "C" 118 try : 119 self.charset = self.charset or locale.getpreferredencoding() 120 except locale.Error : 121 self.charset = sys.stdout.encoding or sys.getfilesystemencoding() 122 123 # Dirty hack : if the charset is ASCII, we can safely use UTF-8 instead 124 # This has the advantage of allowing transparent support for recent 125 # versions of CUPS which (en-)force charset to UTF-8 when printing. 126 # This should be needed only when printing, but is probably (?) safe 127 # to do when using interactive commands. 128 if self.charset.upper() in ('ASCII', 'ANSI_X3.4-1968') : 129 self.charset = "UTF-8" 130 131 # translation stuff 132 try : 133 try : 134 trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)], codeset=self.charset) 135 except TypeError : # Python <2.4 136 trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)]) 137 trans.install(unicode=True) 138 except : 139 gettext.NullTranslations().install(unicode=True) 140 112 141 113 # pykota specific stuff 142 114 self.documentation = doc … … 362 334 # and reset the list of arguments to the lines read from 363 335 # the file. 364 argsfile = open(parsed["arguments"] or parsed["A"], "r") 336 argsfile = open(parsed["arguments"] or parsed["A"], "r") # TODO : charset decoding 365 337 argv = [ l.strip() for l in argsfile.readlines() ] 366 338 argsfile.close()