diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index b0cfb39..4521a6d 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -17,6 +17,7 @@ from plone.z3cform import z2 from plone.z3cform.fieldsets import extensible from plone.z3cform.interfaces import IWrappedForm from Products.CMFCore.utils import getToolByName +from Products.CMFPlone.utils import safe_unicode from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.statusmessages.interfaces import IStatusMessage from six.moves.urllib.parse import quote @@ -152,13 +153,9 @@ class CommentForm(extensible.ExtensibleForm, form.Form): # Make sure author_name/ author_email is properly encoded if 'author_name' in data: - author_name = data['author_name'] - if isinstance(author_name, str): - author_name = six.text_type(author_name, 'utf-8') + author_name = safe_unicode(data['author_name']) if 'author_email' in data: - author_email = data['author_email'] - if isinstance(author_email, str): - author_email = six.text_type(author_email, 'utf-8') + author_email = safe_unicode(data['author_email']) # Set comment author properties for anonymous users or members portal_membership = getToolByName(context, 'portal_membership') @@ -167,8 +164,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form): 'Reply to item', context): # Member member = portal_membership.getAuthenticatedMember() - # memberdata is stored as utf-8 encoded strings - email = member.getProperty('email') + email = safe_unicode(member.getProperty('email')) fullname = member.getProperty('fullname') if not fullname or fullname == '': fullname = member.getUserName() diff --git a/plone/app/discussion/conversation.py b/plone/app/discussion/conversation.py index 5a6ed71..ae13301 100644 --- a/plone/app/discussion/conversation.py +++ b/plone/app/discussion/conversation.py @@ -347,20 +347,20 @@ class ConversationReplies(object): return len(self.children) def __contains__(self, key): - return long(key) in self.children + return int(key) in self.children def __getitem__(self, key): - """Get an item by its long key + """Get an item by its int key """ - key = long(key) + key = int(key) if key not in self.children: raise KeyError(key) return self.conversation[key] def __delitem__(self, key): - """Delete an item by its long key + """Delete an item by its int key """ - key = long(key) + key = int(key) if key not in self.children: raise KeyError(key) del self.conversation[key] @@ -369,7 +369,7 @@ class ConversationReplies(object): return iter(self.children) def get(self, key, default=None): - key = long(key) + key = int(key) if key not in self.children: return default return self.conversation.get(key) diff --git a/plone/app/discussion/tests/functional_test_comments.txt b/plone/app/discussion/tests/functional_test_comments.txt index d78a7eb..36ad8a1 100644 --- a/plone/app/discussion/tests/functional_test_comments.txt +++ b/plone/app/discussion/tests/functional_test_comments.txt @@ -470,7 +470,7 @@ Edit the content object. >>> from hashlib import sha1 as sha >>> ring = _getKeyring('foo') >>> secret = ring.random() - >>> token = hmac.new(secret, 'admin', sha).hexdigest() + >>> token = hmac.new(secret.encode('utf8'), b'admin', sha).hexdigest() >>> browser.open("http://nohost/plone/doc1/edit?_authenticator=" + token) >>> browser.getControl(name='form.widgets.IRichTextBehavior.text').value = "Lorem ipsum" >>> browser.getControl('Save').click() diff --git a/plone/app/discussion/tests/test_comment.py b/plone/app/discussion/tests/test_comment.py index 8ac4d93..0600986 100644 --- a/plone/app/discussion/tests/test_comment.py +++ b/plone/app/discussion/tests/test_comment.py @@ -171,9 +171,10 @@ class CommentTest(unittest.TestCase): def test_getText_with_non_ascii_characters(self): comment1 = createObject('plone.Comment') comment1.text = u'Umlaute sind ä, ö und ü.' + out = b'

Umlaute sind \xc3\xa4, \xc3\xb6 und \xc3\xbc.

' self.assertEqual( comment1.getText(), - '

Umlaute sind \xc3\xa4, \xc3\xb6 und \xc3\xbc.

', + out.decode('utf8') ) def test_getText_doesnt_link(self): diff --git a/plone/app/discussion/tests/test_comments_viewlet.py b/plone/app/discussion/tests/test_comments_viewlet.py index 5a34cb6..942f0d2 100644 --- a/plone/app/discussion/tests/test_comments_viewlet.py +++ b/plone/app/discussion/tests/test_comments_viewlet.py @@ -567,7 +567,8 @@ class TestCommentsViewlet(unittest.TestCase): replies = self.viewlet.get_replies() next(replies) next(replies) - self.assertRaises(StopIteration, replies.next) + with self.assertRaises(StopIteration): + next(replies) def test_get_replies_on_non_annotatable_object(self): context = self.portal.MailHost # the mail host is not annotatable @@ -575,7 +576,8 @@ class TestCommentsViewlet(unittest.TestCase): replies = viewlet.get_replies() self.assertEqual(len(tuple(replies)), 0) replies = viewlet.get_replies() - self.assertRaises(StopIteration, replies.next) + with self.assertRaises(StopIteration): + next(replies) def test_get_replies_with_workflow_actions(self): self.assertFalse(self.viewlet.get_replies(workflow_actions=True)) diff --git a/plone/app/discussion/tests/test_contentrules.py b/plone/app/discussion/tests/test_contentrules.py index 6b9610e..c05aede 100644 --- a/plone/app/discussion/tests/test_contentrules.py +++ b/plone/app/discussion/tests/test_contentrules.py @@ -54,7 +54,7 @@ class CommentContentRulesTest(unittest.TestCase): def testCommentIdStringSubstitution(self): comment_id = getAdapter(self.document, IStringSubstitution, name=u'comment_id') - self.assertIsInstance(comment_id(), long) + self.assertIsInstance(comment_id(), int) def testCommentTextStringSubstitution(self): comment_text = getAdapter(self.document, IStringSubstitution, @@ -114,7 +114,7 @@ class ReplyContentRulesTest(unittest.TestCase): IStringSubstitution, name=u'comment_id', ) - self.assertIsInstance(reply_id(), long) + self.assertIsInstance(reply_id(), int) def testReplyTextStringSubstitution(self): reply_text = getAdapter( diff --git a/plone/app/discussion/tests/test_conversation.py b/plone/app/discussion/tests/test_conversation.py index 6f94894..fcf528c 100644 --- a/plone/app/discussion/tests/test_conversation.py +++ b/plone/app/discussion/tests/test_conversation.py @@ -68,7 +68,7 @@ class ConversationTest(unittest.TestCase): new_id = conversation.addComment(comment) # Check that the conversation methods return the correct data - self.assertTrue(isinstance(comment.comment_id, long)) + self.assertTrue(isinstance(comment.comment_id, int)) self.assertTrue(IComment.providedBy(conversation[new_id])) self.assertEqual( aq_base(conversation[new_id].__parent__), @@ -641,7 +641,7 @@ class ConversationTest(unittest.TestCase): def test_unconvertible_id(self): # make sure the conversation view doesn't break when given comment id - # can't be converted to long + # can't be converted to int conversation = self.portal.doc1.restrictedTraverse( '++conversation++default/ThisCantBeRight',