From 64483c4488c9184705ef08ae59e994a0d706cec1 Mon Sep 17 00:00:00 2001 From: alessandro ceglie Date: Thu, 16 Feb 2023 22:40:12 +0100 Subject: [PATCH 1/4] Python3 fixes --- collective/embedly/browser/controlpanel.py | 9 ++++----- collective/embedly/setuphandlers.py | 4 ++-- collective/embedly/transform.py | 16 ++++++++-------- docs/HISTORY.rst | 2 ++ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/collective/embedly/browser/controlpanel.py b/collective/embedly/browser/controlpanel.py index 3f532f6..6d00d06 100644 --- a/collective/embedly/browser/controlpanel.py +++ b/collective/embedly/browser/controlpanel.py @@ -1,5 +1,5 @@ -from zope.interface import implements -from zope.component import adapts +from zope.interface import implementer +from zope.component import adapter from zope.component import getUtility from zope.formlib import form @@ -13,11 +13,10 @@ from collective.embedly.interfaces import IEmbedlySettings +@implementer(IEmbedlySettings) +@adapter(IPloneSiteRoot) class EmbedlyControlPanelAdapter(SchemaAdapterBase): - adapts(IPloneSiteRoot) - implements(IEmbedlySettings) - def __init__(self, context): super(EmbedlyControlPanelAdapter, self).__init__(context) registry = getUtility(IRegistry) diff --git a/collective/embedly/setuphandlers.py b/collective/embedly/setuphandlers.py index f2d49cb..3d53cf5 100644 --- a/collective/embedly/setuphandlers.py +++ b/collective/embedly/setuphandlers.py @@ -1,4 +1,4 @@ -from zope.interface import implements +from zope.interface import implementer from Products.CMFCore.utils import getToolByName from Products.CMFPlone.interfaces import INonInstallable from zope.component import getUtility @@ -16,8 +16,8 @@ }) +#implementer(INonInstallable) class HiddenProfiles(object): - implements(INonInstallable) def getNonInstallableProfiles(self): """ diff --git a/collective/embedly/transform.py b/collective/embedly/transform.py index bc1abae..b9ede1f 100644 --- a/collective/embedly/transform.py +++ b/collective/embedly/transform.py @@ -1,17 +1,17 @@ -import urllib2 +import urllib import json import re import logging from Products.CMFCore.utils import getToolByName from Products.CMFPlone.utils import safe_unicode from Products.PortalTransforms.interfaces import ITransform -from zope.interface import implements +from zope.interface import implementer from zope.component import getUtility, queryUtility from plone.registry.interfaces import IRegistry from plone.memoize import ram from plone.memoize.interfaces import ICacheChooser from time import time -from urlparse import urlparse, parse_qsl +from urllib.parse import urlparse, parse_qsl try: from zope.app.component.hooks import getSite except ImportError: @@ -48,7 +48,7 @@ def clear_cache(): def update_services(): - resp = urllib2.urlopen('http://api.embed.ly/1/services/python') + resp = urllib.request.urlopen('http://api.embed.ly/1/services/python') if resp.getcode() == 200: list_exp = [] for service in json.loads(resp.read()): @@ -152,12 +152,12 @@ def get_oembed(url, api_key=None, doc=None): if embedly_query: embedly_query = '&' + embedly_query fetch_url = 'http://api.embed.ly/1/oembed?%surl=%s%s&format=json' % \ - (api_key_string, urllib2.quote(curl.encode('utf-8')), embedly_query) + (api_key_string, urllib.parse.quote(curl.encode('utf-8')), embedly_query) logger.debug("HREF:%s URL:%s" % (url, fetch_url)) try: - result = urllib2.urlopen(fetch_url).read() + result = urllib.request.urlopen(fetch_url).read() logger.debug("Response: %s" % result) - except urllib2.HTTPError, e: + except urllib.HTTPError as e: if doc: logger.error("Unexpected response from embedly API (%d: %s) while processing %s in %s" % (e.code, e.msg, url, doc)) else: @@ -202,8 +202,8 @@ def replace(matchobj): return link_url_re.sub(replace, text) +@implementer(ITransform) class EmbedlyTransform: - implements(ITransform) __name__ = "embedly_transform" diff --git a/docs/HISTORY.rst b/docs/HISTORY.rst index 2c4ff00..e1ac732 100644 --- a/docs/HISTORY.rst +++ b/docs/HISTORY.rst @@ -3,6 +3,8 @@ Changelog dev --- +- Py3 compatibility + [sauzher] - Don't attempt to decode unicode strings in transform. [alecm] From 8c278c83935da3904cdb41e242fcc44982054764 Mon Sep 17 00:00:00 2001 From: Alessandro Ceglie Date: Mon, 20 Feb 2023 11:00:21 +0100 Subject: [PATCH 2/4] typo --- collective/embedly/setuphandlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collective/embedly/setuphandlers.py b/collective/embedly/setuphandlers.py index 3d53cf5..653878c 100644 --- a/collective/embedly/setuphandlers.py +++ b/collective/embedly/setuphandlers.py @@ -16,7 +16,7 @@ }) -#implementer(INonInstallable) +@implementer(INonInstallable) class HiddenProfiles(object): def getNonInstallableProfiles(self): From c8f3f1051662b84127b2719328492018483efa58 Mon Sep 17 00:00:00 2001 From: "alessandro.ceglie" Date: Mon, 20 Feb 2023 12:05:00 +0100 Subject: [PATCH 3/4] backward compatibility for Py2 refactoring Controlpanel with p.a.registry RegistryEditForm wrapper (z3c.form) --- collective/embedly/browser/configure.zcml | 4 -- collective/embedly/browser/controlpanel.py | 71 ++++------------------ collective/embedly/tests/patch.py | 24 +++++--- collective/embedly/tests/tests.py | 8 ++- collective/embedly/transform.py | 17 ++++-- 5 files changed, 44 insertions(+), 80 deletions(-) diff --git a/collective/embedly/browser/configure.zcml b/collective/embedly/browser/configure.zcml index e0eb8de..8b27360 100644 --- a/collective/embedly/browser/configure.zcml +++ b/collective/embedly/browser/configure.zcml @@ -4,9 +4,6 @@ xmlns:zcml="http://namespaces.zope.org/zcml" i18n_domain="collective.embedly"> - - Date: Mon, 20 Feb 2023 13:43:20 +0100 Subject: [PATCH 4/4] typo --- collective/embedly/tests/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collective/embedly/tests/tests.py b/collective/embedly/tests/tests.py index 7a2bad3..bdbb23e 100644 --- a/collective/embedly/tests/tests.py +++ b/collective/embedly/tests/tests.py @@ -26,7 +26,7 @@ try: from urllib.request import urlopen except ImportError: - from urllib import urlopen + from urllib2 import urlopen embedly_filter = lambda i: i['path'] == 'collective.embedly.transform.get_oembed'