Skip to content

Commit 70e99e9

Browse files
Update deprecated imports for Plone 6.0 and higher.
1 parent 163955e commit 70e99e9

11 files changed

Lines changed: 31 additions & 49 deletions

File tree

CHANGES.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Changelog
55
4.5.1 (unreleased)
66
------------------
77

8-
- Nothing changed yet.
8+
- Update deprecated imports for Plone 6.0 and higher. [maurits]
99

1010

1111
4.5.0 (2026-01-12)

src/collective/easyform/actions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from plone.registry.interfaces import IRegistry
4646
from plone.supermodel.exportimport import BaseHandler
4747
from Products.CMFCore.utils import getToolByName
48-
from Products.CMFPlone.utils import safe_unicode
48+
from plone.base.utils import safe_text
4949
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
5050
from Products.PythonScripts.PythonScript import PythonScript
5151
from six import BytesIO
@@ -122,8 +122,8 @@ def serialize(self, field):
122122
if isinstance(field, (int, float, Decimal, bool)):
123123
return str(field)
124124
if isinstance(field, six.string_types):
125-
return safe_unicode(field)
126-
return safe_unicode(repr(field))
125+
return safe_text(field)
126+
return safe_text(repr(field))
127127

128128
def onSuccess(self, fields, request):
129129
raise NotImplementedError(
@@ -291,9 +291,9 @@ def get_subject(self, fields, request, context):
291291
subject = dollar_replacer(subject, fields)
292292

293293
if isinstance(subject, six.string_types):
294-
subject = safe_unicode(subject)
294+
subject = safe_text(subject)
295295
elif subject and isinstance(subject, (set, tuple, list)):
296-
subject = ", ".join([safe_unicode(s) for s in subject])
296+
subject = ", ".join([safe_text(s) for s in subject])
297297
else:
298298
subject = nosubject
299299

@@ -489,7 +489,7 @@ def get_mail_text(self, fields, request, context):
489489
getattr(self, "gpg_keyid", False) and "plain" or self.body_type or "html"
490490
)
491491
mime_text = MIMEText(
492-
safe_unicode(body).encode(email_charset, "replace"),
492+
safe_text(body).encode(email_charset, "replace"),
493493
_subtype=subtype,
494494
_charset=email_charset,
495495
)

src/collective/easyform/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from plone.supermodel.parser import SupermodelParseError
1414
from Products.CMFCore.Expression import Expression
1515
from Products.CMFCore.Expression import getExprContext
16-
from Products.CMFPlone.utils import safe_unicode
16+
from plone.base.utils import safe_text
1717
from re import compile
1818
from zope.schema import getFieldsInOrder
1919

