From 23878f4ec2e009bb6336218f15cc054d30d3b1e7 Mon Sep 17 00:00:00 2001 From: MmAaXx500 Date: Thu, 26 Dec 2019 15:01:18 +0100 Subject: [PATCH 1/3] Replace deprecated basestring with str (Py3) --- src/aliceVision/sensorDB/sensorDatabaseSort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aliceVision/sensorDB/sensorDatabaseSort.py b/src/aliceVision/sensorDB/sensorDatabaseSort.py index 6b2f1e54e1..147947d654 100644 --- a/src/aliceVision/sensorDB/sensorDatabaseSort.py +++ b/src/aliceVision/sensorDB/sensorDatabaseSort.py @@ -24,7 +24,7 @@ # process sensors = [entry.split(';') for entry in database] -sensors.sort(key=lambda t : tuple(s.lower() if isinstance(s,basestring) else s for s in t)) +sensors.sort(key=lambda t : tuple(s.lower() if isinstance(s,str) else s for s in t)) outDatabase = "" for entry in sensors: outDatabase += ';'.join(entry) From af691ad5ca2d5e6f29f59ef3913bc3c576730023 Mon Sep 17 00:00:00 2001 From: MmAaXx500 Date: Thu, 2 Apr 2020 14:29:00 +0200 Subject: [PATCH 2/3] Replace str with (str, bytes) For full compatibility with py2 basestring. --- src/aliceVision/sensorDB/sensorDatabaseSort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aliceVision/sensorDB/sensorDatabaseSort.py b/src/aliceVision/sensorDB/sensorDatabaseSort.py index 147947d654..2e6ef4bad3 100644 --- a/src/aliceVision/sensorDB/sensorDatabaseSort.py +++ b/src/aliceVision/sensorDB/sensorDatabaseSort.py @@ -24,7 +24,7 @@ # process sensors = [entry.split(';') for entry in database] -sensors.sort(key=lambda t : tuple(s.lower() if isinstance(s,str) else s for s in t)) +sensors.sort(key=lambda t : tuple(s.lower() if isinstance(s, (str, bytes)) else s for s in t)) outDatabase = "" for entry in sensors: outDatabase += ';'.join(entry) From b99c46aecf5ea9bbbc4573948e9b7d04a9dfed74 Mon Sep 17 00:00:00 2001 From: MmAaXx500 Date: Thu, 2 Apr 2020 17:02:27 +0200 Subject: [PATCH 3/3] Maintain compatibility with Py2 and Py3 --- src/aliceVision/sensorDB/sensorDatabaseSort.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/aliceVision/sensorDB/sensorDatabaseSort.py b/src/aliceVision/sensorDB/sensorDatabaseSort.py index 2e6ef4bad3..941e13749a 100644 --- a/src/aliceVision/sensorDB/sensorDatabaseSort.py +++ b/src/aliceVision/sensorDB/sensorDatabaseSort.py @@ -8,6 +8,12 @@ import argparse +try: + _ = basestring +except NameError: + # 'basestring' is undefined, so it must be Python 3 + basestring = (str, bytes) + # command line parser = argparse.ArgumentParser(description='Sort sensor width camera database by the brand / model name') parser.add_argument('-i', '--input', metavar='inputSensorDatabase.txt', required=True, type=str, @@ -24,7 +30,7 @@ # process sensors = [entry.split(';') for entry in database] -sensors.sort(key=lambda t : tuple(s.lower() if isinstance(s, (str, bytes)) else s for s in t)) +sensors.sort(key=lambda t : tuple(s.lower() if isinstance(s, basestring) else s for s in t)) outDatabase = "" for entry in sensors: outDatabase += ';'.join(entry)