Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Merge branch 'feature/py3' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ja573 committed Aug 12, 2019
2 parents 4e784f4 + 385b08a commit c2a93d1
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python:
- "2.7"
- "3.5"
install:
- pip install -r ./config/requirements.txt
script:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:2
FROM python:3.5

WORKDIR /usr/src/app

Expand Down
2 changes: 1 addition & 1 deletion config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ PyJWT==1.6.1
psycopg2-binary==2.7.5
uri==2.0.0
urllib3==1.24.2
web.py==0.39
web.py==0.40-dev1
2 changes: 1 addition & 1 deletion src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def build_parms(filters):
raise Error(BADFILTERS, msg="Unknown filter '%s'" % (p))

process = {"work_type": types, "uri_scheme": schemes, "canonical": canoncl}
for key, values in process.items():
for key, values in list(process.items()):
if len(values) > 0:
try:
andclause, ops = build_clause(key, values)
Expand Down
4 changes: 2 additions & 2 deletions src/aux.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def logger_instance(name):


def strtolist(data):
if isinstance(data, basestring) or isinstance(data, dict):
if isinstance(data, str) or isinstance(data, dict):
return [data]
elif type(data) is list:
elif isinstance(data, list):
return data
5 changes: 4 additions & 1 deletion src/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def __init__(self, level=DEFAULT, msg='', data=[]):
httpcode = self.get_code(level)
headers = {'Content-Type': 'application/json'}
message = self.get_message(level)
params = web.input() if web.input() else web.data()
if web.ctx.env.get('REQUEST_METHOD', '') == 'GET':
params = web.input()
else:
params = web.data().decode('utf-8')
output = json.dumps(
self.make_output(httpcode, message, msg, params, data))

Expand Down
31 changes: 17 additions & 14 deletions src/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import web
import uuid
import psycopg2
from aux import logger_instance
from aux import logger_instance, debug_mode
from api import db
from uri import URI
from errors import Error, FATAL

logger = logger_instance(__name__)
web.config.debug = debug_mode()


class Work(object):
Expand Down Expand Up @@ -421,10 +423,8 @@ def results_to_works(results, include_relatives=False):
titles = [] # temporary array of work titles
uris = [] # temp array of work URIs (strings, used for comparison)
uris_fmt = [] # temporary array of work URIs (Identifier objects)
last = len(results) - 1

i = 0
for e in results:
for i, e in enumerate(results):
if i == 0:
# we can't do cur=results[0] outsise--it moves IterBetter's pointer
cur = e
Expand All @@ -449,14 +449,17 @@ def results_to_works(results, include_relatives=False):
uris_fmt.append({"uri_scheme": e["uri_scheme"],
"uri_value": e["uri_value"],
"canonical": e["canonical"]})
if i == last:
cur["titles"] = titles
cur["URI"] = uris_fmt
work = result_to_work(cur)
work.URI = results_to_identifiers(cur["URI"])
if include_relatives:
work.load_children()
work.load_parents()
data.append(work.__dict__)
i += 1
try:
cur["titles"] = titles
cur["URI"] = uris_fmt
work = result_to_work(cur)
work.URI = results_to_identifiers(cur["URI"])
if include_relatives:
work.load_children()
work.load_parents()
data.append(work.__dict__)
except NameError:
# we need to run the above with the last element of IterBetter, if it
# fails it means that no results were iterated
pass
return data
4 changes: 2 additions & 2 deletions src/relationsctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def GET(self, name):
@check_token
def POST(self, name):
"""Create a work relation"""
logger.debug("Data: %s" % (web.data()))
logger.debug("Data: %s" % (web.data().decode('utf-8')))

data = json.loads(web.data())
data = json.loads(web.data().decode('utf-8'))
parent_uuid = data.get('parent_UUID') or data.get('parent_uuid')
child_uuid = data.get('child_UUID') or data.get('child_uuid')

Expand Down
4 changes: 2 additions & 2 deletions src/titlesctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def GET(self, name):
@check_token
def POST(self, name):
"""Add titles to an existing work"""
logger.debug("Data: %s" % (web.data()))
logger.debug("Data: %s" % (web.data().decode('utf-8')))

data = json.loads(web.data())
data = json.loads(web.data().decode('utf-8'))
title = data.get('title')
work_id = data.get('UUID') or data.get('uuid')

Expand Down
8 changes: 5 additions & 3 deletions src/translator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import web
import urllib
import urllib.parse
import urllib.error
import urllib.request
from aux import logger_instance, debug_mode
from api import build_parms, json_response, api_response, check_token
from errors import Error, BADPARAMS, NORESULT, NOTALLOWED, \
Expand Down Expand Up @@ -41,7 +43,7 @@ def GET(self, name):
scheme, value = Identifier.split_uri(uri)
assert scheme and value
if title:
title = urllib.unquote(title.strip())
title = urllib.parse.unquote(title.strip())
assert title
assert uri or title
except BaseException:
Expand All @@ -60,7 +62,7 @@ def GET(self, name):
if not results:
raise Error(NORESULT)

return self.process_results(results, strict)
return self.process_results(list(results), strict)

def POST(self, name):
raise Error(NOTALLOWED)
Expand Down
4 changes: 2 additions & 2 deletions src/urisctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def GET(self, name):
@check_token
def POST(self, name):
"""Add identifiers to an existing work"""
logger.debug("Data: %s" % (web.data()))
logger.debug("Data: %s" % (web.data().decode('utf-8')))

data = json.loads(web.data())
data = json.loads(web.data().decode('utf-8'))
uri = data.get('URI') or data.get('uri')
canonical = data.get('canonical') in (True, "true", "True")
work_id = data.get('UUID') or data.get('uuid')
Expand Down
6 changes: 3 additions & 3 deletions src/worksctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def GET(self, name):
@check_token
def POST(self, name):
"""Create a work"""
logger.debug("Data: %s" % (web.data()))
logger.debug("Data: %s" % (web.data().decode('utf-8')))

data = json.loads(web.data())
data = json.loads(web.data().decode('utf-8'))
wtype = data.get('type')
title = data.get('title')
uri = data.get('URI') or data.get('uri')
Expand All @@ -78,7 +78,7 @@ def POST(self, name):
try:
assert WorkType(wtype).exists()
except AssertionError:
t = wtype if type(wtype) == str else ""
t = wtype if isinstance(wtype, str) else ""
raise Error(BADPARAMS, msg="Unknown work type '%s'" % (t))

for i in uris:
Expand Down

0 comments on commit c2a93d1

Please sign in to comment.