Skip to content

Commit 40bcc0f

Browse files
pyupgrade --py3-only
This gets rid of u'unicode markers' and some usages of six.
1 parent 70e99e9 commit 40bcc0f

51 files changed

Lines changed: 786 additions & 842 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/conf.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# collective.easyform documentation build configuration file, created by
43
# sphinx-quickstart on Mon Feb 24 23:51:08 2014.
@@ -51,8 +50,8 @@
5150
master_doc = "index"
5251

5352
# General information about the project.
54-
project = u"collective.easyform"
55-
copyright = u"2014, Roman Kozlovskyi"
53+
project = "collective.easyform"
54+
copyright = "2014, Roman Kozlovskyi"
5655

5756
# The version info for the project you're documenting, acts as replacement for
5857
# |version| and |release|, also used in various other places throughout the
@@ -195,8 +194,8 @@
195194
(
196195
"index",
197196
"collectiveeasyform.tex",
198-
u"collective.easyform Documentation",
199-
u"Roman Kozlovskyi",
197+
"collective.easyform Documentation",
198+
"Roman Kozlovskyi",
200199
"manual",
201200
),
202201
]
@@ -230,8 +229,8 @@
230229
(
231230
"index",
232231
"collectiveeasyform",
233-
u"collective.easyform Documentation",
234-
[u"Roman Kozlovskyi"],
232+
"collective.easyform Documentation",
233+
["Roman Kozlovskyi"],
235234
1,
236235
)
237236
]
@@ -249,8 +248,8 @@
249248
(
250249
"index",
251250
"collectiveeasyform",
252-
u"collective.easyform Documentation",
253-
u"Roman Kozlovskyi",
251+
"collective.easyform Documentation",
252+
"Roman Kozlovskyi",
254253
"collectiveeasyform",
255254
"One line description of project.",
256255
"Miscellaneous",

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
from setuptools import find_packages
32
from setuptools import setup
43

src/collective/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# -*- coding: utf-8 -*-
21
__import__("pkg_resources").declare_namespace(__name__)

src/collective/easyform/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
from zope.i18nmessageid import MessageFactory
32

43

src/collective/easyform/actions.py

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
from AccessControl import getSecurityManager
32
from BTrees.IOBTree import IOBTree
43
from BTrees.LOBTree import LOBTree as SavedDataBTree
@@ -48,8 +47,8 @@
4847
from plone.base.utils import safe_text
4948
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
5049
from Products.PythonScripts.PythonScript import PythonScript
51-
from six import BytesIO
52-
from six import StringIO
50+
from io import BytesIO
51+
from io import StringIO
5352
from tempfile import NamedTemporaryFile
5453
from time import time
5554
from xml.etree import ElementTree as ET
@@ -68,9 +67,9 @@
6867

6968

7069
@implementer(IActionFactory)
71-
class ActionFactory(object):
70+
class ActionFactory:
7271

73-
title = u""
72+
title = ""
7473

7574
def __init__(self, fieldcls, title, permission, *args, **kw):
7675
self.fieldcls = fieldcls
@@ -121,13 +120,13 @@ def serialize(self, field):
121120
return str(field)
122121
if isinstance(field, (int, float, Decimal, bool)):
123122
return str(field)
124-
if isinstance(field, six.string_types):
123+
if isinstance(field, str):
125124
return safe_text(field)
126125
return safe_text(repr(field))
127126

128127
def onSuccess(self, fields, request):
129128
raise NotImplementedError(
130-
"There is not implemented 'onSuccess' of {0!r}".format(self)
129+
"There is not implemented 'onSuccess' of {!r}".format(self)
131130
)
132131

133132

@@ -146,7 +145,7 @@ class Mailer(Action):
146145
def __init__(self, **kw):
147146
for i, f in IMailer.namesAndDescriptions():
148147
setattr(self, i, kw.pop(i, f.default))
149-
super(Mailer, self).__init__(**kw)
148+
super().__init__(**kw)
150149

151150
def get_portal_email_address(self, context):
152151
"""Return the email address defined in the Plone site."""
@@ -179,17 +178,17 @@ def get_mail_body(self, unsorted_data, request, context):
179178
# pass both the bare_fields (fgFields only) and full fields.
180179
# bare_fields for compatability with older templates,
181180
# full fields to enable access to htmlValue
182-
if isinstance(self.body_pre, six.string_types):
181+
if isinstance(self.body_pre, str):
183182
body_pre = self.body_pre
184183
else:
185184
body_pre = self.body_pre.output
186185

187-
if isinstance(self.body_post, six.string_types):
186+
if isinstance(self.body_post, str):
188187
body_post = self.body_post
189188
else:
190189
body_post = self.body_post.output
191190

192-
if isinstance(self.body_footer, six.string_types):
191+
if isinstance(self.body_footer, str):
193192
body_footer = self.body_footer
194193
else:
195194
body_footer = self.body_footer.output
@@ -223,9 +222,9 @@ def get_owner_info(self, context):
223222
toemail = self.get_portal_email_address(context)
224223
if not toemail:
225224
raise ValueError(
226-
u"Unable to mail form input because no recipient address has "
227-
u"been specified. Please check the recipient settings of the "
228-
u"EasyForm Mailer within the current form folder."
225+
"Unable to mail form input because no recipient address has "
226+
"been specified. Please check the recipient settings of the "
227+
"EasyForm Mailer within the current form folder."
229228
)
230229
return (fullname, toemail)
231230

@@ -273,7 +272,7 @@ def get_addresses(self, fields, request, context, from_addr=None, to_addr=None):
273272
def get_subject(self, fields, request, context):
274273
"""Return subject."""
275274
# get subject header
276-
nosubject = u"(no subject)" # TODO: translate
275+
nosubject = "(no subject)" # TODO: translate
277276
subject = None
278277
if hasattr(self, "subjectOverride") and self.subjectOverride:
279278
# subject has a TALES override
@@ -290,7 +289,7 @@ def get_subject(self, fields, request, context):
290289
# we only do subject expansion if there's no field chosen
291290
subject = dollar_replacer(subject, fields)
292291

293-
if isinstance(subject, six.string_types):
292+
if isinstance(subject, str):
294293
subject = safe_text(subject)
295294
elif subject and isinstance(subject, (set, tuple, list)):
296295
subject = ", ".join([safe_text(s) for s in subject])
@@ -322,7 +321,7 @@ def get_header_info(
322321
headerinfo["Subject"] = self.get_subject(fields, request, context)
323322

324323
# CC
325-
if isinstance(self.cc_recipients, six.string_types):
324+
if isinstance(self.cc_recipients, str):
326325
cc_recips = self.cc_recipients
327326
else:
328327
cc_recips = [_f for _f in self.cc_recipients if _f]
@@ -335,7 +334,7 @@ def get_header_info(
335334
headerinfo["Cc"] = format_addresses(cc_recips)
336335

337336
# BCC
338-
if isinstance(self.bcc_recipients, six.string_types):
337+
if isinstance(self.bcc_recipients, str):
339338
bcc_recips = self.bcc_recipients
340339
else:
341340
bcc_recips = [_f for _f in self.bcc_recipients if _f]
@@ -348,7 +347,7 @@ def get_header_info(
348347
headerinfo["Bcc"] = format_addresses(bcc_recips)
349348

350349
for key in getattr(self, "xinfo_headers", []):
351-
headerinfo["X-{0}".format(key)] = self.secure_header_line(
350+
headerinfo["X-{}".format(key)] = self.secure_header_line(
352351
request.get(key, "MISSING")
353352
)
354353
return headerinfo
@@ -357,7 +356,7 @@ def get_header_row(self):
357356
titles = self.getColumnTitles()
358357
encoded_titles = []
359358
for t in titles:
360-
if six.PY2 and isinstance(t, six.text_type):
359+
if six.PY2 and isinstance(t, str):
361360
t = t.encode("utf-8")
362361
encoded_titles.append(t)
363362
return encoded_titles
@@ -433,10 +432,9 @@ def get_attachments(self, fields, request):
433432
writer.writerow(self.get_header_row())
434433
writer.writerow(csvdata)
435434
csv = output.getvalue()
436-
if six.PY3:
437-
csv = csv.encode("utf-8")
435+
csv = csv.encode("utf-8")
438436
now = DateTime().ISO().replace(" ", "-").replace(":", "")
439-
filename = "formdata_{0}.csv".format(now)
437+
filename = "formdata_{}.csv".format(now)
440438
# Set MIME type of attachment to 'application' so that it will be encoded with base64
441439
attachments.append((filename, "application/csv", "utf-8", csv))
442440

@@ -454,7 +452,7 @@ def get_attachments(self, fields, request):
454452
output = tmp.read()
455453

456454
now = DateTime().ISO().replace(" ", "-").replace(":", "")
457-
filename = "formdata_{0}.xlsx".format(now)
455+
filename = "formdata_{}.xlsx".format(now)
458456
attachments.append(
459457
(
460458
filename,
@@ -471,7 +469,7 @@ def get_attachments(self, fields, request):
471469
doc.write(output, encoding="utf-8", xml_declaration=True)
472470
xmlstr = output.getvalue()
473471
now = DateTime().ISO().replace(" ", "-").replace(":", "")
474-
filename = "formdata_{0}.xml".format(now)
472+
filename = "formdata_{}.xml".format(now)
475473
# Set MIME type of attachment to 'application' so that it will be encoded with base64
476474
attachments.append((filename, "application/xml", "utf-8", xmlstr))
477475

@@ -481,7 +479,7 @@ def get_mail_text(self, fields, request, context):
481479
"""Get header and body of e-mail as text (string)"""
482480
headerinfo = self.get_header_info(fields, request, context)
483481
body = self.get_mail_body(fields, request, context)
484-
if six.PY2 and isinstance(body, six.text_type):
482+
if six.PY2 and isinstance(body, str):
485483
body = body.encode("utf-8")
486484
email_charset = "utf-8"
487485
# always use text/plain for encrypted bodies
@@ -523,7 +521,7 @@ def get_mail_text(self, fields, request, context):
523521
maintype, subtype = ctype.split("/", 1)
524522

525523
if maintype == "text":
526-
if not six.PY2 and isinstance(content, six.binary_type):
524+
if not six.PY2 and isinstance(content, bytes):
527525
content = content.decode("utf-8")
528526
msg = MIMEText(content, _subtype=subtype)
529527
elif maintype == "image":
@@ -537,7 +535,7 @@ def get_mail_text(self, fields, request, context):
537535
encoders.encode_base64(msg)
538536

539537
# Set the filename parameter
540-
if six.PY2 and isinstance(filename, six.text_type):
538+
if six.PY2 and isinstance(filename, str):
541539
filename = filename.encode("utf-8")
542540
msg.add_header(
543541
"Content-Disposition", "attachment", filename=("utf-8", "", filename)
@@ -570,7 +568,7 @@ class CustomScript(Action):
570568
def __init__(self, **kw):
571569
for i, f in ICustomScript.namesAndDescriptions():
572570
setattr(self, i, kw.pop(i, f.default))
573-
super(CustomScript, self).__init__(**kw)
571+
super().__init__(**kw)
574572

575573
def getScript(self, context):
576574
# Generate Python script object
@@ -584,10 +582,10 @@ def getScript(self, context):
584582
script._validateProxy = lambda i=None: None
585583

586584
# Force proxy role
587-
if role != u"none":
585+
if role != "none":
588586
script.manage_proxy((role,))
589587

590-
if six.PY2 and isinstance(body, six.text_type):
588+
if six.PY2 and isinstance(body, str):
591589
body = body.encode("utf-8")
592590
params = "fields, easyform, request"
593591
script.ZPythonScript_edit(params, body)
@@ -620,7 +618,7 @@ def checkWarningsAndErrors(self, script):
620618
"Python script " + self.__name__ + " has errors: " + str(script.errors)
621619
)
622620
raise ValueError(
623-
"Python script {0} has errors: {1}".format(
621+
"Python script {} has errors: {}".format(
624622
self.__name__, str(script.errors)
625623
)
626624
)
@@ -658,7 +656,7 @@ class SaveData(Action):
658656
def __init__(self, **kw):
659657
for i, f in ISaveData.namesAndDescriptions():
660658
setattr(self, i, kw.pop(i, f.default))
661-
super(SaveData, self).__init__(**kw)
659+
super().__init__(**kw)
662660

663661
@property
664662
def _storage(self):
@@ -690,7 +688,7 @@ def get_header_row(self):
690688
titles = self.getColumnTitles()
691689
encoded_titles = []
692690
for t in titles:
693-
if six.PY2 and isinstance(t, six.text_type):
691+
if six.PY2 and isinstance(t, str):
694692
t = t.encode("utf-8")
695693
encoded_titles.append(t)
696694
return encoded_titles
@@ -704,7 +702,7 @@ def get_data(row, i):
704702
return data.raw
705703
if is_file_data(data):
706704
data = data.filename
707-
if six.PY2 and isinstance(data, six.text_type):
705+
if six.PY2 and isinstance(data, str):
708706
return data.encode("utf-8")
709707
if isinstance(data, (list, tuple, set)):
710708
data = '|'.join(data)
@@ -793,13 +791,13 @@ def download_csv(self, response, delimiter):
793791
# """
794792
response.setHeader(
795793
"Content-Disposition",
796-
'attachment; filename="{0}.csv"'.format(self.__name__),
794+
'attachment; filename="{}.csv"'.format(self.__name__),
797795
)
798796
response.setHeader("Content-Type", "text/comma-separated-values")
799797
value = self.getSavedFormInputForEdit(
800798
getattr(self, "UseColumnNames", False), delimiter=delimiter
801799
)
802-
if isinstance(value, six.text_type):
800+
if isinstance(value, str):
803801
value = value.encode("utf-8")
804802
response.write(value)
805803

@@ -808,13 +806,13 @@ def download_tsv(self, response):
808806
# """
809807
response.setHeader(
810808
"Content-Disposition",
811-
'attachment; filename="{0}.tsv"'.format(self.__name__),
809+
'attachment; filename="{}.tsv"'.format(self.__name__),
812810
)
813811
response.setHeader("Content-Type", "text/tab-separated-values")
814812
value = self.getSavedFormInputForEdit(
815813
getattr(self, "UseColumnNames", False), delimiter="\t"
816814
)
817-
if isinstance(value, six.text_type):
815+
if isinstance(value, str):
818816
value = value.encode("utf-8")
819817
response.write(value)
820818

@@ -823,7 +821,7 @@ def download_xlsx(self, response):
823821
# """
824822
response.setHeader(
825823
"Content-Disposition",
826-
'attachment; filename="{0}.xlsx"'.format(self.__name__),
824+
'attachment; filename="{}.xlsx"'.format(self.__name__),
827825
)
828826

829827
response.setHeader(
@@ -910,17 +908,17 @@ def onSuccess(self, fields, request):
910908

911909
MailerAction = ActionFactory(
912910
Mailer,
913-
_(u"label_mailer_action", default=u"Mailer"),
911+
_("label_mailer_action", default="Mailer"),
914912
"collective.easyform.AddMailers",
915913
)
916914
CustomScriptAction = ActionFactory(
917915
CustomScript,
918-
_(u"label_customscript_action", default=u"Custom Script"),
916+
_("label_customscript_action", default="Custom Script"),
919917
"collective.easyform.AddCustomScripts",
920918
)
921919
SaveDataAction = ActionFactory(
922920
SaveData,
923-
_(u"label_savedata_action", default=u"Save Data"),
921+
_("label_savedata_action", default="Save Data"),
924922
"collective.easyform.AddDataSavers",
925923
)
926924

0 commit comments

Comments
 (0)