Skip to content
Snippets Groups Projects
Commit 02f080f5 authored by Nuwan Rajika Kumarasiri's avatar Nuwan Rajika Kumarasiri
Browse files

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`.
parent 96fb729c
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ Install spotseeker_client as a Django module in [WiScout](https://git.doit.wisc. ...@@ -14,7 +14,7 @@ Install spotseeker_client as a Django module in [WiScout](https://git.doit.wisc.
* Install spotseeker_server as an editable dependency. * Install spotseeker_server as an editable dependency.
```sh ```sh
# from wiscout inside project # from wiscout
$ pipenv install -e /path/to/spotseeker_client $ pipenv install -e /path/to/spotseeker_client
``` ```
...@@ -29,4 +29,8 @@ INSTALLED_APPS = [ ...@@ -29,4 +29,8 @@ INSTALLED_APPS = [
] ]
``` ```
### Client API ### Run Unit Tests
\ No newline at end of file ```py
# from wiscout
$ python manage.py test spotseeker_restclient.test.spot
```
\ No newline at end of file
...@@ -34,7 +34,7 @@ def save_all_queued_entries(): ...@@ -34,7 +34,7 @@ def save_all_queued_entries():
entry.save() entry.save()
seen_urls[entry.url] = True seen_urls[entry.url] = True
except Exception as ex: except Exception as ex:
print "Error bulk saving cache entries: ", ex print ("Error bulk saving cache entries: ", ex)
__bulk_insert_queue = [] __bulk_insert_queue = []
......
...@@ -13,7 +13,7 @@ class DAO_BASE(object): ...@@ -13,7 +13,7 @@ class DAO_BASE(object):
module, attr = getattr(settings, settings_key).rsplit('.', 1) module, attr = getattr(settings, settings_key).rsplit('.', 1)
try: try:
mod = import_module(module) mod = import_module(module)
except ImportError, e: except ImportError as e:
raise ImproperlyConfigured('Error importing module %s: "%s"' % raise ImproperlyConfigured('Error importing module %s: "%s"' %
(module, e)) (module, e))
try: try:
......
...@@ -6,7 +6,8 @@ import json ...@@ -6,7 +6,8 @@ import json
import logging import logging
import time import time
import socket import socket
from urllib import quote, unquote, urlencode from urllib.parse import unquote
from urllib import parse
from django.conf import settings from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from importlib import import_module from importlib import import_module
...@@ -31,14 +32,14 @@ def __initialize_app_resource_dirs(): ...@@ -31,14 +32,14 @@ def __initialize_app_resource_dirs():
for app in settings.INSTALLED_APPS: for app in settings.INSTALLED_APPS:
try: try:
mod = import_module(app) mod = import_module(app)
except ImportError, e: except ImportError as e:
raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0])) raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
resource_dir = os.path.join(os.path.dirname(mod.__file__), 'resources') resource_dir = os.path.join(os.path.dirname(mod.__file__), 'resources')
if os.path.isdir(resource_dir): if os.path.isdir(resource_dir):
# Cheating, to make sure our resources are overridable # Cheating, to make sure our resources are overridable
data = { data = {
'path': resource_dir.decode(fs_encoding), 'path': resource_dir,
'app': app, 'app': app,
} }
if app == 'restclients': if app == 'restclients':
......
import StringIO from io import StringIO
from spotseeker_restclient.dao import SPOTSEEKER_DAO from spotseeker_restclient.dao import SPOTSEEKER_DAO
from spotseeker_restclient.exceptions import DataFailureException from spotseeker_restclient.exceptions import DataFailureException
from spotseeker_restclient.models.spot import Spot, SpotAvailableHours, \ from spotseeker_restclient.models.spot import Spot, SpotAvailableHours, \
...@@ -8,7 +8,7 @@ import json ...@@ -8,7 +8,7 @@ import json
from django.utils.dateparse import parse_datetime, parse_time from django.utils.dateparse import parse_datetime, parse_time
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.conf import settings from django.conf import settings
from urllib import urlencode import urllib
import requests import requests
from requests_oauthlib import OAuth1 from requests_oauthlib import OAuth1
...@@ -197,7 +197,7 @@ class Spotseeker(object): ...@@ -197,7 +197,7 @@ class Spotseeker(object):
""" """
dao = SPOTSEEKER_DAO() dao = SPOTSEEKER_DAO()
url = "/api/v1/spot?" + urlencode(query_tuple) url = "/api/v1/spot?" + urllib.parse.urlencode(query_tuple)
if isinstance(dao._getDAO(), File): if isinstance(dao._getDAO(), File):
resp = dao.getURL(url, {}) resp = dao.getURL(url, {})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment