[Thuban-commits] r2756 - in trunk/thuban: . Thuban/Model test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Apr 13 12:43:15 CEST 2007


Author: bernhard
Date: 2007-04-13 12:43:14 +0200 (Fri, 13 Apr 2007)
New Revision: 2756

Modified:
   trunk/thuban/ChangeLog
   trunk/thuban/Thuban/Model/proj.py
   trunk/thuban/test/localessupport.py
Log:
* test/localessupport.py: replaced getlocale with setlocale
because of a python problem that the output of getlocale cannot
be used as input of setlocale in all cases. python 2.3 2.4 2.5
had the problem, see
sf[ 1699853 ] locale.getlocale() output fails as setlocale() input
https://sourceforge.net/tracker/index.php?func=detail&aid=1699853&group_id=5470&atid=105470
Did some minor formatting. Added German_Germany.1252 encoding 
from window XP experiments to try.

* Thuban/Model/proj.py: replaced getlocale with setlocale.
This avoids an exception on windows xp sp2 German. But it does
not fix the raster display problem. The second attempt of setlocale
can be removed.


Modified: trunk/thuban/ChangeLog
===================================================================
--- trunk/thuban/ChangeLog	2007-04-12 09:21:58 UTC (rev 2755)
+++ trunk/thuban/ChangeLog	2007-04-13 10:43:14 UTC (rev 2756)
@@ -1,3 +1,19 @@
+2007-04-12  Bernhard Reiter <bernhard at intevation.de>
+
+	* test/localessupport.py: replaced getlocale with setlocale
+	because of a python problem that the output of getlocale cannot
+	be used as input of setlocale in all cases. python 2.3 2.4 2.5
+	had the problem, see
+	sf[ 1699853 ] locale.getlocale() output fails as setlocale() input
+	https://sourceforge.net/tracker/index.php?func=detail&aid=1699853&group_id=5470&atid=105470
+	Did some minor formatting. Added German_Germany.1252 encoding 
+	from window XP experiments to try.
+
+	* Thuban/Model/proj.py: replaced getlocale with setlocale.
+	This avoids an exception on windows xp sp2 German. But it does
+	not fix the raster display problem. The second attempt of setlocale
+	can be removed.
+
 2007-03-17  Didrik Pinte <dpinte at itae.be>
 
 	*  Extensions/ 

Modified: trunk/thuban/Thuban/Model/proj.py
===================================================================
--- trunk/thuban/Thuban/Model/proj.py	2007-04-12 09:21:58 UTC (rev 2755)
+++ trunk/thuban/Thuban/Model/proj.py	2007-04-13 10:43:14 UTC (rev 2756)
@@ -23,27 +23,24 @@
 PROJ_UNITS_DEGREES = 2
 
 def _do_we_have_to_work_around_broken_proj():
-    """ If we have a problematic locale, check if proj results are good. """
+    """If we have a problematic locale, check if proj results are good."""
     if locale.localeconv()['decimal_point'] != '.':
         params = ["proj=latlong", "to_meter=0.01745", "ellps=clrk66"]
         proj = BaseProjection(params)
         result1 = proj.Forward(1,1)
 
-        savedlocale = locale.getlocale(locale.LC_NUMERIC)
+        # using setlocale because of python 2.[345] problem with getlocale here
+        savedlocale = locale.setlocale(locale.LC_NUMERIC)
         locale.setlocale(locale.LC_NUMERIC, "C")
 
         proj = BaseProjection(params)
         result2 = proj.Forward(1,1)
 
-        try:
-            locale.setlocale(locale.LC_NUMERIC, savedlocale)
-        except:
-            # python under some circumstances (observed 2.3.5-2 Debian Sarge)
-            # does not accept savedlocale directly 
-            # deviating from the documentation
-            locale.setlocale(locale.LC_NUMERIC, savedlocale[0])
+        locale.setlocale(locale.LC_NUMERIC, savedlocale)
+
         if result1 != result2:
             return True
+
     return False
 
 class Projection(BaseProjection):
@@ -73,7 +70,8 @@
 
         epsg -- (optional) The EPSG code as a string.
         """
-        self.initlocale = locale.getlocale(locale.LC_NUMERIC)
+        # using setlocale because of python 2.[345] problem with getlocale here
+        self.initlocale = locale.setlocale(locale.LC_NUMERIC)
         self.work_around_broken_proj = _do_we_have_to_work_around_broken_proj()
 
         self.assuregoodlocale()

Modified: trunk/thuban/test/localessupport.py
===================================================================
--- trunk/thuban/test/localessupport.py	2007-04-12 09:21:58 UTC (rev 2755)
+++ trunk/thuban/test/localessupport.py	2007-04-13 10:43:14 UTC (rev 2756)
@@ -11,7 +11,7 @@
 # $Id: xmlsupport.py 1683 2003-08-28 15:20:57Z bh $
 
 import locale
-from locale import LC_NUMERIC, getlocale, setlocale, localeconv
+from locale import LC_NUMERIC, setlocale, localeconv
 
 _verbose = 0
 
@@ -22,10 +22,13 @@
     This can be "(None, None)" or None if none was found.
     """
 
-    encodings = [".UTF-8", "@euro"]
-    locales = ["de_DE", "fr_FR", "fr_BE"]
+    # German_Germany.1252 discovered by Bernhard Reiter 200703 Windows XP
+    encodings = [".UTF-8", "@euro", ".1252"]
+    locales = ["de_DE", "fr_FR", "fr_BE", "German_Germany"]
 
-    oldlocale = getlocale(LC_NUMERIC)
+    # using setlocale, because output of getlocale might not work 
+    # with setlocale, which is a python problem up to at least 2.5
+    oldlocale = setlocale(LC_NUMERIC)
 
     tries = []
     for l in locales:
@@ -36,7 +39,7 @@
         try:
             if _verbose > 0:
                 print "trying", repr(t)
-            setlocale(LC_NUMERIC,t)
+            setlocale(LC_NUMERIC, t)
         except locale.Error:
             continue
         break
@@ -45,7 +48,7 @@
     if localeconv()['decimal_point'] == ",":
         return oldlocale
 
-    setlocale(LC_NUMERIC,oldlocale)
+    setlocale(LC_NUMERIC, oldlocale)
     return None
 
 if __name__ == "__main__":
@@ -57,5 +60,5 @@
         print "none found."
     else:
         print "found: ",
-        print getlocale(LC_NUMERIC)
-        setlocale(LC_NUMERIC,oldlocale)
+        print setlocale(LC_NUMERIC)
+        setlocale(LC_NUMERIC, oldlocale)



More information about the Thuban-commits mailing list