Skip to content

Commit 7f3ce38

Browse files
committed
Clean up
Backport some clean up from #592
1 parent 0526b7c commit 7f3ce38

5 files changed

Lines changed: 15 additions & 18 deletions

File tree

news/592.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clean up. @ale-rt

src/plone/api/content.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@
2121
from zope.globalrequest import getRequest
2222
from zope.interface import Interface
2323
from zope.interface import providedBy
24+
from zope.interface.interface import InterfaceClass
25+
from ZPublisher.BaseRequest import RequestContainer
26+
from ZTUtils.Lazy import LazyCat
27+
from ZTUtils.Lazy import LazyMap
2428

2529
import transaction
2630
import uuid
2731

28-
_marker = []
32+
_marker = object()
2933

3034
# Maximum number of attempts to generate a unique random ID
3135
MAX_UNIQUE_ID_ATTEMPTS = 100
@@ -753,7 +757,7 @@ def iter_ancestors(obj=None, function=None, interface=None, stop_at=_marker):
753757
#
754758
# This is useful if we want to have an empty iterator when checking
755759
# for ancestors in the portal.
756-
return iter(())
760+
yield from ()
757761

758762
chain = aq_chain(aq_inner(obj))
759763

src/plone/api/portal.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,6 @@ def send_email(
170170
# formataddr probably got confused by special characters.
171171
sender = from_address
172172

173-
# If the mail headers are not properly encoded we need to extract
174-
# them and let MailHost manage the encoding.
175-
if isinstance(body, str):
176-
body = body.encode(encoding)
177-
178173
host = get_tool("MailHost")
179174
host.send(
180175
body,

src/plone/api/tests/test_portal.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,18 @@
1515
from Products.CMFPlone.tests.utils import MockMailHost
1616
from Products.MailHost.interfaces import IMailHost
1717
from unittest import mock
18+
from unittest.mock import MagicMock
1819
from zope import schema
1920
from zope.component import getUtility
2021
from zope.component.hooks import setSite
2122
from zope.interface import Interface
2223
from zope.schema.vocabulary import SimpleVocabulary
2324
from zope.site import LocalSiteManager
25+
from ZPublisher.HTTPRequest import HTTPRequest
2426

2527
import DateTime
2628
import unittest
2729

28-
try:
29-
# Python 3
30-
from email import message_from_bytes
31-
except ImportError:
32-
# Python 2
33-
from email import message_from_string as message_from_bytes
34-
35-
3630
HAS_PLONE5 = version.parse(env.plone_version()) >= version.parse("5.0b2")
3731

3832

src/plone/api/user.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,12 @@ def revoke_roles(username=None, user=None, obj=None, roles=None):
438438
if user is None:
439439
raise InvalidParameterError("User could not be found")
440440

441-
roles = set(roles)
441+
if not isinstance(roles, (list, tuple)):
442+
raise InvalidParameterError("Roles must be a list or a tuple of strings")
442443

443-
if "Anonymous" in roles or "Authenticated" in roles:
444+
roles_set = set(roles)
445+
446+
if "Anonymous" in roles_set or "Authenticated" in roles_set:
444447
raise InvalidParameterError
445448

446449
inherit = True
@@ -454,7 +457,7 @@ def revoke_roles(username=None, user=None, obj=None, roles=None):
454457
if role not in ["Anonymous", "Authenticated"]
455458
}
456459

457-
roles = list(actual_roles - roles)
460+
roles = list(actual_roles - roles_set)
458461

459462
if obj is None:
460463
user.setSecurityProfile(roles=roles)

0 commit comments

Comments
 (0)