From 02f080f5d9edd3ddae0dd21ac786e56bf0d1a45c Mon Sep 17 00:00:00 2001
From: Nuwan Rajika Kumarasiri <nuwan.kumarasiri@wisc.edu>
Date: Sun, 21 Oct 2018 23:11:21 -0500
Subject: [PATCH] Add the second set of changes into `spotseeker_client` to
 port to Python 3.x

Changes includes:
* Fix syntax error `ImportError, e` as `ImportError as e`.
* `urllib.quote` -> `urllib.parse`.
* Fix `print` syntax error.
* `StringIO` -> `io import StringIO`.
---
 README.md                                        | 8 ++++++--
 spotseeker_restclient/cache_manager.py           | 2 +-
 spotseeker_restclient/dao.py                     | 2 +-
 spotseeker_restclient/dao_implementation/mock.py | 7 ++++---
 spotseeker_restclient/spotseeker.py              | 6 +++---
 5 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md
index e28bc19..248ada6 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ Install spotseeker_client as a Django module in [WiScout](https://git.doit.wisc.
 * Install spotseeker_server as an editable dependency.
   
 ```sh
-# from wiscout inside project
+# from wiscout
 $ pipenv install -e /path/to/spotseeker_client
 ```
   
@@ -29,4 +29,8 @@ INSTALLED_APPS = [
 ]
 ```
 
-### Client API
\ No newline at end of file
+### Run Unit Tests
+```py
+# from wiscout 
+$ python manage.py test spotseeker_restclient.test.spot
+```
\ No newline at end of file
diff --git a/spotseeker_restclient/cache_manager.py b/spotseeker_restclient/cache_manager.py
index 3ad87d3..cc0e515 100644
--- a/spotseeker_restclient/cache_manager.py
+++ b/spotseeker_restclient/cache_manager.py
@@ -34,7 +34,7 @@ def save_all_queued_entries():
                 entry.save()
                 seen_urls[entry.url] = True
     except Exception as ex:
-        print "Error bulk saving cache entries: ", ex
+        print ("Error bulk saving cache entries: ", ex)
 
     __bulk_insert_queue = []
 
diff --git a/spotseeker_restclient/dao.py b/spotseeker_restclient/dao.py
index 86ca2e8..c00143f 100644
--- a/spotseeker_restclient/dao.py
+++ b/spotseeker_restclient/dao.py
@@ -13,7 +13,7 @@ class DAO_BASE(object):
             module, attr = getattr(settings, settings_key).rsplit('.', 1)
             try:
                 mod = import_module(module)
-            except ImportError, e:
+            except ImportError as e:
                 raise ImproperlyConfigured('Error importing module %s: "%s"' %
                                            (module, e))
             try:
diff --git a/spotseeker_restclient/dao_implementation/mock.py b/spotseeker_restclient/dao_implementation/mock.py
index 8470c9c..86c51da 100644
--- a/spotseeker_restclient/dao_implementation/mock.py
+++ b/spotseeker_restclient/dao_implementation/mock.py
@@ -6,7 +6,8 @@ import json
 import logging
 import time
 import socket
-from urllib import quote, unquote, urlencode
+from urllib.parse import unquote
+from urllib import parse
 from django.conf import settings
 from django.core.exceptions import ImproperlyConfigured
 from importlib import import_module
@@ -31,14 +32,14 @@ def __initialize_app_resource_dirs():
     for app in settings.INSTALLED_APPS:
         try:
             mod = import_module(app)
-        except ImportError, e:
+        except ImportError as e:
             raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
 
         resource_dir = os.path.join(os.path.dirname(mod.__file__), 'resources')
         if os.path.isdir(resource_dir):
             # Cheating, to make sure our resources are overridable
             data = {
-                'path': resource_dir.decode(fs_encoding),
+                'path': resource_dir,
                 'app': app,
             }
             if app == 'restclients':
diff --git a/spotseeker_restclient/spotseeker.py b/spotseeker_restclient/spotseeker.py
index 40f583a..4dfc40c 100644
--- a/spotseeker_restclient/spotseeker.py
+++ b/spotseeker_restclient/spotseeker.py
@@ -1,4 +1,4 @@
-import StringIO
+from io import StringIO
 from spotseeker_restclient.dao import SPOTSEEKER_DAO
 from spotseeker_restclient.exceptions import DataFailureException
 from spotseeker_restclient.models.spot import Spot, SpotAvailableHours, \
@@ -8,7 +8,7 @@ import json
 from django.utils.dateparse import parse_datetime, parse_time
 from django.core.exceptions import ImproperlyConfigured
 from django.conf import settings
-from urllib import urlencode
+import urllib
 import requests
 from requests_oauthlib import OAuth1
 
@@ -197,7 +197,7 @@ class Spotseeker(object):
         """
 
         dao = SPOTSEEKER_DAO()
-        url = "/api/v1/spot?" + urlencode(query_tuple)
+        url = "/api/v1/spot?" + urllib.parse.urlencode(query_tuple)
 
         if isinstance(dao._getDAO(), File):
             resp = dao.getURL(url, {})
-- 
GitLab