From 998a1e2aeaea0c5361e526365d1e94d7eaa9d4e8 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Sun, 17 Mar 2019 21:34:36 +0100 Subject: [PATCH] More Py3 compatibility fixes. --- src/contact/mailing.py | 4 +--- src/lesmianator/models.py | 4 ++-- src/opds/views.py | 2 +- src/search/custom.py | 2 +- src/search/index.py | 6 +++--- src/stats/utils.py | 5 ++--- src/wolnelektury/templates/widget.html | 2 +- 7 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/contact/mailing.py b/src/contact/mailing.py index 2d578e66d..baacf3def 100644 --- a/src/contact/mailing.py +++ b/src/contact/mailing.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from hashlib import md5 from django.conf import settings @@ -8,7 +6,7 @@ from mailchimp3.mailchimpclient import MailChimpError def subscriber_hash(email): - return md5(email).hexdigest() + return md5(email.encode('utf-8')).hexdigest() def remove_from_groups(email, client): diff --git a/src/lesmianator/models.py b/src/lesmianator/models.py index 0a4c0591b..47b431542 100644 --- a/src/lesmianator/models.py +++ b/src/lesmianator/models.py @@ -1,7 +1,7 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from functools import reduce import pickle from pickle import PickleError from datetime import datetime @@ -155,7 +155,7 @@ class Continuations(models.Model): obj = cls.objects.get(content_type=object_type, object_id=sth.id) if not obj.pickle: raise cls.DoesNotExist - f = open(obj.pickle.path) + f = open(obj.pickle.path, 'rb') keys, conts = pickle.load(f) f.close() if set(keys) != should_keys: diff --git a/src/opds/views.py b/src/opds/views.py index 1afbcda3e..f14696bba 100644 --- a/src/opds/views.py +++ b/src/opds/views.py @@ -1,7 +1,7 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from functools import reduce import os.path from urllib.parse import urljoin diff --git a/src/search/custom.py b/src/search/custom.py index 8f7b893b5..933715719 100644 --- a/src/search/custom.py +++ b/src/search/custom.py @@ -23,7 +23,7 @@ class CustomSolrConnection(connection.SolrConnection): url = self.analysis_url kwargs = dict( method="POST", - body=qs, + data=qs, headers={"Content-Type": "application/x-www-form-urlencoded"}, ) else: diff --git a/src/search/index.py b/src/search/index.py index a712b0702..712089396 100644 --- a/src/search/index.py +++ b/src/search/index.py @@ -1,7 +1,7 @@ # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from functools import total_ordering +from functools import reduce, total_ordering from itertools import chain import logging import operator @@ -713,12 +713,12 @@ class SearchResult(object): break def theme_by_name(n): - th = filter(lambda t: t.name == n, themes) + th = list(filter(lambda t: t.name == n, themes)) if th: return th[0] else: return None - themes_hit = filter(lambda a: a is not None, map(theme_by_name, themes_hit)) + themes_hit = list(filter(lambda a: a is not None, map(theme_by_name, themes_hit))) m = {'score': f[self.SCORE], 'fragment': frag, diff --git a/src/stats/utils.py b/src/stats/utils.py index eba720224..d21eb3c3c 100644 --- a/src/stats/utils.py +++ b/src/stats/utils.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -6,7 +5,7 @@ from django.conf import settings from datetime import datetime import logging from functools import update_wrapper -import urllib +from urllib.parse import urlencode from random import random from inspect import isclass @@ -18,7 +17,7 @@ logger = logging.getLogger(__name__) def piwik_url(request): - return urllib.urlencode(dict( + return urlencode(dict( idsite=getattr(settings, 'PIWIK_SITE_ID', '0'), rec=1, url=force_bytes('http://%s%s' % (request.META['HTTP_HOST'], request.path)), diff --git a/src/wolnelektury/templates/widget.html b/src/wolnelektury/templates/widget.html index 1103641f6..de79b5632 100644 --- a/src/wolnelektury/templates/widget.html +++ b/src/wolnelektury/templates/widget.html @@ -15,7 +15,7 @@ -
+ -- 2.20.1