Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Python 2 support (changes in rtree/index.py module) #137

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions rtree/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,11 @@

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


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
RT_Custom = 2
Expand Down Expand Up @@ -220,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
Expand Down Expand Up @@ -1519,23 +1505,23 @@ 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).decode()


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)

filename = property(get_filename, set_filename)
"""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).decode()


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)
Expand All @@ -1544,11 +1530,11 @@ 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).decode()


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)
Expand Down Expand Up @@ -1858,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'
Expand Down