Changeset 3055 for pykota/trunk/pykota
- Timestamp:
- 11/12/06 17:16:49 (18 years ago)
- Location:
- pykota/trunk/pykota
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/cgifuncs.py
r2622 r3055 20 20 # 21 21 22 import sys 22 23 import os 23 24 … … 26 27 languages = os.environ.get("HTTP_ACCEPT_LANGUAGE", "") 27 28 langs = [l.strip().split(';')[0] for l in languages.split(",")] 28 return "%s_%s" % (langs[0], langs[0].upper()) 29 sys.stderr.write("Languages preferences : %s\n" % langs) 30 return langs[0].replace("-", "_") 29 31 30 32 def getCharsetPreference() : … … 32 34 charsets = os.environ.get("HTTP_ACCEPT_CHARSET", "UTF-8") 33 35 charsets = [l.strip().split(';')[0] for l in charsets.split(",")] 36 sys.stderr.write("Charsets preferences : %s\n" % charsets) 34 37 return charsets[0] -
pykota/trunk/pykota/dumper.py
r3050 r3055 283 283 and (typval == "str") : 284 284 try : 285 strvalue = unicode(strvalue, self. getCharset()).encode("UTF-8")285 strvalue = unicode(strvalue, self.charset).encode("UTF-8") 286 286 except UnicodeError : 287 287 pass -
pykota/trunk/pykota/tool.py
r3050 r3055 130 130 131 131 # locale stuff 132 self.defaultToCLocale = 0 133 try : 134 locale.setlocale(locale.LC_ALL, lang) 132 try : 133 locale.setlocale(locale.LC_ALL, (lang, charset)) 135 134 except (locale.Error, IOError) : 136 # locale.setlocale(locale.LC_ALL, "C") 137 self.defaultToCLocale = 1 138 try : 139 gettext.install("pykota") 135 locale.setlocale(locale.LC_ALL, None) 136 (self.language, self.charset) = locale.getlocale() 137 self.language = self.language or "C" 138 self.charset = self.charset or locale.getpreferredencoding() 139 140 # translation stuff 141 try : 142 try : 143 trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)], codeset=self.charset) 144 except TypeError : # Python <2.4 145 trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)]) 146 trans.install() 140 147 except : 141 148 gettext.NullTranslations().install() 142 143 # Finds the correct charset144 self.localecharset = sys.getfilesystemencoding()145 if self.localecharset is None :146 try :147 try :148 self.localecharset = locale.getpreferredencoding()149 except AttributeError :150 try :151 self.localecharset = locale.getlocale()[1]152 self.localecharset = self.localecharset or locale.getdefaultlocale()[1]153 except ValueError :154 pass # Unknown locale, strange...155 except locale.Error :156 pass157 self.charset = charset or self.localecharset or "UTF-8"158 149 159 150 # pykota specific stuff … … 189 180 self.softwareJobPrice = 0.0 190 181 191 if self.defaultToCLocale :192 self.printInfo("Incorrect locale settings. PyKota falls back to the default locale.", "warn")193 182 if environHome : 194 183 self.printInfo("PYKOTA_HOME environment variable is set. Configuration files were searched in %s" % confdir, "info") … … 197 186 self.printInfo("The 'pykota' system account is missing. Configuration files were searched in %s instead." % confdir, "warn") 198 187 199 self.logdebug(" Charset detected from locale settings : %s" % self.localecharset)188 self.logdebug("Language in use : %s" % self.language) 200 189 self.logdebug("Charset in use : %s" % self.charset) 190 201 191 arguments = " ".join(['"%s"' % arg for arg in sys.argv]) 202 192 self.logdebug("Command line arguments : %s" % arguments) … … 237 227 self.logdebug(_("Regained priviledges. Now running as root.")) 238 228 self.privdropped = 0 239 240 def getCharset(self) :241 """Returns the charset in use."""242 return self.charset243 229 244 230 def UTF8ToUserCharset(self, text) :