diff options
| author | Stefan Brand <stefan.brand@eox.at> | 2023-02-17 09:38:39 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-02-17 19:57:34 +0100 |
| commit | 341f33ed157809906b7c4b4ee59d8f11e84462ee (patch) | |
| tree | 885a9c83109d3bbac1a7e502eaea425380c86b3e | |
| parent | 610cd06c3ffe9ef49554f7f7b1f9ff4aa9c2b879 (diff) | |
[4.2.x] Refs #34302 -- Fixed SpatialReference.auth_name()/auth_code() when target is None.
force_bytes() turns None into the byte string b"None". Since
ctypes.c_char_p() also accepts None, we can bypass force_bytes() if
target is None.
Backport of d77762de038d1ab46cdcda2b7202d36c80956e25 from main
| -rw-r--r-- | django/contrib/gis/gdal/srs.py | 8 | ||||
| -rw-r--r-- | tests/gis_tests/gdal_tests/test_srs.py | 7 |
2 files changed, 12 insertions, 3 deletions
diff --git a/django/contrib/gis/gdal/srs.py b/django/contrib/gis/gdal/srs.py index 2e335fe5d5..4df4419026 100644 --- a/django/contrib/gis/gdal/srs.py +++ b/django/contrib/gis/gdal/srs.py @@ -158,11 +158,15 @@ class SpatialReference(GDALBase): def auth_name(self, target): "Return the authority name for the given string target node." - return capi.get_auth_name(self.ptr, force_bytes(target)) + return capi.get_auth_name( + self.ptr, target if target is None else force_bytes(target) + ) def auth_code(self, target): "Return the authority code for the given string target node." - return capi.get_auth_code(self.ptr, force_bytes(target)) + return capi.get_auth_code( + self.ptr, target if target is None else force_bytes(target) + ) def clone(self): "Return a clone of this SpatialReference object." diff --git a/tests/gis_tests/gdal_tests/test_srs.py b/tests/gis_tests/gdal_tests/test_srs.py index fd25dcbc34..293144aa8e 100644 --- a/tests/gis_tests/gdal_tests/test_srs.py +++ b/tests/gis_tests/gdal_tests/test_srs.py @@ -35,7 +35,11 @@ srlist = ( ang_name="degree", lin_units=1.0, ang_units=0.0174532925199, - auth={"GEOGCS": ("EPSG", "4326"), "spheroid": ("EPSG", "7030")}, + auth={ + None: ("EPSG", "4326"), # Top-level authority. + "GEOGCS": ("EPSG", "4326"), + "spheroid": ("EPSG", "7030"), + }, attr=( ("DATUM", "WGS_1984"), (("SPHEROID", 1), "6378137"), @@ -64,6 +68,7 @@ srlist = ( lin_units=1.0, ang_units=0.0174532925199, auth={ + None: ("EPSG", "32140"), # Top-level authority. "PROJCS": ("EPSG", "32140"), "spheroid": ("EPSG", "7019"), "unit": ("EPSG", "9001"), |
