mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
Option to disable key and value normalization.
This commit is contained in:
parent
3a3eb3bd97
commit
069960b7cb
@ -59,12 +59,17 @@ def driver_count():
|
||||
return GDALGetDriverCount() + OGRGetDriverCount()
|
||||
|
||||
|
||||
cpdef get_gdal_config(key):
|
||||
cpdef get_gdal_config(key, normalize=True):
|
||||
"""Get the value of a GDAL configuration option"""
|
||||
key = key.upper().encode('utf-8')
|
||||
if normalize:
|
||||
key = key.upper()
|
||||
|
||||
key = key.encode('utf-8')
|
||||
val = CPLGetConfigOption(<const char *>key, NULL)
|
||||
if not val:
|
||||
return None
|
||||
elif not normalize:
|
||||
return val
|
||||
else:
|
||||
if val == u'ON':
|
||||
return True
|
||||
@ -74,19 +79,23 @@ cpdef get_gdal_config(key):
|
||||
return val
|
||||
|
||||
|
||||
cpdef set_gdal_config(key, val):
|
||||
cpdef set_gdal_config(key, val, normalize=True):
|
||||
"""Set a GDAL configuration option's value"""
|
||||
key = key.upper().encode('utf-8')
|
||||
if normalize:
|
||||
key = key.upper()
|
||||
key = key.encode('utf-8')
|
||||
if isinstance(val, string_types):
|
||||
val = val.encode('utf-8')
|
||||
else:
|
||||
elif normalize:
|
||||
val = ('ON' if val else 'OFF').encode('utf-8')
|
||||
CPLSetConfigOption(<const char *>key, <const char *>val)
|
||||
|
||||
|
||||
cpdef del_gdal_config(key):
|
||||
cpdef del_gdal_config(key, normalize=True):
|
||||
"""Delete a GDAL configuration option"""
|
||||
key = key.upper().encode('utf-8')
|
||||
if normalize:
|
||||
key = key.upper()
|
||||
key = key.encode('utf-8')
|
||||
CPLSetConfigOption(<const char *>key, NULL)
|
||||
|
||||
|
||||
|
||||
@ -41,6 +41,17 @@ def test_gdal_config_accessers():
|
||||
assert get_gdal_config('foo') is None
|
||||
|
||||
|
||||
def test_gdal_config_accessors_no_normalize():
|
||||
"""Disables casting keys to upper case and normalizing values to boolean
|
||||
Python values.
|
||||
"""
|
||||
assert get_gdal_config('foo') is None
|
||||
set_gdal_config('foo', 'ON', normalize=False)
|
||||
assert get_gdal_config('foo', normalize=False) == 'ON'
|
||||
del_gdal_config('foo', normalize=False)
|
||||
assert get_gdal_config('foo', normalize=False) is None
|
||||
|
||||
|
||||
# The 'gdalenv' fixture ensures that gdal configuration is deleted
|
||||
# at the end of the test, making tests as isolates as GDAL allows.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user