Changeset 3055
- Timestamp:
- 11/12/06 17:16:49 (18 years ago)
- Location:
- pykota/trunk
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/cgi-bin/dumpykota.cgi
r3032 r3055 35 35 from pykota.cgifuncs import getLanguagePreference, getCharsetPreference 36 36 37 header = """Content-type: text/html 38 39 <?xml version="1.0" encoding="%s"?> 37 header = """Content-type: text/html;charset=%s 38 40 39 <html> 41 40 <head> … … 70 69 </head> 71 70 <body> 71 <!-- %s %s --> 72 72 <p> 73 73 <form action="dumpykota.cgi" method="GET" name="mainform" onsubmit="return checkvalues()"> … … 124 124 """Displays the dumper interface.""" 125 125 global header, footer 126 print header % (self.getCharset(), _("PyKota Data Dumper"), \ 126 print header % (self.charset, _("PyKota Data Dumper"), \ 127 self.language, self.charset, \ 127 128 self.config.getLogoLink(), \ 128 129 self.config.getLogoURL(), version.__version__, \ … … 228 229 229 230 if __name__ == "__main__" : 230 os.environ["LC_ALL"] = getLanguagePreference() 231 admin = PyKotaDumperGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference()) 231 admin = PyKotaDumperGUI(lang=getLanguagePreference(), charset=getCharsetPreference()) 232 232 admin.deferredInit() 233 233 admin.form = cgi.FieldStorage() -
pykota/trunk/cgi-bin/printquota.cgi
r3050 r3055 37 37 from pykota.cgifuncs import getLanguagePreference, getCharsetPreference 38 38 39 header = """Content-type: text/html 40 41 <?xml version="1.0" encoding="%s"?> 39 header = """Content-type: text/html;charset=%s 40 42 41 <html> 43 42 <head> … … 46 45 </head> 47 46 <body> 47 <!-- %s %s --> 48 48 <p> 49 49 <form action="printquota.cgi" method="POST"> … … 97 97 """Displays the administrative interface.""" 98 98 global header, footer 99 print header % (self.getCharset(), _("PyKota Reports"), \ 99 print header % (self.charset, _("PyKota Reports"), \ 100 self.language, self.charset, \ 100 101 self.config.getLogoLink(), \ 101 102 self.config.getLogoURL(), version.__version__, \ … … 287 288 288 289 if __name__ == "__main__" : 289 os.environ["LC_ALL"] = getLanguagePreference() 290 admin = PyKotaReportGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference()) 290 admin = PyKotaReportGUI(lang=getLanguagePreference(), charset=getCharsetPreference()) 291 291 admin.deferredInit() 292 292 admin.form = cgi.FieldStorage() -
pykota/trunk/cgi-bin/pykotme.cgi
r2909 r3055 37 37 38 38 39 header = """Content-type: text/html 40 41 <?xml version="1.0" encoding="%s"?> 39 header = """Content-type: text/html;charset=%s 40 42 41 <html> 43 42 <head> … … 46 45 </head> 47 46 <body> 47 <!-- %s %s --> 48 48 <p> 49 49 <form action="pykotme.cgi" method="POST" enctype="multipart/form-data"> … … 97 97 """Displays the administrative interface.""" 98 98 global header, footer 99 print header % (self.getCharset(), _("PyKota Quotes"), \ 99 print header % (self.charset, _("PyKota Quotes"), \ 100 self.language, self.charset, \ 100 101 self.config.getLogoLink(), \ 101 102 self.config.getLogoURL(), version.__version__, \ … … 187 188 188 189 if __name__ == "__main__" : 189 os.environ["LC_ALL"] = getLanguagePreference() 190 admin = PyKotMeGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference()) 190 admin = PyKotMeGUI(lang=getLanguagePreference(), charset=getCharsetPreference()) 191 191 admin.deferredInit() 192 192 admin.form = cgi.FieldStorage() -
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) :