Use smarter string decoding in GeoDjango

The first try to solve the Python 3 GIS encoding/decoding issue
was too naive. Using decode() on all read strings is bound to fail
as soon as a non-ascii string is concerned.
This patch is a little more clever, leaving ascii decoding when
plain ascii strings are expected, and allowing to specify a custom
encoding in DataSource hierarchy.
This commit is contained in:
Claude Paroz 2012-10-06 22:56:47 +02:00
parent a62d53c032
commit 9a2bceed1a
17 changed files with 71 additions and 41 deletions

View file

@ -34,7 +34,7 @@ from django.contrib.gis.gdal.error import SRSException
from django.contrib.gis.gdal.prototypes import srs as capi
from django.utils import six
from django.utils.encoding import force_bytes, force_text
from django.utils.encoding import force_bytes
#### Spatial Reference class. ####
@ -139,8 +139,7 @@ class SpatialReference(GDALBase):
"""
if not isinstance(target, six.string_types) or not isinstance(index, int):
raise TypeError
value = capi.get_attr_value(self.ptr, force_bytes(target), index)
return force_text(value, 'ascii', strings_only=True)
return capi.get_attr_value(self.ptr, force_bytes(target), index)
def auth_name(self, target):
"Returns the authority name for the given string target node."