From 0799f73699271b0b58e8affe3e8e039f9781d589 Mon Sep 17 00:00:00 2001 From: Sandeep Murthy Date: Fri, 20 Dec 2019 21:59:22 +0000 Subject: [PATCH 1/3] Drop Python 2 support (changes in `rtree/index.py` module) --- rtree/index.py | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/rtree/index.py b/rtree/index.py index 74646c90..f7d35422 100644 --- a/rtree/index.py +++ b/rtree/index.py @@ -5,24 +5,12 @@ from . import core -try: - import cPickle as pickle -except ImportError: - import pickle +import pickle import sys -if sys.version_info[0] == 2: - range = xrange - string_types = basestring -elif sys.version_info[0] == 3: - string_types = str +string_types = str -def string_output(s): - if sys.version_info[0] == 2: - return s - elif sys.version_info[0] == 3: - return s.decode('UTF-8') RT_Memory = 0 RT_Disk = 1 @@ -1519,8 +1507,8 @@ def set_reinsert_factor(self, value): """Reinsert factor""" def get_filename(self): - s = core.rt.IndexProperty_GetFileName(self.handle) - return string_output(s) + return core.rt.IndexProperty_GetFileName(self.handle) + def set_filename(self, value): if isinstance(value, string_types): @@ -1531,8 +1519,8 @@ def set_filename(self, value): """Index filename for disk storage""" def get_dat_extension(self): - s = core.rt.IndexProperty_GetFileNameExtensionDat(self.handle) - return string_output(s) + return core.rt.IndexProperty_GetFileNameExtensionDat(self.handle) + def set_dat_extension(self, value): if isinstance(value, string_types): @@ -1544,8 +1532,8 @@ def set_dat_extension(self, value): """Extension for .dat file""" def get_idx_extension(self): - s = core.rt.IndexProperty_GetFileNameExtensionIdx(self.handle) - return string_output(s) + return core.rt.IndexProperty_GetFileNameExtensionIdx(self.handle) + def set_idx_extension(self, value): if isinstance(value, string_types): From f855425824ebb18ab9d3d5cde007e87a8d250ae4 Mon Sep 17 00:00:00 2001 From: Sandeep Murthy Date: Fri, 20 Dec 2019 22:05:52 +0000 Subject: [PATCH 2/3] Fix index tests --- rtree/index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rtree/index.py b/rtree/index.py index f7d35422..f47deda1 100644 --- a/rtree/index.py +++ b/rtree/index.py @@ -1507,7 +1507,7 @@ def set_reinsert_factor(self, value): """Reinsert factor""" def get_filename(self): - return core.rt.IndexProperty_GetFileName(self.handle) + return core.rt.IndexProperty_GetFileName(self.handle).decode() def set_filename(self, value): @@ -1519,7 +1519,7 @@ def set_filename(self, value): """Index filename for disk storage""" def get_dat_extension(self): - return core.rt.IndexProperty_GetFileNameExtensionDat(self.handle) + return core.rt.IndexProperty_GetFileNameExtensionDat(self.handle).decode() def set_dat_extension(self, value): @@ -1532,7 +1532,7 @@ def set_dat_extension(self, value): """Extension for .dat file""" def get_idx_extension(self): - return core.rt.IndexProperty_GetFileNameExtensionIdx(self.handle) + return core.rt.IndexProperty_GetFileNameExtensionIdx(self.handle).decode() def set_idx_extension(self, value): From 16f05b28dcd09d6bb1f9dfd99180e6a73898a9fc Mon Sep 17 00:00:00 2001 From: Sandeep Murthy Date: Fri, 20 Dec 2019 22:38:55 +0000 Subject: [PATCH 3/3] Further fixes in index module - remove `string_types` --- rtree/index.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/rtree/index.py b/rtree/index.py index f47deda1..db83428e 100644 --- a/rtree/index.py +++ b/rtree/index.py @@ -9,8 +9,6 @@ import sys -string_types = str - RT_Memory = 0 RT_Disk = 1 @@ -208,7 +206,7 @@ def __init__(self, *args, **kwargs): basename = None storage = None if args: - if isinstance(args[0], string_types) or isinstance(args[0], bytes): + if isinstance(args[0], str) or isinstance(args[0], bytes): # they sent in a filename basename = args[0] # they sent in a filename, stream @@ -1511,7 +1509,7 @@ def get_filename(self): def set_filename(self, value): - if isinstance(value, string_types): + if isinstance(value, str): value = value.encode('utf-8') return core.rt.IndexProperty_SetFileName(self.handle, value) @@ -1523,7 +1521,7 @@ def get_dat_extension(self): def set_dat_extension(self, value): - if isinstance(value, string_types): + if isinstance(value, str): value = value.encode('utf-8') return core.rt.IndexProperty_SetFileNameExtensionDat( self.handle, value) @@ -1536,7 +1534,7 @@ def get_idx_extension(self): def set_idx_extension(self, value): - if isinstance(value, string_types): + if isinstance(value, str): value = value.encode('utf-8') return core.rt.IndexProperty_SetFileNameExtensionIdx( self.handle, value) @@ -1846,7 +1844,7 @@ def __init__(self, *args, **kwargs): [34.37768294..., 26.73758537..., 49.37768294..., 41.73758537...] """ if args: - if isinstance(args[0], string_types) \ + if isinstance(args[0], str) \ or isinstance(args[0], bytes) \ or isinstance(args[0], ICustomStorage): raise ValueError('%s supports only in-memory indexes'