@@ -243,12 +243,12 @@ def cleanup(value):
243243
and returns a list of native strings.
244244
"""
245245
if isinstance(value, six.string_types):
246-
value = safe_unicode(value).strip()
246+
value = safe_text(value).strip()
247247
value = value.replace(u",", u"\n").replace(u";", u"\n")
248248
value = [s for s in value.splitlines()]
249249

250250
if isinstance(value, (list, tuple)):
251-
value = [safe_unicode(s).strip() for s in value]
251+
value = [safe_text(s).strip() for s in value]
252252

253253
if six.PY2:
254254
# py2 expects a list of bytes

src/collective/easyform/browser/fields.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from plone.schemaeditor.browser.schema.listing import SchemaListingPage
1717
from plone.schemaeditor.browser.schema.traversal import SchemaContext
1818
from plone.supermodel.parser import SupermodelParseError
19-
from Products.CMFPlone.utils import safe_bytes
19+
from plone.base.utils import safe_bytes
2020
from Products.Five import BrowserView
2121
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
2222
from z3c.form import button
@@ -26,7 +26,7 @@
2626
from zope.interface import implementer
2727
from ZPublisher.BaseRequest import DefaultPublishTraverse
2828
from Products.statusmessages.interfaces import IStatusMessage
29-
from Products.CMFPlone.utils import safe_unicode
29+
from plone.base.utils import safe_text
3030

3131
import html
3232

@@ -176,7 +176,7 @@ def __call__(self):
176176
root = etree.fromstring(source, parser=parser)
177177
except etree.XMLSyntaxError as e:
178178
IStatusMessage(self.request).addStatusMessage(
179-
"XMLSyntaxError: {0}".format(html.escape(safe_unicode(e.args[0]))),
179+
"XMLSyntaxError: {0}".format(html.escape(safe_text(e.args[0]))),
180180
"error",
181181
)
182182
return super().__call__()

src/collective/easyform/browser/view.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from os.path import splitext
2222
from plone.app.z3cform.inline_validation import InlineValidationView
2323
from plone.autoform.form import AutoExtensibleForm
24+
from plone.base.utils import safe_bytes
2425
from plone.namedfile.interfaces import INamed
2526
from plone.z3cform.layout import FormWrapper
2627
from Products.Five import BrowserView
@@ -44,18 +45,6 @@
4445
logger = getLogger("collective.easyform")
4546
PMF = MessageFactory("plone")
4647

47-
try:
48-
from Products.CMFPlone.utils import safe_encode
49-
except ImportError:
50-
# only thing needed to maintain 5.0.x compatibility
51-
def safe_bytes(value, encoding="utf-8"):
52-
"""Convert text to bytes of the specified encoding."""
53-
if isinstance(value, six.text_type):
54-
value = value.encode(encoding)
55-
return value
56-
57-
safe_encode = safe_bytes
58-
5948

6049
@implementer(IEasyFormForm)
6150
class EasyFormForm(AutoExtensibleForm, form.Form):
@@ -218,7 +207,7 @@ def handleSubmit(self, action):
218207
if thanksPageOverrideAction == "traverse_to":
219208
thanksPage = self.context.restrictedTraverse(thanksPage)
220209
thanksPage = mapply(thanksPage, self.request.args, self.request)
221-
self.request.response.write(safe_encode(thanksPage))
210+
self.request.response.write(safe_bytes(thanksPage))
222211

223212
@button.buttonAndHandler(
224213
_(u"Reset"), name="reset", condition=lambda form: form.context.useCancelButton

src/collective/easyform/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
from Products.CMFPlone.utils import safe_unicode
2+
from plone.base.utils import safe_text
33

44
import os
55
import pkg_resources
@@ -26,22 +26,22 @@
2626
with open(
2727
os.path.join(this_path, "default_schemata", "model_default.xml")
2828
) as fp: # noqa
29-
MODEL_DEFAULT = safe_unicode(fp.read())
29+
MODEL_DEFAULT = safe_text(fp.read())
3030

3131
with open(
3232
os.path.join(this_path, "default_schemata", "fields_default.xml")
3333
) as fp: # noqa
34-
FIELDS_DEFAULT = safe_unicode(fp.read())
34+
FIELDS_DEFAULT = safe_text(fp.read())
3535

3636
with open(
3737
os.path.join(this_path, "default_schemata", "actions_default.xml")
3838
) as fp: # noqa
39-
ACTIONS_DEFAULT = safe_unicode(fp.read())
39+
ACTIONS_DEFAULT = safe_text(fp.read())
4040

4141
with open(
4242
os.path.join(this_path, "default_schemata", "mail_body_default.pt")
4343
) as fp: # noqa
44-
MAIL_BODY_DEFAULT = safe_unicode(fp.read())
44+
MAIL_BODY_DEFAULT = safe_text(fp.read())
4545

4646

4747
FORM_ERROR_MARKER = "FORM_ERROR_MARKER"

src/collective/easyform/interfaces/easyform.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from plone.autoform import directives
88
from plone.supermodel.directives import fieldset
99
from plone.supermodel.model import Schema
10-
from Products.CMFPlone.utils import safe_unicode
10+
from plone.base.utils import safe_text
1111
from zope.i18n import translate
1212
from zope.interface import Interface
1313
from zope.interface import provider
@@ -62,7 +62,7 @@ def default_actions(context):
6262
"easyform_default_actions.xml", default=None
6363
)
6464
if default_actions:
65-
return safe_unicode(default_actions.file.data)
65+
return safe_text(default_actions.file.data)
6666
else:
6767
return config.ACTIONS_DEFAULT
6868

@@ -77,7 +77,7 @@ def default_fields(context):
7777
"easyform_default_fields.xml", default=None
7878
)
7979
if default_fields:
80-
return safe_unicode(default_fields.file.data)
80+
return safe_text(default_fields.file.data)
8181
else:
8282
return config.FIELDS_DEFAULT
8383

src/collective/easyform/interfaces/mailer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from plone.autoform import directives
1010
from plone.schema import Email
1111
from plone.supermodel.directives import fieldset
12-
from Products.CMFPlone.utils import safe_unicode
12+
from plone.base.utils import safe_text
1313
from z3c.form.browser.checkbox import CheckBoxFieldWidget
1414
from z3c.form.browser.textarea import TextAreaWidget
1515
from plone.autoform.interfaces import OMITTED_KEY
@@ -45,7 +45,7 @@ def default_mail_body():
4545
"easyform_mail_body_default.pt", default=None
4646
)
4747
if mail_body_default:
48-
return safe_unicode(mail_body_default.file.data)
48+
return safe_text(mail_body_default.file.data)
4949
else:
5050
return config.MAIL_BODY_DEFAULT
5151

src/collective/easyform/serializer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from collective.easyform.interfaces import IEasyForm
2727
from collective.easyform.interfaces import ILabel
2828
from collective.easyform.interfaces import ISaveData
29-
from Products.CMFPlone.utils import safe_unicode
29+
from plone.base.utils import safe_text
3030

3131

3232
logger = logging.getLogger("collective.easyform.migration")
@@ -107,7 +107,7 @@ def convertBeforeSerialize(value):
107107
elif isinstance(value, set):
108108
return list(value)
109109
elif isinstance(value, RichTextValue):
110-
return safe_unicode(value.raw) #raw_encoded
110+
return safe_text(value.raw) #raw_encoded
111111
else:
112112
return value
113113

src/collective/easyform/tests/testMailer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from plone import api
1515
from plone.app.textfield.value import RichTextValue
1616
from plone.namedfile.file import NamedFile
17-
from Products.CMFPlone.utils import safe_unicode
17+
from plone.base.utils import safe_text
1818
from six import BytesIO
1919

2020
import datetime
@@ -310,7 +310,7 @@ def test_UTF8Subject(self):
310310
encoded_subject_header = msg["subject"]
311311
decoded_header = decode_header(encoded_subject_header)[0][0]
312312

313-
self.assertEqual(safe_unicode(decoded_header), utf8_subject)
313+
self.assertEqual(safe_text(decoded_header), utf8_subject)
314314

315315
def test_UnicodeSubject(self):
316316
"""Test mailer with Unicode encoded subject line"""
@@ -328,7 +328,7 @@ def test_UnicodeSubject(self):
328328
encoded_subject_header = msg["subject"]
329329
decoded_header = decode_header(encoded_subject_header)[0][0]
330330

331-
self.assertEqual(safe_unicode(decoded_header), utf8_subject)
331+
self.assertEqual(safe_text(decoded_header), utf8_subject)
332332

333333
def test_Utf8ListSubject(self):
334334
"""Test mailer with Unicode encoded subject line"""
@@ -345,7 +345,7 @@ def test_Utf8ListSubject(self):
345345
encoded_subject_header = msg["subject"]
346346
decoded_header = decode_header(encoded_subject_header)[0][0]
347347

348-
self.assertEqual(safe_unicode(decoded_header), ", ".join(utf8_subject_list))
348+
self.assertEqual(safe_text(decoded_header), ", ".join(utf8_subject_list))
349349

350350
def test_MailerOverrides(self):
351351
"""Test mailer override functions"""

0 commit comments

Comments
 (0)