Skip to content

Commit 7737088

Browse files
authored
Merge pull request #3598 from cclauss/docker_hack
Fix absolute import and bytes for Python 3
2 parents 85243b4 + b3541fd commit 7737088

File tree

8 files changed

+22
-16
lines changed

8 files changed

+22
-16
lines changed

openlibrary/catalog/utils/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def query(q):
7070
for i in range(20):
7171
try:
7272
ret = urlread(url)
73-
while ret.startswith('canceling statement due to statement timeout'):
73+
while ret.startswith(b'canceling statement due to statement timeout'):
7474
ret = urlread(url)
7575
if not ret:
7676
print('ret == None')

openlibrary/core/ia.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
logger = logging.getLogger('openlibrary.ia')
1818

19-
IA_BASE_URL = config.get('ia_base_url')
19+
# FIXME: We can't reference `config` in module scope like this; it will always be undefined!
20+
# See lending.py for an example of how to do it correctly.
21+
IA_BASE_URL = config.get('ia_base_url', 'https://archive.org')
2022
VALID_READY_REPUB_STATES = ['4', '19', '20', '22']
2123

2224

openlibrary/core/middleware.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""WSGI middleware used in Open Library.
22
"""
33
import web
4-
from six import StringIO
4+
from six import BytesIO
55
import gzip
66

77
class GZipMiddleware:
@@ -23,7 +23,7 @@ def get_response_header(name, default=None):
2323
return default
2424

2525
def compress(text, level=9):
26-
f = StringIO()
26+
f = BytesIO()
2727
gz = gzip.GzipFile(None, 'wb', level, fileobj=f)
2828
gz.write(text)
2929
gz.close()
@@ -41,6 +41,6 @@ def new_start_response(status, headers):
4141

4242
data = self.app(environ, new_start_response)
4343
if response.compress:
44-
return [compress("".join(data), 9)]
44+
return [compress(b"".join(data), 9)]
4545
else:
4646
return data

openlibrary/plugins/upstream/code.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
"""Upstream customizations."""
22

3+
import datetime
4+
import hashlib
5+
import io
36
import os.path
4-
import web
57
import random
6-
import hashlib
7-
import datetime
8+
9+
from six import PY3
10+
11+
import web
812

913
from infogami import config
1014
from infogami.infobase import client
1115
from infogami.utils import delegate, app, types
1216
from infogami.utils.view import public, safeint, render
17+
from infogami.utils.view import render_template # noqa: F401 used for its side effects
1318
from infogami.utils.context import context
1419

15-
from utils import render_template # noqa: F401 render_template used for side effects
16-
1720
from openlibrary import accounts
1821

1922
from openlibrary.plugins.upstream import addbook, covers, merge_authors, models, utils
@@ -68,7 +71,8 @@ def static_url(path):
6871
"""
6972
pardir = os.path.pardir
7073
fullpath = os.path.abspath(os.path.join(__file__, pardir, pardir, pardir, pardir, "static", path))
71-
digest = hashlib.md5(open(fullpath).read()).hexdigest()
74+
with io.open(fullpath, 'rb') as in_file:
75+
digest = hashlib.md5(in_file.read()).hexdigest()
7276
return "/static/%s?v=%s" % (path, digest)
7377

7478
class DynamicDocument:

openlibrary/plugins/upstream/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def get_donation_include(include):
713713
html = ''
714714
if include == 'true' and "dev" in web.ctx.features:
715715
try:
716-
html += opener.open(url_banner_source + param, timeout=3).read()
716+
html += opener.open(url_banner_source + param, timeout=3).read().decode("utf-8")
717717
# Donation banner is temporarily (Jan 2020) disabled on prod, but available on dev (so that it can be used
718718
# for testing). To avoid it appearing like it's working, display a warning if it loads correctly that it's
719719
# disabled on prod.

openlibrary/plugins/worksearch/subjects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
from openlibrary.core.models import Subject
1818
from openlibrary.core.lending import add_availability
19+
from openlibrary.plugins.worksearch.search import work_search
1920
from openlibrary.utils import str_to_key, finddict
2021

22+
2123
__all__ = [
2224
"SubjectEngine", "get_subject"
2325
]
@@ -219,7 +221,6 @@ def get_subject(self, key, details=False, offset=0, limit=DEFAULT_RESULTS, sort=
219221
else:
220222
kw = {}
221223

222-
from search import work_search
223224
result = work_search(
224225
q, offset=offset, limit=limit, sort=sort, **kw)
225226
if not result:

openlibrary/solr/solrwriter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Interface to update solr.
22
"""
3-
import httplib
43
import logging
54
import re
65

@@ -28,7 +27,7 @@ def __init__(self, host, core=None):
2827

2928
def get_conn(self):
3029
if self.conn is None:
31-
self.conn = httplib.HTTPConnection(self.host)
30+
self.conn = six.moves.http_client.HTTPConnection(self.host)
3231
return self.conn
3332

3433
def request(self, xml):

scripts/new-solr-updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def update_keys(keys):
175175
logger.debug("Args: %s" % str(args))
176176
update_work.load_configs(args.ol_url, args.config, 'default')
177177

178-
keys = (k for k in keys if k.count("/") == 2 and k.split("/")[1] in ["books", "authors", "works"])
178+
keys = [k for k in keys if k.count("/") == 2 and k.split("/")[1] in ("books", "authors", "works")]
179179

180180
count = 0
181181
for chunk in web.group(keys, 100):

0 commit comments

Comments
 (0)