[EMAIL PROTECTED] ha scritto:
Author: manlio
Date: Thu Jan 11 15:07:11 2007
New Revision: 258

Modified:
   code/pythonisti/trunk/pythonisti/geo/google.py
   code/pythonisti/trunk/pythonisti/geo/models.py
Log:
Corretta gestione encoding

Modified: code/pythonisti/trunk/pythonisti/geo/google.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/geo/google.py      (original)
+++ code/pythonisti/trunk/pythonisti/geo/google.py      Thu Jan 11 15:07:11 2007
@@ -38,7 +38,7 @@
     info = fp.info()
     content_type = info['content-type']
     charset = _get_charset(content_type) or "utf-8"
-
+    charset = 'iso-8859-1' # XXX Google madness?
     return fp.read().decode(charset)

C'รจ un problema qui.
Come mai Google usa iso-8859-1?
Come si fa a sapere quale encoding usare?

Vi ricordo che Google nel content type restituisce due encoding:
utf-8 e iso-8859-1


Modified: code/pythonisti/trunk/pythonisti/geo/models.py
==============================================================================
--- code/pythonisti/trunk/pythonisti/geo/models.py      (original)
+++ code/pythonisti/trunk/pythonisti/geo/models.py      Thu Jan 11 15:07:11 2007
@@ -21,10 +21,11 @@
def save(self):
         # Setup the computed fields
-        response = google.get_geo_location(self.location)
+        # XXX Django does not supports Unicode
+        response = google.get_geo_location(self.location.decode('utf-8'))
         coordinates = response['Point']['coordinates'][:-1]
- self.address = response['address']
+        self.address = response['address'].encode('utf-8')
         self.geolocation = dumps(coordinates)
         self.geolocation_detail = dumps(response)

Dato che Django non supporta Unicode, dobbiamo fare l'encoding esplicitamente.



Saluti  Manlio Perillo
_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Rispondere a