Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python 2 / 3 compatibility #274

Merged
merged 1 commit into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ New features:

Bug fixes:

- Add Python 2 / 3 compatibility.
[pbauer]

- iCalendar import: Fix usage of ``sync_uid``, which wasn't correctly implemented since plone.app.event 2.0.
[thet]

Expand Down
6 changes: 3 additions & 3 deletions plone/app/event/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import itertools

from Acquisition import aq_inner
from Acquisition import aq_parent
Expand Down Expand Up @@ -35,6 +34,7 @@


import pytz
import six


DEFAULT_END_DELTA = 1 # hours
Expand Down Expand Up @@ -221,8 +221,8 @@ def filter_and_resort(context, brains, start, end, sort, sort_reverse):
_allstarts = sorted(idx['start'])
_allends = sorted(idx['end'])
# assuming (start, end) pairs belong together
#assert(len(_allstarts) == len(_allends))
_occ = itertools.izip(_allstarts, _allends)
# assert(len(_allstarts) == len(_allends))
_occ = six.moves.zip(_allstarts, _allends)
if start:
_occ = [(s, e) for (s, e) in _occ if e >= _start]
if end:
Expand Down
2 changes: 1 addition & 1 deletion plone/app/event/dx/behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def _recurrence_upcoming_event(self):
adapter = IRecurrenceSupport(self.context)
occs = adapter.occurrences(range_start=localized_now())
try:
return occs.next()
return next(occs)
except StopIteration:
# No more future occurrences: passed event
return IEventBasic(self.context)
Expand Down
5 changes: 3 additions & 2 deletions plone/app/event/ical/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
import icalendar
import random
import transaction
import urllib2

from six.moves import urllib


def ical_import(container, ics_resource, event_type,
Expand Down Expand Up @@ -323,7 +324,7 @@ def handleSaveImport(self, action):
ical_resource = ical_file.data
ical_import_from = ical_file.filename
else:
ical_resource = urllib2.urlopen(ical_url).read()
ical_resource = urllib.request.urlopen(ical_url).read()
ical_import_from = ical_url

import_metadata = ical_import(
Expand Down
5 changes: 4 additions & 1 deletion plone/app/event/portlets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
from plone.app.event.base import find_navroot


import six


def get_calendar_url(context, search_base):
# search_base is always from the portal_root object. We won't include
# the path from the portal root object, so we traverse to the calendar
# object and call it's url then.
calendar_url = None
if search_base:
portal = find_ploneroot(context)
if isinstance(search_base, unicode):
if isinstance(search_base, six.text_type):
search_base = search_base.encode('utf8')
search_base = '/'.join(search_base.split('/')[2:])
calendar_url = portal.unrestrictedTraverse(
Expand Down
2 changes: 1 addition & 1 deletion plone/app/event/recurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def publishTraverse(self, request, name):
if dateobj:
occs = IRecurrenceSupport(context).occurrences(range_start=dateobj)
try:
occurrence = occs.next()
occurrence = next(occs)
occ_acc = IEventAccessor(occurrence)
if is_same_day(dateobj, occ_acc.start):
return occurrence
Expand Down
9 changes: 5 additions & 4 deletions plone/app/event/tests/test_base_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@


import pytz
import six
import unittest


Expand Down Expand Up @@ -320,10 +321,10 @@ def test_date_speller(self):
# locale specific
# TODO: test better.
self.assertTrue(isinstance(date_spelled['wkday'], int))
self.assertTrue(isinstance(date_spelled['month_name'], basestring))
self.assertTrue(isinstance(date_spelled['month_abbr'], basestring))
self.assertTrue(isinstance(date_spelled['wkday_name'], basestring))
self.assertTrue(isinstance(date_spelled['wkday_abbr'], basestring))
self.assertTrue(isinstance(date_spelled['month_name'], six.string_types))
self.assertTrue(isinstance(date_spelled['month_abbr'], six.string_types))
self.assertTrue(isinstance(date_spelled['wkday_name'], six.string_types))
self.assertTrue(isinstance(date_spelled['wkday_abbr'], six.string_types))


class TimezoneTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion plone/app/event/tests/test_portlet_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def testInvokeAddview(self):

self.assertEqual(len(mapping), 1)
self.assertTrue(
isinstance(mapping.values()[0], portlet_calendar.Assignment)
isinstance(list(mapping.values())[0], portlet_calendar.Assignment)
)

def testRenderer(self):
Expand Down
2 changes: 1 addition & 1 deletion plone/app/event/tests/test_portlet_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def testInvokeAddview(self):

self.assertEqual(len(mapping), 1)
self.assertTrue(
isinstance(mapping.values()[0], portlet_events.Assignment)
isinstance(list(mapping.values())[0], portlet_events.Assignment)
)

def testInvokeEditView(self):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
'plone.uuid',
'plone.z3cform',
'pytz',
'six',
'transaction',
'z3c.form >= 3.2.1.dev0',
'zope.annotation',
Expand Down