Skip to content

Commit

Permalink
chore: pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Apr 8, 2023
1 parent 4141a1f commit 3815c85
Show file tree
Hide file tree
Showing 32 changed files with 76 additions and 108 deletions.
3 changes: 1 addition & 2 deletions Products/CMFDiffTool/BaseDiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""CMFDiffTool.py
Calculate differences between content objects
Expand Down Expand Up @@ -63,7 +62,7 @@ def applyChanges(self, ob):
def filenameTitle(self, filename):
"""Translate the filename leading text
"""
msg = _(u'Filename: ${filename}',
msg = _('Filename: ${filename}',
mapping={'filename': filename})
return translate(msg)

Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/BinaryDiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from AccessControl.class_init import InitializeClass
from os import linesep
from Products.CMFDiffTool.BaseDiff import _getValue
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/CMFDTHtmlDiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from AccessControl.class_init import InitializeClass
from Products.CMFDiffTool.libs import htmldiff
from Products.CMFDiffTool.TextDiff import TextDiff
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/CMFDiffTool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""CMFDiffTool.py
Calculate differences between content objects
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/ChangeSet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# ChangeSet.py - Zope object representing the differences between
# objects
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Initialize CMFDiffTool Product"""
# Set up a MessageFactory for the cmfdifftool domain
from zope.i18nmessageid import MessageFactory
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/choicediff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from AccessControl.class_init import InitializeClass
from plone.dexterity.interfaces import IDexterityFTI
from plone.dexterity.utils import getAdditionalSchemata
Expand Down
3 changes: 1 addition & 2 deletions Products/CMFDiffTool/dexteritydiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.app.textfield import RichText
from plone.dexterity.browser.edit import DefaultEditForm
from Products.CMFDiffTool.choicediff import ChoiceDiff
Expand Down Expand Up @@ -68,7 +67,7 @@
"""Names of fields not to compare."""


class DexterityCompoundDiff(object):
class DexterityCompoundDiff:
"""text difference for Dexterity"""

meta_type = 'Compound Diff for Dexterity types'
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/exportimport/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
# Make a package
1 change: 0 additions & 1 deletion Products/CMFDiffTool/exportimport/difftool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from Products.CMFCore.utils import getToolByName
from Products.CMFDiffTool.interfaces import IDiffTool
from Products.GenericSetup.utils import exportObjects
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/interfaces/IChangeSet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003 The Connexions Project, All Rights Reserved
# Written by Brent Hendricks

Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/interfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Interface definitions
from zope.interface import Attribute
from zope.interface import Interface
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/interfaces/portal_diff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003 The Connexions Project, All Rights Reserved
# Written by Brent Hendricks

Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/libs/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
2 changes: 1 addition & 1 deletion Products/CMFDiffTool/libs/htmldiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def addStylesheet(self, html, ss):
pos = match.end()
else:
pos = 0
return ('{0}<style type="text/css"><!--\n{1}\n--></style>{2}'.format(
return ('{}<style type="text/css"><!--\n{}\n--></style>{}'.format(
html[:pos], ss, html[pos:]))

def startInsertText(self):
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/namedfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from AccessControl.class_init import InitializeClass
from plone.namedfile import NamedFile
from Products.CMFDiffTool.BinaryDiff import BinaryDiff
Expand Down
9 changes: 4 additions & 5 deletions Products/CMFDiffTool/testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
from plone.app.testing import FunctionalTesting
from plone.app.testing import PloneSandboxLayer
Expand All @@ -13,9 +12,9 @@
TEST_CONTENT_TYPE_ID = 'TestContentType'

VOCABULARY_TUPLES = [
(u'first_value', u'First Title'),
(u'second_value', None),
(u'third_value', u'Third Title'),
('first_value', 'First Title'),
('second_value', None),
('third_value', 'Third Title'),
]

VOCABULARY = SimpleVocabulary(
Expand All @@ -41,7 +40,7 @@ def setUpPloneSite(self, portal):
sm.registerUtility(
component=vocabulary_factory,
provided=IVocabularyFactory,
name=u'Products.CMFDiffTool.testing.VOCABULARY',
name='Products.CMFDiffTool.testing.VOCABULARY',
)

fti = DexterityFTI(
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/tests/BaseTestCase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from Products.CMFDiffTool.testing import CMFDiffToolDXLayer

import unittest
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""\
Unit test package for CMFDiffTool
"""
1 change: 0 additions & 1 deletion Products/CMFDiffTool/tests/testChangeSet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# CMFDiffTool tests
#
Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/tests/testDiffTool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# CMFDiffTool tests
#
Expand Down
17 changes: 8 additions & 9 deletions Products/CMFDiffTool/tests/testFieldDiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# CMFDiffTool tests
#
Expand Down Expand Up @@ -27,10 +26,10 @@ def method(self):


class U:
attribute = u'\xfcnicode value'
attribute = '\xfcnicode value'

def method(self):
return u'different method val\xfce'
return 'different method val\xfce'


class H:
Expand Down Expand Up @@ -118,7 +117,7 @@ def testSameText(self):
self.assertEqual(fd.ndiff(), ' value')
uu = U()
fd = FieldDiff(uu, uu, 'attribute')
self.assertEqual(fd.ndiff(), u' \xfcnicode value')
self.assertEqual(fd.ndiff(), ' \xfcnicode value')

def testDiffText(self):
"""Test text diff output with different value"""
Expand All @@ -128,7 +127,7 @@ def testDiffText(self):
expected = '- value%s+ different value' % linesep
fd = FieldDiff(a, b, 'attribute')
self.assertEqual(fd.ndiff(), expected)
expected = u'- value%s+ \xfcnicode value' % linesep
expected = '- value%s+ \xfcnicode value' % linesep
fd = FieldDiff(a, uu, 'attribute')
self.assertEqual(fd.ndiff(), expected)

Expand All @@ -139,13 +138,13 @@ def test_dump_text(self):
self.assertEqual(diff, ['- support'])
# Try unicode, a 'u' with an umlaut.
diff = []
dump('+', [u's\xfcpport'], 0, 1, diff)
self.assertEqual(diff, [u'+ s\xfcpport'])
dump('+', ['s\xfcpport'], 0, 1, diff)
self.assertEqual(diff, ['+ s\xfcpport'])
# Combine them.
diff = []
dump('-', ['support'], 0, 1, diff)
dump('+', [u's\xfcpport'], 0, 1, diff)
self.assertEqual(diff, ['- support', u'+ s\xfcpport'])
dump('+', ['s\xfcpport'], 0, 1, diff)
self.assertEqual(diff, ['- support', '+ s\xfcpport'])

def test_dump_integer(self):
"""Test dumping a diff of integers."""
Expand Down
17 changes: 8 additions & 9 deletions Products/CMFDiffTool/tests/testListDiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# CMFDiffTool tests
#
Expand Down Expand Up @@ -110,7 +109,7 @@ def testSameText(self):
"""Test text diff output with no diff"""
a = A()
diff = ListDiff(a, a, 'attribute')
expected = ' 1%(linesep)s 2%(linesep)s 3' % {'linesep': linesep}
expected = ' 1{linesep} 2{linesep} 3'.format(linesep=linesep)
self.assertEqual(diff.ndiff(), expected)

def testDiffText(self):
Expand Down Expand Up @@ -153,23 +152,23 @@ def test_inline_diff_hacker_dict(self):

def test_inline_diff_vocabulary(self):
# unchanged, with vocabulary title
expected = u'<div class="InlineDiff">First Title</div>'
expected = '<div class="InlineDiff">First Title</div>'
self._test_diff_list([testing.VOCABULARY_TUPLES[0][0]],
[testing.VOCABULARY_TUPLES[0][0]], True, expected)
# unchanged, without vocabulary title
expected = u'<div class="InlineDiff">second_value</div>'
expected = '<div class="InlineDiff">second_value</div>'
self._test_diff_list([testing.VOCABULARY_TUPLES[1][0]],
[testing.VOCABULARY_TUPLES[1][0]], True, expected)
# changed: add value, with vocabulary title
expected = u'''<div class="InlineDiff">
expected = '''<div class="InlineDiff">
<div class="diff_sub"></div>
<div class="diff_add">First Title</div>
</div>'''
self._test_diff_list([],
[testing.VOCABULARY_TUPLES[0][0]],
False, expected)
# changed: replaced unique value by another one, displaying titles
expected = u'''<div class="InlineDiff">
expected = '''<div class="InlineDiff">
<div class="diff_sub">First Title</div>
<div class="diff_add"></div>
</div>
Expand All @@ -181,7 +180,7 @@ def test_inline_diff_vocabulary(self):
[testing.VOCABULARY_TUPLES[2][0]],
False, expected)
# changed: replaced multiple values by others, displaying titles
expected = u'''<div class="InlineDiff">
expected = '''<div class="InlineDiff">
<div class="diff_sub">First Title</div>
<div class="diff_add"></div>
</div>
Expand All @@ -196,7 +195,7 @@ def test_inline_diff_vocabulary(self):
testing.VOCABULARY_TUPLES[2][0]],
False, expected)
# changed: replaced multiple values by others, displaying titles
expected = u'''<div class="InlineDiff">
expected = '''<div class="InlineDiff">
<div class="diff_sub"></div>
<div class="diff_add">Third Title</div>
</div>
Expand All @@ -211,7 +210,7 @@ def test_inline_diff_vocabulary(self):
testing.VOCABULARY_TUPLES[0][0]],
False, expected)
# changed: removed values, displaying titles
expected = u'''<div class="InlineDiff">
expected = '''<div class="InlineDiff">
<div class="diff_sub">First Title</div>
<div class="diff_add"></div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions Products/CMFDiffTool/tests/testTextDiff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from os import linesep
from plone.app.testing import PLONE_INTEGRATION_TESTING
from Products.CMFDiffTool.TextDiff import TextDiff
Expand Down
5 changes: 2 additions & 3 deletions Products/CMFDiffTool/tests/test_astextdiff.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# -*- coding: utf-8 -*-
from datetime import date
from Products.CMFDiffTool.interfaces import IDifference
from Products.CMFDiffTool.TextDiff import AsTextDiff

import unittest


class DateDummyType(object):
class DateDummyType:
def __init__(self, date):
self.date = date


class BoolDummyType(object):
class BoolDummyType:
def __init__(self, bool_field):
self.bool_field = bool_field

Expand Down
17 changes: 8 additions & 9 deletions Products/CMFDiffTool/tests/test_binarydiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.namedfile.file import NamedFile
Expand All @@ -17,14 +16,14 @@ def test_should_detect_different_filename(self):
self.portal.invokeFactory(
testing.TEST_CONTENT_TYPE_ID,
'obj1',
file=NamedFile(data='contents', filename=u'blah.txt'),
file=NamedFile(data='contents', filename='blah.txt'),
)
obj1 = self.portal['obj1']

self.portal.invokeFactory(
testing.TEST_CONTENT_TYPE_ID,
'obj2',
file=NamedFile(data='contents', filename=u'bleh.txt'),
file=NamedFile(data='contents', filename='bleh.txt'),
)
obj2 = self.portal['obj2']

Expand All @@ -37,14 +36,14 @@ def test_should_detect_different_data(self):
self.portal.invokeFactory(
testing.TEST_CONTENT_TYPE_ID,
'obj1',
file=NamedFile(data='contents', filename=u'f.txt'),
file=NamedFile(data='contents', filename='f.txt'),
)
obj1 = self.portal['obj1']

self.portal.invokeFactory(
testing.TEST_CONTENT_TYPE_ID,
'obj2',
file=NamedFile(data='different contents', filename=u'f.txt'),
file=NamedFile(data='different contents', filename='f.txt'),
)
obj2 = self.portal['obj2']

Expand All @@ -57,14 +56,14 @@ def test_should_detect_same_data_and_filename(self):
self.portal.invokeFactory(
testing.TEST_CONTENT_TYPE_ID,
'obj1',
file=NamedFile(data='contents', filename=u'f.txt'),
file=NamedFile(data='contents', filename='f.txt'),
)
obj1 = self.portal['obj1']

self.portal.invokeFactory(
testing.TEST_CONTENT_TYPE_ID,
'obj2',
file=NamedFile(data='contents', filename=u'f.txt'),
file=NamedFile(data='contents', filename='f.txt'),
)
obj2 = self.portal['obj2']

Expand All @@ -78,14 +77,14 @@ def test_should_escape_html(self):
self.portal.invokeFactory(
testing.TEST_CONTENT_TYPE_ID,
'obj1',
file=NamedFile(data='contents', filename=u'blah.txt'),
file=NamedFile(data='contents', filename='blah.txt'),
)
obj1 = self.portal['obj1']

self.portal.invokeFactory(
testing.TEST_CONTENT_TYPE_ID,
'obj2',
file=NamedFile(data='<script>alert("Hacker data")</script>', filename=u'<script>alert("Hacker filename")</script>.txt'),
file=NamedFile(data='<script>alert("Hacker data")</script>', filename='<script>alert("Hacker filename")</script>.txt'),
)
obj2 = self.portal['obj2']

Expand Down
1 change: 0 additions & 1 deletion Products/CMFDiffTool/tests/test_choicediff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from Products.CMFDiffTool import testing
Expand Down
Loading

0 comments on commit 3815c85

Please sign in to comment.